private void StartVpn() { if (VpnService.Prepare(this) != null) { var activity = ShowingActivity; if (activity?.Handler.Post(activity.VpnServicePrepare) == true) { Logging.info("Using showing activity to request VPN permission."); } else { Logging.info("Starting activity to request VPN permission."); StartActivity(new Intent(this, typeof(MainActivity)).SetAction("PREP_VPN").SetFlags(ActivityFlags.NewTask)); } } else { // continue starting vpn service try { if (vpnHelper == null) { vpnHelper = new VpnHelper(this); } // else it may be reloading vpnHelper.VpnConfig = currentConfig.vpn; vpnHelper.StartVpn(); } catch (Exception e) { Logging.exception(e, Logging.Level.Error, "Starting VPN"); } } }
public void VpnServicePrepare() { var r = VpnService.Prepare(this); if (r == null) { StartServiceWithAction(BgService.Actions.START_VPN); } else { StartActivityForResult(r, REQ_VPN); } }
private void StartVPN() { Intent vpnIntent = VpnService.Prepare(this); if (vpnIntent != null) { StartActivityForResult(vpnIntent, VPN_REQUEST_CODE); } else { OnActivityResult(VPN_REQUEST_CODE, Result.Ok, null); } }
private void StartVPNService() { Intent intent = VpnService.Prepare(m_activity); if (intent != null) { m_activity.StartActivityForResult(intent, VPN_START); } else { OnActivityResult(VPN_START, Result.Ok, null); } }
private void StartVPNService() { Log.Debug(TAG, "StartVPNService"); Intent intent = VpnService.Prepare(context); if (intent != null) { if (activity != null) { activity.StartActivityForResult(intent, VPN_START); } } else { OnActivityResult(VPN_START, Result.Ok, null); } }
private void TryRestoreLastProfile(Context context) { LogsManager.Instance.Debug("EventsReceiver.TryRestoreLastProfile"); if (VpnService.Prepare(context.ApplicationContext) != null) { LogsManager.Instance.Debug("VpnService.Prepare requires confirmation"); return; } if (!OptionsManager.SystemLastProfileRestore) { LogsManager.Instance.Debug("EventsReceiver: SystemRestoreLastProfile disabled"); return; } string lastProfile = OptionsManager.SystemLastProfileActivated; if (Utils.Empty(lastProfile)) { LogsManager.Instance.Debug("EventsReceiver: lastProfile is empty"); return; } LogsManager.Instance.Debug("EventsReceiver: restoring last profile1"); try { Bundle args = new Bundle(); args.PutString(AndroidVPNService.PARAM_PROFILE, lastProfile); Intent intent = new Intent(context, typeof(AndroidVPNService)); intent.PutExtra(AndroidVPNService.PARAM_START, true); intent.PutExtra(AndroidVPNService.EXTRA_RUN_ARGS, args); context.StartService(intent); } catch (Exception e) { LogsManager.Instance.Error("TryRestoreLastProfile", e); } }
private void BindService() { Intent confirmIntent = VpnService.Prepare(m_context.ApplicationContext); if (confirmIntent != null) { // The only case when m_context is not an Activity is from the BootReceiver but in that case the VPN confirmation should already been granted and the confirmIntent will be null Activity activity = m_context as Activity; if (activity != null) { activity.StartActivityForResult(confirmIntent, VPN_REQUEST_CODE); } else { LogsManager.Instance.Error("Failed to cast context to Activity"); } } else { HandleActivityResult(VPN_REQUEST_CODE, Result.Ok, null); } }