Snap for 8712302 from d1c5545015fce4cf098349a0640a7b14a53b8ea2 to tm-frc-extservices-release

Change-Id: I47c819a55cdd24d973063f67bf6161208a0fab5b
diff --git a/Android.bp b/Android.bp
index 7fcd206..4b3d558 100644
--- a/Android.bp
+++ b/Android.bp
@@ -181,7 +181,6 @@
         "framework-connectivity",
         "framework-connectivity-t.stubs.module_lib",
         "framework-tethering",
-        "android.net.ipsec.ike.stubs.module_lib",
     ],
     sdk_version: module_33_version,
     visibility: ["//visibility:private"],
@@ -209,7 +208,6 @@
         "framework-connectivity",
         "framework-connectivity-t.stubs.module_lib",
         "framework-tethering",
-        "android.net.ipsec.ike.stubs.module_lib",
     ],
     sdk_version: "module_current",
     visibility: ["//visibility:private"],
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index ad6c2b5..d616750 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -19,8 +19,8 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.android.networkstack"
   android:sharedUserId="android.uid.networkstack"
-  android:versionCode="319999900"
-  android:versionName="s_aml_319999900"
+  android:versionCode="339990000"
+  android:versionName="339990000"
   coreApp="true"
 >
     <!--- Defines the MAINLINE_NETWORK_STACK permission used by the networkstack process. -->
diff --git a/AndroidManifest_Next.xml b/AndroidManifest_Next.xml
index 244d465..ff2dcdd 100644
--- a/AndroidManifest_Next.xml
+++ b/AndroidManifest_Next.xml
@@ -17,7 +17,7 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
           package="com.android.networkstack"
           android:sharedUserId="android.uid.networkstack"
-          android:versionCode="320000000"
+          android:versionCode="330090000"
           android:versionName="T-next"
           coreApp="true">
 </manifest>
