summaryrefslogtreecommitdiffhomepage
path: root/app/src/main/java
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
commit51fb57433b94bbf7cae5cf352e67be2d2316adcf (patch)
treeb29c2a4fca2bfea394497f9adfe6985c5dd4ed6d /app/src/main/java
parent0496b94aa8ca12db5282e4a573065909fe489126 (diff)
ToolsInstallerPreference: do not check for magisk on main thread
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src/main/java')
-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
2 files changed, 10 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 {