Add root to application list

Shell is already part of the list

Fixes #283
This commit is contained in:
M66B 2016-02-04 16:43:06 +01:00
parent f6c2a3462f
commit 2dcaccd75a
3 changed files with 42 additions and 21 deletions

View File

@ -1095,7 +1095,10 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere
int block = Integer.parseInt(attributes.getValue("block"));
try {
packet.uid = getPackageManager().getApplicationInfo(pkg, 0).uid;
if ("root".equals(pkg))
packet.uid = 0;
else
packet.uid = getPackageManager().getApplicationInfo(pkg, 0).uid;
// This assumes ordered export
if (!listUid.contains(packet.uid)) {

View File

@ -22,6 +22,7 @@ package eu.faircode.netguard;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.XmlResourceParser;
@ -49,6 +50,7 @@ public class Rule {
public boolean system;
public boolean internet;
public boolean enabled;
public Intent intent;
public boolean wifi_default;
public boolean other_default;
@ -70,31 +72,37 @@ public class Rule {
public boolean changed;
public Intent intent;
public boolean expanded = false;
private Rule(PackageInfo info, Context context) {
PackageManager pm = context.getPackageManager();
this.info = info;
this.name = info.applicationInfo.loadLabel(pm).toString();
this.system = Util.isSystem(info.packageName, context);
this.internet = Util.hasInternet(info.packageName, context);
if (info.applicationInfo.uid == 0) {
this.name = context.getString(R.string.title_root);
this.system = true;
this.internet = true;
this.enabled = true;
this.intent = null;
} else {
this.name = info.applicationInfo.loadLabel(pm).toString();
this.system = Util.isSystem(info.packageName, context);
this.internet = Util.hasInternet(info.packageName, context);
int setting;
try {
setting = pm.getApplicationEnabledSetting(info.packageName);
} catch (IllegalArgumentException ex) {
setting = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
int setting;
try {
setting = pm.getApplicationEnabledSetting(info.packageName);
} catch (IllegalArgumentException ex) {
setting = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
}
if (setting == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT)
this.enabled = info.applicationInfo.enabled;
else
this.enabled = (setting == PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
this.intent = pm.getLaunchIntentForPackage(info.packageName);
}
if (setting == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT)
this.enabled = info.applicationInfo.enabled;
else
this.enabled = (setting == PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
this.intent = pm.getLaunchIntentForPackage(info.packageName);
}
public static List<Rule> getRules(boolean all, String tag, Context context) {
@ -168,8 +176,18 @@ public class Rule {
// Build rule list
List<Rule> listRules = new ArrayList<>();
List<PackageInfo> listPI = context.getPackageManager().getInstalledPackages(0);
for (PackageInfo info : context.getPackageManager().getInstalledPackages(0)) {
PackageInfo root = new PackageInfo();
root.packageName = "root";
root.versionCode = 0;
root.versionName = "0";
root.applicationInfo = new ApplicationInfo();
root.applicationInfo.uid = 0;
root.applicationInfo.icon = 0;
listPI.add(root);
for (PackageInfo info : listPI) {
Rule rule = new Rule(info, context);
if (pre_system.containsKey(info.packageName))

View File

@ -680,7 +680,7 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS
dh.insertLog(packet, dname, (last_connected ? last_metered ? 2 : 1 : 0), last_interactive);
// Application log
if (log_app && packet.uid > 0) {
if (log_app && packet.uid >= 0) {
if (dh.updateAccess(packet, dname, -1))
if (notify && prefs.getBoolean("notify_" + packet.uid, true) &&
(system || !Util.isSystem(packet.uid, SinkholeService.this)))
@ -1094,7 +1094,7 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS
if (packet.protocol == 6 /* TCP */ || packet.protocol == 17 /* UDP */
|| packet.protocol == 1 /* ICMPv4 */ || packet.protocol == 58 /* ICMPv6 */) {
if (prefs.getBoolean("filter", false)) {
if (packet.uid <= 0) // unknown, root
if (packet.uid < 0) // unknown
packet.allowed = true;
else {
boolean filtered = false;