コード例 #1
0
 private void ToBackground(bool removeNotif)
 {
     Logger.info("ToBackground(" + removeNotif + ")");
     if (IsInOperation)
     {
         Logger.logWithStackTrace("ToBackground() while the service is in operation", Logging.Level.Warning);
         return;
     }
     notifyTimer?.Dispose();
     notifyTimer = null;
     StopForeground(removeNotif);
     UnregisterReceiver(receiverScreenState);
     receiverScreenState = null;
     onScreen(false);
     SetRunningState(false, true);
     vpnHelper?.Stop();
     vpnHelper = null;
     Task.Run(() => {
         try {
             Controller.Stop();
         } finally {
             SetRunningState(false, false);
         }
     });
 }
コード例 #2
0
 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");
         }
     }
 }