Android Framework 常见解决方案(19)音量/电源按键默认事件响应方案

1 原理

点击电源键、音量+、音量- 按键时不再在UI界面上弹出滚动条,长按电源键时不要弹出系统弹窗,而是让这些响应直接在自定的Launcher中处理(该部分不作介绍),处理的核心原则就是 按键触发时不再响应对应的处理流程 或者 处理流程被修改,而这些多数在framework的配置文件中修改达到效果,部分需要对android framework部分源码进行修改以达到效果。

2 各种音量/电源键UI响应剔除方案

@1 音量条不显示

注释掉<item>com.android.systemui.volume.VolumeUI 即可。

修改文件为frameworks/base/packages/SystemUI/res/values/config.xml。修改内容为:

<!-- SystemUI Services: The classes of the stuff to start. -->
    <string-array name="config_systemUIServiceComponents" translatable="false">
        <item>com.android.systemui.util.NotificationChannels</item>
        <item>com.android.systemui.keyguard.KeyguardViewMediator</item>
        <item>com.android.systemui.recents.Recents</item>
        <!--<item>com.android.systemui.volume.VolumeUI</item>-->
        <item>com.android.systemui.stackdivider.Divider</item>
        <item>com.android.systemui.statusbar.phone.StatusBar</item>
        <item>com.android.systemui.usb.StorageNotification</item>
        <item>com.android.systemui.power.PowerUI</item>
        ...
    </string-array>
...

@2 电源键长按不显示

长按电源键不触发系统弹窗。修改文件为:aosp/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java;修改内容为:

private void powerLongPress() {
        final int behavior = getResolvedLongPressOnPowerBehavior();
        switch (behavior) {
            case LONG_PRESS_POWER_NOTHING:
                break;
            case LONG_PRESS_POWER_GLOBAL_ACTIONS:
                mPowerKeyHandled = true;
                performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, false,
                        "Power - Long Press - Global Actions");
               // showGlobalActionsInternal();//将这句话注释掉
                break;
            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;
            case LONG_PRESS_POWER_GO_TO_VOICE_ASSIST:
                mPowerKeyHandled = true;
                performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, 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.LONG_PRESS, false,
                        "Power - Long Press - Go To Assistant");
                final int powerKeyDeviceId = Integer.MIN_VALUE;
                launchAssistAction(null, powerKeyDeviceId);
                break;
        }
    }

@3 导航栏不显示

去掉最近的应用一个图标,修改文件为:frameworks/base/core/res/res/values/config.xml,修改内容为:

    <!-- Whether the system enables per-display focus. If the system has the input method for each
         display, this value should be true. -->
    <bool name="config_perDisplayFocusEnabled">false</bool>

    <!-- Whether a software navigation bar should be shown. NOTE: in the future this may be
         autodetected from the Configuration. -->
    <!这里修改config_showNavigationBar的属性为false-->
    <bool name="config_showNavigationBar">false</bool>

    <!-- Whether action menu items should be displayed in ALLCAPS or not.
         Defaults to true. If this is not appropriate for specific locales
         it should be disabled in that locale's resources. -->
    <bool name="config_actionMenuItemAllCaps">true</bool>

同时这里将navigation_bar_height高度设置为0,这样导航栏因高度原因无法显示出来。修改文件为:aosp/frameworks/base/core/res/res/values/dimens.xml,修改内容为:

   <!-- Total height of QQS (quick_qs_offset_height + 128) -->
    <dimen name="quick_qs_total_height">176dp</dimen>
    <!-- Total height of QQS with two rows to fit media player (quick_qs_offset_height + 176) -->
    <dimen name="quick_qs_total_height_with_media">224dp</dimen>
    <!-- Height of the bottom navigation / system bar. -->
    <!--<dimen name="navigation_bar_height">48dp</dimen> -->
    <dimen name="navigation_bar_height">0dp</dimen>
    <!-- Height of the bottom navigation bar in portrait; often the same as @dimen/navigation_bar_height -->
    <dimen name="navigation_bar_height_landscape">48dp</dimen>
    <!-- Width of the navigation bar when it is placed vertically on the screen -->
    <dimen name="navigation_bar_width">48dp</dimen>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

图王大胜

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值