I use the following code to request ignore battery optimzation for an app. I can successfully request the permission. I am able to detect if the app is on the system's whitelist using isIgnoringBatteryOptimizations().
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
Intent intent = new Intent();
String packageName = context.getPackageName();
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
if (pm.isIgnoringBatteryOptimizations(packageName))
intent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
else
{
intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
intent.setData(Uri.parse("package:" + packageName));
}
context.startActivity(intent);
I can see a dialog, somethings like "let the app always run in background? ", and I click yes. I assumed that it will add my app to a system battery optimization whitelist.
Here is my problem. The documentation mentioned that user can manually config the list in Settings > Battery > Battery Optimization. So I expected that once I request and granted the permission, I can see it on System Settings, and I should be able to remove it manally. But I can see nothing. I don't see there is any relationship between the request and the list from System Settings.
Do they share the same list? are they equivalent if they are not the same?
That's not what happens, actually. Documentation (https://developer.android.com/training/monitoring-device-state/doze-standby#support_for_other_use_cases) says:
It's just a permission to launch a dialog. The app isn't automatically whitelisted. Any way the user has to explicitly add it to the list.
There is only one list.