@adshift/react-native-plugin 2.1.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AdShiftReactNativePlugin.podspec +20 -4
- package/CHANGELOG.md +57 -8
- package/README.md +131 -74
- package/android/build.gradle +3 -2
- package/android/consumer-rules.pro +2 -21
- package/android/src/main/AndroidManifest.xml +14 -1
- package/android/src/main/java/com/adshift/reactnativeplugin/ActivityIntents.kt +307 -0
- package/android/src/main/java/com/adshift/reactnativeplugin/AdShiftReactNativePluginModule.kt +90 -153
- package/android/src/test/java/com/adshift/reactnativeplugin/ConsentSnapshotTest.kt +0 -20
- package/android/src/test/java/com/adshift/reactnativeplugin/DeepLinkDeliveryTest.kt +40 -7
- package/android/src/test/java/com/adshift/reactnativeplugin/InitializeOrderingTest.kt +51 -5
- package/android/src/test/java/com/adshift/reactnativeplugin/IntentLinkDedupTest.kt +0 -5
- package/android/src/test/java/com/adshift/reactnativeplugin/LaunchIntentForwardingTest.kt +21 -11
- package/android/src/test/java/com/adshift/reactnativeplugin/LaunchLinkRecordTest.kt +420 -0
- package/android/src/test/java/com/adshift/reactnativeplugin/ModuleTestSupport.kt +97 -25
- package/android/src/test/java/com/adshift/reactnativeplugin/StartVerdictTest.kt +0 -4
- package/ios/AdShiftReactNativePlugin.h +0 -12
- package/ios/AdShiftReactNativePlugin.mm +7 -14
- package/ios/AdShiftReactNativePluginHelper.swift +38 -73
- package/ios/Core/BridgeRules.swift +42 -30
- package/lib/commonjs/Adshift.js +100 -284
- package/lib/commonjs/Adshift.js.map +1 -1
- package/lib/commonjs/NativeAdShiftReactNativePlugin.js +2 -11
- package/lib/commonjs/NativeAdShiftReactNativePlugin.js.map +1 -1
- package/lib/commonjs/index.js +6 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/jest/index.js +6 -18
- package/lib/commonjs/jest/index.js.map +1 -1
- package/lib/commonjs/nativeSdkVersions.js +4 -6
- package/lib/commonjs/nativeSdkVersions.js.map +1 -1
- package/lib/commonjs/types/AdshiftAdRevenue.js +0 -24
- package/lib/commonjs/types/AdshiftAdRevenue.js.map +1 -1
- package/lib/commonjs/types/AdshiftConfig.js +11 -23
- package/lib/commonjs/types/AdshiftConfig.js.map +1 -1
- package/lib/commonjs/types/AdshiftConsent.js +9 -45
- package/lib/commonjs/types/AdshiftConsent.js.map +1 -1
- package/lib/commonjs/types/AdshiftConsentSnapshot.js +5 -24
- package/lib/commonjs/types/AdshiftConsentSnapshot.js.map +1 -1
- package/lib/commonjs/types/AdshiftDeepLink.js +50 -33
- package/lib/commonjs/types/AdshiftDeepLink.js.map +1 -1
- package/lib/commonjs/types/AdshiftError.js +7 -27
- package/lib/commonjs/types/AdshiftError.js.map +1 -1
- package/lib/commonjs/types/AdshiftEventParam.js +4 -38
- package/lib/commonjs/types/AdshiftEventParam.js.map +1 -1
- package/lib/commonjs/types/AdshiftEventType.js +1 -39
- package/lib/commonjs/types/AdshiftEventType.js.map +1 -1
- package/lib/commonjs/types/AdshiftThirdPartySharing.js +7 -38
- package/lib/commonjs/types/AdshiftThirdPartySharing.js.map +1 -1
- package/lib/commonjs/types/index.js +12 -0
- package/lib/commonjs/types/index.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/module/Adshift.js +101 -285
- package/lib/module/Adshift.js.map +1 -1
- package/lib/module/NativeAdShiftReactNativePlugin.js +2 -12
- package/lib/module/NativeAdShiftReactNativePlugin.js.map +1 -1
- package/lib/module/index.js +2 -47
- package/lib/module/index.js.map +1 -1
- package/lib/module/jest/index.js +7 -19
- package/lib/module/jest/index.js.map +1 -1
- package/lib/module/nativeSdkVersions.js +4 -6
- package/lib/module/nativeSdkVersions.js.map +1 -1
- package/lib/module/types/AdshiftAdRevenue.js +0 -24
- package/lib/module/types/AdshiftAdRevenue.js.map +1 -1
- package/lib/module/types/AdshiftConfig.js +10 -23
- package/lib/module/types/AdshiftConfig.js.map +1 -1
- package/lib/module/types/AdshiftConsent.js +9 -45
- package/lib/module/types/AdshiftConsent.js.map +1 -1
- package/lib/module/types/AdshiftConsentSnapshot.js +5 -24
- package/lib/module/types/AdshiftConsentSnapshot.js.map +1 -1
- package/lib/module/types/AdshiftDeepLink.js +49 -32
- package/lib/module/types/AdshiftDeepLink.js.map +1 -1
- package/lib/module/types/AdshiftError.js +7 -28
- package/lib/module/types/AdshiftError.js.map +1 -1
- package/lib/module/types/AdshiftEventParam.js +4 -38
- package/lib/module/types/AdshiftEventParam.js.map +1 -1
- package/lib/module/types/AdshiftEventType.js +1 -39
- package/lib/module/types/AdshiftEventType.js.map +1 -1
- package/lib/module/types/AdshiftThirdPartySharing.js +7 -38
- package/lib/module/types/AdshiftThirdPartySharing.js.map +1 -1
- package/lib/module/types/index.js +2 -2
- package/lib/module/types/index.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/typescript/commonjs/src/Adshift.d.ts +68 -184
- package/lib/typescript/commonjs/src/Adshift.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/NativeAdShiftReactNativePlugin.d.ts +18 -35
- package/lib/typescript/commonjs/src/NativeAdShiftReactNativePlugin.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/index.d.ts +2 -34
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/jest/index.d.ts +9 -21
- package/lib/typescript/commonjs/src/jest/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/nativeSdkVersions.d.ts +4 -6
- package/lib/typescript/commonjs/src/nativeSdkVersions.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/AdshiftAdRevenue.d.ts +0 -24
- package/lib/typescript/commonjs/src/types/AdshiftAdRevenue.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/AdshiftConfig.d.ts +35 -39
- package/lib/typescript/commonjs/src/types/AdshiftConfig.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/AdshiftConsent.d.ts +9 -49
- package/lib/typescript/commonjs/src/types/AdshiftConsent.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/AdshiftConsentSnapshot.d.ts +10 -28
- package/lib/typescript/commonjs/src/types/AdshiftConsentSnapshot.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/AdshiftDeepLink.d.ts +55 -39
- package/lib/typescript/commonjs/src/types/AdshiftDeepLink.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/AdshiftError.d.ts +7 -26
- package/lib/typescript/commonjs/src/types/AdshiftError.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/AdshiftEventParam.d.ts +3 -19
- package/lib/typescript/commonjs/src/types/AdshiftEventParam.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/AdshiftEventType.d.ts +1 -23
- package/lib/typescript/commonjs/src/types/AdshiftEventType.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/AdshiftThirdPartySharing.d.ts +7 -38
- package/lib/typescript/commonjs/src/types/AdshiftThirdPartySharing.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/index.d.ts +3 -3
- package/lib/typescript/commonjs/src/types/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/version.d.ts +1 -1
- package/lib/typescript/module/src/Adshift.d.ts +68 -184
- package/lib/typescript/module/src/Adshift.d.ts.map +1 -1
- package/lib/typescript/module/src/NativeAdShiftReactNativePlugin.d.ts +18 -35
- package/lib/typescript/module/src/NativeAdShiftReactNativePlugin.d.ts.map +1 -1
- package/lib/typescript/module/src/index.d.ts +2 -34
- package/lib/typescript/module/src/index.d.ts.map +1 -1
- package/lib/typescript/module/src/jest/index.d.ts +9 -21
- package/lib/typescript/module/src/jest/index.d.ts.map +1 -1
- package/lib/typescript/module/src/nativeSdkVersions.d.ts +4 -6
- package/lib/typescript/module/src/nativeSdkVersions.d.ts.map +1 -1
- package/lib/typescript/module/src/types/AdshiftAdRevenue.d.ts +0 -24
- package/lib/typescript/module/src/types/AdshiftAdRevenue.d.ts.map +1 -1
- package/lib/typescript/module/src/types/AdshiftConfig.d.ts +35 -39
- package/lib/typescript/module/src/types/AdshiftConfig.d.ts.map +1 -1
- package/lib/typescript/module/src/types/AdshiftConsent.d.ts +9 -49
- package/lib/typescript/module/src/types/AdshiftConsent.d.ts.map +1 -1
- package/lib/typescript/module/src/types/AdshiftConsentSnapshot.d.ts +10 -28
- package/lib/typescript/module/src/types/AdshiftConsentSnapshot.d.ts.map +1 -1
- package/lib/typescript/module/src/types/AdshiftDeepLink.d.ts +55 -39
- package/lib/typescript/module/src/types/AdshiftDeepLink.d.ts.map +1 -1
- package/lib/typescript/module/src/types/AdshiftError.d.ts +7 -26
- package/lib/typescript/module/src/types/AdshiftError.d.ts.map +1 -1
- package/lib/typescript/module/src/types/AdshiftEventParam.d.ts +3 -19
- package/lib/typescript/module/src/types/AdshiftEventParam.d.ts.map +1 -1
- package/lib/typescript/module/src/types/AdshiftEventType.d.ts +1 -23
- package/lib/typescript/module/src/types/AdshiftEventType.d.ts.map +1 -1
- package/lib/typescript/module/src/types/AdshiftThirdPartySharing.d.ts +7 -38
- package/lib/typescript/module/src/types/AdshiftThirdPartySharing.d.ts.map +1 -1
- package/lib/typescript/module/src/types/index.d.ts +3 -3
- package/lib/typescript/module/src/types/index.d.ts.map +1 -1
- package/lib/typescript/module/src/version.d.ts +1 -1
- package/package.json +11 -1
- package/src/Adshift.ts +118 -285
- package/src/NativeAdShiftReactNativePlugin.ts +19 -47
- package/src/index.tsx +7 -46
- package/src/jest/index.ts +11 -20
- package/src/nativeSdkVersions.ts +4 -6
- package/src/types/AdshiftAdRevenue.ts +0 -24
- package/src/types/AdshiftConfig.ts +48 -55
- package/src/types/AdshiftConsent.ts +9 -49
- package/src/types/AdshiftConsentSnapshot.ts +11 -38
- package/src/types/AdshiftDeepLink.ts +87 -39
- package/src/types/AdshiftError.ts +7 -26
- package/src/types/AdshiftEventParam.ts +4 -38
- package/src/types/AdshiftEventType.ts +1 -39
- package/src/types/AdshiftThirdPartySharing.ts +7 -38
- package/src/types/index.ts +9 -2
- package/src/version.ts +1 -1
- package/vendor/ios/AdshiftSDK.files.json +30 -0
- package/vendor/ios/AdshiftSDK.xcframework/Info.plist +44 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64/AdshiftSDK.framework/AdshiftSDK +0 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64/AdshiftSDK.framework/Headers/AdshiftSDK-Swift.h +315 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64/AdshiftSDK.framework/Info.plist +0 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64/AdshiftSDK.framework/Modules/AdshiftSDK.swiftmodule/arm64-apple-ios.abi.json +18729 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64/AdshiftSDK.framework/Modules/AdshiftSDK.swiftmodule/arm64-apple-ios.private.swiftinterface +414 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64/AdshiftSDK.framework/Modules/AdshiftSDK.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64/AdshiftSDK.framework/Modules/AdshiftSDK.swiftmodule/arm64-apple-ios.swiftinterface +414 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64/AdshiftSDK.framework/Modules/module.modulemap +4 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64/AdshiftSDK.framework/PrivacyInfo.xcprivacy +132 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64_x86_64-simulator/AdshiftSDK.framework/AdshiftSDK +0 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64_x86_64-simulator/AdshiftSDK.framework/Headers/AdshiftSDK-Swift.h +626 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64_x86_64-simulator/AdshiftSDK.framework/Info.plist +0 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64_x86_64-simulator/AdshiftSDK.framework/Modules/AdshiftSDK.swiftmodule/arm64-apple-ios-simulator.abi.json +18729 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64_x86_64-simulator/AdshiftSDK.framework/Modules/AdshiftSDK.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +414 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64_x86_64-simulator/AdshiftSDK.framework/Modules/AdshiftSDK.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64_x86_64-simulator/AdshiftSDK.framework/Modules/AdshiftSDK.swiftmodule/arm64-apple-ios-simulator.swiftinterface +414 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64_x86_64-simulator/AdshiftSDK.framework/Modules/AdshiftSDK.swiftmodule/x86_64-apple-ios-simulator.abi.json +18729 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64_x86_64-simulator/AdshiftSDK.framework/Modules/AdshiftSDK.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +414 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64_x86_64-simulator/AdshiftSDK.framework/Modules/AdshiftSDK.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64_x86_64-simulator/AdshiftSDK.framework/Modules/AdshiftSDK.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +414 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64_x86_64-simulator/AdshiftSDK.framework/Modules/module.modulemap +4 -0
- package/vendor/ios/AdshiftSDK.xcframework/ios-arm64_x86_64-simulator/AdshiftSDK.framework/PrivacyInfo.xcprivacy +132 -0
package/android/src/main/java/com/adshift/reactnativeplugin/AdShiftReactNativePluginModule.kt
CHANGED
|
@@ -30,26 +30,20 @@ import com.facebook.react.bridge.ReadableType
|
|
|
30
30
|
import com.facebook.react.bridge.WritableMap
|
|
31
31
|
import com.facebook.react.module.annotations.ReactModule
|
|
32
32
|
import java.lang.ref.WeakReference
|
|
33
|
-
import java.security.MessageDigest
|
|
34
33
|
import java.util.Collections
|
|
35
34
|
import java.util.WeakHashMap
|
|
36
35
|
import java.util.concurrent.atomic.AtomicBoolean
|
|
37
36
|
import org.json.JSONObject
|
|
38
37
|
|
|
39
38
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* Bridges the JavaScript contract (`NativeAdShiftReactNativePlugin.ts`) to the
|
|
43
|
-
* AdShift Android SDK. Deep link results are delivered exclusively through the
|
|
44
|
-
* `onDeepLink` event; the SDK listener is registered once per process and
|
|
45
|
-
* forwards to whichever module instance is current, so results keep flowing
|
|
46
|
-
* across JavaScript reloads.
|
|
39
|
+
* Deep link results reach JavaScript only through `onDeepLink`. The SDK listener is registered
|
|
40
|
+
* once per process and forwards to the current module instance, so it survives JavaScript reloads.
|
|
47
41
|
*/
|
|
48
42
|
@ReactModule(name = AdShiftReactNativePluginModule.NAME)
|
|
49
43
|
class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationContext) :
|
|
50
44
|
NativeAdShiftReactNativePluginSpec(reactContext), ActivityEventListener, LifecycleEventListener {
|
|
51
45
|
|
|
52
|
-
/**
|
|
46
|
+
/** Must match `AdshiftErrorCode` in JavaScript. */
|
|
53
47
|
private object ErrorCode {
|
|
54
48
|
const val NOT_INITIALIZED = "NOT_INITIALIZED"
|
|
55
49
|
const val NOT_STARTED = "NOT_STARTED"
|
|
@@ -60,35 +54,31 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
60
54
|
const val UNKNOWN = "UNKNOWN"
|
|
61
55
|
}
|
|
62
56
|
|
|
63
|
-
/**
|
|
57
|
+
/** Codes `AdShiftRequestListener.onError` passes. */
|
|
64
58
|
private object SdkErrorCode {
|
|
65
59
|
const val STOP_TRACKING = 12
|
|
66
60
|
const val NO_DEV_KEY = 41
|
|
67
61
|
const val QUEUE_FULL = 51
|
|
68
62
|
}
|
|
69
63
|
|
|
70
|
-
/** An Intent received before `initialize`, kept until the SDK can process it. */
|
|
71
|
-
private class StoredIntent(val intent: Intent, val fromLaunchPath: Boolean)
|
|
72
|
-
|
|
73
64
|
companion object {
|
|
74
65
|
const val NAME = "AdShiftReactNativePlugin"
|
|
75
66
|
|
|
76
67
|
private const val TAG = "AdShiftRN"
|
|
77
68
|
private const val AUTO_FORWARD_DEDUP_WINDOW_MS = 2_000L
|
|
78
|
-
private const val META_APP_LINK_EXTRA = "al_applink_data"
|
|
79
69
|
|
|
80
|
-
/**
|
|
70
|
+
/** Same value as on iOS. */
|
|
71
|
+
private const val WRAPPER = "react_native"
|
|
72
|
+
|
|
81
73
|
private const val PENDING_DEEP_LINK_LIMIT = 20
|
|
82
74
|
|
|
83
|
-
/** How deep to look for links inside JSON carried by Intent extras. */
|
|
84
75
|
private const val EXTRAS_URL_SEARCH_DEPTH = 3
|
|
85
76
|
|
|
86
77
|
private const val LAUNCH_URL_MEMORY_LIMIT = 20
|
|
87
78
|
|
|
88
|
-
/** How long `start` waits for the SDK listener before answering optimistically. */
|
|
89
79
|
private const val START_VERDICT_TIMEOUT_MS = 5_000L
|
|
90
80
|
|
|
91
|
-
/**
|
|
81
|
+
/** Set from the required fields, so they are dropped from `additionalParameters`. */
|
|
92
82
|
private val RESERVED_AD_REVENUE_KEYS = setOf(
|
|
93
83
|
ASInAppEventParameterName.REVENUE,
|
|
94
84
|
ASInAppEventParameterName.CURRENCY,
|
|
@@ -96,7 +86,7 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
96
86
|
ASInAppEventParameterName.AD_REVENUE_NETWORK_NAME,
|
|
97
87
|
)
|
|
98
88
|
|
|
99
|
-
/**
|
|
89
|
+
/** One main-thread queue, so `start` and `stop` run in the order they were called. */
|
|
100
90
|
private val mainHandler = Handler(Looper.getMainLooper())
|
|
101
91
|
|
|
102
92
|
private val lock = Any()
|
|
@@ -104,34 +94,24 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
104
94
|
@Volatile private var currentModule: WeakReference<AdShiftReactNativePluginModule>? = null
|
|
105
95
|
@Volatile private var sdkInitialized = false
|
|
106
96
|
|
|
107
|
-
/** Set once the SDK is initialised *and* the `initialize` options have been applied. */
|
|
108
97
|
@Volatile private var readyForIntents = false
|
|
109
98
|
@Volatile private var deepLinkListenerRegistered = false
|
|
110
99
|
@Volatile private var autoHandleDeepLinks = true
|
|
111
100
|
@Volatile private var collectOaidApplied = false
|
|
112
101
|
|
|
113
102
|
// Guarded by [lock].
|
|
114
|
-
private var pendingIntent:
|
|
115
|
-
private var lastLaunchIntentFingerprint: String? = null
|
|
103
|
+
private var pendingIntent: Intent? = null
|
|
116
104
|
private val processedIntents: MutableSet<Intent> =
|
|
117
105
|
Collections.newSetFromMap(WeakHashMap<Intent, Boolean>())
|
|
118
106
|
private val autoForwardedUrls = HashMap<String, Long>()
|
|
119
107
|
|
|
120
|
-
/**
|
|
121
|
-
* URLs that opened this process, kept until it dies. Reloading JavaScript replays the
|
|
122
|
-
* launch URL, and that replay can arrive long after the two second window has closed.
|
|
123
|
-
* A new tap arrives as a new Intent, so it is unaffected.
|
|
124
|
-
*/
|
|
108
|
+
/** Kept until the process dies: a `fromLaunch` replay after a reload can come much later. */
|
|
125
109
|
private val launchForwardedUrls = LinkedHashSet<String>()
|
|
126
110
|
|
|
127
111
|
private val registeredPushPaths = HashSet<String>()
|
|
128
112
|
private val pendingDeepLinks = ArrayDeque<DeepLinkResult>()
|
|
129
113
|
|
|
130
|
-
/**
|
|
131
|
-
* Forwards an SDK deep link result to the current module instance, keeping it for the
|
|
132
|
-
* next one when JavaScript cannot receive it yet — a result is delivered once, and a
|
|
133
|
-
* reload must not consume it.
|
|
134
|
-
*/
|
|
114
|
+
/** Keeps a result until JavaScript can receive it: each result is reported only once. */
|
|
135
115
|
private fun dispatchDeepLink(result: DeepLinkResult) {
|
|
136
116
|
if (currentModule?.get()?.emitDeepLink(result) == true) return
|
|
137
117
|
synchronized(lock) {
|
|
@@ -159,15 +139,12 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
159
139
|
|
|
160
140
|
@Volatile private var invalidated = false
|
|
161
141
|
|
|
162
|
-
/**
|
|
163
|
-
* The emitter callback of the generated base class is not volatile, and deep links arrive on an
|
|
164
|
-
* SDK thread. This flag publishes the callback to that thread, so a result is buffered rather
|
|
165
|
-
* than read against a stale null and lost.
|
|
166
|
-
*/
|
|
142
|
+
/** Publishes the non-volatile emitter callback to the thread deep link results arrive on. */
|
|
167
143
|
@Volatile private var emitterAttached = false
|
|
168
144
|
|
|
169
145
|
init {
|
|
170
146
|
synchronized(lock) { currentModule = WeakReference(this) }
|
|
147
|
+
ActivityIntents.register(reactContext)
|
|
171
148
|
reactContext.addActivityEventListener(this)
|
|
172
149
|
reactContext.addLifecycleEventListener(this)
|
|
173
150
|
}
|
|
@@ -184,8 +161,6 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
184
161
|
super.invalidate()
|
|
185
162
|
}
|
|
186
163
|
|
|
187
|
-
// ============ Lifecycle ============
|
|
188
|
-
|
|
189
164
|
override fun initialize(config: ReadableMap) {
|
|
190
165
|
val apiKey = optString(config, "apiKey")
|
|
191
166
|
if (apiKey.isNullOrBlank()) {
|
|
@@ -214,6 +189,12 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
214
189
|
logFailure("initialize", e)
|
|
215
190
|
return
|
|
216
191
|
}
|
|
192
|
+
// On its own: a failure here must not keep links and options from the SDK.
|
|
193
|
+
try {
|
|
194
|
+
AdShiftLib.setWrapper(WRAPPER)
|
|
195
|
+
} catch (e: Exception) {
|
|
196
|
+
logFailure("setWrapper", e)
|
|
197
|
+
}
|
|
217
198
|
|
|
218
199
|
applyOptions(config)
|
|
219
200
|
autoHandleDeepLinks = optBoolean(config, "autoHandleDeepLinks") ?: true
|
|
@@ -222,11 +203,10 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
222
203
|
|
|
223
204
|
val stored = synchronized(lock) { pendingIntent.also { pendingIntent = null } }
|
|
224
205
|
if (!autoHandleDeepLinks) return
|
|
225
|
-
stored?.let
|
|
226
|
-
|
|
206
|
+
stored?.let(::processIntent)
|
|
207
|
+
processCurrentActivityIntent()
|
|
227
208
|
}
|
|
228
209
|
|
|
229
|
-
/** Applies the optional `initialize` keys; absent keys leave SDK defaults untouched. */
|
|
230
210
|
private fun applyOptions(config: ReadableMap) {
|
|
231
211
|
try {
|
|
232
212
|
optBoolean(config, "isDebug")?.let { AdShiftLib.setDebugLog(it) }
|
|
@@ -238,6 +218,7 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
238
218
|
}
|
|
239
219
|
}
|
|
240
220
|
optArray(config, "brandedDomains")?.let { AdShiftLib.setBrandedDomains(stringList(it)) }
|
|
221
|
+
optBoolean(config, "testMode")?.let { AdShiftLib.setTestMode(it) }
|
|
241
222
|
optString(config, "metaAppId")?.takeIf { it.isNotBlank() }?.let { AdShiftLib.setMetaAppId(it) }
|
|
242
223
|
optArray(config, "pushDeepLinkPaths")?.let { paths ->
|
|
243
224
|
for (i in 0 until paths.size()) {
|
|
@@ -252,10 +233,8 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
252
233
|
}
|
|
253
234
|
|
|
254
235
|
/**
|
|
255
|
-
*
|
|
256
|
-
*
|
|
257
|
-
* the main thread, and [START_VERDICT_TIMEOUT_MS] bounds the promise in case the answer comes
|
|
258
|
-
* later than the call.
|
|
236
|
+
* Resolves with the SDK's answer, so an opted-out device or a rejected key is reported. With no
|
|
237
|
+
* answer within [START_VERDICT_TIMEOUT_MS], it resolves as started with `pending`.
|
|
259
238
|
*/
|
|
260
239
|
override fun start(promise: Promise) {
|
|
261
240
|
if (!sdkInitialized) {
|
|
@@ -308,11 +287,6 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
308
287
|
}
|
|
309
288
|
}
|
|
310
289
|
|
|
311
|
-
/**
|
|
312
|
-
* The listener answers only once the SDK holds a usable key, so a success
|
|
313
|
-
* callback is itself the verdict. Silence within the window below means the
|
|
314
|
-
* answer is still outstanding, which is what `pending` reports.
|
|
315
|
-
*/
|
|
316
290
|
private fun startSucceeded(apiKeyValidationStatus: String): WritableMap =
|
|
317
291
|
Arguments.createMap().apply {
|
|
318
292
|
putBoolean("success", true)
|
|
@@ -340,8 +314,6 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
340
314
|
}
|
|
341
315
|
}
|
|
342
316
|
|
|
343
|
-
// ============ Configuration ============
|
|
344
|
-
|
|
345
317
|
override fun setCustomerUserId(userId: String) {
|
|
346
318
|
try {
|
|
347
319
|
AdShiftLib.setCustomerUserId(userId)
|
|
@@ -390,8 +362,6 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
390
362
|
}
|
|
391
363
|
}
|
|
392
364
|
|
|
393
|
-
// ============ Consent ============
|
|
394
|
-
|
|
395
365
|
override fun setConsentData(consent: ReadableMap) {
|
|
396
366
|
try {
|
|
397
367
|
val subjectToGdpr = optBoolean(consent, "isUserSubjectToGDPR") ?: false
|
|
@@ -427,12 +397,8 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
427
397
|
}
|
|
428
398
|
|
|
429
399
|
/**
|
|
430
|
-
* A missing or non-boolean `optOut` is dropped
|
|
431
|
-
*
|
|
432
|
-
* This axis has the opposite polarity to consent: `false` is the app
|
|
433
|
-
* declaring that sharing is allowed, not the absence of an answer. Guessing
|
|
434
|
-
* either way from a malformed call would record a declaration the user never
|
|
435
|
-
* made, and the wrong guess cannot be undone for events already sent.
|
|
400
|
+
* A missing or non-boolean `optOut` is dropped, not defaulted: either default would declare
|
|
401
|
+
* something the app never said.
|
|
436
402
|
*/
|
|
437
403
|
override fun setThirdPartySharing(sharing: ReadableMap) {
|
|
438
404
|
try {
|
|
@@ -479,10 +445,8 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
479
445
|
}
|
|
480
446
|
|
|
481
447
|
/**
|
|
482
|
-
*
|
|
483
|
-
*
|
|
484
|
-
* Storage and data usage both have to be allowed. Under GDPR an undecided
|
|
485
|
-
* flag counts as a refusal; outside it, only an explicit denial does.
|
|
448
|
+
* The Android rule, which differs from the iOS one: under GDPR an undecided flag counts as a
|
|
449
|
+
* refusal; outside it, only an explicit denial does.
|
|
486
450
|
*/
|
|
487
451
|
private fun adIdentifiersAllowed(snapshot: ConsentSnapshot): Boolean {
|
|
488
452
|
val storage = snapshot.adStorageEnabled
|
|
@@ -494,8 +458,6 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
494
458
|
}
|
|
495
459
|
}
|
|
496
460
|
|
|
497
|
-
// ============ Event Tracking ============
|
|
498
|
-
|
|
499
461
|
override fun trackEvent(eventName: String, values: ReadableMap?, promise: Promise) {
|
|
500
462
|
try {
|
|
501
463
|
AdShiftLib.trackEvent(
|
|
@@ -582,8 +544,6 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
582
544
|
}
|
|
583
545
|
}
|
|
584
546
|
|
|
585
|
-
// ============ Identity ============
|
|
586
|
-
|
|
587
547
|
override fun getAdShiftDeviceId(promise: Promise) {
|
|
588
548
|
try {
|
|
589
549
|
promise.resolve(AdShiftLib.getAdShiftDeviceId())
|
|
@@ -592,8 +552,6 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
592
552
|
}
|
|
593
553
|
}
|
|
594
554
|
|
|
595
|
-
// ============ Deep Links ============
|
|
596
|
-
|
|
597
555
|
override fun handleDeepLink(url: String, fromLaunch: Boolean, promise: Promise) {
|
|
598
556
|
val uri = Uri.parse(url)
|
|
599
557
|
val scheme = uri.scheme
|
|
@@ -607,6 +565,21 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
607
565
|
return
|
|
608
566
|
}
|
|
609
567
|
|
|
568
|
+
// On the main thread: React Native emits `url` before this module sees the new Intent.
|
|
569
|
+
onMainThread {
|
|
570
|
+
try {
|
|
571
|
+
forwardLink(url, uri, fromLaunch, promise)
|
|
572
|
+
} catch (e: Exception) {
|
|
573
|
+
rejectWith(promise, e)
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
private fun onMainThread(block: () -> Unit) {
|
|
579
|
+
if (Looper.myLooper() == Looper.getMainLooper()) block() else mainHandler.post(block)
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
private fun forwardLink(url: String, uri: Uri, fromLaunch: Boolean, promise: Promise) {
|
|
610
583
|
val now = System.currentTimeMillis()
|
|
611
584
|
val alreadyForwarded = synchronized(lock) {
|
|
612
585
|
pruneAutoForwarded(now)
|
|
@@ -618,18 +591,39 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
618
591
|
promise.resolve(null)
|
|
619
592
|
return
|
|
620
593
|
}
|
|
594
|
+
|
|
595
|
+
val launch = launchCreationFor(url)
|
|
596
|
+
val launchKey = LaunchRecords.urlKey(url)
|
|
597
|
+
if (launch != null && launch.mayBeRestored && LaunchRecords.contains(launch, launchKey)) {
|
|
598
|
+
Log.d(TAG, "handleDeepLink: launch link of a re-created activity, already forwarded")
|
|
599
|
+
promise.resolve(null)
|
|
600
|
+
return
|
|
601
|
+
}
|
|
621
602
|
if (fromLaunch) {
|
|
622
603
|
synchronized(lock) { rememberLaunchUrls(setOf(url)) }
|
|
623
604
|
}
|
|
624
605
|
|
|
625
606
|
try {
|
|
626
607
|
AdShiftLib.handleAppLinkIntent(Intent(Intent.ACTION_VIEW, uri))
|
|
608
|
+
launch?.let { LaunchRecords.add(it, launchKey) }
|
|
627
609
|
promise.resolve(null)
|
|
628
610
|
} catch (e: Exception) {
|
|
629
611
|
rejectWith(promise, e)
|
|
630
612
|
}
|
|
631
613
|
}
|
|
632
614
|
|
|
615
|
+
private fun launchCreationFor(url: String): ActivityIntents.Creation? {
|
|
616
|
+
val activity = reactContext.currentActivity ?: return null
|
|
617
|
+
ActivityIntents.adopt(activity)
|
|
618
|
+
if (ActivityIntents.hasReceivedNewIntent(activity)) return null
|
|
619
|
+
val intent = activity.intent ?: return null
|
|
620
|
+
val creation = ActivityIntents.creationOf(intent) ?: return null
|
|
621
|
+
return creation.takeIf { intent.dataString == url }
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
/** The clipboard lookup exists on iOS only. */
|
|
625
|
+
override fun handlePastedDeepLink(url: String?) = Unit
|
|
626
|
+
|
|
633
627
|
override fun addPushNotificationDeepLinkPath(path: ReadableArray) {
|
|
634
628
|
val keys = stringList(path)
|
|
635
629
|
if (keys.isEmpty()) {
|
|
@@ -639,7 +633,6 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
639
633
|
registerPushPath(keys)
|
|
640
634
|
}
|
|
641
635
|
|
|
642
|
-
/** Registers a push payload key path once per process. */
|
|
643
636
|
private fun registerPushPath(path: List<String>) {
|
|
644
637
|
val id = path.joinToString("\u001F")
|
|
645
638
|
synchronized(lock) {
|
|
@@ -661,9 +654,7 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
661
654
|
}
|
|
662
655
|
}
|
|
663
656
|
|
|
664
|
-
/**
|
|
665
|
-
* Returns false when JavaScript could not receive the result, so the caller can keep it.
|
|
666
|
-
*/
|
|
657
|
+
/** Returns false when JavaScript could not receive the result, so the caller can keep it. */
|
|
667
658
|
private fun emitDeepLink(result: DeepLinkResult): Boolean {
|
|
668
659
|
if (invalidated || !emitterAttached || mEventEmitterCallback == null) return false
|
|
669
660
|
return try {
|
|
@@ -681,7 +672,6 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
681
672
|
flushPendingDeepLinks()
|
|
682
673
|
}
|
|
683
674
|
|
|
684
|
-
/** Delivers results that arrived while no JavaScript listener was reachable, oldest first. */
|
|
685
675
|
private fun flushPendingDeepLinks() {
|
|
686
676
|
val pending = synchronized(lock) {
|
|
687
677
|
if (pendingDeepLinks.isEmpty()) return
|
|
@@ -694,16 +684,16 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
694
684
|
}
|
|
695
685
|
}
|
|
696
686
|
|
|
697
|
-
|
|
687
|
+
private fun processCurrentActivityIntent() {
|
|
688
|
+
val activity = reactContext.currentActivity ?: return
|
|
689
|
+
ActivityIntents.adopt(activity)
|
|
690
|
+
processIntent(activity.intent)
|
|
691
|
+
}
|
|
698
692
|
|
|
699
|
-
|
|
700
|
-
* Forwards an Intent to the SDK once. Intents that arrive before `initialize`
|
|
701
|
-
* are kept (newest wins) and processed when the SDK becomes available.
|
|
702
|
-
*/
|
|
703
|
-
private fun processIntent(intent: Intent?, fromLaunchPath: Boolean) {
|
|
693
|
+
private fun processIntent(intent: Intent?) {
|
|
704
694
|
if (intent == null) return
|
|
705
695
|
if (!readyForIntents) {
|
|
706
|
-
synchronized(lock) { pendingIntent =
|
|
696
|
+
synchronized(lock) { pendingIntent = intent }
|
|
707
697
|
return
|
|
708
698
|
}
|
|
709
699
|
if (!autoHandleDeepLinks) return
|
|
@@ -716,17 +706,14 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
716
706
|
Log.d(TAG, "intent skipped (duplicate)")
|
|
717
707
|
return
|
|
718
708
|
}
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
Log.d(TAG, "intent skipped (launch)")
|
|
728
|
-
return
|
|
729
|
-
}
|
|
709
|
+
// The key from creation: another library may have added extras to the Intent since.
|
|
710
|
+
val creation = ActivityIntents.creationOf(intent)
|
|
711
|
+
val key = creation?.intentKey
|
|
712
|
+
if (creation != null && key != null && creation.mayBeRestored &&
|
|
713
|
+
LaunchRecords.contains(creation, key)
|
|
714
|
+
) {
|
|
715
|
+
Log.d(TAG, "intent skipped (recreated)")
|
|
716
|
+
return
|
|
730
717
|
}
|
|
731
718
|
|
|
732
719
|
try {
|
|
@@ -735,6 +722,7 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
735
722
|
} catch (e: Exception) {
|
|
736
723
|
Log.d(TAG, "intent processing failed: ${e.javaClass.simpleName}")
|
|
737
724
|
}
|
|
725
|
+
if (creation != null && key != null) LaunchRecords.add(creation, key)
|
|
738
726
|
|
|
739
727
|
val forwarded = linkedSetOf<String>()
|
|
740
728
|
intent.dataString?.let { forwarded += it }
|
|
@@ -750,7 +738,7 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
750
738
|
Log.d(TAG, "intent processed")
|
|
751
739
|
}
|
|
752
740
|
|
|
753
|
-
/**
|
|
741
|
+
/** Must be called with [lock] held. */
|
|
754
742
|
private fun rememberLaunchUrls(urls: Set<String>) {
|
|
755
743
|
for (url in urls) {
|
|
756
744
|
launchForwardedUrls.remove(url)
|
|
@@ -763,51 +751,7 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
763
751
|
}
|
|
764
752
|
}
|
|
765
753
|
|
|
766
|
-
/**
|
|
767
|
-
* Identifies a single Intent delivery, so an Activity recreated with the same Intent is
|
|
768
|
-
* recognised while a genuinely new delivery is not. Covers the data URI, the Meta App Link
|
|
769
|
-
* payload and the extras, because notification taps carry no data URI and are told apart
|
|
770
|
-
* only by their extras.
|
|
771
|
-
*/
|
|
772
|
-
private fun fingerprintOf(intent: Intent): String {
|
|
773
|
-
val data = intent.dataString ?: ""
|
|
774
|
-
val appLink = runCatching {
|
|
775
|
-
@Suppress("DEPRECATION")
|
|
776
|
-
when (val extra = intent.extras?.get(META_APP_LINK_EXTRA)) {
|
|
777
|
-
is String -> extra
|
|
778
|
-
is android.os.Bundle -> extra.getString("target_url") ?: ""
|
|
779
|
-
else -> ""
|
|
780
|
-
}
|
|
781
|
-
}.getOrDefault("")
|
|
782
|
-
val payload = "$data|$appLink|${extrasFingerprint(intent)}"
|
|
783
|
-
val digest = MessageDigest.getInstance("SHA-256").digest(payload.toByteArray())
|
|
784
|
-
return digest.joinToString("") { "%02x".format(it) }
|
|
785
|
-
}
|
|
786
|
-
|
|
787
|
-
/**
|
|
788
|
-
* Extras rendered in a stable order. Only values whose textual form survives re-parcelling
|
|
789
|
-
* are included, so the digest stays equal for the same delivery.
|
|
790
|
-
*/
|
|
791
|
-
private fun extrasFingerprint(intent: Intent): String = runCatching {
|
|
792
|
-
val extras = intent.extras ?: return@runCatching ""
|
|
793
|
-
extras.keySet()
|
|
794
|
-
.filter { it != META_APP_LINK_EXTRA }
|
|
795
|
-
.sorted()
|
|
796
|
-
.mapNotNull { key ->
|
|
797
|
-
@Suppress("DEPRECATION")
|
|
798
|
-
when (val value = extras.get(key)) {
|
|
799
|
-
is CharSequence, is Boolean, is Int, is Long, is Float, is Double -> "$key=$value"
|
|
800
|
-
else -> null
|
|
801
|
-
}
|
|
802
|
-
}
|
|
803
|
-
.joinToString("&")
|
|
804
|
-
}.getOrDefault("")
|
|
805
|
-
|
|
806
|
-
/**
|
|
807
|
-
* URLs carried by the extras, including those nested in JSON payloads. A tapped notification
|
|
808
|
-
* holds its link there, so recording them lets `handleDeepLink` recognise a link the SDK has
|
|
809
|
-
* already received with the Intent.
|
|
810
|
-
*/
|
|
754
|
+
/** A tapped notification carries its link in the extras; `handleDeepLink` must recognise it. */
|
|
811
755
|
private fun urlsIn(extras: Bundle?): Set<String> {
|
|
812
756
|
if (extras == null) return emptySet()
|
|
813
757
|
val found = linkedSetOf<String>()
|
|
@@ -844,12 +788,11 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
844
788
|
}
|
|
845
789
|
}
|
|
846
790
|
|
|
847
|
-
// ============ ActivityEventListener / LifecycleEventListener ============
|
|
848
|
-
|
|
849
791
|
override fun onNewIntent(intent: Intent) {
|
|
850
792
|
if (invalidated) return
|
|
851
793
|
try {
|
|
852
|
-
|
|
794
|
+
reactContext.currentActivity?.let(ActivityIntents::noteNewIntent)
|
|
795
|
+
processIntent(intent)
|
|
853
796
|
} catch (e: Exception) {
|
|
854
797
|
Log.d(TAG, "onNewIntent failed: ${e.javaClass.simpleName}")
|
|
855
798
|
}
|
|
@@ -860,7 +803,7 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
860
803
|
override fun onHostResume() {
|
|
861
804
|
if (invalidated) return
|
|
862
805
|
try {
|
|
863
|
-
|
|
806
|
+
processCurrentActivityIntent()
|
|
864
807
|
} catch (e: Exception) {
|
|
865
808
|
Log.d(TAG, "onHostResume failed: ${e.javaClass.simpleName}")
|
|
866
809
|
}
|
|
@@ -870,8 +813,6 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
870
813
|
|
|
871
814
|
override fun onHostDestroy() = Unit
|
|
872
815
|
|
|
873
|
-
// ============ Error model ============
|
|
874
|
-
|
|
875
816
|
private fun rejectWith(promise: Promise, code: String, message: String, throwable: Throwable?, nativeCode: Any?) {
|
|
876
817
|
val userInfo = Arguments.createMap()
|
|
877
818
|
when (nativeCode) {
|
|
@@ -896,13 +837,13 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
896
837
|
}
|
|
897
838
|
}
|
|
898
839
|
|
|
899
|
-
// ============ Mappers ============
|
|
900
|
-
|
|
901
840
|
private fun toWritableMap(result: DeepLinkResult): WritableMap = Arguments.createMap().apply {
|
|
902
841
|
val query = result.queryParams ?: emptyMap()
|
|
903
842
|
|
|
904
843
|
result.uri?.toString()?.let { putString("deepLink", it) }
|
|
905
|
-
query["deep_link_value"]?.let { putString("deepLinkValue", it) }
|
|
844
|
+
(result.deepLinkValue ?: query["deep_link_value"])?.let { putString("deepLinkValue", it) }
|
|
845
|
+
result.source?.let { putString("source", it.name.lowercase()) }
|
|
846
|
+
result.clickId?.let { putString("clickId", it) }
|
|
906
847
|
result.sub1?.let { putString("deepLinkSub1", it) }
|
|
907
848
|
result.sub2?.let { putString("deepLinkSub2", it) }
|
|
908
849
|
result.sub3?.let { putString("deepLinkSub3", it) }
|
|
@@ -931,8 +872,6 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
931
872
|
result.error?.let { putString("errorMessage", it.name.lowercase().replace('_', ' ')) }
|
|
932
873
|
}
|
|
933
874
|
|
|
934
|
-
// ============ ReadableMap helpers ============
|
|
935
|
-
|
|
936
875
|
private fun optString(map: ReadableMap, key: String): String? =
|
|
937
876
|
if (map.hasKey(key) && map.getType(key) == ReadableType.String) map.getString(key) else null
|
|
938
877
|
|
|
@@ -969,8 +908,6 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
969
908
|
return out
|
|
970
909
|
}
|
|
971
910
|
|
|
972
|
-
// ============ Logging ============
|
|
973
|
-
|
|
974
911
|
private fun logFailure(method: String, e: Exception) {
|
|
975
912
|
Log.e(TAG, "$method failed: ${e.javaClass.simpleName}: ${e.message}")
|
|
976
913
|
}
|
|
@@ -23,12 +23,6 @@ import org.junit.runner.RunWith
|
|
|
23
23
|
import org.robolectric.RobolectricTestRunner
|
|
24
24
|
import org.robolectric.annotation.Config
|
|
25
25
|
|
|
26
|
-
/**
|
|
27
|
-
* The snapshot answers whether consent still lets the SDK use the advertising id.
|
|
28
|
-
* The rule differs from the one iOS applies, so it is settled here rather than in
|
|
29
|
-
* JavaScript: under GDPR an undecided flag counts as a refusal, and outside it
|
|
30
|
-
* only an explicit denial does.
|
|
31
|
-
*/
|
|
32
26
|
@RunWith(RobolectricTestRunner::class)
|
|
33
27
|
@Config(sdk = [35])
|
|
34
28
|
class ConsentSnapshotTest {
|
|
@@ -66,7 +60,6 @@ class ConsentSnapshotTest {
|
|
|
66
60
|
assertTrue("allowed", allowed(gdprApplies = 1, storage = true, dataUsage = true))
|
|
67
61
|
}
|
|
68
62
|
|
|
69
|
-
/** The case a single "any flag granted" rule would get wrong. */
|
|
70
63
|
@Test
|
|
71
64
|
fun `withholds the advertising id when only one flag is granted under gdpr`() {
|
|
72
65
|
assertFalse("allowed", allowed(gdprApplies = 1, storage = true, dataUsage = false))
|
|
@@ -103,12 +96,6 @@ class ConsentSnapshotTest {
|
|
|
103
96
|
assertFalse("cmpDetected", snapshot.getBoolean("cmpDetected"))
|
|
104
97
|
}
|
|
105
98
|
|
|
106
|
-
/**
|
|
107
|
-
* A CMP that has run but has not been answered is indistinguishable from no
|
|
108
|
-
* CMP at all by every other field here, and the two are fixed by opposite
|
|
109
|
-
* actions. Dropping this field on the way through the bridge would leave
|
|
110
|
-
* JavaScript unable to tell them apart.
|
|
111
|
-
*/
|
|
112
99
|
@Test
|
|
113
100
|
fun `forwards that a cmp has run even with nothing decided`() {
|
|
114
101
|
val snapshot = refreshConsent(
|
|
@@ -133,13 +120,6 @@ class ConsentSnapshotTest {
|
|
|
133
120
|
verify { AdShiftLib.clearThirdPartySharing() }
|
|
134
121
|
}
|
|
135
122
|
|
|
136
|
-
/**
|
|
137
|
-
* Nothing said on this axis means sharing is allowed, which is the opposite of
|
|
138
|
-
* how consent reads an absent answer. So a malformed call must not be
|
|
139
|
-
* defaulted: `allowed()` would record a declaration the app never made,
|
|
140
|
-
* `optedOut()` would withhold data the user never asked to withhold, and
|
|
141
|
-
* neither can be recalled for events already sent.
|
|
142
|
-
*/
|
|
143
123
|
@Test
|
|
144
124
|
fun `refuses to guess a malformed sharing answer`() {
|
|
145
125
|
every { AdShiftLib.setThirdPartySharing(any()) } just Runs
|
|
@@ -5,6 +5,7 @@ import android.os.Bundle
|
|
|
5
5
|
import com.adshift.sdk.core.AdShiftLib
|
|
6
6
|
import com.adshift.sdk.core.deeplink.DeepLinkListener
|
|
7
7
|
import com.adshift.sdk.core.deeplink.DeepLinkResult
|
|
8
|
+
import com.adshift.sdk.core.deeplink.DeepLinkSource
|
|
8
9
|
import com.adshift.sdk.core.deeplink.DeepLinkStatus
|
|
9
10
|
import com.facebook.react.bridge.Arguments
|
|
10
11
|
import com.facebook.react.bridge.CxxCallbackImpl
|
|
@@ -25,15 +26,12 @@ import org.junit.runner.RunWith
|
|
|
25
26
|
import org.robolectric.RobolectricTestRunner
|
|
26
27
|
import org.robolectric.annotation.Config
|
|
27
28
|
|
|
28
|
-
/**
|
|
29
|
-
* Every deep link result reaches JavaScript exactly once: results that arrive while no listener
|
|
30
|
-
* is reachable wait for the next one, in the order the SDK produced them.
|
|
31
|
-
*/
|
|
32
29
|
@RunWith(RobolectricTestRunner::class)
|
|
33
30
|
@Config(sdk = [35])
|
|
34
31
|
class DeepLinkDeliveryTest {
|
|
35
32
|
|
|
36
33
|
private val emitted = mutableListOf<String?>()
|
|
34
|
+
private val emittedPayloads = mutableListOf<ReadableMap>()
|
|
37
35
|
|
|
38
36
|
private lateinit var listener: DeepLinkListener
|
|
39
37
|
private lateinit var context: TestReactContext
|
|
@@ -112,20 +110,55 @@ class DeepLinkDeliveryTest {
|
|
|
112
110
|
assertEquals("results still waiting", 0, ModuleState.pendingDeepLinkCount())
|
|
113
111
|
}
|
|
114
112
|
|
|
113
|
+
@Test
|
|
114
|
+
fun `states the value, the source and the click of a result`() {
|
|
115
|
+
attachEventEmitter(module)
|
|
116
|
+
|
|
117
|
+
listener.onDeepLinking(
|
|
118
|
+
DeepLinkResult(
|
|
119
|
+
uri = Uri.parse(link(1)),
|
|
120
|
+
queryParams = mapOf("deep_link_value" to "from_query"),
|
|
121
|
+
isDeferred = false,
|
|
122
|
+
status = DeepLinkStatus.FOUND,
|
|
123
|
+
deepLinkValue = "promo",
|
|
124
|
+
source = DeepLinkSource.APP_LINK,
|
|
125
|
+
clickId = "click-1",
|
|
126
|
+
)
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
val payload = emittedPayloads.single()
|
|
130
|
+
assertEquals("promo", payload.getString("deepLinkValue"))
|
|
131
|
+
assertEquals("app_link", payload.getString("source"))
|
|
132
|
+
assertEquals("click-1", payload.getString("clickId"))
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
@Test
|
|
136
|
+
fun `leaves out the source and the click when the SDK states none`() {
|
|
137
|
+
attachEventEmitter(module)
|
|
138
|
+
|
|
139
|
+
listener.onDeepLinking(deepLinkResult(link(1)))
|
|
140
|
+
|
|
141
|
+
val payload = emittedPayloads.single()
|
|
142
|
+
assertEquals(false, payload.hasKey("source"))
|
|
143
|
+
assertEquals(false, payload.hasKey("clickId"))
|
|
144
|
+
}
|
|
145
|
+
|
|
115
146
|
/** A module created the way a JavaScript reload creates one. */
|
|
116
147
|
private fun reloadedModule() = AdShiftReactNativePluginModule(context.reactContext)
|
|
117
148
|
|
|
118
149
|
private fun attachEventEmitter(target: AdShiftReactNativePluginModule) {
|
|
119
150
|
val callback = mockk<CxxCallbackImpl>(relaxed = true)
|
|
120
|
-
every { callback.invoke(*anyVararg()) } answers {
|
|
151
|
+
every { callback.invoke(*anyVararg()) } answers {
|
|
152
|
+
payloadOf(args)?.let { emittedPayloads += it }
|
|
153
|
+
emitted += payloadOf(args)?.getString("deepLink")
|
|
154
|
+
}
|
|
121
155
|
ATTACH_EMITTER.invoke(target, callback)
|
|
122
156
|
}
|
|
123
157
|
|
|
124
|
-
private fun
|
|
158
|
+
private fun payloadOf(args: List<Any?>): ReadableMap? = args
|
|
125
159
|
.flatMap { if (it is Array<*>) it.asList() else listOf(it) }
|
|
126
160
|
.filterIsInstance<ReadableMap>()
|
|
127
161
|
.firstOrNull()
|
|
128
|
-
?.getString("deepLink")
|
|
129
162
|
|
|
130
163
|
private fun deepLinkResult(url: String) = DeepLinkResult(
|
|
131
164
|
uri = Uri.parse(url),
|