Merge "Remove NATT keepalive from IpSecTransform" am: ef8a605c6f am: 1453310967 am: 702c455bae

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1512881

Change-Id: I53320999a962c12f7cef9fe804616e62071fce1f
This commit is contained in:
Treehugger Robot
2020-12-04 05:14:46 +00:00
committed by Automerger Merge Worker

View File

@@ -17,8 +17,6 @@ package android.net;
import static android.net.IpSecManager.INVALID_RESOURCE_ID; import static android.net.IpSecManager.INVALID_RESOURCE_ID;
import static com.android.internal.util.Preconditions.checkNotNull;
import android.annotation.IntDef; import android.annotation.IntDef;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.annotation.Nullable; import android.annotation.Nullable;
@@ -28,7 +26,6 @@ import android.annotation.SystemApi;
import android.content.Context; import android.content.Context;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.os.Binder; import android.os.Binder;
import android.os.Handler;
import android.os.IBinder; import android.os.IBinder;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.ServiceManager; import android.os.ServiceManager;
@@ -182,7 +179,6 @@ public final class IpSecTransform implements AutoCloseable {
try { try {
IIpSecService svc = getIpSecService(); IIpSecService svc = getIpSecService();
svc.deleteTransform(mResourceId); svc.deleteTransform(mResourceId);
stopNattKeepalive();
} catch (RemoteException e) { } catch (RemoteException e) {
throw e.rethrowAsRuntimeException(); throw e.rethrowAsRuntimeException();
} catch (Exception e) { } catch (Exception e) {
@@ -213,36 +209,6 @@ public final class IpSecTransform implements AutoCloseable {
private int mResourceId; private int mResourceId;
private final Context mContext; private final Context mContext;
private final CloseGuard mCloseGuard = CloseGuard.get(); private final CloseGuard mCloseGuard = CloseGuard.get();
private ConnectivityManager.PacketKeepalive mKeepalive;
private Handler mCallbackHandler;
private final ConnectivityManager.PacketKeepaliveCallback mKeepaliveCallback =
new ConnectivityManager.PacketKeepaliveCallback() {
@Override
public void onStarted() {
synchronized (this) {
mCallbackHandler.post(() -> mUserKeepaliveCallback.onStarted());
}
}
@Override
public void onStopped() {
synchronized (this) {
mKeepalive = null;
mCallbackHandler.post(() -> mUserKeepaliveCallback.onStopped());
}
}
@Override
public void onError(int error) {
synchronized (this) {
mKeepalive = null;
mCallbackHandler.post(() -> mUserKeepaliveCallback.onError(error));
}
}
};
private NattKeepaliveCallback mUserKeepaliveCallback;
/** @hide */ /** @hide */
@VisibleForTesting @VisibleForTesting
@@ -274,76 +240,6 @@ public final class IpSecTransform implements AutoCloseable {
public void onError(int error) {} public void onError(int error) {}
} }
/**
* Start a NAT-T keepalive session for the current transform.
*
* For a transform that is using UDP encapsulated IPv4, NAT-T offloading provides
* a power efficient mechanism of sending NAT-T packets at a specified interval.
*
* @param userCallback a {@link #NattKeepaliveCallback} to receive asynchronous status
* information about the requested NAT-T keepalive session.
* @param intervalSeconds the interval between NAT-T keepalives being sent. The
* the allowed range is between 20 and 3600 seconds.
* @param handler a handler on which to post callbacks when received.
*
* @hide
*/
@RequiresPermission(anyOf = {
android.Manifest.permission.MANAGE_IPSEC_TUNNELS,
android.Manifest.permission.PACKET_KEEPALIVE_OFFLOAD
})
public void startNattKeepalive(@NonNull NattKeepaliveCallback userCallback,
int intervalSeconds, @NonNull Handler handler) throws IOException {
checkNotNull(userCallback);
if (intervalSeconds < 20 || intervalSeconds > 3600) {
throw new IllegalArgumentException("Invalid NAT-T keepalive interval");
}
checkNotNull(handler);
if (mResourceId == INVALID_RESOURCE_ID) {
throw new IllegalStateException(
"Packet keepalive cannot be started for an inactive transform");
}
synchronized (mKeepaliveCallback) {
if (mKeepaliveCallback != null) {
throw new IllegalStateException("Keepalive already active");
}
mUserKeepaliveCallback = userCallback;
ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService(
Context.CONNECTIVITY_SERVICE);
mKeepalive = cm.startNattKeepalive(
mConfig.getNetwork(), intervalSeconds, mKeepaliveCallback,
NetworkUtils.numericToInetAddress(mConfig.getSourceAddress()),
4500, // FIXME urgently, we need to get the port number from the Encap socket
NetworkUtils.numericToInetAddress(mConfig.getDestinationAddress()));
mCallbackHandler = handler;
}
}
/**
* Stop an ongoing NAT-T keepalive session.
*
* Calling this API will request that an ongoing NAT-T keepalive session be terminated.
* If this API is not called when a Transform is closed, the underlying NAT-T session will
* be terminated automatically.
*
* @hide
*/
@RequiresPermission(anyOf = {
android.Manifest.permission.MANAGE_IPSEC_TUNNELS,
android.Manifest.permission.PACKET_KEEPALIVE_OFFLOAD
})
public void stopNattKeepalive() {
synchronized (mKeepaliveCallback) {
if (mKeepalive == null) {
Log.e(TAG, "No active keepalive to stop");
return;
}
mKeepalive.stop();
}
}
/** This class is used to build {@link IpSecTransform} objects. */ /** This class is used to build {@link IpSecTransform} objects. */
public static class Builder { public static class Builder {
private Context mContext; private Context mContext;