android.content.pm.UserInfo Java Examples

The following examples show how to use android.content.pm.UserInfo. 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: ActivityStartInterceptor.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private boolean interceptSuspendedByAdminPackage() {
    DevicePolicyManagerInternal devicePolicyManager = LocalServices
            .getService(DevicePolicyManagerInternal.class);
    if (devicePolicyManager == null) {
        return false;
    }
    mIntent = devicePolicyManager.createShowAdminSupportIntent(mUserId, true);
    mIntent.putExtra(EXTRA_RESTRICTION, POLICY_SUSPEND_PACKAGES);

    mCallingPid = mRealCallingPid;
    mCallingUid = mRealCallingUid;
    mResolvedType = null;

    final UserInfo parent = mUserManager.getProfileParent(mUserId);
    if (parent != null) {
        mRInfo = mSupervisor.resolveIntent(mIntent, mResolvedType, parent.id, 0,
                mRealCallingUid);
    } else {
        mRInfo = mSupervisor.resolveIntent(mIntent, mResolvedType, mUserId, 0,
                mRealCallingUid);
    }
    mAInfo = mSupervisor.resolveActivity(mIntent, mRInfo, mStartFlags, null /*profilerInfo*/);
    return true;
}
 
Example #2
Source File: UserManagerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public @NonNull List<UserInfo> getUsers(boolean excludeDying) {
    checkManageOrCreateUsersPermission("query users");
    synchronized (mUsersLock) {
        ArrayList<UserInfo> users = new ArrayList<UserInfo>(mUsers.size());
        final int userSize = mUsers.size();
        for (int i = 0; i < userSize; i++) {
            UserInfo ui = mUsers.valueAt(i).info;
            if (ui.partial) {
                continue;
            }
            if (!excludeDying || !mRemovingUserIds.get(ui.id)) {
                users.add(userWithName(ui));
            }
        }
        return users;
    }
}
 
Example #3
Source File: TrustManagerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
protected void dump(FileDescriptor fd, final PrintWriter fout, String[] args) {
    if (!DumpUtils.checkDumpPermission(mContext, TAG, fout)) return;
    if (isSafeMode()) {
        fout.println("disabled because the system is in safe mode.");
        return;
    }
    if (!mTrustAgentsCanRun) {
        fout.println("disabled because the third-party apps can't run yet.");
        return;
    }
    final List<UserInfo> userInfos = mUserManager.getUsers(true /* excludeDying */);
    mHandler.runWithScissors(new Runnable() {
        @Override
        public void run() {
            fout.println("Trust manager state:");
            for (UserInfo user : userInfos) {
                dumpUser(fout, user, user.id == mCurrentUser);
            }
        }
    }, 1500);
}
 
Example #4
Source File: UserManagerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Called right before a user is started. This gives us a chance to prepare
 * app storage and apply any user restrictions.
 */
public void onBeforeStartUser(int userId) {
    UserInfo userInfo = getUserInfo(userId);
    if (userInfo == null) {
        return;
    }
    final int userSerial = userInfo.serialNumber;
    // Migrate only if build fingerprints mismatch
    boolean migrateAppsData = !Build.FINGERPRINT.equals(userInfo.lastLoggedInFingerprint);
    mUserDataPreparer.prepareUserData(userId, userSerial, StorageManager.FLAG_STORAGE_DE);
    mPm.reconcileAppsData(userId, StorageManager.FLAG_STORAGE_DE, migrateAppsData);

    if (userId != UserHandle.USER_SYSTEM) {
        synchronized (mRestrictionsLock) {
            applyUserRestrictionsLR(userId);
        }
    }
}
 
Example #5
Source File: UserManagerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
public void makeInitialized(int userId) {
    checkManageUsersPermission("makeInitialized");
    boolean scheduleWriteUser = false;
    UserData userData;
    synchronized (mUsersLock) {
        userData = mUsers.get(userId);
        if (userData == null || userData.info.partial) {
            Slog.w(LOG_TAG, "makeInitialized: unknown user #" + userId);
            return;
        }
        if ((userData.info.flags & UserInfo.FLAG_INITIALIZED) == 0) {
            userData.info.flags |= UserInfo.FLAG_INITIALIZED;
            scheduleWriteUser = true;
        }
    }
    if (scheduleWriteUser) {
        scheduleWriteUser(userData);
    }
}
 
