How to Whitelist App in Doze Mode Android 6.0

Remove app from whitelist in android marshmallow

I found the solution why I didn't find disable button to remove or optimizate battery. Because such button missed in FlymeCover. The FlymeCover ignore android white-listed and use own optimization.

How to white-list system app in doze mode (Nougat)?

It's possible to disable battery optimization in AOSP for default apps in frameworks_base project, inside data/etc/platform.xml (example on AOSP and LineageOS).

You have to add entries as follow: <allow-in-power-save package="my-package-name" />

Attention: user will NOT be able do enable battery optimization in settings with this method.

Doze Mode, Battery Optimization whitelist, AlarmManager more frequent than 9 mins


What are the regular alarms ? is setExactAndAllowWhileIdle() regular ?

No. setExactAndAllowWhileIdle() is not regular. Regular alarm could be AlarmManager alarms set though setExact() and setWindow().

but below 9 minutes it goes to doze mode and do not fire AlarmManager
BroadcastReceiver

It has restrictions on how frequently you can set alarm.

Based on the documentation:

To reduce abuse, there are restrictions on how frequently these alarms
will go off for a particular application. Under normal system
operation, it will not dispatch these alarms more than about every
minute (at which point every such pending alarm is dispatched); when
in low-power idle modes this duration may be significantly longer,
such as 15 minutes.

You can refer to Doze restrictions which says:

Standard AlarmManager alarms (including setExact() and setWindow())
are deferred to the next maintenance window.

  • If you need to set alarms that fire while in Doze, use setAndAllowWhileIdle() or setExactAndAllowWhileIdle().
  • Alarms set with setAlarmClock() continue to fire normally — the system exits Doze shortly before those alarms fire

For Whitelist:

Apps available in whitelist are partially exempt from Doze and App Standby optimizations. This doesn't mean they have full access to and could perform tasks during doze mode. An app that is whitelisted can use the network and hold partial wake locks during Doze and App Standby. However, other restrictions like jobs being differed, standard alarm trigger are still imposed

Note: You should check acceptable usecases for whitelisting an app.

Google Play policies prohibit apps from requesting direct exemption
from Power Management features in Android 6.0+ (Doze and App Standby)
unless the core function of the app is adversely affected.

how to turn off doze mode for specific apps in marshmallow devices programmatically

Add below permission to manifest.xml

<uses-permission 
android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>

Call below method

public void turnOffDozeMode(Context context){  //you can use with or without passing context
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Intent intent = new Intent();
String packageName = context.getPackageName();
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
if (pm.isIgnoringBatteryOptimizations(packageName)) // if you want to desable doze mode for this package
intent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
else { // if you want to enable doze mode
intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
intent.setData(Uri.parse("package:" + packageName));
}
context.startActivity(intent);
}
}

Or you can use below scenario also...

Whitelisting an Android application programmatically can be done as follows:

boolean isIgnoringBatteryOptimizations = pm.isIgnoringBatteryOptimizations(getPackageName());
if(!isIgnoringBatteryOptimizations){
Intent intent = new Intent();
intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
intent.setData(Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, MY_IGNORE_OPTIMIZATION_REQUEST);
}

The result of starting the activity above can be verfied by the following code:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == MY_IGNORE_OPTIMIZATION_REQUEST) {
PowerManager pm = (PowerManager)getSystemService(Context.POWER_SERVICE);
boolean isIgnoringBatteryOptimizations = pm.isIgnoringBatteryOptimizations(getPackageName());
if(isIgnoringBatteryOptimizations){
// Ignoring battery optimization
}else{
// Not ignoring battery optimization
}
}
}


Related Topics



Leave a reply



Submit