Friday, March 19, 2021

[Android] When press power button to shut down the phone without asking confirmation/showing dialog to end user

 For this task, we need to make modifications in PhoneWindowManager class. When we press the power button the system call back comes inside the below method.


private void powerLongPress() {

        final int behavior = getResolvedLongPressOnPowerBehavior();

        switch (behavior) {

          

            case LONG_PRESS_POWER_SHUT_OFF:

            case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:

                mPowerKeyHandled = true;

                performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, false,

                        "Power - Long Press - Shut Off");

                sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);

                mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);

                break;

}

Please find my brief explanation about the sequence and flow of the changes.


1. When system flow goes into "LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM" switch statement case and it calls mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);

 

2. Shutdown process initiates from ShutdownThread.java file’s shutdownInner(context, confirm); function. It will display confirmation dialog with ok / cancel button, but as the system takes the “false” boolean value in shutdown method so it won't show any confirmation dialog.

 

3. beginShutdownSequence() function called when it executes "else" statement in shutdownInner() function.  Then, System will transfer control to the native API call to do further processing.

No comments:

Post a Comment