Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to WhiteList app in Doze mode Android 6.0

This question is related to the Android 6.0 Preview 3 which will be final released at the end of this month.

I'm testing some stuff in Android 6.0 in the preview 3 from Google on Nexus 5 'hammerhead'.

The new feature is the "doze mode" - something like deep sleep mode when the network is disabled and phone sleeps, only the SMS, calls or high priority GCM messages can wake it up. But like WhatsApp - in the doze mode it receives the messages after 2 hours or more depends on the timers. But there is a list of 'not optimised' apps called "white list" where u can manually add app.

Ok, I'd like to find a way to add my application programmatically without user interaction to the "white list app list" which exists in the device in battery settings.

Trying to use the reflection to get into it I found:

Within the android.os.IDeviceIdleController there is a method:

public abstract void addPowerSaveWhitelistApp (String packageNameOfApp)

But this is an interface... So we can not make an instance of interface.

There is not yet documentation about this Interface or about methods, or any inheritance tree.

Maybe you have some idea where i should look for a possibility of programmatically add there my app?

There is also a method

public abstract boolean isPowerSaveWhitelistApp (String packageName)

Which i think should be possible to access somehow?! to check if the app exist on the White List and maybe at the very end hopefully ASK user to add it to the White List.

So my question is, have anyone of you tried to make something with better result ?? cuz I'm stuck and i think its a dead end.

for more info: https://newcircle.com/s/post/1739/2015/06/12/diving-into-android-m-doze

like image 854
Fransis Q Avatar asked Sep 17 '15 09:09

Fransis Q


People also ask

How do I whitelist an Android app?

Whitelisting Apps in Device Owner mode From Android select App Management > Blacklist/Whitelist and click on Configure. Select the Whitelist button. Enable the option Blacklist all non-launchable apps to blacklist the non-launchable applications (for example, Google Play services, Android System WebView, etc.)

How do I control doze mode on Android?

Testing your app with Doze You can test Doze mode by following these steps: Configure a hardware device or virtual device with an Android 6.0 (API level 23) or higher system image. Connect the device to your development machine and install your app. Run your app and leave it active.

Does Internet work in doze mode?

Network access is disabled in doze mode, regardless if your application is ignoring battery optimizations. The only way to wake-up your device from doze mode and to get network access is by sending a high priority Google Cloud Message to your application.

How do I use doze mode?

On Android 6.0 Marshmallow: Doze mode gets activated after a while the screen is off, the device is stationary and it's running on battery. As you can see in the diagram above, when Doze Mode gets activated, the device doesn't get any wakelocks, network access, jobs/syncs, Alarms, GPS/Wi-fi scans.


1 Answers

Add permission

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

request whitelist your app

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {     Intent intent = new Intent();     String packageName = getPackageName();     PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);     if (!pm.isIgnoringBatteryOptimizations(packageName)) {         intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);         intent.setData(Uri.parse("package:" + packageName));         startActivity(intent);     } } 
like image 128
jefry jacky Avatar answered Sep 22 '22 00:09

jefry jacky