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

Commit 6bca0c3e authored by Mariia Sandrikova's avatar Mariia Sandrikova Committed by Automerger Merge Worker
Browse files

Merge "Support respecting nosensor and locked when docked." into tm-qpr-dev am: 088907e9

parents c3277665 088907e9
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -755,6 +755,11 @@
         we rely on gravity to determine the effective orientation. -->
    <bool name="config_deskDockEnablesAccelerometer">true</bool>

    <!-- Control whether nosensor and locked orientation requests are respected from the app when
         config_deskDockEnablesAccelerometer is set to false.
         TODO(b/274763533): Consider making true by default and removing this. -->
    <bool name="config_deskRespectsNoSensorAndLockedWithoutAccelerometer">false</bool>

    <!-- Car dock behavior -->

    <!-- The number of degrees to rotate the display when the device is in a car dock.
+1 −0
Original line number Diff line number Diff line
@@ -1732,6 +1732,7 @@
  <java-symbol type="bool" name="config_carDockEnablesAccelerometer" />
  <java-symbol type="bool" name="config_customUserSwitchUi" />
  <java-symbol type="bool" name="config_deskDockEnablesAccelerometer" />
  <java-symbol type="bool" name="config_deskRespectsNoSensorAndLockedWithoutAccelerometer" />
  <java-symbol type="bool" name="config_disableMenuKeyInLockScreen" />
  <java-symbol type="bool" name="config_enableCarDockHomeLaunch" />
  <java-symbol type="bool" name="config_enableLockBeforeUnlockScreen" />
+9 −0
Original line number Diff line number Diff line
@@ -200,6 +200,7 @@ public class DisplayPolicy {

    private final boolean mCarDockEnablesAccelerometer;
    private final boolean mDeskDockEnablesAccelerometer;
    private final boolean mDeskDockRespectsNoSensorAndLockedWithoutAccelerometer;
    private final AccessibilityManager mAccessibilityManager;
    private final ImmersiveModeConfirmation mImmersiveModeConfirmation;
    private final ScreenshotHelper mScreenshotHelper;
@@ -435,6 +436,8 @@ public class DisplayPolicy {
        final Resources r = mContext.getResources();
        mCarDockEnablesAccelerometer = r.getBoolean(R.bool.config_carDockEnablesAccelerometer);
        mDeskDockEnablesAccelerometer = r.getBoolean(R.bool.config_deskDockEnablesAccelerometer);
        mDeskDockRespectsNoSensorAndLockedWithoutAccelerometer =
                r.getBoolean(R.bool.config_deskRespectsNoSensorAndLockedWithoutAccelerometer);
        mCanSystemBarsBeShownByUser = !r.getBoolean(
                R.bool.config_remoteInsetsControllerControlsSystemBars) || r.getBoolean(
                R.bool.config_remoteInsetsControllerSystemBarsCanBeShownByUserAction);
@@ -755,6 +758,10 @@ public class DisplayPolicy {
        return mDeskDockEnablesAccelerometer;
    }

    boolean isDeskDockRespectsNoSensorAndLockedWithoutAccelerometer() {
        return mDeskDockRespectsNoSensorAndLockedWithoutAccelerometer;
    }

    public void setPersistentVrModeEnabled(boolean persistentVrModeEnabled) {
        mPersistentVrModeEnabled = persistentVrModeEnabled;
    }
@@ -2662,6 +2669,8 @@ public class DisplayPolicy {
        pw.print("mCarDockEnablesAccelerometer="); pw.print(mCarDockEnablesAccelerometer);
        pw.print(" mDeskDockEnablesAccelerometer=");
        pw.println(mDeskDockEnablesAccelerometer);
        pw.print(" mDeskDockRespectsNoSensorAndLockedWithoutAccelerometer=");
        pw.println(mDeskDockRespectsNoSensorAndLockedWithoutAccelerometer);
        pw.print(prefix); pw.print("mDockMode="); pw.print(Intent.dockStateToString(mDockMode));
        pw.print(" mLidState="); pw.println(WindowManagerFuncs.lidStateToString(mLidState));
        pw.print(prefix); pw.print("mAwake="); pw.print(mAwake);
+6 −1
Original line number Diff line number Diff line
@@ -1170,6 +1170,10 @@ public class DisplayRotation {
                mDisplayPolicy.isCarDockEnablesAccelerometer();
        final boolean deskDockEnablesAccelerometer =
                mDisplayPolicy.isDeskDockEnablesAccelerometer();
        final boolean deskDockRespectsNoSensorAndLockedWithoutAccelerometer =
                mDisplayPolicy.isDeskDockRespectsNoSensorAndLockedWithoutAccelerometer()
                        && (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED
                                || orientation == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);

        final int preferredRotation;
        if (!isDefaultDisplay) {
@@ -1188,7 +1192,8 @@ public class DisplayRotation {
        } else if ((dockMode == Intent.EXTRA_DOCK_STATE_DESK
                || dockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
                || dockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
                && (deskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
                && (deskDockEnablesAccelerometer || mDeskDockRotation >= 0)
                && !deskDockRespectsNoSensorAndLockedWithoutAccelerometer) {
            // Ignore sensor when in desk dock unless explicitly enabled.
            // This case can override the behavior of NOSENSOR, and can also
            // enable 180 degree rotation while docked.
+19 −0
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@
package com.android.server.wm;

import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LOCKED;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
@@ -823,6 +825,23 @@ public class DisplayRotationTests {
                SCREEN_ORIENTATION_UNSPECIFIED, Surface.ROTATION_90));
    }

    @Test
    public void testIgnoresDeskDockRotation_whenNoSensorAndLockedRespected() throws Exception {
        mBuilder.setDeskDockRotation(Surface.ROTATION_270).build();
        when(mMockDisplayPolicy.isDeskDockRespectsNoSensorAndLockedWithoutAccelerometer())
                .thenReturn(true);
        configureDisplayRotation(SCREEN_ORIENTATION_LANDSCAPE, false, false);

        when(mMockDisplayPolicy.getDockMode()).thenReturn(Intent.EXTRA_DOCK_STATE_DESK);

        freezeRotation(Surface.ROTATION_90);

        assertEquals(Surface.ROTATION_90, mTarget.rotationForOrientation(
                SCREEN_ORIENTATION_LOCKED, Surface.ROTATION_90));
        assertEquals(Surface.ROTATION_0, mTarget.rotationForOrientation(
                SCREEN_ORIENTATION_NOSENSOR, Surface.ROTATION_90));
    }

    @Test
    public void testReturnsUserRotation_FixedToUserRotation_IgnoreIncompatibleAppRequest()
            throws Exception {