aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-06-06 00:29:44 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-06-06 00:29:44 +0200
commit41dd78d8ae8ae87a14d64c107151c76ef6223c25 (patch)
treeb29c2a4fca2bfea394497f9adfe6985c5dd4ed6d
parentbuild: Allow building release artifacts in-tree (diff)
downloadwireguard-android-41dd78d8ae8ae87a14d64c107151c76ef6223c25.tar.xz
wireguard-android-41dd78d8ae8ae87a14d64c107151c76ef6223c25.zip
ToolsInstallerPreference: do not check for magisk on main thread
-rw-r--r--app/src/main/java/com/wireguard/android/preference/ToolsInstallerPreference.java10
-rw-r--r--app/src/main/java/com/wireguard/android/util/ToolsInstaller.java7
-rw-r--r--app/src/main/res/values/strings.xml1
3 files changed, 11 insertions, 7 deletions
diff --git a/app/src/main/java/com/wireguard/android/preference/ToolsInstallerPreference.java b/app/src/main/java/com/wireguard/android/preference/ToolsInstallerPreference.java
index 4d9e0fa..0d04641 100644
--- a/app/src/main/java/com/wireguard/android/preference/ToolsInstallerPreference.java
+++ b/app/src/main/java/com/wireguard/android/preference/ToolsInstallerPreference.java
@@ -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;
+ private State state = State.INITIAL;
@SuppressWarnings({"SameParameterValue", "WeakerAccess"})
public ToolsInstallerPreference(final Context context, final AttributeSet attrs) {
@@ -34,7 +34,6 @@ public class ToolsInstallerPreference extends Preference {
final ApplicationComponent applicationComponent = Application.getComponent();
asyncWorker = applicationComponent.getAsyncWorker();
toolsInstaller = applicationComponent.getToolsInstaller();
- state = initialState();
}
@Override
@@ -87,16 +86,17 @@ public class ToolsInstallerPreference extends Preference {
}
private State initialState() {
- return toolsInstaller.willInstallAsMagiskModule() ? State.INITIAL_MAGISK : State.INITIAL_SYSTEM;
+ return toolsInstaller.willInstallAsMagiskModule(false) ? State.INITIAL_MAGISK : State.INITIAL_SYSTEM;
}
private State workingState() {
- return toolsInstaller.willInstallAsMagiskModule() ? State.WORKING_MAGISK : State.WORKING_SYSTEM;
+ return toolsInstaller.willInstallAsMagiskModule(false) ? State.WORKING_MAGISK : State.WORKING_SYSTEM;
}
private State successState() {
- return toolsInstaller.willInstallAsMagiskModule() ? State.SUCCESS_MAGISK : State.SUCCESS_SYSTEM;
+ return toolsInstaller.willInstallAsMagiskModule(false) ? State.SUCCESS_MAGISK : State.SUCCESS_SYSTEM;
}
private enum State {
+ INITIAL(R.string.tools_installer_initial, true),
ALREADY(R.string.tools_installer_already, false),
FAILURE(R.string.tools_installer_failure, true),
INITIAL_SYSTEM(R.string.tools_installer_initial_system, true),
diff --git a/app/src/main/java/com/wireguard/android/util/ToolsInstaller.java b/app/src/main/java/com/wireguard/android/util/ToolsInstaller.java
index 0ce089f..2b8280c 100644
--- a/app/src/main/java/com/wireguard/android/util/ToolsInstaller.java
+++ b/app/src/main/java/com/wireguard/android/util/ToolsInstaller.java
@@ -80,6 +80,7 @@ public final class ToolsInstaller {
}
public int areInstalled() throws NoRootException {
+ willInstallAsMagiskModule(true);
if (INSTALL_DIR == null)
return OsConstants.ENOENT;
final StringBuilder script = new StringBuilder();
@@ -116,9 +117,11 @@ public final class ToolsInstaller {
}
}
- public boolean willInstallAsMagiskModule() {
+ public boolean willInstallAsMagiskModule(boolean checkForIt) {
synchronized (lock) {
if (installAsMagiskModule == null) {
+ if (!checkForIt)
+ throw new RuntimeException("Expected to already know whether this is a Magisk system");
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) {
@@ -168,7 +171,7 @@ public final class ToolsInstaller {
}
public int install() throws NoRootException {
- return willInstallAsMagiskModule() ? installMagisk() : installSystem();
+ return willInstallAsMagiskModule(true) ? installMagisk() : installSystem();
}
public int symlink() throws NoRootException {
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 47c1e9a..a9158b3 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -69,6 +69,7 @@
<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</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>