Android does not exit doze mode when moving with device - android

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.

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.

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.

How to disable power saving mode programmatically in android

I'm creating an app that took coordinates every minutes and send to the server using service, but when app is in background and mobile is in idle mode it kill my service but when the phone is not in the power saving mode it doesn't kill my service, because of this scenario i have to disable the power saving mode...
Unfortunately you can not do such thing. And after Marshmallow android introduce Doze behavior for battery optimization which was the biggest halt seems in android for user check this out here.
Please read the above link first before approaching further.
And for more information the power saver mode behavior varies device to device. I myself tested in Samsung Grand and lenovo Vibe devices . Some of Devices will not allow services in background and any network access to the application.
You can find work around for the problem in android documentation in above link

Android Doze mode

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.

Broadcast Receiver for Ultra Power Saving Mode

Is it possible to have a broadcast receiver when user turns off Ultra Power Saving Mode (Samsung) or Ultra Stamina Mode (Sony) and so with Ultra modes implemented by different device vendors?
I have a alarm manager running which triggers my IntentService after a certain interval, when I turn on Ultra mode on either Sony or Samsung, alarm manager is not available, but when I turn off the ultra mode, I want the action broadcasted so that I can receive it and start my alarm manager as normally we do on Boot_Completed.
I found some info online, such as POWER_SAVE_MODE but it also stated it was only available in lollipop.
Appreciate the help.
Thanks
First of all this way only tested on Samsung device with Android 4.4 API 19.
All you have to do is just treating turning off the ultra power saving mode as BOOT_COMPLETED action.
Which means simply you have to make your activity or service (whatever initiating the AlarmManager) start with system boot up so that it start after turning off the ultra power saving mode.
Ultra Power Saving Mode is not enabled or available in the stock android or does not have any documentations whereas sony tries to kill some apps or some sensors to keep the battery for more time.

Categories

Resources