• MTK平台导航栏按键修改-Android13


    一、背景

            MTK平台相对比较少用于台式机研发上面,由于移动终端和平板都有物理按键,所以很少有添加虚拟按键的需求,但是对于一些台式机,可能没有物理的音量键,而且大屏操作时也希望导航栏上能有快捷关机键,因此有了这样的需求。网上其他的方案均存在问题,可以参考此方案快速导入。

    二、流程

    由于13上默认导航栏不居中,因此首先修改导航栏居中显示,然后在添加按键,涉及修改的文件有

    1. .../android/server/policy/PhoneWindowManager.java | 5 +++
    2. .../android/launcher3/taskbar/TaskbarManager.java | 5 ++-
    3. .../apps/SystemUI/res/drawable-xxhdpi/ic_power.png | Bin 0 -> 2112 bytes
    4. .../SystemUI/res/drawable-xxhdpi/ic_volume.png | Bin 0 -> 1957 bytes
    5. .../SystemUI/res/drawable-xxxhdpi/ic_power.png | Bin 0 -> 2112 bytes
    6. .../SystemUI/res/drawable-xxxhdpi/ic_volume.png | Bin 0 -> 1957 bytes
    7. .../packages/apps/SystemUI/res/layout/power.xml | 28 +++++++++++++++
    8. .../packages/apps/SystemUI/res/layout/volume.xml | 27 +++++++++++++++
    9. .../apps/SystemUI/res/values-sw400dp/config.xml | 3 ++
    10. .../apps/SystemUI/res/values-sw600dp/config.xml | 2 +-
    11. .../apps/SystemUI/res/values-sw900dp/config.xml | 2 +-
    12. .../packages/apps/SystemUI/res/values/dimens.xml | 2 ++
    13. .../packages/apps/SystemUI/res/values/strings.xml | 2 ++
    14. .../shared/recents/utilities/Utilities.java | 4 +++
    15. .../systemui/navigationbar/NavigationBar.java | 38 ++++++++++++++++++++-
    16. .../navigationbar/NavigationBarInflaterView.java | 6 ++++
    17. .../systemui/navigationbar/NavigationBarView.java | 25 +++++++++++++-

    1.居中显示

    1. diff --git a/vendor/mediatek/proprietary/packages/apps/Launcher3/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java b/vendor/mediatek/proprietary/packages/apps/Launcher3/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java
    2. index 7433669..fb200e5 100644
    3. --- a/vendor/mediatek/proprietary/packages/apps/Launcher3/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java
    4. +++ b/vendor/mediatek/proprietary/packages/apps/Launcher3/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java
    5. @@ -52,6 +52,7 @@ import com.android.systemui.unfold.UnfoldTransitionProgressProvider;
    6. import com.android.systemui.unfold.util.ScopedUnfoldTransitionProgressProvider;
    7. import java.io.PrintWriter;
    8. +import android.os.SystemProperties;
    9. /**
    10. * Class to manage taskbar lifecycle
    11. @@ -262,7 +263,9 @@ public class TaskbarManager {
    12. private void recreateTaskbar() {
    13. destroyExistingTaskbar();
    14. -
    15. + if (SystemProperties.get("persist.sys.taskbar.enable","0").equals("0")){
    16. + return ;
    17. + }
    18. DeviceProfile dp =
    19. mUserUnlocked ? LauncherAppState.getIDP(mContext).getDeviceProfile(mContext) : null;
    20. diff --git a/vendor/mediatek/proprietary/packages/apps/SystemUI/shared/src/com/android/systemui/shared/recents/utilities/Utilities.java b/vendor/mediatek/proprietary/packages/apps/SystemUI/shared/src/com/android/systemui/shared/recents/utilities/Utilities.java
    21. index 56326e3..88201b4 100644
    22. --- a/vendor/mediatek/proprietary/packages/apps/SystemUI/shared/src/com/android/systemui/shared/recents/utilities/Utilities.java
    23. +++ b/vendor/mediatek/proprietary/packages/apps/SystemUI/shared/src/com/android/systemui/shared/recents/utilities/Utilities.java
    24. @@ -31,6 +31,7 @@ import android.os.Message;
    25. import android.util.DisplayMetrics;
    26. import android.view.Surface;
    27. import android.view.WindowManager;
    28. +import android.os.SystemProperties;
    29. /* Common code */
    30. public class Utilities {
    31. @@ -128,6 +129,9 @@ public class Utilities {
    32. /** @return whether or not {@param context} represents that of a large screen device or not */
    33. @TargetApi(Build.VERSION_CODES.R)
    34. public static boolean isTablet(Context context) {
    35. + if (SystemProperties.get("persist.sys.taskbar.enable","0").equals("0")){
    36. + return false;
    37. + }
    38. final WindowManager windowManager = context.getSystemService(WindowManager.class);
    39. final Rect bounds = windowManager.getCurrentWindowMetrics().getBounds();

    2.首先添加布局文件和资源文件

    布局文件:

    1. diff --git a/vendor/mediatek/proprietary/packages/apps/SystemUI/res/layout/power.xml b/vendor/mediatek/proprietary/packages/apps/SystemUI/res/layout/power.xml
    2. new file mode 100644
    3. index 0000000..bcb177c
    4. --- /dev/null
    5. +++ b/vendor/mediatek/proprietary/packages/apps/SystemUI/res/layout/power.xml
    6. @@ -0,0 +1,28 @@
    7. +"1.0" encoding="utf-8"?>
    8. +
    9. +<com.android.systemui.navigationbar.buttons.KeyButtonView
    10. + xmlns:android="http://schemas.android.com/apk/res/android"
    11. + xmlns:systemui="http://schemas.android.com/apk/res-auto"
    12. + android:id="@+id/power"
    13. + android:layout_width="@dimen/navigation_key_width"
    14. + android:layout_height="match_parent"
    15. + android:layout_weight="0"
    16. + android:scaleType="center"
    17. + android:contentDescription="@string/accessibility_power"
    18. + android:paddingStart="@dimen/navigation_key_padding"
    19. + android:paddingEnd="@dimen/navigation_key_padding"
    20. + />
    21. +
    22. diff --git a/vendor/mediatek/proprietary/packages/apps/SystemUI/res/layout/volume.xml b/vendor/mediatek/proprietary/packages/apps/SystemUI/res/layout/volume.xml
    23. new file mode 100644
    24. index 0000000..ed6c939
    25. --- /dev/null
    26. +++ b/vendor/mediatek/proprietary/packages/apps/SystemUI/res/layout/volume.xml
    27. @@ -0,0 +1,27 @@
    28. +"1.0" encoding="utf-8"?>
    29. +
    30. +<com.android.systemui.navigationbar.buttons.KeyButtonView
    31. + xmlns:android="http://schemas.android.com/apk/res/android"
    32. + xmlns:systemui="http://schemas.android.com/apk/res-auto"
    33. + android:id="@+id/volume"
    34. + android:layout_width="@dimen/navigation_key_width"
    35. + android:layout_height="match_parent"
    36. + android:layout_weight="0"
    37. + android:scaleType="center"
    38. + android:contentDescription="@string/accessibility_volume"
    39. + android:paddingStart="@dimen/navigation_key_padding"
    40. + android:paddingEnd="@dimen/navigation_key_padding"
    41. + />

    资源文件(根据自己分辨率放到指定路径就行了):

    vendor/mediatek/proprietary/packages/apps/SystemUI/res/drawable-xxhdpi/ic_power.png

    vendor/mediatek/proprietary/packages/apps/SystemUI/res/drawable-xxhdpi/ic_volume.png

    3.修改导航栏的布局

    1. diff --git a/vendor/mediatek/proprietary/packages/apps/SystemUI/res/values-sw400dp/config.xml b/vendor/mediatek/proprietary/packages/apps/SystemUI/res/values-sw400dp/config.xml
    2. new file mode 100644
    3. index 0000000..0cc515c
    4. --- /dev/null
    5. +++ b/vendor/mediatek/proprietary/packages/apps/SystemUI/res/values-sw400dp/config.xml
    6. @@ -0,0 +1,3 @@
    7. +<resources>
    8. + <string name="config_navBarLayout" translatable="false">left;poweroff,back,home,recent,volume;rightstring>
    9. +resources>
    10. diff --git a/vendor/mediatek/proprietary/packages/apps/SystemUI/res/values-sw600dp/config.xml b/vendor/mediatek/proprietary/packages/apps/SystemUI/res/values-sw600dp/config.xml
    11. index 36cc0ad..ba3a959 100644
    12. --- a/vendor/mediatek/proprietary/packages/apps/SystemUI/res/values-sw600dp/config.xml
    13. +++ b/vendor/mediatek/proprietary/packages/apps/SystemUI/res/values-sw600dp/config.xml
    14. @@ -27,7 +27,7 @@
    15. <bool name="config_quickSettingsMediaLandscapeCollapsed">falsebool>
    16. - <string name="config_navBarLayout" translatable="false">left;back,home,recent;rightstring>
    17. + <string name="config_navBarLayout" translatable="false">left;power,back,home,recent,volume;rightstring>
    18. <integer name="navigation_bar_deadzone_orientation">0integer>
    19. diff --git a/vendor/mediatek/proprietary/packages/apps/SystemUI/res/values-sw900dp/config.xml b/vendor/mediatek/proprietary/packages/apps/SystemUI/res/values-sw900dp/config.xml
    20. index 221b013..99f2d56 100644
    21. --- a/vendor/mediatek/proprietary/packages/apps/SystemUI/res/values-sw900dp/config.xml
    22. +++ b/vendor/mediatek/proprietary/packages/apps/SystemUI/res/values-sw900dp/config.xml
    23. @@ -19,6 +19,6 @@
    24. <resources>
    25. - <string name="config_navBarLayout" translatable="false">back,home,left;space;right,recentstring>
    26. + <string name="config_navBarLayout" translatable="false">power,back,home,left;space;right,recent,volumestring>
    27. resources>
    28. diff --git a/vendor/mediatek/proprietary/packages/apps/SystemUI/res/values/dimens.xml b/vendor/mediatek/proprietary/packages/apps/SystemUI/res/values/dimens.xml
    29. index b6a2815..3b09c06 100644
    30. --- a/vendor/mediatek/proprietary/packages/apps/SystemUI/res/values/dimens.xml
    31. +++ b/vendor/mediatek/proprietary/packages/apps/SystemUI/res/values/dimens.xml
    32. @@ -49,6 +49,8 @@
    33. <dimen name="navigation_edge_arrow_min_y">64dpdimen>
    34. <dimen name="navigation_edge_finger_offset">48dpdimen>
    35. + <dimen name="navigation_key_width_sw600dp_land">162dpdimen>
    36. + <dimen name="navigation_key_padding_sw600dp_land">42dpdimen>
    37. <dimen name="status_bar_icon_size">@*android:dimen/status_bar_icon_sizedimen>

    4.定义对应的字符串

    1. diff --git a/vendor/mediatek/proprietary/packages/apps/SystemUI/res/values/strings.xml b/vendor/mediatek/proprietary/packages/apps/SystemUI/res/values/strings.xml
    2. index e4607b3..b6c2866 100644
    3. --- a/vendor/mediatek/proprietary/packages/apps/SystemUI/res/values/strings.xml
    4. +++ b/vendor/mediatek/proprietary/packages/apps/SystemUI/res/values/strings.xml
    5. @@ -2545,4 +2545,6 @@
    6. =1 {# notification}
    7. other {# notifications}
    8. }string>
    9. + <string name="accessibility_power">Powerstring>
    10. + <string name="accessibility_volume">Volumestring>
    11. resources>

    5.源码中添加按键布局,增加按键分发,修改触摸区域

    1. diff --git a/vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/navigationbar/NavigationBarInflaterView.java b/vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/navigationbar/NavigationBarInflaterView.java
    2. index 59bb227..ed9e3fc 100644
    3. --- a/vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/navigationbar/NavigationBarInflaterView.java
    4. +++ b/vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/navigationbar/NavigationBarInflaterView.java
    5. @@ -68,6 +68,8 @@ public class NavigationBarInflaterView extends FrameLayout
    6. public static final String RIGHT = "right";
    7. public static final String CONTEXTUAL = "contextual";
    8. public static final String IME_SWITCHER = "ime_switcher";
    9. + public static final String POWER = "power";
    10. + public static final String VOLUME = "volume";
    11. public static final String GRAVITY_SEPARATOR = ";";
    12. public static final String BUTTON_SEPARATOR = ",";
    13. @@ -387,6 +389,10 @@ public class NavigationBarInflaterView extends FrameLayout
    14. v = inflater.inflate(R.layout.home_handle, parent, false);
    15. } else if (IME_SWITCHER.equals(button)) {
    16. v = inflater.inflate(R.layout.ime_switcher, parent, false);
    17. + } else if(POWER.equals(button)) {
    18. + v = inflater.inflate(R.layout.power, parent, false);
    19. + } else if(VOLUME.equals(button)) {
    20. + v = inflater.inflate(R.layout.volume, parent, false);
    21. } else if (button.startsWith(KEY)) {
    22. String uri = extractImage(button);
    23. int code = extractKeycode(button);
    24. diff --git a/vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/navigationbar/NavigationBarView.java b/vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/navigationbar/NavigationBarView.java
    25. index 3fc9afe..11d9e7f 100644
    26. --- a/vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/navigationbar/NavigationBarView.java
    27. +++ b/vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/navigationbar/NavigationBarView.java
    28. @@ -92,7 +92,7 @@ import java.util.function.Consumer;
    29. /** */
    30. public class NavigationBarView extends FrameLayout {
    31. - final static boolean DEBUG = false;
    32. + final static boolean DEBUG = true;
    33. final static String TAG = "NavBarView";
    34. final static boolean ALTERNATE_CAR_MODE_UI = false;
    35. @@ -119,6 +119,9 @@ public class NavigationBarView extends FrameLayout {
    36. private Context mLightContext;
    37. private int mLightIconColor;
    38. private int mDarkIconColor;
    39. + private KeyButtonDrawable mPowerIcon;
    40. + private KeyButtonDrawable mVolumeIcon;
    41. +
    42. private EdgeBackGestureHandler mEdgeBackGestureHandler;
    43. private final DeadZone mDeadZone;
    44. @@ -316,6 +319,8 @@ public class NavigationBarView extends FrameLayout {
    45. mButtonDispatchers.put(R.id.ime_switcher, imeSwitcherButton);
    46. mButtonDispatchers.put(R.id.accessibility_button, accessibilityButton);
    47. mButtonDispatchers.put(R.id.menu_container, mContextualButtonGroup);
    48. + mButtonDispatchers.put(R.id.power, new ButtonDispatcher(R.id.power));
    49. + mButtonDispatchers.put(R.id.volume, new ButtonDispatcher(R.id.volume));
    50. mDeadZone = new DeadZone(this);
    51. }
    52. @@ -412,6 +417,14 @@ public class NavigationBarView extends FrameLayout {
    53. return mButtonDispatchers.get(R.id.accessibility_button);
    54. }
    55. + public ButtonDispatcher getPowerButton() {
    56. + return mButtonDispatchers.get(R.id.power);
    57. + }
    58. +
    59. + public ButtonDispatcher getVolumeButton() {
    60. + return mButtonDispatchers.get(R.id.volume);
    61. + }
    62. +
    63. public RotationContextButton getRotateSuggestionButton() {
    64. return (RotationContextButton) mButtonDispatchers.get(R.id.rotate_suggestion);
    65. }
    66. @@ -456,6 +469,8 @@ public class NavigationBarView extends FrameLayout {
    67. if (orientationChange || densityChange || dirChange) {
    68. mBackIcon = getBackDrawable();
    69. }
    70. + mPowerIcon = getDrawable(R.drawable.ic_power);
    71. + mVolumeIcon = getDrawable(R.drawable.ic_volume);
    72. }
    73. /**
    74. @@ -594,11 +609,15 @@ public class NavigationBarView extends FrameLayout {
    75. KeyButtonDrawable backIcon = mBackIcon;
    76. orientBackButton(backIcon);
    77. KeyButtonDrawable homeIcon = mHomeDefaultIcon;
    78. + KeyButtonDrawable powerIcon = mPowerIcon;
    79. + KeyButtonDrawable volumeIcon = mVolumeIcon;
    80. if (!mUseCarModeUi) {
    81. orientHomeButton(homeIcon);
    82. }
    83. getHomeButton().setImageDrawable(homeIcon);
    84. getBackButton().setImageDrawable(backIcon);
    85. + getPowerButton().setImageDrawable(powerIcon);
    86. + getVolumeButton().setImageDrawable(volumeIcon);
    87. updateRecentsIcon();
    88. @@ -652,6 +671,8 @@ public class NavigationBarView extends FrameLayout {
    89. getHomeButton().setVisibility(disableHome ? View.INVISIBLE : View.VISIBLE);
    90. getRecentsButton().setVisibility(disableRecent ? View.INVISIBLE : View.VISIBLE);
    91. getHomeHandle().setVisibility(disableHomeHandle ? View.INVISIBLE : View.VISIBLE);
    92. + getPowerButton().setVisibility(false ? View.INVISIBLE : View.VISIBLE);
    93. + getVolumeButton().setVisibility(false ? View.INVISIBLE : View.VISIBLE);
    94. notifyActiveTouchRegions();
    95. }
    96. @@ -1122,6 +1143,8 @@ public class NavigationBarView extends FrameLayout {
    97. dumpButton(pw, "back", getBackButton());
    98. dumpButton(pw, "home", getHomeButton());
    99. + dumpButton(pw, "volume", getVolumeButton());
    100. + dumpButton(pw, "power", getPowerButton());
    101. dumpButton(pw, "handle", getHomeHandle());
    102. dumpButton(pw, "rcnt", getRecentsButton());
    103. dumpButton(pw, "rota", getRotateSuggestionButton());
    104. diff --git a/vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/navigationbar/NavigationBar.java b/vendor/mediatek/proprietary/packages/apps/Syst
    105. emUI/src/com/android/systemui/navigationbar/NavigationBar.java
    106. index 91b01ef..9634cb0 100644
    107. --- a/vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/navigationbar/NavigationBar.java
    108. +++ b/vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/navigationbar/NavigationBar.java
    109. @@ -1787,11 +1787,15 @@ public class NavigationBar extends ViewController implements
    110. Region region = new Region();
    111. Map touchRegionCache = mView.getButtonTouchRegionCache();
    112. updateButtonLocation(
    113. + region, touchRegionCache, mView.getPowerButton(), inScreenSpace, useNearestRegion);
    114. + updateButtonLocation(
    115. region, touchRegionCache, mView.getBackButton(), inScreenSpace, useNearestRegion);
    116. updateButtonLocation(
    117. region, touchRegionCache, mView.getHomeButton(), inScreenSpace, useNearestRegion);
    118. updateButtonLocation(region, touchRegionCache, mView.getRecentsButton(), inScreenSpace,
    119. useNearestRegion);
    120. + updateButtonLocation(
    121. + region, touchRegionCache, mView.getVolumeButton(), inScreenSpace, useNearestRegion);
    122. updateButtonLocation(region, touchRegionCache, mView.getImeSwitchButton(), inScreenSpace,
    123. useNearestRegion);
    124. updateButtonLocation(

    6.按键发送广播或调用相关服务

    注:打叉的地方修改成自己喜欢的名字即可

    1. diff --git a/vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/navigationbar/NavigationBar.java b/vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/navigationbar/NavigationBar.java
    2. index aa38b78..91b01ef 100644
    3. --- a/vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/navigationbar/NavigationBar.java
    4. +++ b/vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/navigationbar/NavigationBar.java
    5. @@ -158,6 +158,7 @@ import com.android.systemui.util.DeviceConfigProxy;
    6. import com.android.systemui.util.ViewController;
    7. import com.android.wm.shell.back.BackAnimation;
    8. import com.android.wm.shell.pip.Pip;
    9. +import android.media.AudioManager;
    10. import java.io.PrintWriter;
    11. import java.util.Locale;
    12. @@ -177,7 +178,7 @@ import dagger.Lazy;
    13. public class NavigationBar extends ViewController implements Callbacks {
    14. public static final String TAG = "NavigationBar";
    15. - private static final boolean DEBUG = false;
    16. + private static final boolean DEBUG = true;
    17. private static final String EXTRA_DISABLE_STATE = "disabled_state";
    18. private static final String EXTRA_DISABLE2_STATE = "disabled2_state";
    19. private static final String EXTRA_APPEARANCE = "appearance";
    20. @@ -1260,6 +1261,13 @@ public class NavigationBar extends ViewController implements
    21. accessibilityButton.setOnLongClickListener(this::onAccessibilityLongClick);
    22. updateAccessibilityStateFlags();
    23. + ButtonDispatcher powerButton = mView.getPowerButton();
    24. + powerButton.setOnClickListener(this::powerClick);
    25. + powerButton.setOnTouchListener(this::powerTouch);
    26. +
    27. + ButtonDispatcher volumeButton = mView.getVolumeButton();
    28. + volumeButton.setOnClickListener(this::volumeClick);
    29. +
    30. ButtonDispatcher imeSwitcherButton = mView.getImeSwitchButton();
    31. imeSwitcherButton.setOnClickListener(this::onImeSwitcherClick);
    32. @@ -1450,6 +1458,30 @@ public class NavigationBar extends ViewController implements
    33. return false;
    34. }
    35. + private boolean powerTouch(View v, MotionEvent event) {
    36. + if (event.getAction() == MotionEvent.ACTION_UP) {
    37. + Log.i("xxxxx","powerTouch--sendBroadcast");
    38. + Intent intent=new Intent("com.xxxxx.systemui.power");
    39. + mContext.sendBroadcast(intent);
    40. + }
    41. + return false;
    42. + }
    43. +
    44. + private void powerClick(View v) {
    45. + Log.i("xxxx","powerClick--sendBroadcast");
    46. + Intent intent=new Intent("com.xxxxx.systemui.power");
    47. + mContext.sendBroadcast(intent);
    48. + }
    49. +
    50. + private void volumeClick(View v) {
    51. + Log.i("xxxxx","volumeClick--sendBroadcast");
    52. + AudioManager am = getContext().getSystemService(AudioManager.class);
    53. + am.adjustSuggestedStreamVolume(
    54. + AudioManager.ADJUST_SAME,
    55. + AudioManager.STREAM_MUSIC,
    56. + AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND);
    57. + }
    58. +
    59. private void onAccessibilityClick(View v) {
    60. final Display display = v.getDisplay();
    61. mAccessibilityManager.notifyAccessibilityButtonClicked(

    7.监听广播调出响应弹窗

    注:打叉的地方修改成自己喜欢的名字即可

    1. diff --git a/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java b/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
    2. index 0b61a84..a3d9745 100644
    3. --- a/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
    4. +++ b/frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java
    5. @@ -2071,6 +2071,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    6. filter = new IntentFilter();
    7. filter.addAction(Intent.ACTION_DREAMING_STARTED);
    8. filter.addAction(Intent.ACTION_DREAMING_STOPPED);
    9. + filter.addAction("com.xxxx.systemui.power");
    10. context.registerReceiver(mDreamReceiver, filter);
    11. // register for multiuser-relevant broadcasts
    12. @@ -4449,6 +4450,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    13. BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
    14. @Override
    15. public void onReceive(Context context, Intent intent) {
    16. + Log.i("xxxx", "mDreamReceiver--onReceive");
    17. if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
    18. if (mKeyguardDelegate != null) {
    19. mKeyguardDelegate.onDreamingStarted();
    20. @@ -4457,6 +4459,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    21. if (mKeyguardDelegate != null) {
    22. mKeyguardDelegate.onDreamingStopped();
    23. }
    24. + } else if("com.xxxx.systemui.power".equals(intent.getAction())) {
    25. + Log.i("xxxxx", "Receive a soft poweroff broadcast.");
    26. + showGlobalActionsInternal();
    27. }
    28. }
    29. };

    三、验证

    以上修改完成后,整体编译然后烧录即可实现虚拟按键添加及事件响应

  • 相关阅读:
    某讯D-Link AC集中管理平台未授权访问漏洞复现 CNVD-2023-19479
    计算机毕业设计 基于HTML语言的环保网站的设计与实现 Java实战项目 附源码+文档+视频讲解
    Python计算二项分布教程
    LocalViT 论文解读
    【限时免费】20天拿下华为OD笔试之【不定滑窗】2023Q1A-完美走位【欧弟算法】全网注释最详细分类最全的华为OD真题题解
    WebSocket——相关介绍以及后端配置
    PostgreSQL文本搜索(七)——自定义配置
    Nginx概念
    JavaScript基础语法(数据类型)
    Flutter高仿微信-第29篇-单聊
  • 原文地址:https://blog.csdn.net/u014645605/article/details/134017847