Skip to content
This repository has been archived by the owner on Sep 6, 2019. It is now read-only.

Commit

Permalink
Allow application in application package manager
Browse files Browse the repository at this point in the history
Refs #686
  • Loading branch information
M66B committed Nov 15, 2013
1 parent 2e06107 commit fb3e140
Showing 1 changed file with 41 additions and 4 deletions.
45 changes: 41 additions & 4 deletions src/biz/bokhorst/xprivacy/XApplicationPackageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,22 @@ protected void before(MethodHookParam param) throws Throwable {
// Do nothing
}

@SuppressWarnings("unchecked")
@Override
protected void after(MethodHookParam param) throws Throwable {
if (mMethod == Methods.getInstalledApplications) {
if (param.getResult() != null && isRestricted(param))
param.setResult(new ArrayList<ApplicationInfo>());
param.setResult(filterApplicationInfo((List<ApplicationInfo>) param.getResult()));
} else if (mMethod == Methods.getInstalledPackages || mMethod == Methods.getPreferredPackages) {
if (param.getResult() != null && isRestricted(param))
param.setResult(new ArrayList<PackageInfo>());
param.setResult(filterPackageInfo((List<PackageInfo>) param.getResult()));
} else if (mMethod == Methods.queryBroadcastReceivers || mMethod == Methods.queryIntentActivities
|| mMethod == Methods.queryIntentActivityOptions || mMethod == Methods.queryIntentServices) {
if (param.getResult() != null && isRestricted(param))
param.setResult(new ArrayList<ResolveInfo>());
param.setResult(filterResolveInfo((List<ResolveInfo>) param.getResult()));
} else if (mMethod == Methods.queryContentProviders) {
if (param.getResult() != null && isRestricted(param))
param.setResult(new ArrayList<ProviderInfo>());
param.setResult(filterProviderInfo((List<ProviderInfo>) param.getResult()));
} else
Util.log(this, Log.WARN, "Unknown method=" + param.method.getName());
}
Expand All @@ -89,4 +90,40 @@ protected boolean isRestricted(MethodHookParam param) throws Throwable {
int uid = Binder.getCallingUid();
return getRestricted(context, uid, true);
}

private List<ApplicationInfo> filterApplicationInfo(List<ApplicationInfo> original) {
ArrayList<ApplicationInfo> result = new ArrayList<ApplicationInfo>();
for (ApplicationInfo appInfo : original)
if (packageAllowed(appInfo.packageName))
result.add(appInfo);
return result;
}

private List<PackageInfo> filterPackageInfo(List<PackageInfo> original) {
ArrayList<PackageInfo> result = new ArrayList<PackageInfo>();
for (PackageInfo appInfo : original)
if (packageAllowed(appInfo.packageName))
result.add(appInfo);
return result;
}

private List<ProviderInfo> filterProviderInfo(List<ProviderInfo> original) {
ArrayList<ProviderInfo> result = new ArrayList<ProviderInfo>();
for (ProviderInfo appInfo : original)
if (packageAllowed(appInfo.packageName))
result.add(appInfo);
return result;
}

private List<ResolveInfo> filterResolveInfo(List<ResolveInfo> original) {
ArrayList<ResolveInfo> result = new ArrayList<ResolveInfo>();
for (ResolveInfo appInfo : original)
if (packageAllowed(appInfo.resolvePackageName))
result.add(appInfo);
return result;
}

private boolean packageAllowed(String packageName) {
return PrivacyManager.getSettingBool(null, null, 0, String.format("Application.%s", packageName), false, true);
}
}

0 comments on commit fb3e140

Please sign in to comment.