diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2019-11-15 01:09:05 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-11-15 01:09:05 +0000 |
commit | ffd6b66f5614e93fcf4e48fbffd8544871f0c0ed (patch) | |
tree | ccd170d93178f806c36c11d5f700957942a9e29f | |
parent | 765fe3125d17fdb0a079b8b415e48042e730fdf0 (diff) | |
parent | 1cc318d4e1cca2ee993f62536869e3659a1aa659 (diff) |
Merge changes I07e23d12,I3f17dab2
* changes:
TelephonyUtil: Use public API for isSimPresent
XmlUtil: Use public API for StaticIpConfiguration
5 files changed, 48 insertions, 37 deletions
diff --git a/service/java/com/android/server/wifi/WifiBackupDataV1Parser.java b/service/java/com/android/server/wifi/WifiBackupDataV1Parser.java index 9843f0d95..7c0e41d75 100644 --- a/service/java/com/android/server/wifi/WifiBackupDataV1Parser.java +++ b/service/java/com/android/server/wifi/WifiBackupDataV1Parser.java @@ -491,12 +491,12 @@ class WifiBackupDataV1Parser implements WifiBackupDataParser { ipConfiguration.setIpAssignment(ipAssignment); switch (ipAssignment) { case STATIC: - StaticIpConfiguration staticIpConfiguration = new StaticIpConfiguration(); + StaticIpConfiguration.Builder builder = new StaticIpConfiguration.Builder(); if (linkAddressString != null && linkPrefixLength != null) { LinkAddress linkAddress = new LinkAddress( NetworkUtils.numericToInetAddress(linkAddressString), linkPrefixLength); if (linkAddress.getAddress() instanceof Inet4Address) { - staticIpConfiguration.ipAddress = linkAddress; + builder.setIpAddress(linkAddress); } else { Log.w(TAG, "Non-IPv4 address: " + linkAddress); } @@ -505,19 +505,21 @@ class WifiBackupDataV1Parser implements WifiBackupDataParser { InetAddress gateway = NetworkUtils.numericToInetAddress(gatewayAddressString); RouteInfo route = new RouteInfo(null, gateway, null, RouteInfo.RTN_UNICAST); if (route.isIPv4Default()) { - staticIpConfiguration.gateway = gateway; + builder.setGateway(gateway); } else { Log.w(TAG, "Non-IPv4 default route: " + route); } } if (dnsServerAddressesString != null) { + List<InetAddress> dnsServerAddresses = new ArrayList<>(); for (String dnsServerAddressString : dnsServerAddressesString) { InetAddress dnsServerAddress = NetworkUtils.numericToInetAddress(dnsServerAddressString); - staticIpConfiguration.dnsServers.add(dnsServerAddress); + dnsServerAddresses.add(dnsServerAddress); } + builder.setDnsServers(dnsServerAddresses); } - ipConfiguration.setStaticIpConfiguration(staticIpConfiguration); + ipConfiguration.setStaticIpConfiguration(builder.build()); break; case DHCP: case UNASSIGNED: diff --git a/service/java/com/android/server/wifi/WifiConfigurationUtil.java b/service/java/com/android/server/wifi/WifiConfigurationUtil.java index facc999bd..1bff474e4 100644 --- a/service/java/com/android/server/wifi/WifiConfigurationUtil.java +++ b/service/java/com/android/server/wifi/WifiConfigurationUtil.java @@ -515,7 +515,7 @@ public class WifiConfigurationUtil { Log.e(TAG, "validateIpConfiguration failed: null StaticIpConfiguration"); return false; } - if (staticIpConfig.ipAddress == null) { + if (staticIpConfig.getIpAddress() == null) { Log.e(TAG, "validateIpConfiguration failed: null static ip Address"); return false; } diff --git a/service/java/com/android/server/wifi/util/TelephonyUtil.java b/service/java/com/android/server/wifi/util/TelephonyUtil.java index 60921725e..e9f0a4686 100644 --- a/service/java/com/android/server/wifi/util/TelephonyUtil.java +++ b/service/java/com/android/server/wifi/util/TelephonyUtil.java @@ -34,7 +34,6 @@ import com.android.server.wifi.WifiNative; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.security.PublicKey; -import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -135,8 +134,12 @@ public class TelephonyUtil { * @return true if the subId is active, otherwise false. */ public boolean isSimPresent(int subId) { - return Arrays.stream(mSubscriptionManager.getActiveSubscriptionIdList()) - .anyMatch(id -> id == subId); + List<SubscriptionInfo> subInfoList = mSubscriptionManager.getActiveSubscriptionInfoList(); + if (subInfoList == null || subInfoList.isEmpty()) { + return false; + } + return subInfoList.stream() + .anyMatch(info -> info.getSubscriptionId() == subId); } /** * Get the identity for the current SIM or null if the SIM is not available diff --git a/service/java/com/android/server/wifi/util/XmlUtil.java b/service/java/com/android/server/wifi/util/XmlUtil.java index 7ccd81aa4..a80aa5f4c 100644 --- a/service/java/com/android/server/wifi/util/XmlUtil.java +++ b/service/java/com/android/server/wifi/util/XmlUtil.java @@ -42,9 +42,11 @@ import org.xmlpull.v1.XmlSerializer; import java.io.IOException; import java.net.Inet4Address; import java.net.InetAddress; +import java.util.ArrayList; import java.util.Arrays; import java.util.BitSet; import java.util.HashMap; +import java.util.List; /** * Utils for manipulating XML data. This is essentially a wrapper over XmlUtils provided by core. @@ -777,41 +779,36 @@ public class XmlUtil { private static void writeStaticIpConfigurationToXml( XmlSerializer out, StaticIpConfiguration staticIpConfiguration) throws XmlPullParserException, IOException { - if (staticIpConfiguration.ipAddress != null) { + if (staticIpConfiguration.getIpAddress() != null) { XmlUtil.writeNextValue( out, XML_TAG_LINK_ADDRESS, - staticIpConfiguration.ipAddress.getAddress().getHostAddress()); + staticIpConfiguration.getIpAddress().getAddress().getHostAddress()); XmlUtil.writeNextValue( out, XML_TAG_LINK_PREFIX_LENGTH, - staticIpConfiguration.ipAddress.getPrefixLength()); + staticIpConfiguration.getIpAddress().getPrefixLength()); } else { XmlUtil.writeNextValue( out, XML_TAG_LINK_ADDRESS, null); XmlUtil.writeNextValue( out, XML_TAG_LINK_PREFIX_LENGTH, null); } - if (staticIpConfiguration.gateway != null) { + if (staticIpConfiguration.getGateway() != null) { XmlUtil.writeNextValue( out, XML_TAG_GATEWAY_ADDRESS, - staticIpConfiguration.gateway.getHostAddress()); + staticIpConfiguration.getGateway().getHostAddress()); } else { XmlUtil.writeNextValue( out, XML_TAG_GATEWAY_ADDRESS, null); } - if (staticIpConfiguration.dnsServers != null) { - // Create a string array of DNS server addresses - String[] dnsServers = new String[staticIpConfiguration.dnsServers.size()]; - int dnsServerIdx = 0; - for (InetAddress inetAddr : staticIpConfiguration.dnsServers) { - dnsServers[dnsServerIdx++] = inetAddr.getHostAddress(); - } - XmlUtil.writeNextValue( - out, XML_TAG_DNS_SERVER_ADDRESSES, dnsServers); - } else { - XmlUtil.writeNextValue( - out, XML_TAG_DNS_SERVER_ADDRESSES, null); + // Create a string array of DNS server addresses + String[] dnsServers = new String[staticIpConfiguration.getDnsServers().size()]; + int dnsServerIdx = 0; + for (InetAddress inetAddr : staticIpConfiguration.getDnsServers()) { + dnsServers[dnsServerIdx++] = inetAddr.getHostAddress(); } + XmlUtil.writeNextValue( + out, XML_TAG_DNS_SERVER_ADDRESSES, dnsServers); } /** @@ -870,7 +867,7 @@ public class XmlUtil { */ private static StaticIpConfiguration parseStaticIpConfigurationFromXml(XmlPullParser in) throws XmlPullParserException, IOException { - StaticIpConfiguration staticIpConfiguration = new StaticIpConfiguration(); + StaticIpConfiguration.Builder builder = new StaticIpConfiguration.Builder(); String linkAddressString = (String) XmlUtil.readNextValueWithName(in, XML_TAG_LINK_ADDRESS); @@ -881,7 +878,7 @@ public class XmlUtil { NetworkUtils.numericToInetAddress(linkAddressString), linkPrefixLength); if (linkAddress.getAddress() instanceof Inet4Address) { - staticIpConfiguration.ipAddress = linkAddress; + builder.setIpAddress(linkAddress); } else { Log.w(TAG, "Non-IPv4 address: " + linkAddress); } @@ -893,7 +890,7 @@ public class XmlUtil { NetworkUtils.numericToInetAddress(gatewayAddressString); RouteInfo route = new RouteInfo(null, gateway, null, RouteInfo.RTN_UNICAST); if (route.isIPv4Default()) { - staticIpConfiguration.gateway = gateway; + builder.setGateway(gateway); } else { Log.w(TAG, "Non-IPv4 default route: " + route); } @@ -901,13 +898,15 @@ public class XmlUtil { String[] dnsServerAddressesString = (String[]) XmlUtil.readNextValueWithName(in, XML_TAG_DNS_SERVER_ADDRESSES); if (dnsServerAddressesString != null) { + List<InetAddress> dnsServerAddresses = new ArrayList<>(); for (String dnsServerAddressString : dnsServerAddressesString) { InetAddress dnsServerAddress = NetworkUtils.numericToInetAddress(dnsServerAddressString); - staticIpConfiguration.dnsServers.add(dnsServerAddress); + dnsServerAddresses.add(dnsServerAddress); } + builder.setDnsServers(dnsServerAddresses); } - return staticIpConfiguration; + return builder.build(); } /** diff --git a/tests/wifitests/src/com/android/server/wifi/util/TelephonyUtilTest.java b/tests/wifitests/src/com/android/server/wifi/util/TelephonyUtilTest.java index 5cff6d3d1..b31bb057e 100644 --- a/tests/wifitests/src/com/android/server/wifi/util/TelephonyUtilTest.java +++ b/tests/wifitests/src/com/android/server/wifi/util/TelephonyUtilTest.java @@ -49,6 +49,7 @@ import org.mockito.quality.Strictness; import java.security.PublicKey; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -652,8 +653,12 @@ public class TelephonyUtilTest extends WifiBaseTest { */ @Test public void isSimPresentWithValidSubscriptionIdList() { - when(mSubscriptionManager.getActiveSubscriptionIdList()) - .thenReturn(new int[] {DATA_SUBID, NON_DATA_SUBID}); + SubscriptionInfo subInfo1 = mock(SubscriptionInfo.class); + when(subInfo1.getSubscriptionId()).thenReturn(DATA_SUBID); + SubscriptionInfo subInfo2 = mock(SubscriptionInfo.class); + when(subInfo2.getSubscriptionId()).thenReturn(NON_DATA_SUBID); + when(mSubscriptionManager.getActiveSubscriptionInfoList()) + .thenReturn(Arrays.asList(subInfo1, subInfo2)); assertTrue(mTelephonyUtil.isSimPresent(DATA_SUBID)); } @@ -663,13 +668,15 @@ public class TelephonyUtilTest extends WifiBaseTest { */ @Test public void isSimPresentWithInvalidOrEmptySubscriptionIdList() { - when(mSubscriptionManager.getActiveSubscriptionIdList()) - .thenReturn(new int[]{}); + when(mSubscriptionManager.getActiveSubscriptionInfoList()) + .thenReturn(Collections.emptyList()); assertFalse(mTelephonyUtil.isSimPresent(DATA_SUBID)); - when(mSubscriptionManager.getActiveSubscriptionIdList()) - .thenReturn(new int[]{NON_DATA_SUBID}); + SubscriptionInfo subInfo = mock(SubscriptionInfo.class); + when(subInfo.getSubscriptionId()).thenReturn(NON_DATA_SUBID); + when(mSubscriptionManager.getActiveSubscriptionInfoList()) + .thenReturn(Arrays.asList(subInfo)); assertFalse(mTelephonyUtil.isSimPresent(DATA_SUBID)); } |