From ef48ef13a484fb6a4eef280238c0c9dcc820f942 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 13 Feb 2015 18:34:09 +0100 Subject: [PATCH] Added menu *Manage whitelists* to usage data view for a single application Refs #2093 --- CHANGELOG.md | 2 + res/menu/usage.xml | 3 + src/biz/bokhorst/xprivacy/ActivityUsage.java | 75 +++++++++++++++----- 3 files changed, 63 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1601a7685..697c368e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,8 @@ Changelog **Next release** +* Reverted "Manage white/black lists from usage data" ([issue](/../../issues/2093)) +* Added menu *Manage whitelists* to usage data view for a single application ([issue](/../../issues/2093)) * Updated Czech translation [Open issues](https://github.com/M66B/XPrivacy/issues?state=open) diff --git a/res/menu/usage.xml b/res/menu/usage.xml index 452c79270..80a33590e 100644 --- a/res/menu/usage.xml +++ b/res/menu/usage.xml @@ -10,6 +10,9 @@ + diff --git a/src/biz/bokhorst/xprivacy/ActivityUsage.java b/src/biz/bokhorst/xprivacy/ActivityUsage.java index 2d9bcd41f..922ae2383 100644 --- a/src/biz/bokhorst/xprivacy/ActivityUsage.java +++ b/src/biz/bokhorst/xprivacy/ActivityUsage.java @@ -11,7 +11,9 @@ import java.util.concurrent.ThreadFactory; import android.annotation.SuppressLint; +import android.app.AlertDialog; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.graphics.Color; import android.graphics.drawable.Drawable; @@ -101,6 +103,12 @@ public boolean onCreateOptionsMenu(Menu menu) { return false; } + @Override + public boolean onPrepareOptionsMenu(Menu menu) { + menu.findItem(R.id.menu_whitelists).setVisible(mUid != 0); + return super.onPrepareOptionsMenu(menu); + } + @Override public boolean onOptionsItemSelected(MenuItem item) { UsageTask usageTask; @@ -132,6 +140,16 @@ public boolean onOptionsItemSelected(MenuItem item) { usageTask.executeOnExecutor(mExecutor, (Object) null); return true; + case R.id.menu_whitelists: + if (Util.hasProLicense(this) == null) { + // Redirect to pro page + Util.viewUri(this, ActivityMain.cProUri); + } else { + WhitelistTask whitelistsTask = new WhitelistTask(mUid, null, this); + whitelistsTask.executeOnExecutor(mExecutor, (Object) null); + } + return true; + case R.id.menu_settings: Intent intent = new Intent(this, ActivitySettings.class); startActivity(intent); @@ -301,33 +319,56 @@ public void onClick(View view) { View.OnLongClickListener longClickListener = new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { - final int userId = Util.getUserId(Process.myUid()); + int userId = Util.getUserId(Process.myUid()); final PRestriction usageData = mUsageAdapter.getItem(position); final Hook hook = PrivacyManager.getHook(usageData.restrictionName, usageData.methodName); - final boolean isApp = PrivacyManager.isApplication(usageData.uid); - final boolean odSystem = PrivacyManager.getSettingBool(userId, + boolean isApp = PrivacyManager.isApplication(usageData.uid); + boolean odSystem = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingOnDemandSystem, false); + final boolean wnomod = PrivacyManager.getSettingBool(usageData.uid, + PrivacyManager.cSettingWhitelistNoModify, false); if ((isApp || odSystem) && hook != null && hook.whitelist() != null && usageData.extra != null) { if (Util.hasProLicense(ActivityUsage.this) == null) Util.viewUri(ActivityUsage.this, ActivityMain.cProUri); else { - // Toggle whitelist entry - Boolean current = PrivacyManager.getSettingBool(usageData.uid, hook.whitelist(), - usageData.extra, false); - PrivacyManager.setSetting(usageData.uid, hook.whitelist(), usageData.extra, - Boolean.toString(!current)); - final boolean wnomod = PrivacyManager.getSettingBool(usageData.uid, - PrivacyManager.cSettingWhitelistNoModify, false); - if (!wnomod) - PrivacyManager.updateState(usageData.uid); - - // Show whitelist manager - WhitelistTask whitelistsTask = new WhitelistTask(usageData.uid, hook.whitelist(), - ActivityUsage.this); - whitelistsTask.executeOnExecutor(mExecutor, (Object) null); + AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ActivityUsage.this); + alertDialogBuilder.setTitle(R.string.menu_whitelists); + alertDialogBuilder.setMessage(usageData.restrictionName + "/" + + usageData.methodName + "(" + usageData.extra + ")"); + alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher)); + alertDialogBuilder.setPositiveButton(getString(R.string.title_deny), + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + // Deny + PrivacyManager.setSetting(usageData.uid, hook.whitelist(), + usageData.extra, Boolean.toString(false)); + if (!wnomod) + PrivacyManager.updateState(usageData.uid); + } + }); + alertDialogBuilder.setNeutralButton(getString(R.string.title_allow), + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + // Allow + PrivacyManager.setSetting(usageData.uid, hook.whitelist(), + usageData.extra, Boolean.toString(true)); + if (!wnomod) + PrivacyManager.updateState(usageData.uid); + } + }); + alertDialogBuilder.setNegativeButton(getString(android.R.string.cancel), + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + } + }); + AlertDialog alertDialog = alertDialogBuilder.create(); + alertDialog.show(); } return true; } else