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

Commit 3a7f358f authored by Jason Hsu's avatar Jason Hsu Committed by Automerger Merge Worker
Browse files

Merge "Fix error config for accessibility floating menu under multi-users"...

Merge "Fix error config for accessibility floating menu under multi-users" into sc-dev am: 146efcb5

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

Change-Id: I3af0ee4b1d20d16981348af7351b28c1e8d5e5d3
parents 12acc8d5 146efcb5
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.systemui.accessibility.floatingmenu;
import static android.provider.Settings.Secure.ACCESSIBILITY_BUTTON_MODE_FLOATING_MENU;

import android.content.Context;
import android.os.UserHandle;
import android.text.TextUtils;

import androidx.annotation.MainThread;
@@ -40,11 +41,11 @@ public class AccessibilityFloatingMenuController implements
        AccessibilityButtonModeObserver.ModeChangedListener,
        AccessibilityButtonTargetsObserver.TargetsChangedListener {

    private final Context mContext;
    private final AccessibilityButtonModeObserver mAccessibilityButtonModeObserver;
    private final AccessibilityButtonTargetsObserver mAccessibilityButtonTargetsObserver;
    private final KeyguardUpdateMonitor mKeyguardUpdateMonitor;

    private Context mContext;
    @VisibleForTesting
    IAccessibilityFloatingMenu mFloatingMenu;
    private int mBtnMode;
@@ -79,6 +80,7 @@ public class AccessibilityFloatingMenuController implements

        @Override
        public void onUserSwitchComplete(int userId) {
            mContext = mContext.createContextAsUser(UserHandle.of(userId), /* flags= */ 0);
            mBtnMode = mAccessibilityButtonModeObserver.getCurrentAccessibilityButtonMode();
            mBtnTargets =
                    mAccessibilityButtonTargetsObserver.getCurrentAccessibilityButtonTargets();
+5 −6
Original line number Diff line number Diff line
@@ -234,7 +234,6 @@ public class NavigationBar implements View.OnAttachStateChangeListener,

    private boolean mTransientShown;
    private int mNavBarMode = NAV_BAR_MODE_3BUTTON;
    private int mA11yBtnMode;
    private LightBarController mLightBarController;
    private AutoHideController mAutoHideController;

@@ -491,7 +490,6 @@ public class NavigationBar implements View.OnAttachStateChangeListener,

        mNavBarMode = mNavigationModeController.addListener(this);
        mAccessibilityButtonModeObserver.addListener(this);
        mA11yBtnMode = mAccessibilityButtonModeObserver.getCurrentAccessibilityButtonMode();
    }

    public NavigationBarView getView() {
@@ -1379,8 +1377,9 @@ public class NavigationBar implements View.OnAttachStateChangeListener,

    private void setAccessibilityFloatingMenuModeIfNeeded() {
        if (QuickStepContract.isGesturalMode(mNavBarMode)) {
            Settings.Secure.putInt(mContentResolver, Settings.Secure.ACCESSIBILITY_BUTTON_MODE,
                    ACCESSIBILITY_BUTTON_MODE_FLOATING_MENU);
            Settings.Secure.putIntForUser(mContentResolver,
                    Settings.Secure.ACCESSIBILITY_BUTTON_MODE,
                    ACCESSIBILITY_BUTTON_MODE_FLOATING_MENU, UserHandle.USER_CURRENT);
        }
    }

@@ -1441,7 +1440,8 @@ public class NavigationBar implements View.OnAttachStateChangeListener,

        // If accessibility button is floating menu mode, click and long click state should be
        // disabled.
        if (mA11yBtnMode == ACCESSIBILITY_BUTTON_MODE_FLOATING_MENU) {
        if (mAccessibilityButtonModeObserver.getCurrentAccessibilityButtonMode()
                == ACCESSIBILITY_BUTTON_MODE_FLOATING_MENU) {
            return 0;
        }

@@ -1552,7 +1552,6 @@ public class NavigationBar implements View.OnAttachStateChangeListener,

    @Override
    public void onAccessibilityButtonModeChanged(int mode) {
        mA11yBtnMode = mode;
        updateAccessibilityServicesState(mAccessibilityManager);
    }

+28 −14
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;

import android.content.Context;
import android.content.ContextWrapper;
import android.os.UserHandle;
import android.provider.Settings;
import android.testing.AndroidTestingRunner;
@@ -39,6 +41,7 @@ import com.android.systemui.SysuiTestCase;
import com.android.systemui.accessibility.AccessibilityButtonModeObserver;
import com.android.systemui.accessibility.AccessibilityButtonTargetsObserver;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -58,6 +61,7 @@ public class AccessibilityFloatingMenuControllerTest extends SysuiTestCase {
    @Rule
    public MockitoRule mockito = MockitoJUnit.rule();

    private Context mContextWrapper;
    private KeyguardUpdateMonitor mKeyguardUpdateMonitor;
    private AccessibilityFloatingMenuController mController;
    private AccessibilityButtonTargetsObserver mTargetsObserver;
@@ -66,6 +70,16 @@ public class AccessibilityFloatingMenuControllerTest extends SysuiTestCase {
    private ArgumentCaptor<KeyguardUpdateMonitorCallback> mKeyguardCallbackCaptor;
    private KeyguardUpdateMonitorCallback mKeyguardCallback;

    @Before
    public void setUp() throws Exception {
        mContextWrapper = new ContextWrapper(mContext) {
            @Override
            public Context createContextAsUser(UserHandle user, int flags) {
                return getBaseContext();
            }
        };
    }

    @Test
    public void initController_registerListeners() {
        mController = setUpController();
@@ -105,7 +119,7 @@ public class AccessibilityFloatingMenuControllerTest extends SysuiTestCase {
    public void onKeyguardVisibilityChanged_showing_destroyWidget() {
        enableAccessibilityFloatingMenuConfig();
        mController = setUpController();
        mController.mFloatingMenu = new AccessibilityFloatingMenu(mContext);
        mController.mFloatingMenu = new AccessibilityFloatingMenu(mContextWrapper);
        captureKeyguardUpdateMonitorCallback();
        mKeyguardCallback.onUserUnlocked();

@@ -131,7 +145,7 @@ public class AccessibilityFloatingMenuControllerTest extends SysuiTestCase {
        final int fakeUserId = 1;
        enableAccessibilityFloatingMenuConfig();
        mController = setUpController();
        mController.mFloatingMenu = new AccessibilityFloatingMenu(mContext);
        mController.mFloatingMenu = new AccessibilityFloatingMenu(mContextWrapper);
        captureKeyguardUpdateMonitorCallback();

        mKeyguardCallback.onUserSwitching(fakeUserId);
@@ -144,7 +158,7 @@ public class AccessibilityFloatingMenuControllerTest extends SysuiTestCase {
        final int fakeUserId = 1;
        enableAccessibilityFloatingMenuConfig();
        mController = setUpController();
        mController.mFloatingMenu = new AccessibilityFloatingMenu(mContext);
        mController.mFloatingMenu = new AccessibilityFloatingMenu(mContextWrapper);
        captureKeyguardUpdateMonitorCallback();
        mKeyguardCallback.onUserUnlocked();
        mKeyguardCallback.onKeyguardVisibilityChanged(true);
@@ -172,7 +186,7 @@ public class AccessibilityFloatingMenuControllerTest extends SysuiTestCase {

    @Test
    public void onAccessibilityButtonModeChanged_floatingModeAndHasButtonTargets_showWidget() {
        Settings.Secure.putStringForUser(mContext.getContentResolver(),
        Settings.Secure.putStringForUser(mContextWrapper.getContentResolver(),
                Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, TEST_A11Y_BTN_TARGETS,
                UserHandle.USER_CURRENT);
        mController = setUpController();
@@ -184,7 +198,7 @@ public class AccessibilityFloatingMenuControllerTest extends SysuiTestCase {

    @Test
    public void onAccessibilityButtonModeChanged_floatingModeAndNoButtonTargets_destroyWidget() {
        Settings.Secure.putStringForUser(mContext.getContentResolver(),
        Settings.Secure.putStringForUser(mContextWrapper.getContentResolver(),
                Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, "", UserHandle.USER_CURRENT);
        mController = setUpController();

@@ -195,7 +209,7 @@ public class AccessibilityFloatingMenuControllerTest extends SysuiTestCase {

    @Test
    public void onAccessibilityButtonModeChanged_navBarModeAndHasButtonTargets_destroyWidget() {
        Settings.Secure.putStringForUser(mContext.getContentResolver(),
        Settings.Secure.putStringForUser(mContextWrapper.getContentResolver(),
                Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, TEST_A11Y_BTN_TARGETS,
                UserHandle.USER_CURRENT);
        mController = setUpController();
@@ -207,7 +221,7 @@ public class AccessibilityFloatingMenuControllerTest extends SysuiTestCase {

    @Test
    public void onAccessibilityButtonModeChanged_navBarModeAndNoButtonTargets_destroyWidget() {
        Settings.Secure.putStringForUser(mContext.getContentResolver(),
        Settings.Secure.putStringForUser(mContextWrapper.getContentResolver(),
                Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, "", UserHandle.USER_CURRENT);
        mController = setUpController();

@@ -218,7 +232,7 @@ public class AccessibilityFloatingMenuControllerTest extends SysuiTestCase {

    @Test
    public void onAccessibilityButtonTargetsChanged_floatingModeAndHasButtonTargets_showWidget() {
        Settings.Secure.putIntForUser(mContext.getContentResolver(),
        Settings.Secure.putIntForUser(mContextWrapper.getContentResolver(),
                Settings.Secure.ACCESSIBILITY_BUTTON_MODE, ACCESSIBILITY_BUTTON_MODE_FLOATING_MENU,
                UserHandle.USER_CURRENT);
        mController = setUpController();
@@ -230,7 +244,7 @@ public class AccessibilityFloatingMenuControllerTest extends SysuiTestCase {

    @Test
    public void onAccessibilityButtonTargetsChanged_floatingModeAndNoButtonTargets_destroyWidget() {
        Settings.Secure.putIntForUser(mContext.getContentResolver(),
        Settings.Secure.putIntForUser(mContextWrapper.getContentResolver(),
                Settings.Secure.ACCESSIBILITY_BUTTON_MODE, ACCESSIBILITY_BUTTON_MODE_FLOATING_MENU,
                UserHandle.USER_CURRENT);
        mController = setUpController();
@@ -242,7 +256,7 @@ public class AccessibilityFloatingMenuControllerTest extends SysuiTestCase {

    @Test
    public void onAccessibilityButtonTargetsChanged_navBarModeAndHasButtonTargets_destroyWidget() {
        Settings.Secure.putIntForUser(mContext.getContentResolver(),
        Settings.Secure.putIntForUser(mContextWrapper.getContentResolver(),
                Settings.Secure.ACCESSIBILITY_BUTTON_MODE,
                ACCESSIBILITY_BUTTON_MODE_NAVIGATION_BAR, UserHandle.USER_CURRENT);
        mController = setUpController();
@@ -254,7 +268,7 @@ public class AccessibilityFloatingMenuControllerTest extends SysuiTestCase {

    @Test
    public void onAccessibilityButtonTargetsChanged_navBarModeAndNoButtonTargets_destroyWidget() {
        Settings.Secure.putIntForUser(mContext.getContentResolver(),
        Settings.Secure.putIntForUser(mContextWrapper.getContentResolver(),
                Settings.Secure.ACCESSIBILITY_BUTTON_MODE,
                ACCESSIBILITY_BUTTON_MODE_NAVIGATION_BAR, UserHandle.USER_CURRENT);
        mController = setUpController();
@@ -269,15 +283,15 @@ public class AccessibilityFloatingMenuControllerTest extends SysuiTestCase {
        mModeObserver = spy(Dependency.get(AccessibilityButtonModeObserver.class));
        mKeyguardUpdateMonitor = Dependency.get(KeyguardUpdateMonitor.class);

        return new AccessibilityFloatingMenuController(mContext, mTargetsObserver,
        return new AccessibilityFloatingMenuController(mContextWrapper, mTargetsObserver,
                mModeObserver, mKeyguardUpdateMonitor);
    }

    private void enableAccessibilityFloatingMenuConfig() {
        Settings.Secure.putIntForUser(mContext.getContentResolver(),
        Settings.Secure.putIntForUser(mContextWrapper.getContentResolver(),
                Settings.Secure.ACCESSIBILITY_BUTTON_MODE, ACCESSIBILITY_BUTTON_MODE_FLOATING_MENU,
                UserHandle.USER_CURRENT);
        Settings.Secure.putStringForUser(mContext.getContentResolver(),
        Settings.Secure.putStringForUser(mContextWrapper.getContentResolver(),
                Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, TEST_A11Y_BTN_TARGETS,
                UserHandle.USER_CURRENT);
    }