From 8f8e59abf7c6534e351582293fc665a1ee307303 Mon Sep 17 00:00:00 2001 From: Lorenzo Colitti Date: Wed, 6 Aug 2025 15:21:50 +0900 Subject: [PATCH] Make callers of RoutingCoordinatorService pass in RouteInfoParcel RoutingCoordinatorService's {add,remove,update}Route methods all end up calling netd's *RouteParcel methods. Make callers explicitly generate and pass in the parcel to the manager class instead of having them pass in a RouteInfo and having the service class convert the RouteInfo to a parcel. Also remove the {add,remove,update}Route methods from RoutingCoordinatorManager since they are unused. This is a no-op refactor that simplifies upcoming changes. RoutingCoordinator is not a stable interface and is not used across the platform/mainline boundary, so there are no version skew considerations. Bug: 394308861 Test: atest ConnectivityCoverageTests Flag: EXEMPT no-op refactor Change-Id: Iedf4c9bc28c3fc8c289db421857acddc8c694990 --- .../android/server/ConnectivityService.java | 13 +++-- staticlibs/Android.bp | 3 ++ .../net/module/util/IRoutingCoordinator.aidl | 8 +-- .../util/RoutingCoordinatorManager.java | 49 ------------------- .../util/RoutingCoordinatorService.java | 17 +++---- 5 files changed, 24 insertions(+), 66 deletions(-) diff --git a/service/src/com/android/server/ConnectivityService.java b/service/src/com/android/server/ConnectivityService.java index ed74289c61..553f1d1368 100644 --- a/service/src/com/android/server/ConnectivityService.java +++ b/service/src/com/android/server/ConnectivityService.java @@ -360,6 +360,7 @@ import com.android.net.module.util.LinkPropertiesUtils; import com.android.net.module.util.LinkPropertiesUtils.CompareOrUpdateResult; import com.android.net.module.util.LinkPropertiesUtils.CompareResult; import com.android.net.module.util.LocationPermissionChecker; +import com.android.net.module.util.NetdUtils; import com.android.net.module.util.PerUidCounter; import com.android.net.module.util.PermissionUtils; import com.android.net.module.util.RoutingCoordinatorService; @@ -10594,7 +10595,8 @@ public class ConnectivityService extends IConnectivityManager.Stub if (route.hasGateway()) continue; if (VDBG || DDBG) log("Adding Route [" + route + "] to network " + netId); try { - mRoutingCoordinatorService.addRoute(netId, route); + mRoutingCoordinatorService.addRouteParcel(netId, + NetdUtils.toRouteInfoParcel(route)); } catch (Exception e) { if ((route.getDestination().getAddress() instanceof Inet4Address) || VDBG) { loge("Exception in addRoute for non-gateway: " + e); @@ -10605,7 +10607,8 @@ public class ConnectivityService extends IConnectivityManager.Stub if (!route.hasGateway()) continue; if (VDBG || DDBG) log("Adding Route [" + route + "] to network " + netId); try { - mRoutingCoordinatorService.addRoute(netId, route); + mRoutingCoordinatorService.addRouteParcel(netId, + NetdUtils.toRouteInfoParcel(route)); } catch (Exception e) { if ((route.getGateway() instanceof Inet4Address) || VDBG) { loge("Exception in addRoute for gateway: " + e); @@ -10616,7 +10619,8 @@ public class ConnectivityService extends IConnectivityManager.Stub for (RouteInfo route : routeDiff.removed) { if (VDBG || DDBG) log("Removing Route [" + route + "] from network " + netId); try { - mRoutingCoordinatorService.removeRoute(netId, route); + mRoutingCoordinatorService.removeRouteParcel(netId, + NetdUtils.toRouteInfoParcel(route)); } catch (Exception e) { loge("Exception in removeRoute: " + e); } @@ -10625,7 +10629,8 @@ public class ConnectivityService extends IConnectivityManager.Stub for (RouteInfo route : routeDiff.updated) { if (VDBG || DDBG) log("Updating Route [" + route + "] from network " + netId); try { - mRoutingCoordinatorService.updateRoute(netId, route); + mRoutingCoordinatorService.updateRouteParcel(netId, + NetdUtils.toRouteInfoParcel(route)); } catch (Exception e) { loge("Exception in updateRoute: " + e); } diff --git a/staticlibs/Android.bp b/staticlibs/Android.bp index c657a74761..8849eb391e 100644 --- a/staticlibs/Android.bp +++ b/staticlibs/Android.bp @@ -618,6 +618,9 @@ aidl_interface { visibility: [ "//system/tools/aidl/build", ], + imports: [ + "netd_aidl_interface-V17", // For RouteInfoParcel. + ], } // Use a filegroup and not a library for telephony sources, as framework-annotations cannot be diff --git a/staticlibs/device/com/android/net/module/util/IRoutingCoordinator.aidl b/staticlibs/device/com/android/net/module/util/IRoutingCoordinator.aidl index 7688e6a513..4baeaf98f6 100644 --- a/staticlibs/device/com/android/net/module/util/IRoutingCoordinator.aidl +++ b/staticlibs/device/com/android/net/module/util/IRoutingCoordinator.aidl @@ -21,6 +21,7 @@ import android.net.LinkProperties; import android.net.Network; import android.net.NetworkCapabilities; import android.net.RouteInfo; +import android.net.RouteInfoParcel; import com.android.net.module.util.IIpv4PrefixRequest; @@ -30,6 +31,7 @@ import com.android.net.module.util.IIpv4PrefixRequest; // invocation to an incorrect interface" when calling the IPC. @Descriptor("value=no.jarjar.com.android.net.module.util.IRoutingCoordinator") interface IRoutingCoordinator { + /** * Add a route for specific network * @@ -38,7 +40,7 @@ interface IRoutingCoordinator { * @throws ServiceSpecificException in case of failure, with an error code indicating the * cause of the failure. */ - void addRoute(int netId, in RouteInfo route); + void addRouteParcel(int netId, in RouteInfoParcel route); /** * Remove a route for specific network @@ -48,7 +50,7 @@ interface IRoutingCoordinator { * @throws ServiceSpecificException in case of failure, with an error code indicating the * cause of the failure. */ - void removeRoute(int netId, in RouteInfo route); + void removeRouteParcel(int netId, in RouteInfoParcel route); /** * Update a route for specific network @@ -58,7 +60,7 @@ interface IRoutingCoordinator { * @throws ServiceSpecificException in case of failure, with an error code indicating the * cause of the failure. */ - void updateRoute(int netId, in RouteInfo route); + void updateRouteParcel(int netId, in RouteInfoParcel route); /** * Adds an interface to a network. The interface must not be assigned to any network, including diff --git a/staticlibs/device/com/android/net/module/util/RoutingCoordinatorManager.java b/staticlibs/device/com/android/net/module/util/RoutingCoordinatorManager.java index f5af30c6c5..5234bc1ac6 100644 --- a/staticlibs/device/com/android/net/module/util/RoutingCoordinatorManager.java +++ b/staticlibs/device/com/android/net/module/util/RoutingCoordinatorManager.java @@ -21,7 +21,6 @@ import android.net.LinkAddress; import android.net.LinkProperties; import android.net.Network; import android.net.NetworkCapabilities; -import android.net.RouteInfo; import android.os.IBinder; import android.os.RemoteException; @@ -50,54 +49,6 @@ public class RoutingCoordinatorManager { mService = IRoutingCoordinator.Stub.asInterface(binder); } - /** - * Add a route for specific network - * - * @param netId the network to add the route to - * @param route the route to add - * @throws ServiceSpecificException in case of failure, with an error code indicating the - * cause of the failure. - */ - public void addRoute(final int netId, final RouteInfo route) { - try { - mService.addRoute(netId, route); - } catch (RemoteException e) { - throw e.rethrowFromSystemServer(); - } - } - - /** - * Remove a route for specific network - * - * @param netId the network to remove the route from - * @param route the route to remove - * @throws ServiceSpecificException in case of failure, with an error code indicating the - * cause of the failure. - */ - public void removeRoute(final int netId, final RouteInfo route) { - try { - mService.removeRoute(netId, route); - } catch (RemoteException e) { - throw e.rethrowFromSystemServer(); - } - } - - /** - * Update a route for specific network - * - * @param netId the network to update the route for - * @param route parcelable with route information - * @throws ServiceSpecificException in case of failure, with an error code indicating the - * cause of the failure. - */ - public void updateRoute(final int netId, final RouteInfo route) { - try { - mService.updateRoute(netId, route); - } catch (RemoteException e) { - throw e.rethrowFromSystemServer(); - } - } - /** * Adds an interface to a network. The interface must not be assigned to any network, including * the specified network. diff --git a/staticlibs/device/com/android/net/module/util/RoutingCoordinatorService.java b/staticlibs/device/com/android/net/module/util/RoutingCoordinatorService.java index 61e830f956..1950535bf9 100644 --- a/staticlibs/device/com/android/net/module/util/RoutingCoordinatorService.java +++ b/staticlibs/device/com/android/net/module/util/RoutingCoordinatorService.java @@ -16,17 +16,14 @@ package com.android.net.module.util; -import static com.android.net.module.util.NetdUtils.toRouteInfoParcel; - import android.annotation.NonNull; import android.content.Context; import android.net.INetd; - import android.net.LinkAddress; import android.net.LinkProperties; import android.net.Network; import android.net.NetworkCapabilities; -import android.net.RouteInfo; +import android.net.RouteInfoParcel; import android.os.RemoteException; import android.os.ServiceSpecificException; import android.util.ArraySet; @@ -84,9 +81,9 @@ public class RoutingCoordinatorService extends IRoutingCoordinator.Stub { * cause of the failure. */ @Override - public void addRoute(final int netId, final RouteInfo route) + public void addRouteParcel(int netId, RouteInfoParcel route) throws ServiceSpecificException, RemoteException { - mNetd.networkAddRouteParcel(netId, toRouteInfoParcel(route)); + mNetd.networkAddRouteParcel(netId, route); } /** @@ -98,9 +95,9 @@ public class RoutingCoordinatorService extends IRoutingCoordinator.Stub { * cause of the failure. */ @Override - public void removeRoute(final int netId, final RouteInfo route) + public void removeRouteParcel(int netId, RouteInfoParcel route) throws ServiceSpecificException, RemoteException { - mNetd.networkRemoveRouteParcel(netId, toRouteInfoParcel(route)); + mNetd.networkRemoveRouteParcel(netId, route); } /** @@ -112,9 +109,9 @@ public class RoutingCoordinatorService extends IRoutingCoordinator.Stub { * cause of the failure. */ @Override - public void updateRoute(final int netId, final RouteInfo route) + public void updateRouteParcel(int netId, RouteInfoParcel route) throws ServiceSpecificException, RemoteException { - mNetd.networkUpdateRouteParcel(netId, toRouteInfoParcel(route)); + mNetd.networkUpdateRouteParcel(netId, route); } /**