Search in sources :

Example 6 with PluginPackageParser

use of com.morgoo.droidplugin.pm.parser.PluginPackageParser in project DroidPlugin by DroidPluginTeam.

the class IPluginManagerImpl method getInstalledPackages.

@Override
public List<PackageInfo> getInstalledPackages(int flags) throws RemoteException {
    waitForReadyInner();
    try {
        enforcePluginFileExists();
        List<PackageInfo> infos = new ArrayList<PackageInfo>(mPluginCache.size());
        if (shouldNotBlockOtherInfo()) {
            for (PluginPackageParser pluginPackageParser : mPluginCache.values()) {
                infos.add(pluginPackageParser.getPackageInfo(flags));
            }
        } else {
            List<String> pkgs = mActivityManagerService.getPackageNamesByPid(Binder.getCallingPid());
            for (PluginPackageParser pluginPackageParser : mPluginCache.values()) {
                if (pkgs.contains(pluginPackageParser.getPackageName())) {
                    infos.add(pluginPackageParser.getPackageInfo(flags));
                }
            }
        }
        return infos;
    } catch (Exception e) {
        handleException(e);
    }
    return null;
}
Also used : PackageInfo(android.content.pm.PackageInfo) ArrayList(java.util.ArrayList) PluginPackageParser(com.morgoo.droidplugin.pm.parser.PluginPackageParser) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) RemoteException(android.os.RemoteException)

Example 7 with PluginPackageParser

use of com.morgoo.droidplugin.pm.parser.PluginPackageParser in project DroidPlugin by DroidPluginTeam.

the class IPluginManagerImpl method enforcePluginFileExists.

private void enforcePluginFileExists() throws RemoteException {
    List<String> removedPkg = new ArrayList<>();
    for (String pkg : mPluginCache.keySet()) {
        PluginPackageParser parser = mPluginCache.get(pkg);
        File pluginFile = parser.getPluginFile();
        if (pluginFile != null && pluginFile.exists()) {
        //DO NOTHING
        } else {
            removedPkg.add(pkg);
        }
    }
    for (String pkg : removedPkg) {
        deletePackage(pkg, 0);
    }
}
Also used : ArrayList(java.util.ArrayList) PluginPackageParser(com.morgoo.droidplugin.pm.parser.PluginPackageParser) File(java.io.File)

Example 8 with PluginPackageParser

use of com.morgoo.droidplugin.pm.parser.PluginPackageParser in project DroidPlugin by DroidPluginTeam.

the class IPluginManagerImpl method installPackage.

@Override
public int installPackage(String filepath, int flags) throws RemoteException {
    //install plugin
    String apkfile = null;
    try {
        PackageManager pm = mContext.getPackageManager();
        PackageInfo info = pm.getPackageArchiveInfo(filepath, 0);
        if (info == null) {
            return PackageManagerCompat.INSTALL_FAILED_INVALID_APK;
        }
        apkfile = PluginDirHelper.getPluginApkFile(mContext, info.packageName);
        if ((flags & PackageManagerCompat.INSTALL_REPLACE_EXISTING) != 0) {
            forceStopPackage(info.packageName);
            if (mPluginCache.containsKey(info.packageName)) {
                deleteApplicationCacheFiles(info.packageName, null);
            }
            new File(apkfile).delete();
            Utils.copyFile(filepath, apkfile);
            PluginPackageParser parser = new PluginPackageParser(mContext, new File(apkfile));
            parser.collectCertificates(0);
            PackageInfo pkgInfo = parser.getPackageInfo(PackageManager.GET_PERMISSIONS | PackageManager.GET_SIGNATURES);
            if (pkgInfo != null && pkgInfo.requestedPermissions != null && pkgInfo.requestedPermissions.length > 0) {
                for (String requestedPermission : pkgInfo.requestedPermissions) {
                    boolean b = false;
                    try {
                        b = pm.getPermissionInfo(requestedPermission, 0) != null;
                    } catch (NameNotFoundException e) {
                    }
                    if (!mHostRequestedPermission.contains(requestedPermission) && b) {
                        Log.e(TAG, "No Permission %s", requestedPermission);
                        new File(apkfile).delete();
                        return PluginManager.INSTALL_FAILED_NO_REQUESTEDPERMISSION;
                    }
                }
            }
            saveSignatures(pkgInfo);
            //                }
            if (copyNativeLibs(mContext, apkfile, parser.getApplicationInfo(0)) < 0) {
                new File(apkfile).delete();
                return PackageManagerCompat.INSTALL_FAILED_NOT_SUPPORT_ABI;
            }
            dexOpt(mContext, apkfile, parser);
            mPluginCache.put(parser.getPackageName(), parser);
            mActivityManagerService.onPkgInstalled(mPluginCache, parser, parser.getPackageName());
            sendInstalledBroadcast(info.packageName);
            return PackageManagerCompat.INSTALL_SUCCEEDED;
        } else {
            if (mPluginCache.containsKey(info.packageName)) {
                return PackageManagerCompat.INSTALL_FAILED_ALREADY_EXISTS;
            } else {
                forceStopPackage(info.packageName);
                new File(apkfile).delete();
                Utils.copyFile(filepath, apkfile);
                PluginPackageParser parser = new PluginPackageParser(mContext, new File(apkfile));
                parser.collectCertificates(0);
                PackageInfo pkgInfo = parser.getPackageInfo(PackageManager.GET_PERMISSIONS | PackageManager.GET_SIGNATURES);
                if (pkgInfo != null && pkgInfo.requestedPermissions != null && pkgInfo.requestedPermissions.length > 0) {
                    for (String requestedPermission : pkgInfo.requestedPermissions) {
                        boolean b = false;
                        try {
                            b = pm.getPermissionInfo(requestedPermission, 0) != null;
                        } catch (NameNotFoundException e) {
                        }
                        if (!mHostRequestedPermission.contains(requestedPermission) && b) {
                            Log.e(TAG, "No Permission %s", requestedPermission);
                            new File(apkfile).delete();
                            return PluginManager.INSTALL_FAILED_NO_REQUESTEDPERMISSION;
                        }
                    }
                }
                saveSignatures(pkgInfo);
                if (copyNativeLibs(mContext, apkfile, parser.getApplicationInfo(0)) < 0) {
                    new File(apkfile).delete();
                    return PackageManagerCompat.INSTALL_FAILED_NOT_SUPPORT_ABI;
                }
                dexOpt(mContext, apkfile, parser);
                mPluginCache.put(parser.getPackageName(), parser);
                mActivityManagerService.onPkgInstalled(mPluginCache, parser, parser.getPackageName());
                sendInstalledBroadcast(info.packageName);
                return PackageManagerCompat.INSTALL_SUCCEEDED;
            }
        }
    } catch (Exception e) {
        if (apkfile != null) {
            new File(apkfile).delete();
        }
        handleException(e);
        return PackageManagerCompat.INSTALL_FAILED_INTERNAL_ERROR;
    }
}
Also used : PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) PluginPackageParser(com.morgoo.droidplugin.pm.parser.PluginPackageParser) File(java.io.File) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) RemoteException(android.os.RemoteException)

