实体按键的问题(长按)

“Description: When a key is pressed an initial sound is emitted but there is no sound for the additional keys on the screen.”

“Solution: Play sound when pressing key for a long time.”

frameworks/base/
services/core/java/com/android/server/policy/PhoneWindowManager.java

 

diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java
index 1cb1ffd..1723b58 100644
--- a/services/core/java/com/android/server/policy/PhoneWindowManager.java
+++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java
@@ -701,6 +701,7 @@
     private static final float B = 0.28466892f;
     private static final float C = 0.55991073f;
     private static final int GAMMA_SPACE_MAX = 1023;
+    private boolean mSoundPlay = false;
     private static final int convertGammaToLinear(int val, int min, int max) {
         final float normalizedVal = MathUtils.norm(0, GAMMA_SPACE_MAX, val);
         final float ret;
@@ -2777,6 +2778,25 @@
             Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
                     + repeatCount + " keyguardOn=" + keyguardOn + " canceled=" + canceled);
         }
+        //BSPA-148629 Add sound play for long press.
+        final boolean longPressed = event.getRepeatCount() > 0;
+        if (mSoundPlay && keyCode != KeyEvent.KEYCODE_ALT_LEFT &&
+                keyCode != KeyEvent.KEYCODE_CTRL_LEFT &&
+                keyCode != KeyEvent.KEYCODE_SHIFT_LEFT ) {
+            float level = Settings.System.getFloat(mContext.getContentResolver(), Settings.System.KEYPAD_SOUND_VOLUME_LEVEL, KEYPAD_SOUND_VOLUME_LEVEL_DEFAULT);
+            int keypadSoundEnabled = Settings.System.getInt(mContext.getContentResolver(),
+                    Settings.System.KEYPAD_SOUND_ENABLED,
+                    KEYPAD_SOUND_DEFAULT);
+            if (keypadSoundEnabled != 0 && down && longPressed) {
+                try {
+                    IAudioService service = getAudioService();
+                    service.playKeypadSoundVolume(level);
+                } catch (RemoteException e) {
+                    Log.e(TAG, "Can't play keypad sound");
+                }
+            }
+        }
+        //BSPA-148629 End
 
         // If we think we might have a volume down & power key chord on the way
         // but we're not sure, then tell the dispatcher to wait a little while and
@@ -4044,7 +4064,10 @@
                     } catch (RemoteException e) {
                         Log.e(TAG, "Can't play keypad sound");
                     }
+                    mSoundPlay = true;
                 }
+            } else {
+                mSoundPlay = false;
             }
         }
 

你可能感兴趣的:(android)