22
33import android .Manifest ;
44import android .app .Activity ;
5+ import android .app .AlertDialog ;
56import android .app .Application ;
7+ import android .content .ComponentName ;
68import android .content .Context ;
9+ import android .content .DialogInterface ;
710import android .content .Intent ;
811import android .content .SharedPreferences ;
912import android .content .pm .PackageManager ;
2124import androidx .core .app .ActivityCompat ;
2225import androidx .core .content .ContextCompat ;
2326
27+ import static android .Manifest .permission .ACTIVITY_RECOGNITION ;
2428import static androidx .core .app .ActivityCompat .requestPermissions ;
2529
2630public final class Bridge extends Application {
@@ -34,6 +38,22 @@ public final class Bridge extends Application {
3438 static final String SUMMARY_STEPS ="summarySteps" ;
3539 static final String DATE ="currentDate" ;
3640 static final String INIT_DATE ="initialDate" ;
41+ public static final Intent [] POWERMANAGER_INTENTS = new Intent []{
42+ new Intent ().setComponent (new ComponentName ("com.miui.securitycenter" , "com.miui.permcenter.autostart.AutoStartManagementActivity" )),
43+ new Intent ().setComponent (new ComponentName ("com.letv.android.letvsafe" , "com.letv.android.letvsafe.AutobootManageActivity" )),
44+ new Intent ().setComponent (new ComponentName ("com.huawei.systemmanager" , "com.huawei.systemmanager.startupmgr.ui.StartupNormalAppListActivity" )),
45+ new Intent ().setComponent (new ComponentName ("com.huawei.systemmanager" , "com.huawei.systemmanager.optimize.process.ProtectActivity" )),
46+ new Intent ().setComponent (new ComponentName ("com.huawei.systemmanager" , "com.huawei.systemmanager.appcontrol.activity.StartupAppControlActivity" )),
47+ new Intent ().setComponent (new ComponentName ("com.coloros.safecenter" , "com.coloros.safecenter.permission.startup.StartupAppListActivity" )),
48+ new Intent ().setComponent (new ComponentName ("com.coloros.safecenter" , "com.coloros.safecenter.startupapp.StartupAppListActivity" )),
49+ new Intent ().setComponent (new ComponentName ("com.oppo.safe" , "com.oppo.safe.permission.startup.StartupAppListActivity" )),
50+ new Intent ().setComponent (new ComponentName ("com.iqoo.secure" , "com.iqoo.secure.ui.phoneoptimize.AddWhiteListActivity" )),
51+ new Intent ().setComponent (new ComponentName ("com.iqoo.secure" , "com.iqoo.secure.ui.phoneoptimize.BgStartUpManager" )),
52+ new Intent ().setComponent (new ComponentName ("com.vivo.permissionmanager" , "com.vivo.permissionmanager.activity.BgStartUpManagerActivity" )),
53+ new Intent ().setComponent (new ComponentName ("com.samsung.android.lool" , "com.samsung.android.sm.ui.battery.BatteryActivity" )),
54+ new Intent ().setComponent (new ComponentName ("com.htc.pitroad" , "com.htc.pitroad.landingpage.activity.LandingPageActivity" )),
55+ new Intent ().setComponent (new ComponentName ("com.asus.mobilemanager" , "com.asus.mobilemanager.MainActivity" ))
56+ };
3757
3858 public static void ReceiveActivityInstance (Activity tempActivity ) {
3959 myActivity = tempActivity ;
@@ -49,9 +69,37 @@ public static void ReceiveActivityInstance(Activity tempActivity) {
4969 }
5070
5171 public static void StartService () {
52- myActivity .startForegroundService (new Intent (myActivity , PedometerService .class ));
72+ if (myActivity != null ) {
73+ final SharedPreferences sharedPreferences = myActivity .getSharedPreferences ("service_settings" , MODE_PRIVATE );
74+ if (!sharedPreferences .getBoolean ("auto_start" , false )) {
75+ for (final Intent intent : POWERMANAGER_INTENTS ) {
76+ if (myActivity .getPackageManager ().resolveActivity (intent , PackageManager .MATCH_DEFAULT_ONLY ) != null ) {
77+ AlertDialog alertDialog = new AlertDialog .Builder (myActivity ).create ();
78+ alertDialog .setTitle ("Auto start is required" );
79+ alertDialog .setMessage ("Please enable auto start to provide correct work" );
80+ alertDialog .setButton (AlertDialog .BUTTON_NEUTRAL , "OK" ,
81+ new DialogInterface .OnClickListener () {
82+ public void onClick (DialogInterface dialog , int which ) {
83+ sharedPreferences .edit ().putBoolean ("auto_start" , true ).apply ();
84+ myActivity .startActivity (intent );
85+ }
86+ });
87+ alertDialog .show ();
88+ break ;
89+ }
90+ }
91+ }
92+ start ();
93+ }
94+ else {
95+ start ();
96+ }
5397 }
5498
99+ private static void start (){
100+ myActivity .startForegroundService (new Intent (myActivity , PedometerService .class ));
101+
102+ }
55103 public static void StopService (){
56104 Intent serviceIntent = new Intent (myActivity , PedometerService .class );
57105 myActivity .stopService (serviceIntent );
@@ -88,6 +136,7 @@ public static String SyncData(){
88136 return data ;
89137 }
90138
139+
91140 @ Override
92141 public void onCreate () {
93142 super .onCreate ();
0 commit comments