diff options
author | Sean Leonard <meanderingcode@aetherislands.net> | 2014-02-07 14:46:10 -0800 |
---|---|---|
committer | Sean Leonard <meanderingcode@aetherislands.net> | 2014-02-07 14:46:37 -0800 |
commit | 754e15dc7c46981ccc3fe3f5e9dcc14487ddf5bb (patch) | |
tree | 2459a31d1e7926ebfebd2e8f3bbf06a969102ffd /src/se/leap/bitmaskclient/EIP.java | |
parent | c49e87b8fd272fabc3f674fa8103b455c3bb5304 (diff) |
bugfix for #4664 and #4668 (login/logout messages)
Conflicts:
src/se/leap/bitmaskclient/ProviderAPI.java
res/values/strings.xml (Re-add lines removed in 7297632a01d5fb606b901d8c54e190e28b95716e )
Diffstat (limited to 'src/se/leap/bitmaskclient/EIP.java')
-rw-r--r-- | src/se/leap/bitmaskclient/EIP.java | 73 |
1 files changed, 48 insertions, 25 deletions
diff --git a/src/se/leap/bitmaskclient/EIP.java b/src/se/leap/bitmaskclient/EIP.java index 2b7fd39f..ecb7498f 100644 --- a/src/se/leap/bitmaskclient/EIP.java +++ b/src/se/leap/bitmaskclient/EIP.java @@ -35,13 +35,13 @@ import se.leap.openvpn.OpenVpnService; import se.leap.openvpn.OpenVpnService.LocalBinder; import se.leap.openvpn.ProfileManager; import se.leap.openvpn.VpnProfile; - import android.app.Activity; import android.app.IntentService; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; +import android.drm.DrmStore.Action; import android.os.Bundle; import android.os.IBinder; import android.os.ResultReceiver; @@ -72,6 +72,7 @@ public final class EIP extends IntentService { public final static String SERVICE_API_PATH = "config/eip-service.json"; public final static String RECEIVER_TAG = "receiverTag"; public final static String REQUEST_TAG = "requestTag"; + public final static String TAG = "se.leap.bitmaskclient.EIP"; private static Context context; @@ -141,7 +142,6 @@ public final class EIP extends IntentService { } private static ServiceConnection mVpnServiceConn = new ServiceConnection() { - @Override public void onServiceConnected(ComponentName name, IBinder service) { LocalBinder binder = (LocalBinder) service; @@ -149,17 +149,22 @@ public final class EIP extends IntentService { mBound = true; if (mReceiver != null && mPending != null) { - + boolean running = mVpnService.isRunning(); + int resultCode = Activity.RESULT_CANCELED; - if (mPending.equals(ACTION_IS_EIP_RUNNING)) + if (mPending.equals(ACTION_IS_EIP_RUNNING)){ resultCode = (running) ? Activity.RESULT_OK : Activity.RESULT_CANCELED; - if (mPending.equals(ACTION_START_EIP)) + + } + else if (mPending.equals(ACTION_START_EIP)){ resultCode = (running) ? Activity.RESULT_OK : Activity.RESULT_CANCELED; - else if (mPending.equals(ACTION_STOP_EIP)) + } + else if (mPending.equals(ACTION_STOP_EIP)){ resultCode = (running) ? Activity.RESULT_CANCELED : Activity.RESULT_OK; + } Bundle resultData = new Bundle(); resultData.putString(REQUEST_TAG, ACTION_IS_EIP_RUNNING); mReceiver.send(resultCode, resultData); @@ -178,6 +183,7 @@ public final class EIP extends IntentService { mReceiver.send(Activity.RESULT_CANCELED, resultData); } } + }; @@ -190,25 +196,42 @@ public final class EIP extends IntentService { * Note: If the request to bind OpenVpnService is successful, the ResultReceiver * will be notified in {@link onServiceConnected()} */ - private void isRunning() { - Bundle resultData = new Bundle(); - resultData.putString(REQUEST_TAG, ACTION_IS_EIP_RUNNING); - int resultCode = Activity.RESULT_CANCELED; - if (mBound) { - resultCode = (mVpnService.isRunning()) ? Activity.RESULT_OK : Activity.RESULT_CANCELED; - - if (mReceiver != null){ - mReceiver.send(resultCode, resultData); - } - } else { - mPending = ACTION_IS_EIP_RUNNING; - boolean retrieved_vpn_service = retreiveVpnService(); - if(!retrieved_vpn_service && mReceiver != null) { - mReceiver.send(resultCode, resultData); - } - } - } - + + private void isRunning() { + Bundle resultData = new Bundle(); + resultData.putString(REQUEST_TAG, ACTION_IS_EIP_RUNNING); + int resultCode = Activity.RESULT_CANCELED; + if (mBound) { + resultCode = (mVpnService.isRunning()) ? Activity.RESULT_OK : Activity.RESULT_CANCELED; + + if (mReceiver != null){ + mReceiver.send(resultCode, resultData); + } + } else { + mPending = ACTION_IS_EIP_RUNNING; + boolean retrieved_vpn_service = retreiveVpnService(); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + boolean running = false; + try { + running = mVpnService.isRunning(); + } catch (NullPointerException e){ + e.printStackTrace(); + } + + if (retrieved_vpn_service && running && mReceiver != null){ + mReceiver.send(Activity.RESULT_OK, resultData); + } + else{ + mReceiver.send(Activity.RESULT_CANCELED, resultData); + } + } + } + /** * Initiates an EIP connection by selecting a gateway and preparing and sending an * Intent to {@link se.leap.openvpn.LaunchVPN} |