Example usage for android.os UserHandle getUid

List of usage examples for android.os UserHandle getUid

Introduction

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

Prototype

@UnsupportedAppUsage
public static int getUid(@UserIdInt int userId, @AppIdInt int appId) 

Source Link

Document

Returns the uid that is composed from the userId and the appId.

Usage

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

public static ApplicationInfo generateApplicationInfo(Package p, int flags, PackageUserState state,
        int userId) {
    if (p == null)
        return null;
    if (!checkUseInstalledOrHidden(flags, state)) {
        return null;
    }/* ww w . j  a  va2  s  .  c  o  m*/
    if (!copyNeeded(flags, p, state, null, userId)
            && ((flags & PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS) == 0
                    || state.enabled != PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED)) {
        // In this case it is safe to directly modify the internal ApplicationInfo state:
        // - CompatibilityMode is global state, so will be the same for every call.
        // - We only come in to here if the app should reported as installed; this is the
        // default state, and we will do a copy otherwise.
        // - The enable state will always be reported the same for the application across
        // calls; the only exception is for the UNTIL_USED mode, and in that case we will
        // be doing a copy.
        updateApplicationInfo(p.applicationInfo, flags, state);
        return p.applicationInfo;
    }

    // Make shallow copy so we can store the metadata/libraries safely
    ApplicationInfo ai = new ApplicationInfo(p.applicationInfo);
    ai.uid = UserHandle.getUid(userId, ai.uid);
    ai.dataDir = Environment.getDataUserPackageDirectory(ai.volumeUuid, userId, ai.packageName)
            .getAbsolutePath();
    if ((flags & PackageManager.GET_META_DATA) != 0) {
        ai.metaData = p.mAppMetaData;
    }
    if ((flags & PackageManager.GET_SHARED_LIBRARY_FILES) != 0) {
        ai.sharedLibraryFiles = p.usesLibraryFiles;
    }
    if (state.stopped) {
        ai.flags |= ApplicationInfo.FLAG_STOPPED;
    } else {
        ai.flags &= ~ApplicationInfo.FLAG_STOPPED;
    }
    updateApplicationInfo(ai, flags, state);
    return ai;
}

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

public static ApplicationInfo generateApplicationInfo(ApplicationInfo ai, int flags, PackageUserState state,
        int userId) {
    if (ai == null)
        return null;
    if (!checkUseInstalledOrHidden(flags, state)) {
        return null;
    }/*from  w ww.j  a  va 2 s  . c  o  m*/
    // This is only used to return the ResolverActivity; we will just always
    // make a copy.
    ai = new ApplicationInfo(ai);
    ai.uid = UserHandle.getUid(userId, ai.uid);
    ai.dataDir = Environment.getDataUserPackageDirectory(ai.volumeUuid, userId, ai.packageName)
            .getAbsolutePath();
    if (state.stopped) {
        ai.flags |= ApplicationInfo.FLAG_STOPPED;
    } else {
        ai.flags &= ~ApplicationInfo.FLAG_STOPPED;
    }
    updateApplicationInfo(ai, flags, state);
    return ai;
}