一、相关文件
(1) PhoneWindowManager.java
(2) WindowManagerService.java
二、修改内容
(1)更改PhoneWindowManager.java的interceptKeyBeforeDispatching函数
if (keyCode == KeyEvent.KEYCODE_MENU) {
// Hijack modified menu keys for debugging features
final int chordBug = KeyEvent.META_SHIFT_ON;
if (down && repeatCount == 0) {
if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
mContext.sendOrderedBroadcast(intent, null);
return true;
} else if (SHOW_PROCESSES_ON_ALT_MENU &&
(metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
Intent service = new Intent();
service.setClassName(mContext, "com.android.server.LoadAverageService");
ContentResolver res = mContext.getContentResolver();
boolean shown = Settings.System.getInt(
res, Settings.System.SHOW_PROCESSES, 0) != 0;
if (!shown) {
mContext.startService(service);
} else {
mContext.stopService(service);
}
Settings.System.putInt(
res, Settings.System.SHOW_PROCESSES, shown ? 0 : 1);
return true;
}
}
//---------- 以下内容是Menu按键长按旋转功能 --------------
else if(down && repeatCount == 20 && MenuKeyUp &&(!keyguardOn)){
MenuKeyUp = false;
int ro = 0;
try{
//get the current direction
ro = mWindowManager.getRotation();
if(ro == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE){
ro = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
}else {
ro = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
}
}catch(RemoteException e){
Log.v(TAG,"---- getRotation Failed ----");
}
try{
mWindowManager.setRotation(ro,true,Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
}catch(RemoteException e){
Log.v(TAG,"--- mWindowManager.setRotation failed ---");
}
return true;
}
if(!down){
MenuKeyUp = true;
}
//--------------------------------------------------------
(2)更改WindowManagerService.java中的setRotationUncheckedLocked函数
//rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation,
//mRotation, mDisplayEnabled);
(3)如果不使用Menu键的话,而使用自定义的按键KEYCODE_REMOTE(例如使用遥控器操作)
if (code == KeyEvent.KEYCODE_ROTATE) {
// 当屏幕旋转按键按下时
if (down) {
mButtonPushFlg = true;
try {
int ro = mWindowManager.getRotation(); // Orientation vertical
if (ro == 3 ) {
mWindowManager.setRotation (Surface.ROTATION_0,true,mFancyRotationAnimation);
} else {
mWindowManager.setRotation(Surface.ROTATION_270,true,mFancyRotationAnimation);
}
} catch (RemoteException e) {
Log.i("info", "Rotation failed ");
}
return true;
}
参考文档:http://yueguc.iteye.com/blog/980501