Merge "Remove *_WILDCARD constants from NetworkTemplate" am: 2500069488
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2228859 Change-Id: Iee14f6d0f510ec251c657c41593f237f4ee3e96e Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -88,18 +88,6 @@ public final class NetworkTemplate implements Parcelable {
|
||||
public static final int MATCH_WIFI = 4;
|
||||
/** Match rule to match ethernet networks. */
|
||||
public static final int MATCH_ETHERNET = 5;
|
||||
/**
|
||||
* Match rule to match all cellular networks.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public static final int MATCH_MOBILE_WILDCARD = 6;
|
||||
/**
|
||||
* Match rule to match all wifi networks.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public static final int MATCH_WIFI_WILDCARD = 7;
|
||||
/** Match rule to match bluetooth networks. */
|
||||
public static final int MATCH_BLUETOOTH = 8;
|
||||
/**
|
||||
@@ -177,8 +165,6 @@ public final class NetworkTemplate implements Parcelable {
|
||||
case MATCH_MOBILE:
|
||||
case MATCH_WIFI:
|
||||
case MATCH_ETHERNET:
|
||||
case MATCH_MOBILE_WILDCARD:
|
||||
case MATCH_WIFI_WILDCARD:
|
||||
case MATCH_BLUETOOTH:
|
||||
case MATCH_PROXY:
|
||||
case MATCH_CARRIER:
|
||||
@@ -284,9 +270,8 @@ public final class NetworkTemplate implements Parcelable {
|
||||
|
||||
private static void checkValidMatchSubscriberIds(int matchRule, String[] matchSubscriberIds) {
|
||||
switch (matchRule) {
|
||||
case MATCH_MOBILE:
|
||||
case MATCH_CARRIER:
|
||||
// MOBILE and CARRIER templates must always specify a subscriber ID.
|
||||
// CARRIER templates must always specify a valid subscriber ID.
|
||||
if (matchSubscriberIds.length == 0) {
|
||||
throw new IllegalArgumentException("checkValidMatchSubscriberIds with empty"
|
||||
+ " list of ids for rule" + getMatchRuleName(matchRule));
|
||||
@@ -314,9 +299,9 @@ public final class NetworkTemplate implements Parcelable {
|
||||
//constructor passes METERED_YES for these types.
|
||||
this(matchRule, new String[] { subscriberId },
|
||||
wifiNetworkKey != null ? new String[] { wifiNetworkKey } : new String[0],
|
||||
(matchRule == MATCH_MOBILE || matchRule == MATCH_MOBILE_WILDCARD
|
||||
|| matchRule == MATCH_CARRIER) ? METERED_YES : METERED_ALL,
|
||||
ROAMING_ALL, DEFAULT_NETWORK_ALL, NETWORK_TYPE_ALL, OEM_MANAGED_ALL);
|
||||
(matchRule == MATCH_MOBILE || matchRule == MATCH_CARRIER)
|
||||
? METERED_YES : METERED_ALL, ROAMING_ALL, DEFAULT_NETWORK_ALL,
|
||||
NETWORK_TYPE_ALL, OEM_MANAGED_ALL);
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
@@ -417,43 +402,23 @@ public final class NetworkTemplate implements Parcelable {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public boolean isMatchRuleMobile() {
|
||||
switch (mMatchRule) {
|
||||
case MATCH_MOBILE:
|
||||
case MATCH_MOBILE_WILDCARD:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get match rule of the template. See {@code MATCH_*}.
|
||||
*/
|
||||
@UnsupportedAppUsage
|
||||
public int getMatchRule() {
|
||||
// Wildcard rules are not exposed. For external callers, convert wildcard rules to
|
||||
// exposed rules before returning.
|
||||
switch (mMatchRule) {
|
||||
case MATCH_MOBILE_WILDCARD:
|
||||
return MATCH_MOBILE;
|
||||
case MATCH_WIFI_WILDCARD:
|
||||
return MATCH_WIFI;
|
||||
default:
|
||||
return mMatchRule;
|
||||
}
|
||||
return mMatchRule;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get subscriber Id of the template.
|
||||
*
|
||||
* @deprecated User should get a subscriberId by {@link #getSubscriberIds} instead.
|
||||
* @deprecated User should use {@link #getSubscriberIds} instead.
|
||||
* @hide
|
||||
*/
|
||||
@Deprecated
|
||||
@Nullable
|
||||
@UnsupportedAppUsage
|
||||
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.TIRAMISU,
|
||||
publicAlternatives = "Caller should use {@code getSubscriberIds} instead.")
|
||||
public String getSubscriberId() {
|
||||
return CollectionUtils.isEmpty(mMatchSubscriberIds) ? null : mMatchSubscriberIds[0];
|
||||
}
|
||||
@@ -542,10 +507,6 @@ public final class NetworkTemplate implements Parcelable {
|
||||
return matchesWifi(ident);
|
||||
case MATCH_ETHERNET:
|
||||
return matchesEthernet(ident);
|
||||
case MATCH_MOBILE_WILDCARD:
|
||||
return matchesMobileWildcard(ident);
|
||||
case MATCH_WIFI_WILDCARD:
|
||||
return matchesWifiWildcard(ident);
|
||||
case MATCH_BLUETOOTH:
|
||||
return matchesBluetooth(ident);
|
||||
case MATCH_PROXY:
|
||||
@@ -626,9 +587,9 @@ public final class NetworkTemplate implements Parcelable {
|
||||
// TODO: consider matching against WiMAX subscriber identity
|
||||
return true;
|
||||
} else {
|
||||
return ident.mType == TYPE_MOBILE && !CollectionUtils.isEmpty(mMatchSubscriberIds)
|
||||
&& CollectionUtils.contains(mMatchSubscriberIds, ident.mSubscriberId)
|
||||
&& matchesCollapsedRatType(ident);
|
||||
return (CollectionUtils.isEmpty(mMatchSubscriberIds)
|
||||
|| CollectionUtils.contains(mMatchSubscriberIds, ident.mSubscriberId))
|
||||
&& (ident.mType == TYPE_MOBILE && matchesCollapsedRatType(ident));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -640,6 +601,8 @@ public final class NetworkTemplate implements Parcelable {
|
||||
case TYPE_WIFI:
|
||||
return matchesSubscriberId(ident.mSubscriberId)
|
||||
&& matchesWifiNetworkKey(ident.mWifiNetworkKey);
|
||||
case TYPE_WIFI_P2P:
|
||||
return CollectionUtils.isEmpty(mMatchWifiNetworkKeys);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@@ -675,24 +638,6 @@ public final class NetworkTemplate implements Parcelable {
|
||||
|| CollectionUtils.contains(mMatchWifiNetworkKeys, ident.mWifiNetworkKey)));
|
||||
}
|
||||
|
||||
private boolean matchesMobileWildcard(NetworkIdentity ident) {
|
||||
if (ident.mType == TYPE_WIMAX) {
|
||||
return true;
|
||||
} else {
|
||||
return ident.mType == TYPE_MOBILE && matchesCollapsedRatType(ident);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean matchesWifiWildcard(NetworkIdentity ident) {
|
||||
switch (ident.mType) {
|
||||
case TYPE_WIFI:
|
||||
case TYPE_WIFI_P2P:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if matches Bluetooth network template.
|
||||
*/
|
||||
@@ -718,10 +663,6 @@ public final class NetworkTemplate implements Parcelable {
|
||||
return "WIFI";
|
||||
case MATCH_ETHERNET:
|
||||
return "ETHERNET";
|
||||
case MATCH_MOBILE_WILDCARD:
|
||||
return "MOBILE_WILDCARD";
|
||||
case MATCH_WIFI_WILDCARD:
|
||||
return "WIFI_WILDCARD";
|
||||
case MATCH_BLUETOOTH:
|
||||
return "BLUETOOTH";
|
||||
case MATCH_PROXY:
|
||||
@@ -781,9 +722,8 @@ public final class NetworkTemplate implements Parcelable {
|
||||
return new NetworkTemplate(template.mMatchRule, merged,
|
||||
CollectionUtils.isEmpty(matchWifiNetworkKeys)
|
||||
? new String[0] : new String[] { matchWifiNetworkKeys[0] },
|
||||
(template.mMatchRule == MATCH_MOBILE
|
||||
|| template.mMatchRule == MATCH_MOBILE_WILDCARD
|
||||
|| template.mMatchRule == MATCH_CARRIER) ? METERED_YES : METERED_ALL,
|
||||
(template.mMatchRule == MATCH_MOBILE || template.mMatchRule == MATCH_CARRIER)
|
||||
? METERED_YES : METERED_ALL,
|
||||
ROAMING_ALL, DEFAULT_NETWORK_ALL, NETWORK_TYPE_ALL, OEM_MANAGED_ALL);
|
||||
}
|
||||
|
||||
@@ -951,10 +891,7 @@ public final class NetworkTemplate implements Parcelable {
|
||||
* @param matchRule the target match rule to be checked.
|
||||
*/
|
||||
private static void assertRequestableMatchRule(final int matchRule) {
|
||||
if (!isKnownMatchRule(matchRule)
|
||||
|| matchRule == MATCH_PROXY
|
||||
|| matchRule == MATCH_MOBILE_WILDCARD
|
||||
|| matchRule == MATCH_WIFI_WILDCARD) {
|
||||
if (!isKnownMatchRule(matchRule) || matchRule == MATCH_PROXY) {
|
||||
throw new IllegalArgumentException("Invalid match rule: "
|
||||
+ getMatchRuleName(matchRule));
|
||||
}
|
||||
@@ -974,20 +911,6 @@ public final class NetworkTemplate implements Parcelable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* For backward compatibility, deduce match rule to a wildcard match rule
|
||||
* if the Subscriber Ids are empty.
|
||||
*/
|
||||
private int getWildcardDeducedMatchRule() {
|
||||
if (mMatchRule == MATCH_MOBILE && mMatchSubscriberIds.isEmpty()) {
|
||||
return MATCH_MOBILE_WILDCARD;
|
||||
} else if (mMatchRule == MATCH_WIFI && mMatchSubscriberIds.isEmpty()
|
||||
&& mMatchWifiNetworkKeys.isEmpty()) {
|
||||
return MATCH_WIFI_WILDCARD;
|
||||
}
|
||||
return mMatchRule;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the instance of the NetworkTemplate.
|
||||
*
|
||||
@@ -996,7 +919,7 @@ public final class NetworkTemplate implements Parcelable {
|
||||
@NonNull
|
||||
public NetworkTemplate build() {
|
||||
assertRequestableParameters();
|
||||
return new NetworkTemplate(getWildcardDeducedMatchRule(),
|
||||
return new NetworkTemplate(mMatchRule,
|
||||
mMatchSubscriberIds.toArray(new String[0]),
|
||||
mMatchWifiNetworkKeys.toArray(new String[0]), mMetered, mRoaming,
|
||||
mDefaultNetwork, mRatType, mOemManaged);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -34,10 +34,8 @@ import android.net.NetworkStats.METERED_YES
|
||||
import android.net.NetworkStats.ROAMING_ALL
|
||||
import android.net.NetworkTemplate.MATCH_CARRIER
|
||||
import android.net.NetworkTemplate.MATCH_MOBILE
|
||||
import android.net.NetworkTemplate.MATCH_MOBILE_WILDCARD
|
||||
import android.net.NetworkTemplate.MATCH_TEST
|
||||
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.net.NetworkTemplate.OEM_MANAGED_NO
|
||||
@@ -231,7 +229,6 @@ class NetworkTemplateTest {
|
||||
val templateMobileWildcard = buildTemplateMobileWildcard()
|
||||
val templateMobileNullImsiWithRatType = NetworkTemplate.Builder(MATCH_MOBILE)
|
||||
.setRatType(TelephonyManager.NETWORK_TYPE_UMTS).build()
|
||||
|
||||
val mobileImsi1 = buildMobileNetworkState(TEST_IMSI1)
|
||||
val identMobile1 = buildNetworkIdentity(mockContext, mobileImsi1,
|
||||
false /* defaultNetwork */, TelephonyManager.NETWORK_TYPE_UMTS)
|
||||
@@ -453,7 +450,7 @@ class NetworkTemplateTest {
|
||||
val templateWifi = NetworkTemplate(MATCH_WIFI, emptyArray<String>(),
|
||||
arrayOf(TEST_WIFI_KEY1), METERED_ALL, ROAMING_ALL, DEFAULT_NETWORK_ALL, 0,
|
||||
OEM_MANAGED_ALL)
|
||||
val templateOem = NetworkTemplate(MATCH_MOBILE_WILDCARD, emptyArray<String>(),
|
||||
val templateOem = NetworkTemplate(MATCH_MOBILE, emptyArray<String>(),
|
||||
emptyArray<String>(), METERED_ALL, ROAMING_ALL, DEFAULT_NETWORK_ALL, 0,
|
||||
OEM_MANAGED_YES)
|
||||
assertParcelSane(templateMobile, 8)
|
||||
@@ -491,13 +488,14 @@ class NetworkTemplateTest {
|
||||
* @param matchType A match rule from {@code NetworkTemplate.MATCH_*} corresponding to the
|
||||
* networkType.
|
||||
* @param subscriberId To be populated with {@code TEST_IMSI*} only if networkType is
|
||||
* {@code TYPE_MOBILE}. May be left as null when matchType is
|
||||
* {@link NetworkTemplate.MATCH_MOBILE_WILDCARD}.
|
||||
* @param templateWifiKey Top be populated with {@code TEST_WIFI_KEY*} only if networkType is
|
||||
* {@code TYPE_WIFI}. May be left as null when matchType is
|
||||
* {@link NetworkTemplate.MATCH_WIFI_WILDCARD}.
|
||||
* @param identWifiKey If networkType is {@code TYPE_WIFI}, this value must *NOT* be null. Provide
|
||||
* one of {@code TEST_WIFI_KEY*}.
|
||||
* {@code TYPE_MOBILE}. Note that {@code MATCH_MOBILE} with an empty subscriberId list
|
||||
* will match any subscriber ID.
|
||||
* @param templateWifiKey To be populated with {@code TEST_WIFI_KEY*} only if networkType is
|
||||
* {@code TYPE_WIFI}. Note that {@code MATCH_WIFI} with both an empty subscriberId list
|
||||
* and an empty wifiNetworkKey list will match any subscriber ID and/or any wifi network
|
||||
* key.
|
||||
* @param identWifiKey If networkType is {@code TYPE_WIFI}, this value must *NOT* be null.
|
||||
* Provide one of {@code TEST_WIFI_KEY*}.
|
||||
*/
|
||||
private fun matchOemManagedIdent(
|
||||
networkType: Int,
|
||||
@@ -507,8 +505,10 @@ class NetworkTemplateTest {
|
||||
identWifiKey: String? = null
|
||||
) {
|
||||
val oemManagedStates = arrayOf(OEM_NONE, OEM_PAID, OEM_PRIVATE, OEM_PAID or OEM_PRIVATE)
|
||||
val matchSubscriberIds = arrayOf(subscriberId)
|
||||
val matchWifiNetworkKeys = arrayOf(templateWifiKey)
|
||||
val matchSubscriberIds =
|
||||
if (subscriberId == null) emptyArray<String>() else arrayOf(subscriberId)
|
||||
val matchWifiNetworkKeys =
|
||||
if (templateWifiKey == null) emptyArray<String>() else arrayOf(templateWifiKey)
|
||||
|
||||
val templateOemYes = NetworkTemplate(matchType, matchSubscriberIds,
|
||||
matchWifiNetworkKeys, METERED_ALL, ROAMING_ALL,
|
||||
@@ -547,11 +547,10 @@ class NetworkTemplateTest {
|
||||
@Test
|
||||
fun testOemManagedMatchesIdent() {
|
||||
matchOemManagedIdent(TYPE_MOBILE, MATCH_MOBILE, subscriberId = TEST_IMSI1)
|
||||
matchOemManagedIdent(TYPE_MOBILE, MATCH_MOBILE_WILDCARD)
|
||||
matchOemManagedIdent(TYPE_MOBILE, MATCH_MOBILE)
|
||||
matchOemManagedIdent(TYPE_WIFI, MATCH_WIFI, templateWifiKey = TEST_WIFI_KEY1,
|
||||
identWifiKey = TEST_WIFI_KEY1)
|
||||
matchOemManagedIdent(TYPE_WIFI, MATCH_WIFI_WILDCARD,
|
||||
identWifiKey = TEST_WIFI_KEY1)
|
||||
matchOemManagedIdent(TYPE_WIFI, MATCH_WIFI, identWifiKey = TEST_WIFI_KEY1)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user