Merge changes I9bbff5be,I270b751d,Ibf1bd267 am: fbcd08a28d am: f094ab6db5

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2624380

Change-Id: If26dd9f495f59437a4899dae37d8eccc34d02dbb
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Chiachang Wang
2023-06-19 02:31:38 +00:00
committed by Automerger Merge Worker
3 changed files with 39 additions and 9 deletions

View File

@@ -37,9 +37,10 @@ import android.os.ServiceSpecificException;
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.net.InetAddress;
import java.nio.ByteBuffer;
import java.util.Objects;
import androidx.annotation.RequiresApi;
/**
* This coordinator is responsible for providing clat relevant functionality.
*

View File

@@ -104,19 +104,21 @@ public class KeepaliveTracker {
// 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 @@ public class KeepaliveTracker {
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 @@ public class KeepaliveTracker {
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 @@ public class KeepaliveTracker {
}
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);
}
}
}

View File

@@ -265,7 +265,7 @@ public class AutomaticOnOffKeepaliveTrackerTest {
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) {