Loading libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedController.java +25 −15 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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 = Loading Loading @@ -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 Loading Loading @@ -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(); Loading Loading @@ -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. */ Loading libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedDisplayAreaOrganizer.java +0 −14 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); } Loading libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/onehanded/OneHandedControllerTest.java +53 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); Loading Loading
libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedController.java +25 −15 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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 = Loading Loading @@ -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 Loading Loading @@ -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(); Loading Loading @@ -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. */ Loading
libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedDisplayAreaOrganizer.java +0 −14 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); } Loading
libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/onehanded/OneHandedControllerTest.java +53 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); Loading