Handle accessibility floating menu when switching users
* When switching users completed and keyguard is not show, show accessibility floating menu. Bug: 184620963 Bug: 173938894 Test: atest AccessibilityFloatingMenuControllerTest AccessibilityButtonModeObserverTest AccessibilityButtonTargetsObserverTest SecureSettingsContentObserverTest Change-Id: Iad3b9eb3dea1cb0b7828f00f3221f8c6869a7471
This commit is contained in:
@@ -21,6 +21,7 @@ import android.content.Context;
|
||||
import android.database.ContentObserver;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -75,7 +76,7 @@ public abstract class SecureSettingsContentObserver<T> {
|
||||
if (mListeners.size() == 1) {
|
||||
mContentResolver.registerContentObserver(
|
||||
Settings.Secure.getUriFor(mKey), /* notifyForDescendants= */
|
||||
false, mContentObserver);
|
||||
false, mContentObserver, UserHandle.USER_ALL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,7 +101,7 @@ public abstract class SecureSettingsContentObserver<T> {
|
||||
* See {@link Settings.Secure}.
|
||||
*/
|
||||
public final String getSettingsValue() {
|
||||
return Settings.Secure.getString(mContentResolver, mKey);
|
||||
return Settings.Secure.getStringForUser(mContentResolver, mKey, UserHandle.USER_CURRENT);
|
||||
}
|
||||
|
||||
private void updateValueChanged() {
|
||||
|
||||
@@ -71,6 +71,19 @@ public class AccessibilityFloatingMenuController implements
|
||||
handleFloatingMenuVisibility(mIsKeyguardVisible, mBtnMode, mBtnTargets);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUserSwitching(int userId) {
|
||||
destroyFloatingMenu();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUserSwitchComplete(int userId) {
|
||||
mBtnMode = mAccessibilityButtonModeObserver.getCurrentAccessibilityButtonMode();
|
||||
mBtnTargets =
|
||||
mAccessibilityButtonTargetsObserver.getCurrentAccessibilityButtonTargets();
|
||||
handleFloatingMenuVisibility(mIsKeyguardVisible, mBtnMode, mBtnTargets);
|
||||
}
|
||||
};
|
||||
|
||||
@Inject
|
||||
|
||||
@@ -23,6 +23,7 @@ import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
|
||||
@@ -55,17 +56,18 @@ public class AccessibilityButtonModeObserverTest extends SysuiTestCase {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.putIntForUser(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_BUTTON_MODE,
|
||||
Settings.Secure.ACCESSIBILITY_BUTTON_MODE_NAVIGATION_BAR);
|
||||
Settings.Secure.ACCESSIBILITY_BUTTON_MODE_NAVIGATION_BAR, UserHandle.USER_CURRENT);
|
||||
mAccessibilityButtonModeObserver = new AccessibilityButtonModeObserver(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onChange_haveListener_invokeCallback() {
|
||||
mAccessibilityButtonModeObserver.addListener(mListener);
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_BUTTON_MODE, TEST_A11Y_BTN_MODE_VALUE);
|
||||
Settings.Secure.putIntForUser(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_BUTTON_MODE, TEST_A11Y_BTN_MODE_VALUE,
|
||||
UserHandle.USER_CURRENT);
|
||||
|
||||
mAccessibilityButtonModeObserver.mContentObserver.onChange(false);
|
||||
|
||||
@@ -76,8 +78,9 @@ public class AccessibilityButtonModeObserverTest extends SysuiTestCase {
|
||||
public void onChange_noListener_noInvokeCallback() {
|
||||
mAccessibilityButtonModeObserver.addListener(mListener);
|
||||
mAccessibilityButtonModeObserver.removeListener(mListener);
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_BUTTON_MODE, TEST_A11Y_BTN_MODE_VALUE);
|
||||
Settings.Secure.putIntForUser(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_BUTTON_MODE, TEST_A11Y_BTN_MODE_VALUE,
|
||||
UserHandle.USER_CURRENT);
|
||||
|
||||
mAccessibilityButtonModeObserver.mContentObserver.onChange(false);
|
||||
|
||||
@@ -86,8 +89,9 @@ public class AccessibilityButtonModeObserverTest extends SysuiTestCase {
|
||||
|
||||
@Test
|
||||
public void getCurrentAccessibilityButtonMode_expectedValue() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_BUTTON_MODE, TEST_A11Y_BTN_MODE_VALUE);
|
||||
Settings.Secure.putIntForUser(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_BUTTON_MODE, TEST_A11Y_BTN_MODE_VALUE,
|
||||
UserHandle.USER_CURRENT);
|
||||
|
||||
final int actualValue =
|
||||
mAccessibilityButtonModeObserver.getCurrentAccessibilityButtonMode();
|
||||
|
||||
@@ -22,6 +22,7 @@ import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
|
||||
@@ -60,8 +61,9 @@ public class AccessibilityButtonTargetsObserverTest extends SysuiTestCase {
|
||||
@Test
|
||||
public void onChange_haveListener_invokeCallback() {
|
||||
mAccessibilityButtonTargetsObserver.addListener(mListener);
|
||||
Settings.Secure.putString(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, TEST_A11Y_BTN_TARGETS);
|
||||
Settings.Secure.putStringForUser(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, TEST_A11Y_BTN_TARGETS,
|
||||
UserHandle.USER_CURRENT);
|
||||
|
||||
mAccessibilityButtonTargetsObserver.mContentObserver.onChange(false);
|
||||
|
||||
@@ -72,8 +74,9 @@ public class AccessibilityButtonTargetsObserverTest extends SysuiTestCase {
|
||||
public void onChange_listenerRemoved_noInvokeCallback() {
|
||||
mAccessibilityButtonTargetsObserver.addListener(mListener);
|
||||
mAccessibilityButtonTargetsObserver.removeListener(mListener);
|
||||
Settings.Secure.putString(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, TEST_A11Y_BTN_TARGETS);
|
||||
Settings.Secure.putStringForUser(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, TEST_A11Y_BTN_TARGETS,
|
||||
UserHandle.USER_CURRENT);
|
||||
|
||||
mAccessibilityButtonTargetsObserver.mContentObserver.onChange(false);
|
||||
|
||||
@@ -82,8 +85,9 @@ public class AccessibilityButtonTargetsObserverTest extends SysuiTestCase {
|
||||
|
||||
@Test
|
||||
public void getCurrentAccessibilityButtonTargets_expectedValue() {
|
||||
Settings.Secure.putString(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, TEST_A11Y_BTN_TARGETS);
|
||||
Settings.Secure.putStringForUser(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, TEST_A11Y_BTN_TARGETS,
|
||||
UserHandle.USER_CURRENT);
|
||||
|
||||
final String actualValue =
|
||||
mAccessibilityButtonTargetsObserver.getCurrentAccessibilityButtonTargets();
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.android.systemui.accessibility;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
|
||||
@@ -55,8 +56,8 @@ public class SecureSettingsContentObserverTest extends SysuiTestCase {
|
||||
|
||||
@Test
|
||||
public void checkValue() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_BUTTON_MODE, 1);
|
||||
Settings.Secure.putIntForUser(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_BUTTON_MODE, 1, UserHandle.USER_CURRENT);
|
||||
|
||||
assertThat(mTestObserver.getSettingsValue()).isEqualTo("1");
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
import android.testing.TestableLooper;
|
||||
@@ -125,10 +126,55 @@ public class AccessibilityFloatingMenuControllerTest extends SysuiTestCase {
|
||||
assertThat(mController.mFloatingMenu).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onUserSwitching_destroyWidget() {
|
||||
final int fakeUserId = 1;
|
||||
enableAccessibilityFloatingMenuConfig();
|
||||
mController = setUpController();
|
||||
mController.mFloatingMenu = new AccessibilityFloatingMenu(mContext);
|
||||
captureKeyguardUpdateMonitorCallback();
|
||||
|
||||
mKeyguardCallback.onUserSwitching(fakeUserId);
|
||||
|
||||
assertThat(mController.mFloatingMenu).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onUserSwitch_onKeyguardVisibilityChangedToTrue_destroyWidget() {
|
||||
final int fakeUserId = 1;
|
||||
enableAccessibilityFloatingMenuConfig();
|
||||
mController = setUpController();
|
||||
mController.mFloatingMenu = new AccessibilityFloatingMenu(mContext);
|
||||
captureKeyguardUpdateMonitorCallback();
|
||||
mKeyguardCallback.onUserUnlocked();
|
||||
mKeyguardCallback.onKeyguardVisibilityChanged(true);
|
||||
|
||||
mKeyguardCallback.onUserSwitching(fakeUserId);
|
||||
mKeyguardCallback.onUserSwitchComplete(fakeUserId);
|
||||
|
||||
assertThat(mController.mFloatingMenu).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onUserSwitch_onKeyguardVisibilityChangedToFalse_showWidget() {
|
||||
final int fakeUserId = 1;
|
||||
enableAccessibilityFloatingMenuConfig();
|
||||
mController = setUpController();
|
||||
captureKeyguardUpdateMonitorCallback();
|
||||
mKeyguardCallback.onUserUnlocked();
|
||||
mKeyguardCallback.onKeyguardVisibilityChanged(false);
|
||||
|
||||
mKeyguardCallback.onUserSwitching(fakeUserId);
|
||||
mKeyguardCallback.onUserSwitchComplete(fakeUserId);
|
||||
|
||||
assertThat(mController.mFloatingMenu).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onAccessibilityButtonModeChanged_floatingModeAndHasButtonTargets_showWidget() {
|
||||
Settings.Secure.putString(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, TEST_A11Y_BTN_TARGETS);
|
||||
Settings.Secure.putStringForUser(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, TEST_A11Y_BTN_TARGETS,
|
||||
UserHandle.USER_CURRENT);
|
||||
mController = setUpController();
|
||||
|
||||
mController.onAccessibilityButtonModeChanged(ACCESSIBILITY_BUTTON_MODE_FLOATING_MENU);
|
||||
@@ -138,8 +184,8 @@ public class AccessibilityFloatingMenuControllerTest extends SysuiTestCase {
|
||||
|
||||
@Test
|
||||
public void onAccessibilityButtonModeChanged_floatingModeAndNoButtonTargets_destroyWidget() {
|
||||
Settings.Secure.putString(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, "");
|
||||
Settings.Secure.putStringForUser(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, "", UserHandle.USER_CURRENT);
|
||||
mController = setUpController();
|
||||
|
||||
mController.onAccessibilityButtonModeChanged(ACCESSIBILITY_BUTTON_MODE_FLOATING_MENU);
|
||||
@@ -149,8 +195,9 @@ public class AccessibilityFloatingMenuControllerTest extends SysuiTestCase {
|
||||
|
||||
@Test
|
||||
public void onAccessibilityButtonModeChanged_navBarModeAndHasButtonTargets_destroyWidget() {
|
||||
Settings.Secure.putString(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, TEST_A11Y_BTN_TARGETS);
|
||||
Settings.Secure.putStringForUser(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, TEST_A11Y_BTN_TARGETS,
|
||||
UserHandle.USER_CURRENT);
|
||||
mController = setUpController();
|
||||
|
||||
mController.onAccessibilityButtonModeChanged(ACCESSIBILITY_BUTTON_MODE_NAVIGATION_BAR);
|
||||
@@ -160,8 +207,8 @@ public class AccessibilityFloatingMenuControllerTest extends SysuiTestCase {
|
||||
|
||||
@Test
|
||||
public void onAccessibilityButtonModeChanged_navBarModeAndNoButtonTargets_destroyWidget() {
|
||||
Settings.Secure.putString(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, "");
|
||||
Settings.Secure.putStringForUser(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, "", UserHandle.USER_CURRENT);
|
||||
mController = setUpController();
|
||||
|
||||
mController.onAccessibilityButtonModeChanged(ACCESSIBILITY_BUTTON_MODE_NAVIGATION_BAR);
|
||||
@@ -171,8 +218,9 @@ public class AccessibilityFloatingMenuControllerTest extends SysuiTestCase {
|
||||
|
||||
@Test
|
||||
public void onAccessibilityButtonTargetsChanged_floatingModeAndHasButtonTargets_showWidget() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_BUTTON_MODE, ACCESSIBILITY_BUTTON_MODE_FLOATING_MENU);
|
||||
Settings.Secure.putIntForUser(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_BUTTON_MODE, ACCESSIBILITY_BUTTON_MODE_FLOATING_MENU,
|
||||
UserHandle.USER_CURRENT);
|
||||
mController = setUpController();
|
||||
|
||||
mController.onAccessibilityButtonTargetsChanged(TEST_A11Y_BTN_TARGETS);
|
||||
@@ -182,8 +230,9 @@ public class AccessibilityFloatingMenuControllerTest extends SysuiTestCase {
|
||||
|
||||
@Test
|
||||
public void onAccessibilityButtonTargetsChanged_floatingModeAndNoButtonTargets_destroyWidget() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_BUTTON_MODE, ACCESSIBILITY_BUTTON_MODE_FLOATING_MENU);
|
||||
Settings.Secure.putIntForUser(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_BUTTON_MODE, ACCESSIBILITY_BUTTON_MODE_FLOATING_MENU,
|
||||
UserHandle.USER_CURRENT);
|
||||
mController = setUpController();
|
||||
|
||||
mController.onAccessibilityButtonTargetsChanged("");
|
||||
@@ -193,9 +242,9 @@ public class AccessibilityFloatingMenuControllerTest extends SysuiTestCase {
|
||||
|
||||
@Test
|
||||
public void onAccessibilityButtonTargetsChanged_navBarModeAndHasButtonTargets_destroyWidget() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.putIntForUser(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_BUTTON_MODE,
|
||||
ACCESSIBILITY_BUTTON_MODE_NAVIGATION_BAR);
|
||||
ACCESSIBILITY_BUTTON_MODE_NAVIGATION_BAR, UserHandle.USER_CURRENT);
|
||||
mController = setUpController();
|
||||
|
||||
mController.onAccessibilityButtonTargetsChanged(TEST_A11Y_BTN_TARGETS);
|
||||
@@ -205,9 +254,9 @@ public class AccessibilityFloatingMenuControllerTest extends SysuiTestCase {
|
||||
|
||||
@Test
|
||||
public void onAccessibilityButtonTargetsChanged_navBarModeAndNoButtonTargets_destroyWidget() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.putIntForUser(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_BUTTON_MODE,
|
||||
ACCESSIBILITY_BUTTON_MODE_NAVIGATION_BAR);
|
||||
ACCESSIBILITY_BUTTON_MODE_NAVIGATION_BAR, UserHandle.USER_CURRENT);
|
||||
mController = setUpController();
|
||||
|
||||
mController.onAccessibilityButtonTargetsChanged("");
|
||||
@@ -225,10 +274,12 @@ public class AccessibilityFloatingMenuControllerTest extends SysuiTestCase {
|
||||
}
|
||||
|
||||
private void enableAccessibilityFloatingMenuConfig() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_BUTTON_MODE, ACCESSIBILITY_BUTTON_MODE_FLOATING_MENU);
|
||||
Settings.Secure.putString(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, TEST_A11Y_BTN_TARGETS);
|
||||
Settings.Secure.putIntForUser(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_BUTTON_MODE, ACCESSIBILITY_BUTTON_MODE_FLOATING_MENU,
|
||||
UserHandle.USER_CURRENT);
|
||||
Settings.Secure.putStringForUser(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS, TEST_A11Y_BTN_TARGETS,
|
||||
UserHandle.USER_CURRENT);
|
||||
}
|
||||
|
||||
private void captureKeyguardUpdateMonitorCallback() {
|
||||
|
||||
Reference in New Issue
Block a user