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

Commit

Permalink
Added menu *Manage whitelists* to usage data view for a single applic…
Browse files Browse the repository at this point in the history
…ation

Refs #2093
  • Loading branch information
M66B committed Feb 13, 2015
1 parent b0c121a commit ef48ef1
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 17 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions res/menu/usage.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
<item
android:id="@+id/menu_clear"
android:title="@string/menu_clear_usage"/>
<item
android:id="@+id/menu_whitelists"
android:title="@string/menu_whitelists"/>
<item
android:id="@+id/menu_settings"
android:title="@string/menu_settings"/>
Expand Down
75 changes: 58 additions & 17 deletions src/biz/bokhorst/xprivacy/ActivityUsage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ef48ef1

Please sign in to comment.