]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
android: Allow explicit termination of a profile without confirmation
authorTobias Brunner <tobias@strongswan.org>
Mon, 25 Jun 2018 09:02:08 +0000 (11:02 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 3 Jul 2018 09:31:43 +0000 (11:31 +0200)
src/frontends/android/app/src/main/java/org/strongswan/android/ui/VpnProfileControlActivity.java

index 2ebed6f82318ed1a97cc7e3857933a0abe6ce2dd..78cbebfae4fe7a8936725e9f58b6a3517f4ba4b7 100644 (file)
@@ -315,15 +315,35 @@ public class VpnProfileControlActivity extends AppCompatActivity
 
        /**
         * Disconnect the current connection, if any (silently ignored if there is no connection).
+        *
+        * @param intent Intent that caused us to start this
         */
-       private void disconnect()
+       private void disconnect(Intent intent)
        {
+               VpnProfile profile = null;
+
                removeFragmentByTag(DIALOG_TAG);
 
+               String profileUUID = intent.getStringExtra(EXTRA_VPN_PROFILE_ID);
+               if (profileUUID != null)
+               {
+                       VpnProfileDataSource dataSource = new VpnProfileDataSource(this);
+                       dataSource.open();
+                       profile = dataSource.getVpnProfile(profileUUID);
+                       dataSource.close();
+               }
+
                if (mService != null)
                {
-                       if (mService.getState() == State.CONNECTED || mService.getState() == State.CONNECTING)
+                       if (mService.getState() == State.CONNECTED ||
+                               mService.getState() == State.CONNECTING)
                        {
+                               if (profile != null && profile.equals(mService.getProfile()))
+                               {       /* allow explicit termination without confirmation */
+                                       mService.disconnect();
+                                       finish();
+                                       return;
+                               }
                                Bundle args = new Bundle();
                                args.putBoolean(PROFILE_DISCONNECT, true);
 
@@ -343,13 +363,15 @@ public class VpnProfileControlActivity extends AppCompatActivity
         */
        private void handleIntent()
        {
-               if (START_PROFILE.equals(getIntent().getAction()))
+               Intent intent = getIntent();
+
+               if (START_PROFILE.equals(intent.getAction()))
                {
-                       startVpnProfile(getIntent());
+                       startVpnProfile(intent);
                }
-               else if (DISCONNECT.equals(getIntent().getAction()))
+               else if (DISCONNECT.equals(intent.getAction()))
                {
-                       disconnect();
+                       disconnect(intent);
                }
        }
 
@@ -416,7 +438,7 @@ public class VpnProfileControlActivity extends AppCompatActivity
                                        {
                                                activity.mService.disconnect();
                                        }
-                                       getActivity().finish();
+                                       activity.finish();
                                }
                        };
                        DialogInterface.OnClickListener cancelListener = new DialogInterface.OnClickListener()