[RK3288][Android6.0] Apk设置显示旋转过程小结

来源:互联网 发布:js获取一个input的值 编辑:程序博客网 时间:2024/06/07 11:22

Platform: Rockchip
OS: Android 6.0
Kernel: 3.10.92

setRequestedOrientation -> Activity.java
 ActivityManagerNative.getDefault().setRequestedOrientation //client调用AMS
 setRequestedOrientation -> ActivityManagerService.java
   mWindowManager.setAppOrientation ->
  setAppOrientation WindowManagerService.java //保存ap申请设置的dOrientation到apptoken中
 mWindowManager.updateOrientationFromAppTokens ->
 updateOrientationFromAppTokensLocked ->
  updateOrientationFromAppTokensLocked ->
  getOrientationLocked //获取上一次的Orientation,如何和mForcedAppOrientation不同,就要更新
  mPolicy.setCurrentOrientationLw //通知Policy当前Orientation变化而执行一些动作,比如enable/disable sensor监听旋转
updateRotationUncheckedLocked -> 更新当前rotation,这个函数下面再描述
  computeNewConfigurationLocked //如果updateOrientationFromAppTokensLocked返回ture,说明要旋转,更新displayinfo

updateRotationUncheckedLocked():

public boolean updateRotationUncheckedLocked(boolean inTransaction){    // TODO: Implement forced rotation changes.    //       Set mAltOrientation to indicate that the application is receiving    //       an orientation that has different metrics than it expected.    //       eg. Portrait instead of Landscape.    //将gsensor,mRotation,activity的Orientation放一起计算当前要设置的rotation    int rotation = mPolicy.rotationForOrientationLw(mForcedAppOrientation, mRotation);    //看得到的rotation和mForcedAppOrientation是否兼容,也就是说app force不代表肯定如它愿    boolean altOrientation = !mPolicy.rotationHasCompatibleMetricsLw(            mForcedAppOrientation, rotation);    //系统开了个property让用户动态修改成竖屏    /* display portrait, force android rotation according to 90 */    if("true".equals(SystemProperties.get("persist.display.portrait","false"))){         rotation = Surface.ROTATION_90;    }    /* display portrait end */    //如果和上一次一样没变化,那就不需要更新    if (mRotation == rotation && mAltOrientation == altOrientation) {        // No change.        return false;    }    //保存当前rotation以及altOrientation信息    mRotation = rotation;    mAltOrientation = altOrientation;    mPolicy.setRotationLw(mRotation);    // We need to update our screen size information to match the new rotation. If the rotation    // has actually changed then this method will return true and, according to the comment at    // the top of the method, the caller is obligated to call computeNewConfigurationLocked().    // By updating the Display info here it will be available to    // computeScreenConfigurationLocked later.    //当需要rotate之后,display里的宽高等信息也要跟着更新    updateDisplayAndOrientationLocked();    mDisplayManagerInternal.performTraversalInTransactionFromWindowManager();    return true;}

参考:
Android6.0 旋转屏幕(四)应用强制设置方向

阅读全文
1 0
原创粉丝点击