Android的SAFE MODE(安全模式)
据说Android系统,按住MENU键开机,会安全模式进入系统。安全模式为何,暂未研究,现在看到了代码,先做下记号。
2.1代码位置:
frameworks/policies/base/phone/com/android/internal/policy/impl/PhoneWindowManager.java
收索SAFE MODE 这个tag会看到相关代码。
现分析如下:
步骤:在开机动画时,按住MENU键(或者字母S键,方向键的中间键,鼠标左键中的一个)直到开机,会进入安全模式。
得到log如下:
I/WindowManager( 101): SAFE MODE ENABLED (menu=1 s=-1 dpad=-1 trackball=-1)
现象:在机器左小脚显示“安全模式”。
源码
2.3版本:frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
2291 public boolean detectSafeMode() {
2292 try {
2293 int menuState = mWindowManager.getKeycodeState(KeyEvent.KEYCODE_MENU);
2294 int sState = mWindowManager.getKeycodeState(KeyEvent.KEYCODE_S);
2295 int dpadState = mWindowManager.getDPadKeycodeState(KeyEvent.KEYCODE_DPAD_CENTER);
2296 int trackballState = mWindowManager.getTrackballScancodeState(BTN_MOUSE);
2297 mSafeMode = menuState > 0 || sState > 0 || dpadState > 0 || trackballState > 0;
2298 performHapticFeedbackLw(null, mSafeMode
2299 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
2300 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
2301 if (mSafeMode) {
2302 Log.i(TAG, "SAFE MODE ENABLED (menu=" + menuState + " s=" + sState
2303 + " dpad=" + dpadState + " trackball=" + trackballState + ")");
2304 } else {
2305 Log.i(TAG, "SAFE MODE not enabled");
2306 }
2307 return mSafeMode;
2308 } catch (RemoteException e) {
2309 // Doom! (it's also local)
2310 throw new RuntimeException("window manager dead");
2311 }
2312 }
要把safe mode禁止掉,把mSafeMode赋值为false即可。