Loading services/core/java/com/android/server/wm/DeviceStateAutoRotateSettingController.java +2 −41 Original line number Diff line number Diff line Loading @@ -16,15 +16,8 @@ package com.android.server.wm; import android.annotation.NonNull; import android.content.Context; import android.database.ContentObserver; import android.hardware.devicestate.DeviceState; import android.os.Handler; import android.provider.Settings; import com.android.window.flags.Flags; /** * Syncs ACCELEROMETER_ROTATION and DEVICE_STATE_ROTATION_LOCK setting to consistent values. * <ul> Loading @@ -41,39 +34,7 @@ import com.android.window.flags.Flags; */ public class DeviceStateAutoRotateSettingController { private final DeviceStateAutoRotateSettingIssueLogger mDeviceStateAutoRotateSettingIssueLogger; private final Context mContext; private final Handler mHandler; public DeviceStateAutoRotateSettingController(Context context, DeviceStateAutoRotateSettingIssueLogger deviceStateAutoRotateSettingIssueLogger, Handler handler) { // TODO(b/350946537) Refactor implementation mDeviceStateAutoRotateSettingIssueLogger = deviceStateAutoRotateSettingIssueLogger; mContext = context; mHandler = handler; registerDeviceStateAutoRotateSettingObserver(); } /** Notify controller device state has changed */ public void onDeviceStateChange(@NonNull DeviceState deviceState) { if (Flags.enableDeviceStateAutoRotateSettingLogging()) { mDeviceStateAutoRotateSettingIssueLogger.onDeviceStateChange(); } } private void registerDeviceStateAutoRotateSettingObserver() { mContext.getContentResolver().registerContentObserver( Settings.Secure.getUriFor(Settings.Secure.DEVICE_STATE_ROTATION_LOCK), false, new ContentObserver(mHandler) { @Override public void onChange(boolean selfChange) { if (Flags.enableDeviceStateAutoRotateSettingLogging()) { mDeviceStateAutoRotateSettingIssueLogger .onDeviceStateAutoRotateSettingChange(); } } }); public DeviceStateAutoRotateSettingController() { } } services/core/java/com/android/server/wm/DeviceStateAutoRotateSettingIssueLogger.java +27 −5 Original line number Diff line number Diff line Loading @@ -16,13 +16,20 @@ package com.android.server.wm; import static android.provider.Settings.Secure.DEVICE_STATE_ROTATION_LOCK; import static android.util.MathUtils.abs; import android.annotation.ElapsedRealtimeLong; import android.annotation.NonNull; import android.database.ContentObserver; import android.hardware.devicestate.DeviceState; import android.os.Handler; import android.os.HandlerExecutor; import android.os.UserHandle; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.util.FrameworkStatsLog; import com.android.settingslib.devicestate.SecureSettings; import java.util.function.LongSupplier; Loading Loading @@ -55,18 +62,33 @@ public class DeviceStateAutoRotateSettingIssueLogger { private long mLastDeviceStateAutoRotateSettingChangeTime = TIME_NOT_SET; public DeviceStateAutoRotateSettingIssueLogger( @NonNull LongSupplier elapsedTimeMillisSupplier) { @NonNull LongSupplier elapsedTimeMillisSupplier, SecureSettings secureSettings, DeviceStateController deviceStateController, Handler handler) { mElapsedTimeMillisSupplier = elapsedTimeMillisSupplier; secureSettings.registerContentObserver( DEVICE_STATE_ROTATION_LOCK, /* notifyForDescendants= */ false, new ContentObserver(handler) { @Override public void onChange(boolean selfChange) { onDeviceStateAutoRotateSettingChange(); } }, UserHandle.USER_CURRENT); deviceStateController.registerDeviceStateCallback( (DeviceStateController.DeviceStateEnum deviceStateEnum, DeviceState deviceState) -> { onDeviceStateChange(); }, new HandlerExecutor(handler)); } /** Notify logger that device state has changed. */ public void onDeviceStateChange() { private void onDeviceStateChange() { mLastDeviceStateChangeTime = mElapsedTimeMillisSupplier.getAsLong(); onStateChange(); } /** Notify logger that device state based auto rotate setting has changed. */ public void onDeviceStateAutoRotateSettingChange() { private void onDeviceStateAutoRotateSettingChange() { mLastDeviceStateAutoRotateSettingChangeTime = mElapsedTimeMillisSupplier.getAsLong(); onStateChange(); } Loading services/core/java/com/android/server/wm/DisplayContent.java +1 −1 Original line number Diff line number Diff line Loading @@ -1203,7 +1203,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp mDeviceStateListener = (@NonNull DeviceStateController.DeviceStateEnum deviceStateEnum, @NonNull DeviceState deviceState) -> mDisplayRotation.foldStateChanged( deviceStateEnum, deviceState); deviceStateEnum); mDeviceStateController.registerDeviceStateCallback(mDeviceStateListener, new HandlerExecutor(mWmService.mH)); Loading services/core/java/com/android/server/wm/DisplayRotation.java +56 −18 Original line number Diff line number Diff line Loading @@ -55,7 +55,7 @@ import android.hardware.Sensor; import android.hardware.SensorEvent; import android.hardware.SensorEventListener; import android.hardware.SensorManager; import android.hardware.devicestate.DeviceState; import android.hardware.devicestate.DeviceStateManager; import android.hardware.power.Boost; import android.os.Handler; import android.os.SystemClock; Loading @@ -75,10 +75,16 @@ import android.window.WindowContainerTransaction; import com.android.internal.R; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.os.BackgroundThread; import com.android.internal.protolog.ProtoLog; import com.android.server.UiThread; import com.android.server.policy.WindowManagerPolicy; import com.android.server.statusbar.StatusBarManagerInternal; import com.android.settingslib.devicestate.AndroidSecureSettings; import com.android.settingslib.devicestate.DeviceStateAutoRotateSettingManager; import com.android.settingslib.devicestate.DeviceStateAutoRotateSettingManagerImpl; import com.android.settingslib.devicestate.PostureDeviceStateConverter; import com.android.settingslib.devicestate.SecureSettings; import com.android.window.flags.Flags; import java.io.PrintWriter; Loading Loading @@ -111,8 +117,6 @@ public class DisplayRotation { private final Object mLock; @Nullable private final DisplayRotationImmersiveAppCompatPolicy mCompatPolicyForImmersiveApps; @Nullable private DeviceStateAutoRotateSettingController mDeviceStateAutoRotateSettingController; public final boolean isDefaultDisplay; private final boolean mSupportAutoRotation; Loading Loading @@ -250,8 +254,7 @@ public class DisplayRotation { isDefaultDisplay = displayContent.isDefaultDisplay; mCompatPolicyForImmersiveApps = initImmersiveAppCompatPolicy(service, displayContent); mSupportAutoRotation = mContext.getResources().getBoolean(R.bool.config_supportAutoRotation); mSupportAutoRotation = isAutoRotateSupported(mContext); mAllowRotationResolver = mContext.getResources().getBoolean(R.bool.config_allowRotationResolver); mLidOpenRotation = readRotation(R.integer.config_lidOpenRotation); Loading Loading @@ -290,20 +293,16 @@ public class DisplayRotation { } else { mFoldController = null; } if (mFoldController != null && (Flags.enableDeviceStateAutoRotateSettingLogging() || Flags.enableDeviceStateAutoRotateSettingRefactor())) { mDeviceStateAutoRotateSettingController = new DeviceStateAutoRotateSettingController(mContext, new DeviceStateAutoRotateSettingIssueLogger( SystemClock::elapsedRealtime), mService.mH); } } private static boolean isFoldable(Context context) { return context.getResources().getIntArray(R.array.config_foldedDeviceStates).length > 0; } private static boolean isAutoRotateSupported(@NonNull Context context) { return context.getResources().getBoolean(R.bool.config_supportAutoRotation); } @VisibleForTesting @Nullable DisplayRotationImmersiveAppCompatPolicy initImmersiveAppCompatPolicy( Loading Loading @@ -1594,14 +1593,10 @@ public class DisplayRotation { * method will be invoked *after* this one. */ // TODO(b/409761673) Migrate to only using android.hardware.devicestate.DeviceState void foldStateChanged(DeviceStateController.DeviceStateEnum deviceStateEnum, DeviceState deviceState) { void foldStateChanged(DeviceStateController.DeviceStateEnum deviceStateEnum) { if (mFoldController != null) { synchronized (mLock) { mFoldController.foldStateChanged(deviceStateEnum); if (mDeviceStateAutoRotateSettingController != null) { mDeviceStateAutoRotateSettingController.onDeviceStateChange(deviceState); } } } } Loading Loading @@ -1653,6 +1648,49 @@ public class DisplayRotation { return SystemClock.uptimeMillis(); } /** * Initialize dependencies related to Device state auto-rotate setting. * <p> * Set of dependencies initialized here is: * <ul> * <li>{@link DeviceStateAutoRotateSettingController}</li> * <li>{@link DeviceStateAutoRotateSettingIssueLogger}</li> * <li>{@link DeviceStateAutoRotateSettingManager}</li> * </ul> * @return an instance of {@link DeviceStateAutoRotateSettingController} */ @Nullable static DeviceStateAutoRotateSettingController createDeviceStateAutoRotateDependencies( Context context, DeviceStateController deviceStateController, Handler handler) { if (!isFoldable(context) || !isAutoRotateSupported(context)) return null; if (!Flags.enableDeviceStateAutoRotateSettingLogging() && !Flags.enableDeviceStateAutoRotateSettingRefactor()) { return null; } DeviceStateAutoRotateSettingController deviceStateAutoRotateSettingController = null; final SecureSettings secureSettings = new AndroidSecureSettings( context.getContentResolver()); if (Flags.enableDeviceStateAutoRotateSettingLogging()) { new DeviceStateAutoRotateSettingIssueLogger(SystemClock::elapsedRealtime, secureSettings, deviceStateController, handler); } if (Flags.enableDeviceStateAutoRotateSettingRefactor()) { final DeviceStateAutoRotateSettingManager deviceStateAutoRotateSettingManager = new DeviceStateAutoRotateSettingManagerImpl( context, BackgroundThread.getExecutor(), secureSettings, handler, new PostureDeviceStateConverter(context, new DeviceStateManager())); // TODO(b/406444989): Manager created in previous line will be passed into controller deviceStateAutoRotateSettingController = new DeviceStateAutoRotateSettingController(); } return deviceStateAutoRotateSettingController; } class FoldController { private final boolean mPauseAutorotationDuringUnfolding; @Surface.Rotation Loading services/core/java/com/android/server/wm/RootWindowContainer.java +5 −0 Original line number Diff line number Diff line Loading @@ -255,6 +255,8 @@ class RootWindowContainer extends WindowContainer<DisplayContent> /** Root task id of the front root task when user switched, indexed by userId. */ SparseIntArray mUserRootTaskInFront = new SparseIntArray(2); SparseArray<IntArray> mUserVisibleRootTasks = new SparseArray<>(); @Nullable DeviceStateAutoRotateSettingController mDeviceStateAutoRotateSettingController; /** * A list of tokens that cause the top activity to be put to sleep. Loading Loading @@ -453,6 +455,9 @@ class RootWindowContainer extends WindowContainer<DisplayContent> mDisplayOffTokenAcquirer = mService.new SleepTokenAcquirer(DISPLAY_OFF_SLEEP_TOKEN_TAG); mDeviceStateController = new DeviceStateController(service.mContext, service.mGlobalLock); mDisplayRotationCoordinator = new DisplayRotationCoordinator(); mDeviceStateAutoRotateSettingController = DisplayRotation.createDeviceStateAutoRotateDependencies(mService.mContext, mDeviceStateController, mService.mH); } /** Loading Loading
services/core/java/com/android/server/wm/DeviceStateAutoRotateSettingController.java +2 −41 Original line number Diff line number Diff line Loading @@ -16,15 +16,8 @@ package com.android.server.wm; import android.annotation.NonNull; import android.content.Context; import android.database.ContentObserver; import android.hardware.devicestate.DeviceState; import android.os.Handler; import android.provider.Settings; import com.android.window.flags.Flags; /** * Syncs ACCELEROMETER_ROTATION and DEVICE_STATE_ROTATION_LOCK setting to consistent values. * <ul> Loading @@ -41,39 +34,7 @@ import com.android.window.flags.Flags; */ public class DeviceStateAutoRotateSettingController { private final DeviceStateAutoRotateSettingIssueLogger mDeviceStateAutoRotateSettingIssueLogger; private final Context mContext; private final Handler mHandler; public DeviceStateAutoRotateSettingController(Context context, DeviceStateAutoRotateSettingIssueLogger deviceStateAutoRotateSettingIssueLogger, Handler handler) { // TODO(b/350946537) Refactor implementation mDeviceStateAutoRotateSettingIssueLogger = deviceStateAutoRotateSettingIssueLogger; mContext = context; mHandler = handler; registerDeviceStateAutoRotateSettingObserver(); } /** Notify controller device state has changed */ public void onDeviceStateChange(@NonNull DeviceState deviceState) { if (Flags.enableDeviceStateAutoRotateSettingLogging()) { mDeviceStateAutoRotateSettingIssueLogger.onDeviceStateChange(); } } private void registerDeviceStateAutoRotateSettingObserver() { mContext.getContentResolver().registerContentObserver( Settings.Secure.getUriFor(Settings.Secure.DEVICE_STATE_ROTATION_LOCK), false, new ContentObserver(mHandler) { @Override public void onChange(boolean selfChange) { if (Flags.enableDeviceStateAutoRotateSettingLogging()) { mDeviceStateAutoRotateSettingIssueLogger .onDeviceStateAutoRotateSettingChange(); } } }); public DeviceStateAutoRotateSettingController() { } }
services/core/java/com/android/server/wm/DeviceStateAutoRotateSettingIssueLogger.java +27 −5 Original line number Diff line number Diff line Loading @@ -16,13 +16,20 @@ package com.android.server.wm; import static android.provider.Settings.Secure.DEVICE_STATE_ROTATION_LOCK; import static android.util.MathUtils.abs; import android.annotation.ElapsedRealtimeLong; import android.annotation.NonNull; import android.database.ContentObserver; import android.hardware.devicestate.DeviceState; import android.os.Handler; import android.os.HandlerExecutor; import android.os.UserHandle; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.util.FrameworkStatsLog; import com.android.settingslib.devicestate.SecureSettings; import java.util.function.LongSupplier; Loading Loading @@ -55,18 +62,33 @@ public class DeviceStateAutoRotateSettingIssueLogger { private long mLastDeviceStateAutoRotateSettingChangeTime = TIME_NOT_SET; public DeviceStateAutoRotateSettingIssueLogger( @NonNull LongSupplier elapsedTimeMillisSupplier) { @NonNull LongSupplier elapsedTimeMillisSupplier, SecureSettings secureSettings, DeviceStateController deviceStateController, Handler handler) { mElapsedTimeMillisSupplier = elapsedTimeMillisSupplier; secureSettings.registerContentObserver( DEVICE_STATE_ROTATION_LOCK, /* notifyForDescendants= */ false, new ContentObserver(handler) { @Override public void onChange(boolean selfChange) { onDeviceStateAutoRotateSettingChange(); } }, UserHandle.USER_CURRENT); deviceStateController.registerDeviceStateCallback( (DeviceStateController.DeviceStateEnum deviceStateEnum, DeviceState deviceState) -> { onDeviceStateChange(); }, new HandlerExecutor(handler)); } /** Notify logger that device state has changed. */ public void onDeviceStateChange() { private void onDeviceStateChange() { mLastDeviceStateChangeTime = mElapsedTimeMillisSupplier.getAsLong(); onStateChange(); } /** Notify logger that device state based auto rotate setting has changed. */ public void onDeviceStateAutoRotateSettingChange() { private void onDeviceStateAutoRotateSettingChange() { mLastDeviceStateAutoRotateSettingChangeTime = mElapsedTimeMillisSupplier.getAsLong(); onStateChange(); } Loading
services/core/java/com/android/server/wm/DisplayContent.java +1 −1 Original line number Diff line number Diff line Loading @@ -1203,7 +1203,7 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp mDeviceStateListener = (@NonNull DeviceStateController.DeviceStateEnum deviceStateEnum, @NonNull DeviceState deviceState) -> mDisplayRotation.foldStateChanged( deviceStateEnum, deviceState); deviceStateEnum); mDeviceStateController.registerDeviceStateCallback(mDeviceStateListener, new HandlerExecutor(mWmService.mH)); Loading
services/core/java/com/android/server/wm/DisplayRotation.java +56 −18 Original line number Diff line number Diff line Loading @@ -55,7 +55,7 @@ import android.hardware.Sensor; import android.hardware.SensorEvent; import android.hardware.SensorEventListener; import android.hardware.SensorManager; import android.hardware.devicestate.DeviceState; import android.hardware.devicestate.DeviceStateManager; import android.hardware.power.Boost; import android.os.Handler; import android.os.SystemClock; Loading @@ -75,10 +75,16 @@ import android.window.WindowContainerTransaction; import com.android.internal.R; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.os.BackgroundThread; import com.android.internal.protolog.ProtoLog; import com.android.server.UiThread; import com.android.server.policy.WindowManagerPolicy; import com.android.server.statusbar.StatusBarManagerInternal; import com.android.settingslib.devicestate.AndroidSecureSettings; import com.android.settingslib.devicestate.DeviceStateAutoRotateSettingManager; import com.android.settingslib.devicestate.DeviceStateAutoRotateSettingManagerImpl; import com.android.settingslib.devicestate.PostureDeviceStateConverter; import com.android.settingslib.devicestate.SecureSettings; import com.android.window.flags.Flags; import java.io.PrintWriter; Loading Loading @@ -111,8 +117,6 @@ public class DisplayRotation { private final Object mLock; @Nullable private final DisplayRotationImmersiveAppCompatPolicy mCompatPolicyForImmersiveApps; @Nullable private DeviceStateAutoRotateSettingController mDeviceStateAutoRotateSettingController; public final boolean isDefaultDisplay; private final boolean mSupportAutoRotation; Loading Loading @@ -250,8 +254,7 @@ public class DisplayRotation { isDefaultDisplay = displayContent.isDefaultDisplay; mCompatPolicyForImmersiveApps = initImmersiveAppCompatPolicy(service, displayContent); mSupportAutoRotation = mContext.getResources().getBoolean(R.bool.config_supportAutoRotation); mSupportAutoRotation = isAutoRotateSupported(mContext); mAllowRotationResolver = mContext.getResources().getBoolean(R.bool.config_allowRotationResolver); mLidOpenRotation = readRotation(R.integer.config_lidOpenRotation); Loading Loading @@ -290,20 +293,16 @@ public class DisplayRotation { } else { mFoldController = null; } if (mFoldController != null && (Flags.enableDeviceStateAutoRotateSettingLogging() || Flags.enableDeviceStateAutoRotateSettingRefactor())) { mDeviceStateAutoRotateSettingController = new DeviceStateAutoRotateSettingController(mContext, new DeviceStateAutoRotateSettingIssueLogger( SystemClock::elapsedRealtime), mService.mH); } } private static boolean isFoldable(Context context) { return context.getResources().getIntArray(R.array.config_foldedDeviceStates).length > 0; } private static boolean isAutoRotateSupported(@NonNull Context context) { return context.getResources().getBoolean(R.bool.config_supportAutoRotation); } @VisibleForTesting @Nullable DisplayRotationImmersiveAppCompatPolicy initImmersiveAppCompatPolicy( Loading Loading @@ -1594,14 +1593,10 @@ public class DisplayRotation { * method will be invoked *after* this one. */ // TODO(b/409761673) Migrate to only using android.hardware.devicestate.DeviceState void foldStateChanged(DeviceStateController.DeviceStateEnum deviceStateEnum, DeviceState deviceState) { void foldStateChanged(DeviceStateController.DeviceStateEnum deviceStateEnum) { if (mFoldController != null) { synchronized (mLock) { mFoldController.foldStateChanged(deviceStateEnum); if (mDeviceStateAutoRotateSettingController != null) { mDeviceStateAutoRotateSettingController.onDeviceStateChange(deviceState); } } } } Loading Loading @@ -1653,6 +1648,49 @@ public class DisplayRotation { return SystemClock.uptimeMillis(); } /** * Initialize dependencies related to Device state auto-rotate setting. * <p> * Set of dependencies initialized here is: * <ul> * <li>{@link DeviceStateAutoRotateSettingController}</li> * <li>{@link DeviceStateAutoRotateSettingIssueLogger}</li> * <li>{@link DeviceStateAutoRotateSettingManager}</li> * </ul> * @return an instance of {@link DeviceStateAutoRotateSettingController} */ @Nullable static DeviceStateAutoRotateSettingController createDeviceStateAutoRotateDependencies( Context context, DeviceStateController deviceStateController, Handler handler) { if (!isFoldable(context) || !isAutoRotateSupported(context)) return null; if (!Flags.enableDeviceStateAutoRotateSettingLogging() && !Flags.enableDeviceStateAutoRotateSettingRefactor()) { return null; } DeviceStateAutoRotateSettingController deviceStateAutoRotateSettingController = null; final SecureSettings secureSettings = new AndroidSecureSettings( context.getContentResolver()); if (Flags.enableDeviceStateAutoRotateSettingLogging()) { new DeviceStateAutoRotateSettingIssueLogger(SystemClock::elapsedRealtime, secureSettings, deviceStateController, handler); } if (Flags.enableDeviceStateAutoRotateSettingRefactor()) { final DeviceStateAutoRotateSettingManager deviceStateAutoRotateSettingManager = new DeviceStateAutoRotateSettingManagerImpl( context, BackgroundThread.getExecutor(), secureSettings, handler, new PostureDeviceStateConverter(context, new DeviceStateManager())); // TODO(b/406444989): Manager created in previous line will be passed into controller deviceStateAutoRotateSettingController = new DeviceStateAutoRotateSettingController(); } return deviceStateAutoRotateSettingController; } class FoldController { private final boolean mPauseAutorotationDuringUnfolding; @Surface.Rotation Loading
services/core/java/com/android/server/wm/RootWindowContainer.java +5 −0 Original line number Diff line number Diff line Loading @@ -255,6 +255,8 @@ class RootWindowContainer extends WindowContainer<DisplayContent> /** Root task id of the front root task when user switched, indexed by userId. */ SparseIntArray mUserRootTaskInFront = new SparseIntArray(2); SparseArray<IntArray> mUserVisibleRootTasks = new SparseArray<>(); @Nullable DeviceStateAutoRotateSettingController mDeviceStateAutoRotateSettingController; /** * A list of tokens that cause the top activity to be put to sleep. Loading Loading @@ -453,6 +455,9 @@ class RootWindowContainer extends WindowContainer<DisplayContent> mDisplayOffTokenAcquirer = mService.new SleepTokenAcquirer(DISPLAY_OFF_SLEEP_TOKEN_TAG); mDeviceStateController = new DeviceStateController(service.mContext, service.mGlobalLock); mDisplayRotationCoordinator = new DisplayRotationCoordinator(); mDeviceStateAutoRotateSettingController = DisplayRotation.createDeviceStateAutoRotateDependencies(mService.mContext, mDeviceStateController, mService.mH); } /** Loading