Exit android doze mode - android

I am playing around with the Android doze mode in my app and just wants to examine my apps behavior in doze mode.
My application enqueues some tasks in a job scheduler while in doze mode. I want to check if any event, that wakes up the device, triggers the jobs that my app had put in the job scheduler while in doze.
I programmatically put the device in doze mode by firing the below commands-
adb shell dumpsys battery unplug
adb shell dumpsys deviceidle enable
adb shell dumpsys deviceidle force-idle
I also tried the other set of commands to put it in the doze mode
adb shell dumpsys deviceidle step deep
The above commands put the device in deep idle mode and I check for it with the command-
adb shell dumpsys deviceidle get deep
output: IDLE
But even if I give a phone call, which turns the device screen on and vibrates the device, the device status doesn't change. The above command continuous to give me IDLE status.
Question:
Can I emulate the scenario where I put the device in doze(by firing some commands) and then the device would move out of doze by some events that are stated by the android doc (moving it, turning on the screen, or connecting a charger).
EDIT
My observations after doing a lot of research-
When we program a device to go in the deep idle mode, the device doesn't come out of doze mode unless explicitly done using the command-
adb shell dumpsys deviceidle disable
So, even if you a send a text message or call the device which would cause
- the device screen to turn on
- the device to vibrate
but because if is programmatically set to idle mode, it continuous to remain in the same state.

I believe the problem is that you are using force-idle.
When you do that the device enters IDLE mode until you "unforce" it with:
adb shell dumpsys deviceidle unforce
You can check for alternative ways of entering IDLE mode from adb in the docs or in other question, like here:
How to shift device in Doze Mode (Android Preview M / Marshmallow)?

Related

ADB shell command to refresh android phone screen

I modified android phone hdmi output properties using ADB commands below
adb shell setprop persist.demo.rotationlock false
adb shell setprop persist.demo.singledisplay true
In order to see the change,
I will have to do either one of the following.
turn off phone screen, then turn on phone screen.
restart the phone or tv
unplug the phone to monitor, then plug the phone to monitor.
What I want:
Is there any command to do a quick reload/reset/refresh phone screen or video output connection? so I don't have to do any of the above to see the change.
Any help is appreciated
To "turn off phone screen, then turn on phone screen":
adb shell input keyevent 26
Run the above command twice.
26 is the keyevent code for power button.
To "restart phone":
adb reboot

Android force idle mode vs. really unplug the device

Currently I'm working on an app which does Bluetooth scanning in background service.
I realized that the phones behaviour is different if I force the device to sleep mode by
adb shell dumpsys battery unplug
adb shell dumpsys deviceidle force-idle
or unplug the physical cable from the device.
I can't find information about that there is a difference. But I recognised a difference already on different devices.
Is there a way to put the device in a I-physical-unplug-and-put-screen-off-mode and still be able to debug with logcat?
Thank you very much.

How can I debug multiple charger plug/unplug cycles?

I need to stop and then start (restart) my MainService when the user plugs in the phone's charger. To do this, I have a so-called GodService that registers a receiver for the ACTION_BATTERY_CHANGED intent, and then I restart MainService within that BroadcastReceiver.
I can post the code to that if necessary, but that seems to work fine, since, as soon as I start debugging I'm charging, and I can step through and see MainService get stopped and restarted.
My question is, how can I test this multiple times in a row (which I need to do), since I'll have to unplug the device, thus stopping my debugging session. I'm sure there must be a way to debug the charging port removal, but I must not be searching with the correct terms.
You can actually simulate the phone disconnect and reconnect via ADB. Here is the relevant code:
Prior to Android 6+:
Disconnect USB
$ adb shell dumpsys battery set usb 0
Re-connect USB
$ adb shell dumpsys battery set usb 1
For Android 6+:
Disconnect USB
$ adb shell dumpsys battery unplug
Re-connect USB
$ adb shell dumpsys battery reset
EDIT:
Found a nice tuturial on how to mock different battery statuses. https://stanfy.com/blog/android-shell-part-1-mocking-battery-status/

Android - create alarm with adb commands

