Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ef02f288 authored by Shivangi Dubey's avatar Shivangi Dubey
Browse files

Fix caller string being logged in DisplayRotation

Currently caller string that are being passed through DeviceStateAutoRotateSettingController are being overwritten.
Make sure to perserved original caller string.

Follow-up CL: ag/34033575
Fixes: 427467224
Test: Build and dumpsys to check correct callers are logged
Flag: EXEMPT DEBUG

Change-Id: I585607d239bc73b28103511cf53acaef99bf8b3e
parent a0a7b4a6
Loading
Loading
Loading
Loading
+13 −5
Original line number Diff line number Diff line
@@ -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() {
@@ -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.
@@ -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);
        }
    }

@@ -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;
            }
        }

+1 −1
Original line number Diff line number Diff line
@@ -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);
+11 −11
Original line number Diff line number Diff line
@@ -212,7 +212,7 @@ public class DeviceStateAutoRotateSettingControllerTests {
        setDeviceState(FOLDED);

        mDeviceStateAutoRotateSettingController.requestAccelerometerRotationSettingChange(true,
                USE_CURRENT_ROTATION);
                USE_CURRENT_ROTATION, "");
        mTestLooper.dispatchAll();

        verifyAccelerometerRotationSettingSet(ACCELEROMETER_ROTATION_ON);
@@ -234,7 +234,7 @@ public class DeviceStateAutoRotateSettingControllerTests {
        setDeviceState(FOLDED);

        mDeviceStateAutoRotateSettingController.requestAccelerometerRotationSettingChange(true,
                USE_CURRENT_ROTATION);
                USE_CURRENT_ROTATION, "");
        mTestLooper.dispatchAll();

        verifyDeviceStateAutoRotateSettingSet(
@@ -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);
@@ -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);
@@ -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();
@@ -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(
@@ -433,7 +433,7 @@ public class DeviceStateAutoRotateSettingControllerTests {
        setDeviceState(FOLDED);

        mDeviceStateAutoRotateSettingController.requestAccelerometerRotationSettingChange(true,
                Surface.ROTATION_90);
                Surface.ROTATION_90, "");
        mTestLooper.dispatchAll();

        verify(mMockDisplayRotation).setUserRotationSetting(
@@ -448,7 +448,7 @@ public class DeviceStateAutoRotateSettingControllerTests {
        mTestLooper.dispatchAll();

        mDeviceStateAutoRotateSettingController.requestAccelerometerRotationSettingChange(
                false, Surface.ROTATION_180);
                false, Surface.ROTATION_180, "");
        mTestLooper.dispatchAll();

        verify(mMockDisplayRotation).setUserRotationSetting(
@@ -461,7 +461,7 @@ public class DeviceStateAutoRotateSettingControllerTests {
        mTestLooper.dispatchAll();

        mDeviceStateAutoRotateSettingController.requestAccelerometerRotationSettingChange(true,
                USE_CURRENT_ROTATION);
                USE_CURRENT_ROTATION, "");
        mTestLooper.dispatchAll();

        verify(mMockDisplayRotation).setUserRotationSetting(
@@ -476,7 +476,7 @@ public class DeviceStateAutoRotateSettingControllerTests {
        mTestLooper.dispatchAll();

        mDeviceStateAutoRotateSettingController.requestAccelerometerRotationSettingChange(
                false, NATURAL_ROTATION);
                false, NATURAL_ROTATION, "");
        mTestLooper.dispatchAll();

        verify(mMockDisplayRotation).setUserRotationSetting(
@@ -500,7 +500,7 @@ public class DeviceStateAutoRotateSettingControllerTests {
        setDeviceState(FOLDED);

        mDeviceStateAutoRotateSettingController.requestAccelerometerRotationSettingChange(
                false, Surface.ROTATION_90);
                false, Surface.ROTATION_90, "");
        mTestLooper.dispatchAll();

        verify(mMockDisplayRotation).setUserRotationSetting(
+16 −9
Original line number Diff line number Diff line
@@ -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;
@@ -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
@@ -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
@@ -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