Java Code Examples for android.content.pm.ApplicationInfo#FLAG_HAS_CODE

The following examples show how to use android.content.pm.ApplicationInfo#FLAG_HAS_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: VActivityManagerService.java    From container with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void processRestarted(String packageName, String processName, int userId) {
    int callingPid = getCallingPid();
    int appId = VAppManagerService.get().getAppId(packageName);
    int uid = VUserHandle.getUid(userId, appId);
    synchronized (this) {
        ProcessRecord app = findProcessLocked(callingPid);
        if (app == null) {
            ApplicationInfo appInfo = VPackageManagerService.get().getApplicationInfo(packageName, 0, userId);
            appInfo.flags |= ApplicationInfo.FLAG_HAS_CODE;
            String stubProcessName = getProcessName(callingPid);
            int vpid = parseVPid(stubProcessName);
            if (vpid != -1) {
                performStartProcessLocked(uid, vpid, appInfo, processName);
            }
        }
    }
}
 
Example 2
Source File: AndroidAppIPackageManager.java    From Android-Plugin-Framework with MIT License 6 votes vote down vote up
private static ApplicationInfo getApplicationInfo(PluginDescriptor pluginDescriptor) {
    ApplicationInfo info = new ApplicationInfo();
    info.packageName = getPackageName(pluginDescriptor);
    info.metaData = pluginDescriptor.getMetaData();
    info.name = pluginDescriptor.getApplicationName();
    info.className = pluginDescriptor.getApplicationName();
    info.enabled = true;
    info.processName = null;//需要时再添加
    info.sourceDir = pluginDescriptor.getInstalledPath();
    info.dataDir = new File(pluginDescriptor.getInstalledPath()).getParent();
    //info.uid == Process.myUid();
    info.publicSourceDir = pluginDescriptor.getInstalledPath();
    info.taskAffinity = null;//需要时再加上
    info.theme = pluginDescriptor.getApplicationTheme();
    info.flags = info.flags | ApplicationInfo.FLAG_HAS_CODE;
    info.nativeLibraryDir = new File(pluginDescriptor.getInstalledPath()).getParentFile().getAbsolutePath() + "/lib";
    String targetSdkVersion = pluginDescriptor.getTargetSdkVersion();
    if (!TextUtils.isEmpty(targetSdkVersion)) {
        info.targetSdkVersion = Integer.valueOf(targetSdkVersion);
    } else {
        info.targetSdkVersion = FairyGlobal.getHostApplication().getApplicationInfo().targetSdkVersion;
    }
    return info;
}
 
Example 3
Source File: ActivityThread.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
private LoadedApk getPackageInfo(ApplicationInfo aInfo, CompatibilityInfo compatInfo,
        ClassLoader baseLoader, boolean securityViolation, boolean includeCode) {
    synchronized (mPackages) {
        WeakReference<LoadedApk> ref;
        if (includeCode) {
            ref = mPackages.get(aInfo.packageName);
        } else {
            ref = mResourcePackages.get(aInfo.packageName);
        }
        LoadedApk packageInfo = ref != null ? ref.get() : null;
        if (packageInfo == null || (packageInfo.mResources != null
                && !packageInfo.mResources.getAssets().isUpToDate())) {
            if (localLOGV) Slog.v(TAG, (includeCode ? "Loading code package "
                    : "Loading resource-only package ") + aInfo.packageName
                    + " (in " + (mBoundApplication != null
                            ? mBoundApplication.processName : null)
                    + ")");
            packageInfo =
                new LoadedApk(this, aInfo, compatInfo, this, baseLoader,
                        securityViolation, includeCode &&
                        (aInfo.flags&ApplicationInfo.FLAG_HAS_CODE) != 0);
            if (includeCode) {
                mPackages.put(aInfo.packageName,
                        new WeakReference<LoadedApk>(packageInfo));
            } else {
                mResourcePackages.put(aInfo.packageName,
                        new WeakReference<LoadedApk>(packageInfo));
            }
        }
        return packageInfo;
    }
}
 
