]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
android: Simplify error handling in VPN state fragment
authorTobias Brunner <tobias@strongswan.org>
Fri, 29 Jun 2018 14:42:18 +0000 (16:42 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 3 Jul 2018 09:31:44 +0000 (11:31 +0200)
Always reset the error state when disconnecting via state service. This
way the error state is also cleared when the connection is terminated
directly via control activity.

src/frontends/android/app/src/main/java/org/strongswan/android/logic/VpnStateService.java
src/frontends/android/app/src/main/java/org/strongswan/android/ui/VpnStateFragment.java

index 0dc340346848b5bd7bce55b29b0ae7c73759c283..5889293616e65481d52a0e7f16ba2cbd7411ddc2 100644 (file)
@@ -262,7 +262,10 @@ public class VpnStateService extends Service
         */
        public void disconnect()
        {
+               /* reset any potential retry timer and error state */
                resetRetryTimer();
+               setError(ErrorState.NO_ERROR);
+
                /* as soon as the TUN device is created by calling establish() on the
                 * VpnService.Builder object the system binds to the service and keeps
                 * bound until the file descriptor of the TUN device is closed.  thus
index 9c92463dee1d9e288b97179d8f41103e2752e0e4..edc70fa9642ac45f7c34676a2e18a75f061f9860 100644 (file)
@@ -28,7 +28,6 @@ import android.support.v4.app.Fragment;
 import android.support.v4.content.ContextCompat;
 import android.view.LayoutInflater;
 import android.view.View;
-import android.view.View.OnClickListener;
 import android.view.ViewGroup;
 import android.widget.Button;
 import android.widget.LinearLayout;
@@ -44,8 +43,6 @@ import org.strongswan.android.logic.VpnStateService.VpnStateListener;
 
 public class VpnStateFragment extends Fragment implements VpnStateListener
 {
-       private static final String KEY_ERROR_CONNECTION_ID = "error_connection_id";
-
        private boolean mVisible;
        private TextView mProfileNameView;
        private TextView mProfileView;
@@ -59,7 +56,6 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
        private TextView mErrorText;
        private Button mErrorRetry;
        private Button mShowLog;
-       private long mErrorConnectionID;
        private VpnStateService mService;
        private final ServiceConnection mServiceConnection = new ServiceConnection()
        {
@@ -80,17 +76,6 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
                        }
                }
        };
-       private OnClickListener mDisconnectListener = new OnClickListener()
-       {
-               @Override
-               public void onClick(View v)
-               {
-                       if (mService != null)
-                       {
-                               mService.disconnect();
-                       }
-               }
-       };
 
        @Override
        public void onCreate(Bundle savedInstanceState)
@@ -104,20 +89,6 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
                Context context = getActivity().getApplicationContext();
                context.bindService(new Intent(context, VpnStateService.class),
                                                        mServiceConnection, Service.BIND_AUTO_CREATE);
-
-               mErrorConnectionID = 0;
-               if (savedInstanceState != null && savedInstanceState.containsKey(KEY_ERROR_CONNECTION_ID))
-               {
-                       mErrorConnectionID = (Long)savedInstanceState.getSerializable(KEY_ERROR_CONNECTION_ID);
-               }
-       }
-
-       @Override
-       public void onSaveInstanceState(Bundle outState)
-       {
-               super.onSaveInstanceState(outState);
-
-               outState.putSerializable(KEY_ERROR_CONNECTION_ID, mErrorConnectionID);
        }
 
        @Override
@@ -127,7 +98,12 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
                View view = inflater.inflate(R.layout.vpn_state_fragment, null);
 
                mActionButton = (Button)view.findViewById(R.id.action);
-               mActionButton.setOnClickListener(v -> clearError());
+               mActionButton.setOnClickListener(v -> {
+                       if (mService != null)
+                       {
+                               mService.disconnect();
+                       }
+               });
                enableActionButton(null);
 
                mErrorView = view.findViewById(R.id.vpn_error);
@@ -259,7 +235,6 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
                        mErrorView.setVisibility(View.GONE);
                        return false;
                }
-               mErrorConnectionID = connectionID;
                mProfileNameView.setText(name);
                showProfile(true);
                mStateView.setText(R.string.state_error);
@@ -298,16 +273,4 @@ public class VpnStateFragment extends Fragment implements VpnStateListener
                mActionButton.setEnabled(text != null);
                mActionButton.setVisibility(text != null ? View.VISIBLE : View.GONE);
        }
-
-       private void clearError()
-       {
-               if (mService != null)
-               {
-                       mService.disconnect();
-                       if (mService.getConnectionID() == mErrorConnectionID)
-                       {
-                               mService.setError(ErrorState.NO_ERROR);
-                       }
-               }
-       }
 }