From 92a136c4cd7e5ce0920699d8e6658bc3336703b4 Mon Sep 17 00:00:00 2001 From: Marcel Bokhorst Date: Sat, 22 Jun 2013 08:10:21 +0200 Subject: [PATCH] Remove notification for uninstalled apps, fixes #51 --- src/biz/bokhorst/xprivacy/ActivityApp.java | 4 ++++ src/biz/bokhorst/xprivacy/PackageChange.java | 5 +++-- src/biz/bokhorst/xprivacy/XApplicationInfo.java | 12 ++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/biz/bokhorst/xprivacy/ActivityApp.java b/src/biz/bokhorst/xprivacy/ActivityApp.java index 42a02eae0..a5a702e18 100644 --- a/src/biz/bokhorst/xprivacy/ActivityApp.java +++ b/src/biz/bokhorst/xprivacy/ActivityApp.java @@ -46,6 +46,10 @@ public void onCreate(Bundle savedInstanceState) { // Get app info mAppInfo = new XApplicationInfo(packageName, this); + if (!mAppInfo.getIsInstalled()) { + finish(); + return; + } // Background color if (mAppInfo.getIsSystem()) { diff --git a/src/biz/bokhorst/xprivacy/PackageChange.java b/src/biz/bokhorst/xprivacy/PackageChange.java index dfab0e80a..05c62d02b 100644 --- a/src/biz/bokhorst/xprivacy/PackageChange.java +++ b/src/biz/bokhorst/xprivacy/PackageChange.java @@ -26,6 +26,8 @@ public void onReceive(Context context, Intent intent) { boolean replacing = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false); boolean expert = Boolean.parseBoolean(XRestriction.getSetting(null, context, XRestriction.cSettingExpert, Boolean.FALSE.toString())); + NotificationManager notificationManager = (NotificationManager) context + .getSystemService(Context.NOTIFICATION_SERVICE); // Log XUtil.log(null, Log.INFO, intent.getAction() + " package=" + packageName + " uid=" + uid + " replacing=" @@ -70,12 +72,11 @@ public void onReceive(Context context, Intent intent) { Notification notification = notificationBuilder.build(); // Notify - NotificationManager notificationManager = (NotificationManager) context - .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(pInfo.applicationInfo.uid, notification); } } else if (intent.getAction().equals(Intent.ACTION_PACKAGE_REMOVED) && !replacing) { // Package removed + notificationManager.cancel(uid); // Remove existing restrictions for (String restrictionName : XRestriction.getRestrictions(context)) diff --git a/src/biz/bokhorst/xprivacy/XApplicationInfo.java b/src/biz/bokhorst/xprivacy/XApplicationInfo.java index 8c01db6c6..adcbeca39 100644 --- a/src/biz/bokhorst/xprivacy/XApplicationInfo.java +++ b/src/biz/bokhorst/xprivacy/XApplicationInfo.java @@ -8,6 +8,7 @@ import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; +import android.content.pm.PackageManager.NameNotFoundException; import android.graphics.drawable.Drawable; import android.text.TextUtils; import android.util.SparseArray; @@ -20,12 +21,15 @@ public class XApplicationInfo implements Comparable { private int mUid; private String mVersion; private boolean mSystem; + private boolean mInstalled; public XApplicationInfo(String packageName, Context context) { // Get app info try { ApplicationInfo appInfo = context.getPackageManager().getApplicationInfo(packageName, 0); this.Initialize(appInfo, context); + } catch (NameNotFoundException ex) { + mInstalled = false; } catch (Throwable ex) { XUtil.bug(null, ex); return; @@ -46,7 +50,11 @@ private void Initialize(ApplicationInfo appInfo, Context context) { mUid = appInfo.uid; try { mVersion = pm.getPackageInfo(appInfo.packageName, 0).versionName; + mInstalled = true; + } catch (NameNotFoundException ex) { + mInstalled = false; } catch (Throwable ex) { + mInstalled = false; XUtil.bug(null, ex); } mSystem = ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0); @@ -112,6 +120,10 @@ public boolean getIsSystem() { return mSystem; } + public boolean getIsInstalled() { + return mInstalled; + } + @Override @SuppressLint("DefaultLocale") public String toString() {