diff options
| -rw-r--r-- | services/core/java/com/android/server/wm/ActivityTaskManagerService.java | 8 | ||||
| -rw-r--r-- | tests/MultiUser/Android.bp | 27 | ||||
| -rw-r--r-- | tests/MultiUser/AndroidManifest.xml | 18 | ||||
| -rw-r--r-- | tests/MultiUser/TEST_MAPPING | 7 | ||||
| -rw-r--r-- | tests/MultiUser/src/com/android/test/multiuser/MultiUserSettingsTests.java | 164 |
5 files changed, 224 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java index be01646bc25a..173545c30291 100644 --- a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java +++ b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java @@ -4441,6 +4441,10 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { } private void updateFontScaleIfNeeded(@UserIdInt int userId) { + if (userId != getCurrentUserId()) { + return; + } + final float scaleFactor = Settings.System.getFloatForUser(mContext.getContentResolver(), FONT_SCALE, 1.0f, userId); @@ -4457,6 +4461,10 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub { } private void updateFontWeightAdjustmentIfNeeded(@UserIdInt int userId) { + if (userId != getCurrentUserId()) { + return; + } + final int fontWeightAdjustment = Settings.Secure.getIntForUser( mContext.getContentResolver(), diff --git a/tests/MultiUser/Android.bp b/tests/MultiUser/Android.bp new file mode 100644 index 000000000000..bde309fe3015 --- /dev/null +++ b/tests/MultiUser/Android.bp @@ -0,0 +1,27 @@ +package { + // See: http://go/android-license-faq + // A large-scale-change added 'default_applicable_licenses' to import + // all of the 'license_kinds' from "frameworks_base_license" + // to get the below license kinds: + // SPDX-license-identifier-Apache-2.0 + default_applicable_licenses: ["frameworks_base_license"], +} + +android_test { + name: "MultiUserTests", + platform_apis: true, + srcs: ["src/**/*.java"], + + static_libs: [ + "androidx.test.rules", + "androidx.test.runner", + "services.core", + ], + libs: [ + "android.test.runner", + "android.test.base", + "android.test.mock", + ], + certificate: "platform", + test_suites: ["device-tests"], +} diff --git a/tests/MultiUser/AndroidManifest.xml b/tests/MultiUser/AndroidManifest.xml new file mode 100644 index 000000000000..9a25c0990de4 --- /dev/null +++ b/tests/MultiUser/AndroidManifest.xml @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="utf-8"?> + +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.android.test.multiuser"> + <uses-permission android:name="android.permission.WRITE_SETTINGS" /> + <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" /> + <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" /> + <uses-permission android:name="android.permission.MANAGE_USERS" /> + + + <application android:debuggable="true"> + <uses-library android:name="android.test.runner" /> + </application> + + <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner" + android:targetPackage="com.android.test.multiuser"> + </instrumentation> +</manifest> diff --git a/tests/MultiUser/TEST_MAPPING b/tests/MultiUser/TEST_MAPPING new file mode 100644 index 000000000000..0dbef6cbc6ff --- /dev/null +++ b/tests/MultiUser/TEST_MAPPING @@ -0,0 +1,7 @@ +{ + "presubmit": [ + { + "name": "MultiUserTests" + } + ] +} diff --git a/tests/MultiUser/src/com/android/test/multiuser/MultiUserSettingsTests.java b/tests/MultiUser/src/com/android/test/multiuser/MultiUserSettingsTests.java new file mode 100644 index 000000000000..1521cc617873 --- /dev/null +++ b/tests/MultiUser/src/com/android/test/multiuser/MultiUserSettingsTests.java @@ -0,0 +1,164 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.test.multiuser; + +import static android.provider.Settings.Secure.FONT_WEIGHT_ADJUSTMENT; +import static android.provider.Settings.System.FONT_SCALE; + +import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; + +import static org.junit.Assert.assertEquals; + +import android.content.ContentResolver; +import android.content.Context; +import android.os.UserManager; +import android.provider.Settings; + +import androidx.test.platform.app.InstrumentationRegistry; + +import org.junit.Assume; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class MultiUserSettingsTests { + private final Context mContext = getInstrumentation().getTargetContext(); + private final ContentResolver mContentResolver = mContext.getContentResolver(); + + private static void waitForBroadcastIdle() throws InterruptedException { + final int sleepDuration = 1000; + final String cmdAmWaitForBroadcastIdle = "am wait-for-broadcast-idle"; + + Thread.sleep(sleepDuration); + InstrumentationRegistry.getInstrumentation().getUiAutomation() + .executeShellCommand(cmdAmWaitForBroadcastIdle); + Thread.sleep(sleepDuration); + } + + private float getGlobalFontScale() { + return mContext.getResources().getConfiguration().fontScale; + } + + private int getGlobalFontWeight() { + return mContext.getResources().getConfiguration().fontWeightAdjustment; + } + + private float getFontScaleOfUser(int userId) { + return Settings.System.getFloatForUser(mContentResolver, FONT_SCALE, 1, userId); + } + + private int getFontWeightOfUser(int userId) { + return Settings.Secure.getIntForUser(mContentResolver, FONT_WEIGHT_ADJUSTMENT, 1, userId); + } + + private void setFontScaleOfUser(float fontScale, int userId) throws InterruptedException { + Settings.System.putFloatForUser(mContentResolver, FONT_SCALE, fontScale, userId); + waitForBroadcastIdle(); + } + + private void setFontWeightOfUser(int fontWeight, int userId) throws InterruptedException { + Settings.Secure.putIntForUser(mContentResolver, FONT_WEIGHT_ADJUSTMENT, fontWeight, userId); + waitForBroadcastIdle(); + } + + @Test + public void testChangingFontScaleOfABackgroundUser_shouldNotAffectUI() + throws InterruptedException { + + Assume.assumeTrue(UserManager.supportsMultipleUsers()); + + UserManager userManager = UserManager.get(mContext); + + final int backgroundUserId = userManager.createUser("test_user", + UserManager.USER_TYPE_FULL_SECONDARY, 0).id; + final float oldFontScaleOfBgUser = getFontScaleOfUser(backgroundUserId); + final float oldGlobalFontScale = getGlobalFontScale(); + final float newFontScaleOfBgUser = 1 + Math.max(oldGlobalFontScale, oldFontScaleOfBgUser); + + try { + setFontScaleOfUser(newFontScaleOfBgUser, backgroundUserId); + final float newGlobalFontScale = getGlobalFontScale(); + assertEquals(oldGlobalFontScale, newGlobalFontScale, 0); + } finally { + setFontScaleOfUser(oldFontScaleOfBgUser, backgroundUserId); + userManager.removeUser(backgroundUserId); + } + } + + @Test + public void testChangingFontWeightOfABackgroundUser_shouldNotAffectUI() + throws InterruptedException { + + Assume.assumeTrue(UserManager.supportsMultipleUsers()); + + UserManager userManager = UserManager.get(mContext); + + final int backgroundUserId = userManager.createUser("test_user", + UserManager.USER_TYPE_FULL_SECONDARY, 0).id; + final int oldFontWeightOfBgUser = getFontWeightOfUser(backgroundUserId); + final int oldGlobalFontWeight = getGlobalFontWeight(); + final int newFontWeightOfBgUser = 2 * Math.max(oldGlobalFontWeight, oldFontWeightOfBgUser); + + try { + setFontWeightOfUser(newFontWeightOfBgUser, backgroundUserId); + final int newGlobalFontWeight = getGlobalFontWeight(); + assertEquals(oldGlobalFontWeight, newGlobalFontWeight); + } finally { + setFontWeightOfUser(oldFontWeightOfBgUser, backgroundUserId); + userManager.removeUser(backgroundUserId); + } + } + + @Test + public void testChangingFontScaleOfTheForegroundUser_shouldAffectUI() + throws InterruptedException { + + Assume.assumeTrue(UserManager.supportsMultipleUsers()); + + final int currentUserId = mContext.getUserId(); + final float oldFontScale = getFontScaleOfUser(currentUserId); + final float newFontScale = 1 + oldFontScale; + + try { + setFontScaleOfUser(newFontScale, currentUserId); + final float globalFontScale = getGlobalFontScale(); + assertEquals(newFontScale, globalFontScale, 0); + } finally { + setFontScaleOfUser(oldFontScale, currentUserId); + } + } + + @Test + public void testChangingFontWeightOfTheForegroundUser_shouldAffectUI() + throws InterruptedException { + + Assume.assumeTrue(UserManager.supportsMultipleUsers()); + + final int currentUserId = mContext.getUserId(); + final int oldFontWeight = getFontWeightOfUser(currentUserId); + final int newFontWeight = 2 * oldFontWeight; + + try { + setFontWeightOfUser(newFontWeight, currentUserId); + final int globalFontWeight = getGlobalFontWeight(); + assertEquals(newFontWeight, globalFontWeight); + } finally { + setFontWeightOfUser(oldFontWeight, currentUserId); + } + } +} |