mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-06 17:13:23 +02:00
Switch to polling if battery optimizations enabled on Android 12+
This commit is contained in:
@@ -34,6 +34,7 @@ import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
@@ -432,6 +433,22 @@ public class Helper {
|
||||
return pm.isIgnoringBatteryOptimizations(BuildConfig.APPLICATION_ID);
|
||||
}
|
||||
|
||||
private static Integer targetSdk = null;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
static Integer getBatteryLevel(Context context) {
|
||||
try {
|
||||
BatteryManager bm = (BatteryManager) context.getSystemService(Context.BATTERY_SERVICE);
|
||||
|
||||
Reference in New Issue
Block a user