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

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

Create an IPC for requesting change to device state auto rotate setting

This IPC is intended to but not limited to be used from Settings process.

Fixes: 402764691
Flag: com.android.window.flags.enable_device_state_auto_rotate_setting_refactor
Test: Put logs in server side and call IPC from settings process, check if the logs prints
Change-Id: Ifc3278d064b3ba902dea6e9c30cedcbb8113bae7
parent 34eaed1a
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -341,6 +341,12 @@ interface IWindowManager
     */
    int getPreferredOptionsPanelGravity(int displayId);

    /**
     * Requests to update value of setting key {@link Settings.Secure#DEVICE_STATE_ROTATION_LOCK} to
     * {@link autoRotate} for {@link deviceState}.
     */
    oneway void setDeviceStateAutoRotateSetting(int deviceState, boolean autoRotate);

    /**
     * Equivalent to calling {@link #freezeDisplayRotation(int, int)} with {@link
     * android.view.Display#DEFAULT_DISPLAY} and given rotation.
+14 −0
Original line number Diff line number Diff line
@@ -94,6 +94,20 @@ public final class RotationPolicy {
                        UserHandle.USER_CURRENT) == 0;
    }

    /**
     * Requests to update value of setting key {@link Settings.Secure.DEVICE_STATE_ROTATION_LOCK} to
     * {@link autoRotate} for {@link deviceState}.
     */
    public static void requestDeviceStateAutoRotateSettingChange(int deviceState,
            boolean autoRotate) {
        try {
            IWindowManager wm = WindowManagerGlobal.getWindowManagerService();
            wm.setDeviceStateAutoRotateSetting(deviceState, autoRotate);
        } catch (RemoteException exc) {
            Log.w(TAG, "Unable to save device state auto-rotate setting: " + exc.getMessage());
        }
    }

    /**
     * Returns true if rotation lock is enabled.
     */
+4 −0
Original line number Diff line number Diff line
@@ -792,6 +792,10 @@ public class DisplayRotation {
        }
    }

    void requestDeviceStateAutoRotateSettingChange(int deviceState, boolean autoRotate) {
        // TODO(b/350946537) Redirect request to DeviceStateAutoRotateSettingController
    }

    void freezeRotation(int rotation, String caller) {
        if (mDeviceStateController.shouldReverseRotationDirectionAroundZAxis(mDisplayContent)) {
            rotation = RotationUtils.reverseRotationDirectionAroundZAxis(rotation);
+17 −0
Original line number Diff line number Diff line
@@ -155,6 +155,7 @@ import static com.android.server.wm.WindowManagerServiceDumpProto.INPUT_METHOD_W
import static com.android.server.wm.WindowManagerServiceDumpProto.POLICY;
import static com.android.server.wm.WindowManagerServiceDumpProto.ROOT_WINDOW_CONTAINER;
import static com.android.server.wm.WindowManagerServiceDumpProto.WINDOW_FRAMES_VALID;
import static com.android.window.flags.Flags.enableDeviceStateAutoRotateSettingRefactor;
import static com.android.window.flags.Flags.enableDisplayFocusInShellTransitions;
import static com.android.window.flags.Flags.enablePresentationForConnectedDisplays;
import static com.android.window.flags.Flags.multiCrop;
@@ -4468,6 +4469,22 @@ public class WindowManagerService extends IWindowManager.Stub
                || !mAppCompatConfiguration.isIgnoreOrientationRequestAllowed();
    }

    @Override
    public void setDeviceStateAutoRotateSetting(int deviceState, boolean autoRotate) {
        if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
                "setDeviceStateAutoRotateSetting()")) {
            throw new SecurityException("Requires SET_ORIENTATION permission");
        }
        if (!enableDeviceStateAutoRotateSettingRefactor()) {
            return;
        }
        synchronized (mGlobalLock) {
            final DisplayContent display = mRoot.getDefaultDisplay();
            display.getDisplayRotation().requestDeviceStateAutoRotateSettingChange(deviceState,
                    autoRotate);
        }
    }

    @Override
    public void freezeRotation(int rotation, String caller) {
        freezeDisplayRotation(Display.DEFAULT_DISPLAY, rotation, caller);