Example 9 with PluginPackageParser

use of com.morgoo.droidplugin.pm.parser.PluginPackageParser in project DroidPlugin by DroidPluginTeam.

the class IPluginManagerImpl method deletePackage.

@Override
public int deletePackage(String packageName, int flags) throws RemoteException {
    try {
        if (mPluginCache.containsKey(packageName)) {
            forceStopPackage(packageName);
            PluginPackageParser parser;
            synchronized (mPluginCache) {
                parser = mPluginCache.remove(packageName);
            }
            Utils.deleteDir(PluginDirHelper.makePluginBaseDir(mContext, packageName));
            mActivityManagerService.onPkgDeleted(mPluginCache, parser, packageName);
            mSignatureCache.remove(packageName);
            sendUninstalledBroadcast(packageName);
            return PackageManagerCompat.DELETE_SUCCEEDED;
        }
    } catch (Exception e) {
        handleException(e);
    }
    return PackageManagerCompat.DELETE_FAILED_INTERNAL_ERROR;
}
Also used : PluginPackageParser(com.morgoo.droidplugin.pm.parser.PluginPackageParser) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) RemoteException(android.os.RemoteException)

Example 10 with PluginPackageParser

use of com.morgoo.droidplugin.pm.parser.PluginPackageParser in project DroidPlugin by DroidPluginTeam.

the class IPluginManagerImpl method getServiceInfo.

@Override
public ServiceInfo getServiceInfo(ComponentName className, int flags) throws RemoteException {
    waitForReadyInner();
    try {
        String pkg = getAndCheckCallingPkg(className.getPackageName());
        if (pkg != null) {
            enforcePluginFileExists();
            PluginPackageParser parser = mPluginCache.get(className.getPackageName());
            if (parser != null) {
                return parser.getServiceInfo(className, flags);
            }
        }
    } catch (Exception e) {
        handleException(e);
    }
    return null;
}
Also used : PluginPackageParser(com.morgoo.droidplugin.pm.parser.PluginPackageParser) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) RemoteException(android.os.RemoteException)

Aggregations

PluginPackageParser (com.morgoo.droidplugin.pm.parser.PluginPackageParser)15 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)14 RemoteException (android.os.RemoteException)14 ArrayList (java.util.ArrayList)5 PackageInfo (android.content.pm.PackageInfo)4 File (java.io.File)4 ApplicationInfo (android.content.pm.ApplicationInfo)3 PackageManager (android.content.pm.PackageManager)1 PermissionGroupInfo (android.content.pm.PermissionGroupInfo)1 PermissionInfo (android.content.pm.PermissionInfo)1 Signature (android.content.pm.Signature)1