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.
Related
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.
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.
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
Is there any way to "Power on" the device in case some alarm happens ?. This was available in old Nokia phones when you set an alarm , if the device is OFF , the devices goes on at the alarm time, then goes OFF again. Can we have this in Android ? . I'm not talking about waking up the device while sleeping, I need to power it on if he is OFF and have battery power.
Thanks alot
This isn't possible with android because once your device is shut down, the OS isn't running until the device is manually switched on.
However, with root access you can schedule a system shutdown with an alarm but you'll need a rooted device which can void your warranty.
I cannot get some Android devices to wake up using the AlarmManager. Following the advice in other StackOverflow posts, I am testing CommonsWares cwac-wakeful demo unmodified, compiled in Eclipse, and sent directly to my tablet devices.
When the screen is on the app wakes every 15 minutes and dutifully writes a log message, if I switch the screen off (short press on the power button) and remove the USB cable, then reconnect say 30 minutes later, there are no log messages for the period during which the device was asleep. The alarm does trigger immediately after I wake the device up (according to the log message timestamp). If I leave the USB cable connected the alarm does trigger even with the screen off, presumably because the device is in "debug" mode.
I have seen this behaviour on an older Android 2.2 tablet and I think it might be a bug in the hardware or OS common to both devices. However, I would like to rule out a bug in the cwac-wakeful utility and "operator error" if possible.
Has anyone else seen this behaviour and have any suggestions about further diagnostics or remedies?
I actually get the same behaviour when I set the built-in clock alarm from the home page, i.e. the A90 and the VEGAn-TAB don't wake up until the next manual power on. Therefore it must be a fundamental problem with the tablets rather than a bug in AlarmManager or WakefulIntentService.