@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
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,521 @@
|
|
|
1
|
+
import type { ComponentType } from "react";
|
|
2
|
+
|
|
3
|
+
export type AlertSeverity = "blocker" | "warning" | "info";
|
|
4
|
+
|
|
5
|
+
export interface TrackingQualityAlert {
|
|
6
|
+
type: string;
|
|
7
|
+
severity: AlertSeverity;
|
|
8
|
+
title: string;
|
|
9
|
+
message: string;
|
|
10
|
+
meta?: Record<string, unknown>;
|
|
11
|
+
tripId?: string | null;
|
|
12
|
+
at: number;
|
|
13
|
+
gnss?: {
|
|
14
|
+
satellitesVisible?: number;
|
|
15
|
+
satellitesUsedInFix?: number;
|
|
16
|
+
} | null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface DeviceFitnessResult {
|
|
20
|
+
platform: string;
|
|
21
|
+
apiLevel: number | null;
|
|
22
|
+
apiScore: string;
|
|
23
|
+
apiReason: string;
|
|
24
|
+
gnssCapability: Record<string, unknown>;
|
|
25
|
+
settingsIssues: string[];
|
|
26
|
+
fitness: string;
|
|
27
|
+
capableForTracking: boolean;
|
|
28
|
+
thresholds: Record<string, number>;
|
|
29
|
+
assessedAt: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface SystemHealthResult {
|
|
33
|
+
platform: string;
|
|
34
|
+
powerSaveMode: boolean;
|
|
35
|
+
lowPowerMode: boolean;
|
|
36
|
+
batteryOptimizationEnabled: boolean;
|
|
37
|
+
batteryOptimizationIgnored: boolean;
|
|
38
|
+
batteryLevel: number | null;
|
|
39
|
+
lowBatteryMode: boolean;
|
|
40
|
+
autoDateTimeEnabled: boolean | null;
|
|
41
|
+
clockSkewed: boolean;
|
|
42
|
+
badTimeOrTimezone: boolean;
|
|
43
|
+
timeValidation?: TimeValidationResult;
|
|
44
|
+
backgroundTrackingRestricted: boolean;
|
|
45
|
+
manufacturer: string | null;
|
|
46
|
+
isSamsung: boolean;
|
|
47
|
+
/** OEM family used for background-allowlist navigation, or "none". */
|
|
48
|
+
oemFamily: OemFamily;
|
|
49
|
+
/** Diagnostic only; does not affect device fitness. */
|
|
50
|
+
neverSleepingApps: NeverSleepingAppsInfo | null;
|
|
51
|
+
checkedAt: number;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export type OemFamily =
|
|
55
|
+
| "none"
|
|
56
|
+
| "samsung"
|
|
57
|
+
| "xiaomi"
|
|
58
|
+
| "huawei"
|
|
59
|
+
| "oppo"
|
|
60
|
+
| "realme"
|
|
61
|
+
| "oneplus"
|
|
62
|
+
| "vivo"
|
|
63
|
+
| "asus"
|
|
64
|
+
| "nokia"
|
|
65
|
+
| "letv"
|
|
66
|
+
| "meizu"
|
|
67
|
+
| "motorola";
|
|
68
|
+
|
|
69
|
+
export type NeverSleepingState =
|
|
70
|
+
| "not_applicable"
|
|
71
|
+
| "unverified"
|
|
72
|
+
| "user_confirmed"
|
|
73
|
+
| "user_reported_missing";
|
|
74
|
+
|
|
75
|
+
export interface NeverSleepingAppsInfo {
|
|
76
|
+
/**
|
|
77
|
+
* True on OEMs that ship a dedicated background-allowlist screen
|
|
78
|
+
* (Samsung, Xiaomi, Huawei/Honor, Oppo/Realme/OnePlus, Vivo/iQOO, …).
|
|
79
|
+
*/
|
|
80
|
+
applicable: boolean;
|
|
81
|
+
/** Always false: no OEM exposes a public API to read the list. */
|
|
82
|
+
verifiable: false;
|
|
83
|
+
state: NeverSleepingState;
|
|
84
|
+
/** What the user reported (self-reported, NOT verified). */
|
|
85
|
+
userConfirmed: boolean | null;
|
|
86
|
+
/** Whether a known OEM allowlist screen can be opened on this device. */
|
|
87
|
+
settingsScreenAvailable: boolean;
|
|
88
|
+
/** Detected OEM family, or "none". */
|
|
89
|
+
oemFamily: OemFamily;
|
|
90
|
+
/** Human label for the OEM screen (e.g. "Never sleeping apps", "Startup manager"). */
|
|
91
|
+
label: string | null;
|
|
92
|
+
/** First resolvable OEM target id, if any (e.g. "samsung_never_sleeping"). */
|
|
93
|
+
target: string | null;
|
|
94
|
+
note: string;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface BackgroundSettingsStatus {
|
|
98
|
+
platform: string;
|
|
99
|
+
nativeModuleAvailable: boolean;
|
|
100
|
+
manufacturer: string | null;
|
|
101
|
+
brand?: string | null;
|
|
102
|
+
model?: string | null;
|
|
103
|
+
sdkInt?: number | null;
|
|
104
|
+
isSamsung: boolean;
|
|
105
|
+
/** OEM family used for background-allowlist navigation, or "none". */
|
|
106
|
+
oemFamily: OemFamily;
|
|
107
|
+
/** Verified via PowerManager. null when it cannot be determined. */
|
|
108
|
+
ignoringBatteryOptimizations: boolean | null;
|
|
109
|
+
neverSleepingApps: NeverSleepingAppsInfo;
|
|
110
|
+
error?: string;
|
|
111
|
+
checkedAt: number;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export interface TimeValidationResult {
|
|
115
|
+
platform: string;
|
|
116
|
+
autoDateTimeEnabled: boolean | null;
|
|
117
|
+
clockSkewed: boolean;
|
|
118
|
+
clockSkewCheckInconclusive: boolean;
|
|
119
|
+
badTimeOrTimezone: boolean;
|
|
120
|
+
thresholdMinutes: number;
|
|
121
|
+
checkedAt: number;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export interface GnssStatusSnapshot {
|
|
125
|
+
isGNSSSupported: boolean;
|
|
126
|
+
isDualFrequencySupported: boolean;
|
|
127
|
+
isNavICSupported: boolean;
|
|
128
|
+
satellitesVisible: number;
|
|
129
|
+
satellitesUsedInFix: number;
|
|
130
|
+
averageSignalToNoiseRatio: number;
|
|
131
|
+
supportedConstellations: string[];
|
|
132
|
+
carrierFrequencies: number[];
|
|
133
|
+
satellites: unknown[];
|
|
134
|
+
apiLevel?: number;
|
|
135
|
+
supportsCn0?: boolean;
|
|
136
|
+
supportsCarrierFreq?: boolean;
|
|
137
|
+
platform: string;
|
|
138
|
+
unsupported?: boolean;
|
|
139
|
+
updatedAt: number;
|
|
140
|
+
error?: string;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export interface TrackingQualityStatus {
|
|
144
|
+
running: boolean;
|
|
145
|
+
platform: string;
|
|
146
|
+
apiLevel: number | null;
|
|
147
|
+
gnssSupported: boolean;
|
|
148
|
+
gnssListening: boolean;
|
|
149
|
+
tripId: string | null;
|
|
150
|
+
tripStartedAt: number | null;
|
|
151
|
+
tripStartMaxSats: number;
|
|
152
|
+
tripStartSatWindowFired: boolean;
|
|
153
|
+
lastTraceAt: number | null;
|
|
154
|
+
lastLocation: NormalizedLocation | null;
|
|
155
|
+
poorTrackingStartedAt: number | null;
|
|
156
|
+
latestGnss: GnssStatusSnapshot | null;
|
|
157
|
+
latestSystem: SystemHealthResult | null;
|
|
158
|
+
deviceFitness: DeviceFitnessResult | null;
|
|
159
|
+
recentAlerts: TrackingQualityAlert[];
|
|
160
|
+
thresholds: Thresholds;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export interface NormalizedLocation {
|
|
164
|
+
coords: {
|
|
165
|
+
latitude: number;
|
|
166
|
+
longitude: number;
|
|
167
|
+
accuracy: number | null;
|
|
168
|
+
altitude: number | null;
|
|
169
|
+
speed: number | null;
|
|
170
|
+
heading: number | null;
|
|
171
|
+
mocked: boolean;
|
|
172
|
+
};
|
|
173
|
+
timestamp: number | string;
|
|
174
|
+
mock: boolean;
|
|
175
|
+
raw: unknown;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export interface Thresholds {
|
|
179
|
+
tripStartSatWindowMs: number;
|
|
180
|
+
minSatellitesForGoodFix: number;
|
|
181
|
+
poorTrackingDurationMs: number;
|
|
182
|
+
poorAccuracyThresholdM: number;
|
|
183
|
+
teleportImpliedSpeedKmh: number;
|
|
184
|
+
teleportMinJumpMeters: number;
|
|
185
|
+
expectedTraceIntervalMs: number;
|
|
186
|
+
throttleGapMultiplier: number;
|
|
187
|
+
throttleMinGapMs: number;
|
|
188
|
+
systemCheckIntervalMs: number;
|
|
189
|
+
alertCooldownMs: number;
|
|
190
|
+
timeSkewThresholdMinutes: number;
|
|
191
|
+
lowBatteryFraction: number;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export interface ApiLevelThresholds {
|
|
195
|
+
MIN_LEGACY_GNSS: number;
|
|
196
|
+
MIN_BASIC_GNSS: number;
|
|
197
|
+
MIN_FULL_GNSS_STATUS: number;
|
|
198
|
+
MIN_CARRIER_FREQUENCY: number;
|
|
199
|
+
MIN_BACKGROUND_LOCATION_PERMISSION: number;
|
|
200
|
+
MIN_PRECISE_LOCATION_MODEL: number;
|
|
201
|
+
MIN_FGS_LOCATION_TYPE: number;
|
|
202
|
+
MIN_ACCEPTABLE_FOR_TRACKING: number;
|
|
203
|
+
PREFERRED_FOR_ENHANCED_GNSS: number;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export interface ConfigureOptions {
|
|
207
|
+
getPowerSaveMode?: (() => Promise<boolean>) | null;
|
|
208
|
+
isIgnoringBatteryOptimizations?: (() => Promise<boolean>) | null;
|
|
209
|
+
getPowerState?: (() => Promise<unknown>) | null;
|
|
210
|
+
getBatteryLevel?: (() => Promise<number | null>) | null;
|
|
211
|
+
isAutomaticDateTimeEnabled?: (() => Promise<boolean | null>) | null;
|
|
212
|
+
showNotification?:
|
|
213
|
+
| ((
|
|
214
|
+
title: string,
|
|
215
|
+
message: string,
|
|
216
|
+
options?: Record<string, unknown>,
|
|
217
|
+
) => void | Promise<void>)
|
|
218
|
+
| null;
|
|
219
|
+
persistAlert?: ((alert: TrackingQualityAlert) => void) | null;
|
|
220
|
+
logger?: {
|
|
221
|
+
log?: (...args: unknown[]) => void;
|
|
222
|
+
warn?: (...args: unknown[]) => void;
|
|
223
|
+
error?: (...args: unknown[]) => void;
|
|
224
|
+
} | null;
|
|
225
|
+
/** Partial override of DEFAULT_THRESHOLDS */
|
|
226
|
+
thresholds?: Partial<Thresholds>;
|
|
227
|
+
/** Partial override of DEFAULT_API_LEVEL_THRESHOLDS */
|
|
228
|
+
apiLevelThresholds?: Partial<ApiLevelThresholds>;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export interface TrackingQualityAction {
|
|
232
|
+
type: string;
|
|
233
|
+
message: string;
|
|
234
|
+
meta?: unknown;
|
|
235
|
+
tripId?: string | null;
|
|
236
|
+
at: number;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export declare function configure(options?: ConfigureOptions): ConfigureOptions;
|
|
240
|
+
export declare function getConfig(): ConfigureOptions;
|
|
241
|
+
export declare function resetConfig(): void;
|
|
242
|
+
export declare function getThresholds(): Thresholds;
|
|
243
|
+
export declare function getApiLevelThresholds(): ApiLevelThresholds;
|
|
244
|
+
export declare const DEFAULT_THRESHOLDS: Thresholds;
|
|
245
|
+
export declare const DEFAULT_API_LEVEL_THRESHOLDS: ApiLevelThresholds;
|
|
246
|
+
|
|
247
|
+
export declare function collectSystemHealth(): Promise<SystemHealthResult>;
|
|
248
|
+
|
|
249
|
+
export declare const NEVER_SLEEPING_STATE: {
|
|
250
|
+
NOT_APPLICABLE: "not_applicable";
|
|
251
|
+
UNVERIFIED: "unverified";
|
|
252
|
+
USER_CONFIRMED: "user_confirmed";
|
|
253
|
+
USER_REPORTED_MISSING: "user_reported_missing";
|
|
254
|
+
};
|
|
255
|
+
/** Battery optimization (verified) + OEM background allowlist (unverifiable). */
|
|
256
|
+
export declare function getBackgroundSettingsStatus(): Promise<BackgroundSettingsStatus>;
|
|
257
|
+
/** Android "Ignore battery optimizations". null when undeterminable. */
|
|
258
|
+
export declare function isIgnoringBatteryOptimizations(): Promise<
|
|
259
|
+
boolean | null
|
|
260
|
+
>;
|
|
261
|
+
/**
|
|
262
|
+
* Opens this device's OEM background-allowlist screen only (Samsung Never
|
|
263
|
+
* sleeping, Oppo/OnePlus Startup manager, Vivo Background startup, …).
|
|
264
|
+
* Does not fall back to generic Android screens. Never rejects.
|
|
265
|
+
*/
|
|
266
|
+
export declare function openNeverSleepingApps(): Promise<OpenBackgroundRestrictionResult>;
|
|
267
|
+
export interface OpenBackgroundRestrictionResult {
|
|
268
|
+
/** true when some settings screen was started. */
|
|
269
|
+
opened: boolean;
|
|
270
|
+
/**
|
|
271
|
+
* Which screen opened, e.g. "samsung_never_sleeping", "xiaomi_autostart",
|
|
272
|
+
* "huawei_startup_manager", "coloros_startup_manager", "oplus_startup_manager",
|
|
273
|
+
* "vivo_background_startup", "battery_optimization", "app_details", or "none".
|
|
274
|
+
*/
|
|
275
|
+
target: string;
|
|
276
|
+
/** true for a manufacturer-specific screen, false for the universal fallbacks. */
|
|
277
|
+
isOemScreen: boolean;
|
|
278
|
+
manufacturer: string | null;
|
|
279
|
+
/** OEM family used to pick the screen, or "none". */
|
|
280
|
+
oemFamily: OemFamily;
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Opens the best background / autostart / never-sleeping screen for this
|
|
284
|
+
* device on any Android phone: OEM screen -> battery optimization list ->
|
|
285
|
+
* app info. Best-effort; cannot verify the app was added to any list.
|
|
286
|
+
* Never rejects.
|
|
287
|
+
*/
|
|
288
|
+
export declare function openBackgroundRestrictionSettings(): Promise<OpenBackgroundRestrictionResult>;
|
|
289
|
+
/** Opens Android's "Optimize battery usage" list. false on failure. */
|
|
290
|
+
export declare function openBatteryOptimizationSettings(): Promise<boolean>;
|
|
291
|
+
/** Persist what the user reports about the OEM allowlist (null clears). Not verification. */
|
|
292
|
+
export declare function setNeverSleepingAppsConfirmed(
|
|
293
|
+
confirmed: boolean | null,
|
|
294
|
+
): Promise<boolean>;
|
|
295
|
+
/** Best-effort OEM family from manufacturer/brand strings. */
|
|
296
|
+
export declare function detectOemFamilyFromVendor(
|
|
297
|
+
manufacturer?: string | null,
|
|
298
|
+
brand?: string | null,
|
|
299
|
+
): OemFamily;
|
|
300
|
+
/** Human label for an OEM allowlist screen, or null when oemFamily is "none". */
|
|
301
|
+
export declare function oemRestrictionLabelForFamily(
|
|
302
|
+
oemFamily: OemFamily | string,
|
|
303
|
+
): string | null;
|
|
304
|
+
export declare function assessDeviceFitness(options?: {
|
|
305
|
+
apiLevel?: number | null;
|
|
306
|
+
systemHealth?: SystemHealthResult | null;
|
|
307
|
+
gnssCapabilityFlags?: Record<string, unknown> | null;
|
|
308
|
+
}): DeviceFitnessResult;
|
|
309
|
+
export declare function getAndroidApiLevel(): number | null;
|
|
310
|
+
export declare function getGnssCapabilityProfile(
|
|
311
|
+
apiLevel: number | null,
|
|
312
|
+
): Record<string, unknown>;
|
|
313
|
+
export declare function scoreApiLevel(apiLevel: number | null): {
|
|
314
|
+
score: string;
|
|
315
|
+
reason: string;
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
export declare function validateTimeAndTimezone(options?: {
|
|
319
|
+
thresholdMinutes?: number;
|
|
320
|
+
}): Promise<TimeValidationResult>;
|
|
321
|
+
export declare function isAutomaticDateTimeEnabled(): Promise<boolean | null>;
|
|
322
|
+
/** Opens Android Date & time settings. Returns false on iOS / if unavailable. */
|
|
323
|
+
export declare function openDateTimeSettings(): Promise<boolean>;
|
|
324
|
+
export declare function isClockSkewed(options?: {
|
|
325
|
+
thresholdMinutes?: number;
|
|
326
|
+
}): Promise<boolean | null>;
|
|
327
|
+
export declare function getTimeDifferenceInMinutes(options?: {
|
|
328
|
+
thresholdMinutes?: number;
|
|
329
|
+
}): Promise<boolean | null>;
|
|
330
|
+
|
|
331
|
+
export declare function normalizeLocation(
|
|
332
|
+
raw: unknown,
|
|
333
|
+
): NormalizedLocation | null;
|
|
334
|
+
|
|
335
|
+
export declare const ALERT_TYPES: Record<string, string>;
|
|
336
|
+
export declare const ALERT_SEVERITY: Record<string, AlertSeverity>;
|
|
337
|
+
export declare const EVENT_NAMES: Record<string, string>;
|
|
338
|
+
export declare const API_LEVEL_THRESHOLDS: Record<string, number>;
|
|
339
|
+
export declare const DEVICE_FITNESS: Record<string, string>;
|
|
340
|
+
export declare const MIN_SATELLITES_FOR_GOOD_FIX: number;
|
|
341
|
+
export declare const TRIP_START_SAT_WINDOW_MS: number;
|
|
342
|
+
export declare const POOR_TRACKING_DURATION_MS: number;
|
|
343
|
+
export declare const SYSTEM_CHECK_INTERVAL_MS: number;
|
|
344
|
+
export declare const TIME_SKEW_THRESHOLD_MINUTES: number;
|
|
345
|
+
|
|
346
|
+
export declare class TrackingQualityMonitor {
|
|
347
|
+
readonly isRunning: boolean;
|
|
348
|
+
readonly isLocationTrackingActive: boolean;
|
|
349
|
+
getStatus(): TrackingQualityStatus;
|
|
350
|
+
setLocationTrackingActive(active: boolean): void;
|
|
351
|
+
evaluateDeviceFitnessOnLogin(options?: {
|
|
352
|
+
force?: boolean;
|
|
353
|
+
}): Promise<DeviceFitnessResult>;
|
|
354
|
+
evaluateDeviceFitness(options?: {
|
|
355
|
+
logActions?: boolean;
|
|
356
|
+
}): Promise<DeviceFitnessResult>;
|
|
357
|
+
start(options?: {
|
|
358
|
+
tripId?: string | null;
|
|
359
|
+
notify?: boolean;
|
|
360
|
+
/** Alias of `notify` (driver-app parity). */
|
|
361
|
+
notifyDriver?: boolean;
|
|
362
|
+
}): Promise<TrackingQualityStatus>;
|
|
363
|
+
onTripStarted(tripId?: string | null): void;
|
|
364
|
+
ingestLocation(location: unknown): void;
|
|
365
|
+
heartbeat(): void;
|
|
366
|
+
stop(options?: { clearTrip?: boolean }): Promise<void>;
|
|
367
|
+
onAlert(callback: (alert: TrackingQualityAlert) => void): () => void;
|
|
368
|
+
onStatus(callback: (status: TrackingQualityStatus) => void): () => void;
|
|
369
|
+
onGnssUpdate(callback: (gnss: GnssStatusSnapshot) => void): () => void;
|
|
370
|
+
onAction(callback: (action: TrackingQualityAction) => void): () => void;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
export interface TrackingMonitorLogLine {
|
|
374
|
+
id: string;
|
|
375
|
+
at: number;
|
|
376
|
+
level: string;
|
|
377
|
+
message: string;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
declare const trackingQualityMonitor: TrackingQualityMonitor;
|
|
381
|
+
export { trackingQualityMonitor };
|
|
382
|
+
export default trackingQualityMonitor;
|
|
383
|
+
|
|
384
|
+
export declare function useTrackingQuality(options?: {
|
|
385
|
+
autoStart?: boolean;
|
|
386
|
+
tripId?: string | null;
|
|
387
|
+
}): {
|
|
388
|
+
status: TrackingQualityStatus;
|
|
389
|
+
running: boolean;
|
|
390
|
+
locationTrackingActive: boolean;
|
|
391
|
+
platform: string;
|
|
392
|
+
apiLevel: number | null;
|
|
393
|
+
gnssSupported: boolean;
|
|
394
|
+
gnssListening: boolean;
|
|
395
|
+
tripId: string | null;
|
|
396
|
+
tripStartMaxSats: number;
|
|
397
|
+
tripStartSatWindowFired: boolean;
|
|
398
|
+
deviceFitness: DeviceFitnessResult | null;
|
|
399
|
+
latestGnss: GnssStatusSnapshot | null;
|
|
400
|
+
latestSystem: SystemHealthResult | null;
|
|
401
|
+
lastLocation: NormalizedLocation | null;
|
|
402
|
+
recentAlerts: TrackingQualityAlert[];
|
|
403
|
+
lastAlert: TrackingQualityAlert | null;
|
|
404
|
+
lastAction: TrackingQualityAction | null;
|
|
405
|
+
actions: TrackingQualityAction[];
|
|
406
|
+
start: (opts?: {
|
|
407
|
+
tripId?: string | null;
|
|
408
|
+
notify?: boolean;
|
|
409
|
+
notifyDriver?: boolean;
|
|
410
|
+
}) => Promise<TrackingQualityStatus>;
|
|
411
|
+
stop: (opts?: { clearTrip?: boolean }) => Promise<void>;
|
|
412
|
+
onTripStarted: (id?: string | null) => void;
|
|
413
|
+
ingestLocation: (location: unknown) => void;
|
|
414
|
+
evaluateDeviceFitness: (opts?: {
|
|
415
|
+
logActions?: boolean;
|
|
416
|
+
}) => Promise<DeviceFitnessResult>;
|
|
417
|
+
evaluateDeviceFitnessOnLogin: (opts?: {
|
|
418
|
+
force?: boolean;
|
|
419
|
+
}) => Promise<DeviceFitnessResult>;
|
|
420
|
+
setLocationTrackingActive: (active: boolean) => void;
|
|
421
|
+
heartbeat: () => void;
|
|
422
|
+
getStatus: () => TrackingQualityStatus;
|
|
423
|
+
monitor: TrackingQualityMonitor;
|
|
424
|
+
};
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* Full monitoring hook (POC-equivalent): status + alerts + throttled live log + controls.
|
|
428
|
+
*/
|
|
429
|
+
export declare function useTrackingMonitor(options?: {
|
|
430
|
+
autoStart?: boolean;
|
|
431
|
+
tripId?: string | null;
|
|
432
|
+
maxLogLines?: number;
|
|
433
|
+
gnssLogThrottleMs?: number;
|
|
434
|
+
}): {
|
|
435
|
+
status: TrackingQualityStatus;
|
|
436
|
+
running: boolean;
|
|
437
|
+
locationTrackingActive: boolean;
|
|
438
|
+
platform: string;
|
|
439
|
+
apiLevel: number | null;
|
|
440
|
+
gnssSupported: boolean;
|
|
441
|
+
gnssListening: boolean;
|
|
442
|
+
tripId: string | null;
|
|
443
|
+
tripStartMaxSats: number;
|
|
444
|
+
tripStartSatWindowFired: boolean;
|
|
445
|
+
deviceFitness: DeviceFitnessResult | null;
|
|
446
|
+
latestGnss: GnssStatusSnapshot | null;
|
|
447
|
+
latestSystem: SystemHealthResult | null;
|
|
448
|
+
lastLocation: NormalizedLocation | null;
|
|
449
|
+
recentAlerts: TrackingQualityAlert[];
|
|
450
|
+
thresholds: Thresholds | undefined;
|
|
451
|
+
lastAlert: TrackingQualityAlert | null;
|
|
452
|
+
lastAction: TrackingQualityAction | null;
|
|
453
|
+
logs: TrackingMonitorLogLine[];
|
|
454
|
+
appendLog: (level: string, message: string) => void;
|
|
455
|
+
clearLogs: () => void;
|
|
456
|
+
refresh: () => void;
|
|
457
|
+
start: (opts?: {
|
|
458
|
+
tripId?: string | null;
|
|
459
|
+
notify?: boolean;
|
|
460
|
+
notifyDriver?: boolean;
|
|
461
|
+
}) => Promise<TrackingQualityStatus>;
|
|
462
|
+
stop: (opts?: { clearTrip?: boolean }) => Promise<void>;
|
|
463
|
+
onTripStarted: (id?: string | null) => void;
|
|
464
|
+
ingestLocation: (location: unknown) => void;
|
|
465
|
+
evaluateDeviceFitness: (opts?: {
|
|
466
|
+
logActions?: boolean;
|
|
467
|
+
}) => Promise<DeviceFitnessResult>;
|
|
468
|
+
evaluateDeviceFitnessOnLogin: (opts?: {
|
|
469
|
+
force?: boolean;
|
|
470
|
+
}) => Promise<DeviceFitnessResult>;
|
|
471
|
+
setLocationTrackingActive: (active: boolean) => void;
|
|
472
|
+
heartbeat: () => void;
|
|
473
|
+
getStatus: () => TrackingQualityStatus;
|
|
474
|
+
monitor: TrackingQualityMonitor;
|
|
475
|
+
};
|
|
476
|
+
|
|
477
|
+
export declare function useDeviceFitness(options?: {
|
|
478
|
+
evaluateOnMount?: boolean;
|
|
479
|
+
}): {
|
|
480
|
+
fitness: DeviceFitnessResult | null;
|
|
481
|
+
loading: boolean;
|
|
482
|
+
error: unknown;
|
|
483
|
+
evaluate: () => Promise<DeviceFitnessResult>;
|
|
484
|
+
apiLevel: number | null;
|
|
485
|
+
capableForTracking: boolean;
|
|
486
|
+
settingsIssues: string[];
|
|
487
|
+
};
|
|
488
|
+
|
|
489
|
+
export declare function useSystemHealth(options?: {
|
|
490
|
+
refreshOnMount?: boolean;
|
|
491
|
+
intervalMs?: number;
|
|
492
|
+
}): {
|
|
493
|
+
health: SystemHealthResult | null;
|
|
494
|
+
loading: boolean;
|
|
495
|
+
error: unknown;
|
|
496
|
+
refresh: () => Promise<SystemHealthResult>;
|
|
497
|
+
batteryLevel: number | null | undefined;
|
|
498
|
+
lowPowerMode: boolean;
|
|
499
|
+
batteryOptimizationEnabled: boolean;
|
|
500
|
+
backgroundTrackingRestricted: boolean;
|
|
501
|
+
badTimeOrTimezone: boolean;
|
|
502
|
+
};
|
|
503
|
+
|
|
504
|
+
export declare function useTimeValidation(options?: {
|
|
505
|
+
validateOnMount?: boolean;
|
|
506
|
+
}): {
|
|
507
|
+
result: TimeValidationResult | null;
|
|
508
|
+
loading: boolean;
|
|
509
|
+
error: unknown;
|
|
510
|
+
validate: (options?: {
|
|
511
|
+
thresholdMinutes?: number;
|
|
512
|
+
}) => Promise<TimeValidationResult>;
|
|
513
|
+
autoDateTimeEnabled: boolean | null | undefined;
|
|
514
|
+
clockSkewed: boolean;
|
|
515
|
+
badTimeOrTimezone: boolean;
|
|
516
|
+
};
|
|
517
|
+
|
|
518
|
+
export declare function useTrackingQualityAlerts(options?: { max?: number }): {
|
|
519
|
+
alerts: TrackingQualityAlert[];
|
|
520
|
+
lastAlert: TrackingQualityAlert | null;
|
|
521
|
+
};
|
package/src/index.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import trackingQualityMonitor, {
|
|
2
|
+
TrackingQualityMonitor,
|
|
3
|
+
} from "./TrackingQualityMonitor";
|
|
4
|
+
import {
|
|
5
|
+
configure,
|
|
6
|
+
getConfig,
|
|
7
|
+
resetConfig,
|
|
8
|
+
getThresholds,
|
|
9
|
+
getApiLevelThresholds,
|
|
10
|
+
} from "./config";
|
|
11
|
+
import GnssMonitor, { GnssMonitor as GnssMonitorClass } from "./gnssMonitor";
|
|
12
|
+
import { collectSystemHealth } from "./systemHealth";
|
|
13
|
+
import {
|
|
14
|
+
NEVER_SLEEPING_STATE,
|
|
15
|
+
getBackgroundSettingsStatus,
|
|
16
|
+
isIgnoringBatteryOptimizations,
|
|
17
|
+
openNeverSleepingApps,
|
|
18
|
+
openBackgroundRestrictionSettings,
|
|
19
|
+
openBatteryOptimizationSettings,
|
|
20
|
+
setNeverSleepingAppsConfirmed,
|
|
21
|
+
detectOemFamilyFromVendor,
|
|
22
|
+
oemRestrictionLabelForFamily,
|
|
23
|
+
} from "./backgroundSettings";
|
|
24
|
+
import {
|
|
25
|
+
assessDeviceFitness,
|
|
26
|
+
getAndroidApiLevel,
|
|
27
|
+
getGnssCapabilityProfile,
|
|
28
|
+
scoreApiLevel,
|
|
29
|
+
} from "./deviceFitness";
|
|
30
|
+
import {
|
|
31
|
+
validateTimeAndTimezone,
|
|
32
|
+
isAutomaticDateTimeEnabled,
|
|
33
|
+
isClockSkewed,
|
|
34
|
+
getTimeDifferenceInMinutes,
|
|
35
|
+
openDateTimeSettings,
|
|
36
|
+
} from "./timeValidation";
|
|
37
|
+
import { normalizeLocation } from "./adapters/normalizeLocation";
|
|
38
|
+
import {
|
|
39
|
+
detectAbnormalTrace,
|
|
40
|
+
detectLocationThrottling,
|
|
41
|
+
getAccuracyMeters,
|
|
42
|
+
isGoodAccuracySample,
|
|
43
|
+
isMockedLocation,
|
|
44
|
+
isPoorTrackingSample,
|
|
45
|
+
locationTimestampMs,
|
|
46
|
+
} from "./traceAnalyzer";
|
|
47
|
+
import { useTrackingQuality } from "./hooks/useTrackingQuality";
|
|
48
|
+
import { useTrackingMonitor } from "./hooks/useTrackingMonitor";
|
|
49
|
+
import { useDeviceFitness } from "./hooks/useDeviceFitness";
|
|
50
|
+
import { useSystemHealth } from "./hooks/useSystemHealth";
|
|
51
|
+
import { useTimeValidation } from "./hooks/useTimeValidation";
|
|
52
|
+
import { useTrackingQualityAlerts } from "./hooks/useTrackingQualityAlerts";
|
|
53
|
+
|
|
54
|
+
export {
|
|
55
|
+
// Singleton + class
|
|
56
|
+
trackingQualityMonitor,
|
|
57
|
+
TrackingQualityMonitor,
|
|
58
|
+
// Config
|
|
59
|
+
configure,
|
|
60
|
+
getConfig,
|
|
61
|
+
resetConfig,
|
|
62
|
+
getThresholds,
|
|
63
|
+
getApiLevelThresholds,
|
|
64
|
+
// GNSS
|
|
65
|
+
GnssMonitor,
|
|
66
|
+
GnssMonitorClass,
|
|
67
|
+
// Independent modules
|
|
68
|
+
collectSystemHealth,
|
|
69
|
+
// Background restrictions (battery optimization + OEM allowlists)
|
|
70
|
+
NEVER_SLEEPING_STATE,
|
|
71
|
+
getBackgroundSettingsStatus,
|
|
72
|
+
isIgnoringBatteryOptimizations,
|
|
73
|
+
openNeverSleepingApps,
|
|
74
|
+
openBackgroundRestrictionSettings,
|
|
75
|
+
openBatteryOptimizationSettings,
|
|
76
|
+
setNeverSleepingAppsConfirmed,
|
|
77
|
+
detectOemFamilyFromVendor,
|
|
78
|
+
oemRestrictionLabelForFamily,
|
|
79
|
+
assessDeviceFitness,
|
|
80
|
+
getAndroidApiLevel,
|
|
81
|
+
getGnssCapabilityProfile,
|
|
82
|
+
scoreApiLevel,
|
|
83
|
+
validateTimeAndTimezone,
|
|
84
|
+
isAutomaticDateTimeEnabled,
|
|
85
|
+
openDateTimeSettings,
|
|
86
|
+
isClockSkewed,
|
|
87
|
+
getTimeDifferenceInMinutes,
|
|
88
|
+
// Traces
|
|
89
|
+
normalizeLocation,
|
|
90
|
+
detectAbnormalTrace,
|
|
91
|
+
detectLocationThrottling,
|
|
92
|
+
getAccuracyMeters,
|
|
93
|
+
isGoodAccuracySample,
|
|
94
|
+
isMockedLocation,
|
|
95
|
+
isPoorTrackingSample,
|
|
96
|
+
locationTimestampMs,
|
|
97
|
+
// Hooks
|
|
98
|
+
useTrackingQuality,
|
|
99
|
+
useTrackingMonitor,
|
|
100
|
+
useDeviceFitness,
|
|
101
|
+
useSystemHealth,
|
|
102
|
+
useTimeValidation,
|
|
103
|
+
useTrackingQualityAlerts,
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export {
|
|
107
|
+
ALERT_TYPES,
|
|
108
|
+
ALERT_SEVERITY,
|
|
109
|
+
EVENT_NAMES,
|
|
110
|
+
API_LEVEL_THRESHOLDS,
|
|
111
|
+
DEFAULT_API_LEVEL_THRESHOLDS,
|
|
112
|
+
DEFAULT_THRESHOLDS,
|
|
113
|
+
DEVICE_FITNESS,
|
|
114
|
+
GNSS_CAPABILITY_BY_API,
|
|
115
|
+
MIN_SATELLITES_FOR_GOOD_FIX,
|
|
116
|
+
TRIP_START_SAT_WINDOW_MS,
|
|
117
|
+
POOR_TRACKING_DURATION_MS,
|
|
118
|
+
POOR_ACCURACY_THRESHOLD_M,
|
|
119
|
+
TELEPORT_IMPLIED_SPEED_KMH,
|
|
120
|
+
TELEPORT_MIN_JUMP_METERS,
|
|
121
|
+
EXPECTED_TRACE_INTERVAL_MS,
|
|
122
|
+
THROTTLE_GAP_MULTIPLIER,
|
|
123
|
+
THROTTLE_MIN_GAP_MS,
|
|
124
|
+
SYSTEM_CHECK_INTERVAL_MS,
|
|
125
|
+
ALERT_COOLDOWN_MS,
|
|
126
|
+
TIME_SKEW_THRESHOLD_MINUTES,
|
|
127
|
+
} from "./constants";
|
|
128
|
+
|
|
129
|
+
export default trackingQualityMonitor;
|