From 64b00b73b86d23aa39dac087e398ad941898e6c8 Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 1 Feb 2016 08:25:08 +0100 Subject: [PATCH] Added option to enable application access logging --- .../eu/faircode/netguard/ActivitySettings.java | 12 ++++-------- .../java/eu/faircode/netguard/RuleAdapter.java | 12 ++++++++++++ .../eu/faircode/netguard/SinkholeService.java | 7 +++++-- app/src/main/res/layout/rule.xml | 9 +++++++++ app/src/main/res/values/strings.xml | 7 +++++-- app/src/main/res/xml/preferences.xml | 16 +++++++++++----- 6 files changed, 46 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/eu/faircode/netguard/ActivitySettings.java b/app/src/main/java/eu/faircode/netguard/ActivitySettings.java index 0e21b409..80c6d792 100644 --- a/app/src/main/java/eu/faircode/netguard/ActivitySettings.java +++ b/app/src/main/java/eu/faircode/netguard/ActivitySettings.java @@ -46,6 +46,7 @@ import android.preference.PreferenceManager; import android.preference.PreferenceScreen; import android.preference.SwitchPreference; import android.support.annotation.NonNull; +import android.support.v4.content.LocalBroadcastManager; import android.support.v7.app.AppCompatActivity; import android.telephony.PhoneStateListener; import android.telephony.ServiceState; @@ -428,14 +429,9 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere prefs.edit().putBoolean("show_system", manage).apply(); SinkholeService.reload(null, "changed " + name, this); - - } else if ("log".equals(name)) { - if (prefs.getBoolean(name, false) && !IAB.isPurchased(ActivityPro.SKU_LOG, this)) { - prefs.edit().putBoolean(name, false).apply(); - ((SwitchPreference) getPreferenceScreen().findPreference(name)).setChecked(false); - startActivity(new Intent(this, ActivityPro.class)); - } else - SinkholeService.reload(null, "changed " + name, this); + } else if ("log_app".equals(name)) { + Intent ruleset = new Intent(ActivityMain.ACTION_RULES_CHANGED); + LocalBroadcastManager.getInstance(this).sendBroadcast(ruleset); } else if ("filter".equals(name)) { SinkholeService.reload(null, "changed " + name, this); diff --git a/app/src/main/java/eu/faircode/netguard/RuleAdapter.java b/app/src/main/java/eu/faircode/netguard/RuleAdapter.java index 78b72204..e6cfed1e 100644 --- a/app/src/main/java/eu/faircode/netguard/RuleAdapter.java +++ b/app/src/main/java/eu/faircode/netguard/RuleAdapter.java @@ -114,6 +114,7 @@ public class RuleAdapter extends RecyclerView.Adapter im public Button btnLaunch; public ListView lvAccess; + public TextView tvNolog; public ImageButton btnClearAccess; public TextView tvStatistics; @@ -154,6 +155,7 @@ public class RuleAdapter extends RecyclerView.Adapter im btnLaunch = (Button) itemView.findViewById(R.id.btnLaunch); lvAccess = (ListView) itemView.findViewById(R.id.lvAccess); + tvNolog = (TextView) itemView.findViewById(R.id.tvNolog); btnClearAccess = (ImageButton) itemView.findViewById(R.id.btnClearAccess); tvStatistics = (TextView) itemView.findViewById(R.id.tvStatistics); @@ -530,6 +532,16 @@ public class RuleAdapter extends RecyclerView.Adapter im holder.lvAccess.setOnItemClickListener(null); } + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + boolean log_app = prefs.getBoolean("log_app", false); + holder.tvNolog.setVisibility(log_app ? View.GONE : View.VISIBLE); + holder.tvNolog.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + context.startActivity(new Intent(context, ActivitySettings.class)); + } + }); + holder.btnClearAccess.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { diff --git a/app/src/main/java/eu/faircode/netguard/SinkholeService.java b/app/src/main/java/eu/faircode/netguard/SinkholeService.java index 703643e0..575d1e13 100644 --- a/app/src/main/java/eu/faircode/netguard/SinkholeService.java +++ b/app/src/main/java/eu/faircode/netguard/SinkholeService.java @@ -655,6 +655,7 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS // Get settings SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(SinkholeService.this); boolean log = prefs.getBoolean("log", false); + boolean log_app = prefs.getBoolean("log_app", false); boolean filter = prefs.getBoolean("filter", false); boolean notify = prefs.getBoolean("notify_access", false); boolean system = prefs.getBoolean("manage_system", false); @@ -681,7 +682,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 (packet.uid > 0) { + if (log_app && packet.uid > 0) { if (dname == null) try { dname = InetAddress.getByName(packet.daddr).getHostName(); @@ -693,7 +694,9 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS if (notify && (system || !Util.isSystem(packet.uid, SinkholeService.this))) showAccessNotification(packet.uid); - } else if (packet.dport != 53) + } + + if (packet.uid < 0 && packet.dport != 53) Log.w(TAG, "Unknown application packet=" + packet); dh.close(); diff --git a/app/src/main/res/layout/rule.xml b/app/src/main/res/layout/rule.xml index 69192dbc..8cf278ed 100644 --- a/app/src/main/res/layout/rule.xml +++ b/app/src/main/res/layout/rule.xml @@ -306,6 +306,15 @@ android:layout_height="wrap_content" android:layout_marginTop="4dp" /> + + Options Theme: %1$s Use dark theme - Notify on internet access Auto enable after %1$s minutes Delay screen off %1$s minutes @@ -53,6 +52,8 @@ however it is impossible to guarantee NetGuard will work correctly on every devi Advanced options Manage system applications + Log internet access + Notify on internet access Filter traffic Block domain names VPN IPv4: %s @@ -76,7 +77,6 @@ however it is impossible to guarantee NetGuard will work correctly on every devi Networks Subscriptions - Show a status bar notification when an application attempts to access a new internet address After disabling using the widget, automatically enable NetGuard again after the selected number of minutes (enter zero to disable this option) After turning the screen off, keep screen on rules active for the selected number of minutes (enter zero to disable this option) @@ -88,6 +88,8 @@ however it is impossible to guarantee NetGuard will work correctly on every devi Do not apply roaming rules when the SIM and mobile network country are the same Define rules for system applications (for experts) + Log attempts to access the internet for applications. This might result in extra battery usage. + Show a status bar notification when an application attempts to access a new internet address Filter IP packets going out of the VPN sinkhole. This might result in extra battery usage. Redirect blocked domain names to local device. This switch is disabled when no hosts file has been imported. @@ -125,6 +127,7 @@ Since NetGuard has no internet permission, you know your internet traffic is not has no internet permission Start application Access attempts + Logging is not enabled Access rules take precedence over other rules Rate Allow diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 4f85911c..3bfa3438 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -37,11 +37,6 @@ android:defaultValue="false" android:key="dark_theme" android:title="@string/setting_dark" /> - + +