Search in sources :

Example 1 with PluginPackageParser

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

the class IPluginManagerImpl method loadAllPlugin.

private void loadAllPlugin(Context context) {
    long b = System.currentTimeMillis();
    ArrayList<File> apkfiles = null;
    try {
        apkfiles = new ArrayList<File>();
        File baseDir = new File(PluginDirHelper.getBaseDir(context));
        File[] dirs = baseDir.listFiles();
        for (File dir : dirs) {
            if (dir.isDirectory()) {
                File file = new File(dir, "apk/base-1.apk");
                if (file.exists()) {
                    apkfiles.add(file);
                }
            }
        }
    } catch (Exception e) {
        Log.e(TAG, "scan a apk file error", e);
    }
    Log.i(TAG, "Search apk cost %s ms", (System.currentTimeMillis() - b));
    b = System.currentTimeMillis();
    if (apkfiles != null && apkfiles.size() > 0) {
        for (File pluginFile : apkfiles) {
            long b1 = System.currentTimeMillis();
            try {
                PluginPackageParser pluginPackageParser = new PluginPackageParser(mContext, pluginFile);
                Signature[] signatures = readSignatures(pluginPackageParser.getPackageName());
                if (signatures == null || signatures.length <= 0) {
                    pluginPackageParser.collectCertificates(0);
                    PackageInfo info = pluginPackageParser.getPackageInfo(PackageManager.GET_SIGNATURES);
                    saveSignatures(info);
                } else {
                    mSignatureCache.put(pluginPackageParser.getPackageName(), signatures);
                    pluginPackageParser.writeSignature(signatures);
                }
                if (!mPluginCache.containsKey(pluginPackageParser.getPackageName())) {
                    mPluginCache.put(pluginPackageParser.getPackageName(), pluginPackageParser);
                }
            } catch (Throwable e) {
                Log.e(TAG, "parse a apk file error %s", e, pluginFile.getPath());
            } finally {
                Log.i(TAG, "Parse %s apk cost %s ms", pluginFile.getPath(), (System.currentTimeMillis() - b1));
            }
        }
    }
    Log.i(TAG, "Parse all apk cost %s ms", (System.currentTimeMillis() - b));
    b = System.currentTimeMillis();
    try {
        mActivityManagerService.onCreate(IPluginManagerImpl.this);
    } catch (Throwable e) {
        Log.e(TAG, "mActivityManagerService.onCreate", e);
    }
    Log.i(TAG, "ActivityManagerService.onCreate %s ms", (System.currentTimeMillis() - b));
}
Also used : PackageInfo(android.content.pm.PackageInfo) Signature(android.content.pm.Signature) PluginPackageParser(com.morgoo.droidplugin.pm.parser.PluginPackageParser) File(java.io.File) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) RemoteException(android.os.RemoteException)

Example 2 with PluginPackageParser

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

the class IPluginManagerImpl method clearApplicationUserData.

@Override
public void clearApplicationUserData(String packageName, IPackageDataObserver observer) throws RemoteException {
    boolean success = false;
    try {
        if (TextUtils.isEmpty(packageName)) {
            return;
        }
        PluginPackageParser parser = mPluginCache.get(packageName);
        if (parser == null) {
            return;
        }
        ApplicationInfo applicationInfo = parser.getApplicationInfo(0);
        Utils.deleteDir(applicationInfo.dataDir);
        success = true;
    } catch (Exception e) {
        handleException(e);
    } finally {
        if (observer != null) {
            observer.onRemoveCompleted(packageName, success);
        }
    }
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) PluginPackageParser(com.morgoo.droidplugin.pm.parser.PluginPackageParser) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) RemoteException(android.os.RemoteException)

Example 3 with PluginPackageParser

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

the class IPluginManagerImpl method getReceiverInfo.

@Override
public ActivityInfo getReceiverInfo(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.getReceiverInfo(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)

Example 4 with PluginPackageParser

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

the class IPluginManagerImpl method getAllPermissionGroups.

@Override
public List<PermissionGroupInfo> getAllPermissionGroups(int flags) throws RemoteException {
    waitForReadyInner();
    try {
        enforcePluginFileExists();
        List<PermissionGroupInfo> list = new ArrayList<PermissionGroupInfo>();
        if (shouldNotBlockOtherInfo()) {
            for (PluginPackageParser pluginPackageParser : mPluginCache.values()) {
                List<PermissionGroupInfo> permissionGroupInfos = pluginPackageParser.getPermissionGroups();
                for (PermissionGroupInfo permissionGroupInfo : permissionGroupInfos) {
                    if (!list.contains(permissionGroupInfo)) {
                        list.add(permissionGroupInfo);
                    }
                }
            }
        } else {
            List<String> pkgs = mActivityManagerService.getPackageNamesByPid(Binder.getCallingPid());
            for (PluginPackageParser pluginPackageParser : mPluginCache.values()) {
                List<PermissionGroupInfo> permissionGroupInfos = pluginPackageParser.getPermissionGroups();
                for (PermissionGroupInfo permissionGroupInfo : permissionGroupInfos) {
                    if (!list.contains(permissionGroupInfo) && pkgs.contains(permissionGroupInfo.packageName)) {
                        list.add(permissionGroupInfo);
                    }
                }
            }
        }
        return list;
    } catch (Exception e) {
        handleException(e);
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) PermissionGroupInfo(android.content.pm.PermissionGroupInfo) PluginPackageParser(com.morgoo.droidplugin.pm.parser.PluginPackageParser) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) RemoteException(android.os.RemoteException)

Example 5 with PluginPackageParser

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

the class IPluginManagerImpl method getActivityInfo.

@Override
public ActivityInfo getActivityInfo(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.getActivityInfo(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