Android9.0和11.0系统开机之后发现屏幕会自动转到0度,可以自己保存一下这个旋转值,在初始化时旋转到保存的角度。
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java
index c2fcb28d7a4c..a192ce8cceb8 100755
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java
@@ -1457,12 +1457,16 @@ public class NavigationBarFragment extends LifecycleFragment implements Callback
Log.d(TAG, "getRotation before = " + pre_Rotation);
if (pre_Rotation == Surface.ROTATION_0){
mWindowManagerService.freezeRotation(Surface.ROTATION_90);
+ SystemProperties.set("persist.vendor.orientation", "90");
}else if (pre_Rotation == Surface.ROTATION_90){
mWindowManagerService.freezeRotation(Surface.ROTATION_180);
+ SystemProperties.set("persist.vendor.orientation", "180");
}else if (pre_Rotation == Surface.ROTATION_180){
mWindowManagerService.freezeRotation(Surface.ROTATION_270);
+ SystemProperties.set("persist.vendor.orientation", "270");
}else{
mWindowManagerService.freezeRotation(Surface.ROTATION_0);
+ SystemProperties.set("persist.vendor.orientation", "0");
}
} catch (RemoteException e) {
Log.d(TAG, "onRotateKeyClick error:" + e.toString());
@@ -1772,6 +1776,7 @@ public class NavigationBarFragment extends LifecycleFragment implements Callback
else if("com.itemp.orierntion.changer".equals(action)){
String orierntion = intent.getExtras().getString("orierntion");
int newOrierntion = TextUtils.isEmpty(orierntion) ? 0 : Integer.valueOf(orierntion.trim())/90;
+ SystemProperties.set("persist.vendor.orientation", orierntion);
try {
mWindowManagerService.freezeRotation(newOrierntion);
}catch(RemoteException e){
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/RotationLockControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/RotationLockControllerImpl.java
old mode 100644
new mode 100755
index 1f368e164678..6aaaaa21995a
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/RotationLockControllerImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/RotationLockControllerImpl.java
@@ -22,7 +22,7 @@ import android.os.UserHandle;
import com.android.internal.view.RotationPolicy;
import java.util.concurrent.CopyOnWriteArrayList;
-
+import android.util.Log;
import javax.inject.Inject;
import javax.inject.Singleton;
@@ -30,6 +30,7 @@ import javax.inject.Singleton;
@Singleton
public final class RotationLockControllerImpl implements RotationLockController {
private final Context mContext;
+ private static final String ROTATE_SCREEN_KEY = "persist.vendor.orientation";//"persist.sys.user_rotation";
private final CopyOnWriteArrayList<RotationLockControllerCallback> mCallbacks =
new CopyOnWriteArrayList<RotationLockControllerCallback>();
@@ -69,7 +70,11 @@ public final class RotationLockControllerImpl implements RotationLockController
}
public void setRotationLockedAtAngle(boolean locked, int rotation){
- RotationPolicy.setRotationLockAtAngle(mContext, locked, rotation);
+ //RotationPolicy.setRotationLockAtAngle(mContext, locked, rotation);
+ int rotation_screen = android.os.SystemProperties.getInt(ROTATE_SCREEN_KEY, 0);
+ rotation_screen /= 90;
+ //Log.d("Rotation", "setRotationLockedAtAngle rotation_screen = " + rotation_screen + " , locked = " + locked);
+ RotationPolicy.setRotationLockAtAngle(mContext, locked, rotation_screen);
}
public boolean isRotationLockAffordanceVisible() {
(END)
调试命令:
settings get system accelerometer_rotation
settings put system accelerometer_rotation 0 解锁屏幕旋转
settings put system accelerometer_rotation 1 锁定屏幕旋转
settings get system user_rotation
settings put system user_rotation 1 旋转到90