Power 키의 긴 버튼 및 짧은 버튼 처리 캡처

3287 단어
1. PhoneWindowManager.java에서 Key Event를 수신합니다.KEYCODE_POWER 이벤트(코드: mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq(KeyEvent.KEYCODE POWER)
2. 인터셉트KeyBeforeQueueing에서 KeyEvent에 대해 설명합니다.KEYCODE_POWER 이벤트 처리
            case KeyEvent.KEYCODE_POWER: {
                result &= ~ACTION_PASS_TO_USER;
                if (down) {
                    ITelephony telephonyService = getTelephonyService();
                    boolean hungUp = false;
                    if (telephonyService != null) {
                        try {
                            if (telephonyService.isRinging()) {
                                // Pressing Power while there's a ringing incoming
                                // call should silence the ringer.
                                telephonyService.silenceRinger();
                            } else if ((mIncallPowerBehavior
                                    & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
                                    && telephonyService.isOffhook()) {
                                // Otherwise, if "Power button ends call" is enabled,
                                // the Power button will hang up any current active call.
                                hungUp = telephonyService.endCall();
                            }
                        } catch (RemoteException ex) {
                            Log.w(TAG, "ITelephony threw RemoteException", ex);
                        }
                    }

                    interceptPowerKeyDown(!isScreenOn || hungUp);
					//       ,    isScreenOn true,hungUp          false
                } else {
                    if (interceptPowerKeyUp(canceled)) {
                        result = (result & ~ACTION_POKE_USER_ACTIVITY) | ACTION_GO_TO_SLEEP;
                    }
                }
                break;
            }
3.interceptPowerKeyDown 함수 코드는 다음과 같습니다.
    private void interceptPowerKeyDown(boolean handled) {
        mPowerKeyHandled = handled;
        if (!handled) {
            mHandler.postDelayed(mPowerLongPress, ViewConfiguration.getGlobalActionKeyTimeout());
        }
    }

분석에 의하면 들어오는handled는false로, 이것들은Delay 메시지를 보낼 것이다. 왜냐하면 길게 누르면 500밀리초의 대기 시간이 있기 때문이다.
    private final Runnable mPowerLongPress = new Runnable() {
        public void run() {
            if (!mPowerKeyHandled) {
                mPowerKeyHandled = true;
                performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
                sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
                showGlobalActionsDialog();
            }
        }
    };

코드sendCloseSystemWindows에서 볼 수 있듯이, 왜 길게 누르면 대화상자가 열리는지, 이 함수가 조정된 것이다
Down 이벤트가 있습니다. Up 이벤트가 있습니다. Up 이벤트 처리는interceptPowerKeyUp에서 수행합니다.
private boolean interceptPowerKeyUp(boolean canceled) {
        if (!mPowerKeyHandled) {
		    //         ,  remove     ,        
            mHandler.removeCallbacks(mPowerLongPress);
            return !canceled;
        } else {
            mPowerKeyHandled = true;
            return false;
        }
    }

좋은 웹페이지 즐겨찾기