Example usage for android.os UserHandle getCallingUserId

List of usage examples for android.os UserHandle getCallingUserId

Introduction

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

Prototype

@UnsupportedAppUsage
public static @UserIdInt int getCallingUserId() 

Source Link

Usage

From source file:android.content.pm.PackageParser.java

/**
 * Generate and return the {@link PackageInfo} for a parsed package.
 *
 * @param p the parsed package.//from w  w  w.ja va2 s  . c  o m
 * @param flags indicating which optional information is included.
 */
public static PackageInfo generatePackageInfo(PackageParser.Package p, int gids[], int flags,
        long firstInstallTime, long lastUpdateTime, Set<String> grantedPermissions, PackageUserState state) {

    return generatePackageInfo(p, gids, flags, firstInstallTime, lastUpdateTime, grantedPermissions, state,
            UserHandle.getCallingUserId());
}

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);
                }/* w ww  .  j  av a 2s.  co m*/
            }
        }
        return filtered.toArray(new StorageVolume[filtered.size()]);
    }
}

From source file:android.content.pm.PackageParser.java

public static ApplicationInfo generateApplicationInfo(Package p, int flags, PackageUserState state) {
    return generateApplicationInfo(p, flags, state, UserHandle.getCallingUserId());
}