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

Commit f8ce30e2 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix auto-rotate suggestion button for immersive mode" into main

parents 94ec75e3 cc9b7b6a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -390,7 +390,7 @@ interface IWindowManager
    /**
    * Sets display rotation to {@link rotation} if auto-rotate is OFF.
    */
    void setRotationAtAngleIfLocked(int rotation, String caller);
    void setRotationAtAngleIfAllowed(int rotation, String caller);

    /**
     * Lock the display orientation to the specified rotation, or to the current
+2 −2
Original line number Diff line number Diff line
@@ -144,13 +144,13 @@ public final class RotationPolicy {
     * Sets screen rotation to {@link rotation} if the value of {@link ACCELEROMETER_ROTATION} is
     * false.
     */
    public static void setRotationAtAngleIfLocked(final int rotation, String caller) {
    public static void setRotationAtAngleIfAllowed(final int rotation, String caller) {
        AsyncTask.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    IWindowManager wm = WindowManagerGlobal.getWindowManagerService();
                    wm.setRotationAtAngleIfLocked(rotation, caller);
                    wm.setRotationAtAngleIfAllowed(rotation, caller);
                } catch (RemoteException exc) {
                    Log.w(TAG, "Unable to set rotation to:" + rotation);
                }
+28 −2
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@
package com.android.systemui.shared.rotation;

import static android.content.pm.PackageManager.FEATURE_PC;
import static android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_INNER_PRIMARY;
import static android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_OUTER_PRIMARY;
import static android.view.Display.DEFAULT_DISPLAY;

import static com.android.internal.view.RotationPolicy.NATURAL_ROTATION;
@@ -36,6 +38,8 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.drawable.AnimatedVectorDrawable;
import android.graphics.drawable.Drawable;
import android.hardware.devicestate.DeviceState;
import android.hardware.devicestate.DeviceStateManager;
import android.os.Handler;
import android.os.Looper;
import android.os.RemoteException;
@@ -70,6 +74,7 @@ import com.android.systemui.shared.system.TaskStackChangeListeners;
import com.android.window.flags.Flags;

import java.io.PrintWriter;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
@@ -308,8 +313,8 @@ public class RotationButtonController {
            // Ignore if we can't read the setting for the current user
            return;
        }
        if (Flags.enableDeviceStateAutoRotateSettingRefactor()) {
            RotationPolicy.setRotationAtAngleIfLocked(rotationSuggestion, caller);
        if (isFoldable() && Flags.enableDeviceStateAutoRotateSettingRefactor()) {
            RotationPolicy.setRotationAtAngleIfAllowed(rotationSuggestion, caller);
            return;
        }

@@ -701,6 +706,27 @@ public class RotationButtonController {
        }
    }

    private boolean isFoldable() {
        if (android.hardware.devicestate.feature.flags.Flags.deviceStatePropertyMigration()) {
            final DeviceStateManager deviceStateManager = mContext.getSystemService(
                    DeviceStateManager.class);
            if (deviceStateManager == null) return false;
            List<DeviceState> deviceStates = deviceStateManager.getSupportedDeviceStates();
            for (int i = 0; i < deviceStates.size(); i++) {
                DeviceState state = deviceStates.get(i);
                if (state.hasProperty(PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_OUTER_PRIMARY)
                        || state.hasProperty(
                        PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_INNER_PRIMARY)) {
                    return true;
                }
            }
            return false;
        } else {
            return mContext.getResources().getIntArray(
                    com.android.internal.R.array.config_foldedDeviceStates).length != 0;
        }
    }

    private class TaskStackListenerImpl implements TaskStackChangeListener {
        // Invalidate any rotation suggestion on task change or activity orientation change
        // Note: all callbacks happen on main thread
+4 −4
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ import javax.inject.Inject
interface RotationPolicyWrapper {
    fun setRotationLock(enabled: Boolean, caller: String)
    fun setRotationLockAtAngle(enabled: Boolean, rotation: Int, caller: String)
    fun setRotationAtAngleIfLocked(rotation: Int, caller: String)
    fun setRotationAtAngleIfAllowed(rotation: Int, caller: String)
    fun getRotationLockOrientation(): Int
    fun isRotationLockToggleVisible(): Boolean
    fun isRotationLocked(): Boolean
@@ -58,9 +58,9 @@ class RotationPolicyWrapperImpl @Inject constructor(
    /**
     * Sets screen rotation to [rotation] if the value of [ACCELEROMETER_ROTATION] is false.
     */
    override fun setRotationAtAngleIfLocked(rotation: Int, caller: String) {
        traceSection("RotationPolicyWrapperImpl#setRotationAtAngleIfLocked") {
            RotationPolicy.setRotationAtAngleIfLocked(rotation, caller)
    override fun setRotationAtAngleIfAllowed(rotation: Int, caller: String) {
        traceSection("RotationPolicyWrapperImpl#setRotationAtAngleIfAllowed") {
            RotationPolicy.setRotationAtAngleIfAllowed(rotation, caller)
        }
    }

+1 −1
Original line number Diff line number Diff line
@@ -393,7 +393,7 @@ public class DeviceStateRotationLockSettingControllerTest extends SysuiTestCase
        }

        @Override
        public void setRotationAtAngleIfLocked(int rotation, String caller) {
        public void setRotationAtAngleIfAllowed(int rotation, String caller) {
            throw new AssertionError("Not implemented");
        }

Loading