VpnService: Move it to a backends package
It should be split into two pieces: configuration file management (loading/saving/renaming/deleting) and calling into wg-quick via RootShell. The configuration file management part should then go back into the main package. This is in preparation for adding additional backends based on wg(8) and wireguard-go. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
69d4fe9a81
commit
50a7a12de2
@ -12,6 +12,11 @@
|
|||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@android:style/Theme.Material.Light.DarkActionBar">
|
android:theme="@android:style/Theme.Material.Light.DarkActionBar">
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name=".AddActivity"
|
||||||
|
android:label="@string/add_activity_title"
|
||||||
|
android:parentActivityName=".ConfigActivity" />
|
||||||
<activity android:name=".ConfigActivity">
|
<activity android:name=".ConfigActivity">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
@ -19,10 +24,6 @@
|
|||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
|
||||||
android:name=".AddActivity"
|
|
||||||
android:label="@string/add_activity_title"
|
|
||||||
android:parentActivityName=".ConfigActivity" />
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".SettingsActivity"
|
android:name=".SettingsActivity"
|
||||||
android:label="@string/settings">
|
android:label="@string/settings">
|
||||||
@ -44,12 +45,13 @@
|
|||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.service.quicksettings.action.QS_TILE" />
|
<action android:name="android.service.quicksettings.action.QS_TILE" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="android.service.quicksettings.ACTIVE_TILE"
|
android:name="android.service.quicksettings.ACTIVE_TILE"
|
||||||
android:value="true" />
|
android:value="true" />
|
||||||
</service>
|
</service>
|
||||||
<service
|
<service
|
||||||
android:name=".VpnService"
|
android:name=".backends.VpnService"
|
||||||
android:exported="false" />
|
android:exported="false" />
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import android.content.ServiceConnection;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
|
||||||
|
import com.wireguard.android.backends.VpnService;
|
||||||
import com.wireguard.config.Config;
|
import com.wireguard.config.Config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3,6 +3,7 @@ package com.wireguard.android;
|
|||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import com.wireguard.android.backends.VpnService;
|
||||||
import com.wireguard.config.Config;
|
import com.wireguard.config.Config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4,6 +4,8 @@ import android.content.BroadcastReceiver;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
|
||||||
|
import com.wireguard.android.backends.VpnService;
|
||||||
|
|
||||||
public class BootCompletedReceiver extends BroadcastReceiver {
|
public class BootCompletedReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -8,6 +8,7 @@ import android.os.Bundle;
|
|||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
||||||
|
import com.wireguard.android.backends.VpnService;
|
||||||
import com.wireguard.config.Config;
|
import com.wireguard.config.Config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -14,6 +14,7 @@ import android.view.ViewGroup;
|
|||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.wireguard.android.backends.VpnService;
|
||||||
import com.wireguard.android.databinding.ConfigEditFragmentBinding;
|
import com.wireguard.android.databinding.ConfigEditFragmentBinding;
|
||||||
import com.wireguard.config.Config;
|
import com.wireguard.config.Config;
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ import android.widget.AbsListView;
|
|||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
|
||||||
|
import com.wireguard.android.backends.VpnService;
|
||||||
import com.wireguard.android.bindings.ObservableMapAdapter;
|
import com.wireguard.android.bindings.ObservableMapAdapter;
|
||||||
import com.wireguard.android.databinding.ConfigListFragmentBinding;
|
import com.wireguard.android.databinding.ConfigListFragmentBinding;
|
||||||
import com.wireguard.config.Config;
|
import com.wireguard.config.Config;
|
||||||
|
@ -4,6 +4,8 @@ import android.content.Context;
|
|||||||
import android.preference.ListPreference;
|
import android.preference.ListPreference;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
|
||||||
|
import com.wireguard.android.backends.VpnService;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -13,6 +13,7 @@ import android.preference.PreferenceManager;
|
|||||||
import android.service.quicksettings.Tile;
|
import android.service.quicksettings.Tile;
|
||||||
import android.service.quicksettings.TileService;
|
import android.service.quicksettings.TileService;
|
||||||
|
|
||||||
|
import com.wireguard.android.backends.VpnService;
|
||||||
import com.wireguard.config.Config;
|
import com.wireguard.config.Config;
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.N)
|
@TargetApi(Build.VERSION_CODES.N)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package com.wireguard.android;
|
package com.wireguard.android.backends;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
@ -1,4 +1,4 @@
|
|||||||
package com.wireguard.android;
|
package com.wireguard.android.backends;
|
||||||
|
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
@ -14,6 +14,7 @@ import android.preference.PreferenceManager;
|
|||||||
import android.service.quicksettings.TileService;
|
import android.service.quicksettings.TileService;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.wireguard.android.QuickTileService;
|
||||||
import com.wireguard.android.bindings.ObservableSortedMap;
|
import com.wireguard.android.bindings.ObservableSortedMap;
|
||||||
import com.wireguard.android.bindings.ObservableTreeMap;
|
import com.wireguard.android.bindings.ObservableTreeMap;
|
||||||
import com.wireguard.config.Config;
|
import com.wireguard.config.Config;
|
||||||
@ -45,11 +46,6 @@ public class VpnService extends Service
|
|||||||
private static final String TAG = "VpnService";
|
private static final String TAG = "VpnService";
|
||||||
|
|
||||||
private static VpnService instance;
|
private static VpnService instance;
|
||||||
|
|
||||||
public static VpnService getInstance() {
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
private final IBinder binder = new Binder();
|
private final IBinder binder = new Binder();
|
||||||
private final ObservableTreeMap<String, Config> configurations = new ObservableTreeMap<>();
|
private final ObservableTreeMap<String, Config> configurations = new ObservableTreeMap<>();
|
||||||
private final Set<String> enabledConfigs = new HashSet<>();
|
private final Set<String> enabledConfigs = new HashSet<>();
|
||||||
@ -57,6 +53,10 @@ public class VpnService extends Service
|
|||||||
private String primaryName;
|
private String primaryName;
|
||||||
private RootShell rootShell;
|
private RootShell rootShell;
|
||||||
|
|
||||||
|
public static VpnService getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new configuration to the set of known configurations. The configuration will initially
|
* Add a new configuration to the set of known configurations. The configuration will initially
|
||||||
* be disabled. The configuration's name must be unique within the set of known configurations.
|
* be disabled. The configuration's name must be unique within the set of known configurations.
|
||||||
@ -406,11 +406,11 @@ public class VpnService extends Service
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class ConfigUpdater extends AsyncTask<Void, Void, Boolean> {
|
private class ConfigUpdater extends AsyncTask<Void, Void, Boolean> {
|
||||||
private Config knownConfig;
|
|
||||||
private final Config newConfig;
|
private final Config newConfig;
|
||||||
private final String newName;
|
private final String newName;
|
||||||
private final String oldName;
|
private final String oldName;
|
||||||
private final Boolean shouldConnect;
|
private final Boolean shouldConnect;
|
||||||
|
private Config knownConfig;
|
||||||
|
|
||||||
private ConfigUpdater(final Config knownConfig, final Config newConfig,
|
private ConfigUpdater(final Config knownConfig, final Config newConfig,
|
||||||
final Boolean shouldConnect) {
|
final Boolean shouldConnect) {
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
<import type="android.graphics.Typeface" />
|
<import type="android.graphics.Typeface" />
|
||||||
|
|
||||||
<import type="com.wireguard.android.VpnService" />
|
<import type="com.wireguard.android.backends.VpnService" />
|
||||||
|
|
||||||
<variable
|
<variable
|
||||||
name="key"
|
name="key"
|
||||||
|
Loading…
Reference in New Issue
Block a user