Android Doze mode - android

Documentation says:
If a user leaves a device unplugged and stationary for a period of time, with the screen off, the device enters Doze mode. In Doze mode, the system attempts to conserve battery by restricting apps' access to network and CPU-intensive services. It also prevents apps from accessing the network and defers their jobs, syncs, and standard alarms.
What exactly stationary mean? Does phone go into Doze if it is stationary in a car that is moving? I'm developing an app that send location update to a server and if phone go into Doze mode while moving in car that can't be done.

Stationary means literally stationary, no gyro activity, screen off, not connected to charger. As far as the car is moving, the phone will not enter Doze mode.
Android developers: Optimizing for Doze and App Standby

It should be noted that Android N has extended doze mode further. Here the device doesn't need to be 'absolutely stationary' for a 'lighter' version of doze - that allows wake locks but restricts network access - to kick in.
The principal is that to truly take advantage of this, android needs to conserve battery if the phone is in a user's pocket where it is 'unused' but may not be stationary.
The original Marshmallow 'deep-doze' is still very much present in N so once the phone is stationary for a good amount of time [screen off + not being charged are already met criteria] it will go into the original doze where wifi scans and gps scans [location updates], wake locks, job schedulers, sync adapters, and network access is restricted.
To answer your question for location updates, android has a fine motion detecting sensor which ensures that the device is stationary w.r.t earth before diving into the deeper version of doze. So for this particular use case you should be good to go but you should still use the newly introduced Job scheduler api for batched updates. I am sure fetching location is one aspect, you want to upload it to your servers as well. Network access is restricted in both versions of doze modes.
references
https://plus.google.com/+AndroidDevelopers/posts/gwA68kaVJQ8
https://www.youtube.com/watch?v=VC2Hlb22mZM

In case of Android M doze mode will not get kicked in if the device is in moving car.
But in Android N, a light doze mode has been introduced that does not require the device to be completely stationary or wait as long to activate.It starts shortly after both the screen is off and the device is not charging, waiting only a couple minutes before applying the restrictions just to make sure the user has stopped using their phone.
In case,phone is Android N it may go into light doze mode.

Related

Ble beacon Android Oreo and P not waking app from doze mode

I have an app that uses Bluetooth Beacons. When app is in doze mode proximity notifications from bluetooth beacons are not waking the phone. It is only when I unlock phone that the notification is delivered. This issue is the same for foreground or app that has been killed.
Starting with Android 6.0, Doze mode blocks any bluetooth scan callbacks or other events, including beacon detections. I discussed this issue with Android Bluetooth engineers during a session at Google I/O 2015. Their position was that because sensed motion will exit Doze mode, this is not an issue, since a phone typically cannot discover new bluetooth beacons when it is motionless and therefore presumably in the same place.
While this is true for most use cases, there are a few exceptions: (1) On a train or other vehicle in a single direction on a straight path, the accelerometer won't detect motion and the phone may go into Doze despite being in motion and potentially seeing new beacons. (2) In some use cases, beacon advertisements are built to be dynamic, so they appear and disappear in the same case. In both of these situations Android devices are simply unable to detect new beacon advertisements if they are in Doze mode.
This is an unfortunate limitation you must simply design around.
EDIT: Starting with Android 7 there are two types of Doze mode, heavy and light. Light doze mode kicks in when the screen is off but the phone is not motionless. Heavy doze mode kicks in when the screen is off and the device is motionless for a period of time. In light doze mode, beacon detections are delivered normally. In heavy doze mode, they are not supposed to be according to Google. However, on some devices they do. I see them delivered in heavy doze mode on a Samsung Galaxy S8 with Android 8.0 with a foreground service running.

Does the CPU stay awake when the device is charging?

The documentation mentions that 6.0+ Android devices will not enter doze mode while charging, but what about regular sleep mode? I could not find anything that indicates that the CPU will turn off when it is plugged to a charger.
From some testing I've done it seems that the device is fine without the CPU WakeLock when running background processes, but I want to make sure; because it could be a case of another app holding a WakeLock.
Android sleeps when no wake-lock is active no matter what thread or process you have to execute even when charging and some modified os like miui and other Chinese roms have aggressive cpu sleep, so it's better use wake lock or Other alternative check for more info here [https://developer.android.com/training/scheduling/wakelock].
Doze is more aggressive about preserving your battery life by putting your phone in a low-power.
In this state apps background processes execute in batches, this might have issues executing in background.
And from version 8.0 Google restrict background tasks even more
From my testing with battery historian, CPU will not sleep if phone is charging.
Same for doze, it will not enter doze if phone is charging (I have a patch to force doze even while charging).

Android does not exit doze mode when moving with device