diff --git a/apishim/29/com/android/networkstack/apishim/api29/EthernetManagerShimImpl.java b/apishim/29/com/android/networkstack/apishim/api29/EthernetManagerShimImpl.java
deleted file mode 100644
index 2f5fb7d..0000000
--- a/apishim/29/com/android/networkstack/apishim/api29/EthernetManagerShimImpl.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.networkstack.apishim.api29;
-
-import android.content.Context;
-import android.os.Build;
-
-import androidx.annotation.RequiresApi;
-
-import com.android.networkstack.apishim.common.EthernetManagerShim;
-
-/**
- * Implementation of {@link EthernetManagerShim} for API 29.
- *
- * Cannot actually import EthernetManager because that only became @SystemApi in API 30.
- */
-@RequiresApi(Build.VERSION_CODES.Q)
-public class EthernetManagerShimImpl implements EthernetManagerShim {
-    /**
-     * Get a new instance of {@link EthernetManagerShim}.
-     */
-    public static EthernetManagerShim newInstance(Context context) {
-        return new EthernetManagerShimImpl();
-    }
-}
diff --git a/apishim/29/com/android/networkstack/apishim/api29/Ikev2VpnProfileBuilderShimImpl.java b/apishim/29/com/android/networkstack/apishim/api29/Ikev2VpnProfileBuilderShimImpl.java
deleted file mode 100644
index ecf3f15..0000000
--- a/apishim/29/com/android/networkstack/apishim/api29/Ikev2VpnProfileBuilderShimImpl.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.networkstack.apishim.api29;
-
-import android.os.Build;
-
-import androidx.annotation.RequiresApi;
-
-import com.android.networkstack.apishim.common.Ikev2VpnProfileBuilderShim;
-
-/**
- * Implementation of Ikev2VpnProfileBuilderShim for API 29.
-  *
- * @param <T> type of builder, typically Ikev2VpnProfile.Builder. This is necessary because at
- *            compile time, shims for older releases will not have access to this class as it
- *            debuted in SDK30. So the user of the shim has to pass it in.
- */
-// NOTE : the trick with the formal parameter only works because when this shim was introduced,
-// the stable API already contained the class that the caller needs to pass in; this won't
-// work for a class added in the latest API level.
-@RequiresApi(Build.VERSION_CODES.Q)
-public class Ikev2VpnProfileBuilderShimImpl<T> implements Ikev2VpnProfileBuilderShim<T> {
-}
diff --git a/apishim/29/com/android/networkstack/apishim/api29/Ikev2VpnProfileShimImpl.java b/apishim/29/com/android/networkstack/apishim/api29/Ikev2VpnProfileShimImpl.java
deleted file mode 100644
index 0f8dae5..0000000
--- a/apishim/29/com/android/networkstack/apishim/api29/Ikev2VpnProfileShimImpl.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.networkstack.apishim.api29;
-
-import com.android.networkstack.apishim.common.Ikev2VpnProfileShim;
-
-/**
- * Implementation of Ikev2VpnProfileShim for API 29.
- * @param <T> type of profile, typically Ikev2VpnProfile
- */
-public class Ikev2VpnProfileShimImpl<T> implements Ikev2VpnProfileShim<T> {
-}
diff --git a/apishim/30/com/android/networkstack/apishim/api30/Ikev2VpnProfileBuilderShimImpl.java b/apishim/30/com/android/networkstack/apishim/api30/Ikev2VpnProfileBuilderShimImpl.java
deleted file mode 100644
index 7c126a3..0000000
--- a/apishim/30/com/android/networkstack/apishim/api30/Ikev2VpnProfileBuilderShimImpl.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.networkstack.apishim.api30;
-
-import android.net.Ikev2VpnProfile;
-import android.net.ProxyInfo;
-import android.os.Build;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import androidx.annotation.RequiresApi;
-
-import com.android.networkstack.apishim.common.Ikev2VpnProfileBuilderShim;
-import com.android.networkstack.apishim.common.Ikev2VpnProfileShim;
-import com.android.networkstack.apishim.common.UnsupportedApiLevelException;
-
-import java.security.PrivateKey;
-import java.security.cert.X509Certificate;
-import java.util.List;
-
-/**
- * Implementation of Ikev2VpnProfileBuilderShim for API 30.
- */
-// TODO : when API29 is no longer supported, remove the type argument
-@RequiresApi(Build.VERSION_CODES.R)
-public class Ikev2VpnProfileBuilderShimImpl
-        extends com.android.networkstack.apishim.api29.Ikev2VpnProfileBuilderShimImpl<
-                Ikev2VpnProfile.Builder> {
-    protected Ikev2VpnProfile.Builder mBuilder;
-
-    protected Ikev2VpnProfileBuilderShimImpl(@Nullable String serverAddr,
-            @Nullable String identity, @Nullable Object params) {
-        if (serverAddr != null && identity != null) {
-            mBuilder = new Ikev2VpnProfile.Builder(serverAddr, identity);
-        }
-    }
-    /**
-     * Returns a new instance of this shim impl.
-     */
-    public static Ikev2VpnProfileBuilderShim<Ikev2VpnProfile.Builder> newInstance(
-            @Nullable String serverAddr, @Nullable String identity, @Nullable Object params) {
-        return new Ikev2VpnProfileBuilderShimImpl(serverAddr, identity, params);
-    }
-
-    @Override
-    public Ikev2VpnProfileBuilderShim<Ikev2VpnProfile.Builder> setAuthPsk(@NonNull byte[] psk) {
-        mBuilder.setAuthPsk(psk);
-        return this;
-    }
-
-    @Override
-    public Ikev2VpnProfileBuilderShim<Ikev2VpnProfile.Builder> setAuthUsernamePassword(
-            @NonNull String user, @NonNull String pass, @Nullable X509Certificate serverRootCa)
-            throws UnsupportedApiLevelException {
-        mBuilder.setAuthUsernamePassword(user, pass, serverRootCa);
-        return this;
-    }
-
-    @Override
-    public Ikev2VpnProfileBuilderShim<Ikev2VpnProfile.Builder> setAuthDigitalSignature(
-            @NonNull X509Certificate userCert, @NonNull PrivateKey key,
-            @Nullable X509Certificate serverRootCa) {
-        mBuilder.setAuthDigitalSignature(userCert, key, serverRootCa);
-        return this;
-    }
-
-    @Override
-    public Ikev2VpnProfileBuilderShim<Ikev2VpnProfile.Builder> setBypassable(boolean isBypassable) {
-        mBuilder.setBypassable(true);
-        return this;
-    }
-
-    @Override
-    public Ikev2VpnProfileBuilderShim<Ikev2VpnProfile.Builder> setProxy(@Nullable ProxyInfo proxy) {
-        mBuilder.setProxy(proxy);
-        return this;
-    }
-
-    @Override
-    public Ikev2VpnProfileBuilderShim<Ikev2VpnProfile.Builder> setMaxMtu(int mtu) {
-        mBuilder.setMaxMtu(mtu);
-        return this;
-    }
-
-    @Override
-    public Ikev2VpnProfileBuilderShim<Ikev2VpnProfile.Builder> setMetered(boolean isMetered) {
-        mBuilder.setMetered(isMetered);
-        return this;
-    }
-
-    @Override
-    public Ikev2VpnProfileBuilderShim<Ikev2VpnProfile.Builder> setAllowedAlgorithms(
-            @NonNull List<String> algorithmNames) {
-        mBuilder.setAllowedAlgorithms(algorithmNames);
-        return this;
-    }
-
-    @Override
-    public Ikev2VpnProfile.Builder getBuilder() {
-        return mBuilder;
-    }
-
-    @Override
-    public Ikev2VpnProfileShim build() {
-        return new Ikev2VpnProfileShimImpl(mBuilder.build());
-    }
-}
diff --git a/apishim/30/com/android/networkstack/apishim/api30/Ikev2VpnProfileShimImpl.java b/apishim/30/com/android/networkstack/apishim/api30/Ikev2VpnProfileShimImpl.java
deleted file mode 100644
index 71d68ab..0000000
--- a/apishim/30/com/android/networkstack/apishim/api30/Ikev2VpnProfileShimImpl.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.networkstack.apishim.api30;
-
-import android.net.Ikev2VpnProfile;
-
-/**
- * Implementation of Ikev2VpnProfileShim for API 30.
- */
-// TODO : when API29 is no longer supported, remove the type argument
-public class Ikev2VpnProfileShimImpl extends
-        com.android.networkstack.apishim.api29.Ikev2VpnProfileShimImpl<Ikev2VpnProfile> {
-    protected Ikev2VpnProfile mProfile;
-
-    public Ikev2VpnProfileShimImpl(Ikev2VpnProfile profile) {
-        mProfile = profile;
-    }
-
-    public Ikev2VpnProfile getProfile() {
-        return mProfile;
-    }
-}
diff --git a/apishim/31/com/android/networkstack/apishim/api31/EthernetManagerShimImpl.java b/apishim/31/com/android/networkstack/apishim/api31/EthernetManagerShimImpl.java
deleted file mode 100644
index 2c93d7c..0000000
--- a/apishim/31/com/android/networkstack/apishim/api31/EthernetManagerShimImpl.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.networkstack.apishim.api31;
-
-import static com.android.modules.utils.build.SdkLevel.isAtLeastS;
-
-import android.content.Context;
-import android.os.Build;
-
-import androidx.annotation.RequiresApi;
-
-import com.android.networkstack.apishim.common.EthernetManagerShim;
-
-/**
- * Implementation of {@link EthernetManagerShim} for API 31.
- *
- * Doesn't have any methods, but must exist because the stable shim API level is currently 31.
- * TODO: delete when the stable shim API level becomes 33.
- */
-@RequiresApi(Build.VERSION_CODES.S)
-public class EthernetManagerShimImpl
-        extends com.android.networkstack.apishim.api29.EthernetManagerShimImpl {
-    /**
-     * Get a new instance of {@link EthernetManagerShim}.
-     */
-    @RequiresApi(Build.VERSION_CODES.Q)
-    public static EthernetManagerShim newInstance(Context context) {
-        if (!isAtLeastS()) {
-            return com.android.networkstack.apishim.api29.EthernetManagerShimImpl
-                    .newInstance(context);
-        }
-        return new EthernetManagerShimImpl();
-    }
-}
diff --git a/apishim/31/com/android/networkstack/apishim/api31/Ikev2VpnProfileBuilderShimImpl.java b/apishim/31/com/android/networkstack/apishim/api31/Ikev2VpnProfileBuilderShimImpl.java
deleted file mode 100644
index de60ff3..0000000
--- a/apishim/31/com/android/networkstack/apishim/api31/Ikev2VpnProfileBuilderShimImpl.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.networkstack.apishim.api31;
-
-import android.os.Build;
-
-import androidx.annotation.Nullable;
-import androidx.annotation.RequiresApi;
-
-/**
- * Implementation of Ikev2VpnProfileBuilderShim for API 31.
- */
-@RequiresApi(Build.VERSION_CODES.S)
-public class Ikev2VpnProfileBuilderShimImpl
-        extends com.android.networkstack.apishim.api30.Ikev2VpnProfileBuilderShimImpl {
-    protected Ikev2VpnProfileBuilderShimImpl(@Nullable String serverAddr,
-            @Nullable String identity, @Nullable Object params) {
-        super(serverAddr, identity, params);
-    }
-}
diff --git a/apishim/31/com/android/networkstack/apishim/api31/Ikev2VpnProfileShimImpl.java b/apishim/31/com/android/networkstack/apishim/api31/Ikev2VpnProfileShimImpl.java
deleted file mode 100644
index 1a9e332..0000000
--- a/apishim/31/com/android/networkstack/apishim/api31/Ikev2VpnProfileShimImpl.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.networkstack.apishim.api31;
-
-import android.net.Ikev2VpnProfile;
-
-/**
- * Implementation of Ikev2VpnProfileShim for API 31.
- */
-public class Ikev2VpnProfileShimImpl extends
-        com.android.networkstack.apishim.api30.Ikev2VpnProfileShimImpl {
-    public Ikev2VpnProfileShimImpl(Ikev2VpnProfile profile) {
-        super(profile);
-    }
-}
diff --git a/apishim/33/com/android/networkstack/apishim/api33/EthernetManagerShimImpl.java b/apishim/33/com/android/networkstack/apishim/api33/EthernetManagerShimImpl.java
deleted file mode 100644
index 5bd6487..0000000
--- a/apishim/33/com/android/networkstack/apishim/api33/EthernetManagerShimImpl.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.networkstack.apishim.api33;
-
-import static com.android.modules.utils.build.SdkLevel.isAtLeastT;
-
-import android.content.Context;
-import android.net.EthernetManager;
-import android.os.Build;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.RequiresApi;
-
-import com.android.networkstack.apishim.common.EthernetManagerShim;
-
-import java.util.List;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.Executor;
-
-/**
- * Implementation of {@link EthernetManagerShim} for API 33.
- */
-@RequiresApi(Build.VERSION_CODES.TIRAMISU)
-public class EthernetManagerShimImpl
-        extends com.android.networkstack.apishim.api31.EthernetManagerShimImpl {
-
-    protected final EthernetManager mEm;
-
-    // This is needed because callers of the shim cannot use EthernetManager.InterfaceStateListener,
-    // they need to use EthernetManagerShim.InterfaceStateListener instead. But when actually
-    // registering a callback, the callback type passed to EthernetManager must be a real
-    // listener, not a shim. This map keeps track of the mapping between the two objects so that
-    // when a caller calls removeInterfaceStateListener with a shim listener, this class knows what
-    // real listener to pass to EthernetManager.
-    private final ConcurrentHashMap<InterfaceStateListener, EthernetManager.InterfaceStateListener>
-            mListeners = new ConcurrentHashMap<>();
-
-    protected EthernetManagerShimImpl(Context context) {
-        mEm = context.getSystemService(EthernetManager.class);
-    }
-
-    /**
-     * Get a new instance of {@link EthernetManagerShim}.
-     */
-    @RequiresApi(Build.VERSION_CODES.Q)
-    public static EthernetManagerShim newInstance(Context context) {
-        if (!isAtLeastT()) {
-            return com.android.networkstack.apishim.api31.EthernetManagerShimImpl
-                    .newInstance(context);
-        }
-        return new EthernetManagerShimImpl(context);
-    }
-
-    @Override
-    public void addInterfaceStateListener(@NonNull Executor executor,
-            @NonNull InterfaceStateListener listener) {
-        final EthernetManager.InterfaceStateListener wrapper = (a, b, c, d) -> {
-            listener.onInterfaceStateChanged(a, b, c, d);
-        };
-        // EthernetManager#addInterfaceStateListener will allow registering the same listener twice,
-        // but this does not seem very useful and is difficult to support with the wrapper scheme
-        // used by this shim. Don't allow it.
-        final EthernetManager.InterfaceStateListener existing =
-                mListeners.putIfAbsent(listener, wrapper);
-        if (existing != null) {
-            throw new IllegalStateException("Attempt to register duplicate listener");
-        }
-        mEm.addInterfaceStateListener(executor, wrapper);
-    }
-
-    @Override
-    public void removeInterfaceStateListener(@NonNull InterfaceStateListener listener) {
-        final EthernetManager.InterfaceStateListener wrapper = mListeners.remove(listener);
-        if (wrapper != null) {
-            mEm.removeInterfaceStateListener(wrapper);
-        }
-    }
-
-    @Override
-    // This method existed in R and S, but as @TestApi, so should not appear in the shims before T
-    // because otherwise it could be used by production code on R and S.
-    public void setIncludeTestInterfaces(boolean include) {
-        mEm.setIncludeTestInterfaces(include);
-    }
-
-    @Override
-    @NonNull
-    public List<String> getInterfaceList() {
-        return mEm.getInterfaceList();
-    }
-}
diff --git a/apishim/33/com/android/networkstack/apishim/api33/Ikev2VpnProfileBuilderShimImpl.java b/apishim/33/com/android/networkstack/apishim/api33/Ikev2VpnProfileBuilderShimImpl.java
deleted file mode 100644
index f8c92ee..0000000
--- a/apishim/33/com/android/networkstack/apishim/api33/Ikev2VpnProfileBuilderShimImpl.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.networkstack.apishim.api33;
-
-import android.net.Ikev2VpnProfile;
-import android.net.ipsec.ike.IkeTunnelConnectionParams;
-import android.os.Build;
-
-import androidx.annotation.Nullable;
-import androidx.annotation.RequiresApi;
-
-import com.android.modules.utils.build.SdkLevel;
-import com.android.networkstack.apishim.common.Ikev2VpnProfileBuilderShim;
-
-/**
- * A shim for Ikev2VpnProfile.Builder
- */
-@RequiresApi(Build.VERSION_CODES.TIRAMISU)
-public class Ikev2VpnProfileBuilderShimImpl
-        extends com.android.networkstack.apishim.api31.Ikev2VpnProfileBuilderShimImpl {
-    protected Ikev2VpnProfileBuilderShimImpl(@Nullable String serverAddr,
-            @Nullable String identity, @Nullable Object params) {
-        super(serverAddr, identity, params);
-
-        if (serverAddr == null && identity == null && params == null) {
-            throw new IllegalArgumentException(
-                    "serverAddr, identity and params should not be all null");
-        }
-        // Support building the Builder with an IkeTunnelConnectionParams from API 33.
-        if (params != null) {
-            if (!(params instanceof IkeTunnelConnectionParams)) {
-                throw new IllegalArgumentException("params should be an IkeTunnelConnectionParams");
-            }
-            mBuilder = new Ikev2VpnProfile.Builder((IkeTunnelConnectionParams) params);
-        } else {
-            mBuilder = new Ikev2VpnProfile.Builder(serverAddr, identity);
-        }
-    }
-
-    /**
-     * Returns a new instance of this shim impl.
-     */
-    @RequiresApi(Build.VERSION_CODES.R)
-    public static Ikev2VpnProfileBuilderShim<Ikev2VpnProfile.Builder> newInstance(
-            @Nullable String serverAddr, @Nullable String identity, @Nullable Object params) {
-        if (SdkLevel.isAtLeastT()) {
-            return new Ikev2VpnProfileBuilderShimImpl(serverAddr, identity, params);
-        } else {
-            return com.android.networkstack.apishim.api31.Ikev2VpnProfileBuilderShimImpl
-                    .newInstance(serverAddr, identity, params);
-        }
-    }
-
-    /**
-     * @see Ikev2VpnProfile.Builder#setRequiresInternetValidation(boolean)
-     */
-    @Override
-    public Ikev2VpnProfileBuilderShim<Ikev2VpnProfile.Builder> setRequiresInternetValidation(
-            boolean requiresInternetValidation) {
-        mBuilder.setRequiresInternetValidation(requiresInternetValidation);
-        return this;
-    }
-
-    /**
-     * @see Ikev2VpnProfile.Builder#setLocalRoutesExcluded(boolean)
-     */
-    @Override
-    public Ikev2VpnProfileBuilderShim<Ikev2VpnProfile.Builder> setLocalRoutesExcluded(
-            boolean excludeLocalRoutes) {
-        mBuilder.setLocalRoutesExcluded(excludeLocalRoutes);
-        return this;
-    }
-}
diff --git a/apishim/33/com/android/networkstack/apishim/api33/Ikev2VpnProfileShimImpl.java b/apishim/33/com/android/networkstack/apishim/api33/Ikev2VpnProfileShimImpl.java
deleted file mode 100644
index e846a64..0000000
--- a/apishim/33/com/android/networkstack/apishim/api33/Ikev2VpnProfileShimImpl.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.networkstack.apishim.api33;
-
-import android.net.Ikev2VpnProfile;
-import android.os.Build;
-
-import androidx.annotation.RequiresApi;
-
-/**
- * A shim for Ikev2VpnProfile
- */
-@RequiresApi(Build.VERSION_CODES.TIRAMISU)
-public class Ikev2VpnProfileShimImpl
-        extends com.android.networkstack.apishim.api31.Ikev2VpnProfileShimImpl {
-    public Ikev2VpnProfileShimImpl(Ikev2VpnProfile profile) {
-       super(profile);
-    }
-
-    /**
-     * @see Ikev2VpnProfile#isInternetValidationRequired()
-     */
-    @Override
-    public boolean isInternetValidationRequired() {
-        return mProfile.isInternetValidationRequired();
-    }
-
-    /**
-     * @see Ikev2VpnProfile#getIkeTunnelConnectionParams()
-     */
-    @Override
-    public Object getIkeTunnelConnectionParams() {
-        return mProfile.getIkeTunnelConnectionParams();
-    }
-}
diff --git a/apishim/34/com/android/networkstack/apishim/EthernetManagerShimImpl.java b/apishim/34/com/android/networkstack/apishim/EthernetManagerShimImpl.java
deleted file mode 100644
index e9a33a1..0000000
--- a/apishim/34/com/android/networkstack/apishim/EthernetManagerShimImpl.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.networkstack.apishim;
-
-import android.content.Context;
-import android.os.Build;
-
-import androidx.annotation.RequiresApi;
-
-import com.android.networkstack.apishim.common.EthernetManagerShim;
-
-/**
- * Implementation of {@link EthernetManagerShim} for API 34.
- */
-// TODO: when available in all active branches: @RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
-@RequiresApi(Build.VERSION_CODES.CUR_DEVELOPMENT)
-public class EthernetManagerShimImpl
-        extends com.android.networkstack.apishim.api33.EthernetManagerShimImpl {
-    protected EthernetManagerShimImpl(Context context) {
-        super(context);
-    }
-}
diff --git a/apishim/34/com/android/networkstack/apishim/Ikev2VpnProfileBuilderShimImpl.java b/apishim/34/com/android/networkstack/apishim/Ikev2VpnProfileBuilderShimImpl.java
deleted file mode 100644
index 305f469..0000000
--- a/apishim/34/com/android/networkstack/apishim/Ikev2VpnProfileBuilderShimImpl.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.networkstack.apishim;
-
-import android.os.Build;
-
-import androidx.annotation.Nullable;
-import androidx.annotation.RequiresApi;
-
-/**
- * A shim for Ikev2VpnProfile.Builder
- */
-// TODO: when available in all active branches: @RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
-@RequiresApi(Build.VERSION_CODES.CUR_DEVELOPMENT)
-public class Ikev2VpnProfileBuilderShimImpl
-        extends com.android.networkstack.apishim.api33.Ikev2VpnProfileBuilderShimImpl {
-    protected Ikev2VpnProfileBuilderShimImpl(@Nullable String serverAddr,
-            @Nullable String identity, @Nullable Object params) {
-        super(serverAddr, identity, params);
-    }
-}
diff --git a/apishim/34/com/android/networkstack/apishim/Ikev2VpnProfileShimImpl.java b/apishim/34/com/android/networkstack/apishim/Ikev2VpnProfileShimImpl.java
deleted file mode 100644
index c6c3ac9..0000000
--- a/apishim/34/com/android/networkstack/apishim/Ikev2VpnProfileShimImpl.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.networkstack.apishim;
-
-import android.net.Ikev2VpnProfile;
-import android.os.Build;
-
-import androidx.annotation.RequiresApi;
-
-/**
- * A shim for Ikev2VpnProfile
- */
-// TODO: when available in all active branches: @RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
-@RequiresApi(Build.VERSION_CODES.CUR_DEVELOPMENT)
-public class Ikev2VpnProfileShimImpl
-        extends com.android.networkstack.apishim.api33.Ikev2VpnProfileShimImpl {
-    public Ikev2VpnProfileShimImpl(Ikev2VpnProfile profile) {
-       super(profile);
-    }
-}
diff --git a/apishim/common/com/android/networkstack/apishim/common/EthernetManagerShim.java b/apishim/common/com/android/networkstack/apishim/common/EthernetManagerShim.java
deleted file mode 100644
index 02a08de..0000000
--- a/apishim/common/com/android/networkstack/apishim/common/EthernetManagerShim.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.networkstack.apishim.common;
-
-import android.net.IpConfiguration;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-
-import java.util.List;
-import java.util.concurrent.Executor;
-
-/** API shim for EthernetManager */
-public interface EthernetManagerShim {
-    int STATE_ABSENT = 0;
-    int STATE_LINK_DOWN = 1;
-    int STATE_LINK_UP = 2;
-    int ROLE_NONE = 0;
-    int ROLE_CLIENT = 1;
-    int ROLE_SERVER = 2;
-
-    /** Shim for EthernetManager#InterfaceStateListener. */
-    interface InterfaceStateListener {
-        void onInterfaceStateChanged(@NonNull String iface, int state, int role,
-                @Nullable IpConfiguration configuration);
-    }
-
-    /** Shim for EthernetManager#addInterfaceStateListener */
-    default void addInterfaceStateListener(@NonNull Executor executor,
-            @NonNull InterfaceStateListener listener) throws UnsupportedApiLevelException {
-        throw new UnsupportedApiLevelException();
-    }
-
-    /** Shim for EthernetManager#removeInterfaceStateListener */
-    default void removeInterfaceStateListener(@NonNull InterfaceStateListener listener)
-            throws UnsupportedApiLevelException {
-        throw new UnsupportedApiLevelException("Not supported until API 33");
-    }
-
-    /** Shim for EthernetManager#setIncludeTestInterfaces */
-    default void setIncludeTestInterfaces(boolean include) throws UnsupportedApiLevelException {
-        throw new UnsupportedApiLevelException("Not supported until API 30");
-    }
-
-    /** Shim for EthernetManager#getInterfaceList */
-    default List<String> getInterfaceList() throws UnsupportedApiLevelException {
-        throw new UnsupportedApiLevelException("Not supported until API 33");
-    }
-}
diff --git a/apishim/common/com/android/networkstack/apishim/common/Ikev2VpnProfileBuilderShim.java b/apishim/common/com/android/networkstack/apishim/common/Ikev2VpnProfileBuilderShim.java
deleted file mode 100644
index 0ad989e..0000000
--- a/apishim/common/com/android/networkstack/apishim/common/Ikev2VpnProfileBuilderShim.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.networkstack.apishim.common;
-
-import android.net.ProxyInfo;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-
-import java.security.PrivateKey;
-import java.security.cert.X509Certificate;
-import java.util.List;
-
-
-/**
- * A shim for Ikev2VpnProfile.Builder.
- *
- * T should extend Ikev2VpnProfile.Builder, but this can't be written here as that class is not
- * available in API29.
- * @param <T> type of builder, typically Ikev2VpnProfile.Builder
- */
-// TODO : when API29 is no longer supported, remove the type argument
-public interface Ikev2VpnProfileBuilderShim<T> {
-    /**
-     * @see Ikev2VpnProfile.Builder#setRequiresInternetValidation(boolean)
-     */
-    default Ikev2VpnProfileBuilderShim<T> setRequiresInternetValidation(
-            boolean requiresInternetValidation) throws UnsupportedApiLevelException {
-        throw new UnsupportedApiLevelException("Only supported from API 33");
-    }
-
-    /**
-     * @see Ikev2VpnProfile.Builder#setAuthPsk(byte[])
-     */
-    default Ikev2VpnProfileBuilderShim<T> setAuthPsk(@NonNull byte[] psk)
-            throws UnsupportedApiLevelException {
-        throw new UnsupportedApiLevelException("Only supported from API 30");
-    }
-
-    /**
-     * @see Ikev2VpnProfile.Builder#setAuthUsernamePassword(String, String, X509Certificate)
-     */
-    default Ikev2VpnProfileBuilderShim<T> setAuthUsernamePassword(@NonNull String user,
-            @NonNull String pass, @Nullable X509Certificate serverRootCa)
-            throws UnsupportedApiLevelException {
-        throw new UnsupportedApiLevelException("Only supported from API 30");
-    }
-
-    /**
-     * @see Ikev2VpnProfile.Builder#setAuthDigitalSignature(X509Certificate, PrivateKey,
-     *      X509Certificate)
-     */
-    default Ikev2VpnProfileBuilderShim<T> setAuthDigitalSignature(@NonNull X509Certificate userCert,
-            @NonNull PrivateKey key, @Nullable X509Certificate serverRootCa)
-            throws UnsupportedApiLevelException {
-        throw new UnsupportedApiLevelException("Only supported from API 30");
-    }
-
-    /**
-     * @see Ikev2VpnProfile.Builder#setBypassable(boolean)
-     */
-    default Ikev2VpnProfileBuilderShim<T> setBypassable(boolean isBypassable)
-            throws UnsupportedApiLevelException {
-        throw new UnsupportedApiLevelException("Only supported from API 30");
-    }
-
-    /**
-     * @see Ikev2VpnProfile.Builder#setProxy(ProxyInfo)
-     */
-    default Ikev2VpnProfileBuilderShim<T> setProxy(@Nullable ProxyInfo proxy)
-            throws UnsupportedApiLevelException {
-        throw new UnsupportedApiLevelException("Only supported from API 30");
-    }
-
-    /**
-     * @see Ikev2VpnProfile.Builder#setMaxMtu(int)
-     */
-    default Ikev2VpnProfileBuilderShim<T> setMaxMtu(int mtu) throws UnsupportedApiLevelException {
-        throw new UnsupportedApiLevelException("Only supported from API 30");
-    }
-
-    /**
-     * @see Ikev2VpnProfile.Builder#setMetered(boolean)
-     */
-    default Ikev2VpnProfileBuilderShim<T> setMetered(boolean isMetered)
-            throws UnsupportedApiLevelException {
-        throw new UnsupportedApiLevelException("Only supported from API 30");
-    }
-
-    /**
-     * @see Ikev2VpnProfile.Builder#setAllowedAlgorithms(List<String>)
-     */
-    default Ikev2VpnProfileBuilderShim<T> setAllowedAlgorithms(@NonNull List<String> algorithmNames)
-            throws UnsupportedApiLevelException {
-        throw new UnsupportedApiLevelException("Only supported from API 30");
-    }
-
-    /**
-     * @see Ikev2VpnProfile.Builder#setLocalRoutesExcluded(boolean)
-     */
-    default Ikev2VpnProfileBuilderShim<T> setLocalRoutesExcluded(boolean excludeLocalRoutes)
-            throws UnsupportedApiLevelException {
-        throw new UnsupportedApiLevelException("Only supported from API 33");
-    }
-
-    /**
-     * Get <T> type of builder, typically Ikev2VpnProfile.Builder
-     */
-    default T getBuilder() throws UnsupportedApiLevelException {
-        throw new UnsupportedApiLevelException("Only supported from API 30");
-    }
-
-    /**
-     * Build an Ikev2VpnProfileShim
-     */
-    default Ikev2VpnProfileShim build() throws UnsupportedApiLevelException {
-        throw new UnsupportedApiLevelException("Only supported from API 30");
-    }
-}
diff --git a/apishim/common/com/android/networkstack/apishim/common/Ikev2VpnProfileShim.java b/apishim/common/com/android/networkstack/apishim/common/Ikev2VpnProfileShim.java
deleted file mode 100644
index a29c5bf..0000000
--- a/apishim/common/com/android/networkstack/apishim/common/Ikev2VpnProfileShim.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.networkstack.apishim.common;
-
-/**
- * A shim for Ikev2VpnProfile.
- *
- * T should extend Ikev2VpnProfile, but this can't be written here as that class is not
- * available in API29.
- * @param <T> type of profile, typically Ikev2VpnProfile
- */
-// TODO : when API29 is no longer supported, remove the type argument
-public interface Ikev2VpnProfileShim<T> {
-    /**
-     * @see Ikev2VpnProfile#isInternetValidationRequired()
-     */
-    default boolean isInternetValidationRequired() throws UnsupportedApiLevelException {
-        throw new UnsupportedApiLevelException("Only supported from API level 33.");
-    }
-
-    /**
-     * @see Ikev2VpnProfile#getIkeTunnelConnectionParams()
-     */
-    default Object getIkeTunnelConnectionParams() throws UnsupportedApiLevelException {
-        throw new UnsupportedApiLevelException("Only supported from API level 33.");
-    }
-
-    /**
-     * Return the <T> type of profile.
-     */
-    default T getProfile() throws UnsupportedApiLevelException {
-        throw new UnsupportedApiLevelException("Only supported from API level 30.");
-    }
-}
diff --git a/common/moduleutils/src/android/net/ip/NetlinkMonitor.java b/common/moduleutils/src/android/net/ip/NetlinkMonitor.java
index 17157d8..e58b44e 100644
--- a/common/moduleutils/src/android/net/ip/NetlinkMonitor.java
+++ b/common/moduleutils/src/android/net/ip/NetlinkMonitor.java
@@ -18,6 +18,7 @@
 
 import static android.net.util.SocketUtils.makeNetlinkSocketAddress;
 import static android.system.OsConstants.AF_NETLINK;
