Search in sources :

Example 16 with VPackage

use of com.lody.virtual.server.pm.parser.VPackage in project VirtualApp by asLody.

the class VAppManagerService method installPackage.

public synchronized InstallResult installPackage(String path, int flags, boolean notify) {
    long installTime = System.currentTimeMillis();
    if (path == null) {
        return InstallResult.makeFailure("path = NULL");
    }
    File packageFile = new File(path);
    if (!packageFile.exists() || !packageFile.isFile()) {
        return InstallResult.makeFailure("Package File is not exist.");
    }
    VPackage pkg = null;
    try {
        pkg = PackageParserEx.parsePackage(packageFile);
    } catch (Throwable e) {
        e.printStackTrace();
    }
    if (pkg == null || pkg.packageName == null) {
        return InstallResult.makeFailure("Unable to parse the package.");
    }
    InstallResult res = new InstallResult();
    res.packageName = pkg.packageName;
    // PackageCache holds all packages, try to check if we need to update.
    VPackage existOne = PackageCacheManager.get(pkg.packageName);
    PackageSetting existSetting = existOne != null ? (PackageSetting) existOne.mExtras : null;
    if (existOne != null) {
        if ((flags & InstallStrategy.IGNORE_NEW_VERSION) != 0) {
            res.isUpdate = true;
            return res;
        }
        if (!canUpdate(existOne, pkg, flags)) {
            return InstallResult.makeFailure("Not allowed to update the package.");
        }
        res.isUpdate = true;
    }
    File appDir = VEnvironment.getDataAppPackageDirectory(pkg.packageName);
    File libDir = new File(appDir, "lib");
    if (res.isUpdate) {
        FileUtils.deleteDir(libDir);
        VEnvironment.getOdexFile(pkg.packageName).delete();
        VActivityManagerService.get().killAppByPkg(pkg.packageName, VUserHandle.USER_ALL);
    }
    if (!libDir.exists() && !libDir.mkdirs()) {
        return InstallResult.makeFailure("Unable to create lib dir.");
    }
    boolean dependSystem = (flags & InstallStrategy.DEPEND_SYSTEM_IF_EXIST) != 0 && VirtualCore.get().isOutsideInstalled(pkg.packageName);
    if (existSetting != null && existSetting.dependSystem) {
        dependSystem = false;
    }
    NativeLibraryHelperCompat.copyNativeBinaries(new File(path), libDir);
    if (!dependSystem) {
        File privatePackageFile = new File(appDir, "base.apk");
        File parentFolder = privatePackageFile.getParentFile();
        if (!parentFolder.exists() && !parentFolder.mkdirs()) {
            VLog.w(TAG, "Warning: unable to create folder : " + privatePackageFile.getPath());
        } else if (privatePackageFile.exists() && !privatePackageFile.delete()) {
            VLog.w(TAG, "Warning: unable to delete file : " + privatePackageFile.getPath());
        }
        try {
            FileUtils.copyFile(packageFile, privatePackageFile);
        } catch (IOException e) {
            privatePackageFile.delete();
            return InstallResult.makeFailure("Unable to copy the package file.");
        }
        packageFile = privatePackageFile;
    }
    if (existOne != null) {
        PackageCacheManager.remove(pkg.packageName);
    }
    chmodPackageDictionary(packageFile);
    PackageSetting ps;
    if (existSetting != null) {
        ps = existSetting;
    } else {
        ps = new PackageSetting();
    }
    ps.dependSystem = dependSystem;
    ps.apkPath = packageFile.getPath();
    ps.libPath = libDir.getPath();
    ps.packageName = pkg.packageName;
    ps.appId = VUserHandle.getAppId(mUidSystem.getOrCreateUid(pkg));
    if (res.isUpdate) {
        ps.lastUpdateTime = installTime;
    } else {
        ps.firstInstallTime = installTime;
        ps.lastUpdateTime = installTime;
        for (int userId : VUserManagerService.get().getUserIds()) {
            boolean installed = userId == 0;
            ps.setUserState(userId, false, /*launched*/
            false, /*hidden*/
            installed);
        }
    }
    PackageParserEx.savePackageCache(pkg);
    PackageCacheManager.put(pkg, ps);
    mPersistenceLayer.save();
    BroadcastSystem.get().startApp(pkg);
    if (notify) {
        notifyAppInstalled(ps);
    }
    res.isSuccess = true;
    return res;
}
Also used : VPackage(com.lody.virtual.server.pm.parser.VPackage) IOException(java.io.IOException) File(java.io.File) InstallResult(com.lody.virtual.remote.InstallResult)

Example 17 with VPackage

use of com.lody.virtual.server.pm.parser.VPackage in project VirtualApp by asLody.

the class VAppManagerService method loadPackageInnerLocked.

