@adshift/react-native-plugin 3.0.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 +30 -17
- package/README.md +55 -47
- package/android/build.gradle +2 -3
- package/android/consumer-rules.pro +2 -21
- package/android/src/main/AndroidManifest.xml +1 -1
- package/android/src/main/java/com/adshift/reactnativeplugin/ActivityIntents.kt +307 -0
- package/android/src/main/java/com/adshift/reactnativeplugin/AdShiftReactNativePluginModule.kt +83 -157
- package/android/src/test/java/com/adshift/reactnativeplugin/ConsentSnapshotTest.kt +0 -20
- package/android/src/test/java/com/adshift/reactnativeplugin/DeepLinkDeliveryTest.kt +0 -4
- package/android/src/test/java/com/adshift/reactnativeplugin/InitializeOrderingTest.kt +37 -5
- package/android/src/test/java/com/adshift/reactnativeplugin/IntentLinkDedupTest.kt +0 -5
- package/android/src/test/java/com/adshift/reactnativeplugin/LaunchIntentForwardingTest.kt +7 -26
- package/android/src/test/java/com/adshift/reactnativeplugin/LaunchLinkRecordTest.kt +420 -0
- package/android/src/test/java/com/adshift/reactnativeplugin/ModuleTestSupport.kt +93 -34
- package/android/src/test/java/com/adshift/reactnativeplugin/StartVerdictTest.kt +0 -4
- package/ios/AdShiftReactNativePlugin.h +0 -12
- package/ios/AdShiftReactNativePlugin.mm +2 -14
- package/ios/AdShiftReactNativePluginHelper.swift +14 -73
- package/ios/Core/BridgeRules.swift +24 -29
- package/lib/commonjs/Adshift.js +78 -285
- 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.map +1 -1
- package/lib/commonjs/jest/index.js +4 -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 +3 -24
- 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 +3 -30
- 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/version.js +1 -1
- package/lib/module/Adshift.js +78 -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 +1 -46
- package/lib/module/index.js.map +1 -1
- package/lib/module/jest/index.js +4 -18
- 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 +3 -24
- 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 +3 -31
- 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/version.js +1 -1
- package/lib/typescript/commonjs/src/Adshift.d.ts +61 -185
- package/lib/typescript/commonjs/src/Adshift.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/NativeAdShiftReactNativePlugin.d.ts +10 -36
- package/lib/typescript/commonjs/src/NativeAdShiftReactNativePlugin.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/index.d.ts +0 -32
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/jest/index.d.ts +6 -20
- 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 +10 -37
- 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 +6 -34
- 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/version.d.ts +1 -1
- package/lib/typescript/module/src/Adshift.d.ts +61 -185
- package/lib/typescript/module/src/Adshift.d.ts.map +1 -1
- package/lib/typescript/module/src/NativeAdShiftReactNativePlugin.d.ts +10 -36
- package/lib/typescript/module/src/NativeAdShiftReactNativePlugin.d.ts.map +1 -1
- package/lib/typescript/module/src/index.d.ts +0 -32
- package/lib/typescript/module/src/index.d.ts.map +1 -1
- package/lib/typescript/module/src/jest/index.d.ts +6 -20
- 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 +10 -37
- 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 +6 -34
- 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/version.d.ts +1 -1
- package/package.json +11 -1
- package/src/Adshift.ts +82 -286
- package/src/NativeAdShiftReactNativePlugin.ts +10 -48
- package/src/index.tsx +1 -44
- package/src/jest/index.ts +6 -20
- package/src/nativeSdkVersions.ts +4 -6
- package/src/types/AdshiftAdRevenue.ts +0 -24
- package/src/types/AdshiftConfig.ts +11 -54
- package/src/types/AdshiftConsent.ts +9 -49
- package/src/types/AdshiftConsentSnapshot.ts +11 -38
- package/src/types/AdshiftDeepLink.ts +6 -34
- 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/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/RestoredIntents.kt +0 -64
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,16 +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) }
|
|
171
|
-
|
|
147
|
+
ActivityIntents.register(reactContext)
|
|
172
148
|
reactContext.addActivityEventListener(this)
|
|
173
149
|
reactContext.addLifecycleEventListener(this)
|
|
174
150
|
}
|
|
@@ -185,8 +161,6 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
185
161
|
super.invalidate()
|
|
186
162
|
}
|
|
187
163
|
|
|
188
|
-
// ============ Lifecycle ============
|
|
189
|
-
|
|
190
164
|
override fun initialize(config: ReadableMap) {
|
|
191
165
|
val apiKey = optString(config, "apiKey")
|
|
192
166
|
if (apiKey.isNullOrBlank()) {
|
|
@@ -215,6 +189,12 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
215
189
|
logFailure("initialize", e)
|
|
216
190
|
return
|
|
217
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
|
+
}
|
|
218
198
|
|
|
219
199
|
applyOptions(config)
|
|
220
200
|
autoHandleDeepLinks = optBoolean(config, "autoHandleDeepLinks") ?: true
|
|
@@ -223,11 +203,10 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
223
203
|
|
|
224
204
|
val stored = synchronized(lock) { pendingIntent.also { pendingIntent = null } }
|
|
225
205
|
if (!autoHandleDeepLinks) return
|
|
226
|
-
stored?.let
|
|
227
|
-
|
|
206
|
+
stored?.let(::processIntent)
|
|
207
|
+
processCurrentActivityIntent()
|
|
228
208
|
}
|
|
229
209
|
|
|
230
|
-
/** Applies the optional `initialize` keys; absent keys leave SDK defaults untouched. */
|
|
231
210
|
private fun applyOptions(config: ReadableMap) {
|
|
232
211
|
try {
|
|
233
212
|
optBoolean(config, "isDebug")?.let { AdShiftLib.setDebugLog(it) }
|
|
@@ -254,10 +233,8 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
254
233
|
}
|
|
255
234
|
|
|
256
235
|
/**
|
|
257
|
-
*
|
|
258
|
-
*
|
|
259
|
-
* the main thread, and [START_VERDICT_TIMEOUT_MS] bounds the promise in case the answer comes
|
|
260
|
-
* 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`.
|
|
261
238
|
*/
|
|
262
239
|
override fun start(promise: Promise) {
|
|
263
240
|
if (!sdkInitialized) {
|
|
@@ -310,11 +287,6 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
310
287
|
}
|
|
311
288
|
}
|
|
312
289
|
|
|
313
|
-
/**
|
|
314
|
-
* The listener answers only once the SDK holds a usable key, so a success
|
|
315
|
-
* callback is itself the verdict. Silence within the window below means the
|
|
316
|
-
* answer is still outstanding, which is what `pending` reports.
|
|
317
|
-
*/
|
|
318
290
|
private fun startSucceeded(apiKeyValidationStatus: String): WritableMap =
|
|
319
291
|
Arguments.createMap().apply {
|
|
320
292
|
putBoolean("success", true)
|
|
@@ -342,8 +314,6 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
342
314
|
}
|
|
343
315
|
}
|
|
344
316
|
|
|
345
|
-
// ============ Configuration ============
|
|
346
|
-
|
|
347
317
|
override fun setCustomerUserId(userId: String) {
|
|
348
318
|
try {
|
|
349
319
|
AdShiftLib.setCustomerUserId(userId)
|
|
@@ -392,8 +362,6 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
392
362
|
}
|
|
393
363
|
}
|
|
394
364
|
|
|
395
|
-
// ============ Consent ============
|
|
396
|
-
|
|
397
365
|
override fun setConsentData(consent: ReadableMap) {
|
|
398
366
|
try {
|
|
399
367
|
val subjectToGdpr = optBoolean(consent, "isUserSubjectToGDPR") ?: false
|
|
@@ -429,12 +397,8 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
429
397
|
}
|
|
430
398
|
|
|
431
399
|
/**
|
|
432
|
-
* A missing or non-boolean `optOut` is dropped
|
|
433
|
-
*
|
|
434
|
-
* This axis has the opposite polarity to consent: `false` is the app
|
|
435
|
-
* declaring that sharing is allowed, not the absence of an answer. Guessing
|
|
436
|
-
* either way from a malformed call would record a declaration the user never
|
|
437
|
-
* 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.
|
|
438
402
|
*/
|
|
439
403
|
override fun setThirdPartySharing(sharing: ReadableMap) {
|
|
440
404
|
try {
|
|
@@ -481,10 +445,8 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
481
445
|
}
|
|
482
446
|
|
|
483
447
|
/**
|
|
484
|
-
*
|
|
485
|
-
*
|
|
486
|
-
* Storage and data usage both have to be allowed. Under GDPR an undecided
|
|
487
|
-
* 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.
|
|
488
450
|
*/
|
|
489
451
|
private fun adIdentifiersAllowed(snapshot: ConsentSnapshot): Boolean {
|
|
490
452
|
val storage = snapshot.adStorageEnabled
|
|
@@ -496,8 +458,6 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
496
458
|
}
|
|
497
459
|
}
|
|
498
460
|
|
|
499
|
-
// ============ Event Tracking ============
|
|
500
|
-
|
|
501
461
|
override fun trackEvent(eventName: String, values: ReadableMap?, promise: Promise) {
|
|
502
462
|
try {
|
|
503
463
|
AdShiftLib.trackEvent(
|
|
@@ -584,8 +544,6 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
584
544
|
}
|
|
585
545
|
}
|
|
586
546
|
|
|
587
|
-
// ============ Identity ============
|
|
588
|
-
|
|
589
547
|
override fun getAdShiftDeviceId(promise: Promise) {
|
|
590
548
|
try {
|
|
591
549
|
promise.resolve(AdShiftLib.getAdShiftDeviceId())
|
|
@@ -594,8 +552,6 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
594
552
|
}
|
|
595
553
|
}
|
|
596
554
|
|
|
597
|
-
// ============ Deep Links ============
|
|
598
|
-
|
|
599
555
|
override fun handleDeepLink(url: String, fromLaunch: Boolean, promise: Promise) {
|
|
600
556
|
val uri = Uri.parse(url)
|
|
601
557
|
val scheme = uri.scheme
|
|
@@ -609,6 +565,21 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
609
565
|
return
|
|
610
566
|
}
|
|
611
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) {
|
|
612
583
|
val now = System.currentTimeMillis()
|
|
613
584
|
val alreadyForwarded = synchronized(lock) {
|
|
614
585
|
pruneAutoForwarded(now)
|
|
@@ -620,18 +591,36 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
620
591
|
promise.resolve(null)
|
|
621
592
|
return
|
|
622
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
|
+
}
|
|
623
602
|
if (fromLaunch) {
|
|
624
603
|
synchronized(lock) { rememberLaunchUrls(setOf(url)) }
|
|
625
604
|
}
|
|
626
605
|
|
|
627
606
|
try {
|
|
628
607
|
AdShiftLib.handleAppLinkIntent(Intent(Intent.ACTION_VIEW, uri))
|
|
608
|
+
launch?.let { LaunchRecords.add(it, launchKey) }
|
|
629
609
|
promise.resolve(null)
|
|
630
610
|
} catch (e: Exception) {
|
|
631
611
|
rejectWith(promise, e)
|
|
632
612
|
}
|
|
633
613
|
}
|
|
634
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
|
+
|
|
635
624
|
/** The clipboard lookup exists on iOS only. */
|
|
636
625
|
override fun handlePastedDeepLink(url: String?) = Unit
|
|
637
626
|
|
|
@@ -644,7 +633,6 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
644
633
|
registerPushPath(keys)
|
|
645
634
|
}
|
|
646
635
|
|
|
647
|
-
/** Registers a push payload key path once per process. */
|
|
648
636
|
private fun registerPushPath(path: List<String>) {
|
|
649
637
|
val id = path.joinToString("\u001F")
|
|
650
638
|
synchronized(lock) {
|
|
@@ -666,9 +654,7 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
666
654
|
}
|
|
667
655
|
}
|
|
668
656
|
|
|
669
|
-
/**
|
|
670
|
-
* Returns false when JavaScript could not receive the result, so the caller can keep it.
|
|
671
|
-
*/
|
|
657
|
+
/** Returns false when JavaScript could not receive the result, so the caller can keep it. */
|
|
672
658
|
private fun emitDeepLink(result: DeepLinkResult): Boolean {
|
|
673
659
|
if (invalidated || !emitterAttached || mEventEmitterCallback == null) return false
|
|
674
660
|
return try {
|
|
@@ -686,7 +672,6 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
686
672
|
flushPendingDeepLinks()
|
|
687
673
|
}
|
|
688
674
|
|
|
689
|
-
/** Delivers results that arrived while no JavaScript listener was reachable, oldest first. */
|
|
690
675
|
private fun flushPendingDeepLinks() {
|
|
691
676
|
val pending = synchronized(lock) {
|
|
692
677
|
if (pendingDeepLinks.isEmpty()) return
|
|
@@ -699,16 +684,16 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
699
684
|
}
|
|
700
685
|
}
|
|
701
686
|
|
|
702
|
-
|
|
687
|
+
private fun processCurrentActivityIntent() {
|
|
688
|
+
val activity = reactContext.currentActivity ?: return
|
|
689
|
+
ActivityIntents.adopt(activity)
|
|
690
|
+
processIntent(activity.intent)
|
|
691
|
+
}
|
|
703
692
|
|
|
704
|
-
|
|
705
|
-
* Forwards an Intent to the SDK once. Intents that arrive before `initialize`
|
|
706
|
-
* are kept (newest wins) and processed when the SDK becomes available.
|
|
707
|
-
*/
|
|
708
|
-
private fun processIntent(intent: Intent?, fromLaunchPath: Boolean) {
|
|
693
|
+
private fun processIntent(intent: Intent?) {
|
|
709
694
|
if (intent == null) return
|
|
710
695
|
if (!readyForIntents) {
|
|
711
|
-
synchronized(lock) { pendingIntent =
|
|
696
|
+
synchronized(lock) { pendingIntent = intent }
|
|
712
697
|
return
|
|
713
698
|
}
|
|
714
699
|
if (!autoHandleDeepLinks) return
|
|
@@ -716,26 +701,19 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
716
701
|
Log.d(TAG, "intent skipped (history)")
|
|
717
702
|
return
|
|
718
703
|
}
|
|
719
|
-
if (intent in RestoredIntents) {
|
|
720
|
-
Log.d(TAG, "intent skipped (recreated)")
|
|
721
|
-
return
|
|
722
|
-
}
|
|
723
704
|
val firstSeen = synchronized(lock) { processedIntents.add(intent) }
|
|
724
705
|
if (!firstSeen) {
|
|
725
706
|
Log.d(TAG, "intent skipped (duplicate)")
|
|
726
707
|
return
|
|
727
708
|
}
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
Log.d(TAG, "intent skipped (launch)")
|
|
737
|
-
return
|
|
738
|
-
}
|
|
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
|
|
739
717
|
}
|
|
740
718
|
|
|
741
719
|
try {
|
|
@@ -744,6 +722,7 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
744
722
|
} catch (e: Exception) {
|
|
745
723
|
Log.d(TAG, "intent processing failed: ${e.javaClass.simpleName}")
|
|
746
724
|
}
|
|
725
|
+
if (creation != null && key != null) LaunchRecords.add(creation, key)
|
|
747
726
|
|
|
748
727
|
val forwarded = linkedSetOf<String>()
|
|
749
728
|
intent.dataString?.let { forwarded += it }
|
|
@@ -759,7 +738,7 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
759
738
|
Log.d(TAG, "intent processed")
|
|
760
739
|
}
|
|
761
740
|
|
|
762
|
-
/**
|
|
741
|
+
/** Must be called with [lock] held. */
|
|
763
742
|
private fun rememberLaunchUrls(urls: Set<String>) {
|
|
764
743
|
for (url in urls) {
|
|
765
744
|
launchForwardedUrls.remove(url)
|
|
@@ -772,51 +751,7 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
772
751
|
}
|
|
773
752
|
}
|
|
774
753
|
|
|
775
|
-
/**
|
|
776
|
-
* Identifies a single Intent delivery, so an Activity recreated with the same Intent is
|
|
777
|
-
* recognised while a genuinely new delivery is not. Covers the data URI, the Meta App Link
|
|
778
|
-
* payload and the extras, because notification taps carry no data URI and are told apart
|
|
779
|
-
* only by their extras.
|
|
780
|
-
*/
|
|
781
|
-
private fun fingerprintOf(intent: Intent): String {
|
|
782
|
-
val data = intent.dataString ?: ""
|
|
783
|
-
val appLink = runCatching {
|
|
784
|
-
@Suppress("DEPRECATION")
|
|
785
|
-
when (val extra = intent.extras?.get(META_APP_LINK_EXTRA)) {
|
|
786
|
-
is String -> extra
|
|
787
|
-
is android.os.Bundle -> extra.getString("target_url") ?: ""
|
|
788
|
-
else -> ""
|
|
789
|
-
}
|
|
790
|
-
}.getOrDefault("")
|
|
791
|
-
val payload = "$data|$appLink|${extrasFingerprint(intent)}"
|
|
792
|
-
val digest = MessageDigest.getInstance("SHA-256").digest(payload.toByteArray())
|
|
793
|
-
return digest.joinToString("") { "%02x".format(it) }
|
|
794
|
-
}
|
|
795
|
-
|
|
796
|
-
/**
|
|
797
|
-
* Extras rendered in a stable order. Only values whose textual form survives re-parcelling
|
|
798
|
-
* are included, so the digest stays equal for the same delivery.
|
|
799
|
-
*/
|
|
800
|
-
private fun extrasFingerprint(intent: Intent): String = runCatching {
|
|
801
|
-
val extras = intent.extras ?: return@runCatching ""
|
|
802
|
-
extras.keySet()
|
|
803
|
-
.filter { it != META_APP_LINK_EXTRA }
|
|
804
|
-
.sorted()
|
|
805
|
-
.mapNotNull { key ->
|
|
806
|
-
@Suppress("DEPRECATION")
|
|
807
|
-
when (val value = extras.get(key)) {
|
|
808
|
-
is CharSequence, is Boolean, is Int, is Long, is Float, is Double -> "$key=$value"
|
|
809
|
-
else -> null
|
|
810
|
-
}
|
|
811
|
-
}
|
|
812
|
-
.joinToString("&")
|
|
813
|
-
}.getOrDefault("")
|
|
814
|
-
|
|
815
|
-
/**
|
|
816
|
-
* URLs carried by the extras, including those nested in JSON payloads. A tapped notification
|
|
817
|
-
* holds its link there, so recording them lets `handleDeepLink` recognise a link the SDK has
|
|
818
|
-
* already received with the Intent.
|
|
819
|
-
*/
|
|
754
|
+
/** A tapped notification carries its link in the extras; `handleDeepLink` must recognise it. */
|
|
820
755
|
private fun urlsIn(extras: Bundle?): Set<String> {
|
|
821
756
|
if (extras == null) return emptySet()
|
|
822
757
|
val found = linkedSetOf<String>()
|
|
@@ -853,12 +788,11 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
853
788
|
}
|
|
854
789
|
}
|
|
855
790
|
|
|
856
|
-
// ============ ActivityEventListener / LifecycleEventListener ============
|
|
857
|
-
|
|
858
791
|
override fun onNewIntent(intent: Intent) {
|
|
859
792
|
if (invalidated) return
|
|
860
793
|
try {
|
|
861
|
-
|
|
794
|
+
reactContext.currentActivity?.let(ActivityIntents::noteNewIntent)
|
|
795
|
+
processIntent(intent)
|
|
862
796
|
} catch (e: Exception) {
|
|
863
797
|
Log.d(TAG, "onNewIntent failed: ${e.javaClass.simpleName}")
|
|
864
798
|
}
|
|
@@ -869,7 +803,7 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
869
803
|
override fun onHostResume() {
|
|
870
804
|
if (invalidated) return
|
|
871
805
|
try {
|
|
872
|
-
|
|
806
|
+
processCurrentActivityIntent()
|
|
873
807
|
} catch (e: Exception) {
|
|
874
808
|
Log.d(TAG, "onHostResume failed: ${e.javaClass.simpleName}")
|
|
875
809
|
}
|
|
@@ -879,8 +813,6 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
879
813
|
|
|
880
814
|
override fun onHostDestroy() = Unit
|
|
881
815
|
|
|
882
|
-
// ============ Error model ============
|
|
883
|
-
|
|
884
816
|
private fun rejectWith(promise: Promise, code: String, message: String, throwable: Throwable?, nativeCode: Any?) {
|
|
885
817
|
val userInfo = Arguments.createMap()
|
|
886
818
|
when (nativeCode) {
|
|
@@ -905,8 +837,6 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
905
837
|
}
|
|
906
838
|
}
|
|
907
839
|
|
|
908
|
-
// ============ Mappers ============
|
|
909
|
-
|
|
910
840
|
private fun toWritableMap(result: DeepLinkResult): WritableMap = Arguments.createMap().apply {
|
|
911
841
|
val query = result.queryParams ?: emptyMap()
|
|
912
842
|
|
|
@@ -942,8 +872,6 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
942
872
|
result.error?.let { putString("errorMessage", it.name.lowercase().replace('_', ' ')) }
|
|
943
873
|
}
|
|
944
874
|
|
|
945
|
-
// ============ ReadableMap helpers ============
|
|
946
|
-
|
|
947
875
|
private fun optString(map: ReadableMap, key: String): String? =
|
|
948
876
|
if (map.hasKey(key) && map.getType(key) == ReadableType.String) map.getString(key) else null
|
|
949
877
|
|
|
@@ -980,8 +908,6 @@ class AdShiftReactNativePluginModule(private val reactContext: ReactApplicationC
|
|
|
980
908
|
return out
|
|
981
909
|
}
|
|
982
910
|
|
|
983
|
-
// ============ Logging ============
|
|
984
|
-
|
|
985
911
|
private fun logFailure(method: String, e: Exception) {
|
|
986
912
|
Log.e(TAG, "$method failed: ${e.javaClass.simpleName}: ${e.message}")
|
|
987
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
|
|
@@ -26,10 +26,6 @@ import org.junit.runner.RunWith
|
|
|
26
26
|
import org.robolectric.RobolectricTestRunner
|
|
27
27
|
import org.robolectric.annotation.Config
|
|
28
28
|
|
|
29
|
-
/**
|
|
30
|
-
* Every deep link result reaches JavaScript exactly once: results that arrive while no listener
|
|
31
|
-
* is reachable wait for the next one, in the order the SDK produced them.
|
|
32
|
-
*/
|
|
33
29
|
@RunWith(RobolectricTestRunner::class)
|
|
34
30
|
@Config(sdk = [35])
|
|
35
31
|
class DeepLinkDeliveryTest {
|
|
@@ -3,22 +3,21 @@ package com.adshift.reactnativeplugin
|
|
|
3
3
|
import android.content.Intent
|
|
4
4
|
import android.net.Uri
|
|
5
5
|
import android.os.Bundle
|
|
6
|
+
import android.os.Looper
|
|
6
7
|
import com.adshift.sdk.core.AdShiftLib
|
|
7
8
|
import io.mockk.every
|
|
8
9
|
import io.mockk.mockkStatic
|
|
9
10
|
import io.mockk.unmockkStatic
|
|
10
11
|
import org.junit.After
|
|
12
|
+
import org.junit.Assert.assertFalse
|
|
11
13
|
import org.junit.Assert.assertTrue
|
|
12
14
|
import org.junit.Before
|
|
13
15
|
import org.junit.Test
|
|
14
16
|
import org.junit.runner.RunWith
|
|
15
17
|
import org.robolectric.RobolectricTestRunner
|
|
18
|
+
import org.robolectric.Shadows.shadowOf
|
|
16
19
|
import org.robolectric.annotation.Config
|
|
17
20
|
|
|
18
|
-
/**
|
|
19
|
-
* The `initialize` options reach the SDK before any Intent does, whatever moment the host
|
|
20
|
-
* delivers that Intent.
|
|
21
|
-
*/
|
|
22
21
|
@RunWith(RobolectricTestRunner::class)
|
|
23
22
|
@Config(sdk = [35])
|
|
24
23
|
class InitializeOrderingTest {
|
|
@@ -35,7 +34,13 @@ class InitializeOrderingTest {
|
|
|
35
34
|
fun setUp() {
|
|
36
35
|
ModuleState.reset()
|
|
37
36
|
mockkStatic(AdShiftLib::class)
|
|
38
|
-
every { AdShiftLib.initSdk(any(), any()) } answers { calls +=
|
|
37
|
+
every { AdShiftLib.initSdk(any(), any()) } answers { calls += INIT_SDK }
|
|
38
|
+
// As the SDK does: naming the plugin before initSdk throws.
|
|
39
|
+
every { AdShiftLib.setWrapper(any()) } answers {
|
|
40
|
+
if (INIT_SDK !in calls) throw IllegalArgumentException("SDK not initialized")
|
|
41
|
+
calls += SET_WRAPPER
|
|
42
|
+
}
|
|
43
|
+
every { AdShiftLib.start(any()) } answers { calls += START }
|
|
39
44
|
every { AdShiftLib.setDebugLog(any()) } answers { calls += "setDebugLog" }
|
|
40
45
|
every { AdShiftLib.setBrandedDomains(any()) } answers { calls += SET_BRANDED_DOMAINS }
|
|
41
46
|
every { AdShiftLib.setTestMode(any()) } answers { calls += SET_TEST_MODE }
|
|
@@ -95,6 +100,30 @@ class InitializeOrderingTest {
|
|
|
95
100
|
)
|
|
96
101
|
}
|
|
97
102
|
|
|
103
|
+
@Test
|
|
104
|
+
fun `names the plugin right after the sdk is initialized and before start`() {
|
|
105
|
+
context.launchIntent = deepLinkIntent()
|
|
106
|
+
|
|
107
|
+
module.initialize(initializeConfig())
|
|
108
|
+
module.start(RecordingPromise())
|
|
109
|
+
shadowOf(Looper.getMainLooper()).idle()
|
|
110
|
+
|
|
111
|
+
val wrapper = calls.indexOf(SET_WRAPPER)
|
|
112
|
+
assertTrue("plugin not named: $calls", wrapper >= 0)
|
|
113
|
+
assertTrue("named before initSdk: $calls", calls.indexOf(INIT_SDK) in 0 until wrapper)
|
|
114
|
+
assertTrue("named after start: $calls", wrapper < calls.indexOf(START))
|
|
115
|
+
assertTrue("named after an intent was forwarded: $calls", wrapper < forwardIndex())
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
@Test
|
|
119
|
+
fun `does not name the plugin when the sdk could not be initialized`() {
|
|
120
|
+
every { AdShiftLib.initSdk(any(), any()) } throws IllegalStateException("no context")
|
|
121
|
+
|
|
122
|
+
module.initialize(initializeConfig())
|
|
123
|
+
|
|
124
|
+
assertFalse("named without an SDK: $calls", calls.contains(SET_WRAPPER))
|
|
125
|
+
}
|
|
126
|
+
|
|
98
127
|
private fun assertOptionsPrecedeForwarding() {
|
|
99
128
|
val forward = forwardIndex()
|
|
100
129
|
assertTrue("no intent reached the SDK: $calls", forward >= 0)
|
|
@@ -116,6 +145,9 @@ class InitializeOrderingTest {
|
|
|
116
145
|
Intent(Intent.ACTION_VIEW, Uri.parse("https://$BRANDED_DOMAIN/promo?id=42"))
|
|
117
146
|
|
|
118
147
|
private companion object {
|
|
148
|
+
const val INIT_SDK = "initSdk"
|
|
149
|
+
const val SET_WRAPPER = "setWrapper"
|
|
150
|
+
const val START = "start"
|
|
119
151
|
const val SET_BRANDED_DOMAINS = "setBrandedDomains"
|
|
120
152
|
const val SET_TEST_MODE = "setTestMode"
|
|
121
153
|
const val ADD_PUSH_PATH = "addPushNotificationDeepLinkPath"
|