diff options
Diffstat (limited to 'ui/src/main/java')
-rw-r--r-- | ui/src/main/java/com/wireguard/android/preference/KernelModuleDisablerPreference.java | 21 | ||||
-rw-r--r-- | ui/src/main/java/com/wireguard/android/preference/ModuleDownloaderPreference.java | 12 |
2 files changed, 14 insertions, 19 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; |