/** * Returns 'false' by default, or the value specified via {@link * #setIsRestrictedProfile(boolean)}. */ public boolean isRestrictedProfile() { return getUserInfo(UserHandle.myUserId()).isRestricted(); }
/** Add a profile to be returned by {@link #getProfiles(int)}.**/ public void addProfile( int userHandle, int profileUserHandle, String profileName, int profileFlags) { profiles.putIfAbsent(userHandle, new ArrayList<>()); profiles.get(userHandle).add(new UserInfo(profileUserHandle, profileName, profileFlags)); }
/** * @return `false` by default, or the value specified via {@link #setIsDemoUser(boolean)} */ @Implementation(minSdk = N_MR1) protected boolean isDemoUser() { return getUserInfo(UserHandle.myUserId()).isDemo(); }
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; }
import android.content.pm.UserInfo; import android.os.UserHandle; import android.os.UserManager; public static boolean isRestrictedProfileInEffect(Context context) { UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE); UserInfo restrictedUserInfo = null; for (UserInfo userInfo : userManager.getUsers()) { if (userInfo.isRestricted()) { restrictedUserInfo = userInfo; } } boolean isOwner = UserHandle.myUserId() == UserHandle.USER_OWNER; boolean isRestrictedProfileOn = restrictedUserInfo != null && !isOwner; return isRestrictedProfileOn; }
/** * Creates a user with the specified name, userId and flags. * * @param id the unique id of user * @param name name of the user * @param flags 16 bits for user type. See {@link UserInfo#flags} * @return a handle to the new user */ public UserHandle addUser(int id, String name, int flags) { UserHandle userHandle = id == UserHandle.USER_SYSTEM ? Process.myUserHandle() : new UserHandle(id); addUserProfile(userHandle); setSerialNumberForUser(userHandle, (long) id); userInfoMap.put(id, new UserInfo(id, name, flags)); userPidMap.put( id, id == UserHandle.USER_SYSTEM ? Process.myUid() : id * UserHandle.PER_USER_RANGE + ShadowProcess.getRandomApplicationUid()); return userHandle; }
/** * @return `false` by default, or the value specified via {@link #setIsDemoUser(boolean)} */ @Implementation(minSdk = N_MR1) protected boolean isDemoUser() { return getUserInfo(UserHandle.myUserId()).isDemo(); }
/** * @return 'false' by default, or the value specified via {@link #setIsLinkedUser(boolean)} */ @Implementation(minSdk = JELLY_BEAN_MR2) protected boolean isLinkedUser() { return getUserInfo(UserHandle.myUserId()).isRestricted(); }
/** * Creates a user with the specified name, userId and flags. * * @param id the unique id of user * @param name name of the user * @param flags 16 bits for user type. See {@link UserInfo#flags} */ public void addUser(int id, String name, int flags) { UserHandle userHandle = id == UserHandle.USER_SYSTEM ? Process.myUserHandle() : new UserHandle(id); addUserProfile(userHandle); setSerialNumberForUser(userHandle, (long) id); userInfoMap.put(id, new UserInfo(id, name, flags)); userPidMap.put( id, id == UserHandle.USER_SYSTEM ? Process.myUid() : id * UserHandle.PER_USER_RANGE + ShadowProcess.getRandomApplicationUid()); }