@mojro/react-native-gnss-tracking-health 0.0.0-stage → 0.1.1
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 +374 -2
- package/android/build.gradle +31 -0
- package/android/src/main/AndroidManifest.xml +34 -0
- package/android/src/main/java/com/gnsstrackinghealth/GnssTrackingHealthPackage.java +31 -0
- package/android/src/main/java/com/gnsstrackinghealth/GnssTrackingHealthSettingsModule.java +636 -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 +607 -0
- package/src/adapters/normalizeLocation.js +65 -0
- package/src/backgroundSettings.js +392 -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 +521 -0
- package/src/index.js +129 -0
- package/src/systemHealth.js +118 -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,392 @@
|
|
|
1
|
+
import { NativeModules, Platform } from "react-native";
|
|
2
|
+
import { getLogger } from "./utils/logger";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Background-restriction diagnostics (Android).
|
|
6
|
+
*
|
|
7
|
+
* Two separate settings, reported separately:
|
|
8
|
+
*
|
|
9
|
+
* - Android "Ignore battery optimizations" -> VERIFIED via PowerManager.
|
|
10
|
+
* - OEM background-allowlist screens -> NOT verifiable.
|
|
11
|
+
* Samsung "Never sleeping apps", Xiaomi Autostart, Huawei Startup manager,
|
|
12
|
+
* Oppo/Realme/OnePlus Startup manager, Vivo/iQOO Background startup, etc.
|
|
13
|
+
* OEMs expose intents to open these screens but no public API to read
|
|
14
|
+
* whether this app is on the list. We report `verifiable: false` and only
|
|
15
|
+
* surface what the user has told us (`userConfirmed`).
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export const NEVER_SLEEPING_STATE = {
|
|
19
|
+
/** Not an OEM that ships a dedicated allowlist screen. */
|
|
20
|
+
NOT_APPLICABLE: "not_applicable",
|
|
21
|
+
/** OEM device, nothing known (cannot be read from the OS). */
|
|
22
|
+
UNVERIFIED: "unverified",
|
|
23
|
+
/** User said the app is on the list (self-reported, not verified). */
|
|
24
|
+
USER_CONFIRMED: "user_confirmed",
|
|
25
|
+
/** User said the app is NOT on the list (self-reported). */
|
|
26
|
+
USER_REPORTED_MISSING: "user_reported_missing",
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const NEVER_SLEEPING_NOTE =
|
|
30
|
+
"OEM background-allowlist screens (Never sleeping apps, Autostart, " +
|
|
31
|
+
"Startup manager, etc.) expose no public API to verify membership. " +
|
|
32
|
+
"This value is only what the user reported.";
|
|
33
|
+
|
|
34
|
+
function getNative() {
|
|
35
|
+
if (Platform.OS !== "android") {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
return NativeModules.GnssTrackingHealthSettings || null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function jsManufacturer() {
|
|
42
|
+
if (Platform.OS !== "android") {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
return Platform.constants?.Manufacturer || null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function jsBrand() {
|
|
49
|
+
if (Platform.OS !== "android") {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
return Platform.constants?.Brand || null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Best-effort OEM family from manufacturer/brand when native is unavailable. */
|
|
56
|
+
export function detectOemFamilyFromVendor(manufacturer, brand) {
|
|
57
|
+
const vendor = `${manufacturer || ""} ${brand || ""}`.toLowerCase();
|
|
58
|
+
if (vendor.includes("samsung")) return "samsung";
|
|
59
|
+
if (
|
|
60
|
+
vendor.includes("xiaomi") ||
|
|
61
|
+
vendor.includes("redmi") ||
|
|
62
|
+
vendor.includes("poco")
|
|
63
|
+
) {
|
|
64
|
+
return "xiaomi";
|
|
65
|
+
}
|
|
66
|
+
if (vendor.includes("huawei") || vendor.includes("honor")) return "huawei";
|
|
67
|
+
if (vendor.includes("oneplus")) return "oneplus";
|
|
68
|
+
if (vendor.includes("realme")) return "realme";
|
|
69
|
+
if (vendor.includes("oppo")) return "oppo";
|
|
70
|
+
if (vendor.includes("vivo") || vendor.includes("iqoo")) return "vivo";
|
|
71
|
+
if (vendor.includes("asus")) return "asus";
|
|
72
|
+
if (vendor.includes("nokia") || vendor.includes("hmd")) return "nokia";
|
|
73
|
+
if (vendor.includes("letv") || vendor.includes("leeco")) return "letv";
|
|
74
|
+
if (vendor.includes("meizu")) return "meizu";
|
|
75
|
+
if (vendor.includes("motorola") || vendor.includes("moto")) return "motorola";
|
|
76
|
+
return "none";
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function oemRestrictionLabelForFamily(oemFamily) {
|
|
80
|
+
switch (oemFamily) {
|
|
81
|
+
case "samsung":
|
|
82
|
+
return "Never sleeping apps";
|
|
83
|
+
case "xiaomi":
|
|
84
|
+
return "Autostart / Battery saver";
|
|
85
|
+
case "huawei":
|
|
86
|
+
return "Startup manager / App launch";
|
|
87
|
+
case "oppo":
|
|
88
|
+
case "realme":
|
|
89
|
+
case "oneplus":
|
|
90
|
+
return "Startup manager";
|
|
91
|
+
case "vivo":
|
|
92
|
+
return "Background startup / Whitelist";
|
|
93
|
+
case "asus":
|
|
94
|
+
return "Auto-start manager";
|
|
95
|
+
case "nokia":
|
|
96
|
+
return "Power saver exceptions";
|
|
97
|
+
case "letv":
|
|
98
|
+
return "Autoboot manager";
|
|
99
|
+
case "meizu":
|
|
100
|
+
return "Background management";
|
|
101
|
+
case "motorola":
|
|
102
|
+
return "Battery optimization / Background apps";
|
|
103
|
+
default:
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function buildNeverSleeping({
|
|
109
|
+
applicable,
|
|
110
|
+
userConfirmed,
|
|
111
|
+
settingsScreenAvailable,
|
|
112
|
+
oemFamily,
|
|
113
|
+
label,
|
|
114
|
+
target,
|
|
115
|
+
}) {
|
|
116
|
+
const isApplicable = !!applicable;
|
|
117
|
+
let state = NEVER_SLEEPING_STATE.NOT_APPLICABLE;
|
|
118
|
+
if (isApplicable) {
|
|
119
|
+
if (userConfirmed === true) {
|
|
120
|
+
state = NEVER_SLEEPING_STATE.USER_CONFIRMED;
|
|
121
|
+
} else if (userConfirmed === false) {
|
|
122
|
+
state = NEVER_SLEEPING_STATE.USER_REPORTED_MISSING;
|
|
123
|
+
} else {
|
|
124
|
+
state = NEVER_SLEEPING_STATE.UNVERIFIED;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
applicable: isApplicable,
|
|
129
|
+
verifiable: false,
|
|
130
|
+
state,
|
|
131
|
+
userConfirmed: isApplicable ? userConfirmed ?? null : null,
|
|
132
|
+
settingsScreenAvailable: !!settingsScreenAvailable,
|
|
133
|
+
oemFamily: oemFamily || "none",
|
|
134
|
+
label: label || null,
|
|
135
|
+
target: target || null,
|
|
136
|
+
note: NEVER_SLEEPING_NOTE,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function emptyOpenResult(manufacturer = null, oemFamily = "none") {
|
|
141
|
+
return {
|
|
142
|
+
opened: false,
|
|
143
|
+
target: "none",
|
|
144
|
+
isOemScreen: false,
|
|
145
|
+
manufacturer,
|
|
146
|
+
oemFamily,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function normalizeOpenResult(raw, fallbackManufacturer) {
|
|
151
|
+
// Legacy native builds resolved a bare boolean from openNeverSleepingApps.
|
|
152
|
+
if (typeof raw === "boolean") {
|
|
153
|
+
return {
|
|
154
|
+
opened: raw,
|
|
155
|
+
target: raw ? "oem" : "none",
|
|
156
|
+
isOemScreen: raw,
|
|
157
|
+
manufacturer: fallbackManufacturer,
|
|
158
|
+
oemFamily: detectOemFamilyFromVendor(fallbackManufacturer, jsBrand()),
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
return {
|
|
162
|
+
opened: !!raw?.opened,
|
|
163
|
+
target: raw?.target || "none",
|
|
164
|
+
isOemScreen: !!raw?.isOemScreen,
|
|
165
|
+
manufacturer: raw?.manufacturer || fallbackManufacturer,
|
|
166
|
+
oemFamily:
|
|
167
|
+
raw?.oemFamily ||
|
|
168
|
+
detectOemFamilyFromVendor(
|
|
169
|
+
raw?.manufacturer || fallbackManufacturer,
|
|
170
|
+
jsBrand()
|
|
171
|
+
),
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Collect both background-restriction statuses.
|
|
177
|
+
* Never rejects: falls back to a best-effort JS-only result when the native
|
|
178
|
+
* module is not linked.
|
|
179
|
+
*/
|
|
180
|
+
export async function getBackgroundSettingsStatus() {
|
|
181
|
+
const native = getNative();
|
|
182
|
+
const checkedAt = Date.now();
|
|
183
|
+
|
|
184
|
+
if (!native?.getBackgroundSettingsStatus) {
|
|
185
|
+
if (Platform.OS === "android") {
|
|
186
|
+
getLogger().warn(
|
|
187
|
+
"GnssTrackingHealthSettings native module missing — rebuild the Android app"
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
const manufacturer = jsManufacturer();
|
|
191
|
+
const brand = jsBrand();
|
|
192
|
+
const oemFamily = detectOemFamilyFromVendor(manufacturer, brand);
|
|
193
|
+
const applicable = oemFamily !== "none";
|
|
194
|
+
const isSamsung = oemFamily === "samsung";
|
|
195
|
+
return {
|
|
196
|
+
platform: Platform.OS,
|
|
197
|
+
nativeModuleAvailable: false,
|
|
198
|
+
manufacturer,
|
|
199
|
+
brand,
|
|
200
|
+
model: Platform.constants?.Model || null,
|
|
201
|
+
sdkInt: null,
|
|
202
|
+
isSamsung,
|
|
203
|
+
oemFamily,
|
|
204
|
+
ignoringBatteryOptimizations: null,
|
|
205
|
+
neverSleepingApps: buildNeverSleeping({
|
|
206
|
+
applicable,
|
|
207
|
+
userConfirmed: null,
|
|
208
|
+
settingsScreenAvailable: false,
|
|
209
|
+
oemFamily,
|
|
210
|
+
label: oemRestrictionLabelForFamily(oemFamily),
|
|
211
|
+
target: null,
|
|
212
|
+
}),
|
|
213
|
+
checkedAt,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
try {
|
|
218
|
+
const raw = await native.getBackgroundSettingsStatus();
|
|
219
|
+
const oemFamily =
|
|
220
|
+
raw.oemFamily ||
|
|
221
|
+
detectOemFamilyFromVendor(raw.manufacturer, raw.brand);
|
|
222
|
+
const applicable =
|
|
223
|
+
typeof raw.oemRestrictionApplicable === "boolean"
|
|
224
|
+
? raw.oemRestrictionApplicable
|
|
225
|
+
: oemFamily !== "none";
|
|
226
|
+
return {
|
|
227
|
+
platform: Platform.OS,
|
|
228
|
+
nativeModuleAvailable: true,
|
|
229
|
+
manufacturer: raw.manufacturer,
|
|
230
|
+
brand: raw.brand,
|
|
231
|
+
model: raw.model,
|
|
232
|
+
sdkInt: raw.sdkInt,
|
|
233
|
+
isSamsung: !!raw.isSamsung || oemFamily === "samsung",
|
|
234
|
+
oemFamily,
|
|
235
|
+
ignoringBatteryOptimizations: !!raw.ignoringBatteryOptimizations,
|
|
236
|
+
neverSleepingApps: buildNeverSleeping({
|
|
237
|
+
applicable,
|
|
238
|
+
userConfirmed: raw.neverSleepingUserConfirmed ?? null,
|
|
239
|
+
settingsScreenAvailable: !!raw.neverSleepingScreenAvailable,
|
|
240
|
+
oemFamily,
|
|
241
|
+
label:
|
|
242
|
+
raw.oemRestrictionLabel || oemRestrictionLabelForFamily(oemFamily),
|
|
243
|
+
target: raw.oemRestrictionTarget ?? null,
|
|
244
|
+
}),
|
|
245
|
+
checkedAt,
|
|
246
|
+
};
|
|
247
|
+
} catch (error) {
|
|
248
|
+
getLogger().warn("getBackgroundSettingsStatus failed:", error?.message);
|
|
249
|
+
const manufacturer = jsManufacturer();
|
|
250
|
+
const oemFamily = detectOemFamilyFromVendor(manufacturer, jsBrand());
|
|
251
|
+
return {
|
|
252
|
+
platform: Platform.OS,
|
|
253
|
+
nativeModuleAvailable: true,
|
|
254
|
+
manufacturer,
|
|
255
|
+
oemFamily,
|
|
256
|
+
isSamsung: oemFamily === "samsung",
|
|
257
|
+
ignoringBatteryOptimizations: null,
|
|
258
|
+
neverSleepingApps: buildNeverSleeping({
|
|
259
|
+
applicable: false,
|
|
260
|
+
userConfirmed: null,
|
|
261
|
+
settingsScreenAvailable: false,
|
|
262
|
+
oemFamily: "none",
|
|
263
|
+
label: null,
|
|
264
|
+
target: null,
|
|
265
|
+
}),
|
|
266
|
+
error: error?.message || "getBackgroundSettingsStatus failed",
|
|
267
|
+
checkedAt,
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Android "Ignore battery optimizations" (verified).
|
|
274
|
+
* Resolves null when it cannot be determined (iOS / native module missing).
|
|
275
|
+
*/
|
|
276
|
+
export async function isIgnoringBatteryOptimizations() {
|
|
277
|
+
const native = getNative();
|
|
278
|
+
if (!native?.isIgnoringBatteryOptimizations) {
|
|
279
|
+
return null;
|
|
280
|
+
}
|
|
281
|
+
try {
|
|
282
|
+
return !!(await native.isIgnoringBatteryOptimizations());
|
|
283
|
+
} catch (error) {
|
|
284
|
+
getLogger().warn("isIgnoringBatteryOptimizations failed:", error?.message);
|
|
285
|
+
return null;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Open this device's OEM background-allowlist screen (Samsung Never sleeping
|
|
291
|
+
* apps, Oppo/OnePlus Startup manager, Vivo Background startup, Xiaomi
|
|
292
|
+
* Autostart, …). Does NOT fall back to generic Android screens — use
|
|
293
|
+
* openBackgroundRestrictionSettings() or openBatteryOptimizationSettings()
|
|
294
|
+
* for that.
|
|
295
|
+
*
|
|
296
|
+
* Never rejects. Resolves:
|
|
297
|
+
* { opened, target, isOemScreen, manufacturer, oemFamily }
|
|
298
|
+
*/
|
|
299
|
+
export async function openNeverSleepingApps() {
|
|
300
|
+
const fallback = emptyOpenResult(
|
|
301
|
+
jsManufacturer(),
|
|
302
|
+
detectOemFamilyFromVendor(jsManufacturer(), jsBrand())
|
|
303
|
+
);
|
|
304
|
+
const native = getNative();
|
|
305
|
+
if (!native?.openNeverSleepingApps) {
|
|
306
|
+
return fallback;
|
|
307
|
+
}
|
|
308
|
+
try {
|
|
309
|
+
const raw = await native.openNeverSleepingApps();
|
|
310
|
+
return normalizeOpenResult(raw, fallback.manufacturer);
|
|
311
|
+
} catch (error) {
|
|
312
|
+
getLogger().warn("openNeverSleepingApps failed:", error?.message);
|
|
313
|
+
return fallback;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Open the best "background / autostart / never sleeping" screen for THIS
|
|
319
|
+
* device — works on every Android device, not just Samsung.
|
|
320
|
+
*
|
|
321
|
+
* Order tried natively: manufacturer-specific screen (Samsung, Xiaomi, Huawei /
|
|
322
|
+
* Honor, Oppo / Realme / OnePlus, Vivo / iQOO, Asus, Nokia, Letv, Meizu,
|
|
323
|
+
* Motorola) ->
|
|
324
|
+
* Android "Optimize battery usage" list -> this app's "App info" page.
|
|
325
|
+
*
|
|
326
|
+
* OEM screens are undocumented and vary by model / OS version, so they are
|
|
327
|
+
* best-effort. Nothing here can verify the app was added to any list.
|
|
328
|
+
*
|
|
329
|
+
* Never rejects. Resolves:
|
|
330
|
+
* { opened, target, isOemScreen, manufacturer, oemFamily }
|
|
331
|
+
* `target` is e.g. "samsung_never_sleeping", "xiaomi_autostart",
|
|
332
|
+
* "coloros_startup_manager", "vivo_background_startup",
|
|
333
|
+
* "battery_optimization", "app_details", or "none".
|
|
334
|
+
*/
|
|
335
|
+
export async function openBackgroundRestrictionSettings() {
|
|
336
|
+
const fallback = emptyOpenResult(
|
|
337
|
+
jsManufacturer(),
|
|
338
|
+
detectOemFamilyFromVendor(jsManufacturer(), jsBrand())
|
|
339
|
+
);
|
|
340
|
+
const native = getNative();
|
|
341
|
+
if (!native?.openBackgroundRestrictionSettings) {
|
|
342
|
+
if (Platform.OS === "android") {
|
|
343
|
+
getLogger().warn(
|
|
344
|
+
"openBackgroundRestrictionSettings unavailable — rebuild the Android app"
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
return fallback;
|
|
348
|
+
}
|
|
349
|
+
try {
|
|
350
|
+
const raw = await native.openBackgroundRestrictionSettings();
|
|
351
|
+
return normalizeOpenResult(raw, fallback.manufacturer);
|
|
352
|
+
} catch (error) {
|
|
353
|
+
getLogger().warn("openBackgroundRestrictionSettings failed:", error?.message);
|
|
354
|
+
return fallback;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Open Android's "Optimize battery usage" list. Resolves false on failure.
|
|
360
|
+
*/
|
|
361
|
+
export async function openBatteryOptimizationSettings() {
|
|
362
|
+
const native = getNative();
|
|
363
|
+
if (!native?.openBatteryOptimizationSettings) {
|
|
364
|
+
return false;
|
|
365
|
+
}
|
|
366
|
+
try {
|
|
367
|
+
return !!(await native.openBatteryOptimizationSettings());
|
|
368
|
+
} catch (error) {
|
|
369
|
+
getLogger().warn("openBatteryOptimizationSettings failed:", error?.message);
|
|
370
|
+
return false;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Record what the user says about the OEM background-allowlist screen
|
|
376
|
+
* (persisted natively). Pass `null` to clear. This does NOT verify anything.
|
|
377
|
+
*/
|
|
378
|
+
export async function setNeverSleepingAppsConfirmed(confirmed) {
|
|
379
|
+
const native = getNative();
|
|
380
|
+
if (!native) {
|
|
381
|
+
return false;
|
|
382
|
+
}
|
|
383
|
+
try {
|
|
384
|
+
if (confirmed === null || confirmed === undefined) {
|
|
385
|
+
return !!(await native.clearNeverSleepingAppsConfirmation());
|
|
386
|
+
}
|
|
387
|
+
return !!(await native.setNeverSleepingAppsConfirmed(!!confirmed));
|
|
388
|
+
} catch (error) {
|
|
389
|
+
getLogger().warn("setNeverSleepingAppsConfirmed failed:", error?.message);
|
|
390
|
+
return false;
|
|
391
|
+
}
|
|
392
|
+
}
|
package/src/config.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host-app injection point + runtime threshold overrides.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
DEFAULT_API_LEVEL_THRESHOLDS,
|
|
7
|
+
DEFAULT_THRESHOLDS,
|
|
8
|
+
} from "./constants";
|
|
9
|
+
|
|
10
|
+
const defaultConfig = {
|
|
11
|
+
getPowerSaveMode: null,
|
|
12
|
+
isIgnoringBatteryOptimizations: null,
|
|
13
|
+
getPowerState: null,
|
|
14
|
+
getBatteryLevel: null,
|
|
15
|
+
isAutomaticDateTimeEnabled: null,
|
|
16
|
+
showNotification: null,
|
|
17
|
+
persistAlert: null,
|
|
18
|
+
logger: null,
|
|
19
|
+
/** Partial override of DEFAULT_THRESHOLDS */
|
|
20
|
+
thresholds: {},
|
|
21
|
+
/** Partial override of DEFAULT_API_LEVEL_THRESHOLDS */
|
|
22
|
+
apiLevelThresholds: {},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
let config = {
|
|
26
|
+
...defaultConfig,
|
|
27
|
+
thresholds: {},
|
|
28
|
+
apiLevelThresholds: {},
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export function configure(partial = {}) {
|
|
32
|
+
const nextThresholds = {
|
|
33
|
+
...(config.thresholds || {}),
|
|
34
|
+
...(partial.thresholds || {}),
|
|
35
|
+
};
|
|
36
|
+
const nextApiLevel = {
|
|
37
|
+
...(config.apiLevelThresholds || {}),
|
|
38
|
+
...(partial.apiLevelThresholds || {}),
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const { thresholds: _t, apiLevelThresholds: _a, ...rest } = partial;
|
|
42
|
+
|
|
43
|
+
config = {
|
|
44
|
+
...config,
|
|
45
|
+
...rest,
|
|
46
|
+
thresholds: nextThresholds,
|
|
47
|
+
apiLevelThresholds: nextApiLevel,
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
if (partial.logger) {
|
|
51
|
+
// eslint-disable-next-line global-require
|
|
52
|
+
const { setLogger } = require("./utils/logger");
|
|
53
|
+
setLogger(partial.logger);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return getConfig();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function getConfig() {
|
|
60
|
+
return {
|
|
61
|
+
...config,
|
|
62
|
+
thresholds: getThresholds(),
|
|
63
|
+
apiLevelThresholds: getApiLevelThresholds(),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Effective runtime thresholds = library defaults merged with user overrides.
|
|
69
|
+
*/
|
|
70
|
+
export function getThresholds() {
|
|
71
|
+
return {
|
|
72
|
+
...DEFAULT_THRESHOLDS,
|
|
73
|
+
...(config.thresholds || {}),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Effective Android API floors for device fitness scoring.
|
|
79
|
+
*/
|
|
80
|
+
export function getApiLevelThresholds() {
|
|
81
|
+
return {
|
|
82
|
+
...DEFAULT_API_LEVEL_THRESHOLDS,
|
|
83
|
+
...(config.apiLevelThresholds || {}),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function resetConfig() {
|
|
88
|
+
config = {
|
|
89
|
+
...defaultConfig,
|
|
90
|
+
thresholds: {},
|
|
91
|
+
apiLevelThresholds: {},
|
|
92
|
+
};
|
|
93
|
+
// eslint-disable-next-line global-require
|
|
94
|
+
const { setLogger } = require("./utils/logger");
|
|
95
|
+
setLogger(null);
|
|
96
|
+
}
|
package/src/constants.js
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defaults + enums for react-native-gnss-tracking-health.
|
|
3
|
+
* Numeric thresholds are overridable via configure({ thresholds, apiLevelThresholds }).
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export const ALERT_TYPES = {
|
|
7
|
+
LOCATION_MOCKED: "LOCATION_MOCKED",
|
|
8
|
+
LOW_SATELLITE_AFTER_TRIP_START: "LOW_SATELLITE_AFTER_TRIP_START",
|
|
9
|
+
POOR_TRACKING_SUSTAINED: "POOR_TRACKING_SUSTAINED",
|
|
10
|
+
ABNORMAL_TRACE: "ABNORMAL_TRACE",
|
|
11
|
+
BATTERY_OPTIMIZATION_ENABLED: "BATTERY_OPTIMIZATION_ENABLED",
|
|
12
|
+
LOW_POWER_MODE: "LOW_POWER_MODE",
|
|
13
|
+
LOCATION_THROTTLING: "LOCATION_THROTTLING",
|
|
14
|
+
BACKGROUND_TRACKING_RESTRICTED: "BACKGROUND_TRACKING_RESTRICTED",
|
|
15
|
+
BAD_TIME_TIMEZONE: "BAD_TIME_TIMEZONE",
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const ALERT_SEVERITY = {
|
|
19
|
+
BLOCKER: "blocker",
|
|
20
|
+
WARNING: "warning",
|
|
21
|
+
INFO: "info",
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/** Default Android API floors for device fitness (overridable). */
|
|
25
|
+
export const DEFAULT_API_LEVEL_THRESHOLDS = {
|
|
26
|
+
MIN_LEGACY_GNSS: 21,
|
|
27
|
+
MIN_BASIC_GNSS: 21,
|
|
28
|
+
MIN_FULL_GNSS_STATUS: 24,
|
|
29
|
+
MIN_CARRIER_FREQUENCY: 26,
|
|
30
|
+
MIN_BACKGROUND_LOCATION_PERMISSION: 29,
|
|
31
|
+
MIN_PRECISE_LOCATION_MODEL: 31,
|
|
32
|
+
MIN_FGS_LOCATION_TYPE: 34,
|
|
33
|
+
MIN_ACCEPTABLE_FOR_TRACKING: 24,
|
|
34
|
+
PREFERRED_FOR_ENHANCED_GNSS: 26,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/** @deprecated Use DEFAULT_API_LEVEL_THRESHOLDS or getApiLevelThresholds() */
|
|
38
|
+
export const API_LEVEL_THRESHOLDS = DEFAULT_API_LEVEL_THRESHOLDS;
|
|
39
|
+
|
|
40
|
+
export const DEVICE_FITNESS = {
|
|
41
|
+
UNFIT: "unfit",
|
|
42
|
+
WEAK: "weak",
|
|
43
|
+
ACCEPTABLE: "acceptable",
|
|
44
|
+
GOOD: "good",
|
|
45
|
+
RISKY_SETTINGS: "risky_settings",
|
|
46
|
+
UNKNOWN: "unknown",
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const GNSS_CAPABILITY_BY_API = {
|
|
50
|
+
unsupported: {
|
|
51
|
+
satelliteCount: false,
|
|
52
|
+
constellation: false,
|
|
53
|
+
cn0: false,
|
|
54
|
+
elevationAzimuth: false,
|
|
55
|
+
measurements: false,
|
|
56
|
+
carrierFrequency: false,
|
|
57
|
+
},
|
|
58
|
+
legacy: {
|
|
59
|
+
satelliteCount: true,
|
|
60
|
+
constellation: false,
|
|
61
|
+
cn0: false,
|
|
62
|
+
elevationAzimuth: false,
|
|
63
|
+
measurements: false,
|
|
64
|
+
carrierFrequency: false,
|
|
65
|
+
},
|
|
66
|
+
basic: {
|
|
67
|
+
satelliteCount: true,
|
|
68
|
+
constellation: true,
|
|
69
|
+
cn0: false,
|
|
70
|
+
elevationAzimuth: false,
|
|
71
|
+
measurements: false,
|
|
72
|
+
carrierFrequency: false,
|
|
73
|
+
},
|
|
74
|
+
full_status: {
|
|
75
|
+
satelliteCount: true,
|
|
76
|
+
constellation: true,
|
|
77
|
+
cn0: true,
|
|
78
|
+
elevationAzimuth: true,
|
|
79
|
+
measurements: true,
|
|
80
|
+
carrierFrequency: false,
|
|
81
|
+
},
|
|
82
|
+
enhanced: {
|
|
83
|
+
satelliteCount: true,
|
|
84
|
+
constellation: true,
|
|
85
|
+
cn0: true,
|
|
86
|
+
elevationAzimuth: true,
|
|
87
|
+
measurements: true,
|
|
88
|
+
carrierFrequency: true,
|
|
89
|
+
},
|
|
90
|
+
unknown: {
|
|
91
|
+
satelliteCount: false,
|
|
92
|
+
constellation: false,
|
|
93
|
+
cn0: false,
|
|
94
|
+
elevationAzimuth: false,
|
|
95
|
+
measurements: false,
|
|
96
|
+
carrierFrequency: false,
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Runtime quality / alert thresholds (library defaults).
|
|
102
|
+
* Override any subset with configure({ thresholds: { ... } }).
|
|
103
|
+
*/
|
|
104
|
+
export const DEFAULT_THRESHOLDS = {
|
|
105
|
+
/** Trip-start satellite visibility window (ms) */
|
|
106
|
+
tripStartSatWindowMs: 30 * 1000,
|
|
107
|
+
/** Minimum visible sats considered a good fix */
|
|
108
|
+
minSatellitesForGoodFix: 6,
|
|
109
|
+
/** Sustained poor tracking duration (ms) */
|
|
110
|
+
poorTrackingDurationMs: 10 * 60 * 1000,
|
|
111
|
+
/** Accuracy above this (meters) counts as poor */
|
|
112
|
+
poorAccuracyThresholdM: 50,
|
|
113
|
+
/** Teleport implied speed (km/h) */
|
|
114
|
+
teleportImpliedSpeedKmh: 200,
|
|
115
|
+
/** Teleport minimum jump distance (meters) */
|
|
116
|
+
teleportMinJumpMeters: 500,
|
|
117
|
+
/** Expected location update interval (ms) */
|
|
118
|
+
expectedTraceIntervalMs: 60 * 1000,
|
|
119
|
+
/** Multiplier on expected interval for throttle detection */
|
|
120
|
+
throttleGapMultiplier: 3,
|
|
121
|
+
/** Absolute minimum gap before throttle alert (ms) */
|
|
122
|
+
throttleMinGapMs: 3 * 60 * 1000,
|
|
123
|
+
/** How often to re-check OS / battery / time (ms) */
|
|
124
|
+
systemCheckIntervalMs: 60 * 1000,
|
|
125
|
+
/** Cooldown so the same alert type does not spam (ms) */
|
|
126
|
+
alertCooldownMs: 5 * 60 * 1000,
|
|
127
|
+
/** Clock skew vs HTTP Date sources (minutes) */
|
|
128
|
+
timeSkewThresholdMinutes: 2,
|
|
129
|
+
/** Battery level (0..1) below which lowBatteryMode is true */
|
|
130
|
+
lowBatteryFraction: 0.15,
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/** Named exports kept for docs / backward compatibility (= defaults). */
|
|
134
|
+
export const TRIP_START_SAT_WINDOW_MS = DEFAULT_THRESHOLDS.tripStartSatWindowMs;
|
|
135
|
+
export const MIN_SATELLITES_FOR_GOOD_FIX =
|
|
136
|
+
DEFAULT_THRESHOLDS.minSatellitesForGoodFix;
|
|
137
|
+
export const POOR_TRACKING_DURATION_MS =
|
|
138
|
+
DEFAULT_THRESHOLDS.poorTrackingDurationMs;
|
|
139
|
+
export const POOR_ACCURACY_THRESHOLD_M =
|
|
140
|
+
DEFAULT_THRESHOLDS.poorAccuracyThresholdM;
|
|
141
|
+
export const TELEPORT_IMPLIED_SPEED_KMH =
|
|
142
|
+
DEFAULT_THRESHOLDS.teleportImpliedSpeedKmh;
|
|
143
|
+
export const TELEPORT_MIN_JUMP_METERS = DEFAULT_THRESHOLDS.teleportMinJumpMeters;
|
|
144
|
+
export const EXPECTED_TRACE_INTERVAL_MS =
|
|
145
|
+
DEFAULT_THRESHOLDS.expectedTraceIntervalMs;
|
|
146
|
+
export const THROTTLE_GAP_MULTIPLIER = DEFAULT_THRESHOLDS.throttleGapMultiplier;
|
|
147
|
+
export const THROTTLE_MIN_GAP_MS = DEFAULT_THRESHOLDS.throttleMinGapMs;
|
|
148
|
+
export const SYSTEM_CHECK_INTERVAL_MS =
|
|
149
|
+
DEFAULT_THRESHOLDS.systemCheckIntervalMs;
|
|
150
|
+
export const ALERT_COOLDOWN_MS = DEFAULT_THRESHOLDS.alertCooldownMs;
|
|
151
|
+
export const TIME_SKEW_THRESHOLD_MINUTES =
|
|
152
|
+
DEFAULT_THRESHOLDS.timeSkewThresholdMinutes;
|
|
153
|
+
|
|
154
|
+
/** Same event names as the driver-app TrackingQualityMonitor for drop-in listeners. */
|
|
155
|
+
export const EVENT_NAMES = {
|
|
156
|
+
ALERT: "TrackingQualityMonitor:alert",
|
|
157
|
+
GNSS_UPDATE: "TrackingQualityMonitor:gnss",
|
|
158
|
+
STATUS: "TrackingQualityMonitor:status",
|
|
159
|
+
/** Explicit user/system actions for POC live log (start/stop/trip/fitness). */
|
|
160
|
+
ACTION: "TrackingQualityMonitor:action",
|
|
161
|
+
};
|