I would like to create an alarm with adb commands, e.g. the phone should wake up in 50 seconds. I have tried shell script with sleep command but when the phone goes in sleep mode the device does not wake up in time.
Is there a way to do this?
My test procedure is as following:
enable a wake up in 50 seconds (still researching the commands)
turn off the screen (adb shell input keyevent 26)
wait 50 seconds (sleep 50)
turn on the screen and unlock the device (adb shell input keyevent 3 & adb shell swipe x1 y1 x2 y2)
Once the device is in sleep mode the sleep 50 take longer than expected. Therefore I need to know if I can enable a wake up using the alarm manager.
You might have to install busybox and use adb shell busyboxrtcwake

How to disable battery charging during ADB connection?

Problem description:
Each time wen I connect USB cable between PC and my mobile phone the battery automatically is charged. I want to use ADB protocol but I don't want to charge my battery during ADB connection. Is it possible to to turn off this charging? And ofcourse how can I do this?
Environment:
Mobile phone with Android os 4 and higher
I need only mention that my referential device working on android 5 so there is no /sys/class/power_supply/battery/force_usb_charging file
BEWARE: adb shell dumpsys battery unplug only MOCKS the battery status. I checked with a current indicator on my usb cable and this does not change the amount of flowing current at all so the battery is still charging.
It only changes what applications think about the state, so for example google play would not start updating if you have configured that it can only update when charging...
Changing the value of a file like /sys/devices/battery.XX/power_supply/battery/hv_charger_set to 0 does really work but its a different file for every device. For example, for my yotaphone 2 with a snapdragon 805 there is a file: /sys/devices/qpnp-charger-14/power_supply/battery/charging_enabled
So you could make a script that you can use in tasker(if you have root):
echo $1 > /sys/devices/qpnp-charger-14/power_supply/battery/charging_enabled
if you write that to an executable file /data/setcharging.sh then you could call the script like /data/setcharging.sh 0 to disable or
/data/setcharging.sh 1 to enable.
This works, I checked with my current metering usb cable, but it does not show that it works in the battery status icon. So you could use a combination of this and adb shell dumpsys battery unplug / reset to make it look better, but the problem is that then apps like tasker don't know whether you have ac power or not, so you can not put triggers for that when you've set it to unplugged...
One more thing, I also tested what it does in recovery (twrp) and during boot. And it turns out that during boot and in recovery, the charging just works. So its not like your device will end up dead if you forget to turn on charging again. You can always charge it in recovery mode and then boot up and change the value again (or change it while in recovery if your recovery gives access to adb).
Lastly, there are apps on the play store that are made exactly for this, but I would recommend getting such a current indicating usb-cable and checking if they really do what they say and are not just mocking.
You can make the system think it is not loading th battery using
adb shell dumpsys battery unplug
Refer to this good article :
https://stanfy.com/blog/android-shell-part-1-mocking-battery-status/
Try this for rooted device:
To enable battery Charging:
adb shell dumpsys battery set ac 1
adb shell dumpsys battery set usb 1
adb shell dumpsys battery set wireless 1
To disable battery Charging:
adb shell dumpsys battery set ac 0
adb shell dumpsys battery set usb 0
adb shell dumpsys battery set wireless 0
Probably it can be done via (root privileges):
/sys/devices/battery.XX/power_supply/battery/hv_charger_set
0 - Disable USB Charging
1 - Enable USB Charging
if android os version is more than 6 use unplug and reset to revert back.
adb shell dumpsys battery unplug
adb shell dumpsys battery reset
Copied from perfetto.dev
On rooted phones the power management IC driver allows to disconnect the USB charging while keeping the USB data link active. This feature is SoC-specific, is undocumented and not exposed through any HAL. For instance on a Pixel 2 this can be achieved running, as root: echo 1 > /sys/devices/soc/800f000.qcom,spmi/spmi-0/spmi0-02/800f000.qcom,spmi:qcom,pmi8998#2:qcom,qpnp-smb2/power_supply/battery/input_suspend. Note that in most devices the kernel USB driver holds a wakelock to keep the USB data link active, so the device will never fully suspend even when turning the screen off.

Categories

Resources