Merge "Fix One-handed mode truncated screen when device rotates in multiple user mode" into sc-v2-dev am: 94ec7e0d2a am: f8adb4fe4f

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15838387

Change-Id: Iffff0af0c9521eb8d6b632dde38284d1bba09a71
This commit is contained in:
Jason Chang
2021-09-28 00:33:28 +00:00
committed by Automerger Merge Worker
3 changed files with 78 additions and 29 deletions

View File

@@ -43,6 +43,7 @@ import android.util.Slog;
import android.view.Surface;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityManager;
import android.window.WindowContainerTransaction;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -64,7 +65,8 @@ import java.io.PrintWriter;
/**
* Manages and manipulates the one handed states, transitions, and gesture for phones.
*/
public class OneHandedController implements RemoteCallable<OneHandedController> {
public class OneHandedController implements RemoteCallable<OneHandedController>,
DisplayChangeController.OnDisplayChangingListener {
private static final String TAG = "OneHandedController";
private static final String ONE_HANDED_MODE_OFFSET_PERCENTAGE =
@@ -106,19 +108,6 @@ public class OneHandedController implements RemoteCallable<OneHandedController>
private OneHandedBackgroundPanelOrganizer mBackgroundPanelOrganizer;
private OneHandedUiEventLogger mOneHandedUiEventLogger;
/**
* Handle rotation based on OnDisplayChangingListener callback
*/
private final DisplayChangeController.OnDisplayChangingListener mRotationController =
(display, fromRotation, toRotation, wct) -> {
if (!isInitialized()) {
return;
}
mDisplayAreaOrganizer.onRotateDisplay(mContext, toRotation, wct);
mOneHandedUiEventLogger.writeEvent(
OneHandedUiEventLogger.EVENT_ONE_HANDED_TRIGGER_ROTATION_OUT);
};
private final DisplayController.OnDisplaysChangedListener mDisplaysChangedListener =
new DisplayController.OnDisplaysChangedListener() {
@Override
@@ -296,7 +285,7 @@ public class OneHandedController implements RemoteCallable<OneHandedController>
getObserver(this::onSwipeToNotificationEnabledChanged);
mShortcutEnabledObserver = getObserver(this::onShortcutEnabledChanged);
mDisplayController.addDisplayChangingController(mRotationController);
mDisplayController.addDisplayChangingController(this);
setupCallback();
registerSettingObservers(mUserId);
setupTimeoutListener();
@@ -744,6 +733,27 @@ public class OneHandedController implements RemoteCallable<OneHandedController>
}
}
/**
* Handles rotation based on OnDisplayChangingListener callback
*/
@Override
public void onRotateDisplay(int displayId, int fromRotation, int toRotation,
WindowContainerTransaction wct) {
if (!isInitialized()) {
return;
}
if (!mOneHandedSettingsUtil.getSettingsOneHandedModeEnabled(mContext.getContentResolver(),
mUserId) || mOneHandedSettingsUtil.getSettingsSwipeToNotificationEnabled(
mContext.getContentResolver(), mUserId)) {
return;
}
mDisplayAreaOrganizer.onRotateDisplay(mContext, toRotation, wct);
mOneHandedUiEventLogger.writeEvent(
OneHandedUiEventLogger.EVENT_ONE_HANDED_TRIGGER_ROTATION_OUT);
}
/**
* The interface for calls from outside the Shell, within the host process.
*/

View File

@@ -16,8 +16,6 @@
package com.android.wm.shell.onehanded;
import static android.os.UserHandle.myUserId;
import static com.android.wm.shell.onehanded.OneHandedAnimationController.TRANSITION_DIRECTION_EXIT;
import static com.android.wm.shell.onehanded.OneHandedAnimationController.TRANSITION_DIRECTION_TRIGGER;
@@ -186,20 +184,8 @@ public class OneHandedDisplayAreaOrganizer extends DisplayAreaOrganizer {
if (mDisplayLayout.rotation() == toRotation) {
return;
}
if (!mOneHandedSettingsUtil.getSettingsOneHandedModeEnabled(context.getContentResolver(),
myUserId())) {
return;
}
mDisplayLayout.rotateTo(context.getResources(), toRotation);
updateDisplayBounds();
if (mOneHandedSettingsUtil.getSettingsSwipeToNotificationEnabled(
context.getContentResolver(), myUserId())) {
// If current settings is swipe notification, skip finishOffset.
return;
}
finishOffset(0, TRANSITION_DIRECTION_EXIT);
}

View File

@@ -42,6 +42,7 @@ import android.util.ArrayMap;
import android.view.Display;
import android.view.Surface;
import android.view.SurfaceControl;
import android.window.WindowContainerTransaction;
import androidx.test.filters.SmallTest;
@@ -331,6 +332,58 @@ public class OneHandedControllerTest extends OneHandedTestCase {
verify(mMockDisplayAreaOrganizer, never()).scheduleOffset(anyInt(), anyInt());
}
@Test
public void testOneHandedEnabledRotation90ShouldHandleRotate() {
when(mMockSettingsUitl.getSettingsOneHandedModeEnabled(any(), anyInt())).thenReturn(true);
when(mMockSettingsUitl.getSettingsSwipeToNotificationEnabled(any(), anyInt())).thenReturn(
false);
final WindowContainerTransaction handlerWCT = new WindowContainerTransaction();
mSpiedOneHandedController.onRotateDisplay(mDisplay.getDisplayId(), Surface.ROTATION_0,
Surface.ROTATION_90, handlerWCT);
verify(mMockDisplayAreaOrganizer, atLeastOnce()).onRotateDisplay(eq(mContext),
eq(Surface.ROTATION_90), any(WindowContainerTransaction.class));
}
@Test
public void testOneHandedDisabledRotation90ShouldNotHandleRotate() {
when(mMockSettingsUitl.getSettingsOneHandedModeEnabled(any(), anyInt())).thenReturn(false);
when(mMockSettingsUitl.getSettingsSwipeToNotificationEnabled(any(), anyInt())).thenReturn(
false);
final WindowContainerTransaction handlerWCT = new WindowContainerTransaction();
mSpiedOneHandedController.onRotateDisplay(mDisplay.getDisplayId(), Surface.ROTATION_0,
Surface.ROTATION_90, handlerWCT);
verify(mMockDisplayAreaOrganizer, never()).onRotateDisplay(eq(mContext),
eq(Surface.ROTATION_90), any(WindowContainerTransaction.class));
}
@Test
public void testSwipeToNotificationEnabledRotation90ShouldNotHandleRotate() {
when(mMockSettingsUitl.getSettingsOneHandedModeEnabled(any(), anyInt())).thenReturn(true);
when(mMockSettingsUitl.getSettingsSwipeToNotificationEnabled(any(), anyInt())).thenReturn(
true);
final WindowContainerTransaction handlerWCT = new WindowContainerTransaction();
mSpiedOneHandedController.onRotateDisplay(mDisplay.getDisplayId(), Surface.ROTATION_0,
Surface.ROTATION_90, handlerWCT);
verify(mMockDisplayAreaOrganizer, never()).onRotateDisplay(eq(mContext),
eq(Surface.ROTATION_90), any(WindowContainerTransaction.class));
}
@Test
public void testSwipeToNotificationDisabledRotation90ShouldHandleRotate() {
when(mMockSettingsUitl.getSettingsOneHandedModeEnabled(any(), anyInt())).thenReturn(true);
when(mMockSettingsUitl.getSettingsSwipeToNotificationEnabled(any(), anyInt())).thenReturn(
false);
final WindowContainerTransaction handlerWCT = new WindowContainerTransaction();
mSpiedOneHandedController.onRotateDisplay(mDisplay.getDisplayId(), Surface.ROTATION_0,
Surface.ROTATION_90, handlerWCT);
verify(mMockDisplayAreaOrganizer, atLeastOnce()).onRotateDisplay(eq(mContext),
eq(Surface.ROTATION_90), any(WindowContainerTransaction.class));
}
@Test
public void testStateActive_shortcutRequestActivate_skipActions() {
when(mSpiedTransitionState.getState()).thenReturn(STATE_ACTIVE);