Prevent using background service on Android O+

pull/187/head
M66B 4 years ago
parent f8afd831d9
commit 9b1348a634

@ -958,6 +958,10 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
if ("alert_once".equals(key) && !Log.isXiaomi()) if ("alert_once".equals(key) && !Log.isXiaomi())
continue; continue;
if ("background_service".equals(key) &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
continue;
if (key != null && key.startsWith("widget.")) if (key != null && key.startsWith("widget."))
continue; continue;

@ -351,6 +351,9 @@ public class ApplicationEx extends Application implements SharedPreferences.OnSh
editor.putBoolean("beige", false); editor.putBoolean("beige", false);
} }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
editor.remove("background_service");
if (version < BuildConfig.VERSION_CODE) if (version < BuildConfig.VERSION_CODE)
editor.putInt("previous_version", version); editor.putInt("previous_version", version);
editor.putInt("version", BuildConfig.VERSION_CODE); editor.putInt("version", BuildConfig.VERSION_CODE);

@ -2256,7 +2256,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
private static void start(Context context, Intent intent) { private static void start(Context context, Intent intent) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean background_service = prefs.getBoolean("background_service", false); boolean background_service = prefs.getBoolean("background_service", false);
if (background_service && Build.VERSION.SDK_INT < Build.VERSION_CODES.O) if (background_service)
context.startService(intent); context.startService(intent);
else else
ContextCompat.startForegroundService(context, intent); ContextCompat.startForegroundService(context, intent);

Loading…
Cancel
Save