diff options
Diffstat (limited to 'ui/src/main')
3 files changed, 15 insertions, 21 deletions
diff --git a/ui/src/main/java/com/wireguard/android/preference/KernelModuleDisablerPreference.java b/ui/src/main/java/com/wireguard/android/preference/KernelModuleDisablerPreference.java index 0ea22b24..885e48b3 100644 --- a/ui/src/main/java/com/wireguard/android/preference/KernelModuleDisablerPreference.java +++ b/ui/src/main/java/com/wireguard/android/preference/KernelModuleDisablerPreference.java @@ -5,13 +5,14 @@ package com.wireguard.android.preference; +import android.annotation.SuppressLint; import android.content.Context; import android.content.Intent; -import android.os.SystemClock; import android.util.AttributeSet; import com.wireguard.android.Application; import com.wireguard.android.R; +import com.wireguard.android.activity.SettingsActivity; import com.wireguard.android.backend.Tunnel; import com.wireguard.android.backend.WgQuickBackend; import com.wireguard.util.NonNullForAll; @@ -43,26 +44,20 @@ public class KernelModuleDisablerPreference extends Preference { return getContext().getString(state.titleResourceId); } + @SuppressLint("ApplySharedPref") @Override protected void onClick() { if (state == State.DISABLED) { setState(State.ENABLING); - Application.getSharedPreferences().edit().putBoolean("disable_kernel_module", false).apply(); + Application.getSharedPreferences().edit().putBoolean("disable_kernel_module", false).commit(); } else if (state == State.ENABLED) { setState(State.DISABLING); - Application.getSharedPreferences().edit().putBoolean("disable_kernel_module", true).apply(); + Application.getSharedPreferences().edit().putBoolean("disable_kernel_module", true).commit(); } - final long start = SystemClock.elapsedRealtime(); Application.getAsyncWorker().runAsync(() -> Application.getTunnelManager().getTunnels().thenApply(observableTunnels -> { final Collection<CompletableFuture<Tunnel.State>> c = StreamSupport.stream(observableTunnels.values()).map(t -> t.setState(Tunnel.State.DOWN).toCompletableFuture()).collect(Collectors.toCollection(ArrayList::new)); return CompletableFuture.allOf(c.toArray(new CompletableFuture[0])).thenRun(() -> { - try { - Thread.sleep(Math.max(0, 1000 * 5 - (SystemClock.elapsedRealtime() - start))); - } catch (final Exception ignored) { - } - final Intent restartIntent = getContext().getPackageManager().getLaunchIntentForPackage(getContext().getPackageName()); - if (restartIntent == null) - return; + final Intent restartIntent = new Intent(getContext(), SettingsActivity.class); restartIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); restartIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Application.get().startActivity(restartIntent); @@ -83,8 +78,8 @@ public class KernelModuleDisablerPreference extends Preference { private enum State { ENABLED(R.string.module_disabler_enabled_title, R.string.module_disabler_enabled_summary, true), DISABLED(R.string.module_disabler_disabled_title, R.string.module_disabler_disabled_summary, true), - ENABLING(R.string.module_disabler_disabled_title, R.string.module_disabler_working, false), - DISABLING(R.string.module_disabler_enabled_title, R.string.module_disabler_working, false); + ENABLING(R.string.module_disabler_disabled_title, R.string.success_application_will_restart, false), + DISABLING(R.string.module_disabler_enabled_title, R.string.success_application_will_restart, false); private final boolean shouldEnableView; private final int summaryResourceId; diff --git a/ui/src/main/java/com/wireguard/android/preference/ModuleDownloaderPreference.java b/ui/src/main/java/com/wireguard/android/preference/ModuleDownloaderPreference.java index a7c24cee..8bea5f8c 100644 --- a/ui/src/main/java/com/wireguard/android/preference/ModuleDownloaderPreference.java +++ b/ui/src/main/java/com/wireguard/android/preference/ModuleDownloaderPreference.java @@ -5,6 +5,7 @@ package com.wireguard.android.preference; +import android.annotation.SuppressLint; import android.content.Context; import android.content.Intent; import android.system.OsConstants; @@ -13,6 +14,7 @@ import android.widget.Toast; import com.wireguard.android.Application; import com.wireguard.android.R; +import com.wireguard.android.activity.SettingsActivity; import com.wireguard.android.util.ErrorMessages; import com.wireguard.util.NonNullForAll; @@ -43,6 +45,7 @@ public class ModuleDownloaderPreference extends Preference { Application.getAsyncWorker().supplyAsync(Application.getModuleLoader()::download).whenComplete(this::onDownloadResult); } + @SuppressLint("ApplySharedPref") private void onDownloadResult(final Integer result, @Nullable final Throwable throwable) { if (throwable != null) { setState(State.FAILURE); @@ -51,12 +54,9 @@ public class ModuleDownloaderPreference extends Preference { setState(State.NOTFOUND); else if (result == OsConstants.EXIT_SUCCESS) { setState(State.SUCCESS); - Application.getSharedPreferences().edit().remove("disable_kernel_module").apply(); + Application.getSharedPreferences().edit().remove("disable_kernel_module").commit(); Application.getAsyncWorker().runAsync(() -> { - Thread.sleep(1000 * 5); - final Intent restartIntent = getContext().getPackageManager().getLaunchIntentForPackage(getContext().getPackageName()); - if (restartIntent == null) - return; + final Intent restartIntent = new Intent(getContext(), SettingsActivity.class); restartIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); restartIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Application.get().startActivity(restartIntent); @@ -79,7 +79,7 @@ public class ModuleDownloaderPreference extends Preference { INITIAL(R.string.module_installer_initial, true), FAILURE(R.string.module_installer_error, true), WORKING(R.string.module_installer_working, false), - SUCCESS(R.string.module_installer_success, false), + SUCCESS(R.string.success_application_will_restart, false), NOTFOUND(R.string.module_installer_not_found, false); private final int messageResourceId; diff --git a/ui/src/main/res/values/strings.xml b/ui/src/main/res/values/strings.xml index 6961c83a..e88d0d12 100644 --- a/ui/src/main/res/values/strings.xml +++ b/ui/src/main/res/values/strings.xml @@ -98,7 +98,6 @@ <string name="module_version_error">Unable to determine kernel module version</string> <string name="module_installer_not_found">No modules are available for your device</string> <string name="module_installer_initial">The experimental kernel module can improve performance</string> - <string name="module_installer_success">Success. The application will restart in 5 seconds</string> <string name="module_installer_title">Download and install kernel module</string> <string name="module_installer_working">Downloading and installing…</string> <string name="module_installer_error">Something went wrong. Please try again</string> @@ -106,7 +105,7 @@ <string name="module_disabler_disabled_summary">The experimental kernel module can improve performance</string> <string name="module_disabler_enabled_title">Disable kernel module backend</string> <string name="module_disabler_enabled_summary">The slower userspace backend may improve stability</string> - <string name="module_disabler_working">The application will restart in 5 seconds</string> + <string name="success_application_will_restart">Success. The application will now restart…</string> <string name="mtu">MTU</string> <string name="multiple_tunnels_title">Allow multiple simultaneous tunnels</string> <string name="multiple_tunnels_summary_on">Multiple tunnels may be turned on simultaneously</string> |