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

Commit c7200e18 authored by Jamie Garside's avatar Jamie Garside
Browse files

Add ability to rotate screen in AoD.

This patch prevents DisplayRotation from disabling the
OrientationListener when the screen turns off, if and only if the
underlying sensor is a wakeup device_orientation sensor (i.e. we don't
have to keep the AP on to keep listening). This then allows the AoD on
the device to rotate.

Since many devices doesn't have a wake orienation sensor, a config flag is
provided to force this behaviour on (although note that the AoD might
not rotate if the AP shuts down). This can be enabled by setting
config_forceOrientationListenerEnabledWhileDreaming to true.

Test: Not yet, finding tests...
Change-Id: Ie1ee8e297ebe9a8a73793d07f173bada8e0699f1
parent 99801ee1
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -4610,4 +4610,9 @@
         If omitted, image editing will not be offered via Chooser.
         This name is in the ComponentName flattened format (package/class) [DO NOT TRANSLATE]  -->
    <string name="config_systemImageEditor" translatable="false"></string>

    <!-- Whether to force WindowOrientationListener to keep listening to its sensor, even when
         dreaming. This allows the AoD to rotate on devices without a wake device_orientation
         sensor. Note that this flag should only be enabled for development/testing use. -->
    <bool name="config_forceOrientationListenerEnabledWhileDreaming">false</bool>
</resources>
+2 −0
Original line number Diff line number Diff line
@@ -4146,4 +4146,6 @@
  <java-symbol type="bool" name="config_attachNavBarToAppDuringTransition" />

  <java-symbol type="bool" name="config_enableBackSound" />

  <java-symbol type="bool" name="config_forceOrientationListenerEnabledWhileDreaming" />
</resources>
+15 −0
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ public abstract class WindowOrientationListener {
    private Sensor mSensor;
    private OrientationJudge mOrientationJudge;
    private int mCurrentRotation = -1;
    private final Context mContext;

    private final Object mLock = new Object();

@@ -88,6 +89,7 @@ public abstract class WindowOrientationListener {
     * This constructor is private since no one uses it.
     */
    private WindowOrientationListener(Context context, Handler handler, int rate) {
        mContext = context;
        mHandler = handler;
        mSensorManager = (SensorManager)context.getSystemService(Context.SENSOR_SERVICE);
        mRate = rate;
@@ -284,6 +286,19 @@ public abstract class WindowOrientationListener {
        }
    }

    /**
     * Returns whether this WindowOrientationListener can remain enabled while the device is dozing.
     * If this returns true, it implies that the underlying sensor can still run while the AP is
     * asleep, and that the underlying sensor will wake the AP on an event.
     */
    public boolean shouldStayEnabledWhileDreaming() {
        if (mContext.getResources().getBoolean(
                com.android.internal.R.bool.config_forceOrientationListenerEnabledWhileDreaming)) {
            return true;
        }
        return mSensor.getType() == Sensor.TYPE_DEVICE_ORIENTATION && mSensor.isWakeUpSensor();
    }

    abstract class OrientationJudge implements SensorEventListener {
        // Number of nanoseconds per millisecond.
        protected static final long NANOS_PER_MS = 1000000;
+8 −2
Original line number Diff line number Diff line
@@ -955,10 +955,16 @@ public class DisplayRotation {
                keyguardDrawComplete, windowManagerDrawComplete);

        boolean disable = true;

        // If the orientation listener uses a wake sensor, keep the orientation listener on if the
        // screen is on (regardless of wake state). This allows the AoD to rotate.
        //
        // Note: We postpone the rotating of the screen until the keyguard as well as the
        // window manager have reported a draw complete or the keyguard is going away in dismiss
        // mode.
        if (screenOnEarly && awake && ((keyguardDrawComplete && windowManagerDrawComplete))) {
        if (screenOnEarly
                && (awake || mOrientationListener.shouldStayEnabledWhileDreaming())
                && ((keyguardDrawComplete && windowManagerDrawComplete))) {
            if (needSensorRunning()) {
                disable = false;
                // Enable listener if not already enabled.
@@ -974,7 +980,7 @@ public class DisplayRotation {
            }
        }
        // Check if sensors need to be disabled.
        if (disable && mOrientationListener.mEnabled) {
        if (disable) {
            mOrientationListener.disable();
        }
    }