summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/os/UserManager.java26
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java7
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerMainThreadTest.java28
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java42
-rw-r--r--services/tests/servicestests/src/com/android/server/pm/UserManagerTest.java30
5 files changed, 127 insertions, 6 deletions
diff --git a/core/java/android/os/UserManager.java b/core/java/android/os/UserManager.java
index cc79ae307f60..06b137d5c839 100644
--- a/core/java/android/os/UserManager.java
+++ b/core/java/android/os/UserManager.java
@@ -5074,6 +5074,32 @@ public class UserManager {
}
/**
+ * Returns list of the profiles of the given user, including userId itself, as well as the
+ * communal profile, if there is one.
+ *
+ * <p>Note that this returns both enabled and not enabled profiles.
+ * <p>Note that this includes all profile types (not including Restricted profiles).
+ *
+ * @hide
+ */
+ @FlaggedApi(android.multiuser.Flags.FLAG_SUPPORT_COMMUNAL_PROFILE)
+ @RequiresPermission(anyOf = {
+ Manifest.permission.MANAGE_USERS,
+ Manifest.permission.CREATE_USERS,
+ Manifest.permission.QUERY_USERS})
+ public List<UserInfo> getProfilesIncludingCommunal(@UserIdInt int userId) {
+ final List<UserInfo> profiles = getProfiles(userId);
+ final UserHandle communalProfile = getCommunalProfile();
+ if (communalProfile != null) {
+ final UserInfo communalInfo = getUserInfo(communalProfile.getIdentifier());
+ if (communalInfo != null) {
+ profiles.add(communalInfo);
+ }
+ }
+ return profiles;
+ }
+
+ /**
* Checks if the 2 provided user handles belong to the same profile group.
*
* @param user one of the two user handles to check.
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java
index 710e59d91c6b..3f080c247924 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java
@@ -250,6 +250,7 @@ public class NotificationLockscreenUserManagerImpl implements
private final Handler mMainHandler;
private final Handler mBackgroundHandler;
private final Executor mBackgroundExecutor;
+ /** The current user and its profiles (possibly including a communal profile). */
protected final SparseArray<UserInfo> mCurrentProfiles = new SparseArray<>();
protected final SparseArray<UserInfo> mCurrentManagedProfiles = new SparseArray<>();
@@ -689,12 +690,16 @@ public class NotificationLockscreenUserManagerImpl implements
}
}
+ @SuppressLint("MissingPermission")
private void updateCurrentProfilesCache() {
synchronized (mLock) {
mCurrentProfiles.clear();
mCurrentManagedProfiles.clear();
if (mUserManager != null) {
- for (UserInfo user : mUserManager.getProfiles(mCurrentUserId)) {
+ List<UserInfo> profiles = android.multiuser.Flags.supportCommunalProfile()
+ ? mUserManager.getProfilesIncludingCommunal(mCurrentUserId)
+ : mUserManager.getProfiles(mCurrentUserId);
+ for (UserInfo user : profiles) {
mCurrentProfiles.put(user.id, user);
if (UserManager.USER_TYPE_PROFILE_MANAGED.equals(user.userType)) {
mCurrentManagedProfiles.put(user.id, user);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerMainThreadTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerMainThreadTest.java
index 3a9c24a7109c..01fe40f6dff6 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerMainThreadTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerMainThreadTest.java
@@ -49,6 +49,7 @@ import android.os.UserManager;
import android.provider.Settings;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
+import android.util.SparseArray;
import androidx.test.filters.SmallTest;
@@ -120,6 +121,7 @@ public class NotificationLockscreenUserManagerMainThreadTest extends SysuiTestCa
private UserInfo mCurrentUser;
private UserInfo mSecondaryUser;
private UserInfo mWorkUser;
+ private UserInfo mCommunalUser;
private FakeSettings mSettings;
private TestNotificationLockscreenUserManager mLockscreenUserManager;
private NotificationEntry mCurrentUserNotif;
@@ -142,12 +144,18 @@ public class NotificationLockscreenUserManagerMainThreadTest extends SysuiTestCa
mSecondaryUser = new UserInfo(currentUserId + 1, "", 0);
mWorkUser = new UserInfo(currentUserId + 2, "" /* name */, null /* iconPath */, 0,
UserManager.USER_TYPE_PROFILE_MANAGED);
+ mCommunalUser = new UserInfo(currentUserId + 3, "" /* name */, null /* iconPath */, 0,
+ UserManager.USER_TYPE_PROFILE_COMMUNAL);
when(mKeyguardManager.getPrivateNotificationsAllowed()).thenReturn(true);
when(mUserManager.getProfiles(currentUserId)).thenReturn(Lists.newArrayList(
mCurrentUser, mWorkUser));
+ when(mUserManager.getProfilesIncludingCommunal(currentUserId)).thenReturn(
+ Lists.newArrayList(mCurrentUser, mWorkUser, mCommunalUser));
when(mUserManager.getProfiles(mSecondaryUser.id)).thenReturn(Lists.newArrayList(
mSecondaryUser));
+ when(mUserManager.getProfilesIncludingCommunal(mSecondaryUser.id)).thenReturn(
+ Lists.newArrayList(mSecondaryUser, mCommunalUser));
mDependency.injectTestDependency(Dependency.MAIN_HANDLER,
Handler.createAsync(Looper.myLooper()));
@@ -178,6 +186,26 @@ public class NotificationLockscreenUserManagerMainThreadTest extends SysuiTestCa
}
@Test
+ public void testGetCurrentProfiles() {
+ final SparseArray<UserInfo> expectedCurProfiles = new SparseArray<>();
+ expectedCurProfiles.put(mCurrentUser.id, mCurrentUser);
+ expectedCurProfiles.put(mWorkUser.id, mWorkUser);
+ if (android.multiuser.Flags.supportCommunalProfile()) {
+ expectedCurProfiles.put(mCommunalUser.id, mCommunalUser);
+ }
+ assertTrue(mLockscreenUserManager.getCurrentProfiles().contentEquals(expectedCurProfiles));
+
+ mLockscreenUserManager.mUserChangedCallback.onUserChanging(mSecondaryUser.id, mContext);
+
+ final SparseArray<UserInfo> expectedSecProfiles = new SparseArray<>();
+ expectedSecProfiles.put(mSecondaryUser.id, mSecondaryUser);
+ if (android.multiuser.Flags.supportCommunalProfile()) {
+ expectedSecProfiles.put(mCommunalUser.id, mCommunalUser);
+ }
+ assertTrue(mLockscreenUserManager.getCurrentProfiles().contentEquals(expectedSecProfiles));
+ }
+
+ @Test
public void testLockScreenShowNotificationsFalse() {
mSettings.putInt(LOCK_SCREEN_SHOW_NOTIFICATIONS, 0);
changeSetting(LOCK_SCREEN_SHOW_NOTIFICATIONS);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java
index 43adc69be13f..a1425f811a84 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java
@@ -64,6 +64,7 @@ import android.os.UserManager;
import android.provider.Settings;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
+import android.util.SparseArray;
import androidx.test.filters.SmallTest;
@@ -136,6 +137,7 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
private UserInfo mCurrentUser;
private UserInfo mSecondaryUser;
private UserInfo mWorkUser;
+ private UserInfo mCommunalUser;
private FakeSettings mSettings;
private TestNotificationLockscreenUserManager mLockscreenUserManager;
private NotificationEntry mCurrentUserNotif;
@@ -158,14 +160,20 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
mSecondaryUser = new UserInfo(currentUserId + 1, "", 0);
mWorkUser = new UserInfo(currentUserId + 2, "" /* name */, null /* iconPath */, 0,
UserManager.USER_TYPE_PROFILE_MANAGED);
+ mCommunalUser = new UserInfo(currentUserId + 3, "" /* name */, null /* iconPath */, 0,
+ UserManager.USER_TYPE_PROFILE_COMMUNAL);
when(mKeyguardManager.getPrivateNotificationsAllowed()).thenReturn(true);
when(mUserManager.getProfiles(currentUserId)).thenReturn(Lists.newArrayList(
mCurrentUser, mWorkUser));
+ when(mUserManager.getProfilesIncludingCommunal(currentUserId)).thenReturn(
+ Lists.newArrayList(mCurrentUser, mWorkUser, mCommunalUser));
when(mUserManager.getUsers()).thenReturn(Lists.newArrayList(
- mCurrentUser, mWorkUser, mSecondaryUser));
+ mCurrentUser, mWorkUser, mSecondaryUser, mCommunalUser));
when(mUserManager.getProfiles(mSecondaryUser.id)).thenReturn(Lists.newArrayList(
mSecondaryUser));
+ when(mUserManager.getProfilesIncludingCommunal(mSecondaryUser.id)).thenReturn(
+ Lists.newArrayList(mSecondaryUser, mCommunalUser));
mDependency.injectTestDependency(Dependency.MAIN_HANDLER,
Handler.createAsync(Looper.myLooper()));
@@ -211,6 +219,26 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
}
@Test
+ public void testGetCurrentProfiles() {
+ final SparseArray<UserInfo> expectedCurProfiles = new SparseArray<>();
+ expectedCurProfiles.put(mCurrentUser.id, mCurrentUser);
+ expectedCurProfiles.put(mWorkUser.id, mWorkUser);
+ if (android.multiuser.Flags.supportCommunalProfile()) {
+ expectedCurProfiles.put(mCommunalUser.id, mCommunalUser);
+ }
+ assertTrue(mLockscreenUserManager.getCurrentProfiles().contentEquals(expectedCurProfiles));
+
+ mLockscreenUserManager.mUserChangedCallback.onUserChanging(mSecondaryUser.id, mContext);
+
+ final SparseArray<UserInfo> expectedSecProfiles = new SparseArray<>();
+ expectedSecProfiles.put(mSecondaryUser.id, mSecondaryUser);
+ if (android.multiuser.Flags.supportCommunalProfile()) {
+ expectedSecProfiles.put(mCommunalUser.id, mCommunalUser);
+ }
+ assertTrue(mLockscreenUserManager.getCurrentProfiles().contentEquals(expectedSecProfiles));
+ }
+
+ @Test
public void testLockScreenShowNotificationsFalse() {
mSettings.putInt(LOCK_SCREEN_SHOW_NOTIFICATIONS, 0);
changeSetting(LOCK_SCREEN_SHOW_NOTIFICATIONS);
@@ -713,7 +741,8 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
assertEquals(0, mLockscreenUserManager.mCurrentProfiles.size());
mLockscreenUserManager.mCurrentProfiles.append(0, mock(UserInfo.class));
simulateProfileAvailabilityActions(Intent.ACTION_PROFILE_AVAILABLE);
- assertEquals(2, mLockscreenUserManager.mCurrentProfiles.size());
+ int numProfiles = android.multiuser.Flags.supportCommunalProfile() ? 3 : 2;
+ assertEquals(numProfiles, mLockscreenUserManager.mCurrentProfiles.size());
}
@Test
@@ -723,7 +752,8 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
assertEquals(0, mLockscreenUserManager.mCurrentProfiles.size());
mLockscreenUserManager.mCurrentProfiles.append(0, mock(UserInfo.class));
simulateProfileAvailabilityActions(Intent.ACTION_PROFILE_UNAVAILABLE);
- assertEquals(2, mLockscreenUserManager.mCurrentProfiles.size());
+ int numProfiles = android.multiuser.Flags.supportCommunalProfile() ? 3 : 2;
+ assertEquals(numProfiles, mLockscreenUserManager.mCurrentProfiles.size());
}
@Test
@@ -735,7 +765,8 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
assertEquals(0, mLockscreenUserManager.mCurrentManagedProfiles.size());
mLockscreenUserManager.mCurrentProfiles.append(0, mock(UserInfo.class));
simulateProfileAvailabilityActions(Intent.ACTION_MANAGED_PROFILE_AVAILABLE);
- assertEquals(2, mLockscreenUserManager.mCurrentProfiles.size());
+ int numProfiles = android.multiuser.Flags.supportCommunalProfile() ? 3 : 2;
+ assertEquals(numProfiles, mLockscreenUserManager.mCurrentProfiles.size());
assertEquals(1, mLockscreenUserManager.mCurrentManagedProfiles.size());
}
@@ -748,7 +779,8 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
assertEquals(0, mLockscreenUserManager.mCurrentManagedProfiles.size());
mLockscreenUserManager.mCurrentProfiles.append(0, mock(UserInfo.class));
simulateProfileAvailabilityActions(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE);
- assertEquals(2, mLockscreenUserManager.mCurrentProfiles.size());
+ int numProfiles = android.multiuser.Flags.supportCommunalProfile() ? 3 : 2;
+ assertEquals(numProfiles, mLockscreenUserManager.mCurrentProfiles.size());
assertEquals(1, mLockscreenUserManager.mCurrentManagedProfiles.size());
}
diff --git a/services/tests/servicestests/src/com/android/server/pm/UserManagerTest.java b/services/tests/servicestests/src/com/android/server/pm/UserManagerTest.java
index 89c6a2201434..775d42a4df5f 100644
--- a/services/tests/servicestests/src/com/android/server/pm/UserManagerTest.java
+++ b/services/tests/servicestests/src/com/android/server/pm/UserManagerTest.java
@@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertWithMessage;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;
+import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertThrows;
import android.annotation.UserIdInt;
@@ -34,6 +35,7 @@ import android.os.Bundle;
import android.os.UserHandle;
import android.os.UserManager;
import android.platform.test.annotations.Postsubmit;
+import android.platform.test.annotations.RequiresFlagsEnabled;
import android.provider.Settings;
import android.test.suitebuilder.annotation.LargeTest;
import android.test.suitebuilder.annotation.MediumTest;
@@ -267,6 +269,34 @@ public final class UserManagerTest {
}
@Test
+ @RequiresFlagsEnabled(android.multiuser.Flags.FLAG_SUPPORT_COMMUNAL_PROFILE)
+ public void testGetProfilesIncludingCommunal() throws Exception {
+ int mainUserId = mUserManager.getMainUser().getIdentifier();
+ final UserInfo otherUser = createUser("TestUser", /* flags= */ 0);
+ final UserInfo profile = createProfileForUser("Profile",
+ UserManager.USER_TYPE_PROFILE_MANAGED, mainUserId);
+
+ final UserHandle communalProfile = mUserManager.getCommunalProfile();
+
+ final List<UserInfo> mainsActual = mUserManager.getProfilesIncludingCommunal(mainUserId);
+ final List<UserInfo> othersActual = mUserManager.getProfilesIncludingCommunal(otherUser.id);
+
+ final List<Integer> mainsExpected = new ArrayList<>();
+ mainsExpected.add(mainUserId);
+ if (profile != null) mainsExpected.add(profile.id);
+ if (communalProfile != null) mainsExpected.add(communalProfile.getIdentifier());
+ assertEquals(mainsExpected.stream().sorted().toList(),
+ mainsActual.stream().map(ui -> ui.id).sorted().toList());
+
+
+ final List<Integer> othersExpected = new ArrayList<>();
+ othersExpected.add(otherUser.id);
+ if (communalProfile != null) othersExpected.add(communalProfile.getIdentifier());
+ assertEquals(othersExpected.stream().sorted().toList(),
+ othersActual.stream().map(ui -> ui.id).sorted().toList());
+ }
+
+ @Test
public void testPrivateProfile() throws Exception {
UserHandle mainUser = mUserManager.getMainUser();
assumeTrue("Main user is null", mainUser != null);