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

Commit

Permalink
Remember on demand dialog settings across reboots
Browse files Browse the repository at this point in the history
Fixes #1812
  • Loading branch information
M66B committed Jul 15, 2014
1 parent 32b3130 commit 96a95f0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions src/biz/bokhorst/xprivacy/PrivacyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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#";
Expand Down
37 changes: 23 additions & 14 deletions src/biz/bokhorst/xprivacy/PrivacyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<CSetting, CSetting> mSettingCache = new HashMap<CSetting, CSetting>();
private Map<CRestriction, CRestriction> mAskedOnceCache = new HashMap<CRestriction, CRestriction>();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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));

Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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()))
Expand Down

0 comments on commit 96a95f0

Please sign in to comment.