From 478b7eeb65acff7870d1b728179403ec02c85b7e Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Wed, 25 Jan 2017 02:16:36 +0800 Subject: [PATCH] Stop countdown when user reacts --- .../magisk/superuser/SuRequestActivity.java | 27 +++++++++++++++++-- app/src/main/res/layout/activity_request.xml | 2 +- app/src/main/res/values/strings.xml | 2 +- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/superuser/SuRequestActivity.java b/app/src/main/java/com/topjohnwu/magisk/superuser/SuRequestActivity.java index 9ee97b1d3..1049b2da3 100644 --- a/app/src/main/java/com/topjohnwu/magisk/superuser/SuRequestActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/superuser/SuRequestActivity.java @@ -8,11 +8,13 @@ import android.net.LocalSocket; import android.net.LocalSocketAddress; import android.os.AsyncTask; import android.os.Bundle; +import android.os.CountDownTimer; import android.support.v7.app.AppCompatActivity; import android.view.Window; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ImageView; +import android.widget.LinearLayout; import android.widget.Spinner; import android.widget.TextView; @@ -30,6 +32,7 @@ public class SuRequestActivity extends AppCompatActivity { private final static int SU_PROTOCOL_NAME_MAX = 20; private final static int SU_PROTOCOL_VALUE_MAX = 256; + @BindView(R.id.su_popup) LinearLayout suPopup; @BindView(R.id.timeout) Spinner timeout; @BindView(R.id.app_icon) ImageView appIcon; @BindView(R.id.app_name) TextView appNameView; @@ -42,8 +45,9 @@ public class SuRequestActivity extends AppCompatActivity { private PackageManager pm; private PackageInfo info; - private int uid; + private int uid, countdown = 10; private String appName, packageName; + private CountDownTimer timer; private int[] timeoutList = {0, -1, 10, 20, 30, 60}; @@ -70,8 +74,27 @@ public class SuRequestActivity extends AppCompatActivity { appNameView.setText(appName); packageNameView.setText(packageName); + timer = new CountDownTimer(countdown * 1000, 1000) { + @Override + public void onTick(long millisUntilFinished) { + deny_btn.setText(getString(R.string.deny, "(" + millisUntilFinished / 1000 + ")")); + } + @Override + public void onFinish() { + deny_btn.setText(getString(R.string.deny, "(0)")); + handleAction(false, -1); + } + }; + grant_btn.setOnClickListener(v -> handleAction(true, timeoutList[timeout.getSelectedItemPosition()])); deny_btn.setOnClickListener(v -> handleAction(false, timeoutList[timeout.getSelectedItemPosition()])); + suPopup.setOnClickListener(v -> { + timer.cancel(); + deny_btn.setText(getString(R.string.deny, "")); + }); + + timer.start(); + } void handleAction(boolean action, int timeout) { @@ -85,7 +108,7 @@ public class SuRequestActivity extends AppCompatActivity { policy.uid = uid; policy.packageName = packageName; policy.appName = appName; - policy.until = (timeout == 0) ? 0 : System.currentTimeMillis() + timeout * 60 * 1000; + policy.until = (timeout == 0) ? 0 : (System.currentTimeMillis() / 1000 + timeout * 60); policy.policy = action ? 2 : 1; policy.logging = true; policy.notification = true; diff --git a/app/src/main/res/layout/activity_request.xml b/app/src/main/res/layout/activity_request.xml index 2d617f845..3a0659f51 100644 --- a/app/src/main/res/layout/activity_request.xml +++ b/app/src/main/res/layout/activity_request.xml @@ -1,8 +1,8 @@ Superuser Request - Deny + Deny%1$s Grant Grants full access to your device.\nDeny if you\'re not sure! Forever