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;
}
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);
}
}
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;
}
}
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;
}
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;
}
Aggregations