Add informative message before asking VPN permission

Closes #215
This commit is contained in:
emanuele-f 2022-05-30 22:21:50 +02:00
parent a22d334b5a
commit eb8a504f09
2 changed files with 20 additions and 7 deletions

View File

@ -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();
}

View File

@ -360,4 +360,5 @@
<string name="country_and_asn">Country and ASN</string>
<string name="app_intro_geolocation_msg">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</string>
<string name="features_onboarding">On-boarding</string>
<string name="vpn_setup_msg">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</string>
</resources>