Allow all device types to call updateConfiguration

Usage of this API should not be limited to Automotive devices as
TvSettings also needs to update the IpConfiguration.

Test: TH
Change-Id: I838a0a8684e9f944801718a4d688666de45f42fb
This commit is contained in:
Patrick Rohr
2022-03-08 13:10:18 +01:00
parent 0f66192d88
commit 24fb1ef5b0
2 changed files with 59 additions and 34 deletions

View File

@@ -215,45 +215,34 @@ public class EthernetServiceImpl extends IEthernetManager.Stub {
"EthernetServiceImpl");
}
/**
* Validate the state of ethernet for APIs tied to network management.
*
* @param iface the ethernet interface name to operate on.
* @param methodName the name of the calling method.
*/
private void validateNetworkManagementState(@NonNull final String iface,
final @NonNull String methodName) {
Objects.requireNonNull(iface, "Pass a non-null iface.");
Objects.requireNonNull(methodName, "Pass a non-null methodName.");
// Only bypass the permission/device checks if this is a valid test interface.
if (mTracker.isValidTestInterface(iface)) {
enforceManageTestNetworksPermission();
Log.i(TAG, "Ethernet network management API used with test interface " + iface);
} else {
enforceAutomotiveDevice(methodName);
enforceNetworkManagementPermission();
}
logIfEthernetNotStarted();
}
private void validateTestCapabilities(@Nullable final NetworkCapabilities nc) {
if (null != nc && nc.hasTransport(TRANSPORT_TEST)) {
return;
// For test capabilities, only null or capabilities that include TRANSPORT_TEST are allowed.
if (nc != null && !nc.hasTransport(TRANSPORT_TEST)) {
throw new IllegalArgumentException(
"Updates to test interfaces must have NetworkCapabilities.TRANSPORT_TEST.");
}
throw new IllegalArgumentException(
"Updates to test interfaces must have NetworkCapabilities.TRANSPORT_TEST.");
}
@Override
public void updateConfiguration(@NonNull final String iface,
@NonNull final EthernetNetworkUpdateRequest request,
@Nullable final IEthernetNetworkManagementListener listener) {
validateNetworkManagementState(iface, "updateConfiguration()");
Objects.requireNonNull(iface);
Objects.requireNonNull(request);
// TODO: rename to throwIfEthernetNotStarted.
logIfEthernetNotStarted();
if (mTracker.isValidTestInterface(iface)) {
enforceManageTestNetworksPermission();
validateTestCapabilities(request.getNetworkCapabilities());
// TODO: use NetworkCapabilities#restrictCapabilitiesForTestNetwork when available on a
// local NetworkCapabilities copy to pass to mTracker.updateConfiguration.
} else {
enforceNetworkManagementPermission();
if (request.getNetworkCapabilities() != null) {
// only automotive devices are allowed to set the NetworkCapabilities using this API
enforceAutomotiveDevice("updateConfiguration() with non-null capabilities");
}
}
// TODO: validate that iface is listed in overlay config_ethernet_interfaces
@@ -265,7 +254,17 @@ public class EthernetServiceImpl extends IEthernetManager.Stub {
public void connectNetwork(@NonNull final String iface,
@Nullable final IEthernetNetworkManagementListener listener) {
Log.i(TAG, "connectNetwork called with: iface=" + iface + ", listener=" + listener);
validateNetworkManagementState(iface, "connectNetwork()");
Objects.requireNonNull(iface);
logIfEthernetNotStarted();
if (mTracker.isValidTestInterface(iface)) {
enforceManageTestNetworksPermission();
} else {
// only automotive devices are allowed to use this API.
enforceNetworkManagementPermission();
enforceAutomotiveDevice("connectNetwork()");
}
mTracker.connectNetwork(iface, listener);
}
@@ -273,7 +272,17 @@ public class EthernetServiceImpl extends IEthernetManager.Stub {
public void disconnectNetwork(@NonNull final String iface,
@Nullable final IEthernetNetworkManagementListener listener) {
Log.i(TAG, "disconnectNetwork called with: iface=" + iface + ", listener=" + listener);
validateNetworkManagementState(iface, "disconnectNetwork()");
Objects.requireNonNull(iface);
logIfEthernetNotStarted();
if (mTracker.isValidTestInterface(iface)) {
enforceManageTestNetworksPermission();
} else {
// only automotive devices are allowed to use this API.
enforceNetworkManagementPermission();
enforceAutomotiveDevice("disconnectNetwork()");
}
mTracker.disconnectNetwork(iface, listener);
}
}