Add message for old untracked connections

This commit is contained in:
emanuele-f 2021-03-04 22:02:46 +01:00
parent 0f09214a09
commit fc31bf6e7c
4 changed files with 59 additions and 18 deletions

View File

@ -87,8 +87,8 @@ public class CaptureService extends VpnService implements Runnable {
private NotificationCompat.Builder mNotificationBuilder;
/* The maximum connections to log into the ConnectionsRegister. Older connections are dropped.
* Max Estimated max memory usage: less than 2 MB. */
public static final int CONNECTIONS_LOG_SIZE = 4192;
* Max Estimated max memory usage: less than 4 MB. */
public static final int CONNECTIONS_LOG_SIZE = 8192;
/* The IP address of the virtual network interface */
public static final String VPN_IP_ADDRESS = "10.215.173.1";

View File

@ -76,6 +76,7 @@ public class ConnectionsFragment extends Fragment implements ConnectionsListener
private View mFabDown;
private EmptyRecyclerView mRecyclerView;
private TextView mEmptyText;
private TextView mOldConnectionsText;
private boolean autoScroll;
private boolean listenerSet;
private MenuItem mMenuItemAppSel;
@ -87,6 +88,7 @@ public class ConnectionsFragment extends Fragment implements ConnectionsListener
private boolean mOpenAppsWhenDone;
private BroadcastReceiver mReceiver;
private Uri mCsvFname;
private boolean hasUntrackedConnections;
@Override
public void onDestroy() {
@ -136,6 +138,7 @@ public class ConnectionsFragment extends Fragment implements ConnectionsListener
mHandler = new Handler(Looper.getMainLooper());
mFabDown = view.findViewById(R.id.fabDown);
mRecyclerView = view.findViewById(R.id.connections_view);
mOldConnectionsText = view.findViewById(R.id.old_connections_notice);
LinearLayoutManager layoutMan = new LinearLayoutManager(getContext());
mRecyclerView.setLayoutManager(layoutMan);
@ -179,6 +182,7 @@ public class ConnectionsFragment extends Fragment implements ConnectionsListener
autoScroll = true;
showFabDown(false);
mOldConnectionsText.setVisibility(View.GONE);
mFabDown.setOnClickListener(v -> scrollToBottom());
@ -230,6 +234,8 @@ public class ConnectionsFragment extends Fragment implements ConnectionsListener
autoScroll = true;
showFabDown(false);
mOldConnectionsText.setVisibility(View.GONE);
hasUntrackedConnections = false;
mEmptyText.setText(R.string.no_connections);
}
@ -270,6 +276,11 @@ public class ConnectionsFragment extends Fragment implements ConnectionsListener
}
} else
showFabDown(false);
if((first_visibile_pos == 0) && hasUntrackedConnections)
mOldConnectionsText.setVisibility(View.VISIBLE);
else
mOldConnectionsText.setVisibility(View.GONE);
}
private void showFabDown(boolean visible) {
@ -284,6 +295,7 @@ public class ConnectionsFragment extends Fragment implements ConnectionsListener
mRecyclerView.scrollToPosition(last_pos);
showFabDown(false);
mOldConnectionsText.setVisibility(View.GONE);
}
@Override
@ -344,6 +356,18 @@ public class ConnectionsFragment extends Fragment implements ConnectionsListener
if(autoScroll)
scrollToBottom();
ConnectionsRegister reg = CaptureService.getConnsRegister();
if((reg != null) && (reg.getUntrackedConnCount() > 0)) {
String info = String.format(getString(R.string.older_connections_notice), reg.getUntrackedConnCount());
mOldConnectionsText.setText(info);
if(!hasUntrackedConnections) {
hasUntrackedConnections = true;
recheckScroll();
}
}
});
}

View File

@ -2,14 +2,41 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.emanuelef.remote_capture.views.EmptyRecyclerView
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:scrollbarStyle="outsideOverlay"
android:id="@+id/connections_view" />
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/old_connections_notice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:textSize="15sp"
android:textStyle="italic"
tools:text="74 older connections not shown" />
<TextView
android:id="@+id/no_connections"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:layout_marginTop="40dp"
android:textStyle="italic"
android:textSize="15sp"
android:text="@string/capture_not_started">
</TextView>
<com.emanuelef.remote_capture.views.EmptyRecyclerView
android:id="@+id/connections_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:scrollbarStyle="outsideOverlay" />
</LinearLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fabDown"
@ -20,15 +47,4 @@
android:layout_margin="16dp"
app:maxImageSize="48dp"
android:src="@drawable/ic_arrow_drop_down" />
<TextView
android:id="@+id/no_connections"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:layout_marginTop="40dp"
android:textStyle="italic"
android:textSize="15sp"
android:text="@string/capture_not_started">
</TextView>
</RelativeLayout>

View File

@ -111,5 +111,6 @@
<string name="connections_csv_fields_v1">IPProto,SrcIP,SrcPort,DstIp,DstPort,Uid,App,Proto,Status,Info,BytesSent,BytesRcvd,PktsSent,PktsRcvd,FirstSeen,LastSeen</string>
<string name="save_to_file">Save to file</string>
<string name="file_saved">File successfully saved</string>
<string name="older_connections_notice">%1$d older connections not shown</string>
</resources>