Remove *_WILDCARD constants from NetworkTemplate

NetworkTemplate was moved into mainline module and
provide Builder for external users to build template.
MATCH_MOBILE_WILDCARD and MATCH_WIFI_WILDCARD are not
exposed so currently the usage of these two constants
only in module. This change is to remove the constants.

After removing the constants, two methods matchesWifi
and matchesMobile are changed to adapt the original
matches[Wifi|Mobile]Wildcard behavior.

Bug: 238843364
Test: FrameworksNetTests
Change-Id: I9e156b504ce4eb903b39279e443fad27bc921186
This commit is contained in:
Aaron Huang 2022-11-05 00:39:06 +08:00
commit ece181997c

View file

@ -26,10 +26,8 @@ import android.net.NetworkTemplate.MATCH_BLUETOOTH
import android.net.NetworkTemplate.MATCH_CARRIER
import android.net.NetworkTemplate.MATCH_ETHERNET
import android.net.NetworkTemplate.MATCH_MOBILE
import android.net.NetworkTemplate.MATCH_MOBILE_WILDCARD
import android.net.NetworkTemplate.MATCH_PROXY
import android.net.NetworkTemplate.MATCH_WIFI
import android.net.NetworkTemplate.MATCH_WIFI_WILDCARD
import android.net.NetworkTemplate.NETWORK_TYPE_ALL
import android.net.NetworkTemplate.OEM_MANAGED_ALL
import android.telephony.TelephonyManager
@ -64,10 +62,8 @@ class NetworkTemplateTest {
}
// Verify hidden match rules cannot construct templates.
listOf(MATCH_WIFI_WILDCARD, MATCH_MOBILE_WILDCARD, MATCH_PROXY).forEach {
assertFailsWith<IllegalArgumentException> {
NetworkTemplate.Builder(it).build()
}
assertFailsWith<IllegalArgumentException> {
NetworkTemplate.Builder(MATCH_PROXY).build()
}
// Verify template which matches metered cellular and carrier networks with
@ -102,7 +98,7 @@ class NetworkTemplateTest {
// Verify template which matches metered cellular networks,
// regardless of IMSI. See buildTemplateMobileWildcard.
NetworkTemplate.Builder(MATCH_MOBILE).setMeteredness(METERED_YES).build().let {
val expectedTemplate = NetworkTemplate(MATCH_MOBILE_WILDCARD,
val expectedTemplate = NetworkTemplate(MATCH_MOBILE,
emptyArray<String>() /*subscriberIds*/, emptyArray<String>() /*wifiNetworkKey*/,
METERED_YES, ROAMING_ALL, DEFAULT_NETWORK_ALL, NETWORK_TYPE_ALL,
OEM_MANAGED_ALL)
@ -110,7 +106,6 @@ class NetworkTemplateTest {
}
// Verify template which matches metered cellular networks and ratType.
// See NetworkTemplate#buildTemplateMobileWithRatType.
NetworkTemplate.Builder(MATCH_MOBILE).setSubscriberIds(setOf(TEST_IMSI1))
.setMeteredness(METERED_YES).setRatType(TelephonyManager.NETWORK_TYPE_UMTS)
.build().let {
@ -123,7 +118,7 @@ class NetworkTemplateTest {
// Verify template which matches all wifi networks,
// regardless of Wifi Network Key. See buildTemplateWifiWildcard and buildTemplateWifi.
NetworkTemplate.Builder(MATCH_WIFI).build().let {
val expectedTemplate = NetworkTemplate(MATCH_WIFI_WILDCARD,
val expectedTemplate = NetworkTemplate(MATCH_WIFI,
emptyArray<String>() /*subscriberIds*/, emptyArray<String>(), METERED_ALL,
ROAMING_ALL, DEFAULT_NETWORK_ALL, NETWORK_TYPE_ALL, OEM_MANAGED_ALL)
assertEquals(expectedTemplate, it)
@ -188,7 +183,7 @@ class NetworkTemplateTest {
// Verify template which matches wifi wildcard with the given empty key set.
NetworkTemplate.Builder(MATCH_WIFI).setWifiNetworkKeys(setOf<String>()).build().let {
val expectedTemplate = NetworkTemplate(MATCH_WIFI_WILDCARD,
val expectedTemplate = NetworkTemplate(MATCH_WIFI,
emptyArray<String>() /*subscriberIds*/, emptyArray<String>(),
METERED_ALL, ROAMING_ALL, DEFAULT_NETWORK_ALL, NETWORK_TYPE_ALL,
OEM_MANAGED_ALL)