From 1cc19e415b06eb93947e6f0be821e1356e0c305e Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 28 Dec 2018 08:41:05 +0000 Subject: [PATCH] Check for power management settings --- app/src/main/java/eu/faircode/email/FragmentSetup.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentSetup.java b/app/src/main/java/eu/faircode/email/FragmentSetup.java index bf14a54dd2..5759ac97ee 100644 --- a/app/src/main/java/eu/faircode/email/FragmentSetup.java +++ b/app/src/main/java/eu/faircode/email/FragmentSetup.java @@ -410,10 +410,14 @@ public class FragmentSetup extends FragmentEx { public void onResume() { super.onResume(); - PowerManager pm = (PowerManager) getContext().getSystemService(Context.POWER_SERVICE); boolean ignoring = true; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) - ignoring = pm.isIgnoringBatteryOptimizations(BuildConfig.APPLICATION_ID); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + Intent intent = new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS); + if (intent.resolveActivity(getContext().getPackageManager()) != null) { + PowerManager pm = (PowerManager) getContext().getSystemService(Context.POWER_SERVICE); + ignoring = pm.isIgnoringBatteryOptimizations(BuildConfig.APPLICATION_ID); + } + } btnDoze.setEnabled(!ignoring); tvDozeDone.setText(ignoring ? R.string.title_setup_done : R.string.title_setup_to_do); tvDozeDone.setCompoundDrawablesWithIntrinsicBounds(ignoring ? check : null, null, null, null);