软件版本:Android9
硬件平台:Mtk8175
需求:物理按键触发,底层上报静音事件,上层响应;
按键驱动层面的内容,在此不做记录分析,从驱动上报事件到系统层事件映射透传做起:
1、修改kl映射表:
diff --git a/data/keyboards/Generic.kl b/data/keyboards/Generic.kl
index 860aa9c118b..fd9773a5415 100644
--- a/data/keyboards/Generic.kl
+++ b/data/keyboards/Generic.kl
@@ -132,7 +132,7 @@ key 109 PAGE_DOWN
key 110 INSERT
key 111 FORWARD_DEL
# key 112 "KEY_MACRO"
-key 248 VOLUME_MUTE
+key 248 MUTE
key 114 VOLUME_DOWN
key 115 VOLUME_UP
key 116 POWER
248代表驱动上报的事件键值,由于内核和Framework层键值并未统一,因此在此做映射,后边的MUTE对应的是框架层的KEYCODE_MUTE键值,该按键在framework层代表mic静音。
2、Framework层改动,PhoneWindowManager对事件进行接收和派发,改动如下:
diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java
index b74ae77729b..6ae526ec0ce 100644
--- a/services/core/java/com/android/server/policy/PhoneWindowManager.java
+++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java
@@ -300,6 +300,7 @@ import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
+import java.io.BufferedReader;
import java.util.List;
/**
@@ -460,6 +461,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
private final Object mLock = new Object();
Context mContext;
+ AudioManager mAudioManager;
IWindowManager mWindowManager;
WindowManagerFuncs mWindowManagerFuncs;
WindowManagerInternal mWindowManagerInternal;
@@ -499,6 +501,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
/** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
boolean mEnableShiftMenuBugReports = false;
+ // Switch for micmute debug
+ private static boolean mMicmuteDebug = false;
+
/** Controller that supports enabling an AccessibilityService by holding down the volume keys */
private AccessibilityShortcutController mAccessibilityShortcutController;
@@ -506,6 +511,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
private final ArraySet<WindowState> mScreenDecorWindows = new ArraySet<>();
WindowState mStatusBar = null;
private final int[] mStatusBarHeightForRotation = new int[4];
+ private boolean mMicStatus = false;
WindowState mNavigationBar = null;
boolean mHasNavigationBar = false;
boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
@@ -2022,6 +2028,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class);