ubuntu 在 R40e 上 還有 Debian 在 Sempron 2600 上

2011年7月5日 星期二

Android Power Button Dialog -- code trace

要找一下長按 Power Button 會出現的 dialog 畫面..

原來以為是
frameworks/base/policy/src/com/android/internal/policy/impl/PowerDialog.java,
結果重點是source code 的開頭....
* @deprecated use {@link GlobalActions} instead ......

所以去找 GlobalActions.java。

這個是畫出 PowerDialog 的 class。

最後是在 frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java 找到啟動的地方..
public int interceptKeyBeforeQueueing( )... ... 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); if((result & ACTION_WAKE_TO_SLEEP) !=0 && mPowerManager.getSystemState()==2) { // only try to turn off the screen if we didn't already hang up mPowerKeyHandled = false; mHandler.postDelayed(mPowerLongPress, ViewConfiguration.getGlobalActionKeyTimeout()); result &= ~ACTION_PASS_TO_USER; } } else { if (interceptPowerKeyUp(canceled)) { result = (result & ~ACTION_POKE_USER_ACTIVITY) | ACTION_GO_TO_SLEEP; } } break; }
在 PowerButton 按下 (Down)的部份..有 call private void interceptPowerKeyDown(boolean handled) { mPowerKeyHandled = handled; if (!handled) { mHandler.postDelayed(mPowerLongPress, ViewConfiguration.getGlobalActionKeyTimeout()); } } 大概就是設定一個 5 sec(getGlobalActionKeyTimeout) 後啟動的 function (mPowerLongPress)..

這個 delayed callback function : mPowerLongPress 是 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(); } } }; 的最後是 showGlobalActionsDialog( ) -- 把 GlobalActions new 出來 void showGlobalActionsDialog() { if (mGlobalActions == null) { mGlobalActions = new GlobalActions(mContext); } final boolean keyguardShowing = mKeyguardMediator.isShowingAndNotHidden(); mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned()); if (keyguardShowing) { // since it took two seconds of long press to bring this up, // poke the wake lock so they have some time to see the dialog. mKeyguardMediator.pokeWakelock(); } }


原來早就有人寫了,只是google keyword 不對,所以沒找到..

http://my.unix-center.net/~Simon_fu/?p=592

1 則留言:

Liwin 提到...

請問你會有長按power閃三下的問題出現(show出來的那個視窗)嗎?有把LOG壓在show後面,但logcat秀出的LOG也只有一次而已,視窗卻要閃三下才停止!

標籤

網誌存檔