From eb8a504f092744b4fb57f64e02d0d6efb93058db Mon Sep 17 00:00:00 2001 From: emanuele-f Date: Mon, 30 May 2022 22:21:50 +0200 Subject: [PATCH] Add informative message before asking VPN permission Closes #215 --- .../remote_capture/CaptureHelper.java | 26 ++++++++++++++----- app/src/main/res/values/strings.xml | 1 + 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/emanuelef/remote_capture/CaptureHelper.java b/app/src/main/java/com/emanuelef/remote_capture/CaptureHelper.java index 881bc9e3..dfa8f850 100644 --- a/app/src/main/java/com/emanuelef/remote_capture/CaptureHelper.java +++ b/app/src/main/java/com/emanuelef/remote_capture/CaptureHelper.java @@ -20,6 +20,7 @@ package com.emanuelef.remote_capture; import android.app.Activity; +import android.app.AlertDialog; import android.content.ActivityNotFoundException; import android.content.Intent; import android.net.VpnService; @@ -48,8 +49,10 @@ public class CaptureHelper { private void captureServiceResult(final ActivityResult result) { if(result.getResultCode() == Activity.RESULT_OK) startCaptureOk(); - else if(mListener != null) + else if(mListener != null) { + Utils.showToastLong(mActivity, R.string.vpn_setup_failed); mListener.onCaptureStartResult(false); + } } private void startCaptureOk() { @@ -74,12 +77,21 @@ public class CaptureHelper { Intent vpnPrepareIntent = VpnService.prepare(mActivity); if(vpnPrepareIntent != null) { - try { - mLauncher.launch(vpnPrepareIntent); - } catch (ActivityNotFoundException e) { - Utils.showToastLong(mActivity, R.string.no_intent_handler_found); - mListener.onCaptureStartResult(false); - } + new AlertDialog.Builder(mActivity) + .setMessage(R.string.vpn_setup_msg) + .setPositiveButton(R.string.ok, (dialog, whichButton) -> { + try { + mLauncher.launch(vpnPrepareIntent); + } catch (ActivityNotFoundException e) { + Utils.showToastLong(mActivity, R.string.no_intent_handler_found); + mListener.onCaptureStartResult(false); + } + }) + .setOnCancelListener(dialog -> { + Utils.showToastLong(mActivity, R.string.vpn_setup_failed); + mListener.onCaptureStartResult(false); + }) + .show(); } else startCaptureOk(); } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index be611d73..5ce5c27b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -360,4 +360,5 @@ Country and ASN PCAPdroid can query a local database to determine the country of a remote server\n\nYou must first download the database from the PCAPdroid settings On-boarding + PCAPdroid simulates a VPN in order to capture the network traffic without root.\n\nTo start the capture, you need to accept the VPN request in the next screen