Added option to enable application access logging

This commit is contained in:
M66B 2016-02-01 08:25:08 +01:00
parent ccc0471418
commit 64b00b73b8
6 changed files with 46 additions and 17 deletions

View File

@ -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);

View File

@ -114,6 +114,7 @@ public class RuleAdapter extends RecyclerView.Adapter<RuleAdapter.ViewHolder> 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<RuleAdapter.ViewHolder> 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<RuleAdapter.ViewHolder> 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) {

View File

@ -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();

View File

@ -306,6 +306,15 @@
android:layout_height="wrap_content"
android:layout_marginTop="4dp" />
<TextView
android:id="@+id/tvNolog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:text="@string/title_no_log"
android:textAppearance="@style/TextSmall"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"

View File

@ -38,7 +38,6 @@ however it is impossible to guarantee NetGuard will work correctly on every devi
<string name="setting_options">Options</string>
<string name="setting_theme">Theme: %1$s</string>
<string name="setting_dark">Use dark theme</string>
<string name="setting_access">Notify on internet access</string>
<string name="setting_auto">Auto enable after %1$s minutes</string>
<string name="setting_delay">Delay screen off %1$s minutes</string>
@ -53,6 +52,8 @@ however it is impossible to guarantee NetGuard will work correctly on every devi
<string name="setting_advanced_options">Advanced options</string>
<string name="setting_system">Manage system applications</string>
<string name="setting_log_app">Log internet access</string>
<string name="setting_access">Notify on internet access</string>
<string name="setting_filter">Filter traffic</string>
<string name="setting_block_domains">Block domain names</string>
<string name="setting_vpn4">VPN IPv4: %s</string>
@ -76,7 +77,6 @@ however it is impossible to guarantee NetGuard will work correctly on every devi
<string name="setting_technical_networks">Networks</string>
<string name="setting_technical_subscription">Subscriptions</string>
<string name="summary_access">Show a status bar notification when an application attempts to access a new internet address</string>
<string name="summary_auto">After disabling using the widget, automatically enable NetGuard again after the selected number of minutes (enter zero to disable this option)</string>
<string name="summary_delay">After turning the screen off, keep screen on rules active for the selected number of minutes (enter zero to disable this option)</string>
@ -88,6 +88,8 @@ however it is impossible to guarantee NetGuard will work correctly on every devi
<string name="summary_national_roaming">Do not apply roaming rules when the SIM and mobile network country are the same</string>
<string name="summary_system">Define rules for system applications (for experts)</string>
<string name="summary_log_app">Log attempts to access the internet for applications. This might result in extra battery usage.</string>
<string name="summary_access">Show a status bar notification when an application attempts to access a new internet address</string>
<string name="summary_filter">Filter IP packets going out of the VPN sinkhole. This might result in extra battery usage.</string>
<string name="summary_block_domains">Redirect blocked domain names to local device. This switch is disabled when no hosts file has been imported.</string>
@ -125,6 +127,7 @@ Since NetGuard has no internet permission, you know your internet traffic is not
<string name="title_internet">has no internet permission</string>
<string name="title_launch">Start application</string>
<string name="title_access">Access attempts</string>
<string name="title_no_log"><u>Logging is not enabled</u></string>
<string name="title_precedence">Access rules take precedence over other rules</string>
<string name="title_rate">Rate</string>
<string name="title_allow">Allow</string>

View File

@ -37,11 +37,6 @@
android:defaultValue="false"
android:key="dark_theme"
android:title="@string/setting_dark" />
<SwitchPreference
android:defaultValue="false"
android:key="notify_access"
android:summary="@string/summary_access"
android:title="@string/setting_access" />
<EditTextPreference
android:defaultValue="0"
android:inputType="number"
@ -100,6 +95,17 @@
android:key="manage_system"
android:summary="@string/summary_system"
android:title="@string/setting_system" />
<SwitchPreference
android:defaultValue="false"
android:key="log_app"
android:summary="@string/summary_log_app"
android:title="@string/setting_log_app" />
<SwitchPreference
android:defaultValue="false"
android:dependency="log_app"
android:key="notify_access"
android:summary="@string/summary_access"
android:title="@string/setting_access" />
<SwitchPreference
android:defaultValue="false"
android:key="filter"