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

This commit is contained in:
Jason Hsu
2021-06-24 06:34:36 +00:00
committed by Android (Google) Code Review
3 changed files with 36 additions and 21 deletions

View File

@@ -19,6 +19,7 @@ package com.android.systemui.accessibility.floatingmenu;
import static android.provider.Settings.Secure.ACCESSIBILITY_BUTTON_MODE_FLOATING_MENU; import static android.provider.Settings.Secure.ACCESSIBILITY_BUTTON_MODE_FLOATING_MENU;
import android.content.Context; import android.content.Context;
import android.os.UserHandle;
import android.text.TextUtils; import android.text.TextUtils;
import androidx.annotation.MainThread; import androidx.annotation.MainThread;
@@ -40,11 +41,11 @@ public class AccessibilityFloatingMenuController implements
AccessibilityButtonModeObserver.ModeChangedListener, AccessibilityButtonModeObserver.ModeChangedListener,
AccessibilityButtonTargetsObserver.TargetsChangedListener { AccessibilityButtonTargetsObserver.TargetsChangedListener {
private final Context mContext;
private final AccessibilityButtonModeObserver mAccessibilityButtonModeObserver; private final AccessibilityButtonModeObserver mAccessibilityButtonModeObserver;
private final AccessibilityButtonTargetsObserver mAccessibilityButtonTargetsObserver; private final AccessibilityButtonTargetsObserver mAccessibilityButtonTargetsObserver;
private final KeyguardUpdateMonitor mKeyguardUpdateMonitor; private final KeyguardUpdateMonitor mKeyguardUpdateMonitor;
private Context mContext;
@VisibleForTesting @VisibleForTesting
IAccessibilityFloatingMenu mFloatingMenu; IAccessibilityFloatingMenu mFloatingMenu;
private int mBtnMode; private int mBtnMode;
@@ -79,6 +80,7 @@ public class AccessibilityFloatingMenuController implements
@Override @Override
public void onUserSwitchComplete(int userId) { public void onUserSwitchComplete(int userId) {
mContext = mContext.createContextAsUser(UserHandle.of(userId), /* flags= */ 0);
mBtnMode = mAccessibilityButtonModeObserver.getCurrentAccessibilityButtonMode(); mBtnMode = mAccessibilityButtonModeObserver.getCurrentAccessibilityButtonMode();
mBtnTargets = mBtnTargets =
mAccessibilityButtonTargetsObserver.getCurrentAccessibilityButtonTargets(); mAccessibilityButtonTargetsObserver.getCurrentAccessibilityButtonTargets();

View File

@@ -234,7 +234,6 @@ public class NavigationBar implements View.OnAttachStateChangeListener,
private boolean mTransientShown; private boolean mTransientShown;
private int mNavBarMode = NAV_BAR_MODE_3BUTTON; private int mNavBarMode = NAV_BAR_MODE_3BUTTON;
private int mA11yBtnMode;
private LightBarController mLightBarController; private LightBarController mLightBarController;
private AutoHideController mAutoHideController; private AutoHideController mAutoHideController;
@@ -491,7 +490,6 @@ public class NavigationBar implements View.OnAttachStateChangeListener,
mNavBarMode = mNavigationModeController.addListener(this); mNavBarMode = mNavigationModeController.addListener(this);
mAccessibilityButtonModeObserver.addListener(this); mAccessibilityButtonModeObserver.addListener(this);
mA11yBtnMode = mAccessibilityButtonModeObserver.getCurrentAccessibilityButtonMode();
} }
public NavigationBarView getView() { public NavigationBarView getView() {
@@ -1379,8 +1377,9 @@ public class NavigationBar implements View.OnAttachStateChangeListener,
private void setAccessibilityFloatingMenuModeIfNeeded() { private void setAccessibilityFloatingMenuModeIfNeeded() {
if (QuickStepContract.isGesturalMode(mNavBarMode)) { if (QuickStepContract.isGesturalMode(mNavBarMode)) {
Settings.Secure.putInt(mContentResolver, Settings.Secure.ACCESSIBILITY_BUTTON_MODE, Settings.Secure.putIntForUser(mContentResolver,
ACCESSIBILITY_BUTTON_MODE_FLOATING_MENU); 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 // If accessibility button is floating menu mode, click and long click state should be
// disabled. // disabled.
if (mA11yBtnMode == ACCESSIBILITY_BUTTON_MODE_FLOATING_MENU) { if (mAccessibilityButtonModeObserver.getCurrentAccessibilityButtonMode()
== ACCESSIBILITY_BUTTON_MODE_FLOATING_MENU) {
return 0; return 0;
} }
@@ -1552,7 +1552,6 @@ public class NavigationBar implements View.OnAttachStateChangeListener,
@Override @Override
public void onAccessibilityButtonModeChanged(int mode) { public void onAccessibilityButtonModeChanged(int mode) {
mA11yBtnMode = mode;
updateAccessibilityServicesState(mAccessibilityManager); updateAccessibilityServicesState(mAccessibilityManager);
} }

View File

@@ -25,6 +25,8 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import android.content.Context;
import android.content.ContextWrapper;
import android.os.UserHandle; import android.os.UserHandle;
import android.provider.Settings; import android.provider.Settings;
import android.testing.AndroidTestingRunner; import android.testing.AndroidTestingRunner;
@@ -39,6 +41,7 @@ import com.android.systemui.SysuiTestCase;
import com.android.systemui.accessibility.AccessibilityButtonModeObserver; import com.android.systemui.accessibility.AccessibilityButtonModeObserver;
import com.android.systemui.accessibility.AccessibilityButtonTargetsObserver; import com.android.systemui.accessibility.AccessibilityButtonTargetsObserver;
import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@@ -58,6 +61,7 @@ public class AccessibilityFloatingMenuControllerTest extends SysuiTestCase {
@Rule @Rule
public MockitoRule mockito = MockitoJUnit.rule(); public MockitoRule mockito = MockitoJUnit.rule();
private Context mContextWrapper;
private KeyguardUpdateMonitor mKeyguardUpdateMonitor; private KeyguardUpdateMonitor mKeyguardUpdateMonitor;
private AccessibilityFloatingMenuController mController; private AccessibilityFloatingMenuController mController;
private AccessibilityButtonTargetsObserver mTargetsObserver; private AccessibilityButtonTargetsObserver mTargetsObserver;
@@ -66,6 +70,16 @@ public class AccessibilityFloatingMenuControllerTest extends SysuiTestCase {
private ArgumentCaptor<KeyguardUpdateMonitorCallback> mKeyguardCallbackCaptor; private ArgumentCaptor<KeyguardUpdateMonitorCallback> mKeyguardCallbackCaptor;
private KeyguardUpdateMonitorCallback mKeyguardCallback; private KeyguardUpdateMonitorCallback mKeyguardCallback;
@Before
public void setUp() throws Exception {
mContextWrapper = new ContextWrapper(mContext) {
@Override
public Context createContextAsUser(UserHandle user, int flags) {
return getBaseContext();
}
};
}
@Test @Test
public void initController_registerListeners() { public void initController_registerListeners() {
mController = setUpController(); mController = setUpController();
@@ -105,7 +119,7 @@ public class AccessibilityFloatingMenuControllerTest extends SysuiTestCase {
public void onKeyguardVisibilityChanged_showing_destroyWidget() { public void onKeyguardVisibilityChanged_showing_destroyWidget() {
enableAccessibilityFloatingMenuConfig(); enableAccessibilityFloatingMenuConfig();
mController = setUpController(); mController = setUpController();
mController.mFloatingMenu = new AccessibilityFloatingMenu(mContext); mController.mFloatingMenu = new AccessibilityFloatingMenu(mContextWrapper);
captureKeyguardUpdateMonitorCallback(); captureKeyguardUpdateMonitorCallback();
mKeyguardCallback.onUserUnlocked(); mKeyguardCallback.onUserUnlocked();
@@ -131,7 +145,7 @@ public class AccessibilityFloatingMenuControllerTest extends SysuiTestCase {
final int fakeUserId = 1; final int fakeUserId = 1;
enableAccessibilityFloatingMenuConfig(); enableAccessibilityFloatingMenuConfig();
mController = setUpController(); mController = setUpController();
mController.mFloatingMenu = new AccessibilityFloatingMenu(mContext); mController.mFloatingMenu = new AccessibilityFloatingMenu(mContextWrapper);
captureKeyguardUpdateMonitorCallback(); captureKeyguardUpdateMonitorCallback();
mKeyguardCallback.onUserSwitching(fakeUserId); mKeyguardCallback.onUserSwitching(fakeUserId);
@@ -144,7 +158,7 @@ public class AccessibilityFloatingMenuControllerTest extends SysuiTestCase {
final int fakeUserId = 1; final int fakeUserId = 1;
enableAccessibilityFloatingMenuConfig(); enableAccessibilityFloatingMenuConfig();
mController = setUpController(); mController = setUpController();
mController.mFloatingMenu = new AccessibilityFloatingMenu(mContext); mController.mFloatingMenu = new AccessibilityFloatingMenu(mContextWrapper);
captureKeyguardUpdateMonitorCallback(); captureKeyguardUpdateMonitorCallback();
mKeyguardCallback.onUserUnlocked(); mKeyguardCallback.onUserUnlocked();
mKeyguardCallback.onKeyguardVisibilityChanged(true); mKeyguardCallback.onKeyguardVisibilityChanged(true);
@@ -172,7 +186,7 @@ public class AccessibilityFloatingMenuControllerTest extends SysuiTestCase {
@Test @Test
public void onAccessibilityButtonModeChanged_floatingModeAndHasButtonTargets_showWidget() { public void onAccessibilityButtonModeChanged_floatingModeAndHasButtonTargets_showWidget() {
Settings.Secure.putStringForUser(mContext.getContentResolver(), Settings.Secure.putStringForUser(mContextWrapper.getContentResolver(),
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, TEST_A11Y_BTN_TARGETS, Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, TEST_A11Y_BTN_TARGETS,
UserHandle.USER_CURRENT); UserHandle.USER_CURRENT);
mController = setUpController(); mController = setUpController();
@@ -184,7 +198,7 @@ public class AccessibilityFloatingMenuControllerTest extends SysuiTestCase {
@Test @Test
public void onAccessibilityButtonModeChanged_floatingModeAndNoButtonTargets_destroyWidget() { public void onAccessibilityButtonModeChanged_floatingModeAndNoButtonTargets_destroyWidget() {
Settings.Secure.putStringForUser(mContext.getContentResolver(), Settings.Secure.putStringForUser(mContextWrapper.getContentResolver(),
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, "", UserHandle.USER_CURRENT); Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, "", UserHandle.USER_CURRENT);
mController = setUpController(); mController = setUpController();
@@ -195,7 +209,7 @@ public class AccessibilityFloatingMenuControllerTest extends SysuiTestCase {
@Test @Test
public void onAccessibilityButtonModeChanged_navBarModeAndHasButtonTargets_destroyWidget() { public void onAccessibilityButtonModeChanged_navBarModeAndHasButtonTargets_destroyWidget() {
Settings.Secure.putStringForUser(mContext.getContentResolver(), Settings.Secure.putStringForUser(mContextWrapper.getContentResolver(),
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, TEST_A11Y_BTN_TARGETS, Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, TEST_A11Y_BTN_TARGETS,
UserHandle.USER_CURRENT); UserHandle.USER_CURRENT);
mController = setUpController(); mController = setUpController();
@@ -207,7 +221,7 @@ public class AccessibilityFloatingMenuControllerTest extends SysuiTestCase {
@Test @Test
public void onAccessibilityButtonModeChanged_navBarModeAndNoButtonTargets_destroyWidget() { public void onAccessibilityButtonModeChanged_navBarModeAndNoButtonTargets_destroyWidget() {
Settings.Secure.putStringForUser(mContext.getContentResolver(), Settings.Secure.putStringForUser(mContextWrapper.getContentResolver(),
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, "", UserHandle.USER_CURRENT); Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, "", UserHandle.USER_CURRENT);
mController = setUpController(); mController = setUpController();
@@ -218,7 +232,7 @@ public class AccessibilityFloatingMenuControllerTest extends SysuiTestCase {
@Test @Test
public void onAccessibilityButtonTargetsChanged_floatingModeAndHasButtonTargets_showWidget() { 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, Settings.Secure.ACCESSIBILITY_BUTTON_MODE, ACCESSIBILITY_BUTTON_MODE_FLOATING_MENU,
UserHandle.USER_CURRENT); UserHandle.USER_CURRENT);
mController = setUpController(); mController = setUpController();
@@ -230,7 +244,7 @@ public class AccessibilityFloatingMenuControllerTest extends SysuiTestCase {
@Test @Test
public void onAccessibilityButtonTargetsChanged_floatingModeAndNoButtonTargets_destroyWidget() { 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, Settings.Secure.ACCESSIBILITY_BUTTON_MODE, ACCESSIBILITY_BUTTON_MODE_FLOATING_MENU,
UserHandle.USER_CURRENT); UserHandle.USER_CURRENT);
mController = setUpController(); mController = setUpController();
@@ -242,7 +256,7 @@ public class AccessibilityFloatingMenuControllerTest extends SysuiTestCase {
@Test @Test
public void onAccessibilityButtonTargetsChanged_navBarModeAndHasButtonTargets_destroyWidget() { public void onAccessibilityButtonTargetsChanged_navBarModeAndHasButtonTargets_destroyWidget() {
Settings.Secure.putIntForUser(mContext.getContentResolver(), Settings.Secure.putIntForUser(mContextWrapper.getContentResolver(),
Settings.Secure.ACCESSIBILITY_BUTTON_MODE, Settings.Secure.ACCESSIBILITY_BUTTON_MODE,
ACCESSIBILITY_BUTTON_MODE_NAVIGATION_BAR, UserHandle.USER_CURRENT); ACCESSIBILITY_BUTTON_MODE_NAVIGATION_BAR, UserHandle.USER_CURRENT);
mController = setUpController(); mController = setUpController();
@@ -254,7 +268,7 @@ public class AccessibilityFloatingMenuControllerTest extends SysuiTestCase {
@Test @Test
public void onAccessibilityButtonTargetsChanged_navBarModeAndNoButtonTargets_destroyWidget() { public void onAccessibilityButtonTargetsChanged_navBarModeAndNoButtonTargets_destroyWidget() {
Settings.Secure.putIntForUser(mContext.getContentResolver(), Settings.Secure.putIntForUser(mContextWrapper.getContentResolver(),
Settings.Secure.ACCESSIBILITY_BUTTON_MODE, Settings.Secure.ACCESSIBILITY_BUTTON_MODE,
ACCESSIBILITY_BUTTON_MODE_NAVIGATION_BAR, UserHandle.USER_CURRENT); ACCESSIBILITY_BUTTON_MODE_NAVIGATION_BAR, UserHandle.USER_CURRENT);
mController = setUpController(); mController = setUpController();
@@ -269,15 +283,15 @@ public class AccessibilityFloatingMenuControllerTest extends SysuiTestCase {
mModeObserver = spy(Dependency.get(AccessibilityButtonModeObserver.class)); mModeObserver = spy(Dependency.get(AccessibilityButtonModeObserver.class));
mKeyguardUpdateMonitor = Dependency.get(KeyguardUpdateMonitor.class); mKeyguardUpdateMonitor = Dependency.get(KeyguardUpdateMonitor.class);
return new AccessibilityFloatingMenuController(mContext, mTargetsObserver, return new AccessibilityFloatingMenuController(mContextWrapper, mTargetsObserver,
mModeObserver, mKeyguardUpdateMonitor); mModeObserver, mKeyguardUpdateMonitor);
} }
private void enableAccessibilityFloatingMenuConfig() { private void enableAccessibilityFloatingMenuConfig() {
Settings.Secure.putIntForUser(mContext.getContentResolver(), Settings.Secure.putIntForUser(mContextWrapper.getContentResolver(),
Settings.Secure.ACCESSIBILITY_BUTTON_MODE, ACCESSIBILITY_BUTTON_MODE_FLOATING_MENU, Settings.Secure.ACCESSIBILITY_BUTTON_MODE, ACCESSIBILITY_BUTTON_MODE_FLOATING_MENU,
UserHandle.USER_CURRENT); UserHandle.USER_CURRENT);
Settings.Secure.putStringForUser(mContext.getContentResolver(), Settings.Secure.putStringForUser(mContextWrapper.getContentResolver(),
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, TEST_A11Y_BTN_TARGETS, Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, TEST_A11Y_BTN_TARGETS,
UserHandle.USER_CURRENT); UserHandle.USER_CURRENT);
} }