diff --git a/FAQ.md b/FAQ.md index 55782e31..7ed40b9f 100644 --- a/FAQ.md +++ b/FAQ.md @@ -223,22 +223,22 @@ See also [question 0](#FAQ0). The columns have the following meaning: -1. Day of month -1. Time -1. Protocol -1. Port -1. Packet flags -1. Application icon +1. Time (tap on a log entry to see the date) +1. Wi-Fi / mobile connection +1. Interactive state (screen on) +1. Protocol (see below) +1. Port (tap on a log entry to lookup a port) +1. Packet flags (see below) +1. Application icon (tap on a log entry to see the application name) 1. Application uid -1. Wi-Fi / mobile icon -1. IP address +1. IPv4 or IPv6 address (tap on a log entry to lookup an IP address) Protocols: * I = ICMP * T = TCP * U = UDP -* Number = one of the protocols on [this list](https://en.wikipedia.org/wiki/List_of_IP_protocol_numbers) +* Number = one of the protocols in [this list](https://en.wikipedia.org/wiki/List_of_IP_protocol_numbers) Packet flags: diff --git a/app/src/main/java/eu/faircode/netguard/ActivityLog.java b/app/src/main/java/eu/faircode/netguard/ActivityLog.java index a9e11d84..f34bb111 100644 --- a/app/src/main/java/eu/faircode/netguard/ActivityLog.java +++ b/app/src/main/java/eu/faircode/netguard/ActivityLog.java @@ -40,6 +40,8 @@ import android.widget.ListView; import android.widget.PopupMenu; import android.widget.Toast; +import java.text.SimpleDateFormat; + public class ActivityLog extends AppCompatActivity { private ListView lvLog; private LogAdapter adapter; @@ -78,6 +80,7 @@ public class ActivityLog extends AppCompatActivity { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { Cursor cursor = (Cursor) adapter.getItem(position); + long time = cursor.getLong(cursor.getColumnIndex("time")); String ip = cursor.getString(cursor.getColumnIndex("ip")); final int port = (cursor.isNull(cursor.getColumnIndex("port")) ? -1 : cursor.getInt(cursor.getColumnIndex("port"))); final int uid = (cursor.isNull(cursor.getColumnIndex("uid")) ? -1 : cursor.getInt(cursor.getColumnIndex("uid"))); @@ -104,6 +107,7 @@ public class ActivityLog extends AppCompatActivity { popup.getMenu().add(Menu.NONE, 2, 2, getString(R.string.title_log_whois, whois)); if (port > 0 && getPackageManager().resolveActivity(lookupPort, 0) != null) popup.getMenu().add(Menu.NONE, 3, 3, getString(R.string.title_log_port, port)); + popup.getMenu().add(Menu.NONE, 4, 4, SimpleDateFormat.getDateTimeInstance().format(time)).setEnabled(false); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override diff --git a/app/src/main/java/eu/faircode/netguard/DatabaseHelper.java b/app/src/main/java/eu/faircode/netguard/DatabaseHelper.java index 3529d4c6..e708d17f 100644 --- a/app/src/main/java/eu/faircode/netguard/DatabaseHelper.java +++ b/app/src/main/java/eu/faircode/netguard/DatabaseHelper.java @@ -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 = 4; + private static final int DB_VERSION = 5; private static List logChangedListeners = new ArrayList(); @@ -44,6 +44,7 @@ public class DatabaseHelper extends SQLiteOpenHelper { ", flags TEXT" + ", uid INTEGER NULL" + ", connection INTEGER NULL" + + ", interactive INTEGER NULL" + ");"); db.execSQL("CREATE INDEX idx_log_time ON log(time)"); } @@ -69,6 +70,10 @@ public class DatabaseHelper extends SQLiteOpenHelper { db.execSQL("ALTER TABLE log ADD COLUMN connection INTEGER NULL"); oldVersion = 4; } + if (oldVersion < 5) { + db.execSQL("ALTER TABLE log ADD COLUMN interactive INTEGER NULL"); + oldVersion = 5; + } db.setVersion(DB_VERSION); @@ -82,7 +87,9 @@ public class DatabaseHelper extends SQLiteOpenHelper { // Location - public DatabaseHelper insertLog(int version, String ip, int protocol, int port, String flags, int uid, int connection) { + public DatabaseHelper insertLog( + int version, String ip, int protocol, int port, String flags, + int uid, int connection, boolean interactive) { synchronized (mContext.getApplicationContext()) { SQLiteDatabase db = this.getWritableDatabase(); @@ -109,6 +116,7 @@ public class DatabaseHelper extends SQLiteOpenHelper { cv.put("uid", uid); cv.put("connection", connection); + cv.put("interactive", interactive ? 1 : 0); if (db.insert("log", null, cv) == -1) Log.e(TAG, "Insert log failed"); diff --git a/app/src/main/java/eu/faircode/netguard/LogAdapter.java b/app/src/main/java/eu/faircode/netguard/LogAdapter.java index 1bb7fb89..2200a5fb 100644 --- a/app/src/main/java/eu/faircode/netguard/LogAdapter.java +++ b/app/src/main/java/eu/faircode/netguard/LogAdapter.java @@ -25,6 +25,7 @@ public class LogAdapter extends CursorAdapter { private int colFlags; private int colUid; private int colConnection; + private int colInteractive; public LogAdapter(Context context, Cursor cursor) { super(context, cursor, 0); @@ -36,6 +37,7 @@ public class LogAdapter extends CursorAdapter { colFlags = cursor.getColumnIndex("flags"); colUid = cursor.getColumnIndex("uid"); colConnection = cursor.getColumnIndex("connection"); + colInteractive = cursor.getColumnIndex("interactive"); } @Override @@ -53,22 +55,34 @@ 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); + int connection = (cursor.isNull(colConnection) ? -1 : cursor.getInt(colConnection)); + int interactive = (cursor.isNull(colInteractive) ? -1 : cursor.getInt(colInteractive)); final String whois = (ip.length() > 1 && ip.charAt(0) == '/' ? ip.substring(1) : ip); // Get views TextView tvTime = (TextView) view.findViewById(R.id.tvTime); + ImageView ivConnection = (ImageView) view.findViewById(R.id.ivConnection); + ImageView ivInteractive = (ImageView) view.findViewById(R.id.ivInteractive); TextView tvProtocol = (TextView) view.findViewById(R.id.tvProtocol); TextView tvPort = (TextView) view.findViewById(R.id.tvPort); TextView tvFlags = (TextView) view.findViewById(R.id.tvFlags); ImageView ivIcon = (ImageView) view.findViewById(R.id.ivIcon); TextView tvUid = (TextView) view.findViewById(R.id.tvUid); - ImageView ivConnection = (ImageView) view.findViewById(R.id.ivConnection); TextView tvIP = (TextView) view.findViewById(R.id.tvIP); // Set values - tvTime.setText(new SimpleDateFormat("dd HH:mm:ss").format(time)); + tvTime.setText(new SimpleDateFormat("HH:mm:ss").format(time)); + + if (connection <= 0) + ivConnection.setImageDrawable(null); + else + ivConnection.setImageResource(connection == 1 ? R.drawable.wifi_off : R.drawable.other_off); + + if (interactive <= 0) + ivInteractive.setImageDrawable(null); + else + ivInteractive.setImageResource(R.drawable.screen_on); if (protocol == Packet.Protocol.ICMP) tvProtocol.setText("I"); @@ -100,11 +114,6 @@ public class LogAdapter extends CursorAdapter { 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); - tvIP.setText(whois); } } diff --git a/app/src/main/java/eu/faircode/netguard/SinkholeService.java b/app/src/main/java/eu/faircode/netguard/SinkholeService.java index e01cd2b6..5ce3cc32 100644 --- a/app/src/main/java/eu/faircode/netguard/SinkholeService.java +++ b/app/src/main/java/eu/faircode/netguard/SinkholeService.java @@ -735,7 +735,8 @@ public class SinkholeService extends VpnService { pkt.getDestinationPort(), pkt.getFlags(), pkt.getUid(), - connection).close(); + connection, + last_interactive).close(); } } catch (Throwable ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); diff --git a/app/src/main/res/layout/log.xml b/app/src/main/res/layout/log.xml index fd89c042..b857bfa5 100644 --- a/app/src/main/res/layout/log.xml +++ b/app/src/main/res/layout/log.xml @@ -8,12 +8,23 @@ + + + + - -