mirror of https://github.com/M66B/NetGuard.git
Added interactive state to traffic blocked log
This commit is contained in:
parent
8d5dadff73
commit
26814b2b51
18
FAQ.md
18
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:
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<LogChangedListener> logChangedListeners = new ArrayList<LogChangedListener>();
|
||||
|
||||
|
@ -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");
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -8,12 +8,23 @@
|
|||
|
||||
<TextView
|
||||
android:id="@+id/tvTime"
|
||||
android:layout_width="80dp"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginStart="4dp"
|
||||
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" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/ivInteractive"
|
||||
android:layout_width="16dip"
|
||||
android:layout_height="16dip"
|
||||
android:layout_gravity="center_vertical" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvProtocol"
|
||||
android:layout_width="16dp"
|
||||
|
@ -52,17 +63,12 @@
|
|||
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="4dp"
|
||||
android:layout_weight="1"
|
||||
android:textAppearance="@android:style/TextAppearance.Material.Small" />
|
||||
</LinearLayout>
|
||||
|
|
Loading…
Reference in New Issue