+import static android.system.OsConstants.ENOBUFS;
 import static android.system.OsConstants.SOCK_DGRAM;
 import static android.system.OsConstants.SOCK_NONBLOCK;
 import static android.system.OsConstants.SOL_SOCKET;
@@ -101,7 +102,11 @@
         try {
             fd = Os.socket(AF_NETLINK, SOCK_DGRAM | SOCK_NONBLOCK, mFamily);
             if (mSockRcvbufSize != DEFAULT_SOCKET_RECV_BUFSIZE) {
-                Os.setsockoptInt(fd, SOL_SOCKET, SO_RCVBUF, mSockRcvbufSize);
+                try {
+                    Os.setsockoptInt(fd, SOL_SOCKET, SO_RCVBUF, mSockRcvbufSize);
+                } catch (ErrnoException e) {
+                    Log.wtf(mTag, "Failed to set SO_RCVBUF to " + mSockRcvbufSize, e);
+                }
             }
             Os.bind(fd, makeNetlinkSocketAddress(0, mBindGroups));
             NetlinkSocket.connectToKernel(fd);
@@ -147,6 +152,32 @@
         }
     }
 
+    @Override
+    protected void logError(String msg, Exception e) {
+        mLog.e(msg, e);
+    }
+
+    // Ignoring ENOBUFS may miss any important netlink messages, there are some messages which
+    // cannot be recovered by dumping current state once missed since kernel doesn't keep state
+    // for it. In addition, dumping current state will not result in any RTM_DELxxx messages, so
+    // reconstructing current state from a dump will be difficult. However, for those netlink
+    // messages don't cause any state changes, e.g. RTM_NEWLINK with current link state, maybe
+    // it's okay to ignore them, because these netlink messages won't cause any changes on the
+    // LinkProperties. Given the above trade-offs, try to ignore ENOBUFS and that's similar to
+    // what netd does today.
+    //
+    // TODO: log metrics when ENOBUFS occurs, or even force a disconnect, it will help see how
+    // often this error occurs on fields with the associated socket receive buffer size.
+    @Override
+    protected boolean handleReadError(ErrnoException e) {
+        logError("readPacket error: ", e);
+        if (e.errno == ENOBUFS) {
+            Log.wtf(mTag, "Errno: ENOBUFS");
+            return false;
+        }
+        return true;
+    }
+
     // TODO: move NetworkStackUtils to frameworks/libs/net for NetworkStackUtils#closeSocketQuietly.
     private void closeSocketQuietly(FileDescriptor fd) {
         try {
diff --git a/src/android/net/ip/IpClientLinkObserver.java b/src/android/net/ip/IpClientLinkObserver.java
index f0126e6..bebe7c9 100644
--- a/src/android/net/ip/IpClientLinkObserver.java
+++ b/src/android/net/ip/IpClientLinkObserver.java
@@ -45,6 +45,7 @@
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
 
+import com.android.internal.annotations.VisibleForTesting;
 import com.android.net.module.util.InterfaceParams;
 import com.android.net.module.util.netlink.NduseroptMessage;
 import com.android.net.module.util.netlink.NetlinkConstants;
@@ -160,7 +161,14 @@
     // This must match the interface prefix in clatd.c.
     // TODO: Revert this hack once IpClient and Nat464Xlat work in concert.
     protected static final String CLAT_PREFIX = "v4-";
-    private static final boolean DBG = false;
+    private static final boolean DBG = true;
+
+    // The default socket receive buffer size in bytes(4MB). If too many netlink messages are
+    // sent too quickly, those messages can overflow the socket receive buffer. Set a large-enough
+    // recv buffer size to avoid the ENOBUFS as much as possible.
+    @VisibleForTesting
+    static final String CONFIG_SOCKET_RECV_BUFSIZE = "ipclient_netlink_sock_recv_buf_size";
+    private static final int SOCKET_RECV_BUFSIZE = 4 * 1024 * 1024;
 
     public IpClientLinkObserver(Context context, Handler h, String iface, Callback callback,
             Configuration config, SharedLog log, IpClient.Dependencies deps) {
@@ -178,7 +186,11 @@
         mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
         mDependencies = deps;
         mNetlinkMonitor = new MyNetlinkMonitor(h, log, mTag);
-        mHandler.post(mNetlinkMonitor::start);
+        mHandler.post(() -> {
+            if (!mNetlinkMonitor.start()) {
+                Log.wtf(mTag, "Fail to start NetlinkMonitor.");
+            }
+        });
     }
 
     public void shutdown() {
@@ -207,6 +219,15 @@
                 isAtLeastT() /* default value */);
     }
 
+    private int getSocketReceiveBufferSize() {
+        final int size = mDependencies.getDeviceConfigPropertyInt(CONFIG_SOCKET_RECV_BUFSIZE,
+                SOCKET_RECV_BUFSIZE /* default value */);
+        if (size < 0) {
+            throw new IllegalArgumentException("Invalid SO_RCVBUF " + size);
+        }
+        return size;
+    }
+
     @Override
     public void onInterfaceAdded(String iface) {
         if (isNetlinkEventParsingEnabled()) return;
@@ -279,10 +300,10 @@
     }
 
     private void updateInterfaceDnsServerInfo(long lifetime, final String[] addresses) {
-        maybeLog("interfaceDnsServerInfo", Arrays.toString(addresses));
         final boolean changed = mDnsServerRepository.addServers(lifetime, addresses);
         final boolean linkState;
         if (changed) {
+            maybeLog("interfaceDnsServerInfo", Arrays.toString(addresses));
             synchronized (this) {
                 mDnsServerRepository.setDnsServersOn(mLinkProperties);
                 linkState = getInterfaceLinkStateLocked();
@@ -291,7 +312,7 @@
         }
     }
 
-    private void updateInterfaceAddress(@NonNull final LinkAddress address, boolean add) {
+    private boolean updateInterfaceAddress(@NonNull final LinkAddress address, boolean add) {
         final boolean changed;
         final boolean linkState;
         synchronized (this) {
@@ -309,9 +330,10 @@
                 mCallback.onIpv6AddressRemoved(addr);
             }
         }
+        return changed;
     }
 
-    private void updateInterfaceRoute(final RouteInfo route, boolean add) {
+    private boolean updateInterfaceRoute(final RouteInfo route, boolean add) {
         final boolean changed;
         final boolean linkState;
         synchronized (this) {
@@ -325,6 +347,7 @@
         if (changed) {
             mCallback.update(linkState);
         }
+        return changed;
     }
 
     private void updateInterfaceRemoved() {
@@ -400,11 +423,12 @@
         MyNetlinkMonitor(Handler h, SharedLog log, String tag) {
             super(h, log, tag, OsConstants.NETLINK_ROUTE,
                     !isNetlinkEventParsingEnabled()
-                    ? NetlinkConstants.RTMGRP_ND_USEROPT
-                    : (NetlinkConstants.RTMGRP_ND_USEROPT | NetlinkConstants.RTMGRP_LINK
-                            | NetlinkConstants.RTMGRP_IPV4_IFADDR
-                            | NetlinkConstants.RTMGRP_IPV6_IFADDR
-                            | NetlinkConstants.RTMGRP_IPV6_ROUTE));
+                        ? NetlinkConstants.RTMGRP_ND_USEROPT
+                        : (NetlinkConstants.RTMGRP_ND_USEROPT | NetlinkConstants.RTMGRP_LINK
+                                | NetlinkConstants.RTMGRP_IPV4_IFADDR
+                                | NetlinkConstants.RTMGRP_IPV6_IFADDR
+                                | NetlinkConstants.RTMGRP_IPV6_ROUTE),
+                    getSocketReceiveBufferSize());
 
             mHandler = h;
         }
@@ -423,6 +447,9 @@
         private int mIfindex;
 
         void setIfindex(int ifindex) {
+            if (!isRunning()) {
+                Log.wtf(mTag, "NetlinkMonitor is not running when setting interface parameter!");
+            }
             mIfindex = ifindex;
         }
 
@@ -602,12 +629,14 @@
 
             switch (msg.getHeader().nlmsg_type) {
                 case NetlinkConstants.RTM_NEWADDR:
-                    maybeLog("addressUpdated", mIfindex, la);
-                    updateInterfaceAddress(la, true /* add address */);
+                    if (updateInterfaceAddress(la, true /* add address */)) {
+                        maybeLog("addressUpdated", mIfindex, la);
+                    }
                     break;
                 case NetlinkConstants.RTM_DELADDR:
-                    maybeLog("addressRemoved", mIfindex, la);
-                    updateInterfaceAddress(la, false /* remove address */);
+                    if (updateInterfaceAddress(la, false /* remove address */)) {
+                        maybeLog("addressRemoved", mIfindex, la);
+                    }
                     break;
                 default:
                     Log.e(mTag, "Unknown rtnetlink address msg type " + msg.getHeader().nlmsg_type);
@@ -632,12 +661,14 @@
                     mInterfaceName, msg.getRtMsgHeader().type);
             switch (msg.getHeader().nlmsg_type) {
                 case NetlinkConstants.RTM_NEWROUTE:
-                    maybeLog("routeUpdated", route);
-                    updateInterfaceRoute(route, true /* add route */);
+                    if (updateInterfaceRoute(route, true /* add route */)) {
+                        maybeLog("routeUpdated", route);
+                    }
                     break;
                 case NetlinkConstants.RTM_DELROUTE:
-                    maybeLog("routeRemoved", route);
-                    updateInterfaceRoute(route, false /* remove route */);
+                    if (updateInterfaceRoute(route, false /* remove route */)) {
+                        maybeLog("routeRemoved", route);
+                    }
                     break;
                 default:
                     Log.e(mTag, "Unknown rtnetlink route msg type " + msg.getHeader().nlmsg_type);
diff --git a/tests/integration/src/android/net/ip/IpClientIntegrationTestCommon.java b/tests/integration/src/android/net/ip/IpClientIntegrationTestCommon.java
index 78d0bca..2f3987c 100644
--- a/tests/integration/src/android/net/ip/IpClientIntegrationTestCommon.java
+++ b/tests/integration/src/android/net/ip/IpClientIntegrationTestCommon.java
@@ -29,6 +29,7 @@
 import static android.net.dhcp.DhcpPacket.MIN_V6ONLY_WAIT_MS;
 import static android.net.dhcp.DhcpResultsParcelableUtil.fromStableParcelable;
 import static android.net.ip.IpClientLinkObserver.CLAT_PREFIX;
+import static android.net.ip.IpClientLinkObserver.CONFIG_SOCKET_RECV_BUFSIZE;
 import static android.net.ip.IpReachabilityMonitor.MIN_NUD_SOLICIT_NUM;
 import static android.net.ip.IpReachabilityMonitor.NUD_MCAST_RESOLICIT_NUM;
 import static android.net.ip.IpReachabilityMonitor.nudEventTypeToInt;
@@ -185,6 +186,7 @@
 
 import org.junit.After;
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TestName;
@@ -632,6 +634,11 @@
         mDependencies.setDeviceConfigProperty(DhcpClient.ARP_PROBE_MAX_MS, 20);
         mDependencies.setDeviceConfigProperty(DhcpClient.ARP_FIRST_ANNOUNCE_DELAY_MS, 10);
         mDependencies.setDeviceConfigProperty(DhcpClient.ARP_ANNOUNCE_INTERVAL_MS, 10);
+
+        // Set the initial netlink socket receive buffer size to a minimum of 10KB to ensure test
+        // cases are still working, meanwhile in order to easily overflow the receive buffer by
+        // sending as few RAs as possible for test case where it's used to verify ENOBUFS.
+        mDependencies.setDeviceConfigProperty(CONFIG_SOCKET_RECV_BUFSIZE, 10 * 1024);
     }
 
     private void awaitIpClientShutdown() throws Exception {
@@ -3784,4 +3791,47 @@
         removeTestInterface(clatIface.getFileDescriptor().getFileDescriptor());
         verify(mCb, timeout(TEST_TIMEOUT_MS)).setNeighborDiscoveryOffload(true);
     }
+
+    @Ignore("TODO: temporarily ignore tests until prebuilts are updated")
+    @Test @SignatureRequiredTest(reason = "requires mock callback object")
+    public void testNetlinkSocketReceiveENOBUFS() throws Exception {
+        if (!mIsNetlinkEventParseEnabled) return;
+
+        ProvisioningConfiguration config = new ProvisioningConfiguration.Builder()
+                .withoutIPv4()
+                .build();
+        startIpClientProvisioning(config);
+        doIpv6OnlyProvisioning();
+        HandlerUtils.waitForIdle(mIpc.getHandler(), TEST_TIMEOUT_MS);
+
+        // Block IpClient handler.
+        final CountDownLatch latch = new CountDownLatch(1);
+        mIpc.getHandler().post(() -> {
+            try {
+                latch.await(10_000L /* 10s */, TimeUnit.MILLISECONDS);
+            } catch (InterruptedException e) {
+                // do nothing
+            }
+        });
+
+        // Send large amount of RAs to overflow the netlink socket receive buffer.
+        for (int i = 0; i < 100; i++) {
+            sendBasicRouterAdvertisement(false /* waitRs */);
+        }
+
+        // Unblock the IpClient handler.
+        latch.countDown();
+        HandlerUtils.waitForIdle(mIpc.getHandler(), TEST_TIMEOUT_MS);
+
+        reset(mCb);
+
+        // Send RA with 0 router lifetime to see if IpClient can see the loss of IPv6 default route.
+        // Due to ignoring the ENOBUFS and wait until handler gets idle, IpClient should be still
+        // able to see the RA with 0 router lifetime and the IPv6 default route will be removed.
+        sendRouterAdvertisementWithZeroLifetime();
+        final ArgumentCaptor<LinkProperties> captor = ArgumentCaptor.forClass(LinkProperties.class);
+        verify(mCb, timeout(TEST_TIMEOUT_MS)).onProvisioningFailure(captor.capture());
+        final LinkProperties lp = captor.getValue();
+        assertFalse(lp.hasIpv6DefaultRoute());
+    }
 }
diff --git a/tests/unit/src/android/net/testutils/DeviceInfoUtilsTest.java b/tests/unit/src/android/net/testutils/DeviceInfoUtilsTest.java
deleted file mode 100644
index f99700a..0000000
--- a/tests/unit/src/android/net/testutils/DeviceInfoUtilsTest.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (C) 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.testutils;
-
-import static org.junit.Assert.assertEquals;
-
-import androidx.test.filters.SmallTest;
-
-import org.junit.Test;
-
-@SmallTest
-public final class DeviceInfoUtilsTest {
-    /**
-     * Verifies that version string compare logic returns expected result for various cases.
-     * Note that only major and minor number are compared.
-     */
-    @Test
-    public void testMajorMinorVersionCompare() {
-        assertEquals(0, DeviceInfoUtils.compareMajorMinorVersion("4.8.1", "4.8"));
-        assertEquals(1, DeviceInfoUtils.compareMajorMinorVersion("4.9", "4.8.1"));
-        assertEquals(1, DeviceInfoUtils.compareMajorMinorVersion("5.0", "4.8"));
-        assertEquals(1, DeviceInfoUtils.compareMajorMinorVersion("5", "4.8"));
-        assertEquals(0, DeviceInfoUtils.compareMajorMinorVersion("5", "5.0"));
-        assertEquals(1, DeviceInfoUtils.compareMajorMinorVersion("5-beta1", "4.8"));
-        assertEquals(0, DeviceInfoUtils.compareMajorMinorVersion("4.8.0.0", "4.8"));
-        assertEquals(0, DeviceInfoUtils.compareMajorMinorVersion("4.8-RC1", "4.8"));
-        assertEquals(0, DeviceInfoUtils.compareMajorMinorVersion("4.8", "4.8"));
-        assertEquals(-1, DeviceInfoUtils.compareMajorMinorVersion("3.10", "4.8.0"));
-        assertEquals(-1, DeviceInfoUtils.compareMajorMinorVersion("4.7.10.10", "4.8"));
-    }
-}