Fix glitch on capture start via intent-based API

When a user allows an app permanent capture control, starting the capture
caused the control permission dialog to be shown briefly, causing a glitch.
This is caused by the SOCKS5 host resolution logic introduced in 6d7708e.
To fix this, SOCKS5 host resolution is now disabled in the intent-based API
This commit is contained in:
emanuele-f
2023-12-02 16:10:41 +01:00
parent 3c6bc51ec1
commit 6ca1073806
4 changed files with 11 additions and 4 deletions
@@ -43,11 +43,13 @@ public class CaptureHelper {
private static final String TAG = "CaptureHelper";
private final ComponentActivity mActivity;
private final ActivityResultLauncher<Intent> mLauncher;
private final boolean mResolveHosts;
private CaptureSettings mSettings;
private CaptureStartListener mListener;
public CaptureHelper(ComponentActivity activity) {
public CaptureHelper(ComponentActivity activity, boolean resolve_hosts) {
mActivity = activity;
mResolveHosts = resolve_hosts;
mLauncher = activity.registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(), this::captureServiceResult);
}
@@ -97,6 +99,11 @@ public class CaptureHelper {
}
private void resolveHosts() {
if (!mResolveHosts) {
startCaptureOk();
return;
}
final Handler handler = new Handler(Looper.getMainLooper());
(new Thread(() -> {
@@ -98,7 +98,7 @@ public class CaptureCtrl extends AppCompatActivity {
getWindow().addFlags(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
super.onCreate(savedInstanceState);
mCapHelper = new CaptureHelper(this);
mCapHelper = new CaptureHelper(this, false);
mCapHelper.setListener(success -> {
setResult(success ? RESULT_OK : RESULT_CANCELED, null);
finish();
@@ -161,7 +161,7 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
initAppState();
checkPermissions();
mCapHelper = new CaptureHelper(this);
mCapHelper = new CaptureHelper(this, true);
mCapHelper.setListener(success -> {
if(!success) {
Log.w(TAG, "Capture start failed");
+1 -1
View File
@@ -85,7 +85,7 @@ As shown above, the capture settings can be specified by using intent extras. Th
| http_server_port | int | | | the HTTP server port in http_server mode |
| pcap_uri | string | | | the URI for the PCAP dump in pcap_file mode (overrides pcap_name) |
| socks5_enabled | bool | | vpn | true to redirect the TCP connections to a SOCKS5 proxy |
| socks5_proxy_ip_address | string | | vpn | the SOCKS5 proxy host |
| socks5_proxy_ip_address | string | | vpn | the SOCKS5 proxy IP address |
| socks5_proxy_port | int | | vpn | the SOCKS5 proxy port |
| root_capture | bool | | | true to capture packets in root mode, false to use the VPNService |
| pcapdroid_trailer | bool | | | true to enable the PCAPdroid trailer |