Android backend Linux keeps waking up without going to sleep

Source: Internet
Author: User

Due to the battery life of the Android phone is not plugged into the USB, so put the case into the sh file, then push to the phone, execute.

But there's a problem, if the case has a long sleep operation, turn off the phone screen so that Linux goes to sleep and pauses the execution of the code.

Continue execution from the paused state until you manually press the Power key to light the screen. This can seriously affect automated testing, so here are two ways to make your phone go into sleep mode, even if it's black screen:

The first is implemented through Java code:

1 //first define a mwakelock2PowerManager pm =(PowerManager) Getsystemservice (context.power_service);3 4Mwakelock = Pm.newwakelock (Powermanager.partial_wake_lock, This5 6 . GetClass (). GetName ());7 8  9 Ten //keep waking up, then call One  A Mwakelock.acquire (); -  -  the  -  //Resume normal sleep -  -Mwakelock.release ();

The second is relatively simple and is implemented through the ADB command:

On the ADB shell side, writing a variable to/sys/power/wake_lock will allow Linux to wake up and the black screen will not sleep.

echo AAA >/sys/power/wake_lock

Turn off always wake up, put the value of just write in/sys/power/wake_unlock can
echo AAA >/sys/power/wake_unlock

Android backend Linux keeps waking up without going to sleep

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.