Android long press the power key for automatic shutdown Customization

Source: Internet
Author: User

The Android system does not automatically shut down after a long hold of the power key like Nokia. You have to select the Shutdown option and then confirm the shutdown. In this way, sometimes it is inconvenient.Source codeAfter a small change, the system automatically shuts down after a long press of the power key pop-up option box is held for three seconds. The procedure is as follows:
1. Open the frameworks \ base \ Policy \ SRC \ com \ Android \ internal \ Policy \ impl \ phonewindowmanager. Java file in the android source code.

2. Create a mpowerlongpress2 thread by referring to mpowerlongpress,CodeAs follows:

 
Runnable mpowerlongpress2 = new runnable () {public void run () {mshouldturnoffonkeyup = false; performhapticfeedbacklw (null, hapticfeedbackconstants. long_press, false); sendclosesystemwindows (system_dialog_reason_global_actions); shutdownthread. shutdown (mcontext, false); // shutdown directly when the second option is flase. If the value is true, the shutdown dialog box is displayed }};

 

3. In the code

If (keycode = keyevent. keycode_endcall | keycode = keyevent. keycode_power)

Previously added

 
If (keycode = keyevent. keycode_power) if (down) {mshouldturnoffonkeyup = true; mhandler. postdelayed (mpowerlongpress2, 3000); // The mpowerlongpress2 thread is executed 3 seconds later} else {mhandler. removecallbacks (mpowerlongpress2 );}

After adding the above two pieces of code, return to the source code root directory and execute. build/envsetup. SH and then execute Mmm frameworks/base/policy or execute mm in the frameworks/base/policy directory. /mkimage. sh. Burn system. IMG to the board, enable the Board length and press the power key.

Automatically shut down after holding down for 3 seconds.

Related Article

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.