mirror of
https://github.com/amnezia-vpn/amneziawg-android.git
synced 2026-07-03 14:05:13 +02:00
Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 377ba1c9d1 | |||
| 8ebeeb6d90 | |||
| 3c3de065c6 | |||
| a17ec6b1f7 | |||
| cbf8ac6538 | |||
| d4b1295e94 | |||
| db53e17e58 | |||
| f0a3e63743 | |||
| d636e13717 | |||
| dea60e13c0 | |||
| 40a30d997d | |||
| dba8d0305e | |||
| 27072972ab | |||
| d56e95c576 | |||
| d0ef2c43d9 | |||
| 0c0c1acc3b | |||
| 48f796c463 | |||
| 8aab35a70d |
+2
-2
@@ -14,8 +14,8 @@ android {
|
||||
applicationId 'com.wireguard.android'
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 27
|
||||
versionCode 421
|
||||
versionName '0.0.20180604'
|
||||
versionCode 422
|
||||
versionName '0.0.20180605'
|
||||
}
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
|
||||
@@ -23,7 +23,6 @@ import com.wireguard.android.model.TunnelManager;
|
||||
import com.wireguard.android.util.AsyncWorker;
|
||||
import com.wireguard.android.util.RootShell;
|
||||
import com.wireguard.android.util.ToolsInstaller;
|
||||
import com.wireguard.android.util.Topic;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.Executor;
|
||||
@@ -68,8 +67,6 @@ public class Application extends android.app.Application {
|
||||
ToolsInstaller getToolsInstaller();
|
||||
|
||||
TunnelManager getTunnelManager();
|
||||
|
||||
Topic getThemeChangeTopic();
|
||||
}
|
||||
|
||||
@Qualifier
|
||||
@@ -119,13 +116,6 @@ public class Application extends android.app.Application {
|
||||
return new FileConfigStore(context);
|
||||
}
|
||||
|
||||
@ApplicationScope
|
||||
@Provides
|
||||
public static Topic getThemeChangeTopic() {
|
||||
return new Topic();
|
||||
}
|
||||
|
||||
|
||||
@ApplicationScope
|
||||
@Provides
|
||||
public static Executor getExecutor() {
|
||||
|
||||
@@ -11,24 +11,19 @@ import android.databinding.CallbackRegistry;
|
||||
import android.databinding.CallbackRegistry.NotifierCallback;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.util.Log;
|
||||
|
||||
import com.wireguard.android.Application;
|
||||
import com.wireguard.android.backend.GoBackend;
|
||||
import com.wireguard.android.model.Tunnel;
|
||||
import com.wireguard.android.model.TunnelManager;
|
||||
import com.wireguard.android.util.Topic;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Base class for activities that need to remember the currently-selected tunnel.
|
||||
*/
|
||||
|
||||
public abstract class BaseActivity extends AppCompatActivity implements Topic.Subscriber {
|
||||
private static final String TAG = "WireGuard/" + BaseActivity.class.getSimpleName();
|
||||
|
||||
public abstract class BaseActivity extends ThemeChangeAwareActivity {
|
||||
private static final String KEY_SELECTED_TUNNEL = "selected_tunnel";
|
||||
|
||||
private final SelectionChangeRegistry selectionChangeRegistry = new SelectionChangeRegistry();
|
||||
@@ -45,8 +40,6 @@ public abstract class BaseActivity extends AppCompatActivity implements Topic.Su
|
||||
|
||||
@Override
|
||||
protected void onCreate(final Bundle savedInstanceState) {
|
||||
subscribeTopics();
|
||||
|
||||
// Restore the saved tunnel if there is one; otherwise grab it from the arguments.
|
||||
String savedTunnelName = null;
|
||||
if (savedInstanceState != null)
|
||||
@@ -69,12 +62,6 @@ public abstract class BaseActivity extends AppCompatActivity implements Topic.Su
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
unsubscribeTopics();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(final Bundle outState) {
|
||||
if (selectedTunnel != null)
|
||||
@@ -118,28 +105,4 @@ public abstract class BaseActivity extends AppCompatActivity implements Topic.Su
|
||||
super(new SelectionChangeNotifier());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTopicPublished(Topic topic) {
|
||||
try {
|
||||
Field f = getResources().getClass().getDeclaredField("mResourcesImpl");
|
||||
f.setAccessible(true);
|
||||
Object o = f.get(getResources());
|
||||
f = o.getClass().getDeclaredField("mDrawableCache");
|
||||
f.setAccessible(true);
|
||||
o = f.get(o);
|
||||
f = o.getClass().getSuperclass().getDeclaredField("mThemedEntries");
|
||||
f.setAccessible(true);
|
||||
o = f.get(o);
|
||||
o.getClass().getMethod("clear").invoke(o);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Failed to flush icon cache", e);
|
||||
}
|
||||
recreate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Topic[] getSubscription() {
|
||||
return new Topic[] { Application.getComponent().getThemeChangeTopic() };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class MainActivity extends BaseActivity {
|
||||
getSupportFragmentManager().getFragments().get(0));
|
||||
} catch (final ClassCastException ignored) {
|
||||
}
|
||||
if (fragment == null || !(fragment.collapseActionMenu())) {
|
||||
if (fragment == null || !fragment.collapseActionMenu()) {
|
||||
if (!moveToState(State.ofLayer(state.layer - 1)))
|
||||
super.onBackPressed();
|
||||
}
|
||||
@@ -95,6 +95,15 @@ public class MainActivity extends BaseActivity {
|
||||
moveToState(initialState);
|
||||
}
|
||||
updateActionBar();
|
||||
final int actionBarId = getResources().getIdentifier("action_bar", "id", getPackageName());
|
||||
if (actionBarId != 0 && findViewById(actionBarId) != null) {
|
||||
findViewById(actionBarId).setOnTouchListener((v, e) -> {
|
||||
try {
|
||||
((TunnelListFragment) getSupportFragmentManager().getFragments().get(0)).collapseActionMenu();
|
||||
} catch (final ClassCastException ignored) { }
|
||||
return false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -131,7 +140,6 @@ public class MainActivity extends BaseActivity {
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onSelectedTunnelChanged(final Tunnel oldTunnel, final Tunnel newTunnel) {
|
||||
moveToState(newTunnel != null ? State.DETAIL : State.LIST);
|
||||
|
||||
@@ -21,7 +21,6 @@ import android.view.MenuItem;
|
||||
import com.wireguard.android.Application;
|
||||
import com.wireguard.android.R;
|
||||
import com.wireguard.android.backend.WgQuickBackend;
|
||||
import com.wireguard.android.util.Topic;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -33,7 +32,7 @@ import java.util.Map;
|
||||
* Interface for changing application-global persistent settings.
|
||||
*/
|
||||
|
||||
public class SettingsActivity extends AppCompatActivity implements Topic.Subscriber {
|
||||
public class SettingsActivity extends ThemeChangeAwareActivity {
|
||||
private final Map<Integer, PermissionRequestCallback> permissionRequestCallbacks = new HashMap<>();
|
||||
private int permissionRequestCounter;
|
||||
|
||||
@@ -59,7 +58,6 @@ public class SettingsActivity extends AppCompatActivity implements Topic.Subscri
|
||||
@Override
|
||||
protected void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
subscribeTopics();
|
||||
if (getSupportFragmentManager().findFragmentById(android.R.id.content) == null) {
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
.add(android.R.id.content, new SettingsFragment())
|
||||
@@ -67,12 +65,6 @@ public class SettingsActivity extends AppCompatActivity implements Topic.Subscri
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
unsubscribeTopics();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
@@ -99,17 +91,7 @@ public class SettingsActivity extends AppCompatActivity implements Topic.Subscri
|
||||
void done(String[] permissions, int[] grantResults);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTopicPublished(final Topic topic) {
|
||||
recreate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Topic[] getSubscription() {
|
||||
return new Topic[] { Application.getComponent().getThemeChangeTopic() };
|
||||
}
|
||||
|
||||
public static class SettingsFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
public static class SettingsFragment extends PreferenceFragmentCompat {
|
||||
@Override
|
||||
public void onCreatePreferences(final Bundle savedInstanceState, final String key) {
|
||||
addPreferencesFromResource(R.xml.preferences);
|
||||
@@ -120,26 +102,5 @@ public class SettingsActivity extends AppCompatActivity implements Topic.Subscri
|
||||
getPreferenceScreen().removePreference(pref);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences, final String key) {
|
||||
if ("dark_theme".equals(key)) {
|
||||
AppCompatDelegate.setDefaultNightMode(
|
||||
sharedPreferences.getBoolean(key, false) ? AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO);
|
||||
Application.getComponent().getThemeChangeTopic().publish(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright © 2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
package com.wireguard.android.activity;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.app.AppCompatDelegate;
|
||||
import android.util.Log;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public abstract class ThemeChangeAwareActivity extends AppCompatActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
private static final String TAG = "WireGuard/" + ThemeChangeAwareActivity.class.getSimpleName();
|
||||
|
||||
private static Resources lastResources;
|
||||
private static boolean lastDarkMode;
|
||||
private static synchronized void invalidateDrawableCache(final Resources resources, final boolean darkMode) {
|
||||
if (resources == lastResources && darkMode == lastDarkMode)
|
||||
return;
|
||||
|
||||
try {
|
||||
Field f;
|
||||
Object o = resources;
|
||||
try {
|
||||
f = o.getClass().getDeclaredField("mResourcesImpl");
|
||||
f.setAccessible(true);
|
||||
o = f.get(o);
|
||||
} catch (final Exception ignored) { }
|
||||
f = o.getClass().getDeclaredField("mDrawableCache");
|
||||
f.setAccessible(true);
|
||||
o = f.get(o);
|
||||
try {
|
||||
o.getClass().getMethod("onConfigurationChange", int.class).invoke(o, -1);
|
||||
} catch (final Exception ignored) {
|
||||
o.getClass().getMethod("clear").invoke(o);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
Log.e(TAG, "Failed to flush drawable cache", e);
|
||||
}
|
||||
|
||||
lastResources = resources;
|
||||
lastDarkMode = darkMode;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
PreferenceManager.getDefaultSharedPreferences(this).unregisterOnSharedPreferenceChangeListener(this);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences, final String key) {
|
||||
if ("dark_theme".equals(key)) {
|
||||
final boolean darkMode = sharedPreferences.getBoolean(key, false);
|
||||
AppCompatDelegate.setDefaultNightMode(
|
||||
sharedPreferences.getBoolean(key, false) ?
|
||||
AppCompatDelegate.MODE_NIGHT_YES :
|
||||
AppCompatDelegate.MODE_NIGHT_NO);
|
||||
invalidateDrawableCache(getResources(), darkMode);
|
||||
recreate();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -229,6 +229,12 @@ public class TunnelListFragment extends BaseFragment {
|
||||
binding.createMenu.collapse();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
binding.createMenu.collapse();
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSelectedTunnelChanged(final Tunnel oldTunnel, final Tunnel newTunnel) {
|
||||
// Do nothing.
|
||||
|
||||
@@ -64,7 +64,7 @@ public class LogExporterPreference extends Preference {
|
||||
|
||||
try {
|
||||
final Process process = Runtime.getRuntime().exec(new String[]{
|
||||
"logcat", "-b", "all", "-d", "-v", "threadtime", "--pid", Integer.toString(android.os.Process.myPid()), "-f", file.getAbsolutePath(), "*:V"});
|
||||
"logcat", "-b", "all", "-d", "-v", "threadtime", "-f", file.getAbsolutePath(), "*:V"});
|
||||
if (process.waitFor() != 0) {
|
||||
try (final BufferedReader reader = new BufferedReader(new InputStreamReader(process.getErrorStream()))) {
|
||||
final StringBuilder errors = new StringBuilder();
|
||||
|
||||
@@ -26,7 +26,7 @@ import com.wireguard.android.util.ToolsInstaller;
|
||||
public class ToolsInstallerPreference extends Preference {
|
||||
private final AsyncWorker asyncWorker;
|
||||
private final ToolsInstaller toolsInstaller;
|
||||
private State state = State.INITIAL;
|
||||
private State state;
|
||||
|
||||
@SuppressWarnings({"SameParameterValue", "WeakerAccess"})
|
||||
public ToolsInstallerPreference(final Context context, final AttributeSet attrs) {
|
||||
@@ -34,6 +34,7 @@ public class ToolsInstallerPreference extends Preference {
|
||||
final ApplicationComponent applicationComponent = Application.getComponent();
|
||||
asyncWorker = applicationComponent.getAsyncWorker();
|
||||
toolsInstaller = applicationComponent.getToolsInstaller();
|
||||
state = initialState();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -54,12 +55,12 @@ public class ToolsInstallerPreference extends Preference {
|
||||
|
||||
private void onCheckResult(final Integer result, final Throwable throwable) {
|
||||
setState(throwable == null && result == OsConstants.EALREADY ?
|
||||
State.ALREADY : State.INITIAL);
|
||||
State.ALREADY : initialState());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onClick() {
|
||||
setState(State.WORKING);
|
||||
setState(workingState());
|
||||
asyncWorker.supplyAsync(toolsInstaller::install).whenComplete(this::onInstallResult);
|
||||
}
|
||||
|
||||
@@ -68,7 +69,7 @@ public class ToolsInstallerPreference extends Preference {
|
||||
if (throwable != null)
|
||||
nextState = State.FAILURE;
|
||||
else if (result == OsConstants.EXIT_SUCCESS)
|
||||
nextState = State.SUCCESS;
|
||||
nextState = successState();
|
||||
else if (result == OsConstants.EALREADY)
|
||||
nextState = State.ALREADY;
|
||||
else
|
||||
@@ -85,12 +86,25 @@ public class ToolsInstallerPreference extends Preference {
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
private State initialState() {
|
||||
return toolsInstaller.willInstallAsMagiskModule() ? State.INITIAL_MAGISK : State.INITIAL_SYSTEM;
|
||||
}
|
||||
private State workingState() {
|
||||
return toolsInstaller.willInstallAsMagiskModule() ? State.WORKING_MAGISK : State.WORKING_SYSTEM;
|
||||
}
|
||||
private State successState() {
|
||||
return toolsInstaller.willInstallAsMagiskModule() ? State.SUCCESS_MAGISK : State.SUCCESS_SYSTEM;
|
||||
}
|
||||
|
||||
private enum State {
|
||||
ALREADY(R.string.tools_installer_already, false),
|
||||
FAILURE(R.string.tools_installer_failure, true),
|
||||
INITIAL(R.string.tools_installer_initial, true),
|
||||
SUCCESS(R.string.tools_installer_success, false),
|
||||
WORKING(R.string.tools_installer_working, false);
|
||||
INITIAL_SYSTEM(R.string.tools_installer_initial_system, true),
|
||||
SUCCESS_SYSTEM(R.string.tools_installer_success_system, false),
|
||||
WORKING_SYSTEM(R.string.tools_installer_working_system, false),
|
||||
INITIAL_MAGISK(R.string.tools_installer_initial_magisk, true),
|
||||
SUCCESS_MAGISK(R.string.tools_installer_success_magisk, false),
|
||||
WORKING_MAGISK(R.string.tools_installer_working_magisk, false);
|
||||
|
||||
private final int messageResourceId;
|
||||
private final boolean shouldEnableView;
|
||||
|
||||
@@ -13,6 +13,7 @@ import android.util.Log;
|
||||
import com.wireguard.android.Application;
|
||||
import com.wireguard.android.Application.ApplicationContext;
|
||||
import com.wireguard.android.Application.ApplicationScope;
|
||||
import com.wireguard.android.BuildConfig;
|
||||
import com.wireguard.android.util.RootShell.NoRootException;
|
||||
|
||||
import java.io.File;
|
||||
@@ -48,6 +49,7 @@ public final class ToolsInstaller {
|
||||
private final File nativeLibraryDir;
|
||||
private final RootShell rootShell;
|
||||
private Boolean areToolsAvailable;
|
||||
private Boolean installAsMagiskModule;
|
||||
|
||||
@Inject
|
||||
public ToolsInstaller(@ApplicationContext final Context context, final RootShell rootShell) {
|
||||
@@ -114,7 +116,20 @@ public final class ToolsInstaller {
|
||||
}
|
||||
}
|
||||
|
||||
public int install() throws NoRootException {
|
||||
public boolean willInstallAsMagiskModule() {
|
||||
synchronized (lock) {
|
||||
if (installAsMagiskModule == null) {
|
||||
try {
|
||||
installAsMagiskModule = rootShell.run(null, "[ -d /sbin/.core/mirror -a -d /sbin/.core/img -a ! -f /cache/.disable_magisk ]") == OsConstants.EXIT_SUCCESS;
|
||||
} catch (final Exception ignored) {
|
||||
installAsMagiskModule = false;
|
||||
}
|
||||
}
|
||||
return installAsMagiskModule;
|
||||
}
|
||||
}
|
||||
|
||||
private int installSystem() throws NoRootException {
|
||||
if (INSTALL_DIR == null)
|
||||
return OsConstants.ENOENT;
|
||||
final StringBuilder script = new StringBuilder("set -ex; ");
|
||||
@@ -131,6 +146,31 @@ public final class ToolsInstaller {
|
||||
}
|
||||
}
|
||||
|
||||
private int installMagisk() throws NoRootException {
|
||||
final StringBuilder script = new StringBuilder("set -ex; ");
|
||||
|
||||
script.append("trap 'rm -rf /sbin/.core/img/wireguard' INT TERM EXIT; ");
|
||||
script.append(String.format("rm -rf /sbin/.core/img/wireguard/; mkdir -p /sbin/.core/img/wireguard%s; ", INSTALL_DIR));
|
||||
script.append(String.format("printf 'name=WireGuard Command Line Tools\nversion=%s\nversionCode=%s\nauthor=zx2c4\ndescription=Command line tools for WireGuard\nminMagisk=1500\n' > /sbin/.core/img/wireguard/module.prop; ", BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE));
|
||||
script.append("touch /sbin/.core/img/wireguard/auto_mount; ");
|
||||
for (final String[] names : EXECUTABLES) {
|
||||
final File destination = new File("/sbin/.core/img/wireguard" + INSTALL_DIR, names[1]);
|
||||
script.append(String.format("cp '%s' '%s'; chmod 755 '%s'; restorecon '%s' || true; ",
|
||||
new File(nativeLibraryDir, names[0]), destination, destination, destination));
|
||||
}
|
||||
script.append("trap - INT TERM EXIT;");
|
||||
|
||||
try {
|
||||
return rootShell.run(null, script.toString());
|
||||
} catch (final IOException ignored) {
|
||||
return OsConstants.EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
public int install() throws NoRootException {
|
||||
return willInstallAsMagiskModule() ? installMagisk() : installSystem();
|
||||
}
|
||||
|
||||
public int symlink() throws NoRootException {
|
||||
final StringBuilder script = new StringBuilder("set -x; ");
|
||||
for (final String[] names : EXECUTABLES) {
|
||||
|
||||
@@ -1,109 +0,0 @@
|
||||
/*
|
||||
* Copyright © 2017 John Wu <topjohnwu@gmail.com>
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
package com.wireguard.android.util;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Topic {
|
||||
|
||||
private static final int NON_INIT = 0;
|
||||
private static final int PENDING = 1;
|
||||
private static final int PUBLISHED = 2;
|
||||
|
||||
private int state = NON_INIT;
|
||||
private List<WeakReference<Subscriber>> subscribers;
|
||||
private Object[] results;
|
||||
|
||||
public Topic() {
|
||||
subscribers = new SyncArrayList<>();
|
||||
}
|
||||
|
||||
public synchronized void subscribe(final Subscriber sub) {
|
||||
subscribers.add(new WeakReference<>(sub));
|
||||
}
|
||||
|
||||
public synchronized void unsubscribe() {
|
||||
subscribers = new SyncArrayList<>();
|
||||
}
|
||||
|
||||
public synchronized void unsubscribe(final Subscriber sub) {
|
||||
List<WeakReference<Subscriber>> subs = subscribers;
|
||||
subscribers = new ArrayList<>();
|
||||
for (final WeakReference<Subscriber> subscriber : subs) {
|
||||
if (subscriber.get() != null && subscriber.get() != sub)
|
||||
subscribers.add(subscriber);
|
||||
}
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
state = NON_INIT;
|
||||
results = null;
|
||||
}
|
||||
|
||||
public boolean isPublished() {
|
||||
return state == PUBLISHED;
|
||||
}
|
||||
|
||||
public void publish() {
|
||||
publish(true);
|
||||
}
|
||||
|
||||
public void publish(boolean record, Object... results) {
|
||||
if (record)
|
||||
state = PUBLISHED;
|
||||
this.results = results;
|
||||
// Snapshot
|
||||
List<WeakReference<Subscriber>> subs = subscribers;
|
||||
for (final WeakReference<Subscriber> subscriber : subs) {
|
||||
if (subscriber != null && subscriber.get() != null)
|
||||
subscriber.get().onTopicPublished(this);
|
||||
}
|
||||
}
|
||||
|
||||
public Object[] getResults() {
|
||||
return results;
|
||||
}
|
||||
|
||||
public boolean isPending() {
|
||||
return state == PENDING;
|
||||
}
|
||||
|
||||
public void setPending() {
|
||||
state = PENDING;
|
||||
}
|
||||
|
||||
public interface Subscriber {
|
||||
default void subscribeTopics() {
|
||||
for (final Topic topic : getSubscription()) {
|
||||
if (topic.isPublished()) {
|
||||
onTopicPublished(topic);
|
||||
}
|
||||
topic.subscribe(this);
|
||||
}
|
||||
}
|
||||
default void unsubscribeTopics() {
|
||||
for (final Topic event : getSubscription()) {
|
||||
event.unsubscribe(this);
|
||||
}
|
||||
}
|
||||
void onTopicPublished(Topic topic);
|
||||
Topic[] getSubscription();
|
||||
}
|
||||
|
||||
private static class SyncArrayList<E> extends ArrayList<E> {
|
||||
@Override
|
||||
public synchronized boolean add(final E e) {
|
||||
return super.add(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
package com.wireguard.android.widget.fab;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.*;
|
||||
import android.graphics.Paint.Style;
|
||||
@@ -19,7 +18,6 @@ import android.support.annotation.*;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.widget.AppCompatImageButton;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.TypedValue;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.wireguard.android.R;
|
||||
@@ -60,12 +58,12 @@ public class FloatingActionButton extends AppCompatImageButton {
|
||||
}
|
||||
|
||||
public static int getColorFromTheme(final Context context, final int themeResource, @ColorRes final int fallback) {
|
||||
final TypedValue typedValue = new TypedValue();
|
||||
final Resources.Theme theme = context.getTheme();
|
||||
theme.resolveAttribute(themeResource, typedValue, true);
|
||||
@ColorInt final int color = typedValue.data;
|
||||
return color == 0 ? fallback : color;
|
||||
|
||||
final TypedArray a = context.obtainStyledAttributes(new int[]{themeResource});
|
||||
try {
|
||||
return a.getColor(0, ContextCompat.getColor(context, fallback));
|
||||
} finally {
|
||||
a.recycle();
|
||||
}
|
||||
}
|
||||
|
||||
void init(final Context context, final AttributeSet attributeSet) {
|
||||
@@ -222,6 +220,7 @@ public class FloatingActionButton extends AppCompatImageButton {
|
||||
|
||||
final LayerDrawable layerDrawable = new LayerDrawable(
|
||||
new Drawable[]{
|
||||
//TODO(msf); replace these pngs with programatic elevation
|
||||
getResources().getDrawable(mSize == SIZE_NORMAL ? R.drawable.fab_bg_normal : R.drawable.fab_bg_mini, null),
|
||||
createFillDrawable(strokeWidth),
|
||||
createOuterStrokeDrawable(strokeWidth),
|
||||
|
||||
@@ -14,16 +14,13 @@ import android.animation.TimeInterpolator;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.LayerDrawable;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.ColorRes;
|
||||
import android.support.annotation.Keep;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.widget.AppCompatTextView;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.ContextThemeWrapper;
|
||||
@@ -390,11 +387,6 @@ public class FloatingActionsMenu extends ViewGroup {
|
||||
return new LayoutParams(super.generateLayoutParams(p));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean checkLayoutParams(final ViewGroup.LayoutParams p) {
|
||||
return super.checkLayoutParams(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinishInflate() {
|
||||
super.onFinishInflate();
|
||||
@@ -418,7 +410,7 @@ public class FloatingActionsMenu extends ViewGroup {
|
||||
button.getTag(R.id.fab_label) != null) continue;
|
||||
|
||||
final AppCompatTextView label = new AppCompatTextView(context);
|
||||
label.setTextAppearance(getContext(), mLabelsStyle);
|
||||
label.setTextAppearance(context, mLabelsStyle);
|
||||
label.setText(button.getTitle());
|
||||
addView(label);
|
||||
|
||||
|
||||
@@ -5,5 +5,5 @@
|
||||
android:viewportWidth="24">
|
||||
<path
|
||||
android:fillColor="?android:attr/colorForeground"
|
||||
android:pathData="M19.43,12.98c0.04,-0.32 0.07,-0.64 0.07,-0.98s-0.03,-0.66 -0.07,-0.98l2.11,-1.65c0.19,-0.15 0.24,-0.42 0.12,-0.64l-2,-3.46c-0.12,-0.22 -0.39,-0.3 -0.61,-0.22l-2.49,1c-0.52,-0.4 -1.08,-0.73 -1.69,-0.98l-0.38,-2.65C14.46,2.18 14.25,2 14,2h-4c-0.25,0 -0.46,0.18 -0.49,0.42l-0.38,2.65c-0.61,0.25 -1.17,0.59 -1.69,0.98l-2.49,-1c-0.23,-0.09 -0.49,0 -0.61,0.22l-2,3.46c-0.13,0.22 -0.07,0.49 0.12,0.64l2.11,1.65c-0.04,0.32 -0.07,0.65 -0.07,0.98s0.03,0.66 0.07,0.98l-2.11,1.65c-0.19,0.15 -0.24,0.42 -0.12,0.64l2,3.46c0.12,0.22 0.39,0.3 0.61,0.22l2.49,-1c0.52,0.4 1.08,0.73 1.69,0.98l0.38,2.65c0.03,0.24 0.24,0.42 0.49,0.42h4c0.25,0 0.46,-0.18 0.49,-0.42l0.38,-2.65c0.61,-0.25 1.17,-0.59 1.69,-0.98l2.49,1c0.23,0.09 0.49,0 0.61,-0.22l2,-3.46c0.12,-0.22 0.07,-0.49 -0.12,-0.64l-2.11,-1.65zM12,15.5c-1.93,0 -3.5,-1.57 -3.5,-3.5s1.57,-3.5 3.5,-3.5 3.5,1.57 3.5,3.5 -1.57,3.5 -3.5,3.5z" />
|
||||
android:pathData="M12,8c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2zM12,10c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2zM12,16c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2z"/>
|
||||
</vector>
|
||||
|
||||
@@ -6,5 +6,6 @@
|
||||
android:alphabeticShortcut="s"
|
||||
android:icon="@drawable/ic_settings"
|
||||
android:title="@string/settings"
|
||||
app:showAsAction="never" />
|
||||
app:showAsAction="always"
|
||||
android:orderInCategory="1000" />
|
||||
</menu>
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<!-- TODO(msf): remove these 4 hard-coded colors and replace with theme colors -->
|
||||
<!-- TODO(msf): remove these 3 hard-coded colors and replace with theme colors -->
|
||||
<color name="list_item_activated">#64cfd8dc</color>
|
||||
<color name="list_item_ripple">#a0808e95</color>
|
||||
<color name="fab_label_text_color">#000000</color>
|
||||
<color name="fab_label_background_color">#bbbbbb</color>
|
||||
|
||||
<color name="accent">#BBDEFB</color>
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<!-- TODO(msf): remove these 4 hard-coded colors and replace with theme colors -->
|
||||
<!-- TODO(msf): remove these 3 hard-coded colors and replace with theme colors -->
|
||||
<color name="list_item_activated">#cfd8dc</color> <!-- Blue Grey 200 -->
|
||||
<color name="list_item_ripple">#808e95</color> <!-- Blue Grey 200 dark -->
|
||||
<color name="fab_label_text_color">#ffffff</color>
|
||||
<color name="fab_label_background_color">#444444</color>
|
||||
|
||||
<color name="accent">#2196F3</color>
|
||||
|
||||
@@ -69,10 +69,13 @@
|
||||
<string name="toggle_error">Error toggling WireGuard tunnel: %s</string>
|
||||
<string name="tools_installer_already">wg and wg-quick are already installed</string>
|
||||
<string name="tools_installer_failure">Unable to install command-line tools (no root?)</string>
|
||||
<string name="tools_installer_initial">Install optional tools for scripting into the system partition</string>
|
||||
<string name="tools_installer_success">wg and wg-quick installed into the system partition</string>
|
||||
<string name="tools_installer_initial_system">Install optional tools for scripting into the system partition</string>
|
||||
<string name="tools_installer_initial_magisk">Install optional tools for scripting as Magisk module</string>
|
||||
<string name="tools_installer_success_system">wg and wg-quick installed into the system partition</string>
|
||||
<string name="tools_installer_success_magisk">wg and wg-quick installed as a Magisk module (reboot required)</string>
|
||||
<string name="tools_installer_title">Install command line tools</string>
|
||||
<string name="tools_installer_working">Installing wg and wg-quick into the system partition</string>
|
||||
<string name="tools_installer_working_system">Installing wg and wg-quick into the system partition</string>
|
||||
<string name="tools_installer_working_magisk">Installing wg and wg-quick as a Magisk module</string>
|
||||
<string name="tunnel_create_error">Unable to create tunnel: %s</string>
|
||||
<string name="tunnel_create_success">Successfully created tunnel “%s”</string>
|
||||
<string name="tunnel_rename_error">Unable to rename tunnel: %s</string>
|
||||
|
||||
@@ -9,9 +9,8 @@
|
||||
<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
|
||||
</style>
|
||||
|
||||
<style name="fab_label" parent="android:TextAppearance.DeviceDefault.Inverse">
|
||||
<style name="fab_label" parent="TextAppearance.AppCompat.Inverse">
|
||||
<item name="android:background">@drawable/fab_label_background</item>
|
||||
<item name="android:textColor">@color/fab_label_text_color</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -29,7 +29,7 @@ GOBUILDVERSION_NEEDED := go version go$(GOBUILDVERSION) $(GOBUILDOS)/$(GOBUILDAR
|
||||
|
||||
GOBUILDVERSION_CURRENT := $(shell go version 2>/dev/null)
|
||||
ifeq ($(GOBUILDVERSION_NEEDED),$(GOBUILDVERSION_CURRENT))
|
||||
$(info Using system go)
|
||||
$(info Using system Go)
|
||||
else
|
||||
export GOROOT := $(CURDIR)/goroot
|
||||
export PATH := $(GOROOT)/bin:$(PATH)
|
||||
@@ -41,18 +41,18 @@ $(GOROOT)/bin/go:
|
||||
rm -rf "$(GOROOT)"
|
||||
mkdir -p "$(GOROOT)"
|
||||
curl "$(GOBUILDTARBALL)" | tar -C "$(GOROOT)" --strip-components=1 -xzf - || { rm -rf "$(GOROOT)"; exit 1; }
|
||||
patch -p1 -f -N -r- -d"$(GOROOT)" < goruntime-boottime-over-monotonic.diff || { rm -rf "$(GOROOT)"; exit 1; }
|
||||
patch -p1 -f -N -r- -d "$(GOROOT)" < goruntime-boottime-over-monotonic.diff || { rm -rf "$(GOROOT)"; exit 1; }
|
||||
$(DESTDIR)/libwg-go.so: $(GOROOT)/bin/go
|
||||
endif
|
||||
|
||||
$(shell test "$$(cat .gobuildversion 2>/dev/null)" = "$(GOBUILDVERSION_CURRENT)" || rm -f "$(DESTDIR)/libwg-go.so")
|
||||
|
||||
$(DESTDIR)/libwg-go.so: $(FILES) src/git.zx2c4.com/wireguard-go/api-android.go src/git.zx2c4.com/wireguard-go/tun/api-android.go src/git.zx2c4.com/wireguard-go/jni.c
|
||||
@goroot="$$(go env GOROOT)" || exit 1; patch -p1 -f -R -s --dry-run -d "$$goroot" < goruntime-boottime-over-monotonic.diff >/dev/null 2>&1 || { echo "ERROR: Your system's Go is not patched to use the suspend-aware monotonic clock. Please try again after having run: \`patch -p1 -d \"$$goroot\" < \"$(CURDIR)/goruntime-boottime-over-monotonic.diff\"\`."; exit 1; }
|
||||
find . -name '*.go' -type l -delete
|
||||
find . -type d -empty -delete
|
||||
mkdir -p $(subst ../wireguard-go/,./src/git.zx2c4.com/wireguard-go/,$(dir $(FILES)))
|
||||
$(foreach FILE,$(FILES),ln -sfrt $(subst ../wireguard-go/,./src/git.zx2c4.com/wireguard-go/,$(dir $(FILE))) $(FILE);)
|
||||
patch -p1 -f -R -s --dry-run -d"$$(go env GOROOT)" < goruntime-boottime-over-monotonic.diff
|
||||
GOPATH=$(PWD) go get -v -d git.zx2c4.com/wireguard-go
|
||||
GOPATH=$(PWD) go build -v -o $(DESTDIR)/libwg-go.so -buildmode c-shared git.zx2c4.com/wireguard-go
|
||||
go version > .gobuildversion
|
||||
|
||||
@@ -161,8 +161,8 @@ func wgGetSocketV6(tunnelHandle int32) int32 {
|
||||
}
|
||||
|
||||
//export wgVersion
|
||||
func wgVersion() string {
|
||||
return WireGuardGoVersion
|
||||
func wgVersion() *C.char {
|
||||
return C.CString(WireGuardGoVersion)
|
||||
}
|
||||
|
||||
func main() {}
|
||||
|
||||
@@ -12,7 +12,7 @@ extern int wgTurnOn(struct go_string ifname, int tun_fd, struct go_string settin
|
||||
extern void wgTurnOff(int handle);
|
||||
extern int wgGetSocketV4(int handle);
|
||||
extern int wgGetSocketV6(int handle);
|
||||
extern struct go_string wgVersion();
|
||||
extern char *wgVersion();
|
||||
|
||||
JNIEXPORT jint JNICALL Java_com_wireguard_android_backend_GoBackend_wgTurnOn(JNIEnv *env, jclass c, jstring ifname, jint tun_fd, jstring settings)
|
||||
{
|
||||
@@ -50,13 +50,10 @@ JNIEXPORT jint JNICALL Java_com_wireguard_android_backend_GoBackend_wgGetSocketV
|
||||
JNIEXPORT jstring JNICALL Java_com_wireguard_android_backend_GoBackend_wgVersion(JNIEnv *env, jclass c)
|
||||
{
|
||||
jstring ret;
|
||||
struct go_string s = wgVersion();
|
||||
char *cstr = malloc(s.n + 1);
|
||||
if (!cstr)
|
||||
char *version = wgVersion();
|
||||
if (!version)
|
||||
return NULL;
|
||||
memcpy(cstr, s.str, s.n);
|
||||
cstr[s.n] = '\0';
|
||||
ret = (*env)->NewStringUTF(env, cstr);
|
||||
free(cstr);
|
||||
ret = (*env)->NewStringUTF(env, version);
|
||||
free(version);
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user