From 2a764949c943681a4d25a17a0b203a0127a4a486 Mon Sep 17 00:00:00 2001 From: Kenny Guy Date: Wed, 2 Apr 2014 13:29:20 +0100 Subject: [PATCH] Rename related users to profiles. Rename the related user concept as profiles. When returning profiles of a user include the user as a profile of itself. Change-Id: Id5d4f29017b7ca6844632ce643f10331ad733e1d --- cmds/pm/src/com/android/commands/pm/Pm.java | 10 +-- core/java/android/app/ActivityManager.java | 6 +- core/java/android/content/pm/UserInfo.java | 12 ++-- core/java/android/os/IUserManager.aidl | 4 +- core/java/android/os/UserManager.java | 38 ++++++++--- .../internal/inputmethod/InputMethodUtils.java | 13 ++-- .../android/systemui/recent/RecentTasksLoader.java | 4 +- .../android/systemui/recent/RecentsActivity.java | 2 +- .../recents/AlternateRecentsComponent.java | 4 +- .../systemui/recents/RecentsTaskLoader.java | 2 +- .../android/systemui/statusbar/BaseStatusBar.java | 27 ++++---- .../systemui/statusbar/phone/PhoneStatusBar.java | 8 +-- .../android/server/InputMethodManagerService.java | 22 +++---- .../android/server/am/ActivityManagerService.java | 65 +++++++++---------- .../java/com/android/server/am/ActivityStack.java | 19 +++--- .../notification/NotificationManagerService.java | 30 ++++----- .../com/android/server/pm/UserManagerService.java | 74 ++++++++++++---------- .../android/server/wm/WindowManagerService.java | 21 +++--- .../java/com/android/server/wm/WindowState.java | 2 +- 19 files changed, 193 insertions(+), 170 deletions(-) diff --git a/cmds/pm/src/com/android/commands/pm/Pm.java b/cmds/pm/src/com/android/commands/pm/Pm.java index f415c85e8e65..5454b46c4566 100644 --- a/cmds/pm/src/com/android/commands/pm/Pm.java +++ b/cmds/pm/src/com/android/commands/pm/Pm.java @@ -1033,18 +1033,18 @@ public final class Pm { public void runCreateUser() { String name; - int relatedUserId = -1; + int userId = -1; int flags = 0; String opt; while ((opt = nextOption()) != null) { - if ("--relatedTo".equals(opt)) { + if ("--profileOf".equals(opt)) { String optionData = nextOptionData(); if (optionData == null || !isNumber(optionData)) { System.err.println("Error: no USER_ID specified"); showUsage(); return; } else { - relatedUserId = Integer.parseInt(optionData); + userId = Integer.parseInt(optionData); } } else if ("--managed".equals(opt)) { flags |= UserInfo.FLAG_MANAGED_PROFILE; @@ -1062,14 +1062,14 @@ public final class Pm { name = arg; try { UserInfo info = null; - if (relatedUserId < 0) { + if (userId < 0) { info = mUm.createUser(name, flags); } else { if (Process.myUid() != 0) { System.err.println("Error: not running as root."); return; } - info = mUm.createRelatedUser(name, flags, relatedUserId); + info = mUm.createProfileForUser(name, flags, userId); } if (info != null) { System.out.println("Success: created user id " + info.id); diff --git a/core/java/android/app/ActivityManager.java b/core/java/android/app/ActivityManager.java index d386eff3df86..9d6a340c8aca 100644 --- a/core/java/android/app/ActivityManager.java +++ b/core/java/android/app/ActivityManager.java @@ -605,11 +605,11 @@ public class ActivityManager { public static final int RECENT_IGNORE_UNAVAILABLE = 0x0002; /** - * Provides a list that also contains recent tasks for user - * and related users. + * Provides a list that contains recent tasks for all + * profiles of a user. * @hide */ - public static final int RECENT_INCLUDE_RELATED = 0x0004; + public static final int RECENT_INCLUDE_PROFILES = 0x0004; /** * Return a list of the tasks that the user has recently launched, with diff --git a/core/java/android/content/pm/UserInfo.java b/core/java/android/content/pm/UserInfo.java index 6f1d4f89105c..f53aa4c378c0 100644 --- a/core/java/android/content/pm/UserInfo.java +++ b/core/java/android/content/pm/UserInfo.java @@ -71,7 +71,7 @@ public class UserInfo implements Parcelable { public static final int FLAG_MANAGED_PROFILE = 0x00000020; - public static final int NO_RELATED_GROUP_ID = -1; + public static final int NO_PROFILE_GROUP_ID = -1; public int id; public int serialNumber; @@ -80,7 +80,7 @@ public class UserInfo implements Parcelable { public int flags; public long creationTime; public long lastLoggedInTime; - public int relatedGroupId; + public int profileGroupId; /** User is only partially created. */ public boolean partial; @@ -94,7 +94,7 @@ public class UserInfo implements Parcelable { this.name = name; this.flags = flags; this.iconPath = iconPath; - this.relatedGroupId = NO_RELATED_GROUP_ID; + this.profileGroupId = NO_PROFILE_GROUP_ID; } public boolean isPrimary() { @@ -137,7 +137,7 @@ public class UserInfo implements Parcelable { creationTime = orig.creationTime; lastLoggedInTime = orig.lastLoggedInTime; partial = orig.partial; - relatedGroupId = orig.relatedGroupId; + profileGroupId = orig.profileGroupId; } public UserHandle getUserHandle() { @@ -162,7 +162,7 @@ public class UserInfo implements Parcelable { dest.writeLong(creationTime); dest.writeLong(lastLoggedInTime); dest.writeInt(partial ? 1 : 0); - dest.writeInt(relatedGroupId); + dest.writeInt(profileGroupId); } public static final Parcelable.Creator CREATOR @@ -184,6 +184,6 @@ public class UserInfo implements Parcelable { creationTime = source.readLong(); lastLoggedInTime = source.readLong(); partial = source.readInt() != 0; - relatedGroupId = source.readInt(); + profileGroupId = source.readInt(); } } diff --git a/core/java/android/os/IUserManager.aidl b/core/java/android/os/IUserManager.aidl index 6e6c06dba45a..1192a45f31eb 100644 --- a/core/java/android/os/IUserManager.aidl +++ b/core/java/android/os/IUserManager.aidl @@ -28,13 +28,13 @@ import android.graphics.Bitmap; */ interface IUserManager { UserInfo createUser(in String name, int flags); - UserInfo createRelatedUser(in String name, int flags, int relatedUserId); + UserInfo createProfileForUser(in String name, int flags, int userHandle); boolean removeUser(int userHandle); void setUserName(int userHandle, String name); void setUserIcon(int userHandle, in Bitmap icon); Bitmap getUserIcon(int userHandle); List getUsers(boolean excludeDying); - List getRelatedUsers(int userHandle); + List getProfiles(int userHandle); UserInfo getUserInfo(int userHandle); boolean isRestricted(); void setGuestEnabled(boolean enable); diff --git a/core/java/android/os/UserManager.java b/core/java/android/os/UserManager.java index 1ec5cd517621..520a08c0a0ab 100644 --- a/core/java/android/os/UserManager.java +++ b/core/java/android/os/UserManager.java @@ -410,20 +410,29 @@ public class UserManager { } /** - * Creates a user with the specified name and options. + * Renamed, just present to avoid multi project commit. + * TODO delete. + * @hide + */ + public UserInfo createRelatedUser(String name, int flags, int relatedUserId) { + return createProfileForUser(name, flags, relatedUserId); + } + + /** + * Creates a user with the specified name and options as a profile of another user. * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. * * @param name the user's name * @param flags flags that identify the type of user and other properties. * @see UserInfo - * @param relatedUserId new user will be related to this user id. + * @param userHandle new user will be a profile of this use. * * @return the UserInfo object for the created user, or null if the user could not be created. * @hide */ - public UserInfo createRelatedUser(String name, int flags, int relatedUserId) { + public UserInfo createProfileForUser(String name, int flags, int userHandle) { try { - return mService.createRelatedUser(name, flags, relatedUserId); + return mService.createProfileForUser(name, flags, userHandle); } catch (RemoteException re) { Log.w(TAG, "Could not create a user", re); return null; @@ -454,15 +463,26 @@ public class UserManager { } /** - * Returns information for all users related to userId - * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. - * @param userHandle users related to this user id will be returned. - * @return the list of related users. + * Renaming, left to avoid multi project commit. + * TODO Delete. * @hide */ public List getRelatedUsers(int userHandle) { + return getProfiles(userHandle); + } + + /** + * Returns list of the profiles of userHandle including + * userHandle itself. + * + * Requires {@link android.Manifest.permission#MANAGE_USERS} permission. + * @param userHandle profiles of this user will be returned. + * @return the list of profiles. + * @hide + */ + public List getProfiles(int userHandle) { try { - return mService.getRelatedUsers(userHandle); + return mService.getProfiles(userHandle); } catch (RemoteException re) { Log.w(TAG, "Could not get user list", re); return null; diff --git a/core/java/com/android/internal/inputmethod/InputMethodUtils.java b/core/java/com/android/internal/inputmethod/InputMethodUtils.java index 03a053c62093..f9e5569ba735 100644 --- a/core/java/com/android/internal/inputmethod/InputMethodUtils.java +++ b/core/java/com/android/internal/inputmethod/InputMethodUtils.java @@ -504,7 +504,7 @@ public class InputMethodUtils { private String mEnabledInputMethodsStrCache; private int mCurrentUserId; - private int[] mRelatedUserIds = new int[0]; + private int[] mCurrentProfileIds = new int[0]; private static void buildEnabledInputMethodsSettingString( StringBuilder builder, Pair> pair) { @@ -537,17 +537,16 @@ public class InputMethodUtils { mCurrentUserId = userId; } - public void setRelatedUserIds(int[] relatedUserIds) { + public void setCurrentProfileIds(int[] currentProfileIds) { synchronized (this) { - mRelatedUserIds = relatedUserIds; + mCurrentProfileIds = currentProfileIds; } } - public boolean isRelatedToOrCurrentUser(int userId) { + public boolean isCurrentProfile(int userId) { synchronized (this) { - if (userId == mCurrentUserId) return true; - for (int i = 0; i < mRelatedUserIds.length; i++) { - if (userId == mRelatedUserIds[i]) return true; + for (int i = 0; i < mCurrentProfileIds.length; i++) { + if (userId == mCurrentProfileIds[i]) return true; } return false; } diff --git a/packages/SystemUI/src/com/android/systemui/recent/RecentTasksLoader.java b/packages/SystemUI/src/com/android/systemui/recent/RecentTasksLoader.java index 9d2d6eeabc72..ab2ad966e97f 100644 --- a/packages/SystemUI/src/com/android/systemui/recent/RecentTasksLoader.java +++ b/packages/SystemUI/src/com/android/systemui/recent/RecentTasksLoader.java @@ -368,7 +368,7 @@ public class RecentTasksLoader implements View.OnTouchListener { final ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE); final List recentTasks = am.getRecentTasksForUser(1, - ActivityManager.RECENT_IGNORE_UNAVAILABLE | ActivityManager.RECENT_INCLUDE_RELATED, + ActivityManager.RECENT_IGNORE_UNAVAILABLE | ActivityManager.RECENT_INCLUDE_PROFILES, UserHandle.CURRENT.getIdentifier()); TaskDescription item = null; if (recentTasks.size() > 0) { @@ -441,7 +441,7 @@ public class RecentTasksLoader implements View.OnTouchListener { final List recentTasks = am.getRecentTasks(MAX_TASKS, ActivityManager.RECENT_IGNORE_UNAVAILABLE - | ActivityManager.RECENT_INCLUDE_RELATED); + | ActivityManager.RECENT_INCLUDE_PROFILES); int numTasks = recentTasks.size(); ActivityInfo homeInfo = new Intent(Intent.ACTION_MAIN) .addCategory(Intent.CATEGORY_HOME).resolveActivityInfo(pm, 0); diff --git a/packages/SystemUI/src/com/android/systemui/recent/RecentsActivity.java b/packages/SystemUI/src/com/android/systemui/recent/RecentsActivity.java index f75ea92ac759..7ab40b0744a0 100644 --- a/packages/SystemUI/src/com/android/systemui/recent/RecentsActivity.java +++ b/packages/SystemUI/src/com/android/systemui/recent/RecentsActivity.java @@ -165,7 +165,7 @@ public class RecentsActivity extends Activity { am.getRecentTasks(2, ActivityManager.RECENT_WITH_EXCLUDED | ActivityManager.RECENT_IGNORE_UNAVAILABLE | - ActivityManager.RECENT_INCLUDE_RELATED); + ActivityManager.RECENT_INCLUDE_PROFILES); if (recentTasks.size() > 1 && mRecentsPanel.simulateClick(recentTasks.get(1).persistentId)) { // recents panel will take care of calling show(false) through simulateClick diff --git a/packages/SystemUI/src/com/android/systemui/recents/AlternateRecentsComponent.java b/packages/SystemUI/src/com/android/systemui/recents/AlternateRecentsComponent.java index 1a616a058d00..227e19dd58d4 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/AlternateRecentsComponent.java +++ b/packages/SystemUI/src/com/android/systemui/recents/AlternateRecentsComponent.java @@ -221,7 +221,7 @@ public class AlternateRecentsComponent { Bitmap loadFirstTaskThumbnail() { ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE); List tasks = am.getRecentTasksForUser(1, - ActivityManager.RECENT_IGNORE_UNAVAILABLE | ActivityManager.RECENT_INCLUDE_RELATED, + ActivityManager.RECENT_IGNORE_UNAVAILABLE | ActivityManager.RECENT_INCLUDE_PROFILES, UserHandle.CURRENT.getIdentifier()); for (ActivityManager.RecentTaskInfo t : tasks) { // Skip tasks in the home stack @@ -239,7 +239,7 @@ public class AlternateRecentsComponent { boolean hasFirstTask() { ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE); List tasks = am.getRecentTasksForUser(1, - ActivityManager.RECENT_IGNORE_UNAVAILABLE | ActivityManager.RECENT_INCLUDE_RELATED, + ActivityManager.RECENT_IGNORE_UNAVAILABLE | ActivityManager.RECENT_INCLUDE_PROFILES, UserHandle.CURRENT.getIdentifier()); for (ActivityManager.RecentTaskInfo t : tasks) { // Skip tasks in the home stack diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsTaskLoader.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsTaskLoader.java index b497b69ce53e..65cbd620ef62 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/RecentsTaskLoader.java +++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsTaskLoader.java @@ -376,7 +376,7 @@ public class RecentsTaskLoader { // Get the recent tasks List tasks = am.getRecentTasksForUser(25, ActivityManager.RECENT_IGNORE_UNAVAILABLE | - ActivityManager.RECENT_INCLUDE_RELATED, UserHandle.CURRENT.getIdentifier()); + ActivityManager.RECENT_INCLUDE_PROFILES, UserHandle.CURRENT.getIdentifier()); Collections.reverse(tasks); Console.log(Constants.DebugFlags.App.TimeSystemCalls, "[RecentsTaskLoader|getRecentTasks]", diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java index bad56413e32a..e5e287dce8a1 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java @@ -134,7 +134,7 @@ public abstract class BaseStatusBar extends SystemUI implements protected PopupMenu mNotificationBlamePopup; protected int mCurrentUserId = 0; - final protected SparseArray mRelatedUsers = new SparseArray(); + final protected SparseArray mCurrentProfiles = new SparseArray(); protected int mLayoutDirection = -1; // invalid private Locale mLocale; @@ -244,21 +244,21 @@ public abstract class BaseStatusBar extends SystemUI implements String action = intent.getAction(); if (Intent.ACTION_USER_SWITCHED.equals(action)) { mCurrentUserId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1); - updateRelatedUserCache(); + updateCurrentProfilesCache(); if (true) Log.v(TAG, "userId " + mCurrentUserId + " is in the house"); userSwitched(mCurrentUserId); } else if (Intent.ACTION_USER_ADDED.equals(action)) { - updateRelatedUserCache(); + updateCurrentProfilesCache(); } } }; - private void updateRelatedUserCache() { - synchronized (mRelatedUsers) { - mRelatedUsers.clear(); + private void updateCurrentProfilesCache() { + synchronized (mCurrentProfiles) { + mCurrentProfiles.clear(); if (mUserManager != null) { - for (UserInfo related : mUserManager.getRelatedUsers(mCurrentUserId)) { - mRelatedUsers.put(related.id, related); + for (UserInfo user : mUserManager.getProfiles(mCurrentUserId)) { + mCurrentProfiles.put(user.id, user); } } } @@ -361,24 +361,23 @@ public abstract class BaseStatusBar extends SystemUI implements filter.addAction(Intent.ACTION_USER_ADDED); mContext.registerReceiver(mBroadcastReceiver, filter); - updateRelatedUserCache(); + updateCurrentProfilesCache(); } public void userSwitched(int newUserId) { // should be overridden } - public boolean notificationIsForCurrentOrRelatedUser(StatusBarNotification n) { + public boolean notificationIsForCurrentProfiles(StatusBarNotification n) { final int thisUserId = mCurrentUserId; final int notificationUserId = n.getUserId(); if (DEBUG && MULTIUSER_DEBUG) { Log.v(TAG, String.format("%s: current userid: %d, notification userid: %d", n, thisUserId, notificationUserId)); } - synchronized (mRelatedUsers) { + synchronized (mCurrentProfiles) { return notificationUserId == UserHandle.USER_ALL - || thisUserId == notificationUserId - || mRelatedUsers.get(notificationUserId) != null; + || mCurrentProfiles.get(notificationUserId) != null; } } @@ -1258,7 +1257,7 @@ public abstract class BaseStatusBar extends SystemUI implements updateNotificationVetoButton(oldEntry.row, notification); // Is this for you? - boolean isForCurrentUser = notificationIsForCurrentOrRelatedUser(notification); + boolean isForCurrentUser = notificationIsForCurrentProfiles(notification); if (DEBUG) Log.d(TAG, "notification is " + (isForCurrentUser ? "" : "not ") + "for you"); // Restart the ticker if it's still running diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java index e7f96dc3744b..2257aaae4ece 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java @@ -1078,8 +1078,8 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode { Entry ent = mNotificationData.get(N-i-1); if (!(provisioned || showNotificationEvenIfUnprovisioned(ent.notification))) continue; - // TODO How do we want to badge notifcations from related users. - if (!notificationIsForCurrentOrRelatedUser(ent.notification)) continue; + // TODO How do we want to badge notifcations from profiles. + if (!notificationIsForCurrentProfiles(ent.notification)) continue; final int vis = ent.notification.getNotification().visibility; if (vis != Notification.VISIBILITY_SECRET) { @@ -1138,7 +1138,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode { Entry ent = mNotificationData.get(N-i-1); if (!((provisioned && ent.notification.getScore() >= HIDE_ICONS_BELOW_SCORE) || showNotificationEvenIfUnprovisioned(ent.notification))) continue; - if (!notificationIsForCurrentOrRelatedUser(ent.notification)) continue; + if (!notificationIsForCurrentProfiles(ent.notification)) continue; if (isLockscreenPublicMode() && ent.notification.getNotification().visibility == Notification.VISIBILITY_SECRET @@ -2150,7 +2150,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode { if (!isDeviceProvisioned()) return; // not for you - if (!notificationIsForCurrentOrRelatedUser(n)) return; + if (!notificationIsForCurrentProfiles(n)) return; // Show the ticker if one is requested. Also don't do this // until status bar window is attached to the window manager, diff --git a/services/core/java/com/android/server/InputMethodManagerService.java b/services/core/java/com/android/server/InputMethodManagerService.java index 5fb64056cd21..e69c9a464760 100644 --- a/services/core/java/com/android/server/InputMethodManagerService.java +++ b/services/core/java/com/android/server/InputMethodManagerService.java @@ -445,7 +445,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub return; } else if (Intent.ACTION_USER_ADDED.equals(action) || Intent.ACTION_USER_REMOVED.equals(action)) { - updateRelatedUserIds(); + updateCurrentProfileIds(); return; } else { Slog.w(TAG, "Unexpected intent " + intent); @@ -689,7 +689,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub // mSettings should be created before buildInputMethodListLocked mSettings = new InputMethodSettings( mRes, context.getContentResolver(), mMethodMap, mMethodList, userId); - updateRelatedUserIds(); + updateCurrentProfileIds(); mFileManager = new InputMethodFileManager(mMethodMap, userId); mSwitchingController = new InputMethodSubtypeSwitchingController(mSettings); mSwitchingController.resetCircularListLocked(context); @@ -805,7 +805,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub private void switchUserLocked(int newUserId) { mSettings.setCurrentUserId(newUserId); - updateRelatedUserIds(); + updateCurrentProfileIds(); // InputMethodFileManager should be reset when the user is changed mFileManager = new InputMethodFileManager(mMethodMap, newUserId); final String defaultImiId = mSettings.getSelectedInputMethod(); @@ -826,14 +826,14 @@ public class InputMethodManagerService extends IInputMethodManager.Stub } } - void updateRelatedUserIds() { - List relatedUsers = - UserManager.get(mContext).getRelatedUsers(mSettings.getCurrentUserId()); - int[] relatedUserIds = new int[relatedUsers.size()]; // relatedUsers will not be null - for (int i = 0; i < relatedUserIds.length; i++) { - relatedUserIds[i] = relatedUsers.get(i).id; + void updateCurrentProfileIds() { + List profiles = + UserManager.get(mContext).getProfiles(mSettings.getCurrentUserId()); + int[] currentProfileIds = new int[profiles.size()]; // profiles will not be null + for (int i = 0; i < currentProfileIds.length; i++) { + currentProfileIds[i] = profiles.get(i).id; } - mSettings.setRelatedUserIds(relatedUserIds); + mSettings.setCurrentProfileIds(currentProfileIds); } @Override @@ -931,7 +931,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub + mSettings.getCurrentUserId() + ", calling pid = " + Binder.getCallingPid() + InputMethodUtils.getApiCallStack()); } - if (uid == Process.SYSTEM_UID || mSettings.isRelatedToOrCurrentUser(userId)) { + if (uid == Process.SYSTEM_UID || mSettings.isCurrentProfile(userId)) { return true; } diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index 004d4febae5c..4824f30f3b82 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -1020,7 +1020,7 @@ public final class ActivityManagerService extends ActivityManagerNative final ActivityThread mSystemThread; int mCurrentUserId = 0; - int[] mRelatedUserIds = new int[0]; // Accessed by ActivityStack + int[] mCurrentProfileIds = new int[0]; // Accessed by ActivityStack private UserManagerService mUserManager; private final class AppDeathRecipient implements IBinder.DeathRecipient { @@ -1079,7 +1079,7 @@ public final class ActivityManagerService extends ActivityManagerNative static final int IMMERSIVE_MODE_LOCK_MSG = 37; static final int PERSIST_URI_GRANTS_MSG = 38; static final int REQUEST_ALL_PSS_MSG = 39; - static final int START_RELATED_USERS_MSG = 40; + static final int START_PROFILES_MSG = 40; static final int UPDATE_TIME = 41; static final int FIRST_ACTIVITY_STACK_MSG = 100; @@ -1694,9 +1694,9 @@ public final class ActivityManagerService extends ActivityManagerNative requestPssAllProcsLocked(SystemClock.uptimeMillis(), true, false); break; } - case START_RELATED_USERS_MSG: { + case START_PROFILES_MSG: { synchronized (ActivityManagerService.this) { - startRelatedUsersLocked(); + startProfilesLocked(); } break; } @@ -5209,7 +5209,7 @@ public final class ActivityManagerService extends ActivityManagerNative userId); } } - scheduleStartRelatedUsersLocked(); + scheduleStartProfilesLocked(); } } } @@ -6864,8 +6864,8 @@ public final class ActivityManagerService extends ActivityManagerNative maxNum < N ? maxNum : N); final Set includedUsers; - if ((flags & ActivityManager.RECENT_INCLUDE_RELATED) != 0) { - includedUsers = getRelatedUsersLocked(userId); + if ((flags & ActivityManager.RECENT_INCLUDE_PROFILES) != 0) { + includedUsers = getProfileIdsLocked(userId); } else { includedUsers = new HashSet(); } @@ -16318,19 +16318,19 @@ public final class ActivityManagerService extends ActivityManagerNative * user switch happens or when a new related user is started in the * background. */ - private void updateRelatedUserIdsLocked() { - final List relatedUsers = getUserManagerLocked().getRelatedUsers(mCurrentUserId); - int[] relatedUserIds = new int[relatedUsers.size()]; // relatedUsers will not be null - for (int i = 0; i < relatedUserIds.length; i++) { - relatedUserIds[i] = relatedUsers.get(i).id; + private void updateCurrentProfileIdsLocked() { + final List profiles = getUserManagerLocked().getProfiles(mCurrentUserId); + int[] currentProfileIds = new int[profiles.size()]; // profiles will not be null + for (int i = 0; i < currentProfileIds.length; i++) { + currentProfileIds[i] = profiles.get(i).id; } - mRelatedUserIds = relatedUserIds; + mCurrentProfileIds = currentProfileIds; } - private Set getRelatedUsersLocked(int userId) { + private Set getProfileIdsLocked(int userId) { Set userIds = new HashSet(); - final List relatedUsers = getUserManagerLocked().getRelatedUsers(userId); - for (UserInfo user : relatedUsers) { + final List profiles = getUserManagerLocked().getProfiles(userId); + for (UserInfo user : profiles) { userIds.add(Integer.valueOf(user.id)); } return userIds; @@ -16391,15 +16391,15 @@ public final class ActivityManagerService extends ActivityManagerNative if (foreground) { mCurrentUserId = userId; - updateRelatedUserIdsLocked(); - mWindowManager.setCurrentUser(userId, mRelatedUserIds); + updateCurrentProfileIdsLocked(); + mWindowManager.setCurrentUser(userId, mCurrentProfileIds); // Once the internal notion of the active user has switched, we lock the device // with the option to show the user switcher on the keyguard. mWindowManager.lockNow(null); } else { final Integer currentUserIdInt = Integer.valueOf(mCurrentUserId); - updateRelatedUserIdsLocked(); - mWindowManager.updateRelatedUserIds(mRelatedUserIds); + updateCurrentProfileIdsLocked(); + mWindowManager.setCurrentProfileIds(mCurrentProfileIds); mUserLru.remove(currentUserIdInt); mUserLru.add(currentUserIdInt); } @@ -16619,20 +16619,21 @@ public final class ActivityManagerService extends ActivityManagerNative } } - void scheduleStartRelatedUsersLocked() { - if (!mHandler.hasMessages(START_RELATED_USERS_MSG)) { - mHandler.sendMessageDelayed(mHandler.obtainMessage(START_RELATED_USERS_MSG), + void scheduleStartProfilesLocked() { + if (!mHandler.hasMessages(START_PROFILES_MSG)) { + mHandler.sendMessageDelayed(mHandler.obtainMessage(START_PROFILES_MSG), DateUtils.SECOND_IN_MILLIS); } } - void startRelatedUsersLocked() { - if (DEBUG_MU) Slog.i(TAG_MU, "startRelatedUsersLocked"); - List relatedUsers = getUserManagerLocked().getRelatedUsers(mCurrentUserId); - List toStart = new ArrayList(relatedUsers.size()); - for (UserInfo relatedUser : relatedUsers) { - if ((relatedUser.flags & UserInfo.FLAG_INITIALIZED) == UserInfo.FLAG_INITIALIZED) { - toStart.add(relatedUser); + void startProfilesLocked() { + if (DEBUG_MU) Slog.i(TAG_MU, "startProfilesLocked"); + List profiles = getUserManagerLocked().getProfiles(mCurrentUserId); + List toStart = new ArrayList(profiles.size()); + for (UserInfo user : profiles) { + if ((user.flags & UserInfo.FLAG_INITIALIZED) == UserInfo.FLAG_INITIALIZED + && user.id != mCurrentUserId) { + toStart.add(user); } } final int n = toStart.size(); @@ -16641,7 +16642,7 @@ public final class ActivityManagerService extends ActivityManagerNative startUserInBackground(toStart.get(i).id); } if (i < n) { - Slog.w(TAG_MU, "More related users than MAX_RUNNING_USERS"); + Slog.w(TAG_MU, "More profiles than MAX_RUNNING_USERS"); } } @@ -16660,7 +16661,7 @@ public final class ActivityManagerService extends ActivityManagerNative true, false, MY_PID, Process.SYSTEM_UID, userId); } - startRelatedUsersLocked(); + startProfilesLocked(); int num = mUserLru.size(); int i = 0; diff --git a/services/core/java/com/android/server/am/ActivityStack.java b/services/core/java/com/android/server/am/ActivityStack.java index 6ee3e07a8a87..d949ba0d90e3 100755 --- a/services/core/java/com/android/server/am/ActivityStack.java +++ b/services/core/java/com/android/server/am/ActivityStack.java @@ -341,18 +341,17 @@ final class ActivityStack { } /** - * Checks whether the userid is either the current user or a related user. + * Checks whether the userid is a profile of the current user. */ - private boolean isRelatedToOrCurrentUserLocked(int userId) { - if (mCurrentUser == userId) return true; - for (int i = 0; i < mService.mRelatedUserIds.length; i++) { - if (mService.mRelatedUserIds[i] == userId) return true; + private boolean isCurrentProfileLocked(int userId) { + for (int i = 0; i < mService.mCurrentProfileIds.length; i++) { + if (mService.mCurrentProfileIds[i] == userId) return true; } return false; } boolean okToShowLocked(ActivityRecord r) { - return isRelatedToOrCurrentUserLocked(r.userId) + return isCurrentProfileLocked(r.userId) || (r.info.flags & ActivityInfo.FLAG_SHOW_ON_LOCK_SCREEN) != 0; } @@ -571,7 +570,7 @@ final class ActivityStack { for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) { TaskRecord task = mTaskHistory.get(taskNdx); - if (!isRelatedToOrCurrentUserLocked(task.userId)) { + if (!isCurrentProfileLocked(task.userId)) { return null; } final ArrayList activities = task.mActivities; @@ -602,7 +601,7 @@ final class ActivityStack { int index = mTaskHistory.size(); for (int i = 0; i < index; ) { TaskRecord task = mTaskHistory.get(i); - if (isRelatedToOrCurrentUserLocked(task.userId)) { + if (isCurrentProfileLocked(task.userId)) { if (DEBUG_TASKS) Slog.d(TAG, "switchUserLocked: stack=" + getStackId() + " moving " + task + " to top"); mTaskHistory.remove(i); @@ -1766,10 +1765,10 @@ final class ActivityStack { mTaskHistory.remove(task); // Now put task at top. int stackNdx = mTaskHistory.size(); - if (!isRelatedToOrCurrentUserLocked(task.userId)) { + if (!isCurrentProfileLocked(task.userId)) { // Put non-current user tasks below current user tasks. while (--stackNdx >= 0) { - if (!isRelatedToOrCurrentUserLocked(mTaskHistory.get(stackNdx).userId)) { + if (!isCurrentProfileLocked(mTaskHistory.get(stackNdx).userId)) { break; } } diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index b4f7ae6785a7..3b6d2886df7f 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -219,8 +219,8 @@ public class NotificationManagerService extends SystemService { )); private static final String EXTRA_INTERCEPT = "android.intercept"; - // Users related to the current user. - final protected SparseArray mRelatedUsers = new SparseArray(); + // Profiles of the current user. + final protected SparseArray mCurrentProfiles = new SparseArray(); private static final int MY_UID = Process.myUid(); private static final int MY_PID = Process.myPid(); @@ -1120,9 +1120,9 @@ public class NotificationManagerService extends SystemService { } else if (action.equals(Intent.ACTION_USER_SWITCHED)) { // reload per-user settings mSettingsObserver.update(null); - updateRelatedUserCache(context); + updateCurrentProfilesCache(context); } else if (action.equals(Intent.ACTION_USER_ADDED)) { - updateRelatedUserCache(context); + updateCurrentProfilesCache(context); } } }; @@ -2458,12 +2458,12 @@ public class NotificationManagerService extends SystemService { /** * Determine whether the userId applies to the notification in question, either because * they match exactly, or one of them is USER_ALL (which is treated as a wildcard) or - * because it matches a related user. + * because it matches one of the users profiles. */ - private boolean notificationMatchesUserIdOrRelated(NotificationRecord r, int userId) { - synchronized (mRelatedUsers) { + private boolean notificationMatchesCurrentProfiles(NotificationRecord r, int userId) { + synchronized (mCurrentProfiles) { return notificationMatchesUserId(r, userId) - || mRelatedUsers.get(r.getUserId()) != null; + || mCurrentProfiles.get(r.getUserId()) != null; } } @@ -2561,7 +2561,7 @@ public class NotificationManagerService extends SystemService { final int N = mNotificationList.size(); for (int i=N-1; i>=0; i--) { NotificationRecord r = mNotificationList.get(i); - if (!notificationMatchesUserIdOrRelated(r, userId)) { + if (!notificationMatchesCurrentProfiles(r, userId)) { continue; } @@ -2676,15 +2676,15 @@ public class NotificationManagerService extends SystemService { exceptionPackages); } - private void updateRelatedUserCache(Context context) { + private void updateCurrentProfilesCache(Context context) { UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE); int currentUserId = ActivityManager.getCurrentUser(); if (userManager != null) { - List relatedUsers = userManager.getRelatedUsers(currentUserId); - synchronized (mRelatedUsers) { - mRelatedUsers.clear(); - for (UserInfo related : relatedUsers) { - mRelatedUsers.put(related.id, related); + List profiles = userManager.getProfiles(currentUserId); + synchronized (mCurrentProfiles) { + mCurrentProfiles.clear(); + for (UserInfo user : profiles) { + mCurrentProfiles.put(user.id, user); } } } diff --git a/services/core/java/com/android/server/pm/UserManagerService.java b/services/core/java/com/android/server/pm/UserManagerService.java index 7f55464ca514..a39e958a5b6f 100644 --- a/services/core/java/com/android/server/pm/UserManagerService.java +++ b/services/core/java/com/android/server/pm/UserManagerService.java @@ -92,7 +92,7 @@ public class UserManagerService extends IUserManager.Stub { private static final String ATTR_NEXT_SERIAL_NO = "nextSerialNumber"; private static final String ATTR_PARTIAL = "partial"; private static final String ATTR_USER_VERSION = "version"; - private static final String ATTR_RELATED_GROUP_ID = "relatedGroupId"; + private static final String ATTR_PROFILE_GROUP_ID = "profileGroupId"; private static final String TAG_USERS = "users"; private static final String TAG_USER = "user"; private static final String TAG_RESTRICTIONS = "restrictions"; @@ -257,26 +257,26 @@ public class UserManagerService extends IUserManager.Stub { } @Override - public List getRelatedUsers(int userId) { + public List getProfiles(int userId) { checkManageUsersPermission("query users"); synchronized (mPackagesLock) { UserInfo user = getUserInfoLocked(userId); ArrayList users = new ArrayList(mUsers.size()); for (int i = 0; i < mUsers.size(); i++) { - UserInfo ui = mUsers.valueAt(i); - if (!areRelatedUsers(user, ui)) { + UserInfo profile = mUsers.valueAt(i); + if (!isProfileOf(user, profile)) { continue; } - users.add(ui); + users.add(profile); } return users; } } - private boolean areRelatedUsers(UserInfo user1, UserInfo user2) { - return user1.relatedGroupId != UserInfo.NO_RELATED_GROUP_ID && - user1.relatedGroupId == user2.relatedGroupId && - user1.id != user2.id; + private boolean isProfileOf(UserInfo user, UserInfo profile) { + return user.id == profile.id || + (user.profileGroupId != UserInfo.NO_PROFILE_GROUP_ID + && user.profileGroupId == profile.profileGroupId); } @Override @@ -684,9 +684,9 @@ public class UserManagerService extends IUserManager.Stub { if (userInfo.partial) { serializer.attribute(null, ATTR_PARTIAL, "true"); } - if (userInfo.relatedGroupId != UserInfo.NO_RELATED_GROUP_ID) { - serializer.attribute(null, ATTR_RELATED_GROUP_ID, - Integer.toString(userInfo.relatedGroupId)); + if (userInfo.profileGroupId != UserInfo.NO_PROFILE_GROUP_ID) { + serializer.attribute(null, ATTR_PROFILE_GROUP_ID, + Integer.toString(userInfo.profileGroupId)); } serializer.startTag(null, TAG_NAME); @@ -771,7 +771,7 @@ public class UserManagerService extends IUserManager.Stub { long salt = 0L; String pinHash = null; int failedAttempts = 0; - int relatedGroupId = UserInfo.NO_RELATED_GROUP_ID; + int profileGroupId = UserInfo.NO_PROFILE_GROUP_ID; long lastAttemptTime = 0L; boolean partial = false; Bundle restrictions = new Bundle(); @@ -809,8 +809,14 @@ public class UserManagerService extends IUserManager.Stub { pinHash = parser.getAttributeValue(null, ATTR_PIN_HASH); failedAttempts = readIntAttribute(parser, ATTR_FAILED_ATTEMPTS, 0); lastAttemptTime = readLongAttribute(parser, ATTR_LAST_RETRY_MS, 0L); - relatedGroupId = readIntAttribute(parser, ATTR_RELATED_GROUP_ID, - UserInfo.NO_RELATED_GROUP_ID); + profileGroupId = readIntAttribute(parser, ATTR_PROFILE_GROUP_ID, + UserInfo.NO_PROFILE_GROUP_ID); + if (profileGroupId == UserInfo.NO_PROFILE_GROUP_ID) { + // This attribute was added and renamed during development of L. + // TODO Remove upgrade path by 1st May 2014 + profileGroupId = readIntAttribute(parser, "relatedGroupId", + UserInfo.NO_PROFILE_GROUP_ID); + } String valueString = parser.getAttributeValue(null, ATTR_PARTIAL); if ("true".equals(valueString)) { partial = true; @@ -849,7 +855,7 @@ public class UserManagerService extends IUserManager.Stub { userInfo.creationTime = creationTime; userInfo.lastLoggedInTime = lastLoggedInTime; userInfo.partial = partial; - userInfo.relatedGroupId = relatedGroupId; + userInfo.profileGroupId = profileGroupId; mUserRestrictions.append(id, restrictions); if (salt != 0L) { RestrictionsPinState pinState = mRestrictionsPinStates.get(id); @@ -964,25 +970,25 @@ public class UserManagerService extends IUserManager.Stub { } } - private int getNextRelatedGroupIdLocked() { - int maxGroupId = UserInfo.NO_RELATED_GROUP_ID; + private int getNextProfileGroupIdLocked() { + int maxGroupId = UserInfo.NO_PROFILE_GROUP_ID; for (int i = 0; i < mUsers.size(); i++) { UserInfo ui = mUsers.valueAt(i); - if (maxGroupId < ui.relatedGroupId) { - maxGroupId = ui.relatedGroupId; + if (maxGroupId < ui.profileGroupId) { + maxGroupId = ui.profileGroupId; } } return maxGroupId + 1; } @Override - public UserInfo createRelatedUser(String name, int flags, int relatedUserId) { + public UserInfo createProfileForUser(String name, int flags, int userId) { checkManageUsersPermission("Only the system can create users"); - if (relatedUserId != UserHandle.USER_OWNER) { - Slog.w(LOG_TAG, "Only user owner can have related users"); + if (userId != UserHandle.USER_OWNER) { + Slog.w(LOG_TAG, "Only user owner can have profiles"); return null; } - return createUserInternal(name, flags, relatedUserId); + return createUserInternal(name, flags, userId); } @Override @@ -991,16 +997,16 @@ public class UserManagerService extends IUserManager.Stub { return createUserInternal(name, flags, UserHandle.USER_NULL); } - private UserInfo createUserInternal(String name, int flags, int relatedUserId) { + private UserInfo createUserInternal(String name, int flags, int profileId) { final long ident = Binder.clearCallingIdentity(); UserInfo userInfo = null; try { synchronized (mInstallLock) { synchronized (mPackagesLock) { - UserInfo relatedUser = null; - if (relatedUserId != UserHandle.USER_NULL) { - relatedUser = getUserInfoLocked(relatedUserId); - if (relatedUser == null) return null; + UserInfo profile = null; + if (profileId != UserHandle.USER_NULL) { + profile = getUserInfoLocked(profileId); + if (profile == null) return null; } if (isUserLimitReachedLocked()) return null; int userId = getNextAvailableIdLocked(); @@ -1013,12 +1019,12 @@ public class UserManagerService extends IUserManager.Stub { Environment.getUserSystemDirectory(userInfo.id).mkdirs(); mUsers.put(userId, userInfo); writeUserListLocked(); - if (relatedUser != null) { - if (relatedUser.relatedGroupId == UserInfo.NO_RELATED_GROUP_ID) { - relatedUser.relatedGroupId = getNextRelatedGroupIdLocked(); + if (profile != null) { + if (profile.profileGroupId == UserInfo.NO_PROFILE_GROUP_ID) { + profile.profileGroupId = getNextProfileGroupIdLocked(); + writeUserLocked(profile); } - userInfo.relatedGroupId = relatedUser.relatedGroupId; - writeUserLocked(relatedUser); + userInfo.profileGroupId = profile.profileGroupId; } writeUserLocked(userInfo); mPm.createNewUserLILPw(userId, userPath); diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index dcf588021502..d4670fb7c1f9 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -302,14 +302,14 @@ public class WindowManagerService extends IWindowManager.Stub /** * Current user when multi-user is enabled. Don't show windows of - * non-current user. Also see mRelatedUserIds. + * non-current user. Also see mCurrentProfileIds. */ int mCurrentUserId; /** - * Users related to the current user. These are also allowed to show windows + * Users that are profiles of the current user. These are also allowed to show windows * on the current user. */ - int[] mRelatedUserIds = new int[0]; + int[] mCurrentProfileIds = new int[0]; final Context mContext; @@ -5225,16 +5225,16 @@ public class WindowManagerService extends IWindowManager.Stub ShutdownThread.rebootSafeMode(mContext, confirm); } - public void updateRelatedUserIds(final int[] relatedUserIds) { + public void setCurrentProfileIds(final int[] currentProfileIds) { synchronized (mWindowMap) { - mRelatedUserIds = relatedUserIds; + mCurrentProfileIds = currentProfileIds; } } - public void setCurrentUser(final int newUserId, final int[] relatedUserIds) { + public void setCurrentUser(final int newUserId, final int[] currentProfileIds) { synchronized (mWindowMap) { mCurrentUserId = newUserId; - mRelatedUserIds = relatedUserIds; + mCurrentProfileIds = currentProfileIds; mAppTransition.setCurrentUser(newUserId); mPolicy.setCurrentUserLw(newUserId); @@ -5250,10 +5250,9 @@ public class WindowManagerService extends IWindowManager.Stub } /* Called by WindowState */ - boolean isRelatedToOrCurrentUserLocked(int userId) { - if (userId == mCurrentUserId) return true; - for (int i = 0; i < mRelatedUserIds.length; i++) { - if (mRelatedUserIds[i] == userId) return true; + boolean isCurrentProfileLocked(int userId) { + for (int i = 0; i < mCurrentProfileIds.length; i++) { + if (mCurrentProfileIds[i] == userId) return true; } return false; } diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java index 2c0e99ed1289..dff75efd64dc 100644 --- a/services/core/java/com/android/server/wm/WindowState.java +++ b/services/core/java/com/android/server/wm/WindowState.java @@ -1249,7 +1249,7 @@ final class WindowState implements WindowManagerPolicy.WindowState { } return win.mShowToOwnerOnly - && !mService.isRelatedToOrCurrentUserLocked(UserHandle.getUserId(win.mOwnerUid)); + && !mService.isCurrentProfileLocked(UserHandle.getUserId(win.mOwnerUid)); } private static void applyInsets(Region outRegion, Rect frame, Rect inset) { -- 2.11.0