Example 4
Source File: ActivityThread.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
private LoadedApk getPackageInfo(ApplicationInfo aInfo, CompatibilityInfo compatInfo,
        ClassLoader baseLoader, boolean securityViolation, boolean includeCode) {
    synchronized (mPackages) {
        WeakReference<LoadedApk> ref;
        if (includeCode) {
            ref = mPackages.get(aInfo.packageName);
        } else {
            ref = mResourcePackages.get(aInfo.packageName);
        }
        LoadedApk packageInfo = ref != null ? ref.get() : null;
        if (packageInfo == null || (packageInfo.mResources != null
                && !packageInfo.mResources.getAssets().isUpToDate())) {
            if (localLOGV) Slog.v(TAG, (includeCode ? "Loading code package "
                    : "Loading resource-only package ") + aInfo.packageName
                    + " (in " + (mBoundApplication != null
                            ? mBoundApplication.processName : null)
                    + ")");
            packageInfo =
                new LoadedApk(this, aInfo, compatInfo, this, baseLoader,
                        securityViolation, includeCode &&
                        (aInfo.flags&ApplicationInfo.FLAG_HAS_CODE) != 0);
            if (includeCode) {
                mPackages.put(aInfo.packageName,
                        new WeakReference<LoadedApk>(packageInfo));
            } else {
                mResourcePackages.put(aInfo.packageName,
                        new WeakReference<LoadedApk>(packageInfo));
            }
        }
        return packageInfo;
    }
}
 
Example 5
Source File: LoadedApk.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
private void setupJitProfileSupport() {
    if (!SystemProperties.getBoolean("dalvik.vm.usejitprofiles", false)) {
        return;
    }
    // Only set up profile support if the loaded apk has the same uid as the
    // current process.
    // Currently, we do not support profiling across different apps.
    // (e.g. application's uid might be different when the code is
    // loaded by another app via createApplicationContext)
    if (mApplicationInfo.uid != Process.myUid()) {
        return;
    }

    final List<String> codePaths = new ArrayList<>();
    if ((mApplicationInfo.flags & ApplicationInfo.FLAG_HAS_CODE) != 0) {
        codePaths.add(mApplicationInfo.sourceDir);
    }
    if (mApplicationInfo.splitSourceDirs != null) {
        Collections.addAll(codePaths, mApplicationInfo.splitSourceDirs);
    }

    if (codePaths.isEmpty()) {
        // If there are no code paths there's no need to setup a profile file and register with
        // the runtime,
        return;
    }

    final File profileFile = getPrimaryProfileFile(mPackageName);

    VMRuntime.registerAppInfo(profileFile.getPath(),
            codePaths.toArray(new String[codePaths.size()]));

    // Register the app data directory with the reporter. It will
    // help deciding whether or not a dex file is the primary apk or a
    // secondary dex.
    DexLoadReporter.getInstance().registerAppDataDir(mPackageName, mDataDir);
}
 
Example 6
Source File: ArtManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Build the profiles names for all the package code paths (excluding resource only paths).
 * Return the map [code path -> profile name].
 */
private ArrayMap<String, String> getPackageProfileNames(PackageParser.Package pkg) {
    ArrayMap<String, String> result = new ArrayMap<>();
    if ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_HAS_CODE) != 0) {
        result.put(pkg.baseCodePath, ArtManager.getProfileName(null));
    }
    if (!ArrayUtils.isEmpty(pkg.splitCodePaths)) {
        for (int i = 0; i < pkg.splitCodePaths.length; i++) {
            if ((pkg.splitFlags[i] & ApplicationInfo.FLAG_HAS_CODE) != 0) {
                result.put(pkg.splitCodePaths[i], ArtManager.getProfileName(pkg.splitNames[i]));
            }
        }
    }
    return result;
}
 
Example 7
Source File: PackageDexOptimizer.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
static boolean canOptimizePackage(PackageParser.Package pkg) {
    // We do not dexopt a package with no code.
    if ((pkg.applicationInfo.flags & ApplicationInfo.FLAG_HAS_CODE) == 0) {
        return false;
    }

    return true;
}
 
Example 8
Source File: LoadedApk.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void setupJitProfileSupport() {
    if (!SystemProperties.getBoolean("dalvik.vm.usejitprofiles", false)) {
        return;
    }
    // Only set up profile support if the loaded apk has the same uid as the
    // current process.
    // Currently, we do not support profiling across different apps.
    // (e.g. application's uid might be different when the code is
    // loaded by another app via createApplicationContext)
    if (mApplicationInfo.uid != Process.myUid()) {
        return;
    }

    final List<String> codePaths = new ArrayList<>();
    if ((mApplicationInfo.flags & ApplicationInfo.FLAG_HAS_CODE) != 0) {
        codePaths.add(mApplicationInfo.sourceDir);
    }
    if (mApplicationInfo.splitSourceDirs != null) {
        Collections.addAll(codePaths, mApplicationInfo.splitSourceDirs);
    }

    if (codePaths.isEmpty()) {
        // If there are no code paths there's no need to setup a profile file and register with
        // the runtime,
        return;
    }

    for (int i = codePaths.size() - 1; i >= 0; i--) {
        String splitName = i == 0 ? null : mApplicationInfo.splitNames[i - 1];
        String profileFile = ArtManager.getCurrentProfilePath(
                mPackageName, UserHandle.myUserId(), splitName);
        VMRuntime.registerAppInfo(profileFile, new String[] {codePaths.get(i)});
    }

    // Register the app data directory with the reporter. It will
    // help deciding whether or not a dex file is the primary apk or a
    // secondary dex.
    DexLoadReporter.getInstance().registerAppDataDir(mPackageName, mDataDir);
}
 
