@mojro/react-native-gnss-tracking-health 0.0.0-stage → 0.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/LICENSE +21 -0
- package/README.md +368 -2
- package/android/build.gradle +31 -0
- package/android/src/main/AndroidManifest.xml +24 -0
- package/android/src/main/java/com/gnsstrackinghealth/GnssTrackingHealthPackage.java +31 -0
- package/android/src/main/java/com/gnsstrackinghealth/GnssTrackingHealthSettingsModule.java +431 -0
- package/android/src/main/java/com/gnsstrackinghealth/autodatetime/AutoDateTimeModule.java +87 -0
- package/android/src/main/java/com/gnsstrackinghealth/autodatetime/AutoDateTimePackage.java +27 -0
- package/package.json +55 -3
- package/src/TrackingQualityMonitor.js +600 -0
- package/src/adapters/normalizeLocation.js +65 -0
- package/src/backgroundSettings.js +257 -0
- package/src/config.js +96 -0
- package/src/constants.js +161 -0
- package/src/deviceFitness.js +135 -0
- package/src/gnssMonitor.js +245 -0
- package/src/hooks/useDeviceFitness.js +65 -0
- package/src/hooks/useSystemHealth.js +54 -0
- package/src/hooks/useTimeValidation.js +42 -0
- package/src/hooks/useTrackingMonitor.js +265 -0
- package/src/hooks/useTrackingQuality.js +118 -0
- package/src/hooks/useTrackingQualityAlerts.js +22 -0
- package/src/index.d.ts +476 -0
- package/src/index.js +125 -0
- package/src/systemHealth.js +116 -0
- package/src/timeValidation.js +174 -0
- package/src/traceAnalyzer.js +100 -0
- package/src/utils/distance.js +16 -0
- package/src/utils/logger.js +38 -0
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
package com.gnsstrackinghealth;
|
|
2
|
+
|
|
3
|
+
import android.app.Activity;
|
|
4
|
+
import android.content.ActivityNotFoundException;
|
|
5
|
+
import android.content.ComponentName;
|
|
6
|
+
import android.content.Context;
|
|
7
|
+
import android.content.Intent;
|
|
8
|
+
import android.content.SharedPreferences;
|
|
9
|
+
import android.net.Uri;
|
|
10
|
+
import android.os.Build;
|
|
11
|
+
import android.os.PowerManager;
|
|
12
|
+
import android.provider.Settings;
|
|
13
|
+
|
|
14
|
+
import com.facebook.react.bridge.Arguments;
|
|
15
|
+
import com.facebook.react.bridge.Promise;
|
|
16
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
17
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
18
|
+
import com.facebook.react.bridge.ReactMethod;
|
|
19
|
+
import com.facebook.react.bridge.WritableMap;
|
|
20
|
+
|
|
21
|
+
import java.util.ArrayList;
|
|
22
|
+
import java.util.List;
|
|
23
|
+
import java.util.Locale;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Background-restriction helpers for tracking health.
|
|
27
|
+
*
|
|
28
|
+
* Two different settings are involved and they are NOT the same thing:
|
|
29
|
+
*
|
|
30
|
+
* 1. Android "Ignore battery optimizations" (Doze allowlist)
|
|
31
|
+
* -> verifiable via PowerManager.isIgnoringBatteryOptimizations().
|
|
32
|
+
*
|
|
33
|
+
* 2. Samsung "Never sleeping apps" (One UI Device Care)
|
|
34
|
+
* -> Samsung documents an intent to OPEN the screen, but exposes no
|
|
35
|
+
* public API to READ whether this app is on the list. We therefore
|
|
36
|
+
* never claim it as verified; we only remember what the user told us.
|
|
37
|
+
*
|
|
38
|
+
* Automatic date/time lives in a separate package:
|
|
39
|
+
* {@link com.gnsstrackinghealth.autodatetime.AutoDateTimeModule}.
|
|
40
|
+
*
|
|
41
|
+
* Samsung reference: Application Management ->
|
|
42
|
+
* action com.samsung.android.sm.ACTION_OPEN_CHECKABLE_LISTACTIVITY
|
|
43
|
+
* package com.samsung.android.lool
|
|
44
|
+
* extra activity_type = 0 (Sleeping) | 1 (Deep sleeping) | 2 (Never sleeping)
|
|
45
|
+
*/
|
|
46
|
+
public class GnssTrackingHealthSettingsModule extends ReactContextBaseJavaModule {
|
|
47
|
+
|
|
48
|
+
static final String NAME = "GnssTrackingHealthSettings";
|
|
49
|
+
|
|
50
|
+
private static final String PREFS_NAME = "gnss_tracking_health";
|
|
51
|
+
private static final String KEY_NEVER_SLEEPING_CONFIRMED = "never_sleeping_confirmed";
|
|
52
|
+
|
|
53
|
+
private static final String SAMSUNG_DEVICE_CARE_PACKAGE = "com.samsung.android.lool";
|
|
54
|
+
private static final String SAMSUNG_ACTION_OPEN_CHECKABLE_LIST =
|
|
55
|
+
"com.samsung.android.sm.ACTION_OPEN_CHECKABLE_LISTACTIVITY";
|
|
56
|
+
private static final String SAMSUNG_EXTRA_ACTIVITY_TYPE = "activity_type";
|
|
57
|
+
private static final int SAMSUNG_ACTIVITY_NEVER_SLEEPING = 2;
|
|
58
|
+
|
|
59
|
+
public GnssTrackingHealthSettingsModule(ReactApplicationContext reactContext) {
|
|
60
|
+
super(reactContext);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
@Override
|
|
64
|
+
public String getName() {
|
|
65
|
+
return NAME;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// ---------------------------------------------------------------------
|
|
69
|
+
// Status
|
|
70
|
+
// ---------------------------------------------------------------------
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Resolves a map with device info, the verifiable battery-optimization
|
|
74
|
+
* flag, and the (unverifiable) Never sleeping apps context.
|
|
75
|
+
*/
|
|
76
|
+
@ReactMethod
|
|
77
|
+
public void getBackgroundSettingsStatus(Promise promise) {
|
|
78
|
+
try {
|
|
79
|
+
WritableMap map = Arguments.createMap();
|
|
80
|
+
boolean samsung = isSamsung();
|
|
81
|
+
|
|
82
|
+
map.putString("manufacturer", Build.MANUFACTURER);
|
|
83
|
+
map.putString("brand", Build.BRAND);
|
|
84
|
+
map.putString("model", Build.MODEL);
|
|
85
|
+
map.putInt("sdkInt", Build.VERSION.SDK_INT);
|
|
86
|
+
map.putBoolean("isSamsung", samsung);
|
|
87
|
+
map.putBoolean("ignoringBatteryOptimizations", isIgnoringBatteryOptimizationsInternal());
|
|
88
|
+
map.putBoolean("neverSleepingScreenAvailable", isNeverSleepingScreenAvailable());
|
|
89
|
+
|
|
90
|
+
SharedPreferences prefs = prefs();
|
|
91
|
+
if (prefs.contains(KEY_NEVER_SLEEPING_CONFIRMED)) {
|
|
92
|
+
map.putBoolean(
|
|
93
|
+
"neverSleepingUserConfirmed",
|
|
94
|
+
prefs.getBoolean(KEY_NEVER_SLEEPING_CONFIRMED, false));
|
|
95
|
+
} else {
|
|
96
|
+
map.putNull("neverSleepingUserConfirmed");
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
promise.resolve(map);
|
|
100
|
+
} catch (Exception e) {
|
|
101
|
+
promise.reject("BACKGROUND_STATUS_FAILED", e);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
@ReactMethod
|
|
106
|
+
public void isIgnoringBatteryOptimizations(Promise promise) {
|
|
107
|
+
try {
|
|
108
|
+
promise.resolve(isIgnoringBatteryOptimizationsInternal());
|
|
109
|
+
} catch (Exception e) {
|
|
110
|
+
promise.reject("CHECK_FAILED", e);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// ---------------------------------------------------------------------
|
|
115
|
+
// Navigation
|
|
116
|
+
// ---------------------------------------------------------------------
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Opens Samsung's "Never sleeping apps" list. Resolves false when the
|
|
120
|
+
* device is not Samsung or the screen cannot be opened.
|
|
121
|
+
*/
|
|
122
|
+
@ReactMethod
|
|
123
|
+
public void openNeverSleepingApps(Promise promise) {
|
|
124
|
+
try {
|
|
125
|
+
if (!isSamsung()) {
|
|
126
|
+
promise.resolve(false);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
promise.resolve(launch(neverSleepingIntent()));
|
|
130
|
+
} catch (Exception e) {
|
|
131
|
+
promise.reject("OPEN_SETTINGS_FAILED", e);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Opens the best available "background / autostart / never sleeping"
|
|
137
|
+
* screen for THIS device. Works on every Android device:
|
|
138
|
+
*
|
|
139
|
+
* 1. Manufacturer-specific screen (Samsung Never sleeping apps, Xiaomi
|
|
140
|
+
* Autostart, Huawei/Honor Startup manager, Oppo/Realme/OnePlus
|
|
141
|
+
* Startup manager, Vivo/iQOO Background startup, Asus, Nokia, Letv).
|
|
142
|
+
* 2. Android "Optimize battery usage" list (all devices).
|
|
143
|
+
* 3. This app's system "App info" page (all devices).
|
|
144
|
+
*
|
|
145
|
+
* OEM activities are undocumented and change between OS versions, so each
|
|
146
|
+
* is tried and skipped if it cannot be started. Resolves
|
|
147
|
+
* {opened, target, isOemScreen, manufacturer}; never claims the app was
|
|
148
|
+
* added to any list (no OEM exposes a way to read that).
|
|
149
|
+
*/
|
|
150
|
+
@ReactMethod
|
|
151
|
+
public void openBackgroundRestrictionSettings(Promise promise) {
|
|
152
|
+
try {
|
|
153
|
+
WritableMap result = Arguments.createMap();
|
|
154
|
+
result.putString("manufacturer", Build.MANUFACTURER);
|
|
155
|
+
|
|
156
|
+
for (SettingsTarget target : buildSettingsTargets()) {
|
|
157
|
+
if (launch(target.intent)) {
|
|
158
|
+
result.putBoolean("opened", true);
|
|
159
|
+
result.putString("target", target.id);
|
|
160
|
+
result.putBoolean("isOemScreen", target.oem);
|
|
161
|
+
promise.resolve(result);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
result.putBoolean("opened", false);
|
|
167
|
+
result.putString("target", "none");
|
|
168
|
+
result.putBoolean("isOemScreen", false);
|
|
169
|
+
promise.resolve(result);
|
|
170
|
+
} catch (Exception e) {
|
|
171
|
+
promise.reject("OPEN_SETTINGS_FAILED", e);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Opens Android's "Optimize battery usage" list (Doze allowlist).
|
|
177
|
+
*/
|
|
178
|
+
@ReactMethod
|
|
179
|
+
public void openBatteryOptimizationSettings(Promise promise) {
|
|
180
|
+
try {
|
|
181
|
+
promise.resolve(launch(new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS)));
|
|
182
|
+
} catch (Exception e) {
|
|
183
|
+
promise.reject("OPEN_SETTINGS_FAILED", e);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// ---------------------------------------------------------------------
|
|
188
|
+
// User confirmation (Samsung exposes no way to read the list)
|
|
189
|
+
// ---------------------------------------------------------------------
|
|
190
|
+
|
|
191
|
+
@ReactMethod
|
|
192
|
+
public void setNeverSleepingAppsConfirmed(boolean confirmed, Promise promise) {
|
|
193
|
+
try {
|
|
194
|
+
prefs().edit().putBoolean(KEY_NEVER_SLEEPING_CONFIRMED, confirmed).apply();
|
|
195
|
+
promise.resolve(true);
|
|
196
|
+
} catch (Exception e) {
|
|
197
|
+
promise.reject("PERSIST_FAILED", e);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
@ReactMethod
|
|
202
|
+
public void clearNeverSleepingAppsConfirmation(Promise promise) {
|
|
203
|
+
try {
|
|
204
|
+
prefs().edit().remove(KEY_NEVER_SLEEPING_CONFIRMED).apply();
|
|
205
|
+
promise.resolve(true);
|
|
206
|
+
} catch (Exception e) {
|
|
207
|
+
promise.reject("PERSIST_FAILED", e);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// ---------------------------------------------------------------------
|
|
212
|
+
// Internals
|
|
213
|
+
// ---------------------------------------------------------------------
|
|
214
|
+
|
|
215
|
+
private boolean isSamsung() {
|
|
216
|
+
return "samsung".equalsIgnoreCase(Build.MANUFACTURER);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
private boolean isIgnoringBatteryOptimizationsInternal() {
|
|
220
|
+
ReactApplicationContext context = getReactApplicationContext();
|
|
221
|
+
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
|
222
|
+
if (pm == null) {
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
return pm.isIgnoringBatteryOptimizations(context.getPackageName());
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
private Intent neverSleepingIntent() {
|
|
229
|
+
Intent intent = new Intent(SAMSUNG_ACTION_OPEN_CHECKABLE_LIST);
|
|
230
|
+
intent.setPackage(SAMSUNG_DEVICE_CARE_PACKAGE);
|
|
231
|
+
intent.putExtra(SAMSUNG_EXTRA_ACTIVITY_TYPE, SAMSUNG_ACTIVITY_NEVER_SLEEPING);
|
|
232
|
+
return intent;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
private boolean isNeverSleepingScreenAvailable() {
|
|
236
|
+
if (!isSamsung()) {
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
try {
|
|
240
|
+
return neverSleepingIntent()
|
|
241
|
+
.resolveActivity(getReactApplicationContext().getPackageManager()) != null;
|
|
242
|
+
} catch (RuntimeException e) {
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/** Starts the intent from the foreground activity when possible. */
|
|
248
|
+
private boolean launch(Intent intent) {
|
|
249
|
+
try {
|
|
250
|
+
Activity activity = getReactApplicationContext().getCurrentActivity();
|
|
251
|
+
if (activity != null) {
|
|
252
|
+
activity.startActivity(intent);
|
|
253
|
+
} else {
|
|
254
|
+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
255
|
+
getReactApplicationContext().startActivity(intent);
|
|
256
|
+
}
|
|
257
|
+
return true;
|
|
258
|
+
} catch (ActivityNotFoundException | SecurityException e) {
|
|
259
|
+
// OEM screens vary by model / OS version; not an error.
|
|
260
|
+
return false;
|
|
261
|
+
} catch (RuntimeException e) {
|
|
262
|
+
// Some OEM activities throw other runtime errors (bad extras,
|
|
263
|
+
// missing permission). Treat as "cannot open" and try the next.
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
private static final class SettingsTarget {
|
|
269
|
+
final String id;
|
|
270
|
+
final Intent intent;
|
|
271
|
+
final boolean oem;
|
|
272
|
+
|
|
273
|
+
SettingsTarget(String id, Intent intent, boolean oem) {
|
|
274
|
+
this.id = id;
|
|
275
|
+
this.intent = intent;
|
|
276
|
+
this.oem = oem;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
private static Intent component(String pkg, String cls) {
|
|
281
|
+
Intent intent = new Intent();
|
|
282
|
+
intent.setComponent(new ComponentName(pkg, cls));
|
|
283
|
+
return intent;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Ordered list of screens to try. Only the current manufacturer's OEM
|
|
288
|
+
* screens are included, followed by the universal Android fallbacks.
|
|
289
|
+
*/
|
|
290
|
+
private List<SettingsTarget> buildSettingsTargets() {
|
|
291
|
+
ReactApplicationContext context = getReactApplicationContext();
|
|
292
|
+
String appPackage = context.getPackageName();
|
|
293
|
+
String vendor = (Build.MANUFACTURER + " " + Build.BRAND).toLowerCase(Locale.ROOT);
|
|
294
|
+
List<SettingsTarget> targets = new ArrayList<>();
|
|
295
|
+
|
|
296
|
+
if (isSamsung()) {
|
|
297
|
+
targets.add(new SettingsTarget("samsung_never_sleeping", neverSleepingIntent(), true));
|
|
298
|
+
targets.add(new SettingsTarget(
|
|
299
|
+
"samsung_battery",
|
|
300
|
+
component("com.samsung.android.lool",
|
|
301
|
+
"com.samsung.android.sm.battery.ui.BatteryActivity"),
|
|
302
|
+
true));
|
|
303
|
+
targets.add(new SettingsTarget(
|
|
304
|
+
"samsung_battery_legacy",
|
|
305
|
+
component("com.samsung.android.lool",
|
|
306
|
+
"com.samsung.android.sm.ui.battery.BatteryActivity"),
|
|
307
|
+
true));
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
if (vendor.contains("xiaomi") || vendor.contains("redmi") || vendor.contains("poco")) {
|
|
311
|
+
CharSequence label = context.getPackageManager()
|
|
312
|
+
.getApplicationLabel(context.getApplicationInfo());
|
|
313
|
+
Intent powerKeeper = component("com.miui.powerkeeper",
|
|
314
|
+
"com.miui.powerkeeper.ui.HiddenAppsConfigActivity");
|
|
315
|
+
powerKeeper.putExtra("package_name", appPackage);
|
|
316
|
+
powerKeeper.putExtra("package_label", label == null ? appPackage : label.toString());
|
|
317
|
+
targets.add(new SettingsTarget("xiaomi_battery_saver_app", powerKeeper, true));
|
|
318
|
+
targets.add(new SettingsTarget(
|
|
319
|
+
"xiaomi_autostart",
|
|
320
|
+
component("com.miui.securitycenter",
|
|
321
|
+
"com.miui.permcenter.autostart.AutoStartManagementActivity"),
|
|
322
|
+
true));
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
if (vendor.contains("huawei") || vendor.contains("honor")) {
|
|
326
|
+
targets.add(new SettingsTarget(
|
|
327
|
+
"huawei_startup_manager",
|
|
328
|
+
component("com.huawei.systemmanager",
|
|
329
|
+
"com.huawei.systemmanager.startupmgr.ui.StartupNormalAppListActivity"),
|
|
330
|
+
true));
|
|
331
|
+
targets.add(new SettingsTarget(
|
|
332
|
+
"huawei_app_launch",
|
|
333
|
+
component("com.huawei.systemmanager",
|
|
334
|
+
"com.huawei.systemmanager.appcontrol.activity.StartupAppControlActivity"),
|
|
335
|
+
true));
|
|
336
|
+
targets.add(new SettingsTarget(
|
|
337
|
+
"huawei_protected_apps",
|
|
338
|
+
component("com.huawei.systemmanager",
|
|
339
|
+
"com.huawei.systemmanager.optimize.process.ProtectActivity"),
|
|
340
|
+
true));
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
if (vendor.contains("oppo") || vendor.contains("realme") || vendor.contains("oneplus")) {
|
|
344
|
+
targets.add(new SettingsTarget(
|
|
345
|
+
"coloros_startup_manager",
|
|
346
|
+
component("com.coloros.safecenter",
|
|
347
|
+
"com.coloros.safecenter.permission.startup.StartupAppListActivity"),
|
|
348
|
+
true));
|
|
349
|
+
targets.add(new SettingsTarget(
|
|
350
|
+
"coloros_startup_manager_alt",
|
|
351
|
+
component("com.coloros.safecenter",
|
|
352
|
+
"com.coloros.safecenter.startupapp.StartupAppListActivity"),
|
|
353
|
+
true));
|
|
354
|
+
targets.add(new SettingsTarget(
|
|
355
|
+
"oppo_startup_manager_legacy",
|
|
356
|
+
component("com.oppo.safe",
|
|
357
|
+
"com.oppo.safe.permission.startup.StartupAppListActivity"),
|
|
358
|
+
true));
|
|
359
|
+
targets.add(new SettingsTarget(
|
|
360
|
+
"oneplus_chain_launch",
|
|
361
|
+
component("com.oneplus.security",
|
|
362
|
+
"com.oneplus.security.chainlaunch.view.ChainLaunchAppListActivity"),
|
|
363
|
+
true));
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
if (vendor.contains("vivo") || vendor.contains("iqoo")) {
|
|
367
|
+
targets.add(new SettingsTarget(
|
|
368
|
+
"vivo_background_startup",
|
|
369
|
+
component("com.vivo.permissionmanager",
|
|
370
|
+
"com.vivo.permissionmanager.activity.BgStartUpManagerActivity"),
|
|
371
|
+
true));
|
|
372
|
+
targets.add(new SettingsTarget(
|
|
373
|
+
"vivo_whitelist",
|
|
374
|
+
component("com.iqoo.secure",
|
|
375
|
+
"com.iqoo.secure.ui.phoneoptimize.AddWhiteListActivity"),
|
|
376
|
+
true));
|
|
377
|
+
targets.add(new SettingsTarget(
|
|
378
|
+
"vivo_background_startup_alt",
|
|
379
|
+
component("com.iqoo.secure",
|
|
380
|
+
"com.iqoo.secure.ui.phoneoptimize.BgStartUpManager"),
|
|
381
|
+
true));
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
if (vendor.contains("asus")) {
|
|
385
|
+
targets.add(new SettingsTarget(
|
|
386
|
+
"asus_autostart",
|
|
387
|
+
component("com.asus.mobilemanager",
|
|
388
|
+
"com.asus.mobilemanager.autostart.AutoStartActivity"),
|
|
389
|
+
true));
|
|
390
|
+
targets.add(new SettingsTarget(
|
|
391
|
+
"asus_power_saver",
|
|
392
|
+
component("com.asus.mobilemanager",
|
|
393
|
+
"com.asus.mobilemanager.powersaver.PowerSaverSettings"),
|
|
394
|
+
true));
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
if (vendor.contains("nokia") || vendor.contains("hmd")) {
|
|
398
|
+
targets.add(new SettingsTarget(
|
|
399
|
+
"nokia_power_saver",
|
|
400
|
+
component("com.evenwell.powersaving.g3",
|
|
401
|
+
"com.evenwell.powersaving.g3.exception.PowerSaverExceptionActivity"),
|
|
402
|
+
true));
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
if (vendor.contains("letv") || vendor.contains("leeco")) {
|
|
406
|
+
targets.add(new SettingsTarget(
|
|
407
|
+
"letv_autoboot",
|
|
408
|
+
component("com.letv.android.letvsafe",
|
|
409
|
+
"com.letv.android.letvsafe.AutobootManageActivity"),
|
|
410
|
+
true));
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
// Universal Android fallbacks (every device).
|
|
414
|
+
targets.add(new SettingsTarget(
|
|
415
|
+
"battery_optimization",
|
|
416
|
+
new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS),
|
|
417
|
+
false));
|
|
418
|
+
targets.add(new SettingsTarget(
|
|
419
|
+
"app_details",
|
|
420
|
+
new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
|
|
421
|
+
Uri.parse("package:" + appPackage)),
|
|
422
|
+
false));
|
|
423
|
+
|
|
424
|
+
return targets;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
private SharedPreferences prefs() {
|
|
428
|
+
return getReactApplicationContext()
|
|
429
|
+
.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
package com.gnsstrackinghealth.autodatetime;
|
|
2
|
+
|
|
3
|
+
import android.app.Activity;
|
|
4
|
+
import android.content.ActivityNotFoundException;
|
|
5
|
+
import android.content.Intent;
|
|
6
|
+
import android.provider.Settings;
|
|
7
|
+
|
|
8
|
+
import com.facebook.react.bridge.Promise;
|
|
9
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
10
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
11
|
+
import com.facebook.react.bridge.ReactMethod;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Android automatic date/time + timezone detection.
|
|
15
|
+
*
|
|
16
|
+
* Same semantics as the driver-app AutoDateTime module:
|
|
17
|
+
* returns true only when BOTH "Automatic date & time" and
|
|
18
|
+
* "Automatic time zone" are enabled.
|
|
19
|
+
*/
|
|
20
|
+
public class AutoDateTimeModule extends ReactContextBaseJavaModule {
|
|
21
|
+
|
|
22
|
+
private static final String NAME = "AutoDateTime";
|
|
23
|
+
private static final int ENABLED = 1;
|
|
24
|
+
private static final int DISABLED = 0;
|
|
25
|
+
|
|
26
|
+
private static final String ERROR_CODE_SECURITY = "E_SETTINGS_PERMISSION";
|
|
27
|
+
private static final String ERROR_CODE_UNKNOWN = "E_SETTINGS_UNKNOWN";
|
|
28
|
+
private static final String ERROR_MESSAGE_SECURITY =
|
|
29
|
+
"Unable to read time settings. Permission denied.";
|
|
30
|
+
private static final String ERROR_MESSAGE_UNKNOWN =
|
|
31
|
+
"Unexpected error while reading automatic time settings.";
|
|
32
|
+
|
|
33
|
+
public AutoDateTimeModule(ReactApplicationContext reactContext) {
|
|
34
|
+
super(reactContext);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@Override
|
|
38
|
+
public String getName() {
|
|
39
|
+
return NAME;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@ReactMethod
|
|
43
|
+
public void isAutoDateTimeEnabled(Promise promise) {
|
|
44
|
+
try {
|
|
45
|
+
android.content.ContentResolver resolver =
|
|
46
|
+
getReactApplicationContext().getContentResolver();
|
|
47
|
+
boolean autoTimeEnabled =
|
|
48
|
+
Settings.Global.getInt(resolver, Settings.Global.AUTO_TIME, DISABLED)
|
|
49
|
+
== ENABLED;
|
|
50
|
+
boolean autoTimeZoneEnabled =
|
|
51
|
+
Settings.Global.getInt(resolver, Settings.Global.AUTO_TIME_ZONE, DISABLED)
|
|
52
|
+
== ENABLED;
|
|
53
|
+
promise.resolve(autoTimeEnabled && autoTimeZoneEnabled);
|
|
54
|
+
} catch (SecurityException error) {
|
|
55
|
+
promise.reject(ERROR_CODE_SECURITY, ERROR_MESSAGE_SECURITY, error);
|
|
56
|
+
} catch (Exception error) {
|
|
57
|
+
promise.reject(ERROR_CODE_UNKNOWN, ERROR_MESSAGE_UNKNOWN, error);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Opens the system Date & time settings screen.
|
|
63
|
+
*/
|
|
64
|
+
@ReactMethod
|
|
65
|
+
public void openDateTimeSettings(Promise promise) {
|
|
66
|
+
try {
|
|
67
|
+
promise.resolve(launch(new Intent(Settings.ACTION_DATE_SETTINGS)));
|
|
68
|
+
} catch (Exception error) {
|
|
69
|
+
promise.reject("OPEN_SETTINGS_FAILED", error);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
private boolean launch(Intent intent) {
|
|
74
|
+
try {
|
|
75
|
+
Activity activity = getReactApplicationContext().getCurrentActivity();
|
|
76
|
+
if (activity != null) {
|
|
77
|
+
activity.startActivity(intent);
|
|
78
|
+
} else {
|
|
79
|
+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
80
|
+
getReactApplicationContext().startActivity(intent);
|
|
81
|
+
}
|
|
82
|
+
return true;
|
|
83
|
+
} catch (ActivityNotFoundException | SecurityException e) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
package com.gnsstrackinghealth.autodatetime;
|
|
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.Collections;
|
|
9
|
+
import java.util.List;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* ReactPackage for automatic date/time detection (separate from battery-settings).
|
|
13
|
+
* Also registered via {@link com.gnsstrackinghealth.GnssTrackingHealthPackage}
|
|
14
|
+
* so autolinking picks it up without a second package entry.
|
|
15
|
+
*/
|
|
16
|
+
public class AutoDateTimePackage implements ReactPackage {
|
|
17
|
+
|
|
18
|
+
@Override
|
|
19
|
+
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
|
|
20
|
+
return Collections.<NativeModule>singletonList(new AutoDateTimeModule(reactContext));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@Override
|
|
24
|
+
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
|
|
25
|
+
return Collections.<ViewManager>emptyList();
|
|
26
|
+
}
|
|
27
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,58 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mojro/react-native-gnss-tracking-health",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "GNSS coverage, device fitness, system health, and tracking-quality alerts for React Native. Accepts location traces from any tracking library; peer-depends on react-native-gnss-status-checker.",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"types": "src/index.d.ts",
|
|
7
|
+
"react-native": "src/index.js",
|
|
8
|
+
"files": [
|
|
9
|
+
"src",
|
|
10
|
+
"android/build.gradle",
|
|
11
|
+
"android/src",
|
|
12
|
+
"README.md",
|
|
13
|
+
"LICENSE"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"test": "echo \"No tests yet\" && exit 0"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"react-native",
|
|
20
|
+
"gnss",
|
|
21
|
+
"gps",
|
|
22
|
+
"tracking",
|
|
23
|
+
"health",
|
|
24
|
+
"quality",
|
|
25
|
+
"device-fitness",
|
|
26
|
+
"system-health",
|
|
27
|
+
"timezone",
|
|
28
|
+
"background-geolocation"
|
|
29
|
+
],
|
|
30
|
+
"author": "sureshamojro",
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"react": ">=17.0.0",
|
|
37
|
+
"react-native": ">=0.68.0",
|
|
38
|
+
"react-native-gnss-status-checker": ">=1.0.0"
|
|
39
|
+
},
|
|
40
|
+
"peerDependenciesMeta": {
|
|
41
|
+
"@notifee/react-native": {
|
|
42
|
+
"optional": true
|
|
43
|
+
},
|
|
44
|
+
"react-native-device-info": {
|
|
45
|
+
"optional": true
|
|
46
|
+
},
|
|
47
|
+
"react-native-gnss-status-checker": {
|
|
48
|
+
"optional": false
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"typescript": "^5.0.0"
|
|
53
|
+
},
|
|
54
|
+
"engines": {
|
|
55
|
+
"node": ">=16"
|
|
56
|
+
},
|
|
57
|
+
"packageManager": "yarn@3.6.4"
|
|
6
58
|
}
|