Example #6
Source File: ManagedServices.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void loadAllowedComponentsFromSettings() {
    for (UserInfo user : mUm.getUsers()) {
        final ContentResolver cr = mContext.getContentResolver();
        addApprovedList(Settings.Secure.getStringForUser(
                cr,
                getConfig().secureSettingName,
                user.id), user.id, true);
        if (!TextUtils.isEmpty(getConfig().secondarySettingName)) {
            addApprovedList(Settings.Secure.getStringForUser(
                    cr,
                    getConfig().secondarySettingName,
                    user.id), user.id, false);
        }
    }
    Slog.d(TAG, "Done loading approved values from settings");
}
 
Example #7
Source File: BluetoothManagerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private boolean checkIfCallerIsForegroundUser() {
    int foregroundUser;
    int callingUser = UserHandle.getCallingUserId();
    int callingUid = Binder.getCallingUid();
    long callingIdentity = Binder.clearCallingIdentity();
    UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
    UserInfo ui = um.getProfileParent(callingUser);
    int parentUser = (ui != null) ? ui.id : UserHandle.USER_NULL;
    int callingAppId = UserHandle.getAppId(callingUid);
    boolean valid = false;
    try {
        foregroundUser = ActivityManager.getCurrentUser();
        valid = (callingUser == foregroundUser) || parentUser == foregroundUser
                || callingAppId == Process.NFC_UID || callingAppId == mSystemUiUid;
        if (DBG && !valid) {
            Slog.d(TAG, "checkIfCallerIsForegroundUser: valid=" + valid + " callingUser="
                    + callingUser + " parentUser=" + parentUser + " foregroundUser="
                    + foregroundUser);
        }
    } finally {
        Binder.restoreCallingIdentity(callingIdentity);
    }
    return valid;
}
 
Example #8
Source File: SyncManager.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void whiteListExistingSyncAdaptersIfNeeded() {
    if (!mSyncStorageEngine.shouldGrantSyncAdaptersAccountAccess()) {
        return;
    }
    List<UserInfo> users = mUserManager.getUsers(true);
    final int userCount = users.size();
    for (int i = 0; i < userCount; i++) {
        UserHandle userHandle = users.get(i).getUserHandle();
        final int userId = userHandle.getIdentifier();
        for (RegisteredServicesCache.ServiceInfo<SyncAdapterType> service
                : mSyncAdapters.getAllServices(userId)) {
            String packageName = service.componentName.getPackageName();
            for (Account account : mAccountManager.getAccountsByTypeAsUser(
                    service.type.accountType, userHandle)) {
                if (!canAccessAccount(account, packageName, userId)) {
                    mAccountManager.updateAppPermission(account,
                            AccountManager.ACCOUNT_ACCESS_TOKEN_TYPE, service.uid, true);
                }
            }
        }
    }
}
 
Example #9
Source File: OverlayManagerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void initIfNeeded() {
    final UserManager um = getContext().getSystemService(UserManager.class);
    final List<UserInfo> users = um.getUsers(true /*excludeDying*/);
    synchronized (mLock) {
        final int userCount = users.size();
        for (int i = 0; i < userCount; i++) {
            final UserInfo userInfo = users.get(i);
            if (!userInfo.supportsSwitchTo() && userInfo.id != UserHandle.USER_SYSTEM) {
                // Initialize any users that can't be switched to, as there state would
                // never be setup in onSwitchUser(). We will switch to the system user right
                // after this, and its state will be setup there.
                final List<String> targets = mImpl.updateOverlaysForUser(users.get(i).id);
                updateOverlayPaths(users.get(i).id, targets);
            }
        }
    }
}
 
Example #10
Source File: LockSettingsService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Migrate the credential for the FRP credential owner user if the following are satisfied:
 * - the user has a secure credential
 * - the FRP credential is not set up
 * - the credential is based on a synthetic password.
 */
