Fix possible IllegalStateException on VPN start

"IllegalStateException: Unavailable in lockdown mode" is happening
on some devices. On most devices it just returnss a null intent
This commit is contained in:
emanuele-f 2025-03-23 12:41:13 +01:00
parent 6b8ab97713
commit 5abc3a7e20

View File

@ -148,14 +148,22 @@ public class CaptureHelper {
return;
}
Intent vpnPrepareIntent = VpnService.prepare(mContext);
Intent vpnPrepareIntent = null;
try {
vpnPrepareIntent = VpnService.prepare(mContext);
} catch (RuntimeException e) {
e.printStackTrace();
}
if(vpnPrepareIntent != null) {
final Intent prepareIntent = vpnPrepareIntent;
if (mLauncher != null)
new AlertDialog.Builder(mContext)
.setMessage(R.string.vpn_setup_msg)
.setPositiveButton(R.string.ok, (dialog, whichButton) -> {
try {
mLauncher.launch(vpnPrepareIntent);
mLauncher.launch(prepareIntent);
} catch (ActivityNotFoundException e) {
Utils.showToastLong(mContext, R.string.no_intent_handler_found);
mListener.onCaptureStartResult(false);