Android 12 foreground restrictions

This commit is contained in:
M66B
2021-09-23 20:06:00 +02:00
parent 0903fb77ea
commit 244b6df87e
13 changed files with 94 additions and 73 deletions

View File

@@ -433,20 +433,12 @@ public class Helper {
return pm.isIgnoringBatteryOptimizations(BuildConfig.APPLICATION_ID);
}
private static Integer targetSdk = null;
static boolean isOptimizing12(Context context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S)
return false;
static boolean isTarget(Context context, int sdk) {
if (targetSdk == null)
try {
PackageManager pm = context.getPackageManager();
ApplicationInfo ai = pm.getApplicationInfo(BuildConfig.APPLICATION_ID, 0);
targetSdk = ai.targetSdkVersion;
} catch (Throwable ex) {
Log.e(ex);
targetSdk = Build.VERSION.SDK_INT;
}
return (targetSdk >= sdk);
Boolean ignoring = Helper.isIgnoringOptimizations(context);
return (ignoring != null && !ignoring);
}
static Integer getBatteryLevel(Context context) {