diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-06-06 00:29:44 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-06-06 00:29:44 +0200 |
commit | 51fb57433b94bbf7cae5cf352e67be2d2316adcf (patch) | |
tree | b29c2a4fca2bfea394497f9adfe6985c5dd4ed6d | |
parent | 0496b94aa8ca12db5282e4a573065909fe489126 (diff) |
ToolsInstallerPreference: do not check for magisk on main thread
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
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 4d9e0fa8..0d04641c 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 0ce089fd..2b8280cc 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 47c1e9a0..a9158b37 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> |