private void migrateFrpCredential() throws RemoteException {
    if (mStorage.readPersistentDataBlock() != PersistentData.NONE) {
        return;
    }
    for (UserInfo userInfo : mUserManager.getUsers()) {
        if (userOwnsFrpCredential(mContext, userInfo) && isUserSecure(userInfo.id)) {
            synchronized (mSpManager) {
                if (isSyntheticPasswordBasedCredentialLocked(userInfo.id)) {
                    int actualQuality = (int) getLong(LockPatternUtils.PASSWORD_TYPE_KEY,
                            DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED, userInfo.id);

                    mSpManager.migrateFrpPasswordLocked(
                            getSyntheticPasswordHandleLocked(userInfo.id),
                            userInfo,
                            redactActualQualityToMostLenientEquivalentQuality(actualQuality));
                }
            }
            return;
        }
    }
}
 
Example #11
Source File: UserManagerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/** @return if any user has the given restriction. */
@Override
public boolean hasUserRestrictionOnAnyUser(String restrictionKey) {
    if (!UserRestrictionsUtils.isValidRestriction(restrictionKey)) {
        return false;
    }
    final List<UserInfo> users = getUsers(/* excludeDying= */ true);
    for (int i = 0; i < users.size(); i++) {
        final int userId = users.get(i).id;
        Bundle restrictions = getEffectiveUserRestrictions(userId);
        if (restrictions != null && restrictions.getBoolean(restrictionKey)) {
            return true;
        }
    }
    return false;
}
 
Example #12
Source File: MainActivity.java    From AppOpsX with MIT License 6 votes vote down vote up
private void loadUsers(){
  Helper.getUsers(getApplicationContext(),true).subscribeOn(Schedulers.io())
      .observeOn(AndroidSchedulers.mainThread())
      .subscribe(new SingleObserver<List<UserInfo>>() {
        @Override
        public void onSubscribe(Disposable d) {

        }

        @Override
        public void onSuccess(List<UserInfo> userInfos) {

          Users.getInstance().updateUsers(userInfos);
          invalidateOptionsMenu();
        }

        @Override
        public void onError(Throwable e) {

        }
      });
}
 
Example #13
Source File: BaseSettingsProviderTest.java    From Study_Android_Demo with Apache License 2.0 6 votes vote down vote up
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 #14
Source File: UserManagerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public boolean hasRestrictedProfiles() {
    checkManageUsersPermission("hasRestrictedProfiles");
    final int callingUserId = UserHandle.getCallingUserId();
    synchronized (mUsersLock) {
        final int userSize = mUsers.size();
        for (int i = 0; i < userSize; i++) {
            UserInfo profile = mUsers.valueAt(i).info;
            if (callingUserId != profile.id
                    && profile.restrictedProfileParentId == callingUserId) {
                return true;
            }
        }
        return false;
    }
}
 
Example #15
Source File: UserPackage.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a list of (User,PackageInfo) pairs corresponding to the PackageInfos for all
 * device users for the package named {@param packageName}.
 */
public static List<UserPackage> getPackageInfosAllUsers(Context context,
        String packageName, int packageFlags) {
    List<UserInfo> users = getAllUsers(context);
    List<UserPackage> userPackages = new ArrayList<UserPackage>(users.size());
    for (UserInfo user : users) {
        PackageInfo packageInfo = null;
        try {
            packageInfo = context.getPackageManager().getPackageInfoAsUser(
                    packageName, packageFlags, user.id);
        } catch (NameNotFoundException e) {
        }
        userPackages.add(new UserPackage(user, packageInfo));
    }
    return userPackages;
}
 
Example #16
Source File: UserController.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Stops the guest or ephemeral user if it has gone to the background.
 */
private void stopGuestOrEphemeralUserIfBackground(int oldUserId) {
    if (DEBUG_MU) Slog.i(TAG, "Stop guest or ephemeral user if background: " + oldUserId);
    synchronized(mLock) {
        UserState oldUss = mStartedUsers.get(oldUserId);
        if (oldUserId == UserHandle.USER_SYSTEM || oldUserId == mCurrentUserId || oldUss == null
                || oldUss.state == UserState.STATE_STOPPING
                || oldUss.state == UserState.STATE_SHUTDOWN) {
            return;
        }
    }

    UserInfo userInfo = getUserInfo(oldUserId);
    if (userInfo.isEphemeral()) {
        LocalServices.getService(UserManagerInternal.class).onEphemeralUserStop(oldUserId);
    }
    if (userInfo.isGuest() || userInfo.isEphemeral()) {
        // This is a user to be stopped.
        synchronized (mLock) {
            stopUsersLU(oldUserId, true, null);
        }
    }
}
 
