diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHanded.java b/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHanded.java index 9c78fc5e57b86..9bb709f9a82ad 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHanded.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHanded.java @@ -26,11 +26,6 @@ import java.io.PrintWriter; * Interface to engage one handed feature. */ public interface OneHanded { - /** - * Return whether the device has one handed feature or not. - */ - boolean hasOneHandedFeature(); - /** * Return one handed settings enabled or not. */ diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedController.java index d060f64444634..b1d777f82d310 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/onehanded/OneHandedController.java @@ -30,9 +30,10 @@ import android.os.RemoteException; import android.os.ServiceManager; import android.os.SystemProperties; import android.provider.Settings; -import android.util.Log; +import android.util.Slog; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; import com.android.wm.shell.common.DisplayChangeController; @@ -54,7 +55,6 @@ public class OneHandedController implements OneHanded { static final String SUPPORT_ONE_HANDED_MODE = "ro.support_one_handed_mode"; - private final boolean mHasOneHandedFeature; private boolean mIsOneHandedEnabled; private boolean mIsSwipeToNotificationEnabled; private boolean mTaskChangeToExit; @@ -160,10 +160,16 @@ public class OneHandedController implements OneHanded { }; /** - * The static constructor method to create OneHnadedController. + * Creates {@link OneHandedController}, returns {@code null} if the feature is not supported. */ + @Nullable public static OneHandedController create( Context context, DisplayController displayController) { + if (!SystemProperties.getBoolean(SUPPORT_ONE_HANDED_MODE, false)) { + Slog.w(TAG, "Device doesn't support OneHanded feature"); + return null; + } + OneHandedTutorialHandler tutorialHandler = new OneHandedTutorialHandler(context); OneHandedAnimationController animationController = new OneHandedAnimationController(context); @@ -186,43 +192,30 @@ public class OneHandedController implements OneHanded { OneHandedTutorialHandler tutorialHandler, OneHandedGestureHandler gestureHandler, IOverlayManager overlayManager) { - mHasOneHandedFeature = SystemProperties.getBoolean(SUPPORT_ONE_HANDED_MODE, false); - if (!mHasOneHandedFeature) { - Log.i(TAG, "Device config SUPPORT_ONE_HANDED_MODE off"); - mContext = null; - mDisplayAreaOrganizer = null; - mDisplayController = null; - mTouchHandler = null; - mTutorialHandler = null; - mGestureHandler = null; - mTimeoutHandler = null; - mOverlayManager = null; - } else { - mContext = context; - mDisplayAreaOrganizer = displayAreaOrganizer; - mDisplayController = displayController; - mTouchHandler = touchHandler; - mTutorialHandler = tutorialHandler; - mGestureHandler = gestureHandler; - mOverlayManager = overlayManager; + mContext = context; + mDisplayAreaOrganizer = displayAreaOrganizer; + mDisplayController = displayController; + mTouchHandler = touchHandler; + mTutorialHandler = tutorialHandler; + mGestureHandler = gestureHandler; + mOverlayManager = overlayManager; - mOffSetFraction = SystemProperties.getInt(ONE_HANDED_MODE_OFFSET_PERCENTAGE, 50) - / 100.0f; - mIsOneHandedEnabled = OneHandedSettingsUtil.getSettingsOneHandedModeEnabled( - context.getContentResolver()); - mIsSwipeToNotificationEnabled = - OneHandedSettingsUtil.getSettingsSwipeToNotificationEnabled( - context.getContentResolver()); - mTimeoutHandler = OneHandedTimeoutHandler.get(); + mOffSetFraction = SystemProperties.getInt(ONE_HANDED_MODE_OFFSET_PERCENTAGE, 50) + / 100.0f; + mIsOneHandedEnabled = OneHandedSettingsUtil.getSettingsOneHandedModeEnabled( + context.getContentResolver()); + mIsSwipeToNotificationEnabled = + OneHandedSettingsUtil.getSettingsSwipeToNotificationEnabled( + context.getContentResolver()); + mTimeoutHandler = OneHandedTimeoutHandler.get(); - mDisplayController.addDisplayChangingController(mRotationController); + mDisplayController.addDisplayChangingController(mRotationController); - setupCallback(); - setupSettingObservers(); - setupTimeoutListener(); - setupGesturalOverlay(); - updateSettings(); - } + setupCallback(); + setupSettingObservers(); + setupTimeoutListener(); + setupGesturalOverlay(); + updateSettings(); } /** @@ -248,11 +241,6 @@ public class OneHandedController implements OneHanded { updateOneHandedEnabled(); } - @Override - public boolean hasOneHandedFeature() { - return mHasOneHandedFeature; - } - @Override public boolean isOneHandedEnabled() { return mIsOneHandedEnabled; diff --git a/packages/SystemUI/src/com/android/systemui/wmshell/WMShell.java b/packages/SystemUI/src/com/android/systemui/wmshell/WMShell.java index b828535620493..b1b6280d6da09 100644 --- a/packages/SystemUI/src/com/android/systemui/wmshell/WMShell.java +++ b/packages/SystemUI/src/com/android/systemui/wmshell/WMShell.java @@ -312,10 +312,6 @@ public final class WMShell extends SystemUI @VisibleForTesting void initOneHanded(OneHanded oneHanded) { - if (!oneHanded.hasOneHandedFeature()) { - return; - } - int currentMode = mNavigationModeController.addListener(mode -> oneHanded.setThreeButtonModeEnabled(mode == NAV_BAR_MODE_3BUTTON)); oneHanded.setThreeButtonModeEnabled(currentMode == NAV_BAR_MODE_3BUTTON); diff --git a/packages/SystemUI/src/com/android/systemui/wmshell/WMShellBaseModule.java b/packages/SystemUI/src/com/android/systemui/wmshell/WMShellBaseModule.java index 970d5001172ee..09678b5d1772c 100644 --- a/packages/SystemUI/src/com/android/systemui/wmshell/WMShellBaseModule.java +++ b/packages/SystemUI/src/com/android/systemui/wmshell/WMShellBaseModule.java @@ -40,6 +40,7 @@ import com.android.wm.shell.common.SyncTransactionQueue; import com.android.wm.shell.common.SystemWindows; import com.android.wm.shell.common.TransactionPool; import com.android.wm.shell.onehanded.OneHanded; +import com.android.wm.shell.onehanded.OneHandedController; import com.android.wm.shell.pip.Pip; import com.android.wm.shell.pip.PipSurfaceTransactionHelper; import com.android.wm.shell.pip.PipUiEventLogger; @@ -48,6 +49,8 @@ import com.android.wm.shell.pip.phone.PipMediaController; import com.android.wm.shell.pip.phone.PipTouchHandler; import com.android.wm.shell.splitscreen.SplitScreen; +import java.util.Optional; + import dagger.BindsOptionalOf; import dagger.Module; import dagger.Provides; @@ -164,6 +167,10 @@ public abstract class WMShellBaseModule { @BindsOptionalOf abstract Bubbles optionalBubbles(); - @BindsOptionalOf - abstract OneHanded optionalOneHanded(); + @SysUISingleton + @Provides + static Optional provideOneHandedController(Context context, + DisplayController displayController) { + return Optional.ofNullable(OneHandedController.create(context, displayController)); + } } diff --git a/packages/SystemUI/src/com/android/systemui/wmshell/WMShellModule.java b/packages/SystemUI/src/com/android/systemui/wmshell/WMShellModule.java index 61c3f9c3616f0..ae7b108a2afaa 100644 --- a/packages/SystemUI/src/com/android/systemui/wmshell/WMShellModule.java +++ b/packages/SystemUI/src/com/android/systemui/wmshell/WMShellModule.java @@ -30,8 +30,6 @@ import com.android.wm.shell.common.FloatingContentCoordinator; import com.android.wm.shell.common.SyncTransactionQueue; import com.android.wm.shell.common.SystemWindows; import com.android.wm.shell.common.TransactionPool; -import com.android.wm.shell.onehanded.OneHanded; -import com.android.wm.shell.onehanded.OneHandedController; import com.android.wm.shell.pip.Pip; import com.android.wm.shell.pip.PipBoundsHandler; import com.android.wm.shell.pip.PipSurfaceTransactionHelper; @@ -129,11 +127,4 @@ public class WMShellModule { pipSurfaceTransactionHelper, splitScreenOptional, displayController, pipUiEventLogger, shellTaskOrganizer); } - - @SysUISingleton - @Provides - static OneHanded provideOneHandedController(Context context, - DisplayController displayController) { - return OneHandedController.create(context, displayController); - } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/wmshell/WMShellTest.java b/packages/SystemUI/tests/src/com/android/systemui/wmshell/WMShellTest.java index a5fbf195ed279..76fe3bf96500c 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/wmshell/WMShellTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/wmshell/WMShellTest.java @@ -142,7 +142,6 @@ public class WMShellTest extends SysuiTestCase { @Test public void initOneHanded_registersCallbacks() { - when(mOneHanded.hasOneHandedFeature()).thenReturn(true); mWMShell.initOneHanded(mOneHanded); verify(mKeyguardUpdateMonitor).registerCallback(any(KeyguardUpdateMonitorCallback.class));