@metarouter/react-native-sdk 0.1.13 → 0.1.14
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/android/build.gradle +28 -7
- package/android/src/main/java/com/metarouter/reactnativesdk/MetaRouterReactNativeSdkPackage.java +54 -0
- package/android/src/main/java/com/reactnativecommunity/asyncstorage/AsyncStoragePackage.java +93 -0
- package/android/src/main/java/com/reactnativesovran/Sovran.kt +45 -0
- package/android/src/main/java/com/reactnativesovran/SovranModule.kt +55 -0
- package/android/src/main/java/com/segmentanalyticsreactnative/AnalyticsReactNativeModule.kt +267 -0
- package/android/src/main/java/com/segmentanalyticsreactnative/AnalyticsReactNativePackage.kt +43 -0
- package/android/src/main/java/org/linusu/RNGetRandomValuesModule.java +36 -0
- package/android/src/main/java/org/linusu/RNGetRandomValuesPackage.java +28 -0
- package/package.json +1 -1
package/android/build.gradle
CHANGED
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
apply plugin: 'com.android.library'
|
|
2
|
+
apply plugin: 'kotlin-android'
|
|
3
|
+
apply plugin: 'com.google.devtools.ksp' // Needed for Room compiler
|
|
2
4
|
|
|
3
5
|
def safeExtGet(prop, fallback) {
|
|
4
6
|
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
5
7
|
}
|
|
6
8
|
|
|
9
|
+
// Define AsyncStorage configuration
|
|
10
|
+
ext.AsyncStorageConfig = [
|
|
11
|
+
useNextStorage: true, // or false if you want legacy
|
|
12
|
+
roomVersion: "2.5.0"
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
// Define coroutines version for AsyncStorage
|
|
16
|
+
ext.AsyncStorageLibs = [
|
|
17
|
+
coroutines: "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4"
|
|
18
|
+
]
|
|
19
|
+
|
|
7
20
|
android {
|
|
8
21
|
compileSdkVersion safeExtGet('compileSdkVersion', 33)
|
|
9
22
|
|
|
@@ -18,6 +31,10 @@ android {
|
|
|
18
31
|
sourceCompatibility JavaVersion.VERSION_1_8
|
|
19
32
|
targetCompatibility JavaVersion.VERSION_1_8
|
|
20
33
|
}
|
|
34
|
+
|
|
35
|
+
kotlinOptions {
|
|
36
|
+
jvmTarget = '1.8'
|
|
37
|
+
}
|
|
21
38
|
}
|
|
22
39
|
|
|
23
40
|
repositories {
|
|
@@ -27,13 +44,17 @@ repositories {
|
|
|
27
44
|
}
|
|
28
45
|
|
|
29
46
|
dependencies {
|
|
30
|
-
// React Native core
|
|
31
47
|
implementation 'com.facebook.react:react-native:+'
|
|
32
48
|
|
|
33
|
-
//
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
49
|
+
// Kotlin support
|
|
50
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
|
|
51
|
+
|
|
52
|
+
// AsyncStorage dependencies (when useNextStorage = true)
|
|
53
|
+
if (ext.AsyncStorageConfig.useNextStorage) {
|
|
54
|
+
implementation "androidx.room:room-runtime:${ext.AsyncStorageConfig.roomVersion}"
|
|
55
|
+
implementation "androidx.room:room-ktx:${ext.AsyncStorageConfig.roomVersion}"
|
|
56
|
+
ksp "androidx.room:room-compiler:${ext.AsyncStorageConfig.roomVersion}"
|
|
57
|
+
|
|
58
|
+
implementation ext.AsyncStorageLibs.coroutines
|
|
59
|
+
}
|
|
39
60
|
}
|
package/android/src/main/java/com/metarouter/reactnativesdk/MetaRouterReactNativeSdkPackage.java
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
package com.metarouter.reactnativesdk;
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.ReactPackage;
|
|
4
|
+
import com.facebook.react.bridge.NativeModule;
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
6
|
+
import com.facebook.react.uimanager.ViewManager;
|
|
7
|
+
|
|
8
|
+
import java.util.ArrayList;
|
|
9
|
+
import java.util.Arrays;
|
|
10
|
+
import java.util.List;
|
|
11
|
+
|
|
12
|
+
// Import the bundled packages
|
|
13
|
+
import com.reactnativecommunity.asyncstorage.AsyncStoragePackage;
|
|
14
|
+
import com.segmentanalyticsreactnative.AnalyticsReactNativePackage;
|
|
15
|
+
import com.reactnativesovran.Sovran;
|
|
16
|
+
import org.linusu.RNGetRandomValuesPackage;
|
|
17
|
+
|
|
18
|
+
public class MetaRouterReactNativeSDKPackage implements ReactPackage {
|
|
19
|
+
|
|
20
|
+
// Create instances of bundled packages
|
|
21
|
+
private final AsyncStoragePackage asyncStoragePackage = new AsyncStoragePackage();
|
|
22
|
+
private final AnalyticsReactNativePackage analyticsPackage = new AnalyticsReactNativePackage();
|
|
23
|
+
private final Sovran sovranPackage = new Sovran();
|
|
24
|
+
private final RNGetRandomValuesPackage randomValuesPackage = new RNGetRandomValuesPackage();
|
|
25
|
+
|
|
26
|
+
@Override
|
|
27
|
+
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
|
|
28
|
+
List<NativeModule> modules = new ArrayList<>();
|
|
29
|
+
|
|
30
|
+
// Add modules from all bundled packages
|
|
31
|
+
modules.addAll(asyncStoragePackage.createNativeModules(reactContext));
|
|
32
|
+
modules.addAll(analyticsPackage.createNativeModules(reactContext));
|
|
33
|
+
modules.addAll(sovranPackage.createNativeModules(reactContext));
|
|
34
|
+
modules.addAll(randomValuesPackage.createNativeModules(reactContext));
|
|
35
|
+
|
|
36
|
+
// Add your own SDK modules here if you have any
|
|
37
|
+
// modules.add(new MetaRouterModule(reactContext));
|
|
38
|
+
|
|
39
|
+
return modules;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@Override
|
|
43
|
+
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
|
|
44
|
+
List<ViewManager> viewManagers = new ArrayList<>();
|
|
45
|
+
|
|
46
|
+
// Add view managers from all bundled packages
|
|
47
|
+
viewManagers.addAll(asyncStoragePackage.createViewManagers(reactContext));
|
|
48
|
+
viewManagers.addAll(analyticsPackage.createViewManagers(reactContext));
|
|
49
|
+
viewManagers.addAll(sovranPackage.createViewManagers(reactContext));
|
|
50
|
+
viewManagers.addAll(randomValuesPackage.createViewManagers(reactContext));
|
|
51
|
+
|
|
52
|
+
return viewManagers;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
package com.reactnativecommunity.asyncstorage;
|
|
9
|
+
|
|
10
|
+
import com.facebook.react.TurboReactPackage;
|
|
11
|
+
import com.facebook.react.bridge.ModuleSpec;
|
|
12
|
+
import com.facebook.react.bridge.JavaScriptModule;
|
|
13
|
+
import com.facebook.react.bridge.NativeModule;
|
|
14
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
15
|
+
import com.facebook.react.module.annotations.ReactModule;
|
|
16
|
+
import com.facebook.react.module.annotations.ReactModuleList;
|
|
17
|
+
import com.facebook.react.module.model.ReactModuleInfo;
|
|
18
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider;
|
|
19
|
+
import com.facebook.react.uimanager.ViewManager;
|
|
20
|
+
import java.util.Collections;
|
|
21
|
+
import java.util.HashMap;
|
|
22
|
+
import java.util.List;
|
|
23
|
+
import java.util.Map;
|
|
24
|
+
|
|
25
|
+
import javax.annotation.Nonnull;
|
|
26
|
+
|
|
27
|
+
@ReactModuleList(
|
|
28
|
+
nativeModules = {
|
|
29
|
+
AsyncStorageModule.class,
|
|
30
|
+
}
|
|
31
|
+
)
|
|
32
|
+
public class AsyncStoragePackage extends TurboReactPackage {
|
|
33
|
+
|
|
34
|
+
@Override
|
|
35
|
+
public NativeModule getModule(String name, @Nonnull ReactApplicationContext reactContext) {
|
|
36
|
+
switch (name) {
|
|
37
|
+
case AsyncStorageModule.NAME:
|
|
38
|
+
return new AsyncStorageModule(reactContext);
|
|
39
|
+
default:
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@Override
|
|
45
|
+
public ReactModuleInfoProvider getReactModuleInfoProvider() {
|
|
46
|
+
try {
|
|
47
|
+
Class<?> reactModuleInfoProviderClass =
|
|
48
|
+
Class.forName("com.reactnativecommunity.asyncstorage.AsyncStoragePackage$$ReactModuleInfoProvider");
|
|
49
|
+
return (ReactModuleInfoProvider) reactModuleInfoProviderClass.newInstance();
|
|
50
|
+
} catch (ClassNotFoundException e) {
|
|
51
|
+
// ReactModuleSpecProcessor does not run at build-time. Create this ReactModuleInfoProvider by
|
|
52
|
+
// hand.
|
|
53
|
+
return new ReactModuleInfoProvider() {
|
|
54
|
+
@Override
|
|
55
|
+
public Map<String, ReactModuleInfo> getReactModuleInfos() {
|
|
56
|
+
final Map<String, ReactModuleInfo> reactModuleInfoMap = new HashMap<>();
|
|
57
|
+
boolean isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
|
|
58
|
+
|
|
59
|
+
Class<? extends NativeModule>[] moduleList =
|
|
60
|
+
new Class[] {
|
|
61
|
+
AsyncStorageModule.class,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
for (Class<? extends NativeModule> moduleClass : moduleList) {
|
|
65
|
+
ReactModule reactModule = moduleClass.getAnnotation(ReactModule.class);
|
|
66
|
+
|
|
67
|
+
reactModuleInfoMap.put(
|
|
68
|
+
reactModule.name(),
|
|
69
|
+
new ReactModuleInfo(
|
|
70
|
+
reactModule.name(),
|
|
71
|
+
moduleClass.getName(),
|
|
72
|
+
reactModule.canOverrideExistingModule(),
|
|
73
|
+
reactModule.needsEagerInit(),
|
|
74
|
+
reactModule.hasConstants(),
|
|
75
|
+
reactModule.isCxxModule(),
|
|
76
|
+
isTurboModule));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return reactModuleInfoMap;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
} catch (InstantiationException | IllegalAccessException e) {
|
|
83
|
+
throw new RuntimeException(
|
|
84
|
+
"No ReactModuleInfoProvider for com.reactnativecommunity.asyncstorage.AsyncStoragePackage$$ReactModuleInfoProvider", e);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
@Override
|
|
89
|
+
@SuppressWarnings("rawtypes")
|
|
90
|
+
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
|
|
91
|
+
return Collections.emptyList();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
package com.sovranreactnative
|
|
2
|
+
|
|
3
|
+
import android.util.Log
|
|
4
|
+
import com.facebook.react.ReactPackage
|
|
5
|
+
import com.facebook.react.bridge.NativeModule
|
|
6
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
7
|
+
import com.facebook.react.uimanager.ViewManager
|
|
8
|
+
|
|
9
|
+
class Sovran : ReactPackage {
|
|
10
|
+
|
|
11
|
+
data class Action (val type: String, val payload: Map<String, Any?>)
|
|
12
|
+
|
|
13
|
+
private var isInitialized = false
|
|
14
|
+
private val queue = mutableListOf<Action>()
|
|
15
|
+
private var module: SovranModule? = null
|
|
16
|
+
|
|
17
|
+
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
|
|
18
|
+
module = SovranModule(reactContext)
|
|
19
|
+
|
|
20
|
+
module?.onInitialized = {
|
|
21
|
+
Log.v("SovranModule", "onInitialized queue: ${queue.size}")
|
|
22
|
+
isInitialized = true
|
|
23
|
+
queue.forEach {
|
|
24
|
+
module?.dispatch(it.type, it.payload)
|
|
25
|
+
}
|
|
26
|
+
queue.clear()
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return listOf(module as NativeModule)
|
|
30
|
+
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
|
34
|
+
return emptyList()
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
fun dispatch(action: String, payload: Map<String, Any?>) {
|
|
38
|
+
Log.v("SovranModule", "dispatch: $action isInitialized: $isInitialized")
|
|
39
|
+
if (isInitialized) {
|
|
40
|
+
module?.dispatch(action, payload)
|
|
41
|
+
} else {
|
|
42
|
+
queue.add(Action(action, payload))
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
package com.sovranreactnative
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.Arguments
|
|
4
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
5
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
6
|
+
import com.facebook.react.bridge.ReactMethod
|
|
7
|
+
import com.facebook.react.bridge.Promise
|
|
8
|
+
import com.facebook.react.bridge.WritableMap
|
|
9
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
10
|
+
import com.facebook.react.module.annotations.ReactModule;
|
|
11
|
+
|
|
12
|
+
@ReactModule(name="Sovran")
|
|
13
|
+
class SovranModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
|
|
14
|
+
|
|
15
|
+
var onInitialized: () -> Unit = {};
|
|
16
|
+
|
|
17
|
+
override fun getName(): String {
|
|
18
|
+
return "Sovran"
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
companion object {
|
|
22
|
+
const val ON_STORE_ACTION = "onStoreAction"
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
override fun getConstants() = mapOf(
|
|
26
|
+
"ON_STORE_ACTION" to ON_STORE_ACTION
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
override fun initialize() {
|
|
30
|
+
super.initialize()
|
|
31
|
+
onInitialized()
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Example method
|
|
35
|
+
// See https://reactnative.dev/docs/native-modules-android
|
|
36
|
+
@ReactMethod
|
|
37
|
+
fun addListener(eventName: String?) {
|
|
38
|
+
// Keep: Required for RN built in Event Emitter Calls.
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@ReactMethod
|
|
42
|
+
fun removeListeners(count: Int?) {
|
|
43
|
+
// Keep: Required for RN built in Event Emitter Calls.
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
fun dispatch(action: String, payload: Map<String, Any?>) {
|
|
47
|
+
val map = mapOf(
|
|
48
|
+
"type" to action,
|
|
49
|
+
"payload" to payload
|
|
50
|
+
)
|
|
51
|
+
val event: WritableMap = Arguments.makeNativeMap(map)
|
|
52
|
+
reactApplicationContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
53
|
+
.emit(ON_STORE_ACTION, event)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
package com.segmentanalyticsreactnative
|
|
2
|
+
|
|
3
|
+
import android.annotation.SuppressLint
|
|
4
|
+
import android.app.Activity
|
|
5
|
+
import android.content.Context
|
|
6
|
+
import android.content.Intent
|
|
7
|
+
import android.content.pm.PackageInfo
|
|
8
|
+
import android.content.res.Resources
|
|
9
|
+
import android.media.MediaDrm
|
|
10
|
+
import android.net.ConnectivityManager
|
|
11
|
+
import android.net.NetworkCapabilities
|
|
12
|
+
import android.net.Uri
|
|
13
|
+
import android.os.Build
|
|
14
|
+
import android.util.Log
|
|
15
|
+
import androidx.core.content.pm.PackageInfoCompat
|
|
16
|
+
import com.facebook.react.ReactActivity
|
|
17
|
+
import com.facebook.react.ReactApplication
|
|
18
|
+
import com.facebook.react.bridge.*
|
|
19
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
20
|
+
import com.sovranreactnative.SovranModule
|
|
21
|
+
import java.lang.Exception
|
|
22
|
+
import java.util.*
|
|
23
|
+
import java.security.MessageDigest
|
|
24
|
+
import java.util.UUID
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
enum class ConnectionType {
|
|
28
|
+
Cellular, Unknown, Wifi
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@ReactModule(name="AnalyticsReactNative")
|
|
32
|
+
class AnalyticsReactNativeModule : ReactContextBaseJavaModule, ActivityEventListener, LifecycleEventListener {
|
|
33
|
+
|
|
34
|
+
var onInitialized: () -> Unit = {};
|
|
35
|
+
|
|
36
|
+
constructor(reactContext: ReactApplicationContext) : super(reactContext) {
|
|
37
|
+
this.pInfo = reactContext.packageManager.getPackageInfo(reactContext.packageName, 0)
|
|
38
|
+
// Listen for new intents when app is in the background
|
|
39
|
+
reactContext.addActivityEventListener(this)
|
|
40
|
+
// Listen for resume events when it is cold started, or in the background
|
|
41
|
+
reactContext.addLifecycleEventListener(this)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
override fun initialize() {
|
|
45
|
+
super.initialize()
|
|
46
|
+
onInitialized()
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private var isColdLaunch = true
|
|
50
|
+
private val pInfo: PackageInfo
|
|
51
|
+
|
|
52
|
+
override fun getName(): String {
|
|
53
|
+
return "AnalyticsReactNative"
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private fun getBuildNumber(): String {
|
|
57
|
+
return PackageInfoCompat.getLongVersionCode(pInfo).toString()
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
fun ByteArray.toHexString() = joinToString("") { "%02x".format(it) }
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Workaround for not able to get device id on Android 10 or above using DRM API
|
|
64
|
+
* {@see https://stackoverflow.com/questions/58103580/android-10-imei-no-longer-available-on-api-29-looking-for-alternatives}
|
|
65
|
+
* {@see https://developer.android.com/training/articles/user-data-ids}
|
|
66
|
+
*/
|
|
67
|
+
private fun getUniqueId(collectDeviceId : Boolean): String? {
|
|
68
|
+
if (collectDeviceId) {
|
|
69
|
+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2)
|
|
70
|
+
return null
|
|
71
|
+
|
|
72
|
+
val WIDEVINE_UUID = UUID(-0x121074568629b532L, -0x5c37d8232ae2de13L)
|
|
73
|
+
var wvDrm: MediaDrm? = null
|
|
74
|
+
try {
|
|
75
|
+
wvDrm = MediaDrm(WIDEVINE_UUID)
|
|
76
|
+
val wideVineId = wvDrm.getPropertyByteArray(MediaDrm.PROPERTY_DEVICE_UNIQUE_ID)
|
|
77
|
+
val md = MessageDigest.getInstance("SHA-256")
|
|
78
|
+
md.update(wideVineId)
|
|
79
|
+
return md.digest().toHexString()
|
|
80
|
+
} catch (e: Exception) {
|
|
81
|
+
return null
|
|
82
|
+
} finally {
|
|
83
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
|
84
|
+
wvDrm?.close()
|
|
85
|
+
} else {
|
|
86
|
+
wvDrm?.release()
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return null
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
private fun getConnectionType(context: Context): ConnectionType {
|
|
94
|
+
val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager?
|
|
95
|
+
var result: ConnectionType = ConnectionType.Unknown
|
|
96
|
+
|
|
97
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
98
|
+
cm?.run {
|
|
99
|
+
cm.getNetworkCapabilities(cm.activeNetwork)?.run {
|
|
100
|
+
if (hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
|
|
101
|
+
result = ConnectionType.Wifi
|
|
102
|
+
} else if (hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)) {
|
|
103
|
+
result = ConnectionType.Cellular
|
|
104
|
+
} else {
|
|
105
|
+
result = ConnectionType.Unknown
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
} else {
|
|
110
|
+
cm?.run {
|
|
111
|
+
cm.activeNetworkInfo?.run {
|
|
112
|
+
if (type == ConnectivityManager.TYPE_WIFI) {
|
|
113
|
+
result = ConnectionType.Wifi
|
|
114
|
+
} else if (type == ConnectivityManager.TYPE_MOBILE) {
|
|
115
|
+
result = ConnectionType.Cellular
|
|
116
|
+
} else {
|
|
117
|
+
result = ConnectionType.Unknown
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return result
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
@ReactMethod
|
|
126
|
+
fun getContextInfo(config: ReadableMap, promise: Promise) {
|
|
127
|
+
val appName: String = reactApplicationContext.applicationInfo.loadLabel(reactApplicationContext.packageManager).toString()
|
|
128
|
+
val appVersion: String = pInfo.versionName.toString()
|
|
129
|
+
val buildNumber = getBuildNumber()
|
|
130
|
+
val bundleId = reactApplicationContext.packageName
|
|
131
|
+
|
|
132
|
+
val connectionType: ConnectionType = getConnectionType(reactApplicationContext)
|
|
133
|
+
val timezone: TimeZone = TimeZone.getDefault()
|
|
134
|
+
val currentLocale: Locale = Locale.getDefault()
|
|
135
|
+
val locale: String = "${currentLocale.language}-${currentLocale.country}"
|
|
136
|
+
|
|
137
|
+
val screenWidth = Resources.getSystem().displayMetrics.widthPixels
|
|
138
|
+
val screenHeight = Resources.getSystem().displayMetrics.heightPixels
|
|
139
|
+
|
|
140
|
+
val screenDensity = Resources.getSystem().displayMetrics.density;
|
|
141
|
+
|
|
142
|
+
val contextInfo: WritableMap = Arguments.createMap()
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
if (config.hasKey("collectDeviceId") && config.getBoolean("collectDeviceId")) {
|
|
146
|
+
val fallbackDeviceId = UUID.randomUUID().toString()
|
|
147
|
+
val deviceId = getUniqueId(config.hasKey("collectDeviceId") && config.getBoolean("collectDeviceId"))?: fallbackDeviceId
|
|
148
|
+
|
|
149
|
+
contextInfo.putString("deviceId", deviceId)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
contextInfo.putString("appName", appName)
|
|
153
|
+
contextInfo.putString("appVersion", appVersion)
|
|
154
|
+
contextInfo.putString("buildNumber", buildNumber)
|
|
155
|
+
contextInfo.putString("bundleId", bundleId)
|
|
156
|
+
|
|
157
|
+
contextInfo.putString("deviceName", Build.DEVICE)
|
|
158
|
+
contextInfo.putString("deviceType", "android")
|
|
159
|
+
contextInfo.putString("manufacturer", Build.MANUFACTURER)
|
|
160
|
+
contextInfo.putString("model", Build.MODEL)
|
|
161
|
+
|
|
162
|
+
contextInfo.putString("timezone", timezone.id)
|
|
163
|
+
contextInfo.putString("locale", locale)
|
|
164
|
+
contextInfo.putString("networkType", connectionType.toString().lowercase(currentLocale))
|
|
165
|
+
|
|
166
|
+
contextInfo.putString("osName", "Android")
|
|
167
|
+
contextInfo.putString("osVersion", Build.VERSION.RELEASE)
|
|
168
|
+
|
|
169
|
+
contextInfo.putInt("screenWidth", screenWidth)
|
|
170
|
+
contextInfo.putInt("screenHeight", screenHeight)
|
|
171
|
+
contextInfo.putDouble("screenDensity", screenDensity.toDouble())
|
|
172
|
+
|
|
173
|
+
promise.resolve(contextInfo)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
fun getReferrer(activity: Activity): Uri? {
|
|
177
|
+
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
|
|
178
|
+
activity.referrer
|
|
179
|
+
} else {
|
|
180
|
+
null
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
fun trackDeepLinks(intent: Intent?) {
|
|
185
|
+
if (intent == null || intent.data == null) {
|
|
186
|
+
Log.d(name, "No Intent data found")
|
|
187
|
+
return
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
val properties = Hashtable<String, String>()
|
|
191
|
+
|
|
192
|
+
if (currentActivity == null) {
|
|
193
|
+
Log.d(name, "No activity found")
|
|
194
|
+
return
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
val referrer = getReferrer(currentActivity!!)
|
|
198
|
+
|
|
199
|
+
if (referrer != null) {
|
|
200
|
+
val referringApplication = referrer.toString()
|
|
201
|
+
properties["referring_application"] = referringApplication
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
val uri = intent.data
|
|
205
|
+
try {
|
|
206
|
+
properties["url"] = uri.toString()
|
|
207
|
+
for (parameter in uri!!.queryParameterNames) {
|
|
208
|
+
val value = uri.getQueryParameter(parameter)
|
|
209
|
+
if (value != null && value.trim { it <= ' ' }.isNotEmpty()) {
|
|
210
|
+
properties[parameter] = value
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
} catch (e: Exception) {
|
|
214
|
+
// handle error
|
|
215
|
+
Log.d(name, "Error getting URL: ${e.message}")
|
|
216
|
+
return
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
Log.d(name, "Sending Deeplink data to store: uri=${uri}, referrer=${referrer}")
|
|
220
|
+
val sovran = (currentActivity?.application as ReactApplication)
|
|
221
|
+
?.reactNativeHost
|
|
222
|
+
?.reactInstanceManager
|
|
223
|
+
?.currentReactContext
|
|
224
|
+
?.getNativeModule(SovranModule::class.java)
|
|
225
|
+
sovran?.dispatch("add-deepLink-data", properties)
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
fun setAnonymousId(anonymousId: String) {
|
|
231
|
+
val properties = Hashtable<String, String>()
|
|
232
|
+
properties["anonymousId"] = anonymousId
|
|
233
|
+
|
|
234
|
+
val currentContext = getReactApplicationContext()
|
|
235
|
+
|
|
236
|
+
if (currentContext != null) {
|
|
237
|
+
val sovran = currentContext.getNativeModule(SovranModule::class.java)
|
|
238
|
+
sovran?.dispatch("add-anonymous-id", properties)
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
override fun onActivityResult(activity: Activity, requestCode: Int, resultCode: Int, data: Intent?) {
|
|
243
|
+
// Do nothing
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
override fun onNewIntent(intent: Intent) {
|
|
247
|
+
Log.d(name, "onNewIntent = ${intent}")
|
|
248
|
+
trackDeepLinks(intent)
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
override fun onHostResume() {
|
|
252
|
+
if (currentActivity != null && isColdLaunch) {
|
|
253
|
+
isColdLaunch = false
|
|
254
|
+
Log.d(name, "onHostResume = ${currentActivity!!.intent}")
|
|
255
|
+
trackDeepLinks(currentActivity!!.intent)
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
override fun onHostPause() {
|
|
260
|
+
// Do nothing
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
override fun onHostDestroy() {
|
|
264
|
+
isColdLaunch = true
|
|
265
|
+
// Do nothing
|
|
266
|
+
}
|
|
267
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
package com.segmentanalyticsreactnative
|
|
2
|
+
|
|
3
|
+
import java.util.Arrays
|
|
4
|
+
import java.util.Collections
|
|
5
|
+
|
|
6
|
+
import com.facebook.react.ReactPackage
|
|
7
|
+
import com.facebook.react.bridge.NativeModule
|
|
8
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
9
|
+
import com.facebook.react.uimanager.ViewManager
|
|
10
|
+
import com.facebook.react.bridge.JavaScriptModule
|
|
11
|
+
|
|
12
|
+
class AnalyticsReactNativePackage : ReactPackage {
|
|
13
|
+
|
|
14
|
+
private var isInitialized = false
|
|
15
|
+
private var anonymousId: String? = null
|
|
16
|
+
private var module: AnalyticsReactNativeModule? = null
|
|
17
|
+
|
|
18
|
+
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
|
|
19
|
+
module = AnalyticsReactNativeModule(reactContext)
|
|
20
|
+
module?.onInitialized = {
|
|
21
|
+
isInitialized = true
|
|
22
|
+
anonymousId?.let { anonId ->
|
|
23
|
+
module?.setAnonymousId(anonId)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return listOf(module as NativeModule)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
|
30
|
+
return emptyList<ViewManager<*, *>>()
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
fun setAnonymousId(nativeAnonymousId: String) {
|
|
34
|
+
if (isInitialized) {
|
|
35
|
+
anonymousId = nativeAnonymousId;
|
|
36
|
+
anonymousId?.let { anonId ->
|
|
37
|
+
module?.setAnonymousId(anonId)
|
|
38
|
+
}
|
|
39
|
+
} else {
|
|
40
|
+
anonymousId = nativeAnonymousId
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
package org.linusu;
|
|
2
|
+
|
|
3
|
+
import java.security.NoSuchAlgorithmException;
|
|
4
|
+
import java.security.SecureRandom;
|
|
5
|
+
|
|
6
|
+
import android.util.Base64;
|
|
7
|
+
|
|
8
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
9
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
10
|
+
import com.facebook.react.bridge.ReactMethod;
|
|
11
|
+
import com.facebook.react.bridge.Callback;
|
|
12
|
+
|
|
13
|
+
public class RNGetRandomValuesModule extends ReactContextBaseJavaModule {
|
|
14
|
+
|
|
15
|
+
private final ReactApplicationContext reactContext;
|
|
16
|
+
|
|
17
|
+
public RNGetRandomValuesModule(ReactApplicationContext reactContext) {
|
|
18
|
+
super(reactContext);
|
|
19
|
+
this.reactContext = reactContext;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@Override
|
|
23
|
+
public String getName() {
|
|
24
|
+
return "RNGetRandomValues";
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
28
|
+
public String getRandomBase64(int byteLength) throws NoSuchAlgorithmException {
|
|
29
|
+
byte[] data = new byte[byteLength];
|
|
30
|
+
SecureRandom random = new SecureRandom();
|
|
31
|
+
|
|
32
|
+
random.nextBytes(data);
|
|
33
|
+
|
|
34
|
+
return Base64.encodeToString(data, Base64.NO_WRAP);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
package org.linusu;
|
|
2
|
+
|
|
3
|
+
import java.util.Arrays;
|
|
4
|
+
import java.util.Collections;
|
|
5
|
+
import java.util.List;
|
|
6
|
+
|
|
7
|
+
import com.facebook.react.ReactPackage;
|
|
8
|
+
import com.facebook.react.bridge.NativeModule;
|
|
9
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
10
|
+
import com.facebook.react.uimanager.ViewManager;
|
|
11
|
+
import com.facebook.react.bridge.JavaScriptModule;
|
|
12
|
+
|
|
13
|
+
public class RNGetRandomValuesPackage implements ReactPackage {
|
|
14
|
+
@Override
|
|
15
|
+
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
|
|
16
|
+
return Arrays.<NativeModule>asList(new RNGetRandomValuesModule(reactContext));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Deprecated from RN 0.47
|
|
20
|
+
public List<Class<? extends JavaScriptModule>> createJSModules() {
|
|
21
|
+
return Collections.emptyList();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@Override
|
|
25
|
+
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
|
|
26
|
+
return Collections.emptyList();
|
|
27
|
+
}
|
|
28
|
+
}
|