Use latest values when started by the system

This commit is contained in:
frtget 2022-03-09 16:03:48 -05:00
parent babfb69e64
commit c3d2b32855
1 changed files with 17 additions and 6 deletions

View File

@ -1,6 +1,8 @@
package network.loki.lokinet;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.net.VpnService;
import android.os.Binder;
import android.os.IBinder;
@ -88,8 +90,22 @@ public class LokinetDaemon extends VpnService {
ArrayList<ConfigValue> configVals = new ArrayList<ConfigValue>();
String exitNode = null;
if (intent != null) {
String upstreamDNS = null;
SharedPreferences sharedPreferences = getSharedPreferences("lokinet_lib", MODE_PRIVATE);
if (ACTION_CONNECT.equals(action)) { // started by the app
exitNode = intent.getStringExtra(EXIT_NODE);
upstreamDNS = intent.getStringExtra(UPSTREAM_DNS);
// save values
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(EXIT_NODE, exitNode);
editor.putString(UPSTREAM_DNS, upstreamDNS);
editor.commit();
} else { // if started by the system because Always-on VPN setting is enabled
// use the latest values
exitNode = sharedPreferences.getString(EXIT_NODE, null);
upstreamDNS = sharedPreferences.getString(UPSTREAM_DNS, null);
}
if (exitNode == null || exitNode.isEmpty()) {
@ -100,11 +116,6 @@ public class LokinetDaemon extends VpnService {
Log.e(LOG_TAG, "Using " + exitNode + " as exit-node.");
configVals.add(new ConfigValue("network", "exit-node", exitNode));
String upstreamDNS = null;
if (intent != null) {
upstreamDNS = intent.getStringExtra(UPSTREAM_DNS);
}
if (upstreamDNS == null || upstreamDNS.isEmpty()) {
upstreamDNS = DEFAULT_UPSTREAM_DNS;
Log.e(LOG_TAG, "No upstream DNS configured! Proceeding with default.");