Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9913006d authored by Jason Chang's avatar Jason Chang Committed by Android (Google) Code Review
Browse files

Merge "Do not instantiate one handed objects when property is not config"

parents 078d2937 bccf46f6
Loading
Loading
Loading
Loading
+17 −6
Original line number Diff line number Diff line
@@ -29,7 +29,9 @@ import android.os.IBinder;
import android.os.Looper;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemProperties;
import android.provider.Settings;
import android.util.Log;

import androidx.annotation.VisibleForTesting;

@@ -56,6 +58,7 @@ public class OneHandedUI extends SystemUI implements CommandQueue.Callbacks, Dum
    private static final String TAG = "OneHandedUI";
    private static final String ONE_HANDED_MODE_GESTURAL_OVERLAY =
            "com.android.internal.systemui.onehanded.gestural";
    private static final String SUPPORT_ONE_HANDED_MODE = "ro.support_one_handed_mode";

    private final OneHandedManagerImpl mOneHandedManager;
    private final CommandQueue mCommandQueue;
@@ -136,10 +139,18 @@ public class OneHandedUI extends SystemUI implements CommandQueue.Callbacks, Dum
            ScreenLifecycle screenLifecycle) {
        super(context);

        if (!SystemProperties.getBoolean(SUPPORT_ONE_HANDED_MODE, false)) {
            Log.i(TAG, "Device config SUPPORT_ONE_HANDED_MODE off");
            mCommandQueue = null;
            mOneHandedManager = null;
            mOverlayManager = null;
            mSettingUtil = null;
            mTimeoutHandler = null;
            mScreenLifecycle = null;
            return;
        }

        mCommandQueue = commandQueue;
        /* TODO(b/154290458) define a boolean system properties "support_one_handed_mode"
            boolean supportOneHanded = SystemProperties.getBoolean("support_one_handed_mode");
            if (!supportOneHanded) return; */
        mOneHandedManager = oneHandedManager;
        mSettingUtil = settingsUtil;
        mTimeoutHandler = OneHandedTimeoutHandler.get();
@@ -150,9 +161,9 @@ public class OneHandedUI extends SystemUI implements CommandQueue.Callbacks, Dum

    @Override
    public void start() {
        /* TODO(b/154290458) define a boolean system properties "support_one_handed_mode"
            boolean supportOneHanded = SystemProperties.getBoolean("support_one_handed_mode");
            if (!supportOneHanded) return; */
        if (!SystemProperties.getBoolean(SUPPORT_ONE_HANDED_MODE, false)) {
            return;
        }
        mCommandQueue.addCallback(this);
        setupKeyguardUpdateMonitor();
        setupScreenObserver();
+45 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static org.mockito.Mockito.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import android.os.SystemProperties;
import android.provider.Settings;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
@@ -42,6 +43,9 @@ import org.mockito.MockitoAnnotations;
@RunWith(AndroidTestingRunner.class)
@TestableLooper.RunWithLooper
public class OneHandedUITest extends OneHandedTestCase {
    private static final String SUPPORT_ONE_HANDED_MODE = "ro.support_one_handed_mode";

    boolean mIsSupportOneHandedMode;
    CommandQueue mCommandQueue;
    KeyguardUpdateMonitor mKeyguardUpdateMonitor;
    OneHandedUI mOneHandedUI;
@@ -58,6 +62,7 @@ public class OneHandedUITest extends OneHandedTestCase {
    @Before
    public void setUp() throws Exception {
        MockitoAnnotations.initMocks(this);
        mIsSupportOneHandedMode = SystemProperties.getBoolean(SUPPORT_ONE_HANDED_MODE, false);
        mCommandQueue = new CommandQueue(mContext);
        mScreenLifecycle = new ScreenLifecycle();
        mOneHandedUI = new OneHandedUI(mContext,
@@ -72,6 +77,10 @@ public class OneHandedUITest extends OneHandedTestCase {

    @Test
    public void testStartOneHanded() {
        // Bypass test if device not support one-handed mode
        if (!mIsSupportOneHandedMode) {
            return;
        }
        mOneHandedUI.startOneHanded();

        verify(mMockOneHandedManagerImpl, times(1)).startOneHanded();
@@ -79,6 +88,10 @@ public class OneHandedUITest extends OneHandedTestCase {

    @Test
    public void testStopOneHanded() {
        // Bypass test if device not support one-handed mode
        if (!mIsSupportOneHandedMode) {
            return;
        }
        mOneHandedUI.stopOneHanded();

        verify(mMockOneHandedManagerImpl, times(1)).stopOneHanded();
@@ -86,6 +99,10 @@ public class OneHandedUITest extends OneHandedTestCase {

    @Test
    public void testRegisterSettingsObserver_forEnabled() {
        // Bypass test if device not support one-handed mode
        if (!mIsSupportOneHandedMode) {
            return;
        }
        final String key = Settings.Secure.ONE_HANDED_MODE_ENABLED;

        verify(mMockSettingsUtil, times(1)).registerSettingsKeyObserver(key, any(), any());
@@ -93,6 +110,10 @@ public class OneHandedUITest extends OneHandedTestCase {

    @Test
    public void testRegisterSettingsObserver_forTimeout() {
        // Bypass test if device not support one-handed mode
        if (!mIsSupportOneHandedMode) {
            return;
        }
        final String key = Settings.Secure.ONE_HANDED_MODE_TIMEOUT;

        verify(mMockSettingsUtil, times(1)).registerSettingsKeyObserver(key, any(), any());
@@ -100,6 +121,10 @@ public class OneHandedUITest extends OneHandedTestCase {

    @Test
    public void testRegisterSettingsObserver_forTapAppExit() {
        // Bypass test if device not support one-handed mode
        if (!mIsSupportOneHandedMode) {
            return;
        }
        final String key = Settings.Secure.TAPS_APP_TO_EXIT;

        verify(mMockSettingsUtil, times(1)).registerSettingsKeyObserver(key, any(), any());
@@ -107,6 +132,10 @@ public class OneHandedUITest extends OneHandedTestCase {

    @Test
    public void tesSettingsObserver_updateTapAppToExit() {
        // Bypass test if device not support one-handed mode
        if (!mIsSupportOneHandedMode) {
            return;
        }
        Settings.Secure.putInt(mContext.getContentResolver(),
                Settings.Secure.TAPS_APP_TO_EXIT, 1);

@@ -115,6 +144,10 @@ public class OneHandedUITest extends OneHandedTestCase {

    @Test
    public void tesSettingsObserver_updateEnabled() {
        // Bypass test if device not support one-handed mode
        if (!mIsSupportOneHandedMode) {
            return;
        }
        Settings.Secure.putInt(mContext.getContentResolver(),
                Settings.Secure.ONE_HANDED_MODE_ENABLED, 1);

@@ -123,6 +156,10 @@ public class OneHandedUITest extends OneHandedTestCase {

    @Test
    public void tesSettingsObserver_updateTimeout() {
        // Bypass test if device not support one-handed mode
        if (!mIsSupportOneHandedMode) {
            return;
        }
        Settings.Secure.putInt(mContext.getContentResolver(),
                Settings.Secure.ONE_HANDED_MODE_TIMEOUT,
                OneHandedSettingsUtil.ONE_HANDED_TIMEOUT_MEDIUM_IN_SECONDS);
@@ -134,6 +171,10 @@ public class OneHandedUITest extends OneHandedTestCase {
    @Ignore("Clarifying do not receive callback")
    @Test
    public void testKeyguardBouncerShowing_shouldStopOneHanded() {
        // Bypass test if device not support one-handed mode
        if (!mIsSupportOneHandedMode) {
            return;
        }
        mKeyguardUpdateMonitor.sendKeyguardBouncerChanged(true);

        verify(mMockOneHandedManagerImpl, times(1)).stopOneHanded();
@@ -141,6 +182,10 @@ public class OneHandedUITest extends OneHandedTestCase {

    @Test
    public void testScreenTurningOff_shouldStopOneHanded() {
        // Bypass test if device not support one-handed mode
        if (!mIsSupportOneHandedMode) {
            return;
        }
        mScreenLifecycle.dispatchScreenTurningOff();

        verify(mMockOneHandedManagerImpl, times(1)).stopOneHanded();