@os1-platform/dispatch-mobile 3.0.1 → 3.0.2

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.
@@ -4,7 +4,6 @@
4
4
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
5
5
  <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
6
6
  <uses-permission android:name="android.permission.WAKE_LOCK" />
7
- <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
8
7
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
9
8
  <uses-permission android:name="android.permission.CAMERA" />
10
9
  <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
@@ -10,81 +10,126 @@ import androidx.annotation.RequiresApi
10
10
  import androidx.core.content.ContextCompat
11
11
  import com.facebook.react.bridge.*
12
12
 
13
- class PermissionsModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
14
- companion object {
15
- private const val REQUEST_CODE_FOREGROUND = 1
16
- private const val REQUEST_CODE_BACKGROUND = 2
17
- }
13
+ class PermissionsModule(reactContext: ReactApplicationContext) :
14
+ ReactContextBaseJavaModule(reactContext) {
15
+ companion object {
16
+ private const val REQUEST_CODE_FOREGROUND = 1
17
+ private const val REQUEST_CODE_BACKGROUND = 2
18
+ }
18
19
 
19
- private var foregroundPromise: Promise? = null
20
- private var backgroundPromise: Promise? = null
20
+ private var foregroundPromise: Promise? = null
21
+ private var backgroundPromise: Promise? = null
22
+ private var wakeLockPromise: Promise? = null
21
23
 
22
- override fun getName(): String {
23
- return "PermissionsModule"
24
- }
24
+ override fun getName(): String {
25
+ return "PermissionsModule"
26
+ }
25
27
 
26
- private val requestForegroundPermissionLauncher = (reactContext.currentActivity as? ComponentActivity)?.registerForActivityResult(
27
- ActivityResultContracts.RequestPermission()
28
+ private val requestForegroundPermissionLauncher =
29
+ (reactContext.currentActivity as? ComponentActivity)?.registerForActivityResult(
30
+ ActivityResultContracts.RequestPermission()
28
31
  ) { isGranted: Boolean ->
29
- foregroundPromise?.let {
30
- if (isGranted) {
31
- it.resolve(true)
32
- } else {
33
- it.reject("Permission denied")
34
- }
35
- foregroundPromise = null
32
+ foregroundPromise?.let {
33
+ if (isGranted) {
34
+ it.resolve(true)
35
+ } else {
36
+ it.reject("Permission denied")
36
37
  }
38
+ foregroundPromise = null
39
+ }
37
40
  }
38
41
 
39
- private val requestBackgroundPermissionLauncher =
40
- (reactContext.currentActivity as? ComponentActivity)?.registerForActivityResult(
41
- ActivityResultContracts.RequestPermission()
42
- ) { isGranted: Boolean ->
43
- backgroundPromise?.let {
44
- if (isGranted) {
45
- it.resolve(true)
46
- } else {
47
- it.reject("Permission denied")
48
- }
49
- backgroundPromise = null
50
- }
51
- }
52
-
53
- @ReactMethod
54
- fun requestForegroundPermissions(promise: Promise) {
55
- val activity = currentActivity
56
- if (activity == null) {
57
- promise.reject("Activity doesn't exist")
58
- return
42
+ private val requestBackgroundPermissionLauncher =
43
+ (reactContext.currentActivity as? ComponentActivity)?.registerForActivityResult(
44
+ ActivityResultContracts.RequestPermission()
45
+ ) { isGranted: Boolean ->
46
+ backgroundPromise?.let {
47
+ if (isGranted) {
48
+ it.resolve(true)
49
+ } else {
50
+ it.reject("Permission denied")
59
51
  }
52
+ backgroundPromise = null
53
+ }
54
+ }
60
55
 
61
- if (ContextCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
62
- promise.resolve(true)
56
+ private val requestWakeLockPermissionLauncher =
57
+ (reactContext.currentActivity as? ComponentActivity)?.registerForActivityResult(
58
+ ActivityResultContracts.RequestPermission()
59
+ ) { isGranted: Boolean ->
60
+ wakeLockPromise?.let {
61
+ if (isGranted) {
62
+ it.resolve(true)
63
63
  } else {
64
- foregroundPromise = promise
65
- requestForegroundPermissionLauncher?.launch(Manifest.permission.ACCESS_FINE_LOCATION)
64
+ it.reject("Permission denied")
66
65
  }
66
+ wakeLockPromise = null
67
+ }
67
68
  }
68
69
 
69
- @ReactMethod
70
- fun requestBackgroundPermissions(promise: Promise) {
71
- val activity = currentActivity
72
- if (activity == null) {
73
- promise.reject("Activity doesn't exist")
74
- return
75
- }
70
+ @ReactMethod
71
+ fun requestForegroundPermissions(promise: Promise) {
72
+ val activity = currentActivity
73
+ if (activity == null) {
74
+ promise.reject("Activity doesn't exist")
75
+ return
76
+ }
76
77
 
77
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
78
- // For devices running Android versions below Q, background location permission is not needed.
79
- promise.resolve(true)
80
- return
81
- }
78
+ if (ContextCompat.checkSelfPermission(
79
+ activity,
80
+ Manifest.permission.ACCESS_FINE_LOCATION
81
+ ) == PackageManager.PERMISSION_GRANTED
82
+ ) {
83
+ promise.resolve(true)
84
+ } else {
85
+ foregroundPromise = promise
86
+ requestForegroundPermissionLauncher?.launch(Manifest.permission.ACCESS_FINE_LOCATION)
87
+ }
88
+ }
82
89
 
83
- if (ContextCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_BACKGROUND_LOCATION) == PackageManager.PERMISSION_GRANTED) {
84
- promise.resolve(true)
85
- } else {
86
- backgroundPromise = promise
87
- requestBackgroundPermissionLauncher?.launch(Manifest.permission.ACCESS_BACKGROUND_LOCATION)
88
- }
90
+ @ReactMethod
91
+ fun requestBackgroundPermissions(promise: Promise) {
92
+ val activity = currentActivity
93
+ if (activity == null) {
94
+ promise.reject("Activity doesn't exist")
95
+ return
96
+ }
97
+
98
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
99
+ // For devices running Android versions below Q, background location permission is not needed.
100
+ promise.resolve(true)
101
+ return
102
+ }
103
+
104
+ if (ContextCompat.checkSelfPermission(
105
+ activity,
106
+ Manifest.permission.ACCESS_BACKGROUND_LOCATION
107
+ ) == PackageManager.PERMISSION_GRANTED
108
+ ) {
109
+ promise.resolve(true)
110
+ } else {
111
+ backgroundPromise = promise
112
+ requestBackgroundPermissionLauncher?.launch(Manifest.permission.ACCESS_BACKGROUND_LOCATION)
113
+ }
114
+ }
115
+
116
+ @ReactMethod
117
+ fun requestWakeLockPermissions(promise: Promise) {
118
+ val activity = currentActivity
119
+ if (activity == null) {
120
+ promise.reject("Activity doesn't exist")
121
+ return
122
+ }
123
+
124
+ if (ContextCompat.checkSelfPermission(
125
+ activity,
126
+ Manifest.permission.WAKE_LOCK
127
+ ) == PackageManager.PERMISSION_GRANTED
128
+ ) {
129
+ promise.resolve(true)
130
+ } else {
131
+ wakeLockPromise = promise
132
+ requestWakeLockPermissionLauncher?.launch(Manifest.permission.WAKE_LOCK)
89
133
  }
90
- }
134
+ }
135
+ }
@@ -35,8 +35,9 @@ class SyncManagerService : Service() {
35
35
  val context: Context = applicationContext
36
36
  val myIntent = Intent(context, SyncEventService::class.java)
37
37
  context.startService(myIntent)
38
+
38
39
  HeadlessJsTaskService.acquireWakeLockNow(context)
39
- handler.postDelayed(this, interval)
40
+ // handler.postDelayed(this, interval)
40
41
  }
41
42
  }
42
43
 
@@ -48,14 +49,6 @@ class SyncManagerService : Service() {
48
49
  override fun onCreate() {
49
50
  Tracer.debug(TAG, "onCreate ")
50
51
  super.onCreate()
51
- createNotificationChannel()
52
- val notification: Notification = getNotification()
53
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU){
54
- startForeground(NOTIF_ID, notification)
55
- }else{
56
- startForeground(NOTIF_ID, notification, FOREGROUND_SERVICE_TYPE_DATA_SYNC)
57
- }
58
-
59
52
  }
60
53
 
61
54
  override fun onDestroy() {
@@ -64,18 +57,30 @@ class SyncManagerService : Service() {
64
57
  }
65
58
 
66
59
  override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
67
- Tracer.debug(TAG, "onStartCommand ")
68
- removeCallBacksIfAny()
69
- if (intent != null) {
70
- this.interval =
71
- intent.getDoubleExtra(ModuleConfig.IntentConfig.INTERVAL, ModuleConfig.DEFAULT_INTERVAL)
72
- .toLong()
73
- notifText = intent.getStringExtra(ModuleConfig.IntentConfig.N_TEXT) ?: notifText
74
- notifTitle = intent.getStringExtra(ModuleConfig.IntentConfig.N_TITLE) ?: notifTitle
60
+ try {
61
+ Tracer.debug(TAG, "onStartCommand ")
62
+ // we should call startForeground within 5 sec of the onStartCommand to avoid crashing of the service
63
+ createNotificationChannel()
64
+ val notification: Notification = getNotification()
65
+ updateNotification(notification)
66
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
67
+ startForeground(NOTIF_ID, notification, FOREGROUND_SERVICE_TYPE_DATA_SYNC)
68
+ } else {
69
+ startForeground(NOTIF_ID, notification)
70
+ }
71
+ //
72
+ removeCallBacksIfAny()
73
+ if (intent != null) {
74
+ this.interval =
75
+ intent.getDoubleExtra(ModuleConfig.IntentConfig.INTERVAL, ModuleConfig.DEFAULT_INTERVAL)
76
+ .toLong()
77
+ notifText = intent.getStringExtra(ModuleConfig.IntentConfig.N_TEXT) ?: notifText
78
+ notifTitle = intent.getStringExtra(ModuleConfig.IntentConfig.N_TITLE) ?: notifTitle
79
+ }
80
+ handler.post(runnableCode)
81
+ } catch (e: Exception) {
82
+ Tracer.debug(TAG, "onStartCommand ${e.message}")
75
83
  }
76
- handler.post(runnableCode)
77
- val notification: Notification = getNotification()
78
- updateNotification(notification)
79
84
  return START_STICKY
80
85
  }
81
86
 
@@ -90,9 +95,12 @@ class SyncManagerService : Service() {
90
95
  }
91
96
 
92
97
  private fun getNotification(): Notification {
93
- val channelId =
94
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) ModuleConfig.SYNC_CHANNEL_ID else ""
95
- val notificationBuilder = NotificationCompat.Builder(this, channelId)
98
+ //
99
+ val notificationBuilder = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
100
+ NotificationCompat.Builder(this, ModuleConfig.SYNC_CHANNEL_ID)
101
+ } else {
102
+ NotificationCompat.Builder(this)
103
+ }
96
104
  val bigTextStyle = NotificationCompat.BigTextStyle()
