Set default launcher orientation to portrait
Also stop OrientationTouchTransformer from
spamming logs
b/150214193 should track properly handling
this in the future
Fixes: 146176182
Test: New vertical layout showed up when
swiping to Overview w/ landscape app.
Works for both autorotate on and off.
Change-Id: I3707cf7b5693be0fcf4d63491901f4ec00793f4f
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java
index 72e6391..2942bef 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java
@@ -85,6 +85,7 @@
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Insettable;
import com.android.launcher3.InvariantDeviceProfile;
+import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherState;
import com.android.launcher3.PagedView;
import com.android.launcher3.R;
@@ -275,6 +276,9 @@
}
};
+ private RotationHelper.ForcedRotationChangedListener mForcedRotationChangedListener =
+ isForcedRotation -> RecentsView.this.disableMultipleLayoutRotations(!isForcedRotation);
+
private final PinnedStackAnimationListener mIPinnedStackAnimationListener =
new PinnedStackAnimationListener();
@@ -467,6 +471,8 @@
mIPinnedStackAnimationListener.setActivity(mActivity);
SystemUiProxy.INSTANCE.get(getContext()).setPinnedStackAnimationListener(
mIPinnedStackAnimationListener);
+ Launcher launcher = Launcher.getLauncher(getContext());
+ launcher.getRotationHelper().addForcedRotationCallback(mForcedRotationChangedListener);
}
@Override
@@ -481,6 +487,8 @@
mIdp.removeOnChangeListener(this);
SystemUiProxy.INSTANCE.get(getContext()).setPinnedStackAnimationListener(null);
mIPinnedStackAnimationListener.setActivity(null);
+ Launcher launcher = Launcher.getLauncher(getContext());
+ launcher.getRotationHelper().removeForcedRotationCallback(mForcedRotationChangedListener);
}
@Override
diff --git a/quickstep/src/com/android/quickstep/OrientationTouchTransformer.java b/quickstep/src/com/android/quickstep/OrientationTouchTransformer.java
index 832baf5..92eb036 100644
--- a/quickstep/src/com/android/quickstep/OrientationTouchTransformer.java
+++ b/quickstep/src/com/android/quickstep/OrientationTouchTransformer.java
@@ -49,7 +49,7 @@
class OrientationTouchTransformer {
private static final String TAG = "OrientationTouchTransformer";
- private static final boolean DEBUG = true;
+ private static final boolean DEBUG = false;
private static final int MAX_ORIENTATIONS = 4;
private SparseArray<OrientationRectF> mSwipeTouchRegions = new SparseArray<>(MAX_ORIENTATIONS);
diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java
index ef6bd3d..a6180a6 100644
--- a/src/com/android/launcher3/PagedView.java
+++ b/src/com/android/launcher3/PagedView.java
@@ -47,6 +47,7 @@
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.model.PagedViewOrientedState;
import com.android.launcher3.pageindicators.PageIndicator;
+import com.android.launcher3.states.RotationHelper;
import com.android.launcher3.touch.PortraitPagedViewHandler;
import com.android.launcher3.touch.OverScroll;
import com.android.launcher3.touch.PagedOrientationHandler;
diff --git a/src/com/android/launcher3/states/RotationHelper.java b/src/com/android/launcher3/states/RotationHelper.java
index b47ef72..43d54eb 100644
--- a/src/com/android/launcher3/states/RotationHelper.java
+++ b/src/com/android/launcher3/states/RotationHelper.java
@@ -17,8 +17,10 @@
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_UNSPECIFIED;
import static android.util.DisplayMetrics.DENSITY_DEVICE_STABLE;
+
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
import android.content.ContentResolver;
@@ -41,6 +43,9 @@
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.util.UiThreadHelper;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* Utility class to manage launcher rotation
*/
@@ -49,16 +54,38 @@
public static final String ALLOW_ROTATION_PREFERENCE_KEY = "pref_allowRotation";
public static final String FIXED_ROTATION_TRANSFORM_SETTING_NAME = "fixed_rotation_transform";
+ private final ContentResolver mContentResolver;
+
+ /**
+ * Listener to receive changes when {@link #FIXED_ROTATION_TRANSFORM_SETTING_NAME} flag changes.
+ */
+ public interface ForcedRotationChangedListener {
+ void onForcedRotationChanged(boolean isForcedRotation);
+ }
public static boolean getAllowRotationDefaultValue() {
- // If the device was scaled, used the original dimensions to determine if rotation
- // is allowed of not.
+ // If the device's pixel density was scaled (usually via settings for A11y), use the
+ // original dimensions to determine if rotation is allowed of not.
Resources res = Resources.getSystem();
int originalSmallestWidth = res.getConfiguration().smallestScreenWidthDp
* res.getDisplayMetrics().densityDpi / DENSITY_DEVICE_STABLE;
return originalSmallestWidth >= 600;
}
+
+ private final ContentObserver mContentObserver =
+ new ContentObserver(MAIN_EXECUTOR.getHandler()) {
+ @Override
+ public void onChange(boolean selfChange) {
+ boolean forcedRotation = Utilities.isForcedRotation(mLauncher);
+ PagedView.sFlagForcedRotation = forcedRotation;
+ updateForcedRotation();
+ for (ForcedRotationChangedListener listener : mForcedRotationChangedListeners) {
+ listener.onForcedRotationChanged(forcedRotation);
+ }
+ }
+ };
+
public static final int REQUEST_NONE = 0;
public static final int REQUEST_ROTATE = 1;
public static final int REQUEST_LOCK = 2;
@@ -68,6 +95,8 @@
private boolean mIgnoreAutoRotateSettings;
private boolean mAutoRotateEnabled;
+ private boolean mForcedRotation;
+ private List<ForcedRotationChangedListener> mForcedRotationChangedListeners = new ArrayList<>();
/**
* Rotation request made by
@@ -96,6 +125,7 @@
// On large devices we do not handle auto-rotate differently.
mIgnoreAutoRotateSettings = mLauncher.getResources().getBoolean(R.bool.allow_rotation);
+ updateForcedRotation();
if (!mIgnoreAutoRotateSettings) {
mPrefs = Utilities.getPrefs(mLauncher);
mPrefs.registerOnSharedPreferenceChangeListener(this);
@@ -106,16 +136,24 @@
}
// TODO(b/150260456) Add this in home settings as well
- final ContentResolver resolver = launcher.getContentResolver();
- final ContentObserver observer = new ContentObserver(MAIN_EXECUTOR.getHandler()) {
- @Override
- public void onChange(boolean selfChange) {
- PagedView.sFlagForcedRotation = Utilities.isForcedRotation(mLauncher);
- }
- };
- resolver.registerContentObserver(Settings.Global.getUriFor(
- FIXED_ROTATION_TRANSFORM_SETTING_NAME),
- false, observer);
+ mContentResolver = launcher.getContentResolver();
+ mContentResolver.registerContentObserver(Settings.Global.getUriFor(
+ FIXED_ROTATION_TRANSFORM_SETTING_NAME), false, mContentObserver);
+ }
+
+ private void updateForcedRotation() {
+ mForcedRotation = !getAllowRotationDefaultValue() && Utilities.isForcedRotation(mLauncher);
+ }
+
+ /**
+ * will not be called when first registering the listener.
+ */
+ public void addForcedRotationCallback(ForcedRotationChangedListener listener) {
+ mForcedRotationChangedListeners.add(listener);
+ }
+
+ public void removeForcedRotationCallback(ForcedRotationChangedListener listener) {
+ mForcedRotationChangedListeners.remove(listener);
}
public void setRotationHadDifferentUI(boolean rotationHasDifferentUI) {
@@ -197,6 +235,10 @@
if (mPrefs != null) {
mPrefs.unregisterOnSharedPreferenceChangeListener(this);
}
+ if (mContentResolver != null) {
+ mContentResolver.unregisterContentObserver(mContentObserver);
+ }
+ mForcedRotationChangedListeners.clear();
}
}
@@ -206,7 +248,10 @@
}
final int activityFlags;
- if (mStateHandlerRequest != REQUEST_NONE) {
+ if (mForcedRotation) {
+ // TODO(b/150214193) Properly address this
+ activityFlags = SCREEN_ORIENTATION_PORTRAIT;
+ } else if (mStateHandlerRequest != REQUEST_NONE) {
activityFlags = mStateHandlerRequest == REQUEST_LOCK ?
SCREEN_ORIENTATION_LOCKED : SCREEN_ORIENTATION_UNSPECIFIED;
} else if (mCurrentTransitionRequest != REQUEST_NONE) {