From 740f922abd9c82ec30b791dce5ec5e0bb7799a7d Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 13 Dec 2014 08:14:21 +0100 Subject: [PATCH] Allow querying information about own package Closes #2079 --- CHANGELOG.md | 1 + .../bokhorst/xprivacy/XActivityThread.java | 2 +- .../bokhorst/xprivacy/XContentResolver.java | 2 +- .../bokhorst/xprivacy/XIntentFirewall.java | 2 +- .../bokhorst/xprivacy/XPackageManager.java | 19 ++++++++++--------- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1cb1e2eeb..b23933392 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ See for more information about XPrivacy 3 [this FAQ](https://github.com/M66B/XPr * Broadcast *biz.bokhorst.xprivacy.action.EXCEPTION* if the database could not be read ([issue](/../../issues/2081)) * Fixed all problems reported through the debug info +* Allow querying information about own package in most cases ([issue](/../../issues/2079)) * Updated French translation * Updated Indonesian translation * Updated Polish translation diff --git a/src/biz/bokhorst/xprivacy/XActivityThread.java b/src/biz/bokhorst/xprivacy/XActivityThread.java index 4f0820da8..fbcba3d6c 100644 --- a/src/biz/bokhorst/xprivacy/XActivityThread.java +++ b/src/biz/bokhorst/xprivacy/XActivityThread.java @@ -180,7 +180,7 @@ private boolean checkIntent(int uid, Intent intent) throws Throwable { else packageNames = new String[] { intent.getData().getSchemeSpecificPart() }; for (String packageName : packageNames) - if (!XPackageManager.isPackageAllowed(packageName)) + if (!XPackageManager.isPackageAllowed(0, packageName)) return true; } diff --git a/src/biz/bokhorst/xprivacy/XContentResolver.java b/src/biz/bokhorst/xprivacy/XContentResolver.java index a7db625b2..6edbca1d9 100644 --- a/src/biz/bokhorst/xprivacy/XContentResolver.java +++ b/src/biz/bokhorst/xprivacy/XContentResolver.java @@ -344,7 +344,7 @@ private void handleUriAfter(XParam param) throws Throwable { while (cursor.moveToNext()) { int colPackage = cursor.getColumnIndex("package"); String packageName = (colPackage < 0 ? null : cursor.getString(colPackage)); - if (packageName != null && XPackageManager.isPackageAllowed(packageName)) + if (packageName != null && XPackageManager.isPackageAllowed(0, packageName)) copyColumns(cursor, result); } result.respond(cursor.getExtras()); diff --git a/src/biz/bokhorst/xprivacy/XIntentFirewall.java b/src/biz/bokhorst/xprivacy/XIntentFirewall.java index 4a16371d2..6154eb528 100644 --- a/src/biz/bokhorst/xprivacy/XIntentFirewall.java +++ b/src/biz/bokhorst/xprivacy/XIntentFirewall.java @@ -148,7 +148,7 @@ private boolean isIntentRestricted(int uid, Intent intent) throws Throwable { else packageNames = new String[] { intent.getData().getSchemeSpecificPart() }; for (String packageName : packageNames) - if (!XPackageManager.isPackageAllowed(packageName)) + if (!XPackageManager.isPackageAllowed(0, packageName)) return true; } diff --git a/src/biz/bokhorst/xprivacy/XPackageManager.java b/src/biz/bokhorst/xprivacy/XPackageManager.java index 18094c694..a067b943f 100644 --- a/src/biz/bokhorst/xprivacy/XPackageManager.java +++ b/src/biz/bokhorst/xprivacy/XPackageManager.java @@ -169,15 +169,13 @@ protected void after(XParam param) throws Throwable { ApplicationInfo aInfo = (ApplicationInfo) param.getResult(); uid = aInfo.uid; } - if (uid == Binder.getCallingUid()) - return; String packageName = (String) param.args[0]; // Prevent recursion if (!XPackageManager.class.getPackage().getName().equals(packageName)) if (isRestrictedExtra(param, packageName)) - if (!isPackageAllowed(packageName)) + if (!isPackageAllowed(uid, packageName)) param.setResult(null); } break; @@ -348,7 +346,7 @@ private void checkPermission(XParam param, int uid, String permName) throws Thro private List filterApplicationInfo(List original) { ArrayList result = new ArrayList(); for (ApplicationInfo appInfo : original) - if (isPackageAllowed(appInfo.packageName)) + if (isPackageAllowed(appInfo.uid, appInfo.packageName)) result.add(appInfo); return result; } @@ -356,7 +354,7 @@ private List filterApplicationInfo(List origin private List filterPackageInfo(List original) { ArrayList result = new ArrayList(); for (PackageInfo pkgInfo : original) - if (isPackageAllowed(pkgInfo.packageName)) + if (isPackageAllowed(pkgInfo.applicationInfo == null ? 0 : pkgInfo.applicationInfo.uid, pkgInfo.packageName)) result.add(pkgInfo); return result; } @@ -364,7 +362,8 @@ private List filterPackageInfo(List original) { private List filterProviderInfo(List original) { ArrayList result = new ArrayList(); for (ProviderInfo provInfo : original) - if (isPackageAllowed(provInfo.packageName)) + if (isPackageAllowed(provInfo.applicationInfo == null ? 0 : provInfo.applicationInfo.uid, + provInfo.packageName)) result.add(provInfo); return result; } @@ -373,13 +372,15 @@ private List filterResolveInfo(List original) { ArrayList result = new ArrayList(); for (ResolveInfo resInfo : original) if (resInfo.activityInfo != null && resInfo.activityInfo.applicationInfo != null) - if (isPackageAllowed(resInfo.activityInfo.applicationInfo.packageName)) + if (isPackageAllowed(resInfo.activityInfo.applicationInfo.uid, + resInfo.activityInfo.applicationInfo.packageName)) result.add(resInfo); return result; } - public static boolean isPackageAllowed(String packageName) { - int uid = Binder.getCallingUid(); + public static boolean isPackageAllowed(int uid, String packageName) { + if (uid == Binder.getCallingUid()) + return true; if (packageName == null) { Util.log(null, Log.WARN, "isPackageAllowed uid=" + uid + " package=" + packageName);