Example #17
Source File: UserManagerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@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 #18
Source File: UserManagerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public void setUserAdmin(int userId) {
    checkManageUserAndAcrossUsersFullPermission("set user admin");

    synchronized (mPackagesLock) {
        UserInfo info;
        synchronized (mUsersLock) {
            info = getUserInfoLU(userId);
        }
        if (info == null || info.isAdmin()) {
            // Exit if no user found with that id, or the user is already an Admin.
            return;
        }

        info.flags ^= UserInfo.FLAG_ADMIN;
        writeUserLP(getUserDataLU(info.id));
    }

    // Remove non-admin restrictions.
    // Keep synchronized with createUserEvenWhenDisallowed.
    setUserRestriction(UserManager.DISALLOW_SMS, false, userId);
    setUserRestriction(UserManager.DISALLOW_OUTGOING_CALLS, false, userId);
}
 
Example #19
Source File: UserManagerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * @hide
 */
@Override
public UserInfo createRestrictedProfile(String name, int parentUserId) {
    checkManageOrCreateUsersPermission("setupRestrictedProfile");
    final UserInfo user = createProfileForUser(
            name, UserInfo.FLAG_RESTRICTED, parentUserId, null);
    if (user == null) {
        return null;
    }
    long identity = Binder.clearCallingIdentity();
    try {
        setUserRestriction(UserManager.DISALLOW_MODIFY_ACCOUNTS, true, user.id);
        // Change the setting before applying the DISALLOW_SHARE_LOCATION restriction, otherwise
        // the putIntForUser() will fail.
        android.provider.Settings.Secure.putIntForUser(mContext.getContentResolver(),
                android.provider.Settings.Secure.LOCATION_MODE,
                android.provider.Settings.Secure.LOCATION_MODE_OFF, user.id);
        setUserRestriction(UserManager.DISALLOW_SHARE_LOCATION, true, user.id);
    } finally {
        Binder.restoreCallingIdentity(identity);
    }
    return user;
}
 
