Java Code Examples for android.content.pm.UserInfo#isManagedProfile()
The following examples show how to use
android.content.pm.UserInfo#isManagedProfile() .
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: LocalImageLoader.java From AppOpsX with MIT License | 6 votes |
public static Drawable getDrawable(Context context, AppInfo appInfo) { init(context); Drawable drawable = sLruCache.get(appInfo.packageName); if (drawable == null && appInfo.applicationInfo != null) { if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP_MR1) { drawable = appInfo.applicationInfo.loadUnbadgedIcon(context.getPackageManager()); }else { drawable = appInfo.applicationInfo.loadIcon(context.getPackageManager()); } UserInfo currentUser = Users.getInstance().getCurrentUser(); if(currentUser != null && currentUser.isManagedProfile()){ drawable = context.getPackageManager().getUserBadgedIcon(drawable,currentUser.getUserHandle()); } sLruCache.put(appInfo.packageName, drawable); } return drawable; }
Example 2
Source File: BaseSettingsProviderTest.java From Study_Android_Demo with Apache License 2.0 | 6 votes |
protected int getSecondaryUserId() { if (mSecondaryUserId == Integer.MIN_VALUE) { UserManager userManager = (UserManager) getContext() .getSystemService(Context.USER_SERVICE); List<UserInfo> users = userManager.getUsers(); final int userCount = users.size(); for (int i = 0; i < userCount; i++) { UserInfo user = users.get(i); if (!user.isPrimary() && !user.isManagedProfile()) { mSecondaryUserId = user.id; return mSecondaryUserId; } } } if (mSecondaryUserId == Integer.MIN_VALUE) { mSecondaryUserId = UserHandle.USER_SYSTEM; } return mSecondaryUserId; }
Example 3
Source File: LauncherAppsService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Checks if the calling user is in the same group as {@code targetUser}, and allowed * to access it. * * @return TRUE if the calling user can access {@code targetUserId}. FALSE if not *but * they're still in the same profile group*. * * @throws SecurityException if the calling user and {@code targetUser} are not in the same * group. */ private boolean canAccessProfile(int targetUserId, String message) { final int callingUserId = injectCallingUserId(); if (targetUserId == callingUserId) return true; long ident = injectClearCallingIdentity(); try { final UserInfo callingUserInfo = mUm.getUserInfo(callingUserId); if (callingUserInfo != null && callingUserInfo.isManagedProfile()) { Slog.w(TAG, message + " for another profile " + targetUserId + " from " + callingUserId + " not allowed"); return false; } } finally { injectRestoreCallingIdentity(ident); } return mUserManagerInternal.isProfileAccessible(injectCallingUserId(), targetUserId, message, true); }
Example 4
Source File: UserManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@VisibleForTesting int getFreeProfileBadgeLU(int parentUserId) { int maxManagedProfiles = getMaxManagedProfiles(); boolean[] usedBadges = new boolean[maxManagedProfiles]; final int userSize = mUsers.size(); for (int i = 0; i < userSize; i++) { UserInfo ui = mUsers.valueAt(i).info; // Check which badge indexes are already used by this profile group. if (ui.isManagedProfile() && ui.profileGroupId == parentUserId && !mRemovingUserIds.get(ui.id) && ui.profileBadge < maxManagedProfiles) { usedBadges[ui.profileBadge] = true; } } for (int i = 0; i < maxManagedProfiles; i++) { if (!usedBadges[i]) { return i; } } return 0; }
Example 5
Source File: UserManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Removes a user and all data directories created for that user. This method should be called * after the user's processes have been terminated. * @param userHandle the user's id */ @Override public boolean removeUser(int userHandle) { Slog.i(LOG_TAG, "removeUser u" + userHandle); checkManageOrCreateUsersPermission("Only the system can remove users"); final boolean isManagedProfile; synchronized (mUsersLock) { UserInfo userInfo = getUserInfoLU(userHandle); isManagedProfile = userInfo != null && userInfo.isManagedProfile(); } String restriction = isManagedProfile ? UserManager.DISALLOW_REMOVE_MANAGED_PROFILE : UserManager.DISALLOW_REMOVE_USER; if (getUserRestrictions(UserHandle.getCallingUserId()).getBoolean(restriction, false)) { Log.w(LOG_TAG, "Cannot remove user. " + restriction + " is enabled."); return false; } return removeUserUnchecked(userHandle); }
Example 6
Source File: LockSettingsService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * If the account is credential-encrypted, show notification requesting the user to unlock the * device. */ private void maybeShowEncryptionNotificationForUser(@UserIdInt int userId) { final UserInfo user = mUserManager.getUserInfo(userId); if (!user.isManagedProfile()) { // When the user is locked, we communicate it loud-and-clear // on the lockscreen; we only show a notification below for // locked managed profiles. return; } final UserHandle userHandle = user.getUserHandle(); final boolean isSecure = isUserSecure(userId); if (isSecure && !mUserManager.isUserUnlockingOrUnlocked(userHandle)) { UserInfo parent = mUserManager.getProfileParent(userId); if (parent != null && mUserManager.isUserUnlockingOrUnlocked(parent.getUserHandle()) && !mUserManager.isQuietModeEnabled(userHandle)) { // Only show notifications for managed profiles once their parent // user is unlocked. showEncryptionNotificationForProfile(userHandle); } } }
Example 7
Source File: FingerprintService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * @param userId * @return true if this is a work profile */ private boolean isWorkProfile(int userId) { UserInfo userInfo = null; final long token = Binder.clearCallingIdentity(); try { userInfo = mUserManager.getUserInfo(userId); } finally { Binder.restoreCallingIdentity(token); } return userInfo != null && userInfo.isManagedProfile(); }
Example 8
Source File: WallpaperManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
public boolean hasNamedWallpaper(String name) { synchronized (mLock) { List<UserInfo> users; long ident = Binder.clearCallingIdentity(); try { users = ((UserManager) mContext.getSystemService(Context.USER_SERVICE)).getUsers(); } finally { Binder.restoreCallingIdentity(ident); } for (UserInfo user: users) { // ignore managed profiles if (user.isManagedProfile()) { continue; } WallpaperData wd = mWallpaperMap.get(user.id); if (wd == null) { // User hasn't started yet, so load her settings to peek at the wallpaper loadSettingsLocked(user.id, false); wd = mWallpaperMap.get(user.id); } if (wd != null && name.equals(wd.name)) { return true; } } } return false; }
Example 9
Source File: ApplicationPackageManager.java From AndroidComponentPlugin with Apache License 2.0 | 5 votes |
private int getBadgeResIdForUser(int userHandle) { // Return the framework-provided badge. UserInfo userInfo = getUserIfProfile(userHandle); if (userInfo != null && userInfo.isManagedProfile()) { return com.android.internal.R.drawable.ic_corp_icon_badge; } return 0; }
Example 10
Source File: CallLog.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** @hide */ public static boolean shouldHaveSharedCallLogEntries(Context context, UserManager userManager, int userId) { if (userManager.hasUserRestriction(UserManager.DISALLOW_OUTGOING_CALLS, UserHandle.of(userId))) { return false; } final UserInfo userInfo = userManager.getUserInfo(userId); return userInfo != null && !userInfo.isManagedProfile(); }
Example 11
Source File: LockSettingsService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Synchronize all profile's work challenge of the given user if it's unified: tie or clear them * depending on the parent user's secure state. * * When clearing tied work challenges, a pre-computed password table for profiles are required, * since changing password for profiles requires existing password, and existing passwords can * only be computed before the parent user's password is cleared. * * Strictly this is a recursive function, since setLockCredentialInternal ends up calling this * method again on profiles. However the recursion is guaranteed to terminate as this method * terminates when the user is a managed profile. */ private void synchronizeUnifiedWorkChallengeForProfiles(int userId, Map<Integer, String> profilePasswordMap) throws RemoteException { if (mUserManager.getUserInfo(userId).isManagedProfile()) { return; } final boolean isSecure = isUserSecure(userId); final List<UserInfo> profiles = mUserManager.getProfiles(userId); final int size = profiles.size(); for (int i = 0; i < size; i++) { final UserInfo profile = profiles.get(i); if (profile.isManagedProfile()) { final int managedUserId = profile.id; if (mLockPatternUtils.isSeparateProfileChallengeEnabled(managedUserId)) { continue; } if (isSecure) { tieManagedProfileLockIfNecessary(managedUserId, null); } else { // We use cached work profile password computed before clearing the parent's // credential, otherwise they get lost if (profilePasswordMap != null && profilePasswordMap.containsKey(managedUserId)) { setLockCredentialInternal(null, LockPatternUtils.CREDENTIAL_TYPE_NONE, profilePasswordMap.get(managedUserId), DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED, managedUserId); } else { Slog.wtf(TAG, "clear tied profile challenges, but no password supplied."); // Supplying null here would lead to untrusted credential change setLockCredentialInternal(null, LockPatternUtils.CREDENTIAL_TYPE_NONE, null, DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED, managedUserId); } mStorage.removeChildProfileLock(managedUserId); removeKeystoreProfileKey(managedUserId); } } } }
Example 12
Source File: UserManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@Override public boolean isQuietModeEnabled(int userHandle) { synchronized (mPackagesLock) { UserInfo info; synchronized (mUsersLock) { info = getUserInfoLU(userHandle); } if (info == null || !info.isManagedProfile()) { return false; } return info.isQuietModeEnabled(); } }
Example 13
Source File: UserManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@Override public boolean isManagedProfile(int userId) { int callingUserId = UserHandle.getCallingUserId(); if (callingUserId != userId && !hasManageUsersPermission()) { if (!isSameProfileGroupNoChecks(callingUserId, userId)) { throw new SecurityException( "You need MANAGE_USERS permission to: check if specified user a " + "managed profile outside your profile group"); } } synchronized (mUsersLock) { UserInfo userInfo = getUserInfoLU(userId); return userInfo != null && userInfo.isManagedProfile(); } }
Example 14
Source File: ApplicationPackageManager.java From AndroidComponentPlugin with Apache License 2.0 | 5 votes |
@Override public CharSequence getUserBadgedLabel(CharSequence label, UserHandle user) { UserInfo userInfo = getUserIfProfile(user.getIdentifier()); if (userInfo != null && userInfo.isManagedProfile()) { return Resources.getSystem().getString( com.android.internal.R.string.managed_profile_label_badge, label); } return label; }
Example 15
Source File: UserController.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
boolean switchUser(final int targetUserId) { enforceShellRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES, targetUserId); int currentUserId = getCurrentUserId(); UserInfo targetUserInfo = getUserInfo(targetUserId); if (targetUserId == currentUserId) { Slog.i(TAG, "user #" + targetUserId + " is already the current user"); return true; } if (targetUserInfo == null) { Slog.w(TAG, "No user info for user #" + targetUserId); return false; } if (!targetUserInfo.supportsSwitchTo()) { Slog.w(TAG, "Cannot switch to User #" + targetUserId + ": not supported"); return false; } if (targetUserInfo.isManagedProfile()) { Slog.w(TAG, "Cannot switch to User #" + targetUserId + ": not a full user"); return false; } synchronized (mLock) { mTargetUserId = targetUserId; } if (mUserSwitchUiEnabled) { UserInfo currentUserInfo = getUserInfo(currentUserId); Pair<UserInfo, UserInfo> userNames = new Pair<>(currentUserInfo, targetUserInfo); mUiHandler.removeMessages(START_USER_SWITCH_UI_MSG); mUiHandler.sendMessage(mHandler.obtainMessage( START_USER_SWITCH_UI_MSG, userNames)); } else { mHandler.removeMessages(START_USER_SWITCH_FG_MSG); mHandler.sendMessage(mHandler.obtainMessage( START_USER_SWITCH_FG_MSG, targetUserId, 0)); } return true; }
Example 16
Source File: ApplicationPackageManager.java From AndroidComponentPlugin with Apache License 2.0 | 5 votes |
@Override public Drawable getUserBadgeForDensity(UserHandle user, int density) { UserInfo userInfo = getUserIfProfile(user.getIdentifier()); if (userInfo != null && userInfo.isManagedProfile()) { if (density <= 0) { density = mContext.getResources().getDisplayMetrics().densityDpi; } return Resources.getSystem().getDrawableForDensity( com.android.internal.R.drawable.ic_corp_badge, density); } return null; }
Example 17
Source File: ApplicationPackageManager.java From AndroidComponentPlugin with Apache License 2.0 | 5 votes |
private int getBadgeResIdForUser(int userHandle) { // Return the framework-provided badge. UserInfo userInfo = getUserIfProfile(userHandle); if (userInfo != null && userInfo.isManagedProfile()) { return com.android.internal.R.drawable.ic_corp_icon_badge; } return 0; }
Example 18
Source File: ApplicationPackageManager.java From AndroidComponentPlugin with Apache License 2.0 | 5 votes |
@Override public CharSequence getUserBadgedLabel(CharSequence label, UserHandle user) { UserInfo userInfo = getUserIfProfile(user.getIdentifier()); if (userInfo != null && userInfo.isManagedProfile()) { return Resources.getSystem().getString( com.android.internal.R.string.managed_profile_label_badge, label); } return label; }
Example 19
Source File: LockSettingsService.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
private boolean tiedManagedProfileReadyToUnlock(UserInfo userInfo) { return userInfo.isManagedProfile() && !mLockPatternUtils.isSeparateProfileChallengeEnabled(userInfo.id) && mStorage.hasChildProfileLock(userInfo.id) && mUserManager.isUserRunning(userInfo.id); }
Example 20
Source File: UserController.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
/** * Step from {@link UserState#STATE_RUNNING_UNLOCKING} to * {@link UserState#STATE_RUNNING_UNLOCKED}. */ void finishUserUnlocked(final UserState uss) { final int userId = uss.mHandle.getIdentifier(); // Only keep marching forward if user is actually unlocked if (!StorageManager.isUserKeyUnlocked(userId)) return; synchronized (mLock) { // Bail if we ended up with a stale user if (mStartedUsers.get(uss.mHandle.getIdentifier()) != uss) return; // Do not proceed if unexpected state if (!uss.setState(STATE_RUNNING_UNLOCKING, STATE_RUNNING_UNLOCKED)) { return; } } mInjector.getUserManagerInternal().setUserState(userId, uss.state); uss.mUnlockProgress.finish(); // Get unaware persistent apps running and start any unaware providers // in already-running apps that are partially aware if (userId == UserHandle.USER_SYSTEM) { mInjector.startPersistentApps(PackageManager.MATCH_DIRECT_BOOT_UNAWARE); } mInjector.installEncryptionUnawareProviders(userId); // Dispatch unlocked to external apps final Intent unlockedIntent = new Intent(Intent.ACTION_USER_UNLOCKED); unlockedIntent.putExtra(Intent.EXTRA_USER_HANDLE, userId); unlockedIntent.addFlags( Intent.FLAG_RECEIVER_REGISTERED_ONLY | Intent.FLAG_RECEIVER_FOREGROUND); mInjector.broadcastIntent(unlockedIntent, null, null, 0, null, null, null, AppOpsManager.OP_NONE, null, false, false, MY_PID, SYSTEM_UID, userId); if (getUserInfo(userId).isManagedProfile()) { UserInfo parent = mInjector.getUserManager().getProfileParent(userId); if (parent != null) { final Intent profileUnlockedIntent = new Intent( Intent.ACTION_MANAGED_PROFILE_UNLOCKED); profileUnlockedIntent.putExtra(Intent.EXTRA_USER, UserHandle.of(userId)); profileUnlockedIntent.addFlags( Intent.FLAG_RECEIVER_REGISTERED_ONLY | Intent.FLAG_RECEIVER_FOREGROUND); mInjector.broadcastIntent(profileUnlockedIntent, null, null, 0, null, null, null, AppOpsManager.OP_NONE, null, false, false, MY_PID, SYSTEM_UID, parent.id); } } // Send PRE_BOOT broadcasts if user fingerprint changed; we // purposefully block sending BOOT_COMPLETED until after all // PRE_BOOT receivers are finished to avoid ANR'ing apps final UserInfo info = getUserInfo(userId); if (!Objects.equals(info.lastLoggedInFingerprint, Build.FINGERPRINT)) { // Suppress double notifications for managed profiles that // were unlocked automatically as part of their parent user // being unlocked. final boolean quiet; if (info.isManagedProfile()) { quiet = !uss.tokenProvided || !mLockPatternUtils.isSeparateProfileChallengeEnabled(userId); } else { quiet = false; } mInjector.sendPreBootBroadcast(userId, quiet, () -> finishUserUnlockedCompleted(uss)); } else { finishUserUnlockedCompleted(uss); } }