VersionPreference: account for checking state and move away from tools installer
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
ca7f4e5be9
commit
7b59353910
@ -67,6 +67,8 @@ public class Application extends android.app.Application {
|
|||||||
ToolsInstaller getToolsInstaller();
|
ToolsInstaller getToolsInstaller();
|
||||||
|
|
||||||
TunnelManager getTunnelManager();
|
TunnelManager getTunnelManager();
|
||||||
|
|
||||||
|
RootShell getRootShell();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Qualifier
|
@Qualifier
|
||||||
|
@ -16,6 +16,14 @@ import com.wireguard.android.BuildConfig;
|
|||||||
import com.wireguard.android.R;
|
import com.wireguard.android.R;
|
||||||
import com.wireguard.android.backend.GoBackend;
|
import com.wireguard.android.backend.GoBackend;
|
||||||
import com.wireguard.android.backend.WgQuickBackend;
|
import com.wireguard.android.backend.WgQuickBackend;
|
||||||
|
import com.wireguard.android.util.RootShell;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import java9.util.concurrent.CompletionStage;
|
||||||
|
|
||||||
public class VersionPreference extends Preference {
|
public class VersionPreference extends Preference {
|
||||||
private String versionSummary;
|
private String versionSummary;
|
||||||
@ -26,10 +34,17 @@ public class VersionPreference extends Preference {
|
|||||||
if (Application.getComponent().getBackendType() == GoBackend.class) {
|
if (Application.getComponent().getBackendType() == GoBackend.class) {
|
||||||
versionSummary = getContext().getString(R.string.version_userspace_summary, GoBackend.getVersion());
|
versionSummary = getContext().getString(R.string.version_userspace_summary, GoBackend.getVersion());
|
||||||
} else if (Application.getComponent().getBackendType() == WgQuickBackend.class) {
|
} else if (Application.getComponent().getBackendType() == WgQuickBackend.class) {
|
||||||
Application.getComponent().getToolsInstaller().getVersion().whenComplete((version, exception) -> {
|
versionSummary = getContext().getString(R.string.version_kernel_summary_checking);
|
||||||
|
Application.getComponent().getAsyncWorker().supplyAsync(() -> {
|
||||||
|
final List<String> output = new ArrayList<>();
|
||||||
|
if (Application.getComponent().getRootShell()
|
||||||
|
.run(output, "cat /sys/module/wireguard/version") != 0 || output.isEmpty())
|
||||||
|
throw new RuntimeException("Unable to determine kernel module version");
|
||||||
|
return output.get(0);
|
||||||
|
}).whenComplete((version, exception) -> {
|
||||||
versionSummary = exception == null
|
versionSummary = exception == null
|
||||||
? getContext().getString(R.string.version_kernel_summary, version)
|
? getContext().getString(R.string.version_kernel_summary, version)
|
||||||
: getContext().getString(R.string.version_kernel_unknown_summary);
|
: getContext().getString(R.string.version_kernel_summary_unknown);
|
||||||
notifyChanged();
|
notifyChanged();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -58,15 +58,6 @@ public final class ToolsInstaller {
|
|||||||
this.rootShell = rootShell;
|
this.rootShell = rootShell;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompletionStage<String> getVersion() {
|
|
||||||
return Application.getComponent().getAsyncWorker().supplyAsync(() -> {
|
|
||||||
final List<String> output = new ArrayList<>();
|
|
||||||
if (rootShell.run(output, "cat /sys/module/wireguard/version") != 0 || output.isEmpty())
|
|
||||||
throw new RuntimeException("Unable to determine kernel module version");
|
|
||||||
return output.get(0);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private static File getInstallDir() {
|
private static File getInstallDir() {
|
||||||
final String path = System.getenv("PATH");
|
final String path = System.getenv("PATH");
|
||||||
if (path == null)
|
if (path == null)
|
||||||
|
@ -83,7 +83,8 @@
|
|||||||
<string name="tunnel_rename_success">Successfully renamed tunnel to “%s”</string>
|
<string name="tunnel_rename_success">Successfully renamed tunnel to “%s”</string>
|
||||||
<string name="version_title">WireGuard for Android v%s"</string>
|
<string name="version_title">WireGuard for Android v%s"</string>
|
||||||
<string name="version_kernel_summary">Kernel module backend v%s</string>
|
<string name="version_kernel_summary">Kernel module backend v%s</string>
|
||||||
<string name="version_kernel_unknown_summary">Unknown kernel module version</string>
|
<string name="version_kernel_summary_checking">Checking kernel module backend version</string>
|
||||||
|
<string name="version_kernel_summary_unknown">Unknown kernel module version</string>
|
||||||
<string name="version_userspace_summary">Go userspace backend v%s</string>
|
<string name="version_userspace_summary">Go userspace backend v%s</string>
|
||||||
<string name="zip_exporter_title">Export tunnels to zip file</string>
|
<string name="zip_exporter_title">Export tunnels to zip file</string>
|
||||||
<string name="zip_export_error">Unable to export tunnels: %s</string>
|
<string name="zip_export_error">Unable to export tunnels: %s</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user