Infer launcher rotation when initializing RecentsOrientedState

fixes: 154776599
Change-Id: I9b95f7f96836a974be0fd1236547efb4b405fda5
This commit is contained in:
Vinit Nayak committed 2020-05-11 11:23:49 -07:00
1 parent 144f638fa3
commit b9522d334a
5 files changed
+87 -59

No files matched your search

@@ -23,6 +23,7 @@ import static android.view.Surface.ROTATION_180;
import static android.view.Surface.ROTATION_270;
import static android.view.Surface.ROTATION_90;
import static com.android.launcher3.logging.LoggerUtils.extractObjectNameAndAddress;
import static com.android.launcher3.states.RotationHelper.ALLOW_ROTATION_PREFERENCE_KEY;
import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
@@ -84,7 +85,7 @@ public final class RecentsOrientedState implements SharedPreferences.OnSharedPre
private @SurfaceRotation int mTouchRotation = ROTATION_0;
private @SurfaceRotation int mDisplayRotation = ROTATION_0;
private @SurfaceRotation int mLauncherRotation = Surface.ROTATION_0;
private @SurfaceRotation int mLauncherRotation = ROTATION_0;
// Launcher activity supports multiple orientation, but fallback activity does not
private static final int FLAG_MULTIPLE_ORIENTATION_SUPPORTED_BY_ACTIVITY = 1 << 0;
@@ -102,6 +103,8 @@ public final class RecentsOrientedState implements SharedPreferences.OnSharedPre
private static final int FLAG_ROTATION_WATCHER_SUPPORTED = 1 << 6;
// Whether to enable rotation watcher when multi-rotation is supported
private static final int FLAG_ROTATION_WATCHER_ENABLED = 1 << 7;
// Enable home rotation for UI tests, ignoring home rotation value from prefs
private static final int FLAG_HOME_ROTATION_FORCE_ENABLED_FOR_TESTING = 1 << 8;
private static final int MASK_MULTIPLE_ORIENTATION_SUPPORTED_BY_DEVICE =
FLAG_MULTIPLE_ORIENTATION_SUPPORTED_BY_ACTIVITY
@@ -163,6 +166,10 @@ public final class RecentsOrientedState implements SharedPreferences.OnSharedPre
if (mOrientationListener.canDetectOrientation()) {
mFlags |= FLAG_ROTATION_WATCHER_SUPPORTED;
}
// initialize external flags
updateAutoRotateSetting();
updateHomeRotationSetting();
}
/**
@@ -181,13 +188,15 @@ public final class RecentsOrientedState implements SharedPreferences.OnSharedPre
* false otherwise
*/
public boolean update(
@SurfaceRotation int touchRotation, @SurfaceRotation int displayRotation,
@SurfaceRotation int launcherRotation) {
@SurfaceRotation int touchRotation, @SurfaceRotation int displayRotation) {
if (!isMultipleOrientationSupportedByDevice()) {
return false;
}
if (mDisplayRotation == displayRotation && mTouchRotation == touchRotation
&& launcherRotation == mLauncherRotation) {
int launcherRotation = inferLauncherRotation(displayRotation);
if (mDisplayRotation == displayRotation
&& mTouchRotation == touchRotation
&& mLauncherRotation == launcherRotation) {
return false;
}
@@ -195,11 +204,10 @@ public final class RecentsOrientedState implements SharedPreferences.OnSharedPre
mDisplayRotation = displayRotation;
mTouchRotation = touchRotation;
if (canLauncherRotate() || mLauncherRotation == mTouchRotation) {
// TODO(b/153476489) Need to determine when launcher is rotated
if (mLauncherRotation == mTouchRotation) {
mOrientationHandler = PagedOrientationHandler.HOME_ROTATED;
if (DEBUG) {
Log.d(TAG, "Set Orientation Handler: " + mOrientationHandler);
Log.d(TAG, "current RecentsOrientedState: " + this);
}
return true;
}
@@ -212,11 +220,20 @@ public final class RecentsOrientedState implements SharedPreferences.OnSharedPre
mOrientationHandler = PagedOrientationHandler.PORTRAIT;
}
if (DEBUG) {
Log.d(TAG, "Set Orientation Handler: " + mOrientationHandler);
Log.d(TAG, "current RecentsOrientedState: " + this);
}
return true;
}
@SurfaceRotation
private int inferLauncherRotation(@SurfaceRotation int displayRotation) {
if (!isMultipleOrientationSupportedByDevice() || isHomeRotationAllowed()) {
return displayRotation;
} else {
return ROTATION_0;
}
}
private void setFlag(int mask, boolean enabled) {
boolean wasRotationEnabled = !TestProtocol.sDisableSensorRotation
&& mFlags == VALUE_ROTATION_WATCHER_ENABLED;
@@ -241,7 +258,9 @@ public final class RecentsOrientedState implements SharedPreferences.OnSharedPre
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
updateHomeRotationSetting();
if (ALLOW_ROTATION_PREFERENCE_KEY.equals(s)) {
updateHomeRotationSetting();
}
}
private void updateAutoRotateSetting() {
@@ -255,23 +274,24 @@ public final class RecentsOrientedState implements SharedPreferences.OnSharedPre
}
/**
* Initializes aany system values and registers corresponding change listeners. It must be
* paired with {@link #destroy()} call
* Initializes any system values and registers corresponding change listeners. It must be
* paired with {@link #destroyListeners()} call
*/
public void init() {
public void initListeners() {
if (isMultipleOrientationSupportedByDevice()) {
mSharedPrefs.registerOnSharedPreferenceChangeListener(this);
mContentResolver.registerContentObserver(
Settings.System.getUriFor(Settings.System.ACCELEROMETER_ROTATION),
false, mSystemAutoRotateObserver);
}
initWithoutListeners();
updateAutoRotateSetting();
updateHomeRotationSetting();
}
/**
* Unregisters any previously registered listeners.
*/
public void destroy() {
public void destroyListeners() {
if (isMultipleOrientationSupportedByDevice()) {
mSharedPrefs.unregisterOnSharedPreferenceChangeListener(this);
mContentResolver.unregisterContentObserver(mSystemAutoRotateObserver);
@@ -279,13 +299,8 @@ public final class RecentsOrientedState implements SharedPreferences.OnSharedPre
setRotationWatcherEnabled(false);
}
/**
* Initializes the OrientationState without attaching any listeners. This can be used when
* the object is short lived.
*/
public void initWithoutListeners() {
updateAutoRotateSetting();
updateHomeRotationSetting();
public void forceAllowRotationForTesting(boolean forceAllow) {
setFlag(FLAG_HOME_ROTATION_FORCE_ENABLED_FOR_TESTING, forceAllow);
}
@SurfaceRotation
@@ -310,7 +325,8 @@ public final class RecentsOrientedState implements SharedPreferences.OnSharedPre
public boolean isHomeRotationAllowed() {
return (mFlags & (FLAG_HOME_ROTATION_ALLOWED_IN_PREFS | FLAG_MULTIWINDOW_ROTATION_ALLOWED))
!= 0;
!= 0 ||
(mFlags & FLAG_HOME_ROTATION_FORCE_ENABLED_FOR_TESTING) != 0;
}
public boolean canLauncherRotate() {
@@ -440,9 +456,13 @@ public final class RecentsOrientedState implements SharedPreferences.OnSharedPre
if (degrees < (90 - threshold)) {
return ROTATION_0;
}
if (degrees > (90 + threshold)) {
if (degrees > (90 + threshold) && degrees < 180) {
return ROTATION_180;
}
// flip from seascape to landscape
if (degrees > (180 + threshold) && degrees < 360) {
return ROTATION_90;
}
break;
case ROTATION_180:
if (degrees < (180 - threshold)) {
@@ -453,12 +473,16 @@ public final class RecentsOrientedState implements SharedPreferences.OnSharedPre
}
break;
case ROTATION_90:
if (degrees < (270 - threshold)) {
if (degrees < (270 - threshold) && degrees > 90) {
return ROTATION_180;
}
if (degrees > (270 + threshold)) {
if (degrees > (270 + threshold) && degrees < 360) {
return ROTATION_0;
}
// flip from landscape to seascape
if (degrees > threshold && degrees < 180) {
return ROTATION_270;
}
break;
}
@@ -506,13 +530,15 @@ public final class RecentsOrientedState implements SharedPreferences.OnSharedPre
public String toString() {
boolean systemRotationOn = (mFlags & FLAG_SYSTEM_ROTATION_ALLOWED) != 0;
return "["
+ "mDisplayRotation=" + mDisplayRotation
+ "this=" + extractObjectNameAndAddress(super.toString())
+ " mOrientationHandler=" +
extractObjectNameAndAddress(mOrientationHandler.toString())
+ " mDisplayRotation=" + mDisplayRotation
+ " mTouchRotation=" + mTouchRotation
+ " mLauncherRotation=" + mLauncherRotation
+ " mHomeRotation=" + isHomeRotationAllowed()
+ " mSystemRotation=" + systemRotationOn
+ " mFlags=" + mFlags
+ " mOrientationHandler=" + mOrientationHandler
+ "]";
}
}