概述
Platform: Rockchip
OS: Android 6.0
Kernel: 3.10.92
Settings -> Display有个选项控制旋转屏幕时内容是否跟着旋转
这个功能是通过获取gsensor的方向来改变内容进行旋转的,选项对应的string在
packages/apps/Settings/res/values/strings.xml:6408: <string name="display_auto_rotate_title">When device is rotated</string>
对应的key在Display_settings.xml
<com.android.settings.DropDownPreference
android:key="auto_rotate"
android:title="@string/display_auto_rotate_title" />
android:key=”auto_rotate”的使用:
DisplaySettings.java
private static final String KEY_AUTO_ROTATE = "auto_rotate";
DropDownPreference rotatePreference = (DropDownPreference) findPreference(KEY_AUTO_ROTATE);
rotatePreference.setCallback(new Callback()
{
@Override
public boolean onItemSelected(int pos, Object value) {
final boolean locked = (Boolean) value;
MetricsLogger.action(getActivity(), MetricsLogger.ACTION_ROTATION_LOCK,
locked);
RotationPolicy.setRotationLock(activity, locked);
return true;
}
}
当被开机自动旋转时,有如下调用
onItemSelected ->
RotationPolicy.setRotationLock ->
setRotationLock -> RotationPolicy.java
wm.freezeRotation -> //wm是WindowManagerService
freezeRotation -> WindowManagerService.java
mPolicy.setUserRotationMode(WindowManagerPolicy.USER_ROTATION_LOCKED…)//更新到database中
setUserRotationMode -> PhoneWindowManager.java //更新Settings.System.USER_ROTATION以及Settings.System.ACCELEROMETER_ROTATION,另一方面Settings.System.USER_ROTATION这个值在开机的时候被SettingsObserver的observe()注册监听,一旦有更新,就会调用对应的onChange()
onChange ->
updateSettings ->
updateOrientationListenerLp ->
mOrientationListener.enable -> //集成自WindowOrientationListener,调用父类的enable()
enable -> WindowOrientationListener.java
mOrientationJudge.resetLocked //对应的是OrientationSensorJudge
mSensorManager.registerListener //把OrientationSensorJudge注册到SensorManager中
updateRotationUnchecked
updateRotationUnchecked在 [RK3288][Android6.0] Apk设置显示旋转过程小结 已经分析过了。
当屏幕发生旋转后,sensor模块上报数据给SensorManager,SensorManager会调用OrientationSensorJudge类的onSensorChanged()
public void onSensorChanged(SensorEvent event) {
int newRotation;
synchronized (mLock) {
mDesiredRotation = (int) event.values[0];
//获取新的rotation
newRotation = evaluateRotationChangeLocked();
}
if (newRotation >=0) {
//调用抽象方法
onProposedRotationChanged(newRotation);
}
}
PhoneWindowManager.java
public void onProposedRotationChanged(int rotation) {
if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
mHandler.post(mUpdateRotationRunnable);
}
mUpdateRotationRunnable对应的是下面的
private final Runnable mUpdateRotationRunnable = new Runnable() {
@Override
public void run() {
// send interaction hint to improve redraw performance
mPowerManagerInternal.powerHint(PowerManagerInternal.POWER_HINT_INTERACTION, 0);
updateRotation(false);
}
};
PhoneWindowManager.java
void updateRotation(boolean alwaysSendConfiguration) {
try {
//set orientation on WindowManager
mWindowManager.updateRotation(alwaysSendConfiguration, false);
} catch (RemoteException e) {
// Ignore
}
}
mWindowManager就是WindowManagerService
public void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
updateRotationUnchecked(alwaysSendConfiguration, forceRelayout);
}
最终也是调用updateRotationUnchecked()来更新
参考:
android自动转屏流程分析
最后
以上就是愉快方盒为你收集整理的[RK3288][Android6.0] 设置中通过Sensor旋转显示画面小结的全部内容,希望文章能够帮你解决[RK3288][Android6.0] 设置中通过Sensor旋转显示画面小结所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复