TestNetworkService: Add support for toggling carrier on tun/tap
Adds support for setting carrier to on/off for a tun/tap interface. It turns out that TUNSETCARRIER is also usable by tap interfaces, and TUNSETLINK does not work as expected. Test: atest EthernetManagerTest Change-Id: I39d70e0a65a34e7a4c4df70c53e4cc781a24a213
This commit is contained in:
@@ -32,6 +32,8 @@ interface ITestNetworkManager
|
||||
TestNetworkInterface createInterface(boolean isTun, boolean bringUp, in LinkAddress[] addrs,
|
||||
in @nullable String iface);
|
||||
|
||||
void setCarrierEnabled(in TestNetworkInterface iface, boolean enabled);
|
||||
|
||||
void setupTestNetwork(in String iface, in LinkProperties lp, in boolean isMetered,
|
||||
in int[] administratorUids, in IBinder binder);
|
||||
|
||||
|
||||
@@ -231,4 +231,23 @@ public class TestNetworkManager {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable / disable carrier on TestNetworkInterface
|
||||
*
|
||||
* Note: TUNSETCARRIER is not supported until kernel version 5.0.
|
||||
* TODO: add RequiresApi annotation.
|
||||
*
|
||||
* @param iface the interface to configure.
|
||||
* @param enabled true to turn carrier on, false to turn carrier off.
|
||||
* @hide
|
||||
*/
|
||||
@RequiresPermission(Manifest.permission.MANAGE_TEST_NETWORKS)
|
||||
public void setCarrierEnabled(@NonNull TestNetworkInterface iface, boolean enabled) {
|
||||
try {
|
||||
mService.setCarrierEnabled(iface, enabled);
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user