97
105
  bigTextStyle.setBigContentTitle(notifTitle)
98
106
  bigTextStyle.bigText(notifText)
@@ -14,8 +14,12 @@ const requestForegroundPermissions = async () => {
14
14
  const requestBackgroundPermissions = async () => {
15
15
  return PermissionsModule.requestBackgroundPermissions();
16
16
  };
17
+ const requestWakeLockPermissions = async () => {
18
+ return PermissionsModule.requestWakeLockPermissions();
19
+ };
17
20
  var _default = exports.default = {
18
21
  requestForegroundPermissions,
19
- requestBackgroundPermissions
22
+ requestBackgroundPermissions,
23
+ requestWakeLockPermissions
20
24
  };
21
25
  //# sourceMappingURL=PermissionModule.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_reactNative","require","PermissionsModule","NativeModules","requestForegroundPermissions","requestBackgroundPermissions","_default","exports","default"],"sources":["PermissionModule.ts"],"sourcesContent":["import { NativeModules } from 'react-native';\n\nconst { PermissionsModule } = NativeModules;\n\ninterface PermissionsModuleType {\n requestForegroundPermissions: () => Promise<boolean>;\n requestBackgroundPermissions: () => Promise<boolean>;\n}\n\nconst requestForegroundPermissions = async (): Promise<boolean> => {\n return PermissionsModule.requestForegroundPermissions();\n};\n\nconst requestBackgroundPermissions = async (): Promise<boolean> => {\n return PermissionsModule.requestBackgroundPermissions();\n};\n\nexport default {\n requestForegroundPermissions,\n requestBackgroundPermissions,\n} as PermissionsModuleType;"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,MAAM;EAAEC;AAAkB,CAAC,GAAGC,0BAAa;AAO3C,MAAMC,4BAA4B,GAAG,MAAAA,CAAA,KAA8B;EAC/D,OAAOF,iBAAiB,CAACE,4BAA4B,CAAC,CAAC;AAC3D,CAAC;AAED,MAAMC,4BAA4B,GAAG,MAAAA,CAAA,KAA8B;EAC/D,OAAOH,iBAAiB,CAACG,4BAA4B,CAAC,CAAC;AAC3D,CAAC;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEa;EACXJ,4BAA4B;EAC5BC;AACJ,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["_reactNative","require","PermissionsModule","NativeModules","requestForegroundPermissions","requestBackgroundPermissions","requestWakeLockPermissions","_default","exports","default"],"sources":["PermissionModule.ts"],"sourcesContent":["import { NativeModules } from 'react-native';\n\nconst { PermissionsModule } = NativeModules;\n\ninterface PermissionsModuleType {\n requestForegroundPermissions: () => Promise<boolean>;\n requestBackgroundPermissions: () => Promise<boolean>;\n requestWakeLockPermissions: () => Promise<boolean>;\n}\n\nconst requestForegroundPermissions = async (): Promise<boolean> => {\n return PermissionsModule.requestForegroundPermissions();\n};\n\nconst requestBackgroundPermissions = async (): Promise<boolean> => {\n return PermissionsModule.requestBackgroundPermissions();\n};\n\nconst requestWakeLockPermissions = async (): Promise<boolean> => {\n return PermissionsModule.requestWakeLockPermissions();\n};\n\nexport default {\n requestForegroundPermissions,\n requestBackgroundPermissions,\n requestWakeLockPermissions\n} as PermissionsModuleType;"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,MAAM;EAAEC;AAAkB,CAAC,GAAGC,0BAAa;AAQ3C,MAAMC,4BAA4B,GAAG,MAAAA,CAAA,KAA8B;EAC/D,OAAOF,iBAAiB,CAACE,4BAA4B,CAAC,CAAC;AAC3D,CAAC;AAED,MAAMC,4BAA4B,GAAG,MAAAA,CAAA,KAA8B;EAC/D,OAAOH,iBAAiB,CAACG,4BAA4B,CAAC,CAAC;AAC3D,CAAC;AAED,MAAMC,0BAA0B,GAAG,MAAAA,CAAA,KAA8B;EAC7D,OAAOJ,iBAAiB,CAACI,0BAA0B,CAAC,CAAC;AACzD,CAAC;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEa;EACXL,4BAA4B;EAC5BC,4BAA4B;EAC5BC;AACJ,CAAC","ignoreList":[]}
@@ -101,6 +101,7 @@ class SdkUtils {
101
101
  throw new _BaseError.BaseError(_ErrorCodes.default.SYSTEM_TIME_CHECK_FAILED, 'Automatic date/time not enabled!');
102
102
  }
103
103
  if (_reactNative.Platform.OS === 'android') {
104
+ await _PermissionModule.default.requestWakeLockPermissions();
104
105
  await Location.enableNetworkProviderAsync();
105
106
  let locationServicesCheck = await Location.hasServicesEnabledAsync();
106
107
  const foregroundLocation = await _PermissionModule.default.requestForegroundPermissions();
@@ -1 +1 @@
1
- {"version":3,"names":["_remoteConfig","_interopRequireDefault","require","_Logger","_interopRequireWildcard","FileSystem","_reactNative","Location","_NetworkUtil","_BaseError","_ErrorCodes","_PermissionModule","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","DispatchSdkUtils","NativeModules","exports","DispatchUtilsInterface","SdkUtils","getRemoteConfig","expiration","Promise","resolve","reject","remoteConfig","fetch","setDefaults","cxRumDevApiKey","cxRumProdApiKey","isMandatoryUpdate","isMandatoryUpdateiOS","toggleInAppUpdateiOS","toggleInAppUpdate","then","fetchAndActivate","fetchedRemotely","config","getAll","Logger","getInstance","logEvent","LOG_TYPE","SDK_INFO","catch","err","error","downloadAPK","apkURL","version","callback","fileUri","cacheDirectory","fileInfo","getInfoAsync","currentDate","Date","toLocaleDateString","fileDate","modificationTime","exists","uri","downloadResumable","createDownloadResumable","downloadResult","downloadAsync","deleteApk","deleteAsync","openAPKFile","openAndInstallApk","openAppSettings","openSettings","message","SDK_ERROR","checkMandatory","Platform","OS","foregroundLocation","PermissionModule","requestForegroundPermissions","BaseError","ErrorCodes","LOCATION_OR_GPS_NOT_ENABLED","dateTimeCheck","isAutomaticDateTimeEnabled","SYSTEM_TIME_CHECK_FAILED","enableNetworkProviderAsync","locationServicesCheck","hasServicesEnabledAsync","bgLocation","requestBackgroundPermissions","internet","NetworkUtil","isAvailableAsync","INTERNET_NOT_ENABLED"],"sources":["SdkUtils.ts"],"sourcesContent":["import remoteConfig from '@react-native-firebase/remote-config';\nimport Logger, { LOG_TYPE } from './Logger';\nimport type { DownloadProgressData } from 'expo-file-system';\nimport * as FileSystem from 'expo-file-system';\nimport { NativeModules, Platform } from 'react-native';\nimport * as Location from 'expo-location';\nimport NetworkUtil from './NetworkUtil';\nimport { BaseError } from '../errors/BaseError';\nimport ErrorCodes from '../errors/ErrorCodes';\nimport PermissionModule from '../native/PermissionModule';\n\nconst { DispatchSdkUtils } = NativeModules;\n\ninterface DispatchUtilsInterface {\n openAndInstallApk(apkUri: String): Promise<boolean>;\n openSettings(): Promise<boolean>;\n showAndroidDialog(\n title: string,\n message: string,\n positiveText: string,\n negativeText: string | null,\n cancelable: boolean\n ): Promise<boolean>;\n isAutomaticDateTimeEnabled(): Promise<boolean>;\n}\n\nexport { DispatchSdkUtils as DispatchUtilsInterface };\n\nexport default class SdkUtils {\n /**\n * number of seconds to cache the firebase config\n * @param expiration\n */\n static async getRemoteConfig(expiration: number): Promise<any> {\n return new Promise(async (resolve, reject) => {\n try {\n await remoteConfig().fetch(expiration);\n remoteConfig()\n .setDefaults({\n cxRumDevApiKey: 'NA',\n cxRumProdApiKey: 'NA',\n isMandatoryUpdate: 'false',\n isMandatoryUpdateiOS: 'false',\n toggleInAppUpdateiOS: 'false',\n toggleInAppUpdate: 'false',\n })\n .then(() => remoteConfig().fetchAndActivate())\n .then((fetchedRemotely) => {\n let config = remoteConfig().getAll();\n if (fetchedRemotely) {\n Logger.getInstance().logEvent(\n 'Remote Config',\n 'Configs were retrieved from the backend and activated.',\n LOG_TYPE.SDK_INFO\n );\n resolve(config);\n } else {\n Logger.getInstance().logEvent(\n 'Remote Config',\n 'No configs were fetched from the backend, and the local configs were already activated',\n LOG_TYPE.SDK_INFO\n );\n resolve(config);\n }\n })\n .catch((err) => {\n reject(err);\n });\n } catch (error: any) {\n reject(error);\n }\n });\n }\n\n /**\n * Function to download apk file from a public URL\n * @param apkURL - URL where apk is hosted\n * @param version - expected version of apk (used for naming the file)\n * @param callback - callback for getting progress of download\n */\n public static async downloadAPK(\n apkURL: string,\n version: string,\n callback: (progress: DownloadProgressData) => any\n ): Promise<string | undefined> {\n const fileUri = FileSystem.cacheDirectory + `${version}.apk`;\n const fileInfo = await FileSystem.getInfoAsync(fileUri);\n const currentDate = new Date().toLocaleDateString();\n const fileDate = new Date(\n fileInfo.modificationTime ? fileInfo.modificationTime * 1000 : 0\n ).toLocaleDateString();\n if (fileInfo.exists && currentDate === fileDate) {\n return fileInfo.uri;\n }\n const downloadResumable = FileSystem.createDownloadResumable(\n apkURL,\n FileSystem.cacheDirectory + `${version}.apk`,\n {},\n callback\n );\n const downloadResult = await downloadResumable.downloadAsync();\n return downloadResult?.uri;\n }\n\n /**\n * Opens & Install an APK file\n * @param uri - source of apk file\n */\n public static async deleteApk(version: string) {\n await FileSystem.deleteAsync(FileSystem.cacheDirectory + `${version}.apk`);\n }\n\n public static async openAPKFile(uri: string) {\n return await (DispatchSdkUtils as DispatchUtilsInterface).openAndInstallApk(\n uri\n );\n }\n\n public static openAppSettings() {\n (DispatchSdkUtils as DispatchUtilsInterface)\n .openSettings()\n .then()\n .catch((error) => {\n Logger.getInstance().logEvent(\n 'Intent error',\n error.message,\n LOG_TYPE.SDK_ERROR\n );\n });\n }\n\n public static async checkMandatory() {\n if (Platform.OS === 'ios'){\n const foregroundLocation = await PermissionModule.requestForegroundPermissions();\n if (!(foregroundLocation)) {\n throw new BaseError(\n ErrorCodes.LOCATION_OR_GPS_NOT_ENABLED,\n 'Location or GPS not enabled'\n );\n }\n return;\n }\n const dateTimeCheck = await (\n DispatchSdkUtils as DispatchUtilsInterface\n ).isAutomaticDateTimeEnabled();\n if (!dateTimeCheck) {\n throw new BaseError(\n ErrorCodes.SYSTEM_TIME_CHECK_FAILED,\n 'Automatic date/time not enabled!'\n );\n }\n if (Platform.OS === 'android') {\n await Location.enableNetworkProviderAsync();\n let locationServicesCheck = await Location.hasServicesEnabledAsync();\n const foregroundLocation = await PermissionModule.requestForegroundPermissions();\n // await Location.requestForegroundPermissionsAsync(); //permission code using expo module\n const bgLocation = await PermissionModule.requestBackgroundPermissions();\n // await Location.requestBackgroundPermissionsAsync(); //permission code using expo module\n if (!(locationServicesCheck && foregroundLocation && bgLocation)) {\n throw new BaseError(\n ErrorCodes.LOCATION_OR_GPS_NOT_ENABLED,\n 'Location or GPS not enabled'\n );\n }\n }\n let internet = await NetworkUtil.isAvailableAsync();\n if (!internet)\n throw new BaseError(\n ErrorCodes.INTERNET_NOT_ENABLED,\n 'Internet is disabled! Please enable internet and try again '\n );\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,aAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAC,uBAAA,CAAAF,OAAA;AAEA,IAAAG,UAAA,GAAAD,uBAAA,CAAAF,OAAA;AACA,IAAAI,YAAA,GAAAJ,OAAA;AACA,IAAAK,QAAA,GAAAH,uBAAA,CAAAF,OAAA;AACA,IAAAM,YAAA,GAAAP,sBAAA,CAAAC,OAAA;AACA,IAAAO,UAAA,GAAAP,OAAA;AACA,IAAAQ,WAAA,GAAAT,sBAAA,CAAAC,OAAA;AACA,IAAAS,iBAAA,GAAAV,sBAAA,CAAAC,OAAA;AAA0D,SAAAU,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAT,wBAAAS,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA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,mBAAU,CAACI,wBAAwB,EACnC,kCACF,CAAC;IACH;IACA,IAAIV,qBAAQ,CAACC,EAAE,KAAK,SAAS,EAAE;MAC7B,MAAMtF,QAAQ,CAACgG,0BAA0B,CAAC,CAAC;MAC3C,IAAIC,qBAAqB,GAAG,MAAMjG,QAAQ,CAACkG,uBAAuB,CAAC,CAAC;MACpE,MAAMX,kBAAkB,GAAG,MAAMC,yBAAgB,CAACC,4BAA4B,CAAC,CAAC;MAChF;MACA,MAAMU,UAAU,GAAG,MAAMX,yBAAgB,CAACY,4BAA4B,CAAC,CAAC;MACxE;MACA,IAAI,EAAEH,qBAAqB,IAAIV,kBAAkB,IAAIY,UAAU,CAAC,EAAE;QAChE,MAAM,IAAIT,oBAAS,CACjBC,mBAAU,CAACC,2BAA2B,EACtC,6BACF,CAAC;MACH;IACF;IACA,IAAIS,QAAQ,GAAG,MAAMC,oBAAW,CAACC,gBAAgB,CAAC,CAAC;IACnD,IAAI,CAACF,QAAQ,EACX,MAAM,IAAIX,oBAAS,CACjBC,mBAAU,CAACa,oBAAoB,EAC/B,6DACF,CAAC;EACL;AACF;AAAC7E,OAAA,CAAAhB,OAAA,GAAAkB,QAAA","ignoreList":[]}
1
+ {"version":3,"names":["_remoteConfig","_interopRequireDefault","require","_Logger","_interopRequireWildcard","FileSystem","_reactNative","Location","_NetworkUtil","_BaseError","_ErrorCodes","_PermissionModule","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","DispatchSdkUtils","NativeModules","exports","DispatchUtilsInterface","SdkUtils","getRemoteConfig","expiration","Promise","resolve","reject","remoteConfig","fetch","setDefaults","cxRumDevApiKey","cxRumProdApiKey","isMandatoryUpdate","isMandatoryUpdateiOS","toggleInAppUpdateiOS","toggleInAppUpdate","then","fetchAndActivate","fetchedRemotely","config","getAll","Logger","getInstance","logEvent","LOG_TYPE","SDK_INFO","catch","err","error","downloadAPK","apkURL","version","callback","fileUri","cacheDirectory","fileInfo","getInfoAsync","currentDate","Date","toLocaleDateString","fileDate","modificationTime","exists","uri","downloadResumable","createDownloadResumable","downloadResult","downloadAsync","deleteApk","deleteAsync","openAPKFile","openAndInstallApk","openAppSettings","openSettings","message","SDK_ERROR","checkMandatory","Platform","OS","foregroundLocation","PermissionModule","requestForegroundPermissions","BaseError","ErrorCodes","LOCATION_OR_GPS_NOT_ENABLED","dateTimeCheck","isAutomaticDateTimeEnabled","SYSTEM_TIME_CHECK_FAILED","requestWakeLockPermissions","enableNetworkProviderAsync","locationServicesCheck","hasServicesEnabledAsync","bgLocation","requestBackgroundPermissions","internet","NetworkUtil","isAvailableAsync","INTERNET_NOT_ENABLED"],"sources":["SdkUtils.ts"],"sourcesContent":["import remoteConfig from '@react-native-firebase/remote-config';\nimport Logger, { LOG_TYPE } from './Logger';\nimport type { DownloadProgressData } from 'expo-file-system';\nimport * as FileSystem from 'expo-file-system';\nimport { NativeModules, Platform } from 'react-native';\nimport * as Location from 'expo-location';\nimport NetworkUtil from './NetworkUtil';\nimport { BaseError } from '../errors/BaseError';\nimport ErrorCodes from '../errors/ErrorCodes';\nimport PermissionModule from '../native/PermissionModule';\n\nconst { DispatchSdkUtils } = NativeModules;\n\ninterface DispatchUtilsInterface {\n openAndInstallApk(apkUri: String): Promise<boolean>;\n openSettings(): Promise<boolean>;\n showAndroidDialog(\n title: string,\n message: string,\n positiveText: string,\n negativeText: string | null,\n cancelable: boolean\n ): Promise<boolean>;\n isAutomaticDateTimeEnabled(): Promise<boolean>;\n}\n\nexport { DispatchSdkUtils as DispatchUtilsInterface };\n\nexport default class SdkUtils {\n /**\n * number of seconds to cache the firebase config\n * @param expiration\n */\n static async getRemoteConfig(expiration: number): Promise<any> {\n return new Promise(async (resolve, reject) => {\n try {\n await remoteConfig().fetch(expiration);\n remoteConfig()\n .setDefaults({\n cxRumDevApiKey: 'NA',\n cxRumProdApiKey: 'NA',\n isMandatoryUpdate: 'false',\n isMandatoryUpdateiOS: 'false',\n toggleInAppUpdateiOS: 'false',\n toggleInAppUpdate: 'false',\n })\n .then(() => remoteConfig().fetchAndActivate())\n .then((fetchedRemotely) => {\n let config = remoteConfig().getAll();\n if (fetchedRemotely) {\n Logger.getInstance().logEvent(\n 'Remote Config',\n 'Configs were retrieved from the backend and activated.',\n LOG_TYPE.SDK_INFO\n );\n resolve(config);\n } else {\n Logger.getInstance().logEvent(\n 'Remote Config',\n 'No configs were fetched from the backend, and the local configs were already activated',\n LOG_TYPE.SDK_INFO\n );\n resolve(config);\n }\n })\n .catch((err) => {\n reject(err);\n });\n } catch (error: any) {\n reject(error);\n }\n });\n }\n\n /**\n * Function to download apk file from a public URL\n * @param apkURL - URL where apk is hosted\n * @param version - expected version of apk (used for naming the file)\n * @param callback - callback for getting progress of download\n */\n public static async downloadAPK(\n apkURL: string,\n version: string,\n callback: (progress: DownloadProgressData) => any\n ): Promise<string | undefined> {\n const fileUri = FileSystem.cacheDirectory + `${version}.apk`;\n const fileInfo = await FileSystem.getInfoAsync(fileUri);\n const currentDate = new Date().toLocaleDateString();\n const fileDate = new Date(\n fileInfo.modificationTime ? fileInfo.modificationTime * 1000 : 0\n ).toLocaleDateString();\n if (fileInfo.exists && currentDate === fileDate) {\n return fileInfo.uri;\n }\n const downloadResumable = FileSystem.createDownloadResumable(\n apkURL,\n FileSystem.cacheDirectory + `${version}.apk`,\n {},\n callback\n );\n const downloadResult = await downloadResumable.downloadAsync();\n return downloadResult?.uri;\n }\n\n /**\n * Opens & Install an APK file\n * @param uri - source of apk file\n */\n public static async deleteApk(version: string) {\n await FileSystem.deleteAsync(FileSystem.cacheDirectory + `${version}.apk`);\n }\n\n public static async openAPKFile(uri: string) {\n return await (DispatchSdkUtils as DispatchUtilsInterface).openAndInstallApk(\n uri\n );\n }\n\n public static openAppSettings() {\n (DispatchSdkUtils as DispatchUtilsInterface)\n .openSettings()\n .then()\n .catch((error) => {\n Logger.getInstance().logEvent(\n 'Intent error',\n error.message,\n LOG_TYPE.SDK_ERROR\n );\n });\n }\n\n public static async checkMandatory() {\n if (Platform.OS === 'ios') {\n const foregroundLocation = await PermissionModule.requestForegroundPermissions();\n if (!(foregroundLocation)) {\n throw new BaseError(\n ErrorCodes.LOCATION_OR_GPS_NOT_ENABLED,\n 'Location or GPS not enabled'\n );\n }\n return;\n }\n const dateTimeCheck = await (\n DispatchSdkUtils as DispatchUtilsInterface\n ).isAutomaticDateTimeEnabled();\n if (!dateTimeCheck) {\n throw new BaseError(\n ErrorCodes.SYSTEM_TIME_CHECK_FAILED,\n 'Automatic date/time not enabled!'\n );\n }\n if (Platform.OS === 'android') {\n await PermissionModule.requestWakeLockPermissions();\n await Location.enableNetworkProviderAsync();\n let locationServicesCheck = await Location.hasServicesEnabledAsync();\n const foregroundLocation = await PermissionModule.requestForegroundPermissions();\n // await Location.requestForegroundPermissionsAsync(); //permission code using expo module\n const bgLocation = await PermissionModule.requestBackgroundPermissions();\n // await Location.requestBackgroundPermissionsAsync(); //permission code using expo module\n if (!(locationServicesCheck && foregroundLocation && bgLocation)) {\n throw new BaseError(\n ErrorCodes.LOCATION_OR_GPS_NOT_ENABLED,\n 'Location or GPS not enabled'\n );\n }\n }\n let internet = await NetworkUtil.isAvailableAsync();\n if (!internet)\n throw new BaseError(\n ErrorCodes.INTERNET_NOT_ENABLED,\n 'Internet is disabled! Please enable internet and try again '\n );\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,aAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAC,uBAAA,CAAAF,OAAA;AAEA,IAAAG,UAAA,GAAAD,uBAAA,CAAAF,OAAA;AACA,IAAAI,YAAA,GAAAJ,OAAA;AACA,IAAAK,QAAA,GAAAH,uBAAA,CAAAF,OAAA;AACA,IAAAM,YAAA,GAAAP,sBAAA,CAAAC,OAAA;AACA,IAAAO,UAAA,GAAAP,OAAA;AACA,IAAAQ,WAAA,GAAAT,sBAAA,CAAAC,OAAA;AACA,I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oBAAW,CAACC,gBAAgB,CAAC,CAAC;IACnD,IAAI,CAACF,QAAQ,EACX,MAAM,IAAIZ,oBAAS,CACjBC,mBAAU,CAACc,oBAAoB,EAC/B,6DACF,CAAC;EACL;AACF;AAAC9E,OAAA,CAAAhB,OAAA,GAAAkB,QAAA","ignoreList":[]}
@@ -8,8 +8,12 @@ const requestForegroundPermissions = async () => {
8
8
  const requestBackgroundPermissions = async () => {
9
9
  return PermissionsModule.requestBackgroundPermissions();
10
10
  };
11
+ const requestWakeLockPermissions = async () => {
12
+ return PermissionsModule.requestWakeLockPermissions();
13
+ };
11
14
  export default {
12
15
  requestForegroundPermissions,
13
- requestBackgroundPermissions
16
+ requestBackgroundPermissions,
17
+ requestWakeLockPermissions
14
18
  };
15
19
  //# sourceMappingURL=PermissionModule.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["NativeModules","PermissionsModule","requestForegroundPermissions","requestBackgroundPermissions"],"sources":["PermissionModule.ts"],"sourcesContent":["import { NativeModules } from 'react-native';\n\nconst { PermissionsModule } = NativeModules;\n\ninterface PermissionsModuleType {\n requestForegroundPermissions: () => Promise<boolean>;\n requestBackgroundPermissions: () => Promise<boolean>;\n}\n\nconst requestForegroundPermissions = async (): Promise<boolean> => {\n return PermissionsModule.requestForegroundPermissions();\n};\n\nconst requestBackgroundPermissions = async (): Promise<boolean> => {\n return PermissionsModule.requestBackgroundPermissions();\n};\n\nexport default {\n requestForegroundPermissions,\n requestBackgroundPermissions,\n} as PermissionsModuleType;"],"mappings":"AAAA,SAASA,aAAa,QAAQ,cAAc;AAE5C,MAAM;EAAEC;AAAkB,CAAC,GAAGD,aAAa;AAO3C,MAAME,4BAA4B,GAAG,MAAAA,CAAA,KAA8B;EAC/D,OAAOD,iBAAiB,CAACC,4BAA4B,CAAC,CAAC;AAC3D,CAAC;AAED,MAAMC,4BAA4B,GAAG,MAAAA,CAAA,KAA8B;EAC/D,OAAOF,iBAAiB,CAACE,4BAA4B,CAAC,CAAC;AAC3D,CAAC;AAED,eAAe;EACXD,4BAA4B;EAC5BC;AACJ,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["NativeModules","PermissionsModule","requestForegroundPermissions","requestBackgroundPermissions","requestWakeLockPermissions"],"sources":["PermissionModule.ts"],"sourcesContent":["import { NativeModules } from 'react-native';\n\nconst { PermissionsModule } = NativeModules;\n\ninterface PermissionsModuleType {\n requestForegroundPermissions: () => Promise<boolean>;\n requestBackgroundPermissions: () => Promise<boolean>;\n requestWakeLockPermissions: () => Promise<boolean>;\n}\n\nconst requestForegroundPermissions = async (): Promise<boolean> => {\n return PermissionsModule.requestForegroundPermissions();\n};\n\nconst requestBackgroundPermissions = async (): Promise<boolean> => {\n return PermissionsModule.requestBackgroundPermissions();\n};\n\nconst requestWakeLockPermissions = async (): Promise<boolean> => {\n return PermissionsModule.requestWakeLockPermissions();\n};\n\nexport default {\n requestForegroundPermissions,\n requestBackgroundPermissions,\n requestWakeLockPermissions\n} as PermissionsModuleType;"],"mappings":"AAAA,SAASA,aAAa,QAAQ,cAAc;AAE5C,MAAM;EAAEC;AAAkB,CAAC,GAAGD,aAAa;AAQ3C,MAAME,4BAA4B,GAAG,MAAAA,CAAA,KAA8B;EAC/D,OAAOD,iBAAiB,CAACC,4BAA4B,CAAC,CAAC;AAC3D,CAAC;AAED,MAAMC,4BAA4B,GAAG,MAAAA,CAAA,KAA8B;EAC/D,OAAOF,iBAAiB,CAACE,4BAA4B,CAAC,CAAC;AAC3D,CAAC;AAED,MAAMC,0BAA0B,GAAG,MAAAA,CAAA,KAA8B;EAC7D,OAAOH,iBAAiB,CAACG,0BAA0B,CAAC,CAAC;AACzD,CAAC;AAED,eAAe;EACXF,4BAA4B;EAC5BC,4BAA4B;EAC5BC;AACJ,CAAC","ignoreList":[]}
@@ -92,6 +92,7 @@ export default class SdkUtils {
92
92
  throw new BaseError(ErrorCodes.SYSTEM_TIME_CHECK_FAILED, 'Automatic date/time not enabled!');
93
93
  }
94
94
  if (Platform.OS === 'android') {
95
+ await PermissionModule.requestWakeLockPermissions();
95
96
  await Location.enableNetworkProviderAsync();
96
97
  let locationServicesCheck = await Location.hasServicesEnabledAsync();
97
98
  const foregroundLocation = await PermissionModule.requestForegroundPermissions();
@@ -1 +1 @@
1
- {"version":3,"names":["remoteConfig","Logger","LOG_TYPE","FileSystem","NativeModules","Platform","Location","NetworkUtil","BaseError","ErrorCodes","PermissionModule","DispatchSdkUtils","DispatchUtilsInterface","SdkUtils","getRemoteConfig","expiration","Promise","resolve","reject","fetch","setDefaults","cxRumDevApiKey","cxRumProdApiKey","isMandatoryUpdate","isMandatoryUpdateiOS","toggleInAppUpdateiOS","toggleInAppUpdate","then","fetchAndActivate","fetchedRemotely","config","getAll","getInstance","logEvent","SDK_INFO","catch","err","error","downloadAPK","apkURL","version","callback","fileUri","cacheDirectory","fileInfo","getInfoAsync","currentDate","Date","toLocaleDateString","fileDate","modificationTime","exists","uri","downloadResumable","createDownloadResumable","downloadResult","downloadAsync","deleteApk","deleteAsync","openAPKFile","openAndInstallApk","openAppSettings","openSettings","message","SDK_ERROR","checkMandatory","OS","foregroundLocation","requestForegroundPermissions","LOCATION_OR_GPS_NOT_ENABLED","dateTimeCheck","isAutomaticDateTimeEnabled","SYSTEM_TIME_CHECK_FAILED","enableNetworkProviderAsync","locationServicesCheck","hasServicesEnabledAsync","bgLocation","requestBackgroundPermissions","internet","isAvailableAsync","INTERNET_NOT_ENABLED"],"sources":["SdkUtils.ts"],"sourcesContent":["import remoteConfig from '@react-native-firebase/remote-config';\nimport Logger, { LOG_TYPE } from './Logger';\nimport type { DownloadProgressData } from 'expo-file-system';\nimport * as FileSystem from 'expo-file-system';\nimport { NativeModules, Platform } from 'react-native';\nimport * as Location from 'expo-location';\nimport NetworkUtil from './NetworkUtil';\nimport { BaseError } from '../errors/BaseError';\nimport ErrorCodes from '../errors/ErrorCodes';\nimport PermissionModule from '../native/PermissionModule';\n\nconst { DispatchSdkUtils } = NativeModules;\n\ninterface DispatchUtilsInterface {\n openAndInstallApk(apkUri: String): Promise<boolean>;\n openSettings(): Promise<boolean>;\n showAndroidDialog(\n title: string,\n message: string,\n positiveText: string,\n negativeText: string | null,\n cancelable: boolean\n ): Promise<boolean>;\n isAutomaticDateTimeEnabled(): Promise<boolean>;\n}\n\nexport { DispatchSdkUtils as DispatchUtilsInterface };\n\nexport default class SdkUtils {\n /**\n * number of seconds to cache the firebase config\n * @param expiration\n */\n static async getRemoteConfig(expiration: number): Promise<any> {\n return new Promise(async (resolve, reject) => {\n try {\n await remoteConfig().fetch(expiration);\n remoteConfig()\n .setDefaults({\n cxRumDevApiKey: 'NA',\n cxRumProdApiKey: 'NA',\n isMandatoryUpdate: 'false',\n isMandatoryUpdateiOS: 'false',\n toggleInAppUpdateiOS: 'false',\n toggleInAppUpdate: 'false',\n })\n .then(() => remoteConfig().fetchAndActivate())\n .then((fetchedRemotely) => {\n let config = remoteConfig().getAll();\n if (fetchedRemotely) {\n Logger.getInstance().logEvent(\n 'Remote Config',\n 'Configs were retrieved from the backend and activated.',\n LOG_TYPE.SDK_INFO\n );\n resolve(config);\n } else {\n Logger.getInstance().logEvent(\n 'Remote Config',\n 'No configs were fetched from the backend, and the local configs were already activated',\n LOG_TYPE.SDK_INFO\n );\n resolve(config);\n }\n })\n .catch((err) => {\n reject(err);\n });\n } catch (error: any) {\n reject(error);\n }\n });\n }\n\n /**\n * Function to download apk file from a public URL\n * @param apkURL - URL where apk is hosted\n * @param version - expected version of apk (used for naming the file)\n * @param callback - callback for getting progress of download\n */\n public static async downloadAPK(\n apkURL: string,\n version: string,\n callback: (progress: DownloadProgressData) => any\n ): Promise<string | undefined> {\n const fileUri = FileSystem.cacheDirectory + `${version}.apk`;\n const fileInfo = await FileSystem.getInfoAsync(fileUri);\n const currentDate = new Date().toLocaleDateString();\n const fileDate = new Date(\n fileInfo.modificationTime ? fileInfo.modificationTime * 1000 : 0\n ).toLocaleDateString();\n if (fileInfo.exists && currentDate === fileDate) {\n return fileInfo.uri;\n }\n const downloadResumable = FileSystem.createDownloadResumable(\n apkURL,\n FileSystem.cacheDirectory + `${version}.apk`,\n {},\n callback\n );\n const downloadResult = await downloadResumable.downloadAsync();\n return downloadResult?.uri;\n }\n\n /**\n * Opens & Install an APK file\n * @param uri - source of apk file\n */\n public static async deleteApk(version: string) {\n await FileSystem.deleteAsync(FileSystem.cacheDirectory + `${version}.apk`);\n }\n\n public static async openAPKFile(uri: string) {\n return await (DispatchSdkUtils as DispatchUtilsInterface).openAndInstallApk(\n uri\n );\n }\n\n public static openAppSettings() {\n (DispatchSdkUtils as DispatchUtilsInterface)\n .openSettings()\n .then()\n .catch((error) => {\n Logger.getInstance().logEvent(\n 'Intent error',\n error.message,\n LOG_TYPE.SDK_ERROR\n );\n });\n }\n\n public static async checkMandatory() {\n if (Platform.OS === 'ios'){\n const foregroundLocation = await PermissionModule.requestForegroundPermissions();\n if (!(foregroundLocation)) {\n throw new BaseError(\n ErrorCodes.LOCATION_OR_GPS_NOT_ENABLED,\n 'Location or GPS not enabled'\n );\n }\n return;\n }\n const dateTimeCheck = await (\n DispatchSdkUtils as DispatchUtilsInterface\n ).isAutomaticDateTimeEnabled();\n if (!dateTimeCheck) {\n throw new BaseError(\n ErrorCodes.SYSTEM_TIME_CHECK_FAILED,\n 'Automatic date/time not enabled!'\n );\n }\n if (Platform.OS === 'android') {\n await Location.enableNetworkProviderAsync();\n let locationServicesCheck = await Location.hasServicesEnabledAsync();\n const foregroundLocation = await PermissionModule.requestForegroundPermissions();\n // await Location.requestForegroundPermissionsAsync(); //permission code using expo module\n const bgLocation = await PermissionModule.requestBackgroundPermissions();\n // await Location.requestBackgroundPermissionsAsync(); //permission code using expo module\n if (!(locationServicesCheck && foregroundLocation && bgLocation)) {\n throw new BaseError(\n ErrorCodes.LOCATION_OR_GPS_NOT_ENABLED,\n 'Location or GPS not enabled'\n );\n }\n }\n let internet = await NetworkUtil.isAvailableAsync();\n if (!internet)\n throw new BaseError(\n ErrorCodes.INTERNET_NOT_ENABLED,\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BAAuB,CAAC,CAAC;MACpE,MAAMR,kBAAkB,GAAG,MAAMzD,gBAAgB,CAAC0D,4BAA4B,CAAC,CAAC;MAChF;MACA,MAAMQ,UAAU,GAAG,MAAMlE,gBAAgB,CAACmE,4BAA4B,CAAC,CAAC;MACxE;MACA,IAAI,EAAEH,qBAAqB,IAAIP,kBAAkB,IAAIS,UAAU,CAAC,EAAE;QAChE,MAAM,IAAIpE,SAAS,CACjBC,UAAU,CAAC4D,2BAA2B,EACtC,6BACF,CAAC;MACH;IACF;IACA,IAAIS,QAAQ,GAAG,MAAMvE,WAAW,CAACwE,gBAAgB,CAAC,CAAC;IACnD,IAAI,CAACD,QAAQ,EACX,MAAM,IAAItE,SAAS,CACjBC,UAAU,CAACuE,oBAAoB,EAC/B,6DACF,CAAC;EACL;AACF","ignoreList":[]}
1
+ {"version":3,"names":["remoteConfig","Logger","LOG_TYPE","FileSystem","NativeModules","Platform","Location","NetworkUtil","BaseError","ErrorCodes","PermissionModule","DispatchSdkUtils","DispatchUtilsInterface","SdkUtils","getRemoteConfig","expiration","Promise","resolve","reject","fetch","setDefaults","cxRumDevApiKey","cxRumProdApiKey","isMandatoryUpdate","isMandatoryUpdateiOS","toggleInAppUpdateiOS","toggleInAppUpdate","then","fetchAndActivate","fetchedRemotely","config","getAll","getInstance","logEvent","SDK_INFO","catch","err","error","downloadAPK","apkURL","version","callback","fileUri","cacheDirectory","fileInfo","getInfoAsync","currentDate","Date","toLocaleDateString","fileDate","modificationTime","exists","uri","downloadResumable","createDownloadResumable","downloadResult","downloadAsync","deleteApk","deleteAsync","openAPKFile","openAndInstallApk","openAppSettings","openSettings","message","SDK_ERROR","checkMandatory","OS","foregroundLocation","requestForegroundPermissions","LOCATION_OR_GPS_NOT_ENABLED","dateTimeCheck","isAutomaticDateTimeEnabled","SYSTEM_TIME_CHECK_FAILED","requestWakeLockPermissions","enableNetworkProviderAsync","locationServicesCheck","hasServicesEnabledAsync","bgLocation","requestBackgroundPermissions","internet","isAvailableAsync","INTERNET_NOT_ENABLED"],"sources":["SdkUtils.ts"],"sourcesContent":["import remoteConfig from '@react-native-firebase/remote-config';\nimport Logger, { LOG_TYPE } from './Logger';\nimport type { DownloadProgressData } from 'expo-file-system';\nimport * as FileSystem from 'expo-file-system';\nimport { NativeModules, Platform } from 'react-native';\nimport * as Location from 'expo-location';\nimport NetworkUtil from './NetworkUtil';\nimport { BaseError } from '../errors/BaseError';\nimport ErrorCodes from '../errors/ErrorCodes';\nimport PermissionModule from '../native/PermissionModule';\n\nconst { DispatchSdkUtils } = NativeModules;\n\ninterface DispatchUtilsInterface {\n openAndInstallApk(apkUri: String): Promise<boolean>;\n openSettings(): Promise<boolean>;\n showAndroidDialog(\n title: string,\n message: string,\n positiveText: string,\n negativeText: string | null,\n cancelable: boolean\n ): Promise<boolean>;\n isAutomaticDateTimeEnabled(): Promise<boolean>;\n}\n\nexport { DispatchSdkUtils as DispatchUtilsInterface };\n\nexport default class SdkUtils {\n /**\n * number of seconds to cache the firebase config\n * @param expiration\n */\n static async getRemoteConfig(expiration: number): Promise<any> {\n return new Promise(async (resolve, reject) => {\n try {\n await remoteConfig().fetch(expiration);\n remoteConfig()\n .setDefaults({\n cxRumDevApiKey: 'NA',\n cxRumProdApiKey: 'NA',\n isMandatoryUpdate: 'false',\n isMandatoryUpdateiOS: 'false',\n toggleInAppUpdateiOS: 'false',\n toggleInAppUpdate: 'false',\n })\n .then(() => remoteConfig().fetchAndActivate())\n .then((fetchedRemotely) => {\n let config = remoteConfig().getAll();\n if (fetchedRemotely) {\n Logger.getInstance().logEvent(\n 'Remote Config',\n 'Configs were retrieved from the backend and activated.',\n LOG_TYPE.SDK_INFO\n );\n resolve(config);\n } else {\n Logger.getInstance().logEvent(\n 'Remote Config',\n 'No configs were fetched from the backend, and the local configs were already activated',\n LOG_TYPE.SDK_INFO\n );\n resolve(config);\n }\n })\n .catch((err) => {\n reject(err);\n });\n } catch (error: any) {\n reject(error);\n }\n });\n }\n\n /**\n * Function to download apk file from a public URL\n * @param apkURL - URL where apk is hosted\n * @param version - expected version of apk (used for naming the file)\n * @param callback - callback for getting progress of download\n */\n public static async downloadAPK(\n apkURL: string,\n version: string,\n callback: (progress: DownloadProgressData) => any\n ): Promise<string | undefined> {\n const fileUri = FileSystem.cacheDirectory + `${version}.apk`;\n const fileInfo = await FileSystem.getInfoAsync(fileUri);\n const currentDate = new Date().toLocaleDateString();\n const fileDate = new Date(\n fileInfo.modificationTime ? fileInfo.modificationTime * 1000 : 0\n ).toLocaleDateString();\n if (fileInfo.exists && currentDate === fileDate) {\n return fileInfo.uri;\n }\n const downloadResumable = FileSystem.createDownloadResumable(\n apkURL,\n FileSystem.cacheDirectory + `${version}.apk`,\n {},\n callback\n );\n const downloadResult = await downloadResumable.downloadAsync();\n return downloadResult?.uri;\n }\n\n /**\n * Opens & Install an APK file\n * @param uri - source of apk file\n */\n public static async deleteApk(version: string) {\n await FileSystem.deleteAsync(FileSystem.cacheDirectory + `${version}.apk`);\n }\n\n public static async openAPKFile(uri: string) {\n return await (DispatchSdkUtils as DispatchUtilsInterface).openAndInstallApk(\n uri\n );\n }\n\n public static openAppSettings() {\n (DispatchSdkUtils as DispatchUtilsInterface)\n .openSettings()\n .then()\n .catch((error) => {\n Logger.getInstance().logEvent(\n 'Intent error',\n error.message,\n LOG_TYPE.SDK_ERROR\n );\n });\n }\n\n public static async checkMandatory() {\n if (Platform.OS === 'ios') {\n const foregroundLocation = await PermissionModule.requestForegroundPermissions();\n if (!(foregroundLocation)) {\n throw new BaseError(\n ErrorCodes.LOCATION_OR_GPS_NOT_ENABLED,\n 'Location or GPS not enabled'\n );\n }\n return;\n }\n const dateTimeCheck = await (\n DispatchSdkUtils as DispatchUtilsInterface\n ).isAutomaticDateTimeEnabled();\n if (!dateTimeCheck) {\n throw new BaseError(\n ErrorCodes.SYSTEM_TIME_CHECK_FAILED,\n 'Automatic date/time not enabled!'\n );\n }\n if (Platform.OS === 'android') {\n await PermissionModule.requestWakeLockPermissions();\n await Location.enableNetworkProviderAsync();\n let locationServicesCheck = await Location.hasServicesEnabledAsync();\n const foregroundLocation = await PermissionModule.requestForegroundPermissions();\n // await Location.requestForegroundPermissionsAsync(); //permission code using expo module\n const bgLocation = await PermissionModule.requestBackgroundPermissions();\n // await Location.requestBackgroundPermissionsAsync(); //permission code using expo module\n if (!(locationServicesCheck && foregroundLocation && bgLocation)) {\n throw new BaseError(\n ErrorCodes.LOCATION_OR_GPS_NOT_ENABLED,\n 'Location or GPS not enabled'\n );\n }\n }\n let internet = await NetworkUtil.isAvailableAsync();\n if (!internet)\n throw new BaseError(\n ErrorCodes.INTERNET_NOT_ENABLED,\n 'Internet is disabled! Please enable internet and try again '\n );\n }\n}\n"],"mappings":"AAAA,OAAOA,YAAY,MAAM,sCAAsC;AAC/D,OAAOC,MAAM,IAAIC,QAAQ,QAAQ,UAAU;AAE3C,OAAO,KAAKC,UAAU,MAAM,kBAAkB;AAC9C,SAASC,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AACtD,OAAO,KAAKC,QAAQ,MAAM,eAAe;AACzC,OAAOC,WAAW,MAAM,eAAe;AACvC,SAASC,SAAS,QAAQ,qBAAqB;AAC/C,OAAOC,UAAU,MAAM,sBAAsB;AAC7C,OAAOC,gBAAgB,MAAM,4BAA4B;AAEzD,MAAM;EAAEC;AAAiB,CAAC,GAAGP,aAAa;AAe1C,SAASO,gBAAgB,IAAIC,sBAAsB;AAEnD,eAAe,MAAMC,QAAQ,CAAC;EAC5B;AACF;AACA;AACA;EACE,aAAaC,eAAeA,CAACC,UAAkB,EAAgB;IAC7D,OAAO,IAAIC,OAAO,CAAC,OAAOC,OAAO,EAAEC,MAAM,KAAK;MAC5C,IAAI;QACF,MAAMlB,YAAY,CAAC,CAAC,CAACmB,KAAK,CAACJ,UAAU,CAAC;QACtCf,YAAY,CAAC,CAAC,CACXoB,WAAW,CAAC;UACXC,cAAc,EAAE,IAAI;UACpBC,eAAe,EAAE,IAAI;UACrBC,iBAAiB,EAAE,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AS,CACjBC,UAAU,CAAC4D,2BAA2B,EACtC,6BACF,CAAC;MACH;MACA;IACF;IACA,MAAMC,aAAa,GAAG,MACpB3D,gBAAgB,CAChB4D,0BAA0B,CAAC,CAAC;IAC9B,IAAI,CAACD,aAAa,EAAE;MAClB,MAAM,IAAI9D,SAAS,CACjBC,UAAU,CAAC+D,wBAAwB,EACnC,kCACF,CAAC;IACH;IACA,IAAInE,QAAQ,CAAC6D,EAAE,KAAK,SAAS,EAAE;MAC7B,MAAMxD,gBAAgB,CAAC+D,0BAA0B,CAAC,CAAC;MACnD,MAAMnE,QAAQ,CAACoE,0BAA0B,CAAC,CAAC;MAC3C,IAAIC,qBAAqB,GAAG,MAAMrE,QAAQ,CAACsE,uBAAuB,CAAC,CAAC;MACpE,MAAMT,kBAAkB,GAAG,MAAMzD,gBAAgB,CAAC0D,4BAA4B,CAAC,CAAC;MAChF;MACA,MAAMS,UAAU,GAAG,MAAMnE,gBAAgB,CAACoE,4BAA4B,CAAC,CAAC;MACxE;MACA,IAAI,EAAEH,qBAAqB,IAAIR,kBAAkB,IAAIU,UAAU,CAAC,EAAE;QAChE,MAAM,IAAIrE,SAAS,CACjBC,UAAU,CAAC4D,2BAA2B,EACtC,6BACF,CAAC;MACH;IACF;IACA,IAAIU,QAAQ,GAAG,MAAMxE,WAAW,CAACyE,gBAAgB,CAAC,CAAC;IACnD,IAAI,CAACD,QAAQ,EACX,MAAM,IAAIvE,SAAS,CACjBC,UAAU,CAACwE,oBAAoB,EAC/B,6DACF,CAAC;EACL;AACF","ignoreList":[]}
@@ -1,6 +1,7 @@
1
1
  interface PermissionsModuleType {
2
2
  requestForegroundPermissions: () => Promise<boolean>;
3
3
  requestBackgroundPermissions: () => Promise<boolean>;
4
+ requestWakeLockPermissions: () => Promise<boolean>;
4
5
  }
5
6
  declare const _default: PermissionsModuleType;
6
7
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@os1-platform/dispatch-mobile",
3
- "version": "3.0.1",
3
+ "version": "3.0.2",
4
4
  "description": "Dispatch SDK React Native Package",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -5,6 +5,7 @@ const { PermissionsModule } = NativeModules;
5
5
  interface PermissionsModuleType {
6
6
  requestForegroundPermissions: () => Promise<boolean>;
7
7
  requestBackgroundPermissions: () => Promise<boolean>;
8
+ requestWakeLockPermissions: () => Promise<boolean>;
8
9
  }
9
10
 
10
11
  const requestForegroundPermissions = async (): Promise<boolean> => {
@@ -15,7 +16,12 @@ const requestBackgroundPermissions = async (): Promise<boolean> => {
15
16
  return PermissionsModule.requestBackgroundPermissions();
16
17
  };
17
18
 
19
+ const requestWakeLockPermissions = async (): Promise<boolean> => {
20
+ return PermissionsModule.requestWakeLockPermissions();
21
+ };
22
+
18
23
  export default {
19
24
  requestForegroundPermissions,
20
25
  requestBackgroundPermissions,
26
+ requestWakeLockPermissions
21
27
  } as PermissionsModuleType;
@@ -130,7 +130,7 @@ export default class SdkUtils {
130
130
  }
131
131
 
132
132
  public static async checkMandatory() {
133
- if (Platform.OS === 'ios'){
133
+ if (Platform.OS === 'ios') {
134
134
  const foregroundLocation = await PermissionModule.requestForegroundPermissions();
135
135
  if (!(foregroundLocation)) {
136
136
  throw new BaseError(
@@ -150,6 +150,7 @@ export default class SdkUtils {
150
150
  );
151
151
  }
152
152
  if (Platform.OS === 'android') {
153
+ await PermissionModule.requestWakeLockPermissions();
153
154
  await Location.enableNetworkProviderAsync();
154
155
  let locationServicesCheck = await Location.hasServicesEnabledAsync();
155
156
  const foregroundLocation = await PermissionModule.requestForegroundPermissions();