当前位置:   article > 正文

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

framework 长按音量

1 原理

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

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

@1 音量条不显示

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

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

  1. <!-- SystemUI Services: The classes of the stuff to start. -->
  2. <string-array name="config_systemUIServiceComponents" translatable="false">
  3. <item>com.android.systemui.util.NotificationChannels</item>
  4. <item>com.android.systemui.keyguard.KeyguardViewMediator</item>
  5. <item>com.android.systemui.recents.Recents</item>
  6. <!--<item>com.android.systemui.volume.VolumeUI</item>-->
  7. <item>com.android.systemui.stackdivider.Divider</item>
  8. <item>com.android.systemui.statusbar.phone.StatusBar</item>
  9. <item>com.android.systemui.usb.StorageNotification</item>
  10. <item>com.android.systemui.power.PowerUI</item>
  11. ...
  12. </string-array>
  13. ...

@2 电源键长按不显示

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

  1. private void powerLongPress() {
  2. final int behavior = getResolvedLongPressOnPowerBehavior();
  3. switch (behavior) {
  4. case LONG_PRESS_POWER_NOTHING:
  5. break;
  6. case LONG_PRESS_POWER_GLOBAL_ACTIONS:
  7. mPowerKeyHandled = true;
  8. performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, false,
  9. "Power - Long Press - Global Actions");
  10. // showGlobalActionsInternal();//将这句话注释掉
  11. break;
  12. case LONG_PRESS_POWER_SHUT_OFF:
  13. case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
  14. mPowerKeyHandled = true;
  15. performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, false,
  16. "Power - Long Press - Shut Off");
  17. sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
  18. mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
  19. break;
  20. case LONG_PRESS_POWER_GO_TO_VOICE_ASSIST:
  21. mPowerKeyHandled = true;
  22. performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, false,
  23. "Power - Long Press - Go To Voice Assist");
  24. // Some devices allow the voice assistant intent during setup (and use that intent
  25. // to launch something else, like Settings). So we explicitly allow that via the
  26. // config_allowStartActivityForLongPressOnPowerInSetup resource in config.xml.
  27. launchVoiceAssist(mAllowStartActivityForLongPressOnPowerDuringSetup);
  28. break;
  29. case LONG_PRESS_POWER_ASSISTANT:
  30. mPowerKeyHandled = true;
  31. performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, false,
  32. "Power - Long Press - Go To Assistant");
  33. final int powerKeyDeviceId = Integer.MIN_VALUE;
  34. launchAssistAction(null, powerKeyDeviceId);
  35. break;
  36. }
  37. }

@3 导航栏不显示

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

  1. <!-- Whether the system enables per-display focus. If the system has the input method for each
  2. display, this value should be true. -->
  3. <bool name="config_perDisplayFocusEnabled">false</bool>
  4. <!-- Whether a software navigation bar should be shown. NOTE: in the future this may be
  5. autodetected from the Configuration. -->
  6. <!这里修改config_showNavigationBar的属性为false-->
  7. <bool name="config_showNavigationBar">false</bool>
  8. <!-- Whether action menu items should be displayed in ALLCAPS or not.
  9. Defaults to true. If this is not appropriate for specific locales
  10. it should be disabled in that locale's resources. -->
  11. <bool name="config_actionMenuItemAllCaps">true</bool>

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

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/爱喝兽奶帝天荒/article/detail/875987?site
推荐阅读
相关标签
  

闽ICP备14008679号