调试android记录 —— 屏幕改为竖屏【转】
原文链接:http://hi.baidu.com/jsxhxcq/blog/item/f8a5070df798a0c863d9860e.html
在调试android时,项目需要将屏幕竖屏,而且没有传感器。
按照网上的要求 在 build/target/product/core.mk 中
PRODUCT_POLICY := android.policy_phone //mid 改为phone
但是改完没有任何反应。随就追踪下去
1. 系统启动后 执行 performEnableScreen()
performEnableScreen() --> mPolicy.enableScreenAfterBoot();->
windowmanagerservice.java
public void enableScreenAfterBoot() {
synchronized(mWindowMap) {
if (mSystemBooted) {
return;
}
mSystemBooted = true;
}
2. 在其函数中调用updateRotation();
public void enableScreenAfterBoot() {
readLidState();
updateRotation(Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE);
}
void updateRotation(int animFlags) {
mPowerManager.setKeyboardVisibility(mLidOpen);
int rotation = Surface.ROTATION_0;
if (mLidOpen) {
rotation = mLidOpenRotation;
} else if (mDockState == Intent.EXTRA_DOCK_STATE_CAR && mCarDockRotation >= 0) {
rotation = mCarDockRotation;
} else if (mDockState == Intent.EXTRA_DOCK_STATE_DESK && mDeskDockRotation >= 0) {
rotation = mDeskDockRotation;
}
//if lid is closed orientation will be portrait
try {
//set orientation on WindowManager
mWindowManager.setRotation(rotation, true,
mFancyRotationAnimation | animFlags);
} catch (RemoteException e) {
// Ignore
}
}
3. setRotation()函数在 windowmanagerservices.java 中
static final boolean DEBUG_ORIENTATION = true; //打开调试信息
设置旋转函数, 下面调用关系
setRotation() - > setRotationUnchecked() - > setRotationUncheckedLocked()-> rotationForOrientationLw()
if (useSensorForOrientationLp(orientation)) {
// If the user has enabled auto rotation by default, do it.
int curRotation = mOrientationListener.getCurrentRotation();
return curRotation >= 0 ? curRotation : lastRotation;
}
return Surface.ROTATION_90; //xcq
由于没有传感器 ,系统默认没有改竖屏。 就手动改为 Surface.ROTATION_90。 重新编译OK
posted on 2011-09-07 23:20 miaoshuncai 阅读(1048) 评论(0) 收藏 举报
浙公网安备 33010602011771号