Merge changes I9bbff5be,I270b751d,Ibf1bd267 am: fbcd08a28d
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2624380
Change-Id: I79a7fc9ddcb32e19361b9646480f6fda645f8660
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/service/src/com/android/server/connectivity/ClatCoordinator.java b/service/src/com/android/server/connectivity/ClatCoordinator.java
index d87f250..eb3e7ce 100644
--- a/service/src/com/android/server/connectivity/ClatCoordinator.java
+++ b/service/src/com/android/server/connectivity/ClatCoordinator.java
@@ -37,9 +37,10 @@
import android.system.ErrnoException;
import android.util.Log;
+import androidx.annotation.RequiresApi;
+
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.IndentingPrintWriter;
-import com.android.modules.utils.build.SdkLevel;
import com.android.net.module.util.BpfMap;
import com.android.net.module.util.IBpfMap;
import com.android.net.module.util.InterfaceParams;
@@ -59,8 +60,6 @@
import java.nio.ByteBuffer;
import java.util.Objects;
-import androidx.annotation.RequiresApi;
-
/**
* This coordinator is responsible for providing clat relevant functionality.
*
diff --git a/service/src/com/android/server/connectivity/KeepaliveTracker.java b/service/src/com/android/server/connectivity/KeepaliveTracker.java
index b4f74d5..fe5d0cf 100644
--- a/service/src/com/android/server/connectivity/KeepaliveTracker.java
+++ b/service/src/com/android/server/connectivity/KeepaliveTracker.java
@@ -104,19 +104,21 @@
// Allowed unprivileged keepalive slots per uid. Caller's permission will be enforced if
// the number of remaining keepalive slots is less than or equal to the threshold.
private final int mAllowedUnprivilegedSlotsForUid;
-
+ private final Dependencies mDependencies;
public KeepaliveTracker(Context context, Handler handler) {
- this(context, handler, new TcpKeepaliveController(handler));
+ this(context, handler, new TcpKeepaliveController(handler), new Dependencies());
}
@VisibleForTesting
- KeepaliveTracker(Context context, Handler handler, TcpKeepaliveController tcpController) {
+ KeepaliveTracker(Context context, Handler handler, TcpKeepaliveController tcpController,
+ Dependencies deps) {
mTcpController = tcpController;
mContext = context;
+ mDependencies = deps;
- mSupportedKeepalives = KeepaliveResourceUtil.getSupportedKeepalives(context);
+ mSupportedKeepalives = mDependencies.getSupportedKeepalives(mContext);
- final ConnectivityResources res = new ConnectivityResources(mContext);
+ final ConnectivityResources res = mDependencies.createConnectivityResources(mContext);
mReservedPrivilegedSlots = res.get().getInteger(
R.integer.config_reservedPrivilegedKeepaliveSlots);
mAllowedUnprivilegedSlotsForUid = res.get().getInteger(
@@ -725,6 +727,7 @@
srcAddress = InetAddresses.parseNumericAddress(srcAddrString);
dstAddress = InetAddresses.parseNumericAddress(dstAddrString);
} catch (IllegalArgumentException e) {
+ Log.e(TAG, "Fail to construct address", e);
notifyErrorCallback(cb, ERROR_INVALID_IP_ADDRESS);
return null;
}
@@ -734,6 +737,7 @@
packet = NattKeepalivePacketData.nattKeepalivePacket(
srcAddress, srcPort, dstAddress, NATT_PORT);
} catch (InvalidPacketException e) {
+ Log.e(TAG, "Fail to construct keepalive packet", e);
notifyErrorCallback(cb, e.getError());
return null;
}
@@ -866,4 +870,31 @@
}
pw.decreaseIndent();
}
+
+ /**
+ * Dependencies class for testing.
+ */
+ @VisibleForTesting
+ public static class Dependencies {
+ /**
+ * Read supported keepalive count for each transport type from overlay resource. This should
+ * be used to create a local variable store of resource customization, and set as the
+ * input for {@link getSupportedKeepalivesForNetworkCapabilities}.
+ *
+ * @param context The context to read resource from.
+ * @return An array of supported keepalive count for each transport type.
+ */
+ @NonNull
+ public int[] getSupportedKeepalives(@NonNull Context context) {
+ return KeepaliveResourceUtil.getSupportedKeepalives(context);
+ }
+
+ /**
+ * Create a new {@link ConnectivityResources}.
+ */
+ @NonNull
+ public ConnectivityResources createConnectivityResources(@NonNull Context context) {
+ return new ConnectivityResources(context);
+ }
+ }
}
diff --git a/tests/unit/java/com/android/server/connectivity/AutomaticOnOffKeepaliveTrackerTest.java b/tests/unit/java/com/android/server/connectivity/AutomaticOnOffKeepaliveTrackerTest.java
index 8232658..67adcc0 100644
--- a/tests/unit/java/com/android/server/connectivity/AutomaticOnOffKeepaliveTrackerTest.java
+++ b/tests/unit/java/com/android/server/connectivity/AutomaticOnOffKeepaliveTrackerTest.java
@@ -265,7 +265,7 @@
TestKeepaliveTracker(@NonNull final Context context, @NonNull final Handler handler,
@NonNull final TcpKeepaliveController tcpController) {
- super(context, handler, tcpController);
+ super(context, handler, tcpController, new Dependencies());
}
public void setReturnedKeepaliveInfo(@NonNull final KeepaliveInfo ki) {