private boolean loadPackageInnerLocked(PackageSetting ps) {
    if (ps.dependSystem) {
        if (!VirtualCore.get().isOutsideInstalled(ps.packageName)) {
            return false;
        }
    }
    File cacheFile = VEnvironment.getPackageCacheFile(ps.packageName);
    VPackage pkg = null;
    try {
        pkg = PackageParserEx.readPackageCache(ps.packageName);
    } catch (Throwable e) {
        e.printStackTrace();
    }
    if (pkg == null || pkg.packageName == null) {
        return false;
    }
    chmodPackageDictionary(cacheFile);
    PackageCacheManager.put(pkg, ps);
    BroadcastSystem.get().startApp(pkg);
    return true;
}
Also used : VPackage(com.lody.virtual.server.pm.parser.VPackage) File(java.io.File)

Example 18 with VPackage

use of com.lody.virtual.server.pm.parser.VPackage in project VirtualApp by asLody.

the class VPackageManagerService method getInstalledApplications.

@Override
public VParceledListSlice<ApplicationInfo> getInstalledApplications(int flags, int userId) {
    checkUserId(userId);
    flags = updateFlagsNought(flags);
    ArrayList<ApplicationInfo> list = new ArrayList<>(mPackages.size());
    synchronized (mPackages) {
        for (VPackage p : mPackages.values()) {
            PackageSetting ps = (PackageSetting) p.mExtras;
            ApplicationInfo info = PackageParserEx.generateApplicationInfo(p, flags, ps.readUserState(userId), userId);
            list.add(info);
        }
    }
    return new VParceledListSlice<>(list);
}
Also used : VPackage(com.lody.virtual.server.pm.parser.VPackage) VParceledListSlice(com.lody.virtual.remote.VParceledListSlice) ArrayList(java.util.ArrayList) ApplicationInfo(android.content.pm.ApplicationInfo)

Example 19 with VPackage

use of com.lody.virtual.server.pm.parser.VPackage in project VirtualApp by asLody.

the class VPackageManagerService method cleanUpUser.

void cleanUpUser(int userId) {
    for (VPackage p : mPackages.values()) {
        PackageSetting ps = (PackageSetting) p.mExtras;
        ps.removeUser(userId);
    }
}
Also used : VPackage(com.lody.virtual.server.pm.parser.VPackage)

Example 20 with VPackage

use of com.lody.virtual.server.pm.parser.VPackage in project VirtualApp by asLody.

the class VPackageManagerService method queryIntentActivities.

@Override
public List<ResolveInfo> queryIntentActivities(Intent intent, String resolvedType, int flags, int userId) {
    checkUserId(userId);
    flags = updateFlagsNought(flags);
    ComponentName comp = intent.getComponent();
    if (comp == null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
            if (intent.getSelector() != null) {
                intent = intent.getSelector();
                comp = intent.getComponent();
            }
        }
    }
    if (comp != null) {
        final List<ResolveInfo> list = new ArrayList<ResolveInfo>(1);
        final ActivityInfo ai = getActivityInfo(comp, flags, userId);
        if (ai != null) {
            final ResolveInfo ri = new ResolveInfo();
            ri.activityInfo = ai;
            list.add(ri);
        }
        return list;
    }
    // reader
    synchronized (mPackages) {
        final String pkgName = intent.getPackage();
        if (pkgName == null) {
            return mActivities.queryIntent(intent, resolvedType, flags, userId);
        }
        final VPackage pkg = mPackages.get(pkgName);
        if (pkg != null) {
            return mActivities.queryIntentForPackage(intent, resolvedType, flags, pkg.activities, userId);
        }
        return new ArrayList<ResolveInfo>();
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ActivityInfo(android.content.pm.ActivityInfo) VPackage(com.lody.virtual.server.pm.parser.VPackage) ArrayList(java.util.ArrayList) ComponentName(android.content.ComponentName)

Aggregations

VPackage (com.lody.virtual.server.pm.parser.VPackage)23 ArrayList (java.util.ArrayList)10 ActivityInfo (android.content.pm.ActivityInfo)5 ComponentName (android.content.ComponentName)4 ResolveInfo (android.content.pm.ResolveInfo)4 ProviderInfo (android.content.pm.ProviderInfo)3 ServiceInfo (android.content.pm.ServiceInfo)2 InstalledAppInfo (com.lody.virtual.remote.InstalledAppInfo)2 VParceledListSlice (com.lody.virtual.remote.VParceledListSlice)2 File (java.io.File)2 TargetApi (android.annotation.TargetApi)1 BroadcastReceiver (android.content.BroadcastReceiver)1 IntentFilter (android.content.IntentFilter)1 ApplicationInfo (android.content.pm.ApplicationInfo)1 PackageInfo (android.content.pm.PackageInfo)1 InstallResult (com.lody.virtual.remote.InstallResult)1 PackageSetting (com.lody.virtual.server.pm.PackageSetting)1 IOException (java.io.IOException)1