Example usage for android.os UserHandle getIdentifier

List of usage examples for android.os UserHandle getIdentifier

Introduction

In this page you can find the example usage for android.os UserHandle getIdentifier.

Prototype

@SystemApi
@TestApi
public @UserIdInt int getIdentifier() 

Source Link

Document

Returns the userId stored in this UserHandle.

Usage

From source file:com.android.tv.settings.users.AppRestrictionsFragment.java

/**
 * Queries for the UserInfo of a user. Returns null if the user doesn't exist (was removed).
 * @param userManager Instance of UserManager
 * @param checkUser The user to check the existence of.
 * @return UserInfo of the user or null for non-existent user.
 *//*w w w.jav  a  2  s .  co m*/
public static UserInfo getExistingUser(UserManager userManager, UserHandle checkUser) {
    final List<UserInfo> users = userManager.getUsers(true /* excludeDying */);
    final int checkUserId = checkUser.getIdentifier();
    for (UserInfo user : users) {
        if (user.id == checkUserId) {
            return user;
        }
    }
    return null;
}

From source file:com.android.settings.users.RestrictedProfileSettings.java

private UserInfo getExistingUser(UserHandle thisUser) {
    final List<UserInfo> users = mUserManager.getUsers(true); // Only get non-dying
    for (UserInfo user : users) {
        if (user.id == thisUser.getIdentifier()) {
            return user;
        }/*from w  ww .j a  va 2 s  . co m*/
    }
    return null;
}

From source file:com.android.managedprovisioning.ProfileOwnerProvisioningService.java

/**
 * Notify the mdm that provisioning has completed. When the mdm has received the intent, stop
 * the service and notify the {@link ProfileOwnerProvisioningActivity} so that it can finish
 * itself.//  ww  w . j a v  a 2 s.c  o  m
 */
private void notifyMdmAndCleanup() {
    // Set DPM userProvisioningState appropriately and persist mParams for use during
    // FinalizationActivity if necessary.
    mUtils.markUserProvisioningStateInitiallyDone(this, mParams);

    if (mParams.provisioningAction.equals(ACTION_PROVISION_MANAGED_PROFILE)) {
        // Set the user_setup_complete flag on the managed-profile as setup-wizard is never run
        // for that user. This is not relevant for other cases since
        // Utils.markUserProvisioningStateInitiallyDone() communicates provisioning state to
        // setup-wizard via DPM.setUserProvisioningState() if necessary.
        mUtils.markUserSetupComplete(this, mManagedProfileOrUserInfo.id);
    }

    // If profile owner provisioning was started after current user setup is completed, then we
    // can directly send the ACTION_PROFILE_PROVISIONING_COMPLETE broadcast to the MDM.
    // But if the provisioning was started as part of setup wizard flow, we signal setup-wizard
    // should shutdown via DPM.setUserProvisioningState(), which will result in a finalization
    // intent being sent to us once setup-wizard finishes. As part of the finalization intent
    // handling we then broadcast ACTION_PROFILE_PROVISIONING_COMPLETE.
    if (mUtils.isUserSetupCompleted(this)) {
        UserHandle managedUserHandle = new UserHandle(mManagedProfileOrUserInfo.id);

        // Use an ordered broadcast, so that we only finish when the mdm has received it.
        // Avoids a lag in the transition between provisioning and the mdm.
        BroadcastReceiver mdmReceivedSuccessReceiver = new MdmReceivedSuccessReceiver(mParams.accountToMigrate,
                mParams.deviceAdminComponentName.getPackageName());

        Intent completeIntent = new Intent(ACTION_PROFILE_PROVISIONING_COMPLETE);
        completeIntent.setComponent(mParams.deviceAdminComponentName);
        completeIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES | Intent.FLAG_RECEIVER_FOREGROUND);
        if (mParams.adminExtrasBundle != null) {
            completeIntent.putExtra(EXTRA_PROVISIONING_ADMIN_EXTRAS_BUNDLE, mParams.adminExtrasBundle);
        }

        sendOrderedBroadcastAsUser(completeIntent, managedUserHandle, null, mdmReceivedSuccessReceiver, null,
                Activity.RESULT_OK, null, null);
        ProvisionLogger.logd(
                "Provisioning complete broadcast has been sent to user " + managedUserHandle.getIdentifier());
    }
}

From source file:android.app.Notification.java

/** {@hide} */
public void setUser(UserHandle user) {
    if (user.getIdentifier() == UserHandle.USER_ALL) {
        user = UserHandle.OWNER;//ww w .jav a 2 s .co m
    }
    if (tickerView != null) {
        tickerView.setUser(user);
    }
    if (contentView != null) {
        contentView.setUser(user);
    }
    if (bigContentView != null) {
        bigContentView.setUser(user);
    }
}

From source file:com.android.server.MountService.java

@Override
public StorageVolume[] getVolumeList() {
    final int callingUserId = UserHandle.getCallingUserId();
    final boolean accessAll = (mContext.checkPermission(android.Manifest.permission.ACCESS_ALL_EXTERNAL_STORAGE,
            Binder.getCallingPid(), Binder.getCallingUid()) == PERMISSION_GRANTED);

    synchronized (mVolumesLock) {
        final ArrayList<StorageVolume> filtered = Lists.newArrayList();
        for (StorageVolume volume : mVolumes) {
            final UserHandle owner = volume.getOwner();
            final boolean ownerMatch = owner == null || owner.getIdentifier() == callingUserId;
            if (accessAll || ownerMatch) {
                if (!accessAll && volume.isEmulated()) {
                    filtered.add(0, volume);
                } else {
                    filtered.add(volume);
                }//from  ww  w.j  av a  2s  .c o m
            }
        }
        return filtered.toArray(new StorageVolume[filtered.size()]);
    }
}

From source file:com.android.server.MountService.java

/**
 * Create and add new {@link StorageVolume} for given {@link UserHandle}
 * using {@link #mEmulatedTemplate} as template.
 *//*w  w w .  j a v  a  2 s.  c  om*/
private void createEmulatedVolumeForUserLocked(UserHandle user) {
    if (mEmulatedTemplate == null) {
        throw new IllegalStateException("Missing emulated volume multi-user template");
    }

    final UserEnvironment userEnv = new UserEnvironment(user.getIdentifier());
    final File path = userEnv.getExternalStorageDirectory();
    final StorageVolume volume = StorageVolume.fromTemplate(mEmulatedTemplate, path, user);
    volume.setStorageId(0);
    addVolumeLocked(volume);

    if (mSystemReady) {
        updatePublicVolumeState(volume, Environment.MEDIA_MOUNTED);
    } else {
        // Place stub status for early callers to find
        mVolumeStates.put(volume.getPath(), Environment.MEDIA_MOUNTED);
        volume.setState(Environment.MEDIA_MOUNTED);
    }
}