mirror of
https://github.com/emanuele-f/PCAPdroid.git
synced 2026-06-16 21:10:57 +08:00
Show active connections indicator and improve layout
This commit is contained in:
parent
90dc3cf4f9
commit
dd1011809a
@ -42,6 +42,7 @@ class ConnDescriptor implements Serializable {
|
||||
String l7proto;
|
||||
int uid;
|
||||
int incr_id;
|
||||
boolean closed;
|
||||
|
||||
/* Invoked by native code
|
||||
* NOTE: interleaving String and int in the parameters is not good as it makes the app crash
|
||||
@ -49,7 +50,7 @@ class ConnDescriptor implements Serializable {
|
||||
public void setData(String _src_ip, String _dst_ip, String _info, String _url, String _l7proto,
|
||||
int _ipproto, int _src_port, int _dst_port, long _first_seen, long _last_seen,
|
||||
long _sent_bytes, long _rcvd_bytes, int _sent_pkts, int _rcvd_pkts, int _uid,
|
||||
int _incr_id) {
|
||||
int _incr_id, boolean _closed) {
|
||||
/* Metadata */
|
||||
ipproto = _ipproto;
|
||||
src_ip = _src_ip;
|
||||
@ -69,5 +70,6 @@ class ConnDescriptor implements Serializable {
|
||||
l7proto = _l7proto;
|
||||
uid = _uid;
|
||||
incr_id = _incr_id;
|
||||
closed = _closed;
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,6 +35,7 @@ import java.util.Objects;
|
||||
|
||||
class ViewHolder extends RecyclerView.ViewHolder {
|
||||
ImageView icon;
|
||||
ImageView statusInd;
|
||||
TextView remote;
|
||||
TextView l7proto;
|
||||
TextView traffic;
|
||||
@ -46,6 +47,7 @@ class ViewHolder extends RecyclerView.ViewHolder {
|
||||
remote = itemView.findViewById(R.id.remote);
|
||||
l7proto = itemView.findViewById(R.id.l7proto);
|
||||
traffic = itemView.findViewById(R.id.traffic);
|
||||
statusInd = itemView.findViewById(R.id.status_ind);
|
||||
}
|
||||
|
||||
public void bindConn(MainActivity activity, ConnDescriptor conn, Drawable unknownIcon) {
|
||||
@ -63,6 +65,9 @@ class ViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
l7proto.setText(conn.l7proto);
|
||||
traffic.setText(Utils.formatBytes(conn.sent_bytes + conn.rcvd_bytes));
|
||||
|
||||
if(conn.closed)
|
||||
statusInd.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -31,6 +31,7 @@ import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
@ -80,6 +81,10 @@ public class ConnectionsFragment extends Fragment implements AppStateListener, C
|
||||
mAdapter = new ConnectionsAdapter(mActivity);
|
||||
mRecyclerView.setAdapter(mAdapter);
|
||||
|
||||
/*DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mRecyclerView.getContext(),
|
||||
layoutMan.getOrientation());
|
||||
mRecyclerView.addItemDecoration(dividerItemDecoration);*/
|
||||
|
||||
mAdapter.setClickListener(v -> {
|
||||
int pos = mRecyclerView.getChildLayoutPosition(v);
|
||||
ConnDescriptor item = mAdapter.getItem(pos);
|
||||
|
||||
@ -169,7 +169,7 @@ static void conns_clear(conn_array_t *arr, bool free_all) {
|
||||
for(int i=0; i < arr->cur_items; i++) {
|
||||
vpn_conn_t *slot = &arr->items[i];
|
||||
|
||||
if(slot->data && (slot->data->terminated || free_all))
|
||||
if(slot->data && (slot->data->closed || free_all))
|
||||
free_connection_data(slot->data);
|
||||
}
|
||||
|
||||
@ -283,7 +283,21 @@ struct ndpi_detection_module_struct* init_ndpi() {
|
||||
|
||||
/* ******************************************************* */
|
||||
|
||||
const char *getL7ProtoName(struct ndpi_detection_module_struct *mod, ndpi_protocol l7proto) {
|
||||
const char *getProtoName(struct ndpi_detection_module_struct *mod, ndpi_protocol l7proto, int ipproto) {
|
||||
if(l7proto.master_protocol == NDPI_PROTOCOL_UNKNOWN) {
|
||||
// Return the L3 protocol
|
||||
switch (ipproto) {
|
||||
case IPPROTO_TCP:
|
||||
return "TCP";
|
||||
case IPPROTO_UDP:
|
||||
return "UDP";
|
||||
case IPPROTO_ICMP:
|
||||
return "ICMP";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
return ndpi_get_proto_name(mod, l7proto.master_protocol);
|
||||
}
|
||||
|
||||
@ -558,7 +572,7 @@ static void destroy_connection(zdtun_t *tun, const zdtun_conn_t *conn_info) {
|
||||
|
||||
/* Will free the other data in sendConnectionsDump */
|
||||
free_ndpi(data);
|
||||
data->terminated = true;
|
||||
data->closed = true;
|
||||
}
|
||||
|
||||
/* ******************************************************* */
|
||||
@ -707,7 +721,7 @@ static int dumpConnection(vpnproxy_data_t *proxy, const vpn_conn_t *conn, jobjec
|
||||
|
||||
jobject info_string = (*env)->NewStringUTF(env, data->info ? data->info : "");
|
||||
jobject url_string = (*env)->NewStringUTF(env, data->url ? data->url : "");
|
||||
jobject proto_string = (*env)->NewStringUTF(env, getL7ProtoName(proxy->ndpi, data->l7proto));
|
||||
jobject proto_string = (*env)->NewStringUTF(env, getProtoName(proxy->ndpi, data->l7proto, conn_info->ipproto));
|
||||
jobject src_string = (*env)->NewStringUTF(env, srcip);
|
||||
jobject dst_string = (*env)->NewStringUTF(env, dstip);
|
||||
jobject conn_descriptor = (*env)->NewObject(env, cls.conn, mids.connInit);
|
||||
@ -720,8 +734,8 @@ static int dumpConnection(vpnproxy_data_t *proxy, const vpn_conn_t *conn, jobjec
|
||||
conn_info->ipproto, ntohs(conn_info->src_port),
|
||||
ntohs(conn_info->dst_port),
|
||||
data->first_seen, data->last_seen, data->sent_bytes,
|
||||
data->rcvd_bytes,
|
||||
data->sent_pkts, data->rcvd_pkts, data->uid, data->incr_id);
|
||||
data->rcvd_bytes, data->sent_pkts,
|
||||
data->rcvd_pkts, data->uid, data->incr_id, data->closed);
|
||||
if(jniCheckException(env))
|
||||
rv = -1;
|
||||
else {
|
||||
@ -894,7 +908,7 @@ static int run_tun(JNIEnv *env, jclass vpn, int tapfd, jint sdk) {
|
||||
mids.connInit = jniGetMethodID(env, cls.conn, "<init>", "()V");
|
||||
mids.connSetData = jniGetMethodID(env, cls.conn, "setData",
|
||||
/* NOTE: must match ConnDescriptor::setData */
|
||||
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IIIJJJJIIII)V");
|
||||
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IIIJJJJIIIIZ)V");
|
||||
mids.statsInit = jniGetMethodID(env, cls.stats, "<init>", "()V");
|
||||
mids.statsSetData = jniGetMethodID(env, cls.stats, "setData", "(IIIIII)V");
|
||||
|
||||
|
||||
@ -52,7 +52,7 @@ typedef struct conn_data {
|
||||
char *info;
|
||||
char *url;
|
||||
jint uid;
|
||||
bool terminated;
|
||||
bool closed;
|
||||
bool pending_notification;
|
||||
bool mitm_header_needed;
|
||||
} conn_data_t;
|
||||
|
||||
5
app/src/main/res/drawable/ic_active_connection.xml
Normal file
5
app/src/main/res/drawable/ic_active_connection.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<vector android:autoMirrored="true" android:height="24dp"
|
||||
android:tint="#919191" android:viewportHeight="24"
|
||||
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M9.01,14H2v2h7.01v3L13,15l-3.99,-4V14zM14.99,13v-3H22V8h-7.01V5L11,9L14.99,13z"/>
|
||||
</vector>
|
||||
@ -2,37 +2,59 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:paddingHorizontal="5dp"
|
||||
android:layout_height="40dp">
|
||||
android:orientation="horizontal"
|
||||
android:paddingHorizontal="4dp"
|
||||
android:layout_height="42dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/icon"
|
||||
android:layout_width="40dp"
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_margin="4dp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_width="2sp"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_weight="0.2"
|
||||
android:text="HTTP"
|
||||
android:layout_marginStart="2dp"
|
||||
android:text="Unknown"
|
||||
android:textSize="10sp"
|
||||
android:maxLines="2"
|
||||
android:gravity="center_vertical"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:id="@+id/l7proto"/>
|
||||
|
||||
<ImageView
|
||||
android:gravity="center"
|
||||
android:id="@+id/status_ind"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginEnd="2dp"
|
||||
android:src="@drawable/ic_active_connection" />
|
||||
|
||||
<Space
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="0.05" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_weight="0.5"
|
||||
android:layout_weight="0.75"
|
||||
android:layout_marginEnd="4dp"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:text="example.org:80"
|
||||
android:textSize="12sp"
|
||||
android:gravity="center_vertical"
|
||||
android:id="@+id/remote"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_width="8sp"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_weight="0.3"
|
||||
android:layout_weight="0.2"
|
||||
android:text="1.05 MB"
|
||||
android:textSize="12sp"
|
||||
android:gravity="center_vertical|end"
|
||||
android:id="@+id/traffic"/>
|
||||
</LinearLayout>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user