Loading services/core/java/com/android/server/wm/DeviceStateAutoRotateSettingController.java +13 −5 Original line number Diff line number Diff line Loading @@ -173,8 +173,9 @@ public class DeviceStateAutoRotateSettingController { * Request to change {@link ACCELEROMETER_ROTATION} persisted setting. If needed, we might also * write into {@link USER_ROTATION} with {@param userRotation}. */ public void requestAccelerometerRotationSettingChange(boolean autoRotate, int userRotation) { postUpdate(new UpdateAccelerometerRotationSetting(autoRotate, userRotation)); public void requestAccelerometerRotationSettingChange(boolean autoRotate, int userRotation, String caller) { postUpdate(new UpdateAccelerometerRotationSetting(autoRotate, userRotation, caller)); } private void registerDeviceStateAutoRotateSettingObserver() { Loading Loading @@ -342,10 +343,13 @@ public class DeviceStateAutoRotateSettingController { return; } final int userRotation; final String caller; if (event instanceof UpdateAccelerometerRotationSetting) { // If the event is `UpdateAccelerometerRotationSetting`, it means that the // userRotation was provided, so we should set it. userRotation = ((UpdateAccelerometerRotationSetting) event).mUserRotation; caller = ((UpdateAccelerometerRotationSetting) event).mCaller; } else { // If the event is not `UpdateAccelerometerRotationSetting`, it means that the // userRotation was not explicitly provided. Loading @@ -357,12 +361,12 @@ public class DeviceStateAutoRotateSettingController { ? USE_CURRENT_ROTATION : NATURAL_ROTATION; } caller = "DSAutoRotateCtrl#" + event.getClass().getSimpleName(); } synchronized (mWm.mRoot.mService.mGlobalLock) { mWm.mRoot.getDefaultDisplay().getDisplayRotation().setUserRotationSetting( mAccelerometerSetting ? WindowManagerPolicy.USER_ROTATION_FREE : WindowManagerPolicy.USER_ROTATION_LOCKED, userRotation, "DSAutoRotateCtrl"); : WindowManagerPolicy.USER_ROTATION_LOCKED, userRotation, caller); } } Loading Loading @@ -399,15 +403,19 @@ public class DeviceStateAutoRotateSettingController { static final class UpdateAccelerometerRotationSetting extends Event { final boolean mAutoRotate; final int mUserRotation; final String mCaller; /** * @param autoRotate The desired auto-rotate state to write into * ACCELEROMETER_ROTATION. * @param userRotation The desired user rotation to write into USER_ROTATION. * @param caller Identifying the caller for logging/debugging purposes. */ UpdateAccelerometerRotationSetting(boolean autoRotate, int userRotation) { UpdateAccelerometerRotationSetting(boolean autoRotate, int userRotation, String caller) { mAutoRotate = autoRotate; mUserRotation = userRotation; mCaller = caller; } } Loading services/core/java/com/android/server/wm/DisplayRotation.java +1 −1 Original line number Diff line number Diff line Loading @@ -764,7 +764,7 @@ public class DisplayRotation { // setUserRotationSetting may be called. mService.mRoot.mDeviceStateAutoRotateSettingController .requestAccelerometerRotationSettingChange(accelerometerRotation == 1, userRotation); userRotation, caller); } else { Settings.System.putIntForUser(res, Settings.System.ACCELEROMETER_ROTATION, accelerometerRotation, UserHandle.USER_CURRENT); Loading services/tests/wmtests/src/com/android/server/wm/DeviceStateAutoRotateSettingControllerTests.java +11 −11 Original line number Diff line number Diff line Loading @@ -212,7 +212,7 @@ public class DeviceStateAutoRotateSettingControllerTests { setDeviceState(FOLDED); mDeviceStateAutoRotateSettingController.requestAccelerometerRotationSettingChange(true, USE_CURRENT_ROTATION); USE_CURRENT_ROTATION, ""); mTestLooper.dispatchAll(); verifyAccelerometerRotationSettingSet(ACCELEROMETER_ROTATION_ON); Loading @@ -234,7 +234,7 @@ public class DeviceStateAutoRotateSettingControllerTests { setDeviceState(FOLDED); mDeviceStateAutoRotateSettingController.requestAccelerometerRotationSettingChange(true, USE_CURRENT_ROTATION); USE_CURRENT_ROTATION, ""); mTestLooper.dispatchAll(); verifyDeviceStateAutoRotateSettingSet( Loading Loading @@ -344,7 +344,7 @@ public class DeviceStateAutoRotateSettingControllerTests { @Test public void requestAccelerometerRotationChange_dSUnavailable_noSettingUpdate() { mDeviceStateAutoRotateSettingController.requestAccelerometerRotationSettingChange(true, USE_CURRENT_ROTATION); USE_CURRENT_ROTATION, ""); mTestLooper.dispatchAll(); verifyAccelerometerRotationSettingSet(ACCELEROMETER_ROTATION_OFF); Loading @@ -362,7 +362,7 @@ public class DeviceStateAutoRotateSettingControllerTests { @Test public void requestAccelerometerRotationChange_dSUnavailable_writeAfterReceivingDSUpdate() { mDeviceStateAutoRotateSettingController.requestAccelerometerRotationSettingChange(true, USE_CURRENT_ROTATION); USE_CURRENT_ROTATION, ""); mTestLooper.dispatchAll(); setDeviceState(FOLDED); Loading Loading @@ -390,7 +390,7 @@ public class DeviceStateAutoRotateSettingControllerTests { mDeviceStateAutoRotateSettingController.requestDeviceStateAutoRotateSettingChange( FOLDED.getIdentifier(), true); mDeviceStateAutoRotateSettingController.requestAccelerometerRotationSettingChange(false, USE_CURRENT_ROTATION); USE_CURRENT_ROTATION, ""); mDeviceStateAutoRotateSettingController.requestDeviceStateAutoRotateSettingChange( OPEN.getIdentifier(), true); mTestLooper.dispatchAll(); Loading @@ -404,7 +404,7 @@ public class DeviceStateAutoRotateSettingControllerTests { @Test public void dSUnavailable_sendMultipleRequests_dSAutoRotatePrecedesAfterReceivingDSUpdate() { mDeviceStateAutoRotateSettingController.requestAccelerometerRotationSettingChange(false, USE_CURRENT_ROTATION); USE_CURRENT_ROTATION, ""); mDeviceStateAutoRotateSettingController.requestDeviceStateAutoRotateSettingChange( OPEN.getIdentifier(), true); mDeviceStateAutoRotateSettingController.requestDeviceStateAutoRotateSettingChange( Loading Loading @@ -433,7 +433,7 @@ public class DeviceStateAutoRotateSettingControllerTests { setDeviceState(FOLDED); mDeviceStateAutoRotateSettingController.requestAccelerometerRotationSettingChange(true, Surface.ROTATION_90); Surface.ROTATION_90, ""); mTestLooper.dispatchAll(); verify(mMockDisplayRotation).setUserRotationSetting( Loading @@ -448,7 +448,7 @@ public class DeviceStateAutoRotateSettingControllerTests { mTestLooper.dispatchAll(); mDeviceStateAutoRotateSettingController.requestAccelerometerRotationSettingChange( false, Surface.ROTATION_180); false, Surface.ROTATION_180, ""); mTestLooper.dispatchAll(); verify(mMockDisplayRotation).setUserRotationSetting( Loading @@ -461,7 +461,7 @@ public class DeviceStateAutoRotateSettingControllerTests { mTestLooper.dispatchAll(); mDeviceStateAutoRotateSettingController.requestAccelerometerRotationSettingChange(true, USE_CURRENT_ROTATION); USE_CURRENT_ROTATION, ""); mTestLooper.dispatchAll(); verify(mMockDisplayRotation).setUserRotationSetting( Loading @@ -476,7 +476,7 @@ public class DeviceStateAutoRotateSettingControllerTests { mTestLooper.dispatchAll(); mDeviceStateAutoRotateSettingController.requestAccelerometerRotationSettingChange( false, NATURAL_ROTATION); false, NATURAL_ROTATION, ""); mTestLooper.dispatchAll(); verify(mMockDisplayRotation).setUserRotationSetting( Loading @@ -500,7 +500,7 @@ public class DeviceStateAutoRotateSettingControllerTests { setDeviceState(FOLDED); mDeviceStateAutoRotateSettingController.requestAccelerometerRotationSettingChange( false, Surface.ROTATION_90); false, Surface.ROTATION_90, ""); mTestLooper.dispatchAll(); verify(mMockDisplayRotation).setUserRotationSetting( Loading services/tests/wmtests/src/com/android/server/wm/DisplayRotationTests.java +16 −9 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import static android.view.IWindowManager.FIXED_TO_USER_ROTATION_IF_NO_AUTO_ROTA import static com.android.dx.mockito.inline.extended.ExtendedMockito.any; import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyBoolean; import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyInt; import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyString; import static com.android.dx.mockito.inline.extended.ExtendedMockito.atLeast; import static com.android.dx.mockito.inline.extended.ExtendedMockito.atMost; import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; Loading Loading @@ -248,9 +249,11 @@ public class DisplayRotationTests { freezeRotation(Surface.ROTATION_180); verify(mockDeviceStateAutoRotateSettingController, times(1)).requestAccelerometerRotationSettingChange(eq(false), eq(Surface.ROTATION_180)); verify(mockDeviceStateAutoRotateSettingController, times(1)) .requestAccelerometerRotationSettingChange( /* autoRotate= */ eq(false), /* userRotation= */ eq(Surface.ROTATION_180), /* caller= */ anyString()); } @Test Loading @@ -264,9 +267,11 @@ public class DisplayRotationTests { thawRotation(); verify(mockDeviceStateAutoRotateSettingController, times(1)).requestAccelerometerRotationSettingChange(eq(true), anyInt()); verify(mockDeviceStateAutoRotateSettingController, times(1)) .requestAccelerometerRotationSettingChange( /* autoRotate= */ eq(true), /* userRotation= */ anyInt(), /* caller= */ anyString()); } @Test Loading @@ -281,9 +286,11 @@ public class DisplayRotationTests { freezeRotation(DisplayRotation.USE_CURRENT_ROTATION); verify(mockDeviceStateAutoRotateSettingController, times(1)).requestAccelerometerRotationSettingChange(eq(false), eq(Surface.ROTATION_90)); verify(mockDeviceStateAutoRotateSettingController, times(1)) .requestAccelerometerRotationSettingChange( /* autoRotate= */ eq(false), /* userRotation= */ eq(Surface.ROTATION_90), /* caller= */ anyString()); } @Test Loading Loading
services/core/java/com/android/server/wm/DeviceStateAutoRotateSettingController.java +13 −5 Original line number Diff line number Diff line Loading @@ -173,8 +173,9 @@ public class DeviceStateAutoRotateSettingController { * Request to change {@link ACCELEROMETER_ROTATION} persisted setting. If needed, we might also * write into {@link USER_ROTATION} with {@param userRotation}. */ public void requestAccelerometerRotationSettingChange(boolean autoRotate, int userRotation) { postUpdate(new UpdateAccelerometerRotationSetting(autoRotate, userRotation)); public void requestAccelerometerRotationSettingChange(boolean autoRotate, int userRotation, String caller) { postUpdate(new UpdateAccelerometerRotationSetting(autoRotate, userRotation, caller)); } private void registerDeviceStateAutoRotateSettingObserver() { Loading Loading @@ -342,10 +343,13 @@ public class DeviceStateAutoRotateSettingController { return; } final int userRotation; final String caller; if (event instanceof UpdateAccelerometerRotationSetting) { // If the event is `UpdateAccelerometerRotationSetting`, it means that the // userRotation was provided, so we should set it. userRotation = ((UpdateAccelerometerRotationSetting) event).mUserRotation; caller = ((UpdateAccelerometerRotationSetting) event).mCaller; } else { // If the event is not `UpdateAccelerometerRotationSetting`, it means that the // userRotation was not explicitly provided. Loading @@ -357,12 +361,12 @@ public class DeviceStateAutoRotateSettingController { ? USE_CURRENT_ROTATION : NATURAL_ROTATION; } caller = "DSAutoRotateCtrl#" + event.getClass().getSimpleName(); } synchronized (mWm.mRoot.mService.mGlobalLock) { mWm.mRoot.getDefaultDisplay().getDisplayRotation().setUserRotationSetting( mAccelerometerSetting ? WindowManagerPolicy.USER_ROTATION_FREE : WindowManagerPolicy.USER_ROTATION_LOCKED, userRotation, "DSAutoRotateCtrl"); : WindowManagerPolicy.USER_ROTATION_LOCKED, userRotation, caller); } } Loading Loading @@ -399,15 +403,19 @@ public class DeviceStateAutoRotateSettingController { static final class UpdateAccelerometerRotationSetting extends Event { final boolean mAutoRotate; final int mUserRotation; final String mCaller; /** * @param autoRotate The desired auto-rotate state to write into * ACCELEROMETER_ROTATION. * @param userRotation The desired user rotation to write into USER_ROTATION. * @param caller Identifying the caller for logging/debugging purposes. */ UpdateAccelerometerRotationSetting(boolean autoRotate, int userRotation) { UpdateAccelerometerRotationSetting(boolean autoRotate, int userRotation, String caller) { mAutoRotate = autoRotate; mUserRotation = userRotation; mCaller = caller; } } Loading
services/core/java/com/android/server/wm/DisplayRotation.java +1 −1 Original line number Diff line number Diff line Loading @@ -764,7 +764,7 @@ public class DisplayRotation { // setUserRotationSetting may be called. mService.mRoot.mDeviceStateAutoRotateSettingController .requestAccelerometerRotationSettingChange(accelerometerRotation == 1, userRotation); userRotation, caller); } else { Settings.System.putIntForUser(res, Settings.System.ACCELEROMETER_ROTATION, accelerometerRotation, UserHandle.USER_CURRENT); Loading
services/tests/wmtests/src/com/android/server/wm/DeviceStateAutoRotateSettingControllerTests.java +11 −11 Original line number Diff line number Diff line Loading @@ -212,7 +212,7 @@ public class DeviceStateAutoRotateSettingControllerTests { setDeviceState(FOLDED); mDeviceStateAutoRotateSettingController.requestAccelerometerRotationSettingChange(true, USE_CURRENT_ROTATION); USE_CURRENT_ROTATION, ""); mTestLooper.dispatchAll(); verifyAccelerometerRotationSettingSet(ACCELEROMETER_ROTATION_ON); Loading @@ -234,7 +234,7 @@ public class DeviceStateAutoRotateSettingControllerTests { setDeviceState(FOLDED); mDeviceStateAutoRotateSettingController.requestAccelerometerRotationSettingChange(true, USE_CURRENT_ROTATION); USE_CURRENT_ROTATION, ""); mTestLooper.dispatchAll(); verifyDeviceStateAutoRotateSettingSet( Loading Loading @@ -344,7 +344,7 @@ public class DeviceStateAutoRotateSettingControllerTests { @Test public void requestAccelerometerRotationChange_dSUnavailable_noSettingUpdate() { mDeviceStateAutoRotateSettingController.requestAccelerometerRotationSettingChange(true, USE_CURRENT_ROTATION); USE_CURRENT_ROTATION, ""); mTestLooper.dispatchAll(); verifyAccelerometerRotationSettingSet(ACCELEROMETER_ROTATION_OFF); Loading @@ -362,7 +362,7 @@ public class DeviceStateAutoRotateSettingControllerTests { @Test public void requestAccelerometerRotationChange_dSUnavailable_writeAfterReceivingDSUpdate() { mDeviceStateAutoRotateSettingController.requestAccelerometerRotationSettingChange(true, USE_CURRENT_ROTATION); USE_CURRENT_ROTATION, ""); mTestLooper.dispatchAll(); setDeviceState(FOLDED); Loading Loading @@ -390,7 +390,7 @@ public class DeviceStateAutoRotateSettingControllerTests { mDeviceStateAutoRotateSettingController.requestDeviceStateAutoRotateSettingChange( FOLDED.getIdentifier(), true); mDeviceStateAutoRotateSettingController.requestAccelerometerRotationSettingChange(false, USE_CURRENT_ROTATION); USE_CURRENT_ROTATION, ""); mDeviceStateAutoRotateSettingController.requestDeviceStateAutoRotateSettingChange( OPEN.getIdentifier(), true); mTestLooper.dispatchAll(); Loading @@ -404,7 +404,7 @@ public class DeviceStateAutoRotateSettingControllerTests { @Test public void dSUnavailable_sendMultipleRequests_dSAutoRotatePrecedesAfterReceivingDSUpdate() { mDeviceStateAutoRotateSettingController.requestAccelerometerRotationSettingChange(false, USE_CURRENT_ROTATION); USE_CURRENT_ROTATION, ""); mDeviceStateAutoRotateSettingController.requestDeviceStateAutoRotateSettingChange( OPEN.getIdentifier(), true); mDeviceStateAutoRotateSettingController.requestDeviceStateAutoRotateSettingChange( Loading Loading @@ -433,7 +433,7 @@ public class DeviceStateAutoRotateSettingControllerTests { setDeviceState(FOLDED); mDeviceStateAutoRotateSettingController.requestAccelerometerRotationSettingChange(true, Surface.ROTATION_90); Surface.ROTATION_90, ""); mTestLooper.dispatchAll(); verify(mMockDisplayRotation).setUserRotationSetting( Loading @@ -448,7 +448,7 @@ public class DeviceStateAutoRotateSettingControllerTests { mTestLooper.dispatchAll(); mDeviceStateAutoRotateSettingController.requestAccelerometerRotationSettingChange( false, Surface.ROTATION_180); false, Surface.ROTATION_180, ""); mTestLooper.dispatchAll(); verify(mMockDisplayRotation).setUserRotationSetting( Loading @@ -461,7 +461,7 @@ public class DeviceStateAutoRotateSettingControllerTests { mTestLooper.dispatchAll(); mDeviceStateAutoRotateSettingController.requestAccelerometerRotationSettingChange(true, USE_CURRENT_ROTATION); USE_CURRENT_ROTATION, ""); mTestLooper.dispatchAll(); verify(mMockDisplayRotation).setUserRotationSetting( Loading @@ -476,7 +476,7 @@ public class DeviceStateAutoRotateSettingControllerTests { mTestLooper.dispatchAll(); mDeviceStateAutoRotateSettingController.requestAccelerometerRotationSettingChange( false, NATURAL_ROTATION); false, NATURAL_ROTATION, ""); mTestLooper.dispatchAll(); verify(mMockDisplayRotation).setUserRotationSetting( Loading @@ -500,7 +500,7 @@ public class DeviceStateAutoRotateSettingControllerTests { setDeviceState(FOLDED); mDeviceStateAutoRotateSettingController.requestAccelerometerRotationSettingChange( false, Surface.ROTATION_90); false, Surface.ROTATION_90, ""); mTestLooper.dispatchAll(); verify(mMockDisplayRotation).setUserRotationSetting( Loading
services/tests/wmtests/src/com/android/server/wm/DisplayRotationTests.java +16 −9 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import static android.view.IWindowManager.FIXED_TO_USER_ROTATION_IF_NO_AUTO_ROTA import static com.android.dx.mockito.inline.extended.ExtendedMockito.any; import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyBoolean; import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyInt; import static com.android.dx.mockito.inline.extended.ExtendedMockito.anyString; import static com.android.dx.mockito.inline.extended.ExtendedMockito.atLeast; import static com.android.dx.mockito.inline.extended.ExtendedMockito.atMost; import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; Loading Loading @@ -248,9 +249,11 @@ public class DisplayRotationTests { freezeRotation(Surface.ROTATION_180); verify(mockDeviceStateAutoRotateSettingController, times(1)).requestAccelerometerRotationSettingChange(eq(false), eq(Surface.ROTATION_180)); verify(mockDeviceStateAutoRotateSettingController, times(1)) .requestAccelerometerRotationSettingChange( /* autoRotate= */ eq(false), /* userRotation= */ eq(Surface.ROTATION_180), /* caller= */ anyString()); } @Test Loading @@ -264,9 +267,11 @@ public class DisplayRotationTests { thawRotation(); verify(mockDeviceStateAutoRotateSettingController, times(1)).requestAccelerometerRotationSettingChange(eq(true), anyInt()); verify(mockDeviceStateAutoRotateSettingController, times(1)) .requestAccelerometerRotationSettingChange( /* autoRotate= */ eq(true), /* userRotation= */ anyInt(), /* caller= */ anyString()); } @Test Loading @@ -281,9 +286,11 @@ public class DisplayRotationTests { freezeRotation(DisplayRotation.USE_CURRENT_ROTATION); verify(mockDeviceStateAutoRotateSettingController, times(1)).requestAccelerometerRotationSettingChange(eq(false), eq(Surface.ROTATION_90)); verify(mockDeviceStateAutoRotateSettingController, times(1)) .requestAccelerometerRotationSettingChange( /* autoRotate= */ eq(false), /* userRotation= */ eq(Surface.ROTATION_90), /* caller= */ anyString()); } @Test Loading