From 0135764eb3aeade8d0aae194a777cfc18a1617d5 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Thu, 22 Mar 2018 00:33:52 +0100 Subject: #8876 fix first part of review findings in EIP service --- app/src/main/java/se/leap/bitmaskclient/eip/EIP.java | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java index ab644c93..5dbf20c8 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java @@ -55,7 +55,6 @@ import static android.app.Activity.RESULT_CANCELED; import static android.app.Activity.RESULT_OK; import static android.content.Intent.CATEGORY_DEFAULT; import static se.leap.bitmaskclient.ConfigHelper.ensureNotOnMainThread; -import static se.leap.bitmaskclient.ConfigHelper.trim; import static se.leap.bitmaskclient.Constants.BROADCAST_EIP_EVENT; import static se.leap.bitmaskclient.Constants.BROADCAST_RESULT_CODE; import static se.leap.bitmaskclient.Constants.BROADCAST_RESULT_KEY; @@ -91,10 +90,10 @@ public final class EIP extends Service implements Observer { ERRORS = "errors", ERROR_ID = "errorID"; - private WeakReference mReceiverRef = new WeakReference<>(null); - private SharedPreferences preferences; + private volatile WeakReference mReceiverRef = new WeakReference<>(null); + private volatile SharedPreferences preferences; private AtomicInteger processCounter; - private EipStatus eipStatus; + private volatile EipStatus eipStatus; // Service connection to OpenVpnService, shared between threads private volatile OpenvpnServiceConnection openvpnServiceConnection; @@ -160,7 +159,7 @@ public final class EIP extends Service implements Observer { */ @SuppressLint("ApplySharedPref") private void startEIP(boolean earlyRoutes) { - if (!EipStatus.getInstance().isBlockingVpnEstablished() && earlyRoutes) { + if (!eipStatus.isBlockingVpnEstablished() && earlyRoutes) { earlyRoutes(); } @@ -232,7 +231,6 @@ public final class EIP extends Service implements Observer { */ @WorkerThread private void stopEIP() { - // if the OpenVpnConnection doesn't exist remember to disconnect after connecting int resultCode = stop() ? RESULT_OK : RESULT_CANCELED; tellToReceiverOrBroadcast(EIP_ACTION_STOP, resultCode); } @@ -243,7 +241,6 @@ public final class EIP extends Service implements Observer { * request if it's not connected, Activity.RESULT_OK otherwise. */ private void isRunning() { - EipStatus eipStatus = EipStatus.getInstance(); int resultCode = (eipStatus.isConnected()) ? RESULT_OK : RESULT_CANCELED; @@ -307,7 +304,7 @@ public final class EIP extends Service implements Observer { } /** - * broadcast resul + * broadcast result * @param resultCode RESULT_OK if action was successful RESULT_CANCELED otherwise * @param resultData other data to broadcast or return to receiver */ @@ -410,10 +407,10 @@ public final class EIP extends Service implements Observer { private ServiceConnection serviceConnection; private IOpenVPNServiceInternal service; - protected OpenvpnServiceConnection(Context context) throws InterruptedException { + protected OpenvpnServiceConnection(Context context) throws InterruptedException, IllegalStateException { this.context = context; ensureNotOnMainThread(context); - Log.d(TAG, "initSynchronzedServiceConnection!"); + Log.d(TAG, "initSynchronizedServiceConnection!"); initSynchronizedServiceConnection(context); } -- cgit v1.2.3