Android5.0 Long press power key off no bounce OK dialog box Direct shutdown

Source: Internet
Author: User

Android5.0 Long Press the power button to shut down the machine does not play OK dialog box directly off, but after the user clicked the Shutdown option, you should play a confirmation dialog box to the user prompts whether or not really into the shutdown mode.

First, the frameworks layer of the dialog box is opened.

Frameworks\base\policy\src\com\android\internal\policy\impl\globalactions.java

       @Override public        void Onpress () {            final Boolean quickbootenabled = Settings.System.getInt (                    Mcontext.getcontentresolver (), "Enable_quickboot", 0) = = 1;            Go to quickboot mode if enabled            if (quickbootenabled) {                startquickboot ();                return;            }            Shutdown by making sure radio and power is handled accordingly.            Mwindowmanagerfuncs.shutdown (TRUE/* confirm */);//20150423 Show the Power-off dialog        }

The source code for the processing of the displayed string is logical, so if you do not make any changes to the shutdown when the pop-up dialog box is restarted. Modify the following:

Frameworks\base\services\core\java\com\android\server\power\shutdownthread.java


static void Shutdowninner (Final context context, Boolean confirm) {//ensure-one thread is trying to POW        Er down.                Any additional calls is just returned synchronized (Sisstartedguard) {if (sisstarted) {                LOG.D (TAG, "Request to shutdown already running, returning.");            Return        }} Boolean showrebootoption = false; string[] defaultactions = Context.getresources (). Getstringarray (Com.android.internal.r.array.config_global        Actionslist);  for (int i = 0; i < defaultactions.length; i++) {if (Defaultactions[i].equals ("reboot") && Mreboot)                {//if (Defaultactions[i].equals ("reboot")) {20150421 for Power_off dialog showrebootoption = true;            Break }} final int longpressbehavior = Context.getresources (). Getinteger (Com.android.inte Rnal. R.integer.config_longpressonpowerbehaviOR); int resourceId = Mrebootsafemode? Com.android.internal.r.string.reboot_safemode_confirm: (Longpressbehavior = = 2? Co M.android.internal.r.string.shutdown_confirm_question:com.android.internal.r.string.shutdown_conf        IRM);        if (showrebootoption &&!mrebootsafemode) {resourceId = com.android.internal.r.string.reboot_confirm;        } log.d (TAG, "notifying thread to start shutdown longpressbehavior=" + longpressbehavior);            if (confirm) {final Closedialogreceiver closer = new Closedialogreceiver (context);            if (sconfirmdialog! = null) {Sconfirmdialog.dismiss ();                            } Sconfirmdialog = new Alertdialog.builder (context). Settitle (Mrebootsafemode ?                         Com.android.internal.r.string.reboot_safemode_title:showrebootoption           ?                    Com.android.internal.r.string.reboot_title:com.android.internal.r.string.power_off)                            . Setmessage (ResourceId). Setpositivebutton (Com.android.internal.r.string.yes, New Dialoginterface.onclicklistener () {public void OnClick (Dialoginterface dia                        log, int which) {beginshutdownsequence (context); }}). Setnegativebutton (com.android.internal.r.string.no, NULL).            Create ();            Closer.dialog = Sconfirmdialog;            Sconfirmdialog.setondismisslistener (Closer);            Sconfirmdialog.getwindow (). SetType (WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);        Sconfirmdialog.show ();        } else {beginshutdownsequence (context); }    }


Android5.0 Long press power key off no bounce OK dialog box Direct shutdown

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.