Commit 045675a8 authored by cyberta's avatar cyberta
Browse files

* use static atomicBoolean to save alwaysOn settings instead of sharedPrefs

>> avoid race conditions between sharedPreference writing and onBoot receiver reading
* don't explicitly exclude Bitmask from routes
parent 2979517d
......@@ -44,7 +44,6 @@ import de.blinkt.openvpn.core.VpnStatus.ByteCountListener;
import de.blinkt.openvpn.core.VpnStatus.StateListener;
import se.leap.bitmaskclient.R;
import se.leap.bitmaskclient.VpnNotificationManager;
import se.leap.bitmaskclient.utils.PreferenceHelper;
import static de.blinkt.openvpn.core.ConnectionStatus.LEVEL_CONNECTED;
import static de.blinkt.openvpn.core.ConnectionStatus.LEVEL_WAITING_FOR_USER_INPUT;
......@@ -319,14 +318,15 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
updateShortCutUsage(mProfile);
}
PreferenceHelper.setAlwaysOn(this, false);
VpnStatus.setAlwaysOn(false);
} else {
/* The intent is null when we are set as always-on or the service has been restarted. */
mProfile = VpnStatus.getLastConnectedVpnProfile(this);
VpnStatus.logInfo(R.string.service_restarted);
if (mProfile != null) {
PreferenceHelper.setAlwaysOn(this, true);
VpnStatus.setAlwaysOn(true);
}
}
......@@ -543,13 +543,6 @@ public class OpenVPNService extends VpnService implements StateListener, Callbac
if (mProfile.mAllowLocalLAN) {
allowAllAFFamilies(builder);
}
if (PreferenceHelper.isAlwaysOn(this)) {
try {
builder.addDisallowedApplication(this.getPackageName());
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
}
}
if (mLocalIP == null && mLocalIPv6 == null) {
......
......@@ -17,6 +17,7 @@ import java.util.LinkedList;
import java.util.Locale;
import java.util.Vector;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicBoolean;
import de.blinkt.openvpn.VpnProfile;
import se.leap.bitmaskclient.R;
......@@ -33,6 +34,8 @@ public class VpnStatus {
private static CopyOnWriteArrayList<StateListener> stateListener;
private static Vector<ByteCountListener> byteCountListener;
private static AtomicBoolean isAlwaysOnBooting = new AtomicBoolean(false);
private static String mLaststatemsg = "";
private static String mLaststate = "NOPROCESS";
......@@ -504,7 +507,6 @@ public class VpnStatus {
}
public static synchronized void updateByteCount(long in, long out) {
TrafficHistory.LastDiff diff = trafficHistory.add(in, out);
......@@ -512,4 +514,12 @@ public class VpnStatus {
bcl.updateByteCount(in, out, diff.getDiffIn(), diff.getDiffOut());
}
}
public static void setAlwaysOn(boolean alwaysOn) {
isAlwaysOnBooting.set(alwaysOn);
}
public static boolean isAlwaysOn() {
return isAlwaysOnBooting.get();
}
}
......@@ -6,6 +6,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.util.Log;
import de.blinkt.openvpn.core.VpnStatus;
import se.leap.bitmaskclient.utils.PreferenceHelper;
import static android.content.Intent.ACTION_BOOT_COMPLETED;
......@@ -29,7 +30,7 @@ public class OnBootReceiver extends BroadcastReceiver {
preferences = context.getSharedPreferences(SHARED_PREFERENCES, Context.MODE_PRIVATE);
boolean providerConfigured = !preferences.getString(PROVIDER_VPN_CERTIFICATE, "").isEmpty();
boolean startOnBoot = preferences.getBoolean(EIP_RESTART_ON_BOOT, false);
boolean isAlwaysOnConfigured = PreferenceHelper.isAlwaysOn(context);
boolean isAlwaysOnConfigured = VpnStatus.isAlwaysOn();
Log.d("OpenVPN", "OpenVPN onBoot intent received. Provider configured? " + providerConfigured + " Start on boot? " + startOnBoot + " isAlwaysOn feature configured: " + isAlwaysOnConfigured);
if (providerConfigured) {
if (isAlwaysOnConfigured) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment