去掉长按遥控器power键后提示关机、飞行模式的弹窗

首先找到对应长短按power键的位置:

frameworks\base\policy\src\com\android\internal\policy\impl\PhoneWindowManager.java

java 复制代码
private final Runnable mPowerLongPress = new Runnable() {
        @Override
        public void run() {
            // The context isn't read
            if (mLongPressOnPowerBehavior < 0) {
                mLongPressOnPowerBehavior = mContext.getResources().getInteger(
                        com.android.internal.R.integer.config_longPressOnPowerBehavior);
            }
            int resolvedBehavior = mLongPressOnPowerBehavior;
            if (FactoryTest.isLongPressOnPowerOffEnabled()) {
                resolvedBehavior = LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
            }
            switch (resolvedBehavior) {
            case LONG_PRESS_POWER_NOTHING:
                break;
            case LONG_PRESS_POWER_GLOBAL_ACTIONS:
                mPowerKeyHandled = true;
                //<!-- $_rbox_$_modify_$_huangjc -->
                if("true".equals(SystemProperties.get("persist.sys.realsleep"))){
                   showSleepDialog();
                } else {
                if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
                    performAuditoryFeedbackForAccessibilityIfNeed();
                }
                sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
                showGlobalActionsDialog();
                }
                break;
            case LONG_PRESS_POWER_SHUT_OFF:
            case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
                mPowerKeyHandled = true;
                performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
                sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
                mWindowManagerFuncs.shutdown(resolvedBehavior == LONG_PRESS_POWER_SHUT_OFF);
                break;
            }
        }
    };

其中case LONG_PRESS_POWER_GLOBAL_ACTIONS: 对应的是长按, 而调用的方法showGlobalActionsDialog()就是处理弹窗的方法;

java 复制代码
   void showGlobalActionsDialog() {
        if (mGlobalActions == null) {
            mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
        }
        final boolean keyguardShowing = keyguardIsShowingTq();
        mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
        if (keyguardShowing) {
            // since it took two seconds of long press to bring this up,
            // poke the wake lock so they have some time to see the dialog.
            mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
        }
    }

所以去掉showGlobalActionsDialog();就不会再有弹窗出现了;

如果要做短按power键使系统直接关机的这个功能,那么只需要在PhoneWindowManager.java中找到短按处理的代码,然后添加mWindowManagerFuncs.shutdown(true);就可以了。

相关推荐
逐光老顽童10 小时前
Java 与 Kotlin 混合开发避坑指南:30 个真实案例实录
android·kotlin
爱勇宝21 小时前
鸿蒙生态的下半场:开发者不只要能开发,还要能赚钱
android·前端·程序员
Yeyu1 天前
刷新一帧的艺术:invalidate / postInvalidate / postInvalidateOnAnimation全解析
android
潘潘潘1 天前
Android OTA 升级原理和流程介绍
android
plainGeekDev1 天前
null 判断 → Kotlin 可空类型
android·java·kotlin
plainGeekDev1 天前
getter/setter → Kotlin 属性
android·java·kotlin
YXL1111YXL1 天前
Handler 消息回收与协程异步执行的时序陷阱
android
恋猫de小郭1 天前
KMP / CMP 鸿蒙版本 Beta 发布,他有什么特别之处?
android·前端·flutter
三少爷的鞋1 天前
Android 协程并发控制:别动线程池,控制好并发语义就够了
android
weiggle2 天前
第七篇:状态提升与单向数据流——架构设计的核心
android