@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.
@@ -0,0 +1,636 @@
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.content.pm.PackageManager;
10
+ import android.net.Uri;
11
+ import android.os.Build;
12
+ import android.os.PowerManager;
13
+ import android.provider.Settings;
14
+
15
+ import com.facebook.react.bridge.Arguments;
16
+ import com.facebook.react.bridge.Promise;
17
+ import com.facebook.react.bridge.ReactApplicationContext;
18
+ import com.facebook.react.bridge.ReactContextBaseJavaModule;
19
+ import com.facebook.react.bridge.ReactMethod;
20
+ import com.facebook.react.bridge.WritableMap;
21
+
22
+ import java.util.ArrayList;
23
+ import java.util.List;
24
+ import java.util.Locale;
25
+
26
+ /**
27
+ * Background-restriction helpers for tracking health.
28
+ *
29
+ * Two different settings are involved and they are NOT the same thing:
30
+ *
31
+ * 1. Android "Ignore battery optimizations" (Doze allowlist)
32
+ * -> verifiable via PowerManager.isIgnoringBatteryOptimizations().
33
+ *
34
+ * 2. OEM "keep running / autostart / never sleeping" allowlists
35
+ * (Samsung Never sleeping apps, Xiaomi Autostart, Huawei Startup manager,
36
+ * Oppo/Realme/OnePlus Startup manager, Vivo/iQOO Background startup, …)
37
+ * -> OEMs document (or leak) intents to OPEN these screens, but none expose
38
+ * a public API to READ whether this app is on the list. We therefore
39
+ * never claim membership as verified; we only remember what the user
40
+ * told us via setNeverSleepingAppsConfirmed().
41
+ *
42
+ * Automatic date/time lives in a separate package:
43
+ * {@link com.gnsstrackinghealth.autodatetime.AutoDateTimeModule}.
44
+ *
45
+ * Samsung reference: Application Management ->
46
+ * action com.samsung.android.sm.ACTION_OPEN_CHECKABLE_LISTACTIVITY
47
+ * package com.samsung.android.lool
48
+ * extra activity_type = 0 (Sleeping) | 1 (Deep sleeping) | 2 (Never sleeping)
49
+ */
50
+ public class GnssTrackingHealthSettingsModule extends ReactContextBaseJavaModule {
51
+
52
+ static final String NAME = "GnssTrackingHealthSettings";
53
+
54
+ private static final String PREFS_NAME = "gnss_tracking_health";
55
+ private static final String KEY_NEVER_SLEEPING_CONFIRMED = "never_sleeping_confirmed";
56
+
57
+ private static final String SAMSUNG_DEVICE_CARE_PACKAGE = "com.samsung.android.lool";
58
+ private static final String SAMSUNG_ACTION_OPEN_CHECKABLE_LIST =
59
+ "com.samsung.android.sm.ACTION_OPEN_CHECKABLE_LISTACTIVITY";
60
+ private static final String SAMSUNG_EXTRA_ACTIVITY_TYPE = "activity_type";
61
+ private static final int SAMSUNG_ACTIVITY_NEVER_SLEEPING = 2;
62
+
63
+ /** OEM families that ship a dedicated background-allowlist screen. */
64
+ private static final String OEM_NONE = "none";
65
+ private static final String OEM_SAMSUNG = "samsung";
66
+ private static final String OEM_XIAOMI = "xiaomi";
67
+ private static final String OEM_HUAWEI = "huawei";
68
+ private static final String OEM_OPPO = "oppo";
69
+ private static final String OEM_REALME = "realme";
70
+ private static final String OEM_ONEPLUS = "oneplus";
71
+ private static final String OEM_VIVO = "vivo";
72
+ private static final String OEM_ASUS = "asus";
73
+ private static final String OEM_NOKIA = "nokia";
74
+ private static final String OEM_LETV = "letv";
75
+ private static final String OEM_MEIZU = "meizu";
76
+ private static final String OEM_MOTOROLA = "motorola";
77
+
78
+ public GnssTrackingHealthSettingsModule(ReactApplicationContext reactContext) {
79
+ super(reactContext);
80
+ }
81
+
82
+ @Override
83
+ public String getName() {
84
+ return NAME;
85
+ }
86
+
87
+ // ---------------------------------------------------------------------
88
+ // Status
89
+ // ---------------------------------------------------------------------
90
+
91
+ /**
92
+ * Resolves a map with device info, the verifiable battery-optimization
93
+ * flag, and the (unverifiable) OEM background-allowlist context.
94
+ */
95
+ @ReactMethod
96
+ public void getBackgroundSettingsStatus(Promise promise) {
97
+ try {
98
+ WritableMap map = Arguments.createMap();
99
+ String oemFamily = detectOemFamily();
100
+ boolean samsung = OEM_SAMSUNG.equals(oemFamily);
101
+ SettingsTarget oemScreen = findFirstResolvableOemTarget();
102
+
103
+ map.putString("manufacturer", Build.MANUFACTURER);
104
+ map.putString("brand", Build.BRAND);
105
+ map.putString("model", Build.MODEL);
106
+ map.putInt("sdkInt", Build.VERSION.SDK_INT);
107
+ map.putBoolean("isSamsung", samsung);
108
+ map.putString("oemFamily", oemFamily);
109
+ map.putBoolean("oemRestrictionApplicable", !OEM_NONE.equals(oemFamily));
110
+ if (OEM_NONE.equals(oemFamily)) {
111
+ map.putNull("oemRestrictionLabel");
112
+ } else {
113
+ map.putString("oemRestrictionLabel", oemRestrictionLabel(oemFamily));
114
+ }
115
+ map.putBoolean("ignoringBatteryOptimizations", isIgnoringBatteryOptimizationsInternal());
116
+ map.putBoolean("neverSleepingScreenAvailable", oemScreen != null);
117
+ if (oemScreen != null) {
118
+ map.putString("oemRestrictionTarget", oemScreen.id);
119
+ } else {
120
+ map.putNull("oemRestrictionTarget");
121
+ }
122
+
123
+ SharedPreferences prefs = prefs();
124
+ if (prefs.contains(KEY_NEVER_SLEEPING_CONFIRMED)) {
125
+ map.putBoolean(
126
+ "neverSleepingUserConfirmed",
127
+ prefs.getBoolean(KEY_NEVER_SLEEPING_CONFIRMED, false));
128
+ } else {
129
+ map.putNull("neverSleepingUserConfirmed");
130
+ }
131
+
132
+ promise.resolve(map);
133
+ } catch (Exception e) {
134
+ promise.reject("BACKGROUND_STATUS_FAILED", e);
135
+ }
136
+ }
137
+
138
+ @ReactMethod
139
+ public void isIgnoringBatteryOptimizations(Promise promise) {
140
+ try {
141
+ promise.resolve(isIgnoringBatteryOptimizationsInternal());
142
+ } catch (Exception e) {
143
+ promise.reject("CHECK_FAILED", e);
144
+ }
145
+ }
146
+
147
+ // ---------------------------------------------------------------------
148
+ // Navigation
149
+ // ---------------------------------------------------------------------
150
+
151
+ /**
152
+ * Opens this device's OEM background-allowlist screen (Samsung Never
153
+ * sleeping apps, Oppo/OnePlus Startup manager, Vivo Background startup,
154
+ * Xiaomi Autostart, …). Resolves false when the OEM has no such screen
155
+ * or none of the known activities can be started.
156
+ *
157
+ * Unlike {@link #openBackgroundRestrictionSettings}, this never falls
158
+ * back to the generic Android battery-optimization / app-info screens —
159
+ * callers that want those should use openBackgroundRestrictionSettings
160
+ * or openBatteryOptimizationSettings.
161
+ */
162
+ @ReactMethod
163
+ public void openNeverSleepingApps(Promise promise) {
164
+ try {
165
+ WritableMap result = Arguments.createMap();
166
+ result.putString("manufacturer", Build.MANUFACTURER);
167
+ result.putString("oemFamily", detectOemFamily());
168
+
169
+ SettingsTarget oemScreen = findFirstResolvableOemTarget();
170
+ if (oemScreen != null && launch(oemScreen.intent)) {
171
+ result.putBoolean("opened", true);
172
+ result.putString("target", oemScreen.id);
173
+ result.putBoolean("isOemScreen", true);
174
+ promise.resolve(result);
175
+ return;
176
+ }
177
+
178
+ result.putBoolean("opened", false);
179
+ result.putString("target", "none");
180
+ result.putBoolean("isOemScreen", false);
181
+ promise.resolve(result);
182
+ } catch (Exception e) {
183
+ promise.reject("OPEN_SETTINGS_FAILED", e);
184
+ }
185
+ }
186
+
187
+ /**
188
+ * Opens the best available "background / autostart / never sleeping"
189
+ * screen for THIS device. Works on every Android device:
190
+ *
191
+ * 1. Manufacturer-specific screen (Samsung Never sleeping apps, Xiaomi
192
+ * Autostart, Huawei/Honor Startup manager, Oppo/Realme/OnePlus
193
+ * Startup manager, Vivo/iQOO Background startup, Asus, Nokia, Letv,
194
+ * Meizu, Motorola).
195
+ * 2. Android "Optimize battery usage" list (all devices).
196
+ * 3. This app's system "App info" page (all devices).
197
+ *
198
+ * OEM activities are undocumented and change between OS versions, so each
199
+ * is tried and skipped if it cannot be started. Resolves
200
+ * {opened, target, isOemScreen, manufacturer, oemFamily}; never claims
201
+ * the app was added to any list (no OEM exposes a way to read that).
202
+ */
203
+ @ReactMethod
204
+ public void openBackgroundRestrictionSettings(Promise promise) {
205
+ try {
206
+ WritableMap result = Arguments.createMap();
207
+ result.putString("manufacturer", Build.MANUFACTURER);
208
+ result.putString("oemFamily", detectOemFamily());
209
+
210
+ for (SettingsTarget target : buildSettingsTargets(/* oemOnly */ false)) {
211
+ if (launch(target.intent)) {
212
+ result.putBoolean("opened", true);
213
+ result.putString("target", target.id);
214
+ result.putBoolean("isOemScreen", target.oem);
215
+ promise.resolve(result);
216
+ return;
217
+ }
218
+ }
219
+
220
+ result.putBoolean("opened", false);
221
+ result.putString("target", "none");
222
+ result.putBoolean("isOemScreen", false);
223
+ promise.resolve(result);
224
+ } catch (Exception e) {
225
+ promise.reject("OPEN_SETTINGS_FAILED", e);
226
+ }
227
+ }
228
+
229
+ /**
230
+ * Opens Android's "Optimize battery usage" list (Doze allowlist).
231
+ */
232
+ @ReactMethod
233
+ public void openBatteryOptimizationSettings(Promise promise) {
234
+ try {
235
+ promise.resolve(launch(new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS)));
236
+ } catch (Exception e) {
237
+ promise.reject("OPEN_SETTINGS_FAILED", e);
238
+ }
239
+ }
240
+
241
+ // ---------------------------------------------------------------------
242
+ // User confirmation (OEMs expose no way to read the list)
243
+ // ---------------------------------------------------------------------
244
+
245
+ @ReactMethod
246
+ public void setNeverSleepingAppsConfirmed(boolean confirmed, Promise promise) {
247
+ try {
248
+ prefs().edit().putBoolean(KEY_NEVER_SLEEPING_CONFIRMED, confirmed).apply();
249
+ promise.resolve(true);
250
+ } catch (Exception e) {
251
+ promise.reject("PERSIST_FAILED", e);
252
+ }
253
+ }
254
+
255
+ @ReactMethod
256
+ public void clearNeverSleepingAppsConfirmation(Promise promise) {
257
+ try {
258
+ prefs().edit().remove(KEY_NEVER_SLEEPING_CONFIRMED).apply();
259
+ promise.resolve(true);
260
+ } catch (Exception e) {
261
+ promise.reject("PERSIST_FAILED", e);
262
+ }
263
+ }
264
+
265
+ // ---------------------------------------------------------------------
266
+ // Internals
267
+ // ---------------------------------------------------------------------
268
+
269
+ private String vendorBlob() {
270
+ return (Build.MANUFACTURER + " " + Build.BRAND).toLowerCase(Locale.ROOT);
271
+ }
272
+
273
+ /**
274
+ * Best-effort OEM family from manufacturer/brand. Used for labels and to
275
+ * decide whether the OEM-allowlist flow is applicable. Detection is
276
+ * independent of whether a known activity currently resolves.
277
+ */
278
+ private String detectOemFamily() {
279
+ String vendor = vendorBlob();
280
+ if (vendor.contains("samsung")) {
281
+ return OEM_SAMSUNG;
282
+ }
283
+ if (vendor.contains("xiaomi") || vendor.contains("redmi") || vendor.contains("poco")) {
284
+ return OEM_XIAOMI;
285
+ }
286
+ if (vendor.contains("huawei") || vendor.contains("honor")) {
287
+ return OEM_HUAWEI;
288
+ }
289
+ // OnePlus / Realme before generic Oppo — they share ColorOS/Oplus screens
290
+ // but we still surface the specific brand in status.
291
+ if (vendor.contains("oneplus")) {
292
+ return OEM_ONEPLUS;
293
+ }
294
+ if (vendor.contains("realme")) {
295
+ return OEM_REALME;
296
+ }
297
+ if (vendor.contains("oppo")) {
298
+ return OEM_OPPO;
299
+ }
300
+ if (vendor.contains("vivo") || vendor.contains("iqoo")) {
301
+ return OEM_VIVO;
302
+ }
303
+ if (vendor.contains("asus")) {
304
+ return OEM_ASUS;
305
+ }
306
+ if (vendor.contains("nokia") || vendor.contains("hmd")) {
307
+ return OEM_NOKIA;
308
+ }
309
+ if (vendor.contains("letv") || vendor.contains("leeco")) {
310
+ return OEM_LETV;
311
+ }
312
+ if (vendor.contains("meizu")) {
313
+ return OEM_MEIZU;
314
+ }
315
+ // Motorola / Moto (Lenovo-owned). Near-stock Android; some builds still
316
+ // ship Lenovo security / pure-background screens.
317
+ if (vendor.contains("motorola") || vendor.contains("moto")) {
318
+ return OEM_MOTOROLA;
319
+ }
320
+ return OEM_NONE;
321
+ }
322
+
323
+ private static String oemRestrictionLabel(String oemFamily) {
324
+ switch (oemFamily) {
325
+ case OEM_SAMSUNG:
326
+ return "Never sleeping apps";
327
+ case OEM_XIAOMI:
328
+ return "Autostart / Battery saver";
329
+ case OEM_HUAWEI:
330
+ return "Startup manager / App launch";
331
+ case OEM_OPPO:
332
+ case OEM_REALME:
333
+ case OEM_ONEPLUS:
334
+ return "Startup manager";
335
+ case OEM_VIVO:
336
+ return "Background startup / Whitelist";
337
+ case OEM_ASUS:
338
+ return "Auto-start manager";
339
+ case OEM_NOKIA:
340
+ return "Power saver exceptions";
341
+ case OEM_LETV:
342
+ return "Autoboot manager";
343
+ case OEM_MEIZU:
344
+ return "Background management";
345
+ case OEM_MOTOROLA:
346
+ return "Battery optimization / Background apps";
347
+ default:
348
+ return "Background restrictions";
349
+ }
350
+ }
351
+
352
+ private boolean isIgnoringBatteryOptimizationsInternal() {
353
+ ReactApplicationContext context = getReactApplicationContext();
354
+ PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
355
+ if (pm == null) {
356
+ return false;
357
+ }
358
+ return pm.isIgnoringBatteryOptimizations(context.getPackageName());
359
+ }
360
+
361
+ private Intent neverSleepingIntent() {
362
+ Intent intent = new Intent(SAMSUNG_ACTION_OPEN_CHECKABLE_LIST);
363
+ intent.setPackage(SAMSUNG_DEVICE_CARE_PACKAGE);
364
+ intent.putExtra(SAMSUNG_EXTRA_ACTIVITY_TYPE, SAMSUNG_ACTIVITY_NEVER_SLEEPING);
365
+ return intent;
366
+ }
367
+
368
+ private SettingsTarget findFirstResolvableOemTarget() {
369
+ PackageManager pm = getReactApplicationContext().getPackageManager();
370
+ for (SettingsTarget target : buildSettingsTargets(/* oemOnly */ true)) {
371
+ try {
372
+ if (target.intent.resolveActivity(pm) != null) {
373
+ return target;
374
+ }
375
+ } catch (RuntimeException ignored) {
376
+ // Keep looking.
377
+ }
378
+ }
379
+ return null;
380
+ }
381
+
382
+ /** Starts the intent from the foreground activity when possible. */
383
+ private boolean launch(Intent intent) {
384
+ try {
385
+ Activity activity = getReactApplicationContext().getCurrentActivity();
386
+ if (activity != null) {
387
+ activity.startActivity(intent);
388
+ } else {
389
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
390
+ getReactApplicationContext().startActivity(intent);
391
+ }
392
+ return true;
393
+ } catch (ActivityNotFoundException | SecurityException e) {
394
+ // OEM screens vary by model / OS version; not an error.
395
+ return false;
396
+ } catch (RuntimeException e) {
397
+ // Some OEM activities throw other runtime errors (bad extras,
398
+ // missing permission). Treat as "cannot open" and try the next.
399
+ return false;
400
+ }
401
+ }
402
+
403
+ private static final class SettingsTarget {
404
+ final String id;
405
+ final Intent intent;
406
+ final boolean oem;
407
+
408
+ SettingsTarget(String id, Intent intent, boolean oem) {
409
+ this.id = id;
410
+ this.intent = intent;
411
+ this.oem = oem;
412
+ }
413
+ }
414
+
415
+ private static Intent component(String pkg, String cls) {
416
+ Intent intent = new Intent();
417
+ intent.setComponent(new ComponentName(pkg, cls));
418
+ return intent;
419
+ }
420
+
421
+ /**
422
+ * Ordered list of screens to try. Only the current manufacturer's OEM
423
+ * screens are included; when {@code oemOnly} is false the universal
424
+ * Android fallbacks are appended.
425
+ */
426
+ private List<SettingsTarget> buildSettingsTargets(boolean oemOnly) {
427
+ ReactApplicationContext context = getReactApplicationContext();
428
+ String appPackage = context.getPackageName();
429
+ String oemFamily = detectOemFamily();
430
+ List<SettingsTarget> targets = new ArrayList<>();
431
+
432
+ switch (oemFamily) {
433
+ case OEM_SAMSUNG:
434
+ targets.add(new SettingsTarget("samsung_never_sleeping", neverSleepingIntent(), true));
435
+ targets.add(new SettingsTarget(
436
+ "samsung_battery",
437
+ component("com.samsung.android.lool",
438
+ "com.samsung.android.sm.battery.ui.BatteryActivity"),
439
+ true));
440
+ targets.add(new SettingsTarget(
441
+ "samsung_battery_legacy",
442
+ component("com.samsung.android.lool",
443
+ "com.samsung.android.sm.ui.battery.BatteryActivity"),
444
+ true));
445
+ break;
446
+
447
+ case OEM_XIAOMI:
448
+ CharSequence label = context.getPackageManager()
449
+ .getApplicationLabel(context.getApplicationInfo());
450
+ Intent powerKeeper = component("com.miui.powerkeeper",
451
+ "com.miui.powerkeeper.ui.HiddenAppsConfigActivity");
452
+ powerKeeper.putExtra("package_name", appPackage);
453
+ powerKeeper.putExtra("package_label", label == null ? appPackage : label.toString());
454
+ targets.add(new SettingsTarget("xiaomi_battery_saver_app", powerKeeper, true));
455
+ targets.add(new SettingsTarget(
456
+ "xiaomi_autostart",
457
+ component("com.miui.securitycenter",
458
+ "com.miui.permcenter.autostart.AutoStartManagementActivity"),
459
+ true));
460
+ break;
461
+
462
+ case OEM_HUAWEI:
463
+ targets.add(new SettingsTarget(
464
+ "huawei_startup_manager",
465
+ component("com.huawei.systemmanager",
466
+ "com.huawei.systemmanager.startupmgr.ui.StartupNormalAppListActivity"),
467
+ true));
468
+ targets.add(new SettingsTarget(
469
+ "huawei_app_launch",
470
+ component("com.huawei.systemmanager",
471
+ "com.huawei.systemmanager.appcontrol.activity.StartupAppControlActivity"),
472
+ true));
473
+ targets.add(new SettingsTarget(
474
+ "huawei_protected_apps",
475
+ component("com.huawei.systemmanager",
476
+ "com.huawei.systemmanager.optimize.process.ProtectActivity"),
477
+ true));
478
+ break;
479
+
480
+ case OEM_OPPO:
481
+ case OEM_REALME:
482
+ case OEM_ONEPLUS:
483
+ // ColorOS / OxygenOS / newer Oplus builds share these screens.
484
+ // Prefer newer com.oplus.* packages, then legacy ColorOS / Oppo /
485
+ // OnePlus security packages.
486
+ targets.add(new SettingsTarget(
487
+ "oplus_startup_manager",
488
+ component("com.oplus.safecenter",
489
+ "com.oplus.safecenter.permission.startup.StartupAppListActivity"),
490
+ true));
491
+ targets.add(new SettingsTarget(
492
+ "oplus_startup_manager_alt",
493
+ component("com.oplus.safecenter",
494
+ "com.oplus.safecenter.startupapp.StartupAppListActivity"),
495
+ true));
496
+ targets.add(new SettingsTarget(
497
+ "coloros_startup_manager",
498
+ component("com.coloros.safecenter",
499
+ "com.coloros.safecenter.permission.startup.StartupAppListActivity"),
500
+ true));
501
+ targets.add(new SettingsTarget(
502
+ "coloros_startup_manager_alt",
503
+ component("com.coloros.safecenter",
504
+ "com.coloros.safecenter.startupapp.StartupAppListActivity"),
505
+ true));
506
+ targets.add(new SettingsTarget(
507
+ "oppo_startup_manager_legacy",
508
+ component("com.oppo.safe",
509
+ "com.oppo.safe.permission.startup.StartupAppListActivity"),
510
+ true));
511
+ targets.add(new SettingsTarget(
512
+ "oneplus_chain_launch",
513
+ component("com.oneplus.security",
514
+ "com.oneplus.security.chainlaunch.view.ChainLaunchAppListActivity"),
515
+ true));
516
+ targets.add(new SettingsTarget(
517
+ "oplus_battery",
518
+ component("com.oplus.battery",
519
+ "com.oplus.powermanager.fuelgaue.PowerConsumptionActivity"),
520
+ true));
521
+ targets.add(new SettingsTarget(
522
+ "coloros_battery",
523
+ component("com.coloros.oppoguardelf",
524
+ "com.coloros.powermanager.fuelgaue.PowerUsageModelActivity"),
525
+ true));
526
+ break;
527
+
528
+ case OEM_VIVO:
529
+ targets.add(new SettingsTarget(
530
+ "vivo_background_startup",
531
+ component("com.vivo.permissionmanager",
532
+ "com.vivo.permissionmanager.activity.BgStartUpManagerActivity"),
533
+ true));
534
+ targets.add(new SettingsTarget(
535
+ "vivo_whitelist",
536
+ component("com.iqoo.secure",
537
+ "com.iqoo.secure.ui.phoneoptimize.AddWhiteListActivity"),
538
+ true));
539
+ targets.add(new SettingsTarget(
540
+ "vivo_background_startup_alt",
541
+ component("com.iqoo.secure",
542
+ "com.iqoo.secure.ui.phoneoptimize.BgStartUpManager"),
543
+ true));
544
+ targets.add(new SettingsTarget(
545
+ "vivo_high_power",
546
+ component("com.vivo.abe",
547
+ "com.vivo.applicationbehaviorengine.ui.ExcessivePowerManagerActivity"),
548
+ true));
549
+ break;
550
+
551
+ case OEM_ASUS:
552
+ targets.add(new SettingsTarget(
553
+ "asus_autostart",
554
+ component("com.asus.mobilemanager",
555
+ "com.asus.mobilemanager.autostart.AutoStartActivity"),
556
+ true));
557
+ targets.add(new SettingsTarget(
558
+ "asus_power_saver",
559
+ component("com.asus.mobilemanager",
560
+ "com.asus.mobilemanager.powersaver.PowerSaverSettings"),
561
+ true));
562
+ break;
563
+
564
+ case OEM_NOKIA:
565
+ targets.add(new SettingsTarget(
566
+ "nokia_power_saver",
567
+ component("com.evenwell.powersaving.g3",
568
+ "com.evenwell.powersaving.g3.exception.PowerSaverExceptionActivity"),
569
+ true));
570
+ break;
571
+
572
+ case OEM_LETV:
573
+ targets.add(new SettingsTarget(
574
+ "letv_autoboot",
575
+ component("com.letv.android.letvsafe",
576
+ "com.letv.android.letvsafe.AutobootManageActivity"),
577
+ true));
578
+ break;
579
+
580
+ case OEM_MEIZU:
581
+ targets.add(new SettingsTarget(
582
+ "meizu_smart_bg",
583
+ component("com.meizu.safe",
584
+ "com.meizu.safe.permission.SmartBGActivity"),
585
+ true));
586
+ targets.add(new SettingsTarget(
587
+ "meizu_security",
588
+ component("com.meizu.safe",
589
+ "com.meizu.safe.security.SHOW_APPSEC"),
590
+ true));
591
+ break;
592
+
593
+ case OEM_MOTOROLA:
594
+ // Some Lenovo-era / regional Motos expose these; most Motos are
595
+ // near-stock and only the system battery list applies.
596
+ targets.add(new SettingsTarget(
597
+ "lenovo_pure_background",
598
+ component("com.lenovo.security",
599
+ "com.lenovo.security.purebackground.PureBackgroundActivity"),
600
+ true));
601
+ targets.add(new SettingsTarget(
602
+ "lenovo_safecenter",
603
+ component("com.lenovo.safecenter",
604
+ "com.lenovo.safecenter.MainTab.LeSafeMainActivity"),
605
+ true));
606
+ targets.add(new SettingsTarget(
607
+ "motorola_battery_optimization",
608
+ new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS),
609
+ true));
610
+ break;
611
+
612
+ default:
613
+ break;
614
+ }
615
+
616
+ if (!oemOnly) {
617
+ // Universal Android fallbacks (every device).
618
+ targets.add(new SettingsTarget(
619
+ "battery_optimization",
620
+ new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS),
621
+ false));
622
+ targets.add(new SettingsTarget(
623
+ "app_details",
624
+ new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
625
+ Uri.parse("package:" + appPackage)),
626
+ false));
627
+ }
628
+
629
+ return targets;
630
+ }
631
+
632
+ private SharedPreferences prefs() {
633
+ return getReactApplicationContext()
634
+ .getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
635
+ }
636
+ }