Merge "API to detect which network interfaces support wake-on-lan" am: c6a375706e am: 3429df9c8d
am: 22ba70df25
Change-Id: I706ad94dfb2645f5f66869a48390b5fcb22bbda2
This commit is contained in:
committed by
android-build-merger
commit
c53848b014
@@ -68,6 +68,7 @@ public final class LinkProperties implements Parcelable {
|
|||||||
// in the format "rmem_min,rmem_def,rmem_max,wmem_min,wmem_def,wmem_max"
|
// in the format "rmem_min,rmem_def,rmem_max,wmem_min,wmem_def,wmem_max"
|
||||||
private String mTcpBufferSizes;
|
private String mTcpBufferSizes;
|
||||||
private IpPrefix mNat64Prefix;
|
private IpPrefix mNat64Prefix;
|
||||||
|
private boolean mWakeOnLanSupported;
|
||||||
|
|
||||||
private static final int MIN_MTU = 68;
|
private static final int MIN_MTU = 68;
|
||||||
private static final int MIN_MTU_V6 = 1280;
|
private static final int MIN_MTU_V6 = 1280;
|
||||||
@@ -193,6 +194,7 @@ public final class LinkProperties implements Parcelable {
|
|||||||
setMtu(source.mMtu);
|
setMtu(source.mMtu);
|
||||||
mTcpBufferSizes = source.mTcpBufferSizes;
|
mTcpBufferSizes = source.mTcpBufferSizes;
|
||||||
mNat64Prefix = source.mNat64Prefix;
|
mNat64Prefix = source.mNat64Prefix;
|
||||||
|
mWakeOnLanSupported = source.mWakeOnLanSupported;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -852,6 +854,7 @@ public final class LinkProperties implements Parcelable {
|
|||||||
mMtu = 0;
|
mMtu = 0;
|
||||||
mTcpBufferSizes = null;
|
mTcpBufferSizes = null;
|
||||||
mNat64Prefix = null;
|
mNat64Prefix = null;
|
||||||
|
mWakeOnLanSupported = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -913,6 +916,10 @@ public final class LinkProperties implements Parcelable {
|
|||||||
resultJoiner.add("MTU:");
|
resultJoiner.add("MTU:");
|
||||||
resultJoiner.add(Integer.toString(mMtu));
|
resultJoiner.add(Integer.toString(mMtu));
|
||||||
|
|
||||||
|
if (mWakeOnLanSupported) {
|
||||||
|
resultJoiner.add("WakeOnLanSupported: true");
|
||||||
|
}
|
||||||
|
|
||||||
if (mTcpBufferSizes != null) {
|
if (mTcpBufferSizes != null) {
|
||||||
resultJoiner.add("TcpBufferSizes:");
|
resultJoiner.add("TcpBufferSizes:");
|
||||||
resultJoiner.add(mTcpBufferSizes);
|
resultJoiner.add(mTcpBufferSizes);
|
||||||
@@ -1424,6 +1431,37 @@ public final class LinkProperties implements Parcelable {
|
|||||||
return Objects.equals(mNat64Prefix, target.mNat64Prefix);
|
return Objects.equals(mNat64Prefix, target.mNat64Prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compares this {@code LinkProperties} WakeOnLan supported against the target.
|
||||||
|
*
|
||||||
|
* @param target LinkProperties to compare.
|
||||||
|
* @return {@code true} if both are identical, {@code false} otherwise.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public boolean isIdenticalWakeOnLan(LinkProperties target) {
|
||||||
|
return isWakeOnLanSupported() == target.isWakeOnLanSupported();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set whether the network interface supports WakeOnLAN
|
||||||
|
*
|
||||||
|
* @param supported WakeOnLAN supported value
|
||||||
|
*
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public void setWakeOnLanSupported(boolean supported) {
|
||||||
|
mWakeOnLanSupported = supported;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the network interface supports WakeOnLAN
|
||||||
|
*
|
||||||
|
* @return {@code true} if interface supports WakeOnLAN, {@code false} otherwise.
|
||||||
|
*/
|
||||||
|
public boolean isWakeOnLanSupported() {
|
||||||
|
return mWakeOnLanSupported;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compares this {@code LinkProperties} instance against the target
|
* Compares this {@code LinkProperties} instance against the target
|
||||||
* LinkProperties in {@code obj}. Two LinkPropertieses are equal if
|
* LinkProperties in {@code obj}. Two LinkPropertieses are equal if
|
||||||
@@ -1461,7 +1499,8 @@ public final class LinkProperties implements Parcelable {
|
|||||||
&& isIdenticalStackedLinks(target)
|
&& isIdenticalStackedLinks(target)
|
||||||
&& isIdenticalMtu(target)
|
&& isIdenticalMtu(target)
|
||||||
&& isIdenticalTcpBufferSizes(target)
|
&& isIdenticalTcpBufferSizes(target)
|
||||||
&& isIdenticalNat64Prefix(target);
|
&& isIdenticalNat64Prefix(target)
|
||||||
|
&& isIdenticalWakeOnLan(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1577,7 +1616,8 @@ public final class LinkProperties implements Parcelable {
|
|||||||
+ (mUsePrivateDns ? 57 : 0)
|
+ (mUsePrivateDns ? 57 : 0)
|
||||||
+ mPcscfs.size() * 67
|
+ mPcscfs.size() * 67
|
||||||
+ ((null == mPrivateDnsServerName) ? 0 : mPrivateDnsServerName.hashCode())
|
+ ((null == mPrivateDnsServerName) ? 0 : mPrivateDnsServerName.hashCode())
|
||||||
+ Objects.hash(mNat64Prefix);
|
+ Objects.hash(mNat64Prefix)
|
||||||
|
+ (mWakeOnLanSupported ? 71 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1622,6 +1662,8 @@ public final class LinkProperties implements Parcelable {
|
|||||||
|
|
||||||
ArrayList<LinkProperties> stackedLinks = new ArrayList<>(mStackedLinks.values());
|
ArrayList<LinkProperties> stackedLinks = new ArrayList<>(mStackedLinks.values());
|
||||||
dest.writeList(stackedLinks);
|
dest.writeList(stackedLinks);
|
||||||
|
|
||||||
|
dest.writeBoolean(mWakeOnLanSupported);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1677,6 +1719,7 @@ public final class LinkProperties implements Parcelable {
|
|||||||
for (LinkProperties stackedLink: stackedLinks) {
|
for (LinkProperties stackedLink: stackedLinks) {
|
||||||
netProp.addStackedLink(stackedLink);
|
netProp.addStackedLink(stackedLink);
|
||||||
}
|
}
|
||||||
|
netProp.setWakeOnLanSupported(in.readBoolean());
|
||||||
return netProp;
|
return netProp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -579,6 +579,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
// the set of network types that can only be enabled by system/sig apps
|
// the set of network types that can only be enabled by system/sig apps
|
||||||
private List mProtectedNetworks;
|
private List mProtectedNetworks;
|
||||||
|
|
||||||
|
private Set<String> mWolSupportedInterfaces;
|
||||||
|
|
||||||
private TelephonyManager mTelephonyManager;
|
private TelephonyManager mTelephonyManager;
|
||||||
|
|
||||||
private KeepaliveTracker mKeepaliveTracker;
|
private KeepaliveTracker mKeepaliveTracker;
|
||||||
@@ -1055,6 +1057,10 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mWolSupportedInterfaces = new ArraySet(
|
||||||
|
mContext.getResources().getStringArray(
|
||||||
|
com.android.internal.R.array.config_wakeonlan_supported_interfaces));
|
||||||
|
|
||||||
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||||
|
|
||||||
mTethering = deps.makeTethering(mContext, mNMS, mStatsService, mPolicyManager,
|
mTethering = deps.makeTethering(mContext, mNMS, mStatsService, mPolicyManager,
|
||||||
@@ -5600,6 +5606,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
} else {
|
} else {
|
||||||
updateProxy(newLp, oldLp);
|
updateProxy(newLp, oldLp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateWakeOnLan(newLp);
|
||||||
|
|
||||||
// TODO - move this check to cover the whole function
|
// TODO - move this check to cover the whole function
|
||||||
if (!Objects.equals(newLp, oldLp)) {
|
if (!Objects.equals(newLp, oldLp)) {
|
||||||
synchronized (networkAgent) {
|
synchronized (networkAgent) {
|
||||||
@@ -5770,6 +5779,10 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateWakeOnLan(@NonNull LinkProperties lp) {
|
||||||
|
lp.setWakeOnLanSupported(mWolSupportedInterfaces.contains(lp.getInterfaceName()));
|
||||||
|
}
|
||||||
|
|
||||||
private int getNetworkPermission(NetworkCapabilities nc) {
|
private int getNetworkPermission(NetworkCapabilities nc) {
|
||||||
if (!nc.hasCapability(NET_CAPABILITY_NOT_RESTRICTED)) {
|
if (!nc.hasCapability(NET_CAPABILITY_NOT_RESTRICTED)) {
|
||||||
return INetd.PERMISSION_SYSTEM;
|
return INetd.PERMISSION_SYSTEM;
|
||||||
|
|||||||
@@ -99,6 +99,7 @@ public class LinkPropertiesTest {
|
|||||||
assertFalse(lp.isIpv4Provisioned());
|
assertFalse(lp.isIpv4Provisioned());
|
||||||
assertFalse(lp.isIpv6Provisioned());
|
assertFalse(lp.isIpv6Provisioned());
|
||||||
assertFalse(lp.isPrivateDnsActive());
|
assertFalse(lp.isPrivateDnsActive());
|
||||||
|
assertFalse(lp.isWakeOnLanSupported());
|
||||||
}
|
}
|
||||||
|
|
||||||
private LinkProperties makeTestObject() {
|
private LinkProperties makeTestObject() {
|
||||||
@@ -120,6 +121,7 @@ public class LinkPropertiesTest {
|
|||||||
lp.setMtu(MTU);
|
lp.setMtu(MTU);
|
||||||
lp.setTcpBufferSizes(TCP_BUFFER_SIZES);
|
lp.setTcpBufferSizes(TCP_BUFFER_SIZES);
|
||||||
lp.setNat64Prefix(new IpPrefix("2001:db8:0:64::/96"));
|
lp.setNat64Prefix(new IpPrefix("2001:db8:0:64::/96"));
|
||||||
|
lp.setWakeOnLanSupported(true);
|
||||||
return lp;
|
return lp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,6 +160,9 @@ public class LinkPropertiesTest {
|
|||||||
assertTrue(source.isIdenticalTcpBufferSizes(target));
|
assertTrue(source.isIdenticalTcpBufferSizes(target));
|
||||||
assertTrue(target.isIdenticalTcpBufferSizes(source));
|
assertTrue(target.isIdenticalTcpBufferSizes(source));
|
||||||
|
|
||||||
|
assertTrue(source.isIdenticalWakeOnLan(target));
|
||||||
|
assertTrue(target.isIdenticalWakeOnLan(source));
|
||||||
|
|
||||||
// Check result of equals().
|
// Check result of equals().
|
||||||
assertTrue(source.equals(target));
|
assertTrue(source.equals(target));
|
||||||
assertTrue(target.equals(source));
|
assertTrue(target.equals(source));
|
||||||
@@ -1057,4 +1062,13 @@ public class LinkPropertiesTest {
|
|||||||
lp.clear();
|
lp.clear();
|
||||||
assertFalse(lp.isPrivateDnsActive());
|
assertFalse(lp.isPrivateDnsActive());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWakeOnLanSupported() {
|
||||||
|
final LinkProperties lp = makeTestObject();
|
||||||
|
assertTrue(lp.isWakeOnLanSupported());
|
||||||
|
|
||||||
|
lp.clear();
|
||||||
|
assertFalse(lp.isWakeOnLanSupported());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -274,6 +274,7 @@ public class ConnectivityServiceTest {
|
|||||||
private static final String CLAT_PREFIX = "v4-";
|
private static final String CLAT_PREFIX = "v4-";
|
||||||
private static final String MOBILE_IFNAME = "test_rmnet_data0";
|
private static final String MOBILE_IFNAME = "test_rmnet_data0";
|
||||||
private static final String WIFI_IFNAME = "test_wlan0";
|
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 static final String[] EMPTY_STRING_ARRAY = new String[0];
|
||||||
|
|
||||||
private MockContext mServiceContext;
|
private MockContext mServiceContext;
|
||||||
@@ -343,6 +344,12 @@ public class ConnectivityServiceTest {
|
|||||||
"mobile_mms,2,0,2,60000,true",
|
"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 = new MockContentResolver();
|
||||||
mContentResolver.addProvider(Settings.AUTHORITY, settingsProvider);
|
mContentResolver.addProvider(Settings.AUTHORITY, settingsProvider);
|
||||||
}
|
}
|
||||||
@@ -5947,6 +5954,24 @@ public class ConnectivityServiceTest {
|
|||||||
assertContainsExactly(uidCaptor.getValue(), APP2_UID);
|
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,
|
private TestNetworkAgentWrapper establishVpn(LinkProperties lp, int establishingUid,
|
||||||
Set<UidRange> vpnRange) throws Exception {
|
Set<UidRange> vpnRange) throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user