2018-05-02 17:29:58 +02:00
|
|
|
/*
|
|
|
|
* Copyright © 2018 Samuel Holland <samuel@sholland.org>
|
2018-05-02 21:40:01 +02:00
|
|
|
* Copyright © 2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
|
2018-05-02 17:29:58 +02:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
|
|
|
|
2018-01-01 09:06:37 +01:00
|
|
|
package com.wireguard.android;
|
|
|
|
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
import com.wireguard.android.model.TunnelManager;
|
|
|
|
import com.wireguard.android.util.ExceptionLoggers;
|
|
|
|
|
|
|
|
public class BootShutdownReceiver extends BroadcastReceiver {
|
2018-01-08 20:29:51 +01:00
|
|
|
private static final String TAG = "WireGuard/" + BootShutdownReceiver.class.getSimpleName();
|
2018-01-01 09:06:37 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onReceive(final Context context, final Intent intent) {
|
|
|
|
final String action = intent.getAction();
|
|
|
|
if (action == null)
|
|
|
|
return;
|
|
|
|
final TunnelManager tunnelManager = Application.getComponent().getTunnelManager();
|
|
|
|
if (Intent.ACTION_BOOT_COMPLETED.equals(action)) {
|
2018-01-09 16:37:49 +01:00
|
|
|
Log.i(TAG, "Broadcast receiver restoring state (boot)");
|
2018-01-01 09:06:37 +01:00
|
|
|
tunnelManager.restoreState().whenComplete(ExceptionLoggers.D);
|
|
|
|
} else if (Intent.ACTION_SHUTDOWN.equals(action)) {
|
2018-01-09 16:37:49 +01:00
|
|
|
Log.i(TAG, "Broadcast receiver saving state (shutdown)");
|
2018-01-08 04:52:14 +01:00
|
|
|
tunnelManager.saveState();
|
2018-01-01 09:06:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|