diff options
Diffstat (limited to 'app/src/main/java/com/wireguard/android/BootShutdownReceiver.java')
-rw-r--r-- | app/src/main/java/com/wireguard/android/BootShutdownReceiver.java | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/app/src/main/java/com/wireguard/android/BootShutdownReceiver.java b/app/src/main/java/com/wireguard/android/BootShutdownReceiver.java index f3ed3f08..fd7aa9f9 100644 --- a/app/src/main/java/com/wireguard/android/BootShutdownReceiver.java +++ b/app/src/main/java/com/wireguard/android/BootShutdownReceiver.java @@ -20,18 +20,20 @@ public class BootShutdownReceiver extends BroadcastReceiver { @Override public void onReceive(final Context context, final Intent intent) { - if (Application.getBackendType() != WgQuickBackend.class) - 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(); - } + Application.onHaveBackend(backend -> { + if (backend.getClass() != WgQuickBackend.class) + 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(); + } + }); } } |