Check for power management settings

This commit is contained in:
M66B 2018-12-28 08:41:05 +00:00
parent abccc2a5c0
commit 1cc19e415b
1 changed files with 7 additions and 3 deletions

View File

@ -410,10 +410,14 @@ public class FragmentSetup extends FragmentEx {
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
PowerManager pm = (PowerManager) getContext().getSystemService(Context.POWER_SERVICE);
boolean ignoring = true; boolean ignoring = true;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
ignoring = pm.isIgnoringBatteryOptimizations(BuildConfig.APPLICATION_ID); 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); btnDoze.setEnabled(!ignoring);
tvDozeDone.setText(ignoring ? R.string.title_setup_done : R.string.title_setup_to_do); tvDozeDone.setText(ignoring ? R.string.title_setup_done : R.string.title_setup_to_do);
tvDozeDone.setCompoundDrawablesWithIntrinsicBounds(ignoring ? check : null, null, null, null); tvDozeDone.setCompoundDrawablesWithIntrinsicBounds(ignoring ? check : null, null, null, null);