2017-01-24 14:19:28 +08:00
|
|
|
package com.topjohnwu.magisk.superuser;
|
|
|
|
|
|
|
|
import android.content.ContentValues;
|
2017-01-25 01:23:41 +08:00
|
|
|
import android.content.pm.PackageInfo;
|
|
|
|
import android.content.pm.PackageManager;
|
2017-01-24 14:19:28 +08:00
|
|
|
import android.database.Cursor;
|
|
|
|
|
|
|
|
|
|
|
|
public class Policy {
|
2017-01-26 01:13:23 +08:00
|
|
|
public static final int INTERACTIVE = 0;
|
|
|
|
public static final int DENY = 1;
|
|
|
|
public static final int ALLOW = 2;
|
|
|
|
|
|
|
|
|
2017-01-24 14:19:28 +08:00
|
|
|
public int uid, policy;
|
|
|
|
public long until;
|
2017-01-30 19:27:00 +08:00
|
|
|
public boolean logging = true, notification = true;
|
2017-01-24 14:19:28 +08:00
|
|
|
public String packageName, appName;
|
2017-01-30 19:27:00 +08:00
|
|
|
public PackageInfo info;
|
2017-01-24 14:19:28 +08:00
|
|
|
|
2017-01-30 19:27:00 +08:00
|
|
|
public Policy(int uid, PackageManager pm) throws PackageManager.NameNotFoundException {
|
2017-01-25 01:23:41 +08:00
|
|
|
String[] pkgs = pm.getPackagesForUid(uid);
|
|
|
|
if (pkgs != null && pkgs.length > 0) {
|
2017-01-30 19:27:00 +08:00
|
|
|
info = pm.getPackageInfo(pkgs[0], 0);
|
2017-01-25 01:23:41 +08:00
|
|
|
packageName = pkgs[0];
|
|
|
|
appName = info.applicationInfo.loadLabel(pm).toString();
|
2017-01-30 19:27:00 +08:00
|
|
|
} else throw new PackageManager.NameNotFoundException();
|
2017-01-25 01:23:41 +08:00
|
|
|
}
|
|
|
|
|
2017-01-24 14:19:28 +08:00
|
|
|
public Policy(Cursor c) {
|
|
|
|
uid = c.getInt(c.getColumnIndex("uid"));
|
|
|
|
packageName = c.getString(c.getColumnIndex("package_name"));
|
|
|
|
appName = c.getString(c.getColumnIndex("app_name"));
|
|
|
|
policy = c.getInt(c.getColumnIndex("policy"));
|
|
|
|
until = c.getLong(c.getColumnIndex("until"));
|
|
|
|
logging = c.getInt(c.getColumnIndex("logging")) != 0;
|
|
|
|
notification = c.getInt(c.getColumnIndex("notification")) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ContentValues getContentValues() {
|
|
|
|
ContentValues values = new ContentValues();
|
|
|
|
values.put("uid", uid);
|
|
|
|
values.put("package_name", packageName);
|
|
|
|
values.put("app_name", appName);
|
2017-01-27 01:02:40 +08:00
|
|
|
values.put("policy", policy);
|
2017-01-24 14:19:28 +08:00
|
|
|
values.put("until", until);
|
|
|
|
values.put("logging", logging ? 1 : 0);
|
|
|
|
values.put("notification", notification ? 1 : 0);
|
|
|
|
return values;
|
|
|
|
}
|
|
|
|
}
|