From df580ff4ca160bee13bb071e1db86c0a0945557e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Wed, 9 Oct 2013 12:46:34 +0200 Subject: Real VPN status is returned from Eip.isRunning(). retrieveVpnService now uses BIND_AUTO_CREATE flag, so that if the OpenVpnService has not been started, the state is still notified. retrieveVpnService now returns a boolean, so that if bindService fails false is returned. --- src/se/leap/bitmaskclient/EIP.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/se/leap/bitmaskclient/EIP.java b/src/se/leap/bitmaskclient/EIP.java index 84a0ce59..f9384ff6 100644 --- a/src/se/leap/bitmaskclient/EIP.java +++ b/src/se/leap/bitmaskclient/EIP.java @@ -134,10 +134,10 @@ public final class EIP extends IntentService { * Sends an Intent to bind OpenVpnService. * Used when OpenVpnService isn't bound but might be running. */ - private void retreiveVpnService() { + private boolean retreiveVpnService() { Intent bindIntent = new Intent(this,OpenVpnService.class); bindIntent.setAction(OpenVpnService.RETRIEVE_SERVICE); - bindService(bindIntent, mVpnServiceConn, 0); + return bindService(bindIntent, mVpnServiceConn, BIND_AUTO_CREATE); } private static ServiceConnection mVpnServiceConn = new ServiceConnection() { @@ -161,7 +161,7 @@ public final class EIP extends IntentService { resultCode = (running) ? Activity.RESULT_CANCELED : Activity.RESULT_OK; Bundle resultData = new Bundle(); - resultData.putString(REQUEST_TAG, EIP_NOTIFICATION); + resultData.putString(REQUEST_TAG, ACTION_IS_EIP_RUNNING); mReceiver.send(resultCode, resultData); mPending = null; @@ -196,13 +196,16 @@ public final class EIP extends IntentService { 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; - this.retreiveVpnService(); - } - - if (mReceiver != null){ - mReceiver.send(resultCode, resultData); + boolean retrieved_vpn_service = retreiveVpnService(); + if(!retrieved_vpn_service && mReceiver != null) { + mReceiver.send(resultCode, resultData); + } } } -- cgit v1.2.3