Several bug fixes

Fix #57
This commit is contained in:
topjohnwu
2017-01-31 03:39:24 +08:00
parent ed7920d61e
commit 0efb4da0ee
4 changed files with 192 additions and 181 deletions

View File

@ -11,7 +11,6 @@ public class Policy {
public static final int DENY = 1;
public static final int ALLOW = 2;
public int uid, policy;
public long until;
public boolean logging = true, notification = true;
@ -22,6 +21,7 @@ public class Policy {
String[] pkgs = pm.getPackagesForUid(uid);
if (pkgs != null && pkgs.length > 0) {
info = pm.getPackageInfo(pkgs[0], 0);
this.uid = uid;
packageName = pkgs[0];
appName = info.applicationInfo.loadLabel(pm).toString();
} else throw new PackageManager.NameNotFoundException();

View File

@ -87,11 +87,10 @@ public class SuRequestActivity extends AppCompatActivity implements CallbackHand
switch (Global.Configs.suResponseType) {
case AUTO_DENY:
event.trigger();
handleAction(Policy.DENY, 0);
return;
case AUTO_ALLOW:
policy.policy = Policy.ALLOW;
event.trigger(policy);
handleAction(Policy.ALLOW, 0);
return;
case PROMPT:
default:
@ -157,9 +156,12 @@ public class SuRequestActivity extends AppCompatActivity implements CallbackHand
}
void handleAction(int action) {
handleAction(action, timeoutList[timeout.getSelectedItemPosition()]);
}
void handleAction(int action, int time) {
policy.policy = action;
event.trigger(policy);
int time = timeoutList[timeout.getSelectedItemPosition()];
if (time >= 0) {
policy.until = time == 0 ? 0 : (System.currentTimeMillis() / 1000 + time * 60);
new SuDatabaseHelper(this).addPolicy(policy);