Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force an android phone to sleep, in order to test?

Tags:

I'm writing an android application that depends on network activity and the alarm manager sometimes waking the phone up from a sleeping state.

My question is how can I reliably test this on device? Ideally, how can I force the phone into a full-on sleeping state. Failing that, how can I know for sure when the phone has fully gone to sleep?

How do you test your Alarm Manager / Wake Lock / Sleep handling code?

like image 205
Chris Best Avatar asked Aug 05 '10 17:08

Chris Best


People also ask

How do you force an app to sleep?

Navigate to and open Settings, and then tap Battery and device care. Tap Battery, and then tap Background usage limits. The following settings will be available: Put unused apps to sleep: If you haven't used an app in a while, it will automatically be put to sleep.

Is there a sleep function on Android?

With Bedtime mode, formerly known as Wind Down in the Digital Wellbeing settings, your Android phone can stay dark and quiet while you sleep. While Bedtime mode is on, it uses Do Not Disturb to silence calls, texts and other notifications that might disturb your sleep.

How do you run a test on an Android phone?

Open the dialer app of your phone. Two codes can be used to open up the secret tools: *#0*# and *#*#4636#*#* . The first code will launch tools to run standalone tests to check the performance of various hardware of your device, such as phone's screen display, volumes/power button, cameras, and sensor.


2 Answers

Turn off the screen of the device/emulator and then run the following commands:

adb shell dumpsys battery unplug adb shell dumpsys deviceidle step 

Re-run the second one until you get the message "IDLE". This works on devices running Android 6.0 or newer.

like image 102
Force Avatar answered Nov 02 '22 17:11

Force


Step 1

a. Put the device to "discharging" in settings (follow instructions in the red boxes).

b. Turn off the device screen by pressing the "power" button (blue box).

Turn of the phone in Emulator

Step 2

a. To directly put the device to sleep mode, run:

adb shell dumpsys deviceidle force-idle

b. Or slowly step into sleep mode, run:

adb shell dumpsys deviceidle step multiple times.

Step 3

To confirm device idle status, run:

adb shell dumpsys deviceidle get deep

like image 42
user1032613 Avatar answered Nov 02 '22 18:11

user1032613