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

Commit

Permalink
Remove notification for uninstalled apps, fixes #51
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcel Bokhorst committed Jun 22, 2013
1 parent 23001d2 commit 92a136c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/biz/bokhorst/xprivacy/ActivityApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
5 changes: 3 additions & 2 deletions src/biz/bokhorst/xprivacy/PackageChange.java
Original file line number Diff line number Diff line change
Expand Up @@ -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="
Expand Down Expand Up @@ -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))
Expand Down
12 changes: 12 additions & 0 deletions src/biz/bokhorst/xprivacy/XApplicationInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,12 +21,15 @@ public class XApplicationInfo implements Comparable<XApplicationInfo> {
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;
Expand All @@ -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);
Expand Down Expand Up @@ -112,6 +120,10 @@ public boolean getIsSystem() {
return mSystem;
}

public boolean getIsInstalled() {
return mInstalled;
}

@Override
@SuppressLint("DefaultLocale")
public String toString() {
Expand Down

0 comments on commit 92a136c

Please sign in to comment.