API to detect which network interfaces support wake-on-lan

Add a new method in LinkProperties, isWakeOnLanEnabled() which returns
true if network interface is defined in config_wakeonlan_enabled_interfaces
string-array (config.xml)

Bug: 132705025
Test: atest LinkPropertiesTest & atest ConnectivityServiceTest
Change-Id: I3f7803aafd2f8eaf8aa18419b21339e15d4b7a0b
This commit is contained in:
Valentin Iftime
2019-09-24 13:32:13 +02:00
parent 71203fcf6f
commit 9fa3509a51
4 changed files with 97 additions and 2 deletions

View File

@@ -274,6 +274,7 @@ public class ConnectivityServiceTest {
private static final String CLAT_PREFIX = "v4-";
private static final String MOBILE_IFNAME = "test_rmnet_data0";
private static final String WIFI_IFNAME = "test_wlan0";
private static final String WIFI_WOL_IFNAME = "test_wlan_wol";
private static final String[] EMPTY_STRING_ARRAY = new String[0];
private MockContext mServiceContext;
@@ -343,6 +344,12 @@ public class ConnectivityServiceTest {
"mobile_mms,2,0,2,60000,true",
});
when(mResources.getStringArray(
com.android.internal.R.array.config_wakeonlan_supported_interfaces))
.thenReturn(new String[]{
WIFI_WOL_IFNAME,
});
mContentResolver = new MockContentResolver();
mContentResolver.addProvider(Settings.AUTHORITY, settingsProvider);
}
@@ -5947,6 +5954,24 @@ public class ConnectivityServiceTest {
assertContainsExactly(uidCaptor.getValue(), APP2_UID);
}
@Test
public void testLinkPropertiesWithWakeOnLanForActiveNetwork() throws Exception {
mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI);
LinkProperties wifiLp = new LinkProperties();
wifiLp.setInterfaceName(WIFI_WOL_IFNAME);
wifiLp.setWakeOnLanSupported(false);
// Default network switch should update ifaces.
mWiFiNetworkAgent.connect(false);
mWiFiNetworkAgent.sendLinkProperties(wifiLp);
waitForIdle();
// ConnectivityService should have changed the WakeOnLanSupported to true
wifiLp.setWakeOnLanSupported(true);
assertEquals(wifiLp, mService.getActiveLinkProperties());
}
private TestNetworkAgentWrapper establishVpn(LinkProperties lp, int establishingUid,
Set<UidRange> vpnRange) throws Exception {