最近RK平台 12.0系统中,遇到调用“System.putInt(contentResolver, “user_rotation”, rotation);” 调整屏幕方向时,重启后方向总恢复默认方向的问题。
问题原因:
开机时系统重新设置了user_rotation
frameworks\base\services\core\java\com\android\server\wm\DisplayRotation.java
@VisibleForTesting
void setUserRotation(int userRotationMode, int userRotation) {
if (isDefaultDisplay) {
// We'll be notified via settings listener, so we don't need to update internal values.
final ContentResolver res = mContext.getContentResolver();
final int accelerometerRotation =
userRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED ? 0 : 1;
Settings.System.putIntForUser(res, Settings.System.ACCELEROMETER_ROTATION,
accelerometerRotation, UserHandle.USER_CURRENT);
Settings.System.putIntForUser(res, Settings.System.USER_ROTATION, userRotation, 0),
UserHandle.USER_CURRENT);
return;
}
boolean changed = false;
if (mUserRotationMode != userRotationMode) {
mUserRotationMode = userRotationMode;
changed = true;
}
if (mUserRotation != userRotation) {
mUserRotation = userRotation;
changed = true;
}
mDisplayWindowSettings.setUserRotation(mDisplayContent, userRotationMode,
userRotation);
if (changed) {
mService.updateRotation(true /* alwaysSendConfiguration */,
false /* forceRelayout */);
}
}
调整方向:
设置时保存屏幕方向到persist属性,并在上述方法中设置即可
Settings.System.putIntForUser(res, Settings.System.USER_ROTATION, SystemProperties.getInt("persist.vendor.screen.property", 0),
UserHandle.USER_CURRENT);