159 lines
5.3 KiB
Java
159 lines
5.3 KiB
Java
/*
|
|
* Copyright (C) 2023 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 android.net;
|
|
|
|
import android.content.Context;
|
|
import android.os.Build;
|
|
import android.os.RemoteException;
|
|
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.RequiresApi;
|
|
|
|
/**
|
|
* A manager class for talking to the routing coordinator service.
|
|
*
|
|
* This class should only be used by the connectivity and tethering module. This is enforced
|
|
* by the build rules. Do not change build rules to gain access to this class from elsewhere.
|
|
* @hide
|
|
*/
|
|
@RequiresApi(Build.VERSION_CODES.S)
|
|
public class RoutingCoordinatorManager {
|
|
@NonNull final Context mContext;
|
|
@NonNull final IRoutingCoordinator mService;
|
|
|
|
public RoutingCoordinatorManager(@NonNull final Context context,
|
|
@NonNull final IRoutingCoordinator service) {
|
|
mContext = context;
|
|
mService = service;
|
|
}
|
|
|
|
/**
|
|
* 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.
|
|
*
|
|
* @param netId the network to add the interface to.
|
|
* @param iface the name of the interface to add.
|
|
*
|
|
* @throws ServiceSpecificException in case of failure, with an error code corresponding to the
|
|
* unix errno.
|
|
*/
|
|
public void addInterfaceToNetwork(final int netId, final String iface) {
|
|
try {
|
|
mService.addInterfaceToNetwork(netId, iface);
|
|
} catch (RemoteException e) {
|
|
throw e.rethrowFromSystemServer();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Removes an interface from a network. The interface must be assigned to the specified network.
|
|
*
|
|
* @param netId the network to remove the interface from.
|
|
* @param iface the name of the interface to remove.
|
|
*
|
|
* @throws ServiceSpecificException in case of failure, with an error code corresponding to the
|
|
* unix errno.
|
|
*/
|
|
public void removeInterfaceFromNetwork(final int netId, final String iface) {
|
|
try {
|
|
mService.removeInterfaceFromNetwork(netId, iface);
|
|
} catch (RemoteException e) {
|
|
throw e.rethrowFromSystemServer();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Add forwarding ip rule
|
|
*
|
|
* @param fromIface interface name to add forwarding ip rule
|
|
* @param toIface interface name to add forwarding ip rule
|
|
* @throws ServiceSpecificException in case of failure, with an error code indicating the
|
|
* cause of the failure.
|
|
*/
|
|
public void addInterfaceForward(final String fromIface, final String toIface) {
|
|
try {
|
|
mService.addInterfaceForward(fromIface, toIface);
|
|
} catch (RemoteException e) {
|
|
throw e.rethrowFromSystemServer();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Remove forwarding ip rule
|
|
*
|
|
* @param fromIface interface name to remove forwarding ip rule
|
|
* @param toIface interface name to remove forwarding ip rule
|
|
* @throws ServiceSpecificException in case of failure, with an error code indicating the
|
|
* cause of the failure.
|
|
*/
|
|
public void removeInterfaceForward(final String fromIface, final String toIface) {
|
|
try {
|
|
mService.removeInterfaceForward(fromIface, toIface);
|
|
} catch (RemoteException e) {
|
|
throw e.rethrowFromSystemServer();
|
|
}
|
|
}
|
|
}
|