Example 9
Source File: DynamicApkInfo.java    From Android-plugin-support with MIT License 5 votes vote down vote up
/**
 * Filtered set of {@link #getAllCodePaths()} that excludes
 * resource-only APKs.
 */
public List<String> getAllCodePathsExcludingResourceOnly() {
    ArrayList<String> paths = new ArrayList<>();
    if ((applicationInfo.flags & ApplicationInfo.FLAG_HAS_CODE) != 0) {
        paths.add(baseCodePath);
    }
    return paths;
}
 
Example 10
Source File: PackageDexOptimizer.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Performs dexopt on all code paths of the given package.
 * It assumes the install lock is held.
 */
@GuardedBy("mInstallLock")
private int performDexOptLI(PackageParser.Package pkg, String[] sharedLibraries,
        String[] targetInstructionSets, CompilerStats.PackageStats packageStats,
        PackageDexUsage.PackageUseInfo packageUseInfo, DexoptOptions options) {
    final String[] instructionSets = targetInstructionSets != null ?
            targetInstructionSets : getAppDexInstructionSets(pkg.applicationInfo);
    final String[] dexCodeInstructionSets = getDexCodeInstructionSets(instructionSets);
    final List<String> paths = pkg.getAllCodePaths();

    int sharedGid = UserHandle.getSharedAppGid(pkg.applicationInfo.uid);
    if (sharedGid == -1) {
        Slog.wtf(TAG, "Well this is awkward; package " + pkg.applicationInfo.name + " had UID "
                + pkg.applicationInfo.uid, new Throwable());
        sharedGid = android.os.Process.NOBODY_UID;
    }

    // Get the class loader context dependencies.
    // For each code path in the package, this array contains the class loader context that
    // needs to be passed to dexopt in order to ensure correct optimizations.
    boolean[] pathsWithCode = new boolean[paths.size()];
    pathsWithCode[0] = (pkg.applicationInfo.flags & ApplicationInfo.FLAG_HAS_CODE) != 0;
    for (int i = 1; i < paths.size(); i++) {
        pathsWithCode[i] = (pkg.splitFlags[i - 1] & ApplicationInfo.FLAG_HAS_CODE) != 0;
    }
    String[] classLoaderContexts = DexoptUtils.getClassLoaderContexts(
            pkg.applicationInfo, sharedLibraries, pathsWithCode);

    // Sanity check that we do not call dexopt with inconsistent data.
    if (paths.size() != classLoaderContexts.length) {
        String[] splitCodePaths = pkg.applicationInfo.getSplitCodePaths();
        throw new IllegalStateException("Inconsistent information "
            + "between PackageParser.Package and its ApplicationInfo. "
            + "pkg.getAllCodePaths=" + paths
            + " pkg.applicationInfo.getBaseCodePath=" + pkg.applicationInfo.getBaseCodePath()
            + " pkg.applicationInfo.getSplitCodePaths="
            + (splitCodePaths == null ? "null" : Arrays.toString(splitCodePaths)));
    }

    int result = DEX_OPT_SKIPPED;
    for (int i = 0; i < paths.size(); i++) {
        // Skip paths that have no code.
        if (!pathsWithCode[i]) {
            continue;
        }
        if (classLoaderContexts[i] == null) {
            throw new IllegalStateException("Inconsistent information in the "
                    + "package structure. A split is marked to contain code "
                    + "but has no dependency listed. Index=" + i + " path=" + paths.get(i));
        }

        // Append shared libraries with split dependencies for this split.
        String path = paths.get(i);
        if (options.getSplitName() != null) {
            // We are asked to compile only a specific split. Check that the current path is
            // what we are looking for.
            if (!options.getSplitName().equals(new File(path).getName())) {
                continue;
            }
        }

        String profileName = ArtManager.getProfileName(i == 0 ? null : pkg.splitNames[i - 1]);

        String dexMetadataPath = null;
        if (options.isDexoptInstallWithDexMetadata()) {
            File dexMetadataFile = DexMetadataHelper.findDexMetadataForFile(new File(path));
            dexMetadataPath = dexMetadataFile == null
                    ? null : dexMetadataFile.getAbsolutePath();
        }

        final boolean isUsedByOtherApps = options.isDexoptAsSharedLibrary()
                || packageUseInfo.isUsedByOtherApps(path);
        final String compilerFilter = getRealCompilerFilter(pkg.applicationInfo,
            options.getCompilerFilter(), isUsedByOtherApps);
        final boolean profileUpdated = options.isCheckForProfileUpdates() &&
            isProfileUpdated(pkg, sharedGid, profileName, compilerFilter);

        // Get the dexopt flags after getRealCompilerFilter to make sure we get the correct
        // flags.
        final int dexoptFlags = getDexFlags(pkg, compilerFilter, options);

        for (String dexCodeIsa : dexCodeInstructionSets) {
            int newResult = dexOptPath(pkg, path, dexCodeIsa, compilerFilter,
                    profileUpdated, classLoaderContexts[i], dexoptFlags, sharedGid,
                    packageStats, options.isDowngrade(), profileName, dexMetadataPath,
                    options.getCompilationReason());
            // The end result is:
            //  - FAILED if any path failed,
            //  - PERFORMED if at least one path needed compilation,
            //  - SKIPPED when all paths are up to date
            if ((result != DEX_OPT_FAILED) && (newResult != DEX_OPT_SKIPPED)) {
                result = newResult;
            }
        }
    }
    return result;
}
 
