diff options
author | Harsh Shandilya <me@msfjarvis.dev> | 2020-03-09 19:06:11 +0530 |
---|---|---|
committer | Harsh Shandilya <me@msfjarvis.dev> | 2020-03-09 19:24:27 +0530 |
commit | 7d48bef70a56d4370856eedab619b1f83ac3d0d0 (patch) | |
tree | 76fd859578e499cd3a8fd2f402652530ea36a72d /ui/src/main/java/com/wireguard/android/BootShutdownReceiver.java | |
parent | 6bc3e257f80a273d35d07099bd4ed99eb45163bf (diff) |
Rename app module to ui
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'ui/src/main/java/com/wireguard/android/BootShutdownReceiver.java')
-rw-r--r-- | ui/src/main/java/com/wireguard/android/BootShutdownReceiver.java | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/ui/src/main/java/com/wireguard/android/BootShutdownReceiver.java b/ui/src/main/java/com/wireguard/android/BootShutdownReceiver.java new file mode 100644 index 00000000..e3ffce7a --- /dev/null +++ b/ui/src/main/java/com/wireguard/android/BootShutdownReceiver.java @@ -0,0 +1,38 @@ +/* + * Copyright © 2017-2019 WireGuard LLC. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +package com.wireguard.android; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.util.Log; + +import com.wireguard.android.backend.WgQuickBackend; +import com.wireguard.android.model.TunnelManager; +import com.wireguard.android.util.ExceptionLoggers; + +public class BootShutdownReceiver extends BroadcastReceiver { + private static final String TAG = "WireGuard/" + BootShutdownReceiver.class.getSimpleName(); + + @Override + public void onReceive(final Context context, final Intent intent) { + Application.getBackendAsync().thenAccept(backend -> { + if (!(backend instanceof WgQuickBackend)) + return; + final String action = intent.getAction(); + if (action == null) + return; + final TunnelManager tunnelManager = Application.getTunnelManager(); + if (Intent.ACTION_BOOT_COMPLETED.equals(action)) { + Log.i(TAG, "Broadcast receiver restoring state (boot)"); + tunnelManager.restoreState(false).whenComplete(ExceptionLoggers.D); + } else if (Intent.ACTION_SHUTDOWN.equals(action)) { + Log.i(TAG, "Broadcast receiver saving state (shutdown)"); + tunnelManager.saveState(); + } + }); + } +} |