Example #20
Source File: UserManager.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Similar to {@link #createProfileForUser(String, int, int, String[])}
 * except bypassing the checking of {@link UserManager#DISALLOW_ADD_MANAGED_PROFILE}.
 * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
 *
 * @see #createProfileForUser(String, int, int, String[])
 * @hide
 */
public UserInfo createProfileForUserEvenWhenDisallowed(String name, int flags,
        @UserIdInt int userHandle, String[] disallowedPackages) {
    try {
        return mService.createProfileForUserEvenWhenDisallowed(name, flags, userHandle,
                disallowedPackages);
    } catch (RemoteException re) {
        throw re.rethrowFromSystemServer();
    }
}
 
Example #21
Source File: SyntheticPasswordManager.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public void migrateFrpPasswordLocked(long handle, UserInfo userInfo, int requestedQuality) {
    if (mStorage.getPersistentDataBlock() != null
            && LockPatternUtils.userOwnsFrpCredential(mContext, userInfo)) {
        PasswordData pwd = PasswordData.fromBytes(loadState(PASSWORD_DATA_NAME, handle,
                userInfo.id));
        if (pwd.passwordType != LockPatternUtils.CREDENTIAL_TYPE_NONE) {
            int weaverSlot = loadWeaverSlot(handle, userInfo.id);
            if (weaverSlot != INVALID_WEAVER_SLOT) {
                synchronizeWeaverFrpPassword(pwd, requestedQuality, userInfo.id, weaverSlot);
            } else {
                synchronizeFrpPassword(pwd, requestedQuality, userInfo.id);
            }
        }
    }
}
 
Example #22
Source File: UserDataPreparer.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Examine all users present on given mounted volume, and destroy data
 * belonging to users that are no longer valid, or whose user ID has been
 * recycled.
 */
void reconcileUsers(String volumeUuid, List<UserInfo> validUsersList) {
    final List<File> files = new ArrayList<>();
    Collections.addAll(files, FileUtils
            .listFilesOrEmpty(Environment.getDataUserDeDirectory(volumeUuid)));
    Collections.addAll(files, FileUtils
            .listFilesOrEmpty(Environment.getDataUserCeDirectory(volumeUuid)));
    Collections.addAll(files, FileUtils
            .listFilesOrEmpty(Environment.getDataSystemDeDirectory()));
    Collections.addAll(files, FileUtils
            .listFilesOrEmpty(Environment.getDataSystemCeDirectory()));
    Collections.addAll(files, FileUtils
            .listFilesOrEmpty(Environment.getDataMiscCeDirectory()));
    reconcileUsers(volumeUuid, validUsersList, files);
}
 
Example #23
Source File: MediaSessionService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void updateUser() {
    synchronized (mLock) {
        UserManager manager = (UserManager) getContext().getSystemService(Context.USER_SERVICE);
        mFullUserIds.clear();
        List<UserInfo> allUsers = manager.getUsers();
        if (allUsers != null) {
            for (UserInfo userInfo : allUsers) {
                if (userInfo.isManagedProfile()) {
                    mFullUserIds.put(userInfo.id, userInfo.profileGroupId);
                } else {
                    mFullUserIds.put(userInfo.id, userInfo.id);
                    if (mUserRecords.get(userInfo.id) == null) {
                        mUserRecords.put(userInfo.id, new FullUserRecord(userInfo.id));
                    }
                }
            }
        }
        // Ensure that the current full user exists.
        int currentFullUserId = ActivityManager.getCurrentUser();
        mCurrentFullUserRecord = mUserRecords.get(currentFullUserId);
        if (mCurrentFullUserRecord == null) {
            Log.w(TAG, "Cannot find FullUserInfo for the current user " + currentFullUserId);
            mCurrentFullUserRecord = new FullUserRecord(currentFullUserId);
            mUserRecords.put(currentFullUserId, mCurrentFullUserRecord);
        }
        mFullUserIds.put(currentFullUserId, currentFullUserId);
    }
}
 
Example #24
Source File: InstallNonMarketAppsDeprecationTest.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
@Test
public void testValueForNewUser() throws Exception {
    UserInfo newUser = mUm.createUser("TEST_USER", 0);
    mUsersAddedByTest.add(newUser.id);
    String value = getSecureSettingForUserViaShell(newUser.id);
    assertEquals("install_non_market_apps should be 1 for a new user", value, "1");
}
 
Example #25
Source File: UserManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@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 #26
Source File: UserManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private UserInfo getUserInfoLU(int userId) {
    final UserData userData = mUsers.get(userId);
    // If it is partial and not in the process of being removed, return as unknown user.
    if (userData != null && userData.info.partial && !mRemovingUserIds.get(userId)) {
        Slog.w(LOG_TAG, "getUserInfo: unknown user #" + userId);
        return null;
    }
    return userData != null ? userData.info : null;
}
 
Example #27
Source File: UserManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@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 #28
Source File: UserManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void setUserEnabled(int userId) {
    checkManageUsersPermission("enable user");
    synchronized (mPackagesLock) {
        UserInfo info;
        synchronized (mUsersLock) {
            info = getUserInfoLU(userId);
        }
        if (info != null && !info.isEnabled()) {
            info.flags ^= UserInfo.FLAG_DISABLED;
            writeUserLP(getUserDataLU(info.id));
        }
    }
}
 
Example #29
Source File: UserManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isUserNameSet(int userHandle) {
    synchronized (mUsersLock) {
        UserInfo userInfo = getUserInfoLU(userHandle);
        return userInfo != null && userInfo.name != null;
    }
}
 
Example #30
Source File: UserManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isDemoUser(int userId) {
    int callingUserId = UserHandle.getCallingUserId();
    if (callingUserId != userId && !hasManageUsersPermission()) {
        throw new SecurityException("You need MANAGE_USERS permission to query if u=" + userId
                + " is a demo user");
    }
    synchronized (mUsersLock) {
        UserInfo userInfo = getUserInfoLU(userId);
        return userInfo != null && userInfo.isDemo();
    }
}