PhoneWindowManager.java:
在interceptKeyBeforeQueueing函数中
performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
这里把false改为true。
public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) { final boolean hapticsDisabled = Settings.System.getInt(mContext.getContentResolver(), Settings.System.HAPTIC_FEEDBACK_ENABLED, 0) == 0; if (!always && (hapticsDisabled || mKeyguardMediator.isShowingAndNotHidden())) { return false; } long[] pattern = null; switch (effectId) { case HapticFeedbackConstants.LONG_PRESS: pattern = mLongPressVibePattern; break; case HapticFeedbackConstants.VIRTUAL_KEY: pattern = mVirtualKeyVibePattern; break; case HapticFeedbackConstants.KEYBOARD_TAP: pattern = mKeyboardTapVibePattern; break; case HapticFeedbackConstants.SAFE_MODE_DISABLED: pattern = mSafeModeDisabledVibePattern; break; case HapticFeedbackConstants.SAFE_MODE_ENABLED: pattern = mSafeModeEnabledVibePattern; break; default: return false; } if (pattern.length == 1) { // One-shot vibration mVibrator.vibrate(pattern[0]); } else { // Pattern vibration mVibrator.vibrate(pattern, -1);//震动起来,OH! }
这里的震动值是从mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
com.android.internal.R.array.config_virtualKeyVibePattern);获得的。
对于震动时间是修改是在对应的xml中
frameworks/base/core/res/res/values/config.xml
<!-- Vibrator pattern for feedback about touching a virtual key -->
<integer-array name="config_virtualKeyVibePattern">
<item>0</item>
<item>10</item>
<item>20</item>
<item>30</item>
</integer-array>
这个mVibrator是Vibrator.java中的class.