PhoneWindowManager.java
intercept :拦截的意思
- public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn) {
- if (down && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
- && event.getRepeatCount() == 0) {
- performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
- }
- public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
- Log.e("++++++++++++++++++++++", "++++++++++performHapticFeedbackLw PhoneWindowManager.java");
- 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);
- }
- return true;
- }
其实还有其他的地方会用到振动,但是他们有自己的performHapticFeedback函数。比如:
View.java (这个会在长按桌面,图标时振动)
- public boolean performHapticFeedback(int feedbackConstant, int flags) {
- if (mAttachInfo == null) {
- return false;
- }
- //noinspection SimplifiableIfStatement
- if ((flags & HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING) == 0
- && !isHapticFeedbackEnabled()) {
- return false;
- }
- return mAttachInfo.mRootCallbacks.performHapticFeedback(feedbackConstant,
- (flags & HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING) != 0);
- }
好像这个是通过Session.java调用了PhoneWindowManager.java的performHapticFeedbackLw()。