Prevent using background service on Android O+

This commit is contained in:
M66B
2020-10-12 08:25:09 +02:00
parent f8afd831d9
commit 9b1348a634
3 changed files with 8 additions and 1 deletions

View File

@@ -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;

View File

@@ -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);

View File

@@ -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);