mirror of
https://github.com/M66B/NetGuard.git
synced 2025-02-24 23:23:08 +00:00
Added connection type to blocked traffic log, added logging
This commit is contained in:
parent
c1c23b0573
commit
2c2922b94f
4 changed files with 40 additions and 5 deletions
|
@ -16,7 +16,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
|||
private static final String TAG = "NetGuard.Database";
|
||||
|
||||
private static final String DB_NAME = "Netguard";
|
||||
private static final int DB_VERSION = 3;
|
||||
private static final int DB_VERSION = 4;
|
||||
|
||||
private static List<LogChangedListener> logChangedListeners = new ArrayList<LogChangedListener>();
|
||||
|
||||
|
@ -43,6 +43,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
|||
", port INTEGER NULL" +
|
||||
", flags TEXT" +
|
||||
", uid INTEGER NULL" +
|
||||
", connection INTEGER NULL" +
|
||||
");");
|
||||
db.execSQL("CREATE INDEX idx_log_time ON log(time)");
|
||||
}
|
||||
|
@ -64,6 +65,10 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
|||
db.execSQL("ALTER TABLE log ADD COLUMN flags TEXT");
|
||||
oldVersion = 3;
|
||||
}
|
||||
if (oldVersion < 4) {
|
||||
db.execSQL("ALTER TABLE log ADD COLUMN connection INTEGER NULL");
|
||||
oldVersion = 4;
|
||||
}
|
||||
|
||||
db.setVersion(DB_VERSION);
|
||||
|
||||
|
@ -77,7 +82,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
|||
|
||||
// Location
|
||||
|
||||
public DatabaseHelper insertLog(int version, String ip, int protocol, int port, String flags, int uid) {
|
||||
public DatabaseHelper insertLog(int version, String ip, int protocol, int port, String flags, int uid, int connection) {
|
||||
synchronized (mContext.getApplicationContext()) {
|
||||
SQLiteDatabase db = this.getWritableDatabase();
|
||||
|
||||
|
@ -103,6 +108,8 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
|||
else
|
||||
cv.put("uid", uid);
|
||||
|
||||
cv.put("connection", connection);
|
||||
|
||||
if (db.insert("log", null, cv) == -1)
|
||||
Log.e(TAG, "Insert log failed");
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ public class LogAdapter extends CursorAdapter {
|
|||
private int colPort;
|
||||
private int colFlags;
|
||||
private int colUid;
|
||||
private int colConnection;
|
||||
|
||||
public LogAdapter(Context context, Cursor cursor) {
|
||||
super(context, cursor, 0);
|
||||
|
@ -34,6 +35,7 @@ public class LogAdapter extends CursorAdapter {
|
|||
colPort = cursor.getColumnIndex("port");
|
||||
colFlags = cursor.getColumnIndex("flags");
|
||||
colUid = cursor.getColumnIndex("uid");
|
||||
colConnection = cursor.getColumnIndex("connection");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -51,6 +53,7 @@ public class LogAdapter extends CursorAdapter {
|
|||
int port = (cursor.isNull(colPort) ? -1 : cursor.getInt(colPort));
|
||||
String flags = cursor.getString(colFlags);
|
||||
final int uid = (cursor.isNull(colUid) ? -1 : cursor.getInt(colUid));
|
||||
int connection = cursor.getInt(colConnection);
|
||||
|
||||
final String whois = (ip.length() > 1 && ip.charAt(0) == '/' ? ip.substring(1) : ip);
|
||||
|
||||
|
@ -62,6 +65,7 @@ public class LogAdapter extends CursorAdapter {
|
|||
TextView tvPort = (TextView) view.findViewById(R.id.tvPort);
|
||||
TextView tvFlags = (TextView) view.findViewById(R.id.tvFlags);
|
||||
TextView tvUid = (TextView) view.findViewById(R.id.tvUid);
|
||||
ImageView ivConnection = (ImageView) view.findViewById(R.id.ivConnection);
|
||||
|
||||
// Application icon
|
||||
ApplicationInfo info = null;
|
||||
|
@ -95,5 +99,10 @@ public class LogAdapter extends CursorAdapter {
|
|||
tvPort.setText(port < 0 ? "" : Integer.toString(port));
|
||||
tvFlags.setText(flags);
|
||||
tvUid.setText(uid < 0 ? "" : uid == 0 ? "root" : Integer.toString(uid % 100000));
|
||||
|
||||
if (connection == 0)
|
||||
ivConnection.setImageDrawable(null);
|
||||
else
|
||||
ivConnection.setImageResource(connection == 1 ? R.drawable.wifi : R.drawable.other);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,6 +56,7 @@ import android.telephony.PhoneStateListener;
|
|||
import android.telephony.ServiceState;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.widget.RemoteViews;
|
||||
|
@ -595,8 +596,10 @@ public class SinkholeService extends VpnService {
|
|||
// Update metered state
|
||||
if (wifi && (!useMetered || !telephony))
|
||||
metered = false;
|
||||
if (wifi && ssidHomes.size() > 0 && !ssidHomes.contains(ssidNetwork))
|
||||
if (wifi && ssidHomes.size() > 0 && !ssidHomes.contains(ssidNetwork)) {
|
||||
metered = true;
|
||||
Log.i(TAG, "Not at home");
|
||||
}
|
||||
if (unmetered_2g && "2G".equals(generation))
|
||||
metered = false;
|
||||
if (unmetered_3g && "3G".equals(generation))
|
||||
|
@ -613,6 +616,8 @@ public class SinkholeService extends VpnService {
|
|||
|
||||
Log.i(TAG, "Starting connected=" + last_connected +
|
||||
" wifi=" + wifi +
|
||||
" home=" + TextUtils.join(",", ssidHomes) +
|
||||
" network=" + ssidNetwork +
|
||||
" metered=" + metered +
|
||||
" telephony=" + telephony +
|
||||
" generation=" + generation +
|
||||
|
@ -703,13 +708,22 @@ public class SinkholeService extends VpnService {
|
|||
"/" + pkt.getDestinationPort() +
|
||||
" " + pkt.getFlags() +
|
||||
" " + pkt.getProtocol());
|
||||
int connection;
|
||||
if (last_connected)
|
||||
if (last_metered)
|
||||
connection = 2;
|
||||
else
|
||||
connection = 1;
|
||||
else
|
||||
connection = 0;
|
||||
new DatabaseHelper(SinkholeService.this).insertLog(
|
||||
pkt.version,
|
||||
pkt.getDestinationAddress().toString(),
|
||||
pkt.getProtocol(),
|
||||
pkt.getDestinationPort(),
|
||||
pkt.getFlags(),
|
||||
pkt.getUid()).close();
|
||||
pkt.getUid(),
|
||||
connection).close();
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
|
||||
|
|
|
@ -52,12 +52,17 @@
|
|||
android:gravity="end"
|
||||
android:textAppearance="@android:style/TextAppearance.Material.Small" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/ivConnection"
|
||||
android:layout_width="16dip"
|
||||
android:layout_height="16dip"
|
||||
android:layout_gravity="center_vertical" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvIP"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_weight="1"
|
||||
android:textAppearance="@android:style/TextAppearance.Material.Small" />
|
||||
</LinearLayout>
|
||||
|
|
Loading…
Reference in a new issue