ToolsInstallerPreference: do not check for magisk on main thread
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
0496b94aa8
commit
51fb57433b
@ -26,7 +26,7 @@ import com.wireguard.android.util.ToolsInstaller;
|
|||||||
public class ToolsInstallerPreference extends Preference {
|
public class ToolsInstallerPreference extends Preference {
|
||||||
private final AsyncWorker asyncWorker;
|
private final AsyncWorker asyncWorker;
|
||||||
private final ToolsInstaller toolsInstaller;
|
private final ToolsInstaller toolsInstaller;
|
||||||
private State state;
|
private State state = State.INITIAL;
|
||||||
|
|
||||||
@SuppressWarnings({"SameParameterValue", "WeakerAccess"})
|
@SuppressWarnings({"SameParameterValue", "WeakerAccess"})
|
||||||
public ToolsInstallerPreference(final Context context, final AttributeSet attrs) {
|
public ToolsInstallerPreference(final Context context, final AttributeSet attrs) {
|
||||||
@ -34,7 +34,6 @@ public class ToolsInstallerPreference extends Preference {
|
|||||||
final ApplicationComponent applicationComponent = Application.getComponent();
|
final ApplicationComponent applicationComponent = Application.getComponent();
|
||||||
asyncWorker = applicationComponent.getAsyncWorker();
|
asyncWorker = applicationComponent.getAsyncWorker();
|
||||||
toolsInstaller = applicationComponent.getToolsInstaller();
|
toolsInstaller = applicationComponent.getToolsInstaller();
|
||||||
state = initialState();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -87,16 +86,17 @@ public class ToolsInstallerPreference extends Preference {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private State initialState() {
|
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() {
|
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() {
|
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 {
|
private enum State {
|
||||||
|
INITIAL(R.string.tools_installer_initial, true),
|
||||||
ALREADY(R.string.tools_installer_already, false),
|
ALREADY(R.string.tools_installer_already, false),
|
||||||
FAILURE(R.string.tools_installer_failure, true),
|
FAILURE(R.string.tools_installer_failure, true),
|
||||||
INITIAL_SYSTEM(R.string.tools_installer_initial_system, true),
|
INITIAL_SYSTEM(R.string.tools_installer_initial_system, true),
|
||||||
|
@ -80,6 +80,7 @@ public final class ToolsInstaller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int areInstalled() throws NoRootException {
|
public int areInstalled() throws NoRootException {
|
||||||
|
willInstallAsMagiskModule(true);
|
||||||
if (INSTALL_DIR == null)
|
if (INSTALL_DIR == null)
|
||||||
return OsConstants.ENOENT;
|
return OsConstants.ENOENT;
|
||||||
final StringBuilder script = new StringBuilder();
|
final StringBuilder script = new StringBuilder();
|
||||||
@ -116,9 +117,11 @@ public final class ToolsInstaller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean willInstallAsMagiskModule() {
|
public boolean willInstallAsMagiskModule(boolean checkForIt) {
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
if (installAsMagiskModule == null) {
|
if (installAsMagiskModule == null) {
|
||||||
|
if (!checkForIt)
|
||||||
|
throw new RuntimeException("Expected to already know whether this is a Magisk system");
|
||||||
try {
|
try {
|
||||||
installAsMagiskModule = rootShell.run(null, "[ -d /sbin/.core/mirror -a -d /sbin/.core/img -a ! -f /cache/.disable_magisk ]") == OsConstants.EXIT_SUCCESS;
|
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) {
|
} catch (final Exception ignored) {
|
||||||
@ -168,7 +171,7 @@ public final class ToolsInstaller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int install() throws NoRootException {
|
public int install() throws NoRootException {
|
||||||
return willInstallAsMagiskModule() ? installMagisk() : installSystem();
|
return willInstallAsMagiskModule(true) ? installMagisk() : installSystem();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int symlink() throws NoRootException {
|
public int symlink() throws NoRootException {
|
||||||
|
@ -69,6 +69,7 @@
|
|||||||
<string name="toggle_error">Error toggling WireGuard tunnel: %s</string>
|
<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_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_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_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_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_system">wg and wg-quick installed into the system partition</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user