react-native-nitro-location-tracking 0.1.16 → 0.1.18

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.
@@ -9,6 +9,14 @@
9
9
  <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
10
10
  <uses-permission android:name="android.permission.WAKE_LOCK" />
11
11
 
12
+ <!-- Required on Android 11+ (API 30) to query all installed packages
13
+ for mock location detection via AppOpsManager -->
14
+ <queries>
15
+ <intent>
16
+ <action android:name="android.intent.action.MAIN" />
17
+ </intent>
18
+ </queries>
19
+
12
20
  <application>
13
21
  <service
14
22
  android:name=".LocationForegroundService"
@@ -164,18 +164,31 @@ class LocationEngine(private val context: Context) {
164
164
  return mockSetting == "1"
165
165
  }
166
166
 
167
- // API 23+: check if any app holds MOCK_LOCATION permission via AppOpsManager
167
+ // API 23+: scan all installed packages for OP_MOCK_LOCATION permission
168
168
  try {
169
169
  val appOps = context.getSystemService(Context.APP_OPS_SERVICE) as AppOpsManager
170
- // Use reflection to access undocumented OP_MOCK_LOCATION (op code 58)
171
- val opMockLocation = 58
172
- val method = AppOpsManager::class.java.getMethod(
170
+ val opMockLocation = 58 // OP_MOCK_LOCATION
171
+ val checkOp = AppOpsManager::class.java.getMethod(
173
172
  "checkOp", Int::class.javaPrimitiveType, Int::class.javaPrimitiveType, String::class.java
174
173
  )
175
- val result = method.invoke(
176
- appOps, opMockLocation, android.os.Process.myUid(), context.packageName
177
- ) as Int
178
- return result == AppOpsManager.MODE_ALLOWED
174
+
175
+ val pm = context.packageManager
176
+ @Suppress("DEPRECATION")
177
+ val packages = pm.getInstalledApplications(0)
178
+ for (appInfo in packages) {
179
+ if (appInfo.packageName == context.packageName) continue
180
+ try {
181
+ val result = checkOp.invoke(
182
+ appOps, opMockLocation, appInfo.uid, appInfo.packageName
183
+ ) as Int
184
+ if (result == AppOpsManager.MODE_ALLOWED) {
185
+ Log.d(TAG, "Mock location provider detected: ${appInfo.packageName}")
186
+ return true
187
+ }
188
+ } catch (_: Exception) {
189
+ // Some packages may not be queryable
190
+ }
191
+ }
179
192
  } catch (e: Exception) {
180
193
  Log.w(TAG, "Could not check mock location app ops: ${e.message}")
181
194
  }
@@ -90,25 +90,42 @@ class MockLocationMonitor(private val context: Context) {
90
90
  return mockSetting == "1"
91
91
  }
92
92
 
93
- // API 23+: check if any app holds MOCK_LOCATION permission via AppOpsManager
93
+ // API 23+: scan ALL installed packages for OP_MOCK_LOCATION permission.
94
+ // The previous approach only checked our own UID which always returned false
95
+ // since the mock location app (not ours) holds the permission.
94
96
  try {
95
97
  val appOps = context.getSystemService(Context.APP_OPS_SERVICE) as AppOpsManager
96
98
  val opMockLocation = 58 // OP_MOCK_LOCATION
97
- val method = AppOpsManager::class.java.getMethod(
99
+ val checkOp = AppOpsManager::class.java.getMethod(
98
100
  "checkOp",
99
101
  Int::class.javaPrimitiveType,
100
102
  Int::class.javaPrimitiveType,
101
103
  String::class.java
102
104
  )
103
- val result = method.invoke(
104
- appOps, opMockLocation, android.os.Process.myUid(), context.packageName
105
- ) as Int
106
- if (result == AppOpsManager.MODE_ALLOWED) return true
105
+
106
+ val pm = context.packageManager
107
+ @Suppress("DEPRECATION")
108
+ val packages = pm.getInstalledApplications(0)
109
+ for (appInfo in packages) {
110
+ // Skip our own package
111
+ if (appInfo.packageName == context.packageName) continue
112
+ try {
113
+ val result = checkOp.invoke(
114
+ appOps, opMockLocation, appInfo.uid, appInfo.packageName
115
+ ) as Int
116
+ if (result == AppOpsManager.MODE_ALLOWED) {
117
+ Log.d(TAG, "Mock location provider detected: ${appInfo.packageName}")
118
+ return true
119
+ }
120
+ } catch (_: Exception) {
121
+ // Some packages may not be queryable — skip
122
+ }
123
+ }
107
124
  } catch (e: Exception) {
108
125
  Log.w(TAG, "Could not check mock location app ops: ${e.message}")
109
126
  }
110
127
 
111
- // Additional check: scan installed packages for known mock location apps
128
+ // Fallback: check for known mock location app package names
112
129
  try {
113
130
  val pm = context.packageManager
114
131
  val knownMockApps = listOf(
@@ -123,6 +140,7 @@ class MockLocationMonitor(private val context: Context) {
123
140
  )
124
141
  for (pkg in knownMockApps) {
125
142
  try {
143
+ @Suppress("DEPRECATION")
126
144
  pm.getApplicationInfo(pkg, 0)
127
145
  Log.d(TAG, "Known mock location app detected: $pkg")
128
146
  return true
package/nitro.json CHANGED
@@ -11,6 +11,9 @@
11
11
  "NitroLocationTracking": {
12
12
  "swift": "NitroLocationTracking",
13
13
  "kotlin": "NitroLocationTracking"
14
+ },
15
+ "NitroLocationComplexLogicsCalculation": {
16
+ "cpp": "HybridNitroLocationComplexLogicsCalculation"
14
17
  }
15
18
  },
16
19
  "ignorePaths": ["node_modules"]
@@ -25,6 +25,7 @@
25
25
  #include "JFunc_void_LocationProviderStatus_LocationProviderStatus.hpp"
26
26
  #include "JFunc_void_PermissionStatus.hpp"
27
27
  #include <NitroModules/DefaultConstructableObject.hpp>
28
+ #include "HybridNitroLocationComplexLogicsCalculation.hpp"
28
29
 
29
30
  namespace margelo::nitro::nitrolocationtracking {
30
31
 
@@ -54,6 +55,15 @@ int initialize(JavaVM* vm) {
54
55
  return instance->cthis()->shared();
55
56
  }
56
57
  );
58
+ HybridObjectRegistry::registerHybridObjectConstructor(
59
+ "NitroLocationComplexLogicsCalculation",
60
+ []() -> std::shared_ptr<HybridObject> {
61
+ static_assert(std::is_default_constructible_v<HybridNitroLocationComplexLogicsCalculation>,
62
+ "The HybridObject \"HybridNitroLocationComplexLogicsCalculation\" is not default-constructible! "
63
+ "Create a public constructor that takes zero arguments to be able to autolink this HybridObject.");
64
+ return std::make_shared<HybridNitroLocationComplexLogicsCalculation>();
65
+ }
66
+ );
57
67
  });
58
68
  }
59
69
 
@@ -11,6 +11,7 @@
11
11
  #import <type_traits>
12
12
 
13
13
  #include "HybridNitroLocationTrackingSpecSwift.hpp"
14
+ #include "HybridNitroLocationComplexLogicsCalculation.hpp"
14
15
 
15
16
  @interface NitroLocationTrackingAutolinking : NSObject
16
17
  @end
@@ -28,6 +29,15 @@
28
29
  return hybridObject;
29
30
  }
30
31
  );
32
+ HybridObjectRegistry::registerHybridObjectConstructor(
33
+ "NitroLocationComplexLogicsCalculation",
34
+ []() -> std::shared_ptr<HybridObject> {
35
+ static_assert(std::is_default_constructible_v<HybridNitroLocationComplexLogicsCalculation>,
36
+ "The HybridObject \"HybridNitroLocationComplexLogicsCalculation\" is not default-constructible! "
37
+ "Create a public constructor that takes zero arguments to be able to autolink this HybridObject.");
38
+ return std::make_shared<HybridNitroLocationComplexLogicsCalculation>();
39
+ }
40
+ );
31
41
  }
32
42
 
33
43
  @end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-nitro-location-tracking",
3
- "version": "0.1.16",
3
+ "version": "0.1.18",
4
4
  "description": "A React Native Nitro module for location tracking",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",