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

Commit

Permalink
Do not notify if on demand (2)
Browse files Browse the repository at this point in the history
Resf #1417
  • Loading branch information
M66B committed Feb 22, 2014
1 parent e51c71c commit fe76ae6
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/biz/bokhorst/xprivacy/PrivacyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -572,13 +572,13 @@ public PRestriction getRestriction(final PRestriction restriction, boolean usage
}

// Ask to restrict
boolean ondemand = false;
if (!mresult.asked && usage && PrivacyManager.isApplication(restriction.uid))
onDemandDialog(hook, restriction, mresult);
else {
// Notify user
if (mresult.restricted && hook != null && hook.shouldNotify())
notifyRestricted(restriction);
}
ondemand = onDemandDialog(hook, restriction, mresult);

// Notify user
if (!ondemand && mresult.restricted && usage && hook != null && hook.shouldNotify())
notifyRestricted(restriction);

// Log usage
if (usage && hook != null && hook.hasUsageData())
Expand Down Expand Up @@ -1141,32 +1141,32 @@ public void dump(int uid) throws RemoteException {

// Helper methods

private void onDemandDialog(final Hook hook, final PRestriction restriction, final PRestriction result) {
private boolean onDemandDialog(final Hook hook, final PRestriction restriction, final PRestriction result) {
// Neither category nor method is restricted and asked for
try {
// Without handler nothing can be done
if (mHandler == null)
return;
return false;

// Check for exceptions
if (hook != null && !hook.canOnDemand())
return;
return false;

// Check if enabled
if (!getSettingBool(0, PrivacyManager.cSettingOnDemand, true))
return;
return false;
if (!getSettingBool(restriction.uid, PrivacyManager.cSettingOnDemand, false))
return;
return false;

// Skip dangerous methods
final boolean dangerous = getSettingBool(0, PrivacyManager.cSettingDangerous, false);
if (!dangerous && hook != null && hook.isDangerous())
return;
return false;

// Get am context
final Context context = getContext();
if (context == null)
return;
return false;

long token = 0;
try {
Expand All @@ -1177,15 +1177,15 @@ private void onDemandDialog(final Hook hook, final PRestriction restriction, fin

// Check if system application
if (!dangerous && appInfo.isSystem())
return;
return false;

// Go ask
Util.log(null, Log.WARN, "On demand " + restriction);
mOndemandSemaphore.acquireUninterruptibly();
try {
// Check if activity manager agrees
if (!XActivityManagerService.canOnDemand())
return;
return false;

Util.log(null, Log.WARN, "On demanding " + restriction);

Expand All @@ -1195,21 +1195,21 @@ private void onDemandDialog(final Hook hook, final PRestriction restriction, fin
if (mRestrictionCache.containsKey(key))
if (mRestrictionCache.get(key).asked) {
Util.log(null, Log.WARN, "Already asked " + restriction);
return;
return false;
}
}
synchronized (mAskedOnceCache) {
if (mAskedOnceCache.containsKey(key) && !mAskedOnceCache.get(key).isExpired()) {
Util.log(null, Log.WARN, "Already asked once " + restriction);
return;
return false;
}
}
if (hook != null && hook.whitelist() != null) {
CSetting skey = new CSetting(restriction.uid, hook.whitelist() + "." + restriction.extra);
synchronized (mSettingCache) {
if (mSettingCache.containsKey(skey)) {
Util.log(null, Log.WARN, "Already asked " + skey);
return;
return false;
}
}
}
Expand Down Expand Up @@ -1282,6 +1282,8 @@ public void run() {
} catch (Throwable ex) {
Util.bug(null, ex);
}

return true;
}

final class AlertDialogHolder {
Expand Down

0 comments on commit fe76ae6

Please sign in to comment.