mirror of https://github.com/M66B/NetGuard.git
parent
be00ef48c0
commit
c4391a7c94
|
@ -77,10 +77,7 @@ public class ActivityLog extends AppCompatActivity implements SharedPreferences.
|
|||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (adapter != null) {
|
||||
adapter.changeCursor(dh.getLog());
|
||||
applyFilter();
|
||||
}
|
||||
updateAdapter();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -124,8 +121,14 @@ public class ActivityLog extends AppCompatActivity implements SharedPreferences.
|
|||
|
||||
lvLog = (ListView) findViewById(R.id.lvLog);
|
||||
|
||||
boolean udp = prefs.getBoolean("proto_udp", true);
|
||||
boolean tcp = prefs.getBoolean("proto_tcp", true);
|
||||
boolean other = prefs.getBoolean("proto_other", true);
|
||||
boolean allowed = prefs.getBoolean("traffic_allowed", true);
|
||||
boolean blocked = prefs.getBoolean("traffic_blocked", true);
|
||||
|
||||
dh = new DatabaseHelper(this);
|
||||
adapter = new LogAdapter(this, dh.getLog(), resolve);
|
||||
adapter = new LogAdapter(this, dh.getLog(udp, tcp, other, allowed, blocked), resolve);
|
||||
adapter.setFilterQueryProvider(new FilterQueryProvider() {
|
||||
public Cursor runQuery(CharSequence constraint) {
|
||||
return dh.searchLog(constraint.toString());
|
||||
|
@ -216,8 +219,7 @@ public class ActivityLog extends AppCompatActivity implements SharedPreferences.
|
|||
super.onResume();
|
||||
if (live) {
|
||||
dh.addLogChangedListener(listener);
|
||||
adapter.changeCursor(dh.getLog());
|
||||
applyFilter();
|
||||
updateAdapter();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -298,14 +300,17 @@ public class ActivityLog extends AppCompatActivity implements SharedPreferences.
|
|||
// https://gist.github.com/granoeste/5574148
|
||||
File pcap_file = new File(getCacheDir(), "netguard.pcap");
|
||||
|
||||
boolean resolve = prefs.getBoolean("resolve", false);
|
||||
boolean filter = prefs.getBoolean("filter", false);
|
||||
boolean pcap_enabled = prefs.getBoolean("pcap", false);
|
||||
boolean export = (getPackageManager().resolveActivity(getIntentPCAPDocument(), 0) != null);
|
||||
|
||||
menu.findItem(R.id.menu_log_resolve).setChecked(resolve);
|
||||
menu.findItem(R.id.menu_pcap_enabled).setChecked(pcap_enabled);
|
||||
menu.findItem(R.id.menu_pcap_enabled).setEnabled(filter);
|
||||
menu.findItem(R.id.menu_protocol_udp).setChecked(prefs.getBoolean("proto_udp", true));
|
||||
menu.findItem(R.id.menu_protocol_tcp).setChecked(prefs.getBoolean("proto_tcp", true));
|
||||
menu.findItem(R.id.menu_protocol_other).setChecked(prefs.getBoolean("proto_other", true));
|
||||
menu.findItem(R.id.menu_traffic_allowed).setChecked(prefs.getBoolean("traffic_allowed", true));
|
||||
menu.findItem(R.id.menu_traffic_blocked).setChecked(prefs.getBoolean("traffic_blocked", true));
|
||||
|
||||
menu.findItem(R.id.menu_log_resolve).setChecked(prefs.getBoolean("resolve", false));
|
||||
menu.findItem(R.id.menu_pcap_enabled).setEnabled(prefs.getBoolean("filter", false));
|
||||
menu.findItem(R.id.menu_pcap_enabled).setChecked(prefs.getBoolean("pcap", false));
|
||||
menu.findItem(R.id.menu_pcap_export).setEnabled(pcap_file.exists() && export);
|
||||
|
||||
return super.onPrepareOptionsMenu(menu);
|
||||
|
@ -322,13 +327,42 @@ public class ActivityLog extends AppCompatActivity implements SharedPreferences.
|
|||
NavUtils.navigateUpFromSameTask(this);
|
||||
return true;
|
||||
|
||||
case R.id.menu_protocol_udp:
|
||||
item.setChecked(!item.isChecked());
|
||||
prefs.edit().putBoolean("proto_udp", item.isChecked()).apply();
|
||||
updateAdapter();
|
||||
return true;
|
||||
|
||||
case R.id.menu_protocol_tcp:
|
||||
item.setChecked(!item.isChecked());
|
||||
prefs.edit().putBoolean("proto_tcp", item.isChecked()).apply();
|
||||
updateAdapter();
|
||||
return true;
|
||||
|
||||
case R.id.menu_protocol_other:
|
||||
item.setChecked(!item.isChecked());
|
||||
prefs.edit().putBoolean("proto_other", item.isChecked()).apply();
|
||||
updateAdapter();
|
||||
return true;
|
||||
|
||||
case R.id.menu_traffic_allowed:
|
||||
item.setChecked(!item.isChecked());
|
||||
prefs.edit().putBoolean("traffic_allowed", item.isChecked()).apply();
|
||||
updateAdapter();
|
||||
return true;
|
||||
|
||||
case R.id.menu_traffic_blocked:
|
||||
item.setChecked(!item.isChecked());
|
||||
prefs.edit().putBoolean("traffic_blocked", item.isChecked()).apply();
|
||||
updateAdapter();
|
||||
return true;
|
||||
|
||||
case R.id.menu_log_live:
|
||||
item.setChecked(!item.isChecked());
|
||||
live = item.isChecked();
|
||||
if (live) {
|
||||
dh.addLogChangedListener(listener);
|
||||
adapter.changeCursor(dh.getLog());
|
||||
applyFilter();
|
||||
updateAdapter();
|
||||
} else
|
||||
dh.removeLogChangedListener(listener);
|
||||
return true;
|
||||
|
@ -368,9 +402,8 @@ public class ActivityLog extends AppCompatActivity implements SharedPreferences.
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Object o) {
|
||||
adapter.changeCursor(dh.getLog());
|
||||
applyFilter();
|
||||
protected void onPostExecute(Object result) {
|
||||
updateAdapter();
|
||||
}
|
||||
}.execute();
|
||||
return true;
|
||||
|
@ -387,10 +420,19 @@ public class ActivityLog extends AppCompatActivity implements SharedPreferences.
|
|||
}
|
||||
}
|
||||
|
||||
private void applyFilter() {
|
||||
if (adapter != null && menuSearch != null && menuSearch.isActionViewExpanded()) {
|
||||
SearchView searchView = (SearchView) MenuItemCompat.getActionView(menuSearch);
|
||||
adapter.getFilter().filter(searchView.getQuery().toString());
|
||||
private void updateAdapter() {
|
||||
if (adapter != null) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
boolean udp = prefs.getBoolean("proto_udp", true);
|
||||
boolean tcp = prefs.getBoolean("proto_tcp", true);
|
||||
boolean other = prefs.getBoolean("proto_other", true);
|
||||
boolean allowed = prefs.getBoolean("traffic_allowed", true);
|
||||
boolean blocked = prefs.getBoolean("traffic_blocked", true);
|
||||
adapter.changeCursor(dh.getLog(udp, tcp, other, allowed, blocked));
|
||||
if (menuSearch != null && menuSearch.isActionViewExpanded()) {
|
||||
SearchView searchView = (SearchView) MenuItemCompat.getActionView(menuSearch);
|
||||
adapter.getFilter().filter(searchView.getQuery().toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,10 +21,12 @@ package eu.faircode.netguard;
|
|||
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteDoneException;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -43,11 +45,11 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
|||
private static List<LogChangedListener> logChangedListeners = new ArrayList<>();
|
||||
private static List<AccessChangedListener> accessChangedListeners = new ArrayList<>();
|
||||
|
||||
private Context mContext;
|
||||
private Context context;
|
||||
|
||||
public DatabaseHelper(Context context) {
|
||||
super(context, DB_NAME, null, DB_VERSION);
|
||||
mContext = context;
|
||||
this.context = context;
|
||||
|
||||
if (!once) {
|
||||
once = true;
|
||||
|
@ -219,7 +221,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
|||
// Log
|
||||
|
||||
public DatabaseHelper insertLog(Packet packet, String dname, int connection, boolean interactive) {
|
||||
synchronized (mContext.getApplicationContext()) {
|
||||
synchronized (context.getApplicationContext()) {
|
||||
SQLiteDatabase db = this.getWritableDatabase();
|
||||
|
||||
ContentValues cv = new ContentValues();
|
||||
|
@ -277,7 +279,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
|||
}
|
||||
|
||||
public DatabaseHelper clearLog() {
|
||||
synchronized (mContext.getApplicationContext()) {
|
||||
synchronized (context.getApplicationContext()) {
|
||||
SQLiteDatabase db = this.getReadableDatabase();
|
||||
db.delete("log", null, new String[]{});
|
||||
db.execSQL("VACUUM");
|
||||
|
@ -293,10 +295,24 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Cursor getLog() {
|
||||
public Cursor getLog(boolean udp, boolean tcp, boolean other, boolean allowed, boolean blocked) {
|
||||
// There is no index on protocol/allowed for write performance
|
||||
SQLiteDatabase db = this.getReadableDatabase();
|
||||
String query = "SELECT ID AS _id, *";
|
||||
query += " FROM log";
|
||||
query += " WHERE (0 = 1";
|
||||
if (udp)
|
||||
query += " OR protocol = 17";
|
||||
if (tcp)
|
||||
query += " OR protocol = 6";
|
||||
if (other)
|
||||
query += " OR (protocol <> 6 AND protocol <> 17)";
|
||||
query += ") AND (0 = 1";
|
||||
if (allowed)
|
||||
query += " OR allowed = 1";
|
||||
if (blocked)
|
||||
query += " OR allowed = 0";
|
||||
query += ")";
|
||||
query += " ORDER BY time DESC";
|
||||
return db.rawQuery(query, new String[]{});
|
||||
}
|
||||
|
@ -314,7 +330,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
|||
|
||||
public boolean updateAccess(Packet packet, String dname, int block) {
|
||||
int rows;
|
||||
synchronized (mContext.getApplicationContext()) {
|
||||
synchronized (context.getApplicationContext()) {
|
||||
SQLiteDatabase db = this.getWritableDatabase();
|
||||
|
||||
ContentValues cv = new ContentValues();
|
||||
|
@ -353,7 +369,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
|||
}
|
||||
|
||||
public DatabaseHelper setAccess(long id, int uid, int block) {
|
||||
synchronized (mContext.getApplicationContext()) {
|
||||
synchronized (context.getApplicationContext()) {
|
||||
SQLiteDatabase db = this.getWritableDatabase();
|
||||
|
||||
ContentValues cv = new ContentValues();
|
||||
|
@ -375,7 +391,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
|||
}
|
||||
|
||||
public DatabaseHelper clearAccess(int uid) {
|
||||
synchronized (mContext.getApplicationContext()) {
|
||||
synchronized (context.getApplicationContext()) {
|
||||
SQLiteDatabase db = this.getReadableDatabase();
|
||||
db.delete("access", "uid = ? AND block < 0", new String[]{Integer.toString(uid)});
|
||||
}
|
||||
|
@ -417,7 +433,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
|||
}
|
||||
|
||||
public DatabaseHelper insertDns(ResourceRecord rr) {
|
||||
synchronized (mContext.getApplicationContext()) {
|
||||
synchronized (context.getApplicationContext()) {
|
||||
SQLiteDatabase db = this.getWritableDatabase();
|
||||
|
||||
ContentValues cv = new ContentValues();
|
||||
|
@ -446,8 +462,8 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
|||
}
|
||||
|
||||
public DatabaseHelper cleanupDns(long time) {
|
||||
// There is no index on time, because an index will delay writing
|
||||
synchronized (mContext.getApplicationContext()) {
|
||||
// There is no index on time for write performance
|
||||
synchronized (context.getApplicationContext()) {
|
||||
SQLiteDatabase db = this.getWritableDatabase();
|
||||
int rows = db.delete("dns", "time < ?", new String[]{Long.toString(time)});
|
||||
Log.i(TAG, "Cleanup DNS" +
|
||||
|
|
|
@ -7,6 +7,36 @@
|
|||
android:title="@string/menu_search"
|
||||
netguard:actionViewClass="android.support.v7.widget.SearchView"
|
||||
netguard:showAsAction="always|collapseActionView" />
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_filter"
|
||||
android:icon="@drawable/ic_filter_list_white_24dp"
|
||||
android:title="@string/menu_filter"
|
||||
netguard:showAsAction="always|collapseActionView">
|
||||
<menu>
|
||||
<item
|
||||
android:id="@+id/menu_protocol_udp"
|
||||
android:checkable="true"
|
||||
android:title="@string/menu_protocol_udp" />
|
||||
<item
|
||||
android:id="@+id/menu_protocol_tcp"
|
||||
android:checkable="true"
|
||||
android:title="@string/menu_protocol_tcp" />
|
||||
<item
|
||||
android:id="@+id/menu_protocol_other"
|
||||
android:checkable="true"
|
||||
android:title="@string/menu_protocol_other" />
|
||||
<item
|
||||
android:id="@+id/menu_traffic_allowed"
|
||||
android:checkable="true"
|
||||
android:title="@string/menu_traffic_allowed" />
|
||||
<item
|
||||
android:id="@+id/menu_traffic_blocked"
|
||||
android:checkable="true"
|
||||
android:title="@string/menu_traffic_blocked" />
|
||||
</menu>
|
||||
</item>
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_log_live"
|
||||
android:checkable="true"
|
||||
|
|
|
@ -22,6 +22,11 @@ however it is impossible to guarantee NetGuard will work correctly on every devi
|
|||
<string name="menu_support">Support</string>
|
||||
<string name="menu_about">About</string>
|
||||
|
||||
<string name="menu_protocol_udp" translatable="false">UDP</string>
|
||||
<string name="menu_protocol_tcp" translatable="false">TCP</string>
|
||||
<string name="menu_protocol_other">Other</string>
|
||||
<string name="menu_traffic_allowed">Allowed</string>
|
||||
<string name="menu_traffic_blocked">Blocked</string>
|
||||
<string name="menu_live">Live updates</string>
|
||||
<string name="menu_resolve">Show names</string>
|
||||
<string name="menu_pcap_enabled">PCAP enabled</string>
|
||||
|
|
|
@ -201,7 +201,7 @@
|
|||
android:entries="@array/logLevelNames"
|
||||
android:entryValues="@array/logLevelValues"
|
||||
android:key="loglevel"
|
||||
android:summary="Log level debug or verbose will impact performance and battery usage"
|
||||
android:summary="Log level verbose, debug and info will impact performance and battery usage"
|
||||
android:title="Native log level" />
|
||||
</PreferenceCategory>
|
||||
|
||||
|
|
|
@ -202,7 +202,7 @@
|
|||
android:entries="@array/logLevelNames"
|
||||
android:entryValues="@array/logLevelValues"
|
||||
android:key="loglevel"
|
||||
android:summary="Log level debug or verbose will impact performance and battery usage"
|
||||
android:summary="Log level verbose, debug and info will impact performance and battery usage"
|
||||
android:title="Native log level" />
|
||||
</PreferenceCategory>
|
||||
|
||||
|
|
Loading…
Reference in New Issue