Merge "Remove unused methods from NetworkTemplate" am: 23d8cd11c7
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2286634 Change-Id: I5b3869cd968f11bf03aae2a09b5c3f018988ab85 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -47,7 +47,6 @@ import android.net.wifi.WifiInfo;
|
|||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.util.ArraySet;
|
import android.util.ArraySet;
|
||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
@@ -59,7 +58,6 @@ import java.lang.annotation.Retention;
|
|||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
@@ -197,149 +195,67 @@ public final class NetworkTemplate implements Parcelable {
|
|||||||
* Template to match {@link ConnectivityManager#TYPE_MOBILE} networks with
|
* Template to match {@link ConnectivityManager#TYPE_MOBILE} networks with
|
||||||
* the given IMSI.
|
* the given IMSI.
|
||||||
*
|
*
|
||||||
|
* @deprecated Use {@link Builder} to build a template.
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
@UnsupportedAppUsage
|
@Deprecated
|
||||||
public static NetworkTemplate buildTemplateMobileAll(String subscriberId) {
|
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.TIRAMISU,
|
||||||
return new NetworkTemplate(MATCH_MOBILE, subscriberId, null);
|
publicAlternatives = "Use {@code Builder} instead.")
|
||||||
}
|
public static NetworkTemplate buildTemplateMobileAll(@NonNull String subscriberId) {
|
||||||
|
return new NetworkTemplate.Builder(MATCH_MOBILE).setMeteredness(METERED_YES)
|
||||||
/**
|
.setSubscriberIds(Set.of(subscriberId)).build();
|
||||||
* Template to match cellular networks with the given IMSI, {@code ratType} and
|
|
||||||
* {@code metered}. Use {@link #NETWORK_TYPE_ALL} to include all network types when
|
|
||||||
* filtering. See {@code TelephonyManager.NETWORK_TYPE_*}.
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public static NetworkTemplate buildTemplateMobileWithRatType(@Nullable String subscriberId,
|
|
||||||
int ratType, int metered) {
|
|
||||||
if (TextUtils.isEmpty(subscriberId)) {
|
|
||||||
return new NetworkTemplate(MATCH_MOBILE_WILDCARD, null /* subscriberId */,
|
|
||||||
null /* matchSubscriberIds */,
|
|
||||||
new String[0] /* matchWifiNetworkKeys */, metered, ROAMING_ALL,
|
|
||||||
DEFAULT_NETWORK_ALL, ratType, OEM_MANAGED_ALL,
|
|
||||||
NetworkStatsUtils.SUBSCRIBER_ID_MATCH_RULE_EXACT);
|
|
||||||
}
|
|
||||||
return new NetworkTemplate(MATCH_MOBILE, subscriberId, new String[] { subscriberId },
|
|
||||||
new String[0] /* matchWifiNetworkKeys */,
|
|
||||||
metered, ROAMING_ALL, DEFAULT_NETWORK_ALL, ratType, OEM_MANAGED_ALL,
|
|
||||||
NetworkStatsUtils.SUBSCRIBER_ID_MATCH_RULE_EXACT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Template to match metered {@link ConnectivityManager#TYPE_MOBILE} networks,
|
* Template to match metered {@link ConnectivityManager#TYPE_MOBILE} networks,
|
||||||
* regardless of IMSI.
|
* regardless of IMSI.
|
||||||
*
|
*
|
||||||
|
* @deprecated Use {@link Builder} to build a template.
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
|
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
|
||||||
public static NetworkTemplate buildTemplateMobileWildcard() {
|
public static NetworkTemplate buildTemplateMobileWildcard() {
|
||||||
return new NetworkTemplate(MATCH_MOBILE_WILDCARD, null, null);
|
return new NetworkTemplate.Builder(MATCH_MOBILE).setMeteredness(METERED_YES).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Template to match all metered {@link ConnectivityManager#TYPE_WIFI} networks,
|
* Template to match all metered {@link ConnectivityManager#TYPE_WIFI} networks,
|
||||||
* regardless of key of the wifi network.
|
* regardless of key of the wifi network.
|
||||||
*
|
*
|
||||||
|
* @deprecated Use {@link Builder} to build a template.
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
@UnsupportedAppUsage
|
@Deprecated
|
||||||
|
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.TIRAMISU,
|
||||||
|
publicAlternatives = "Use {@code Builder} instead.")
|
||||||
public static NetworkTemplate buildTemplateWifiWildcard() {
|
public static NetworkTemplate buildTemplateWifiWildcard() {
|
||||||
// TODO: Consider replace this with MATCH_WIFI with NETWORK_ID_ALL
|
return new NetworkTemplate.Builder(MATCH_WIFI).build();
|
||||||
// and SUBSCRIBER_ID_MATCH_RULE_ALL.
|
|
||||||
return new NetworkTemplate(MATCH_WIFI_WILDCARD, null, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
/**
|
||||||
|
* @deprecated Use {@link Builder} to build a template.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@UnsupportedAppUsage
|
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.TIRAMISU,
|
||||||
|
publicAlternatives = "Use {@code Builder} instead.")
|
||||||
public static NetworkTemplate buildTemplateWifi() {
|
public static NetworkTemplate buildTemplateWifi() {
|
||||||
return buildTemplateWifiWildcard();
|
return buildTemplateWifiWildcard();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Template to match {@link ConnectivityManager#TYPE_WIFI} networks with the
|
|
||||||
* given key of the wifi network.
|
|
||||||
*
|
|
||||||
* @param wifiNetworkKey key of the wifi network. see {@link WifiInfo#getNetworkKey()}
|
|
||||||
* to know details about the key.
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public static NetworkTemplate buildTemplateWifi(@NonNull String wifiNetworkKey) {
|
|
||||||
Objects.requireNonNull(wifiNetworkKey);
|
|
||||||
return new NetworkTemplate(MATCH_WIFI, null /* subscriberId */,
|
|
||||||
new String[] { null } /* matchSubscriberIds */,
|
|
||||||
new String[] { wifiNetworkKey }, METERED_ALL, ROAMING_ALL,
|
|
||||||
DEFAULT_NETWORK_ALL, NETWORK_TYPE_ALL, OEM_MANAGED_ALL,
|
|
||||||
NetworkStatsUtils.SUBSCRIBER_ID_MATCH_RULE_ALL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Template to match all {@link ConnectivityManager#TYPE_WIFI} networks with the given
|
|
||||||
* key of the wifi network and IMSI.
|
|
||||||
*
|
|
||||||
* Call with {@link #WIFI_NETWORK_KEY_ALL} for {@code wifiNetworkKey} to get result regardless
|
|
||||||
* of key of the wifi network.
|
|
||||||
*
|
|
||||||
* @param wifiNetworkKey key of the wifi network. see {@link WifiInfo#getNetworkKey()}
|
|
||||||
* to know details about the key.
|
|
||||||
* @param subscriberId the IMSI associated to this wifi network.
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public static NetworkTemplate buildTemplateWifi(@Nullable String wifiNetworkKey,
|
|
||||||
@Nullable String subscriberId) {
|
|
||||||
return new NetworkTemplate(MATCH_WIFI, subscriberId, new String[] { subscriberId },
|
|
||||||
wifiNetworkKey != null
|
|
||||||
? new String[] { wifiNetworkKey } : new String[0],
|
|
||||||
METERED_ALL, ROAMING_ALL, DEFAULT_NETWORK_ALL, NETWORK_TYPE_ALL, OEM_MANAGED_ALL,
|
|
||||||
NetworkStatsUtils.SUBSCRIBER_ID_MATCH_RULE_EXACT);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Template to combine all {@link ConnectivityManager#TYPE_ETHERNET} style
|
* Template to combine all {@link ConnectivityManager#TYPE_ETHERNET} style
|
||||||
* networks together.
|
* networks together.
|
||||||
*
|
*
|
||||||
|
* @deprecated Use {@link Builder} to build a template.
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
@UnsupportedAppUsage
|
@Deprecated
|
||||||
|
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.TIRAMISU,
|
||||||
|
publicAlternatives = "Use {@code Builder} instead.")
|
||||||
public static NetworkTemplate buildTemplateEthernet() {
|
public static NetworkTemplate buildTemplateEthernet() {
|
||||||
return new NetworkTemplate(MATCH_ETHERNET, null, null);
|
return new NetworkTemplate.Builder(MATCH_ETHERNET).build();
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Template to combine all {@link ConnectivityManager#TYPE_BLUETOOTH} style
|
|
||||||
* networks together.
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public static NetworkTemplate buildTemplateBluetooth() {
|
|
||||||
return new NetworkTemplate(MATCH_BLUETOOTH, null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Template to combine all {@link ConnectivityManager#TYPE_PROXY} style
|
|
||||||
* networks together.
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public static NetworkTemplate buildTemplateProxy() {
|
|
||||||
return new NetworkTemplate(MATCH_PROXY, null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Template to match all metered carrier networks with the given IMSI.
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public static NetworkTemplate buildTemplateCarrierMetered(@NonNull String subscriberId) {
|
|
||||||
Objects.requireNonNull(subscriberId);
|
|
||||||
return new NetworkTemplate(MATCH_CARRIER, subscriberId,
|
|
||||||
new String[] { subscriberId },
|
|
||||||
new String[0] /* matchWifiNetworkKeys */,
|
|
||||||
METERED_YES, ROAMING_ALL,
|
|
||||||
DEFAULT_NETWORK_ALL, NETWORK_TYPE_ALL, OEM_MANAGED_ALL,
|
|
||||||
NetworkStatsUtils.SUBSCRIBER_ID_MATCH_RULE_EXACT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final int mMatchRule;
|
private final int mMatchRule;
|
||||||
@@ -387,9 +303,13 @@ public final class NetworkTemplate implements Parcelable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
/**
|
||||||
// TODO: Deprecate this constructor, mark it @UnsupportedAppUsage(maxTargetSdk = S)
|
* @deprecated Use {@link Builder} to build a template.
|
||||||
@UnsupportedAppUsage
|
* @hide
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.TIRAMISU,
|
||||||
|
publicAlternatives = "Use {@code Builder} instead.")
|
||||||
public NetworkTemplate(int matchRule, String subscriberId, String wifiNetworkKey) {
|
public NetworkTemplate(int matchRule, String subscriberId, String wifiNetworkKey) {
|
||||||
this(matchRule, subscriberId, new String[] { subscriberId }, wifiNetworkKey);
|
this(matchRule, subscriberId, new String[] { subscriberId }, wifiNetworkKey);
|
||||||
}
|
}
|
||||||
@@ -409,17 +329,6 @@ public final class NetworkTemplate implements Parcelable {
|
|||||||
OEM_MANAGED_ALL, NetworkStatsUtils.SUBSCRIBER_ID_MATCH_RULE_EXACT);
|
OEM_MANAGED_ALL, NetworkStatsUtils.SUBSCRIBER_ID_MATCH_RULE_EXACT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
|
||||||
// TODO: Remove it after updating all of the caller.
|
|
||||||
public NetworkTemplate(int matchRule, String subscriberId, String[] matchSubscriberIds,
|
|
||||||
String wifiNetworkKey, int metered, int roaming, int defaultNetwork, int ratType,
|
|
||||||
int oemManaged) {
|
|
||||||
this(matchRule, subscriberId, matchSubscriberIds,
|
|
||||||
wifiNetworkKey != null ? new String[] { wifiNetworkKey } : new String[0],
|
|
||||||
metered, roaming, defaultNetwork, ratType, oemManaged,
|
|
||||||
NetworkStatsUtils.SUBSCRIBER_ID_MATCH_RULE_EXACT);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
public NetworkTemplate(int matchRule, String subscriberId, String[] matchSubscriberIds,
|
public NetworkTemplate(int matchRule, String subscriberId, String[] matchSubscriberIds,
|
||||||
String[] matchWifiNetworkKeys, int metered, int roaming,
|
String[] matchWifiNetworkKeys, int metered, int roaming,
|
||||||
@@ -881,48 +790,29 @@ public final class NetworkTemplate implements Parcelable {
|
|||||||
* For example, given an incoming template matching B, and the currently
|
* For example, given an incoming template matching B, and the currently
|
||||||
* active merge set [A,B], we'd return a new template that primarily matches
|
* active merge set [A,B], we'd return a new template that primarily matches
|
||||||
* A, but also matches B.
|
* A, but also matches B.
|
||||||
* TODO: remove and use {@link #normalize(NetworkTemplate, List)}.
|
|
||||||
*
|
*
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
@UnsupportedAppUsage
|
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.TIRAMISU,
|
||||||
|
publicAlternatives = "There is no alternative for {@code NetworkTemplate.normalize}."
|
||||||
|
+ "Callers should have their own logic to merge template for"
|
||||||
|
+ " different IMSIs and stop calling this function.")
|
||||||
public static NetworkTemplate normalize(NetworkTemplate template, String[] merged) {
|
public static NetworkTemplate normalize(NetworkTemplate template, String[] merged) {
|
||||||
return normalize(template, Arrays.<String[]>asList(merged));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Examine the given template and normalize it.
|
|
||||||
* We pick the "lowest" merged subscriber as the primary
|
|
||||||
* for key purposes, and expand the template to match all other merged
|
|
||||||
* subscribers.
|
|
||||||
*
|
|
||||||
* There can be multiple merged subscriberIds for multi-SIM devices.
|
|
||||||
*
|
|
||||||
* <p>
|
|
||||||
* For example, given an incoming template matching B, and the currently
|
|
||||||
* active merge set [A,B], we'd return a new template that primarily matches
|
|
||||||
* A, but also matches B.
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
// TODO: @SystemApi when ready.
|
|
||||||
public static NetworkTemplate normalize(NetworkTemplate template, List<String[]> mergedList) {
|
|
||||||
// Now there are several types of network which uses SubscriberId to store network
|
// Now there are several types of network which uses SubscriberId to store network
|
||||||
// information. For instances:
|
// information. For instances:
|
||||||
// The TYPE_WIFI with subscriberId means that it is a merged carrier wifi network.
|
// The TYPE_WIFI with subscriberId means that it is a merged carrier wifi network.
|
||||||
// The TYPE_CARRIER means that the network associate to specific carrier network.
|
// The TYPE_CARRIER means that the network associate to specific carrier network.
|
||||||
|
|
||||||
if (template.mSubscriberId == null) return template;
|
if (template.mSubscriberId == null) return template;
|
||||||
|
|
||||||
for (String[] merged : mergedList) {
|
if (CollectionUtils.contains(merged, template.mSubscriberId)) {
|
||||||
if (CollectionUtils.contains(merged, template.mSubscriberId)) {
|
// Requested template subscriber is part of the merge group; return
|
||||||
// Requested template subscriber is part of the merge group; return
|
// a template that matches all merged subscribers.
|
||||||
// a template that matches all merged subscribers.
|
final String[] matchWifiNetworkKeys = template.mMatchWifiNetworkKeys;
|
||||||
final String[] matchWifiNetworkKeys = template.mMatchWifiNetworkKeys;
|
// TODO: Use NetworkTemplate.Builder to build a template after NetworkTemplate
|
||||||
return new NetworkTemplate(template.mMatchRule, merged[0], merged,
|
// could handle incompatible subscriberIds. See b/217805241.
|
||||||
CollectionUtils.isEmpty(matchWifiNetworkKeys)
|
return new NetworkTemplate(template.mMatchRule, merged[0], merged,
|
||||||
? null : matchWifiNetworkKeys[0]);
|
CollectionUtils.isEmpty(matchWifiNetworkKeys)
|
||||||
}
|
? null : matchWifiNetworkKeys[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return template;
|
return template;
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import android.net.NetworkStats.METERED_ALL
|
|||||||
import android.net.NetworkStats.METERED_NO
|
import android.net.NetworkStats.METERED_NO
|
||||||
import android.net.NetworkStats.METERED_YES
|
import android.net.NetworkStats.METERED_YES
|
||||||
import android.net.NetworkStats.ROAMING_ALL
|
import android.net.NetworkStats.ROAMING_ALL
|
||||||
|
import android.net.NetworkTemplate.MATCH_CARRIER
|
||||||
import android.net.NetworkTemplate.MATCH_MOBILE
|
import android.net.NetworkTemplate.MATCH_MOBILE
|
||||||
import android.net.NetworkTemplate.MATCH_MOBILE_WILDCARD
|
import android.net.NetworkTemplate.MATCH_MOBILE_WILDCARD
|
||||||
import android.net.NetworkTemplate.MATCH_TEST
|
import android.net.NetworkTemplate.MATCH_TEST
|
||||||
@@ -41,12 +42,8 @@ import android.net.NetworkTemplate.NETWORK_TYPE_ALL
|
|||||||
import android.net.NetworkTemplate.OEM_MANAGED_ALL
|
import android.net.NetworkTemplate.OEM_MANAGED_ALL
|
||||||
import android.net.NetworkTemplate.OEM_MANAGED_NO
|
import android.net.NetworkTemplate.OEM_MANAGED_NO
|
||||||
import android.net.NetworkTemplate.OEM_MANAGED_YES
|
import android.net.NetworkTemplate.OEM_MANAGED_YES
|
||||||
import android.net.NetworkTemplate.WIFI_NETWORK_KEY_ALL
|
|
||||||
import android.net.NetworkTemplate.buildTemplateCarrierMetered
|
|
||||||
import android.net.NetworkTemplate.buildTemplateMobileAll
|
import android.net.NetworkTemplate.buildTemplateMobileAll
|
||||||
import android.net.NetworkTemplate.buildTemplateMobileWildcard
|
import android.net.NetworkTemplate.buildTemplateMobileWildcard
|
||||||
import android.net.NetworkTemplate.buildTemplateMobileWithRatType
|
|
||||||
import android.net.NetworkTemplate.buildTemplateWifi
|
|
||||||
import android.net.NetworkTemplate.buildTemplateWifiWildcard
|
import android.net.NetworkTemplate.buildTemplateWifiWildcard
|
||||||
import android.net.NetworkTemplate.normalize
|
import android.net.NetworkTemplate.normalize
|
||||||
import android.net.wifi.WifiInfo
|
import android.net.wifi.WifiInfo
|
||||||
@@ -144,10 +141,16 @@ class NetworkTemplateTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testWifiMatches() {
|
fun testWifiMatches() {
|
||||||
val templateWifiKey1 = buildTemplateWifi(TEST_WIFI_KEY1)
|
val templateWifiKey1 = NetworkTemplate.Builder(MATCH_WIFI)
|
||||||
val templateWifiKey1ImsiNull = buildTemplateWifi(TEST_WIFI_KEY1, null)
|
.setWifiNetworkKeys(setOf(TEST_WIFI_KEY1)).build()
|
||||||
val templateWifiKey1Imsi1 = buildTemplateWifi(TEST_WIFI_KEY1, TEST_IMSI1)
|
val templateWifiKey1ImsiNull = NetworkTemplate.Builder(MATCH_WIFI)
|
||||||
val templateWifiKeyAllImsi1 = buildTemplateWifi(WIFI_NETWORK_KEY_ALL, TEST_IMSI1)
|
.setSubscriberIds(setOf(null))
|
||||||
|
.setWifiNetworkKeys(setOf(TEST_WIFI_KEY1)).build()
|
||||||
|
val templateWifiKey1Imsi1 = NetworkTemplate.Builder(MATCH_WIFI)
|
||||||
|
.setSubscriberIds(setOf(TEST_IMSI1))
|
||||||
|
.setWifiNetworkKeys(setOf(TEST_WIFI_KEY1)).build()
|
||||||
|
val templateWifiKeyAllImsi1 = NetworkTemplate.Builder(MATCH_WIFI)
|
||||||
|
.setSubscriberIds(setOf(TEST_IMSI1)).build()
|
||||||
|
|
||||||
val identMobile1 = buildNetworkIdentity(mockContext, buildMobileNetworkState(TEST_IMSI1),
|
val identMobile1 = buildNetworkIdentity(mockContext, buildMobileNetworkState(TEST_IMSI1),
|
||||||
false, TelephonyManager.NETWORK_TYPE_UMTS)
|
false, TelephonyManager.NETWORK_TYPE_UMTS)
|
||||||
@@ -196,8 +199,10 @@ class NetworkTemplateTest {
|
|||||||
@Test
|
@Test
|
||||||
fun testMobileMatches() {
|
fun testMobileMatches() {
|
||||||
val templateMobileImsi1 = buildTemplateMobileAll(TEST_IMSI1)
|
val templateMobileImsi1 = buildTemplateMobileAll(TEST_IMSI1)
|
||||||
val templateMobileImsi2WithRatType = buildTemplateMobileWithRatType(TEST_IMSI2,
|
val templateMobileImsi2WithRatType = NetworkTemplate.Builder(MATCH_MOBILE)
|
||||||
TelephonyManager.NETWORK_TYPE_UMTS, METERED_YES)
|
.setMeteredness(METERED_YES)
|
||||||
|
.setSubscriberIds(setOf(TEST_IMSI2))
|
||||||
|
.setRatType(TelephonyManager.NETWORK_TYPE_UMTS).build()
|
||||||
|
|
||||||
val mobileImsi1 = buildNetworkState(TYPE_MOBILE, TEST_IMSI1, null /* wifiKey */,
|
val mobileImsi1 = buildNetworkState(TYPE_MOBILE, TEST_IMSI1, null /* wifiKey */,
|
||||||
OEM_NONE, true /* metered */)
|
OEM_NONE, true /* metered */)
|
||||||
@@ -225,8 +230,8 @@ class NetworkTemplateTest {
|
|||||||
@Test
|
@Test
|
||||||
fun testMobileWildcardMatches() {
|
fun testMobileWildcardMatches() {
|
||||||
val templateMobileWildcard = buildTemplateMobileWildcard()
|
val templateMobileWildcard = buildTemplateMobileWildcard()
|
||||||
val templateMobileNullImsiWithRatType = buildTemplateMobileWithRatType(null,
|
val templateMobileNullImsiWithRatType = NetworkTemplate.Builder(MATCH_MOBILE)
|
||||||
TelephonyManager.NETWORK_TYPE_UMTS, METERED_ALL)
|
.setRatType(TelephonyManager.NETWORK_TYPE_UMTS).build()
|
||||||
|
|
||||||
val mobileImsi1 = buildMobileNetworkState(TEST_IMSI1)
|
val mobileImsi1 = buildMobileNetworkState(TEST_IMSI1)
|
||||||
val identMobile1 = buildNetworkIdentity(mockContext, mobileImsi1,
|
val identMobile1 = buildNetworkIdentity(mockContext, mobileImsi1,
|
||||||
@@ -277,7 +282,9 @@ class NetworkTemplateTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testCarrierMeteredMatches() {
|
fun testCarrierMeteredMatches() {
|
||||||
val templateCarrierImsi1Metered = buildTemplateCarrierMetered(TEST_IMSI1)
|
val templateCarrierImsi1Metered = NetworkTemplate.Builder(MATCH_CARRIER)
|
||||||
|
.setMeteredness(METERED_YES)
|
||||||
|
.setSubscriberIds(setOf(TEST_IMSI1)).build()
|
||||||
|
|
||||||
val mobileImsi1 = buildMobileNetworkState(TEST_IMSI1)
|
val mobileImsi1 = buildMobileNetworkState(TEST_IMSI1)
|
||||||
val mobileImsi1Unmetered = buildNetworkState(TYPE_MOBILE, TEST_IMSI1,
|
val mobileImsi1Unmetered = buildNetworkState(TYPE_MOBILE, TEST_IMSI1,
|
||||||
@@ -322,24 +329,25 @@ class NetworkTemplateTest {
|
|||||||
|
|
||||||
// Build UMTS template that matches mobile identities with RAT in the same
|
// Build UMTS template that matches mobile identities with RAT in the same
|
||||||
// group with any IMSI. See {@link NetworkTemplate#getCollapsedRatType}.
|
// group with any IMSI. See {@link NetworkTemplate#getCollapsedRatType}.
|
||||||
val templateUmtsMetered = buildTemplateMobileWithRatType(null,
|
val templateUmtsMetered = NetworkTemplate.Builder(MATCH_MOBILE)
|
||||||
TelephonyManager.NETWORK_TYPE_UMTS, METERED_YES)
|
.setMeteredness(METERED_YES)
|
||||||
|
.setRatType(TelephonyManager.NETWORK_TYPE_UMTS).build()
|
||||||
// Build normal template that matches mobile identities with any RAT and IMSI.
|
// Build normal template that matches mobile identities with any RAT and IMSI.
|
||||||
val templateAllMetered = buildTemplateMobileWithRatType(null, NETWORK_TYPE_ALL,
|
val templateAllMetered = NetworkTemplate.Builder(MATCH_MOBILE)
|
||||||
METERED_YES)
|
.setMeteredness(METERED_YES).build()
|
||||||
// Build template with UNKNOWN RAT that matches mobile identities with RAT that
|
// Build template with UNKNOWN RAT that matches mobile identities with RAT that
|
||||||
// cannot be determined.
|
// cannot be determined.
|
||||||
val templateUnknownMetered =
|
val templateUnknownMetered = NetworkTemplate.Builder(MATCH_MOBILE)
|
||||||
buildTemplateMobileWithRatType(null, TelephonyManager.NETWORK_TYPE_UNKNOWN,
|
.setMeteredness(METERED_YES)
|
||||||
METERED_YES)
|
.setRatType(TelephonyManager.NETWORK_TYPE_UNKNOWN).build()
|
||||||
|
val templateUmtsNonMetered = NetworkTemplate.Builder(MATCH_MOBILE)
|
||||||
val templateUmtsNonMetered = buildTemplateMobileWithRatType(null,
|
.setMeteredness(METERED_NO)
|
||||||
TelephonyManager.NETWORK_TYPE_UMTS, METERED_NO)
|
.setRatType(TelephonyManager.NETWORK_TYPE_UMTS).build()
|
||||||
val templateAllNonMetered = buildTemplateMobileWithRatType(null, NETWORK_TYPE_ALL,
|
val templateAllNonMetered = NetworkTemplate.Builder(MATCH_MOBILE)
|
||||||
METERED_NO)
|
.setMeteredness(METERED_NO).build()
|
||||||
val templateUnknownNonMetered =
|
val templateUnknownNonMetered = NetworkTemplate.Builder(MATCH_MOBILE)
|
||||||
buildTemplateMobileWithRatType(null, TelephonyManager.NETWORK_TYPE_UNKNOWN,
|
.setMeteredness(METERED_NO)
|
||||||
METERED_NO)
|
.setRatType(TelephonyManager.NETWORK_TYPE_UNKNOWN).build()
|
||||||
|
|
||||||
val identUmtsMetered = buildNetworkIdentity(
|
val identUmtsMetered = buildNetworkIdentity(
|
||||||
mockContext, stateMobileImsi1Metered, false, TelephonyManager.NETWORK_TYPE_UMTS)
|
mockContext, stateMobileImsi1Metered, false, TelephonyManager.NETWORK_TYPE_UMTS)
|
||||||
@@ -553,7 +561,7 @@ class NetworkTemplateTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testNormalize() {
|
fun testNormalize() {
|
||||||
var mergedImsiList = listOf(arrayOf(TEST_IMSI1, TEST_IMSI2))
|
var mergedImsiList = arrayOf(TEST_IMSI1, TEST_IMSI2)
|
||||||
val identMobileImsi1 = buildNetworkIdentity(mockContext,
|
val identMobileImsi1 = buildNetworkIdentity(mockContext,
|
||||||
buildMobileNetworkState(TEST_IMSI1), false /* defaultNetwork */,
|
buildMobileNetworkState(TEST_IMSI1), false /* defaultNetwork */,
|
||||||
TelephonyManager.NETWORK_TYPE_UMTS)
|
TelephonyManager.NETWORK_TYPE_UMTS)
|
||||||
@@ -575,12 +583,18 @@ class NetworkTemplateTest {
|
|||||||
it.assertMatches(identMobileImsi2)
|
it.assertMatches(identMobileImsi2)
|
||||||
it.assertDoesNotMatch(identMobileImsi3)
|
it.assertDoesNotMatch(identMobileImsi3)
|
||||||
}
|
}
|
||||||
normalize(buildTemplateCarrierMetered(TEST_IMSI1), mergedImsiList).also {
|
val templateCarrierImsi1 = NetworkTemplate.Builder(MATCH_CARRIER)
|
||||||
|
.setMeteredness(METERED_YES)
|
||||||
|
.setSubscriberIds(setOf(TEST_IMSI1)).build()
|
||||||
|
normalize(templateCarrierImsi1, mergedImsiList).also {
|
||||||
it.assertMatches(identMobileImsi1)
|
it.assertMatches(identMobileImsi1)
|
||||||
it.assertMatches(identMobileImsi2)
|
it.assertMatches(identMobileImsi2)
|
||||||
it.assertDoesNotMatch(identMobileImsi3)
|
it.assertDoesNotMatch(identMobileImsi3)
|
||||||
}
|
}
|
||||||
normalize(buildTemplateWifi(TEST_WIFI_KEY1, TEST_IMSI1), mergedImsiList).also {
|
val templateWifiKey1Imsi1 = NetworkTemplate.Builder(MATCH_WIFI)
|
||||||
|
.setWifiNetworkKeys(setOf(TEST_WIFI_KEY1))
|
||||||
|
.setSubscriberIds(setOf(TEST_IMSI1)).build()
|
||||||
|
normalize(templateWifiKey1Imsi1, mergedImsiList).also {
|
||||||
it.assertMatches(identWifiImsi1Key1)
|
it.assertMatches(identWifiImsi1Key1)
|
||||||
it.assertMatches(identWifiImsi2Key1)
|
it.assertMatches(identWifiImsi2Key1)
|
||||||
it.assertDoesNotMatch(identWifiImsi3WifiKey1)
|
it.assertDoesNotMatch(identWifiImsi3WifiKey1)
|
||||||
|
|||||||
Reference in New Issue
Block a user