Example 11
Source File: ComponentFixer.java    From container with GNU General Public License v3.0 4 votes vote down vote up
public static void fixApplicationInfo(AppSetting setting, ApplicationInfo applicationInfo, int userId) {
	applicationInfo.flags |= ApplicationInfo.FLAG_HAS_CODE;
	if (TextUtils.isEmpty(applicationInfo.processName)) {
		applicationInfo.processName = applicationInfo.packageName;
	}
	applicationInfo.name = fixComponentClassName(setting.packageName, applicationInfo.name);
	applicationInfo.publicSourceDir = setting.apkPath;
	applicationInfo.sourceDir = setting.apkPath;
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
		applicationInfo.splitSourceDirs = new String[]{setting.apkPath};
		applicationInfo.splitPublicSourceDirs = applicationInfo.splitSourceDirs;
		ApplicationInfoL.scanSourceDir.set(applicationInfo, applicationInfo.dataDir);
		ApplicationInfoL.scanPublicSourceDir.set(applicationInfo, applicationInfo.dataDir);
           String hostPrimaryCpuAbi = ApplicationInfoL.primaryCpuAbi.get(VirtualCore.get().getContext().getApplicationInfo());
		ApplicationInfoL.primaryCpuAbi.set(applicationInfo, hostPrimaryCpuAbi);
	}
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
		ApplicationInfoN.deviceEncryptedDataDir.set(applicationInfo, applicationInfo.dataDir);
		ApplicationInfoN.deviceProtectedDataDir.set(applicationInfo, applicationInfo.dataDir);
		ApplicationInfoN.credentialEncryptedDataDir.set(applicationInfo, applicationInfo.dataDir);
		ApplicationInfoN.credentialProtectedDataDir.set(applicationInfo, applicationInfo.dataDir);
	}
	applicationInfo.enabled = true;
	applicationInfo.nativeLibraryDir = setting.libPath;
	applicationInfo.dataDir = VEnvironment.getDataUserPackageDirectory(userId, setting.packageName).getPath();
	applicationInfo.uid = setting.appId;
	if (setting.dependSystem) {
		String[] sharedLibraryFiles = sSharedLibCache.get(setting.packageName);
		if (sharedLibraryFiles == null) {
			PackageManager hostPM = VirtualCore.get().getUnHookPackageManager();
			try {
				ApplicationInfo hostInfo = hostPM.getApplicationInfo(setting.packageName, PackageManager.GET_SHARED_LIBRARY_FILES);
				sharedLibraryFiles = hostInfo.sharedLibraryFiles;
				if (sharedLibraryFiles == null) sharedLibraryFiles = new String[0];
				sSharedLibCache.put(setting.packageName, sharedLibraryFiles);
			} catch (PackageManager.NameNotFoundException e) {
				e.printStackTrace();
			}
		}
		applicationInfo.sharedLibraryFiles = sharedLibraryFiles;
	}
}