Java Code Examples for android.content.pm.UserInfo#NO_PROFILE_GROUP_ID
The following examples show how to use
android.content.pm.UserInfo#NO_PROFILE_GROUP_ID .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserController.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Determines the list of users that should be stopped together with the specified * {@code userId}. The returned list includes {@code userId}. */ private @NonNull int[] getUsersToStopLU(int userId) { int startedUsersSize = mStartedUsers.size(); IntArray userIds = new IntArray(); userIds.add(userId); int userGroupId = mUserProfileGroupIds.get(userId, UserInfo.NO_PROFILE_GROUP_ID); for (int i = 0; i < startedUsersSize; i++) { UserState uss = mStartedUsers.valueAt(i); int startedUserId = uss.mHandle.getIdentifier(); // Skip unrelated users (profileGroupId mismatch) int startedUserGroupId = mUserProfileGroupIds.get(startedUserId, UserInfo.NO_PROFILE_GROUP_ID); boolean sameGroup = (userGroupId != UserInfo.NO_PROFILE_GROUP_ID) && (userGroupId == startedUserGroupId); // userId has already been added boolean sameUserId = startedUserId == userId; if (!sameGroup || sameUserId) { continue; } userIds.add(startedUserId); } return userIds.toArray(); }
Example 2
Source File: UserController.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Refreshes the list of users related to the current user when either a * user switch happens or when a new related user is started in the * background. */ private void updateCurrentProfileIds() { final List<UserInfo> profiles = mInjector.getUserManager().getProfiles(getCurrentUserId(), false /* enabledOnly */); 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; } final List<UserInfo> users = mInjector.getUserManager().getUsers(false); synchronized (mLock) { mCurrentProfileIds = currentProfileIds; mUserProfileGroupIds.clear(); for (int i = 0; i < users.size(); i++) { UserInfo user = users.get(i); if (user.profileGroupId != UserInfo.NO_PROFILE_GROUP_ID) { mUserProfileGroupIds.put(user.id, user.profileGroupId); } } } }
Example 3
Source File: UserManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private boolean isSameProfileGroupNoChecks(int userId, int otherUserId) { synchronized (mUsersLock) { UserInfo userInfo = getUserInfoLU(userId); if (userInfo == null || userInfo.profileGroupId == UserInfo.NO_PROFILE_GROUP_ID) { return false; } UserInfo otherUserInfo = getUserInfoLU(otherUserId); if (otherUserInfo == null || otherUserInfo.profileGroupId == UserInfo.NO_PROFILE_GROUP_ID) { return false; } return userInfo.profileGroupId == otherUserInfo.profileGroupId; } }
Example 4
Source File: UserManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private UserInfo getProfileParentLU(int userHandle) { UserInfo profile = getUserInfoLU(userHandle); if (profile == null) { return null; } int parentUserId = profile.profileGroupId; if (parentUserId == userHandle || parentUserId == UserInfo.NO_PROFILE_GROUP_ID) { return null; } else { return getUserInfoLU(parentUserId); } }
Example 5
Source File: UserManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@Override public ParcelFileDescriptor getUserIcon(int targetUserId) { String iconPath; synchronized (mPackagesLock) { UserInfo targetUserInfo = getUserInfoNoChecks(targetUserId); if (targetUserInfo == null || targetUserInfo.partial) { Slog.w(LOG_TAG, "getUserIcon: unknown user #" + targetUserId); return null; } final int callingUserId = UserHandle.getCallingUserId(); final int callingGroupId = getUserInfoNoChecks(callingUserId).profileGroupId; final int targetGroupId = targetUserInfo.profileGroupId; final boolean sameGroup = (callingGroupId != UserInfo.NO_PROFILE_GROUP_ID && callingGroupId == targetGroupId); if ((callingUserId != targetUserId) && !sameGroup) { checkManageUsersPermission("get the icon of a user who is not related"); } if (targetUserInfo.iconPath == null) { return null; } iconPath = targetUserInfo.iconPath; } try { return ParcelFileDescriptor.open( new File(iconPath), ParcelFileDescriptor.MODE_READ_ONLY); } catch (FileNotFoundException e) { Log.e(LOG_TAG, "Couldn't find icon file", e); } return null; }
Example 6
Source File: UserManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@Override public boolean isProfileAccessible(int callingUserId, int targetUserId, String debugMsg, boolean throwSecurityException) { if (targetUserId == callingUserId) { return true; } synchronized (mUsersLock) { UserInfo callingUserInfo = getUserInfoLU(callingUserId); if (callingUserInfo == null || callingUserInfo.isManagedProfile()) { if (throwSecurityException) { throw new SecurityException( debugMsg + " for another profile " + targetUserId + " from " + callingUserId); } } UserInfo targetUserInfo = getUserInfoLU(targetUserId); if (targetUserInfo == null || !targetUserInfo.isEnabled()) { // Do not throw any exception here as this could happen due to race conditions // between the system updating its state and the client getting notified. if (throwSecurityException) { Slog.w(LOG_TAG, debugMsg + " for disabled profile " + targetUserId + " from " + callingUserId); } return false; } if (targetUserInfo.profileGroupId == UserInfo.NO_PROFILE_GROUP_ID || targetUserInfo.profileGroupId != callingUserInfo.profileGroupId) { if (throwSecurityException) { throw new SecurityException( debugMsg + " for unrelated profile " + targetUserId); } return false; } } return true; }
Example 7
Source File: UserController.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
boolean isSameProfileGroup(int callingUserId, int targetUserId) { if (callingUserId == targetUserId) { return true; } synchronized (mLock) { int callingProfile = mUserProfileGroupIds.get(callingUserId, UserInfo.NO_PROFILE_GROUP_ID); int targetProfile = mUserProfileGroupIds.get(targetUserId, UserInfo.NO_PROFILE_GROUP_ID); return callingProfile != UserInfo.NO_PROFILE_GROUP_ID && callingProfile == targetProfile; } }
Example 8
Source File: UserController.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
boolean isUserOrItsParentRunning(int userId) { synchronized (mLock) { if (isUserRunning(userId, 0)) { return true; } final int parentUserId = mUserProfileGroupIds.get(userId, UserInfo.NO_PROFILE_GROUP_ID); if (parentUserId == UserInfo.NO_PROFILE_GROUP_ID) { return false; } return isUserRunning(parentUserId, 0); } }
Example 9
Source File: UserManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
private static boolean isProfileOf(UserInfo user, UserInfo profile) { return user.id == profile.id || (user.profileGroupId != UserInfo.NO_PROFILE_GROUP_ID && user.profileGroupId == profile.profileGroupId); }
Example 10
Source File: UserManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
@VisibleForTesting void writeUserLP(UserData userData, OutputStream os) throws IOException, XmlPullParserException { // XmlSerializer serializer = XmlUtils.serializerInstance(); final XmlSerializer serializer = new FastXmlSerializer(); serializer.setOutput(os, StandardCharsets.UTF_8.name()); serializer.startDocument(null, true); serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); final UserInfo userInfo = userData.info; serializer.startTag(null, TAG_USER); serializer.attribute(null, ATTR_ID, Integer.toString(userInfo.id)); serializer.attribute(null, ATTR_SERIAL_NO, Integer.toString(userInfo.serialNumber)); serializer.attribute(null, ATTR_FLAGS, Integer.toString(userInfo.flags)); serializer.attribute(null, ATTR_CREATION_TIME, Long.toString(userInfo.creationTime)); serializer.attribute(null, ATTR_LAST_LOGGED_IN_TIME, Long.toString(userInfo.lastLoggedInTime)); if (userInfo.lastLoggedInFingerprint != null) { serializer.attribute(null, ATTR_LAST_LOGGED_IN_FINGERPRINT, userInfo.lastLoggedInFingerprint); } if (userInfo.iconPath != null) { serializer.attribute(null, ATTR_ICON_PATH, userInfo.iconPath); } if (userInfo.partial) { serializer.attribute(null, ATTR_PARTIAL, "true"); } if (userInfo.guestToRemove) { serializer.attribute(null, ATTR_GUEST_TO_REMOVE, "true"); } if (userInfo.profileGroupId != UserInfo.NO_PROFILE_GROUP_ID) { serializer.attribute(null, ATTR_PROFILE_GROUP_ID, Integer.toString(userInfo.profileGroupId)); } serializer.attribute(null, ATTR_PROFILE_BADGE, Integer.toString(userInfo.profileBadge)); if (userInfo.restrictedProfileParentId != UserInfo.NO_PROFILE_GROUP_ID) { serializer.attribute(null, ATTR_RESTRICTED_PROFILE_PARENT_ID, Integer.toString(userInfo.restrictedProfileParentId)); } // Write seed data if (userData.persistSeedData) { if (userData.seedAccountName != null) { serializer.attribute(null, ATTR_SEED_ACCOUNT_NAME, userData.seedAccountName); } if (userData.seedAccountType != null) { serializer.attribute(null, ATTR_SEED_ACCOUNT_TYPE, userData.seedAccountType); } } if (userInfo.name != null) { serializer.startTag(null, TAG_NAME); serializer.text(userInfo.name); serializer.endTag(null, TAG_NAME); } synchronized (mRestrictionsLock) { UserRestrictionsUtils.writeRestrictions(serializer, mBaseUserRestrictions.get(userInfo.id), TAG_RESTRICTIONS); UserRestrictionsUtils.writeRestrictions(serializer, mDevicePolicyLocalUserRestrictions.get(userInfo.id), TAG_DEVICE_POLICY_RESTRICTIONS); UserRestrictionsUtils.writeRestrictions(serializer, mDevicePolicyGlobalUserRestrictions.get(userInfo.id), TAG_DEVICE_POLICY_GLOBAL_RESTRICTIONS); } if (userData.account != null) { serializer.startTag(null, TAG_ACCOUNT); serializer.text(userData.account); serializer.endTag(null, TAG_ACCOUNT); } if (userData.persistSeedData && userData.seedAccountOptions != null) { serializer.startTag(null, TAG_SEED_ACCOUNT_OPTIONS); userData.seedAccountOptions.saveToXml(serializer); serializer.endTag(null, TAG_SEED_ACCOUNT_OPTIONS); } serializer.endTag(null, TAG_USER); serializer.endDocument(); }