diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d56440a2..2e9af3b3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,10 @@ Test and beta releases will have experimental functions enabled by default. **Next release** +* Fixed not restricting if not using on demand ([issue](https://github.com/M66B/XPrivacy/issues/1242)) +* Fixed multiple on demand dialogs ([issue](https://github.com/M66B/XPrivacy/issues/1243)) +* Broken on demand asking for same restriction + [Open issues](https://github.com/M66B/XPrivacy/issues?state=open) **Version 1.99.29 TEST** diff --git a/src/biz/bokhorst/xprivacy/CRestriction.java b/src/biz/bokhorst/xprivacy/CRestriction.java index 70ae781fd..094f20673 100644 --- a/src/biz/bokhorst/xprivacy/CRestriction.java +++ b/src/biz/bokhorst/xprivacy/CRestriction.java @@ -8,7 +8,7 @@ public class CRestriction { public CRestriction(PRestriction restriction) { mTimestamp = new Date().getTime(); - mRestriction = restriction; + mRestriction = new PRestriction(restriction); } public PRestriction getRestriction() { @@ -16,7 +16,7 @@ public PRestriction getRestriction() { } public void setRestriction(PRestriction restriction) { - mRestriction = restriction; + mRestriction = new PRestriction(restriction); } public boolean isExpired() { diff --git a/src/biz/bokhorst/xprivacy/PRestriction.java b/src/biz/bokhorst/xprivacy/PRestriction.java index 97bd8d0c6..376fca450 100644 --- a/src/biz/bokhorst/xprivacy/PRestriction.java +++ b/src/biz/bokhorst/xprivacy/PRestriction.java @@ -14,6 +14,14 @@ public class PRestriction implements Parcelable { public PRestriction() { } + public PRestriction(PRestriction other) { + uid = other.uid; + restrictionName = other.restrictionName; + methodName = other.methodName; + restricted = other.restricted; + time = other.time; + } + public PRestriction(int _uid, String category, String method) { uid = _uid; restrictionName = category; diff --git a/src/biz/bokhorst/xprivacy/PSetting.java b/src/biz/bokhorst/xprivacy/PSetting.java index b927bd5b6..d6c2f7e21 100644 --- a/src/biz/bokhorst/xprivacy/PSetting.java +++ b/src/biz/bokhorst/xprivacy/PSetting.java @@ -11,6 +11,12 @@ public class PSetting implements Parcelable { public PSetting() { } + public PSetting(PSetting other) { + uid = other.uid; + name = other.name; + value = other.value; + } + public PSetting(int _uid, String _name, String _value) { uid = _uid; name = _name; diff --git a/src/biz/bokhorst/xprivacy/PrivacyService.java b/src/biz/bokhorst/xprivacy/PrivacyService.java index 1954a5dc3..82d1417b0 100644 --- a/src/biz/bokhorst/xprivacy/PrivacyService.java +++ b/src/biz/bokhorst/xprivacy/PrivacyService.java @@ -11,8 +11,8 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; -import java.util.concurrent.locks.ReentrantLock; import android.annotation.SuppressLint; import android.app.AlertDialog; @@ -60,7 +60,7 @@ public class PrivacyService { private static Handler mHandler = null; private static boolean mBootCompleted = false; - private static ReentrantLock mOndemandLock = new ReentrantLock(true); + private static Semaphore mOndemandSemaphore = new Semaphore(1, true); private static SQLiteStatement stmtGetRestriction = null; private static SQLiteStatement stmtGetSetting = null; @@ -81,7 +81,7 @@ public class PrivacyService { private static final int cMaxOnDemandDialog = 10; // seconds // TODO: define column names - // sqlite3 /data/data/biz.bokhorst.xprivacy/xprivacy.db + // sqlite3 /data/xprivacy/xprivacy.db public static void register(List listError, String secret) { // Store secret and errors @@ -129,9 +129,10 @@ public void run() { protected void beforeHookedMethod(MethodHookParam param) throws Throwable { try { // Delay ANR while on demand dialog open + boolean ondemanding = (mOndemandSemaphore.availablePermits() < 1); Util.log(null, Log.WARN, "Foreground ANR uid=" + getUidANR(param) + " ondemand=" - + mOndemandLock.isLocked()); - if (mOndemandLock.isLocked()) + + ondemanding); + if (ondemanding) param.setResult(5 * 1000); } catch (Throwable ex) { Util.bug(null, ex); @@ -153,9 +154,10 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable { protected void beforeHookedMethod(MethodHookParam param) throws Throwable { try { // Ignore ANR while on demand dialog open + boolean ondemanding = (mOndemandSemaphore.availablePermits() < 1); Util.log(null, Log.WARN, "Background ANR uid=" + getUidANR(param) + " ondemand=" - + mOndemandLock.isLocked()); - if (mOndemandLock.isLocked()) + + ondemanding); + if (ondemanding) param.setResult(null); } catch (Throwable ex) { Util.bug(null, ex); @@ -509,7 +511,7 @@ else if (PrivacyManager.cView.equals(restriction.restrictionName)) notifyRestricted(restriction); // Ask to restrict - if (!result.asked && usage && PrivacyManager.isApplication(restriction.uid)) + if (!result.restricted && !result.asked && usage && PrivacyManager.isApplication(restriction.uid)) result.restricted = onDemandDialog(hook, restriction); // Log usage @@ -1067,24 +1069,10 @@ private Boolean onDemandDialog(final Hook hook, final PRestriction restriction) // Go ask Util.log(null, Log.WARN, "On demand " + restriction); - mOndemandLock.lock(); + mOndemandSemaphore.acquireUninterruptibly(); try { Util.log(null, Log.WARN, "On demanding " + restriction); - // Check if not asked before - CRestriction key = new CRestriction(restriction); - synchronized (mRestrictionCache) { - if (mRestrictionCache.containsKey(key)) { - PRestriction cache = mRestrictionCache.get(key).getRestriction(); - result.restricted = cache.restricted; - result.asked = cache.asked; - } - } - if (result.asked) { - Util.log(null, Log.WARN, "Already asked " + restriction); - return result.restricted; - } - final AlertDialogHolder holder = new AlertDialogHolder(); final CountDownLatch latch = new CountDownLatch(1); @@ -1126,7 +1114,7 @@ public void run() { }); } } finally { - mOndemandLock.unlock(); + mOndemandSemaphore.release(); } } catch (Throwable ex) { Util.bug(null, ex);