Java Code Examples for android.content.Context#CONTEXT_INCLUDE_CODE

The following examples show how to use android.content.Context#CONTEXT_INCLUDE_CODE . 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: ActivityThread.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
public final LoadedApk getPackageInfo(ApplicationInfo ai, CompatibilityInfo compatInfo,
        int flags) {
    boolean includeCode = (flags&Context.CONTEXT_INCLUDE_CODE) != 0;
    boolean securityViolation = includeCode && ai.uid != 0
            && ai.uid != Process.SYSTEM_UID && (mBoundApplication != null
                    ? !UserId.isSameApp(ai.uid, mBoundApplication.appInfo.uid)
                    : true);
    if ((flags&(Context.CONTEXT_INCLUDE_CODE
            |Context.CONTEXT_IGNORE_SECURITY))
            == Context.CONTEXT_INCLUDE_CODE) {
        if (securityViolation) {
            String msg = "Requesting code from " + ai.packageName
                    + " (with uid " + ai.uid + ")";
            if (mBoundApplication != null) {
                msg = msg + " to be run in process "
                    + mBoundApplication.processName + " (with uid "
                    + mBoundApplication.appInfo.uid + ")";
            }
            throw new SecurityException(msg);
        }
    }
    return getPackageInfo(ai, compatInfo, null, securityViolation, includeCode);
}
 
Example 2
Source File: ActivityThread.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
public final LoadedApk getPackageInfo(ApplicationInfo ai, CompatibilityInfo compatInfo,
        int flags) {
    boolean includeCode = (flags&Context.CONTEXT_INCLUDE_CODE) != 0;
    boolean securityViolation = includeCode && ai.uid != 0
            && ai.uid != Process.SYSTEM_UID && (mBoundApplication != null
                    ? ai.uid != mBoundApplication.appInfo.uid : true);
    if ((flags&(Context.CONTEXT_INCLUDE_CODE
            |Context.CONTEXT_IGNORE_SECURITY))
            == Context.CONTEXT_INCLUDE_CODE) {
        if (securityViolation) {
            String msg = "Requesting code from " + ai.packageName
                    + " (with uid " + ai.uid + ")";
            if (mBoundApplication != null) {
                msg = msg + " to be run in process "
                    + mBoundApplication.processName + " (with uid "
                    + mBoundApplication.appInfo.uid + ")";
            }
            throw new SecurityException(msg);
        }
    }
    return getPackageInfo(ai, compatInfo, null, securityViolation, includeCode);
}
 
Example 3
Source File: ActivityThread.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
public final LoadedApk getPackageInfo(String packageName, CompatibilityInfo compatInfo,
        int flags) {
    synchronized (mPackages) {
        WeakReference<LoadedApk> ref;
        if ((flags&Context.CONTEXT_INCLUDE_CODE) != 0) {
            ref = mPackages.get(packageName);
        } else {
            ref = mResourcePackages.get(packageName);
        }
        LoadedApk packageInfo = ref != null ? ref.get() : null;
        //Slog.i(TAG, "getPackageInfo " + packageName + ": " + packageInfo);
        //if (packageInfo != null) Slog.i(TAG, "isUptoDate " + packageInfo.mResDir
        //        + ": " + packageInfo.mResources.getAssets().isUpToDate());
        if (packageInfo != null && (packageInfo.mResources == null
                || packageInfo.mResources.getAssets().isUpToDate())) {
            if (packageInfo.isSecurityViolation()
                    && (flags&Context.CONTEXT_IGNORE_SECURITY) == 0) {
                throw new SecurityException(
                        "Requesting code from " + packageName
                        + " to be run in process "
                        + mBoundApplication.processName
                        + "/" + mBoundApplication.appInfo.uid);
            }
            return packageInfo;
        }
    }

    ApplicationInfo ai = null;
    try {
        ai = getPackageManager().getApplicationInfo(packageName,
                PackageManager.GET_SHARED_LIBRARY_FILES, UserId.myUserId());
    } catch (RemoteException e) {
        // Ignore
    }

    if (ai != null) {
        return getPackageInfo(ai, compatInfo, flags);
    }

    return null;
}
 
Example 4
Source File: ActivityThread.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
public final LoadedApk getPackageInfo(String packageName, CompatibilityInfo compatInfo,
        int flags) {
    synchronized (mPackages) {
        WeakReference<LoadedApk> ref;
        if ((flags&Context.CONTEXT_INCLUDE_CODE) != 0) {
            ref = mPackages.get(packageName);
        } else {
            ref = mResourcePackages.get(packageName);
        }
        LoadedApk packageInfo = ref != null ? ref.get() : null;
        //Slog.i(TAG, "getPackageInfo " + packageName + ": " + packageInfo);
        //if (packageInfo != null) Slog.i(TAG, "isUptoDate " + packageInfo.mResDir
        //        + ": " + packageInfo.mResources.getAssets().isUpToDate());
        if (packageInfo != null && (packageInfo.mResources == null
                || packageInfo.mResources.getAssets().isUpToDate())) {
            if (packageInfo.isSecurityViolation()
                    && (flags&Context.CONTEXT_IGNORE_SECURITY) == 0) {
                throw new SecurityException(
                        "Requesting code from " + packageName
                        + " to be run in process "
                        + mBoundApplication.processName
                        + "/" + mBoundApplication.appInfo.uid);
            }
            return packageInfo;
        }
    }

    ApplicationInfo ai = null;
    try {
        ai = getPackageManager().getApplicationInfo(packageName,
                PackageManager.GET_SHARED_LIBRARY_FILES);
    } catch (RemoteException e) {
        // Ignore
    }

    if (ai != null) {
        return getPackageInfo(ai, compatInfo, flags);
    }

    return null;
}