T820 Dev 03 Power Long Press

发布于 2024-03-28  61 次阅读


  在frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManger.java中定义了如下长按事件:

  1. LONG_PRESS_POWER_ASSISTANT: 唤醒助手界面
  2. LONG_PRESS_POWER_GO_TO_VOICE_ASSIST: 唤醒语音助手
  3. LONG_PRESS_POWER_GLOBAL_ACTIONS: 弹出关机、重启等选项对话框
  4. LONG_PRESS_POWER_SHUT_OFF: 关闭所有窗口并关机

我们开机后连上adb,长按并读取调试信息:发现它默认的输出总是LONG_PRESS_POWER_ASSISTANT。我们选择将其注释,并移动到case LONG_PRESS_POWER_GLOBAL_ACTIONS:下,以实现长按弹出关机选项。如果想要实现直接关机,则可以移动到LONG_PRESS_POWER_SHUT_OFF的位置。

switch (behavior) {
    case LONG_PRESS_POWER_NOTHING:
        break;
    case LONG_PRESS_POWER_GLOBAL_ACTIONS:
    case LONG_PRESS_POWER_ASSISTANT:
        mPowerKeyHandled = true;
        performHapticFeedback(HapticFeedbackConstants.LONG_PRESS_POWER_BUTTON, false,
                "Power - Long Press - Global Actions");
        showGlobalActions();
        break;
    case LONG_PRESS_POWER_SHUT_OFF:
    case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
        mPowerKeyHandled = true;
        performHapticFeedback(HapticFeedbackConstants.LONG_PRESS_POWER_BUTTON, false,
                "Power - Long Press - Shut Off");
        sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
        mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
        break;
    case LONG_PRESS_POWER_GO_TO_VOICE_ASSIST:
        mPowerKeyHandled = true;
        performHapticFeedback(HapticFeedbackConstants.LONG_PRESS_POWER_BUTTON, false,
                "Power - Long Press - Go To Voice Assist");
        // Some devices allow the voice assistant intent during setup (and use that intent
        // to launch something else, like Settings). So we explicitly allow that via the
        // config_allowStartActivityForLongPressOnPowerInSetup resource in config.xml.
        launchVoiceAssist(mAllowStartActivityForLongPressOnPowerDuringSetup);
        break;
    // case LONG_PRESS_POWER_ASSISTANT:
    //     mPowerKeyHandled = true;
    //     performHapticFeedback(HapticFeedbackConstants.ASSISTANT_BUTTON, false,
    //             "Power - Long Press - Go To Assistant");
    //     final int powerKeyDeviceId = Integer.MIN_VALUE;
    //     launchAssistAction(null, powerKeyDeviceId, eventTime,
    //             AssistUtils.INVOCATION_TYPE_POWER_BUTTON_LONG_PRESS);
    //     break;
}