From 15ca18848ec03f03fb34e55097591f11b4e1ad30 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Thu, 26 Jan 2017 03:30:12 +0800 Subject: [PATCH] Add su revoke --- .../magisk/adapters/ModulesAdapter.java | 8 +-- .../magisk/adapters/PolicyAdapter.java | 54 +++++++++++++------ app/src/main/res/drawable/ic_delete.xml | 2 +- app/src/main/res/drawable/ic_delete_black.xml | 9 ---- app/src/main/res/layout/list_item_module.xml | 1 + app/src/main/res/layout/list_item_policy.xml | 10 ++++ app/src/main/res/menu/menu_log.xml | 2 +- app/src/main/res/values/strings.xml | 15 ++++-- 8 files changed, 66 insertions(+), 35 deletions(-) delete mode 100644 app/src/main/res/drawable/ic_delete_black.xml diff --git a/app/src/main/java/com/topjohnwu/magisk/adapters/ModulesAdapter.java b/app/src/main/java/com/topjohnwu/magisk/adapters/ModulesAdapter.java index 35df917ef..65504c34c 100644 --- a/app/src/main/java/com/topjohnwu/magisk/adapters/ModulesAdapter.java +++ b/app/src/main/java/com/topjohnwu/magisk/adapters/ModulesAdapter.java @@ -61,8 +61,8 @@ public class ModulesAdapter extends RecyclerView.Adapter { @@ -63,38 +64,56 @@ public class PolicyAdapter extends RecyclerView.Adapter { - if (isChecked && policy.policy == Policy.DENY) { - policy.policy = Policy.ALLOW; - dbHelper.addPolicy(policy); - } else if (!isChecked && policy.policy == Policy.ALLOW) { - policy.policy = Policy.DENY; + if ((isChecked && policy.policy == Policy.DENY) || + (!isChecked && policy.policy == Policy.ALLOW)) { + policy.policy = isChecked ? Policy.ALLOW : Policy.DENY; + String message = v.getContext().getString( + isChecked ? R.string.su_snack_grant : R.string.su_snack_deny, policy.appName); + Snackbar.make(holder.itemView, message, Snackbar.LENGTH_SHORT).show(); dbHelper.addPolicy(policy); } }); holder.notificationSwitch.setOnCheckedChangeListener((v, isChecked) -> { - if (isChecked && !policy.notification) { - policy.notification = true; - dbHelper.addPolicy(policy); - } else if (!isChecked && policy.notification) { - policy.notification = false; + if ((isChecked && !policy.notification) || + (!isChecked && policy.notification)) { + policy.notification = isChecked; + String message = v.getContext().getString( + isChecked ? R.string.su_snack_notif_on : R.string.su_snack_notif_off, policy.appName); + Snackbar.make(holder.itemView, message, Snackbar.LENGTH_SHORT).show(); dbHelper.addPolicy(policy); } }); holder.loggingSwitch.setOnCheckedChangeListener((v, isChecked) -> { - if (isChecked && !policy.logging) { - policy.logging = true; - dbHelper.addPolicy(policy); - } else if (!isChecked && policy.logging) { - policy.logging = false; + if ((isChecked && !policy.logging) || + (!isChecked && policy.logging)) { + policy.logging = isChecked; + String message = v.getContext().getString( + isChecked ? R.string.su_snack_log_on : R.string.su_snack_log_off, policy.appName); + Snackbar.make(holder.itemView, message, Snackbar.LENGTH_SHORT).show(); dbHelper.addPolicy(policy); } }); + holder.delete.setOnClickListener(v -> Utils.getAlertDialogBuilder(v.getContext()) + .setTitle(R.string.su_revoke_title) + .setMessage(v.getContext().getString(R.string.su_revoke_msg, policy.appName)) + .setPositiveButton(R.string.yes, (dialog, which) -> { + policyList.remove(position); + notifyItemRemoved(position); + notifyItemRangeChanged(position, policyList.size()); + Snackbar.make(holder.itemView, v.getContext().getString(R.string.su_snack_revoke, policy.appName), + Snackbar.LENGTH_SHORT).show(); + dbHelper.deletePolicy(policy.uid); + }) + .setNegativeButton(R.string.no_thanks, null) + .setCancelable(true) + .show()); holder.masterSwitch.setChecked(policy.policy == Policy.ALLOW); holder.notificationSwitch.setChecked(policy.notification); holder.loggingSwitch.setChecked(policy.logging); } catch (PackageManager.NameNotFoundException e) { policyList.remove(position); + dbHelper.deletePolicy(policy.uid); notifyItemRemoved(position); notifyItemRangeChanged(position, policyList.size()); onBindViewHolder(holder, position); @@ -116,6 +135,7 @@ public class PolicyAdapter extends RecyclerView.Adapter diff --git a/app/src/main/res/drawable/ic_delete_black.xml b/app/src/main/res/drawable/ic_delete_black.xml deleted file mode 100644 index 7de27c6a9..000000000 --- a/app/src/main/res/drawable/ic_delete_black.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - diff --git a/app/src/main/res/layout/list_item_module.xml b/app/src/main/res/layout/list_item_module.xml index b53f90b93..6c0b70774 100644 --- a/app/src/main/res/layout/list_item_module.xml +++ b/app/src/main/res/layout/list_item_module.xml @@ -106,6 +106,7 @@ android:gravity="center" android:padding="@dimen/checkbox_padding" android:src="@drawable/ic_delete" + android:tint="@color/icon_grey" tools:ignore="ContentDescription"/> diff --git a/app/src/main/res/layout/list_item_policy.xml b/app/src/main/res/layout/list_item_policy.xml index bb6b723d3..e32ef2c96 100644 --- a/app/src/main/res/layout/list_item_policy.xml +++ b/app/src/main/res/layout/list_item_policy.xml @@ -142,6 +142,16 @@ + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0a6c6ed59..52ba65777 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -87,6 +87,7 @@ This feature will not work without permission to write external storage. No thanks + Yes Install %1$s Do you want to install %1$s ? Download & install @@ -155,9 +156,17 @@ 20 min 30 min 60 min - %1$s is granted Superuser permissions - %1$s is denied Superuser permissions + %1$s is granted Superuser rights + %1$s is denied Superuser rights No apps found - + Superuser rights of %1$s is granted + Superuser rights of %1$s is denied + Notifications of %1$s is enabled + Notifications of %1$s is disabled + Logging of %1$s is enabled + Logging of %1$s is disabled + %1$s rights are revoked + Revoke? + Confirm to revoke %1$s rights?