mirror of https://github.com/M66B/NetGuard.git
Add root to application list
Shell is already part of the list Fixes #283
This commit is contained in:
parent
f6c2a3462f
commit
2dcaccd75a
|
@ -1095,6 +1095,9 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere
|
||||||
int block = Integer.parseInt(attributes.getValue("block"));
|
int block = Integer.parseInt(attributes.getValue("block"));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if ("root".equals(pkg))
|
||||||
|
packet.uid = 0;
|
||||||
|
else
|
||||||
packet.uid = getPackageManager().getApplicationInfo(pkg, 0).uid;
|
packet.uid = getPackageManager().getApplicationInfo(pkg, 0).uid;
|
||||||
|
|
||||||
// This assumes ordered export
|
// This assumes ordered export
|
||||||
|
|
|
@ -22,6 +22,7 @@ package eu.faircode.netguard;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.XmlResourceParser;
|
import android.content.res.XmlResourceParser;
|
||||||
|
@ -49,6 +50,7 @@ public class Rule {
|
||||||
public boolean system;
|
public boolean system;
|
||||||
public boolean internet;
|
public boolean internet;
|
||||||
public boolean enabled;
|
public boolean enabled;
|
||||||
|
public Intent intent;
|
||||||
|
|
||||||
public boolean wifi_default;
|
public boolean wifi_default;
|
||||||
public boolean other_default;
|
public boolean other_default;
|
||||||
|
@ -70,14 +72,19 @@ public class Rule {
|
||||||
|
|
||||||
public boolean changed;
|
public boolean changed;
|
||||||
|
|
||||||
public Intent intent;
|
|
||||||
|
|
||||||
public boolean expanded = false;
|
public boolean expanded = false;
|
||||||
|
|
||||||
private Rule(PackageInfo info, Context context) {
|
private Rule(PackageInfo info, Context context) {
|
||||||
PackageManager pm = context.getPackageManager();
|
PackageManager pm = context.getPackageManager();
|
||||||
|
|
||||||
this.info = info;
|
this.info = info;
|
||||||
|
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.name = info.applicationInfo.loadLabel(pm).toString();
|
||||||
this.system = Util.isSystem(info.packageName, context);
|
this.system = Util.isSystem(info.packageName, context);
|
||||||
this.internet = Util.hasInternet(info.packageName, context);
|
this.internet = Util.hasInternet(info.packageName, context);
|
||||||
|
@ -96,6 +103,7 @@ public class Rule {
|
||||||
|
|
||||||
this.intent = pm.getLaunchIntentForPackage(info.packageName);
|
this.intent = pm.getLaunchIntentForPackage(info.packageName);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static List<Rule> getRules(boolean all, String tag, Context context) {
|
public static List<Rule> getRules(boolean all, String tag, Context context) {
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
|
@ -168,8 +176,18 @@ public class Rule {
|
||||||
// Build rule list
|
// Build rule list
|
||||||
List<Rule> listRules = new ArrayList<>();
|
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);
|
Rule rule = new Rule(info, context);
|
||||||
|
|
||||||
if (pre_system.containsKey(info.packageName))
|
if (pre_system.containsKey(info.packageName))
|
||||||
|
|
|
@ -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);
|
dh.insertLog(packet, dname, (last_connected ? last_metered ? 2 : 1 : 0), last_interactive);
|
||||||
|
|
||||||
// Application log
|
// Application log
|
||||||
if (log_app && packet.uid > 0) {
|
if (log_app && packet.uid >= 0) {
|
||||||
if (dh.updateAccess(packet, dname, -1))
|
if (dh.updateAccess(packet, dname, -1))
|
||||||
if (notify && prefs.getBoolean("notify_" + packet.uid, true) &&
|
if (notify && prefs.getBoolean("notify_" + packet.uid, true) &&
|
||||||
(system || !Util.isSystem(packet.uid, SinkholeService.this)))
|
(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 */
|
if (packet.protocol == 6 /* TCP */ || packet.protocol == 17 /* UDP */
|
||||||
|| packet.protocol == 1 /* ICMPv4 */ || packet.protocol == 58 /* ICMPv6 */) {
|
|| packet.protocol == 1 /* ICMPv4 */ || packet.protocol == 58 /* ICMPv6 */) {
|
||||||
if (prefs.getBoolean("filter", false)) {
|
if (prefs.getBoolean("filter", false)) {
|
||||||
if (packet.uid <= 0) // unknown, root
|
if (packet.uid < 0) // unknown
|
||||||
packet.allowed = true;
|
packet.allowed = true;
|
||||||
else {
|
else {
|
||||||
boolean filtered = false;
|
boolean filtered = false;
|
||||||
|
|
Loading…
Reference in New Issue