So some background, i am developing a location tracking application. I have a service running that gets gps updates using the fused location provider. When the app is closed or the device is locked my service is moved to the foreground. It also uses a partial wakelock and is whitelisted.
I am under the impression that a device should exit doze mode if it moves. As stated in this answer here. However i am seeing inconsistent results on different devices. I have three test devices. A sony experia, a moto e4 plus and a nexus 5x. The application works great on the sony and the nexus. I leave it idle, doze mode kicks in and then when i move the device it exits doze mode and gps updates start again. Which is great because i do not need gps updates when the device is stationary, it would just waste battery life. Just for clarity the different android version for each device are:
Sony Xperia: 7.0
Moto E4 plus: 7.1.1
Nexus 5X: 8.0
The issue is with the moto, i leave the device to enter doze mode. However upon picking it up and moving with it, it does not exit doze mode. It only exits doze mode with some user interaction. After looking through other answers and androids documentation am i correct in assuming that moving the device should always results in it existing from doze mode. If that is the case is this more likely to be a hardware issue, or can the OEM change how doze mode should work?
Thank you for any help.
So android needs to be able to detect motion in order to leave doze mode. The moto does not have a gyroscope. This stops it detecting the movement and exiting doze mode.
For having this feature working, the manufacturer should have been implemented the "Significant Motion sensor". You can check if this sensor is available by asking if this sensor exists: "android.sensor.significant_motion".
SensorManager mSensorManager = (SensorManager) mContext.getSystemService(Service.SENSOR_SERVICE);
boolean isSensorPresent = mSensorManager.getDefaultSensor(Sensor.TYPE_SIGNIFICANT_MOTION) != null;
Apart of this, there is also some manufacturers that bypass the Doze mode rules with their own power management system. It is the case for some of the phone manufactured by Huawei & Xiaomi for example.
In those cases, it is possible to stop the manufacturer power manager system to suspend your application. But it has to be done manually by the user.

Android auto sync and power saving mode

I am using Google photos to back up my all the photos. So in my Samsung galaxy J7 2016 phone, I have turned on auto sync and it is set to use only in wifi. So whenever I connected to a wifi network it automatically uploads all photos to google photos. This is the process. I know you all know that.
My question is that when the power saving mode on, does sync disabled for temporary or I have to on that again in manual after disabling power saving mode or it is automatically on after disabling the power saving?
My question is that when the power saving mode on, does sync disabled
for temporary?
Yes.
Based on the documentation:
In Doze mode, the system attempts to conserve battery by restricting
apps' access to network and CPU-intensive services. It also prevents
apps from accessing the network and defers their jobs, syncs, and
standard alarms.
For the question:
or I have to on that again in manual after disabling power saving mode
or it is automatically on after disabling the power saving?
You don't have to do anything.
As soon as the user wakes the device by moving it, turning on the screen, or connecting a charger, the system exits Doze and all apps return to normal activity.
Even when in doze mode, system has some maintenance windows, during which the pending syncs will be executed.

White listed android app in doze mode

I am trying to make a GPS tracker app.
I don't intent to distribute this app in play store. So, I got full control of the device(and can do manually whitelist).
I would like to know if:
Would doze mode be activated if charger is always connected to
phone?
Would sudden jerk or vibration to phone disables doze mode
after a prolonged inactivity? For example,consider phone placed
inside a truck and would that vibration (from engine start or
travelling) be sufficient to get the device from doze to normal
mode?
Will job scheduler service work in doze mode with scheduled
app manually whitelisted (including GPS and network)?
Would phone call to doze mode device changes its state to normal mode?
Would sensors like gyro, accelerometer work in doze mode?
Question 1:
Would doze mode be activated if charger is always connected to phone?
No.
As soon as the user wakes the device by moving it, turning on the
screen, or connecting a charger, the system exits Doze and all apps
return to normal activity.
Question 2:
Would sudden jerk or vibration to phone disables doze mode after a
prolonged inactivity? For example,consider phone placed inside a truck and would that vibration (from engine start or travelling) be sufficient to get
the device from doze to normal mode?
Prior to Android N, Yes. From Android N, no.
Android 7.0 brings further enhancements to Doze by applying a subset
of CPU and network restrictions while the device is unplugged with the
screen turned off, but not necessarily stationary, for example, when a
handset is traveling in a user’s pocket.
Question 3
Will job scheduler service work in doze mode with scheduled app
manually whitelisted (including GPS and network)?
No.
An app that is whitelisted can use the network and hold partial wake
locks during Doze and App Standby. However, other restrictions still
apply to the whitelisted app, just as they do to other apps. For
example, the whitelisted app’s jobs and syncs are deferred (on API
level 23 and below), and its regular AlarmManager alarms do not fire.
Question 4
Would phone call to doze mode device changes its state to normal mode?
Yes. Due to same reason as Question 1.
Question 5
Would sensors like gyro, accelerometer work in doze mode?
Might not work in Doze mode
For more details on Optimizations in Doze mode, you can refer this document.

Categories

Resources