diff --git a/CHANGELOG.md b/CHANGELOG.md index 92623df0f..529e06c9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ Changelog **Next release** * Updated Japanese translation +* Remember on demand dialog settings across reboots ([issue](/../../issues/1812)) * Showing stored version in *About* when different from current version [Open issues](https://github.com/M66B/XPrivacy/issues?state=open) diff --git a/src/biz/bokhorst/xprivacy/PrivacyManager.java b/src/biz/bokhorst/xprivacy/PrivacyManager.java index 1a5d11fc0..2d6dee459 100644 --- a/src/biz/bokhorst/xprivacy/PrivacyManager.java +++ b/src/biz/bokhorst/xprivacy/PrivacyManager.java @@ -125,6 +125,9 @@ public class PrivacyManager { public final static String cSettingNoResolve = "NoResolve"; public final static String cSettingFreeze = "Freeze"; public final static String cSettingPermMan = "PermMan"; + public final static String cSettingODExpert = "ODExpert"; + public final static String cSettingODCategory = "ODCategory"; + public final static String cSettingODOnce = "ODOnce"; // Special value names public final static String cValueRandom = "#Random#"; diff --git a/src/biz/bokhorst/xprivacy/PrivacyService.java b/src/biz/bokhorst/xprivacy/PrivacyService.java index ea6966b13..b45ba5171 100644 --- a/src/biz/bokhorst/xprivacy/PrivacyService.java +++ b/src/biz/bokhorst/xprivacy/PrivacyService.java @@ -230,9 +230,6 @@ public static PSetting getSetting(PSetting setting) throws RemoteException { private AtomicLong mCount = new AtomicLong(0); private AtomicLong mRestricted = new AtomicLong(0); - private boolean mSelectExpert = false; - private boolean mSelectCategory = true; - private boolean mSelectOnce = false; private Map mSettingCache = new HashMap(); private Map mAskedOnceCache = new HashMap(); @@ -1621,7 +1618,7 @@ public void run() { @SuppressLint("InflateParams") private View getOnDemandView(final PRestriction restriction, final Hook hook, ApplicationInfoEx appInfo, final PRestriction result, Context context, final OnDemandDialogHolder holder, - final OnDemandResult oResult) throws NameNotFoundException { + final OnDemandResult oResult) throws NameNotFoundException, RemoteException { // Get resources String self = PrivacyService.class.getPackage().getName(); Resources resources = context.getPackageManager().getResourcesForApplication(self); @@ -1652,7 +1649,11 @@ private View getOnDemandView(final PRestriction restriction, final Hook hook, Ap Button btnDontKnow = (Button) view.findViewById(R.id.btnDontKnow); Button btnAllow = (Button) view.findViewById(R.id.btnAllow); - boolean expert = (mSelectExpert || !mSelectCategory || mSelectOnce); + final int userId = Util.getUserId(Process.myUid()); + boolean expert = getSettingBool(userId, PrivacyManager.cSettingODExpert, false); + boolean category = getSettingBool(userId, PrivacyManager.cSettingODCategory, true); + boolean once = getSettingBool(userId, PrivacyManager.cSettingODOnce, false); + expert = expert || !category || once; final boolean whitelistDangerous = (hook != null && hook.isDangerous() && hook.whitelist() != null); // Set values @@ -1700,10 +1701,10 @@ private View getOnDemandView(final PRestriction restriction, final Hook hook, Ap llWhiteList.setVisibility(View.VISIBLE); // Category - cbCategory.setChecked(mSelectCategory); + cbCategory.setChecked(category); // Once - cbOnce.setChecked(mSelectOnce); + cbOnce.setChecked(once); cbOnce.setText(String.format(resources.getString(R.string.title_once), PrivacyManager.cRestrictionCacheTimeoutMs / 1000)); @@ -1729,10 +1730,10 @@ private View getOnDemandView(final PRestriction restriction, final Hook hook, Ap cbExpert.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - mSelectExpert = isChecked; + setSettingBool(userId, "", PrivacyManager.cSettingODExpert, isChecked); if (!isChecked) { - mSelectCategory = true; - mSelectOnce = false; + setSettingBool(userId, "", PrivacyManager.cSettingODCategory, true); + setSettingBool(userId, "", PrivacyManager.cSettingODOnce, false); cbCategory.setChecked(true); cbOnce.setChecked(false); cbWhitelist.setChecked(false); @@ -1833,8 +1834,8 @@ public void onClick(View v) { result.asked = true; if (!cbWhitelist.isChecked() && !cbWhitelistExtra1.isChecked() && !cbWhitelistExtra2.isChecked() && !cbWhitelistExtra3.isChecked()) { - mSelectCategory = cbCategory.isChecked(); - mSelectOnce = cbOnce.isChecked(); + setSettingBool(userId, "", PrivacyManager.cSettingODCategory, cbCategory.isChecked()); + setSettingBool(userId, "", PrivacyManager.cSettingODOnce, cbOnce.isChecked()); } if (cbWhitelist.isChecked()) onDemandWhitelist(restriction, null, result, hook); @@ -1871,8 +1872,8 @@ public void onClick(View view) { result.asked = true; if (!cbWhitelist.isChecked() && !cbWhitelistExtra1.isChecked() && !cbWhitelistExtra2.isChecked() && !cbWhitelistExtra3.isChecked()) { - mSelectCategory = cbCategory.isChecked(); - mSelectOnce = cbOnce.isChecked(); + setSettingBool(userId, "", PrivacyManager.cSettingODCategory, cbCategory.isChecked()); + setSettingBool(userId, "", PrivacyManager.cSettingODOnce, cbOnce.isChecked()); } if (cbWhitelist.isChecked()) onDemandWhitelist(restriction, null, result, hook); @@ -2074,6 +2075,14 @@ private boolean getSettingBool(int uid, String type, String name, boolean defaul return Boolean.parseBoolean(value); } + private void setSettingBool(int uid, String type, String name, boolean value) { + try { + setSettingInternal(new PSetting(uid, type, name, Boolean.toString(value))); + } catch (RemoteException ex) { + Util.bug(null, ex); + } + } + private void enforcePermission(int uid) { if (uid >= 0) if (Util.getUserId(uid) != Util.getUserId(Binder.getCallingUid()))