Restore the null behavior of buildWifiTemplate
The old behavior was to only return those wifis that have a null key/subscriber ID (e.g. not carrier wifi). To keep backward compatibility, restore that behavior. Also only crash the old methods on devices with initial SDK U, because it can't be mandated that devices that upgrade must not call these methods. Bug: 273963543 Test: FrameworksNetTests Merged-In: Iefb976ed86a732158964fae38e9e601001c2637a Change-Id: Iefb976ed86a732158964fae38e9e601001c2637a
This commit is contained in:
committed by
Remi NGUYEN VAN
parent
6e12ac60b8
commit
843cd6ca48
@@ -184,6 +184,23 @@ public final class NetworkTemplate implements Parcelable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Set<String> setOf(@Nullable final String item) {
|
||||||
|
if (item == null) {
|
||||||
|
// Set.of will throw if item is null
|
||||||
|
final Set<String> set = new HashSet<>();
|
||||||
|
set.add(null);
|
||||||
|
return Collections.unmodifiableSet(set);
|
||||||
|
} else {
|
||||||
|
return Set.of(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void throwAboveU() {
|
||||||
|
if (SdkLevel.isAtLeastU()) {
|
||||||
|
throw new UnsupportedOperationException("Method not supported on Android U or above");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Template to match {@link ConnectivityManager#TYPE_MOBILE} networks with
|
* Template to match {@link ConnectivityManager#TYPE_MOBILE} networks with
|
||||||
* the given IMSI.
|
* the given IMSI.
|
||||||
@@ -195,22 +212,8 @@ public final class NetworkTemplate implements Parcelable {
|
|||||||
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.TIRAMISU,
|
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.TIRAMISU,
|
||||||
publicAlternatives = "Use {@code Builder} instead.")
|
publicAlternatives = "Use {@code Builder} instead.")
|
||||||
public static NetworkTemplate buildTemplateMobileAll(@NonNull String subscriberId) {
|
public static NetworkTemplate buildTemplateMobileAll(@NonNull String subscriberId) {
|
||||||
final Set<String> set;
|
|
||||||
// Prevent from crash for b/273963543, where the OEMs still call into this method
|
|
||||||
// with null subscriberId and get crashed.
|
|
||||||
final int firstSdk = Build.VERSION.DEVICE_INITIAL_SDK_INT;
|
|
||||||
if (firstSdk > Build.VERSION_CODES.TIRAMISU && subscriberId == null) {
|
|
||||||
throw new IllegalArgumentException("buildTemplateMobileAll does not accept null"
|
|
||||||
+ " subscriberId on Android U devices or above");
|
|
||||||
}
|
|
||||||
if (subscriberId == null) {
|
|
||||||
set = new HashSet<>();
|
|
||||||
set.add(null);
|
|
||||||
} else {
|
|
||||||
set = Set.of(subscriberId);
|
|
||||||
}
|
|
||||||
return new NetworkTemplate.Builder(MATCH_MOBILE).setMeteredness(METERED_YES)
|
return new NetworkTemplate.Builder(MATCH_MOBILE).setMeteredness(METERED_YES)
|
||||||
.setSubscriberIds(set).build();
|
.setSubscriberIds(setOf(subscriberId)).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -274,10 +277,8 @@ public final class NetworkTemplate implements Parcelable {
|
|||||||
// TODO(b/270089918): Remove this method. This can only be done after there are no more callers,
|
// TODO(b/270089918): Remove this method. This can only be done after there are no more callers,
|
||||||
// including in OEM code which can access this by linking against the framework.
|
// including in OEM code which can access this by linking against the framework.
|
||||||
public static NetworkTemplate buildTemplateBluetooth() {
|
public static NetworkTemplate buildTemplateBluetooth() {
|
||||||
if (SdkLevel.isAtLeastU()) {
|
// TODO : this is part of hidden-o txt, does that mean it should be annotated with
|
||||||
throw new UnsupportedOperationException(
|
// @UnsupportedAppUsage(maxTargetSdk = O) ? If yes, can't throwAboveU().
|
||||||
"buildTemplateBluetooth is not supported on Android U devices or above");
|
|
||||||
}
|
|
||||||
return new NetworkTemplate.Builder(MATCH_BLUETOOTH).build();
|
return new NetworkTemplate.Builder(MATCH_BLUETOOTH).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -290,10 +291,8 @@ public final class NetworkTemplate implements Parcelable {
|
|||||||
// TODO(b/270089918): Remove this method. This can only be done after there are no more callers,
|
// TODO(b/270089918): Remove this method. This can only be done after there are no more callers,
|
||||||
// including in OEM code which can access this by linking against the framework.
|
// including in OEM code which can access this by linking against the framework.
|
||||||
public static NetworkTemplate buildTemplateProxy() {
|
public static NetworkTemplate buildTemplateProxy() {
|
||||||
if (SdkLevel.isAtLeastU()) {
|
// TODO : this is part of hidden-o txt, does that mean it should be annotated with
|
||||||
throw new UnsupportedOperationException(
|
// @UnsupportedAppUsage(maxTargetSdk = O) ? If yes, can't throwAboveU().
|
||||||
"buildTemplateProxy is not supported on Android U devices or above");
|
|
||||||
}
|
|
||||||
return new NetworkTemplate(MATCH_PROXY, null, null);
|
return new NetworkTemplate(MATCH_PROXY, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -305,10 +304,7 @@ public final class NetworkTemplate implements Parcelable {
|
|||||||
// TODO(b/273963543): Remove this method. This can only be done after there are no more callers,
|
// TODO(b/273963543): Remove this method. This can only be done after there are no more callers,
|
||||||
// including in OEM code which can access this by linking against the framework.
|
// including in OEM code which can access this by linking against the framework.
|
||||||
public static NetworkTemplate buildTemplateCarrierMetered(@NonNull String subscriberId) {
|
public static NetworkTemplate buildTemplateCarrierMetered(@NonNull String subscriberId) {
|
||||||
if (SdkLevel.isAtLeastU()) {
|
throwAboveU();
|
||||||
throw new UnsupportedOperationException(
|
|
||||||
"buildTemplateCarrierMetered is not supported on Android U devices or above");
|
|
||||||
}
|
|
||||||
return new NetworkTemplate.Builder(MATCH_CARRIER)
|
return new NetworkTemplate.Builder(MATCH_CARRIER)
|
||||||
// Set.of will throw if subscriberId is null
|
// Set.of will throw if subscriberId is null
|
||||||
.setSubscriberIds(Set.of(subscriberId))
|
.setSubscriberIds(Set.of(subscriberId))
|
||||||
@@ -327,10 +323,7 @@ public final class NetworkTemplate implements Parcelable {
|
|||||||
// including in OEM code which can access this by linking against the framework.
|
// including in OEM code which can access this by linking against the framework.
|
||||||
public static NetworkTemplate buildTemplateMobileWithRatType(@Nullable String subscriberId,
|
public static NetworkTemplate buildTemplateMobileWithRatType(@Nullable String subscriberId,
|
||||||
int ratType, int metered) {
|
int ratType, int metered) {
|
||||||
if (SdkLevel.isAtLeastU()) {
|
throwAboveU();
|
||||||
throw new UnsupportedOperationException("buildTemplateMobileWithRatType is not "
|
|
||||||
+ "supported on Android U devices or above");
|
|
||||||
}
|
|
||||||
return new NetworkTemplate.Builder(MATCH_MOBILE)
|
return new NetworkTemplate.Builder(MATCH_MOBILE)
|
||||||
.setSubscriberIds(TextUtils.isEmpty(subscriberId)
|
.setSubscriberIds(TextUtils.isEmpty(subscriberId)
|
||||||
? Collections.emptySet()
|
? Collections.emptySet()
|
||||||
@@ -340,7 +333,6 @@ public final class NetworkTemplate implements Parcelable {
|
|||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Template to match {@link ConnectivityManager#TYPE_WIFI} networks with the
|
* Template to match {@link ConnectivityManager#TYPE_WIFI} networks with the
|
||||||
* given key of the wifi network.
|
* given key of the wifi network.
|
||||||
@@ -352,12 +344,9 @@ public final class NetworkTemplate implements Parcelable {
|
|||||||
// TODO(b/273963543): Remove this method. This can only be done after there are no more callers,
|
// TODO(b/273963543): Remove this method. This can only be done after there are no more callers,
|
||||||
// including in OEM code which can access this by linking against the framework.
|
// including in OEM code which can access this by linking against the framework.
|
||||||
public static NetworkTemplate buildTemplateWifi(@NonNull String wifiNetworkKey) {
|
public static NetworkTemplate buildTemplateWifi(@NonNull String wifiNetworkKey) {
|
||||||
if (SdkLevel.isAtLeastU()) {
|
// TODO : this is part of hidden-o txt, does that mean it should be annotated with
|
||||||
throw new UnsupportedOperationException("buildTemplateWifi is not "
|
// @UnsupportedAppUsage(maxTargetSdk = O) ? If yes, can't throwAboveU().
|
||||||
+ "supported on Android U devices or above");
|
|
||||||
}
|
|
||||||
return new NetworkTemplate.Builder(MATCH_WIFI)
|
return new NetworkTemplate.Builder(MATCH_WIFI)
|
||||||
// Set.of will throw if wifiNetworkKey is null
|
|
||||||
.setWifiNetworkKeys(Set.of(wifiNetworkKey))
|
.setWifiNetworkKeys(Set.of(wifiNetworkKey))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
@@ -379,14 +368,9 @@ public final class NetworkTemplate implements Parcelable {
|
|||||||
// including in OEM code which can access this by linking against the framework.
|
// including in OEM code which can access this by linking against the framework.
|
||||||
public static NetworkTemplate buildTemplateWifi(@Nullable String wifiNetworkKey,
|
public static NetworkTemplate buildTemplateWifi(@Nullable String wifiNetworkKey,
|
||||||
@Nullable String subscriberId) {
|
@Nullable String subscriberId) {
|
||||||
if (SdkLevel.isAtLeastU()) {
|
throwAboveU();
|
||||||
throw new UnsupportedOperationException("buildTemplateWifi is not "
|
|
||||||
+ "supported on Android U devices or above");
|
|
||||||
}
|
|
||||||
return new NetworkTemplate.Builder(MATCH_WIFI)
|
return new NetworkTemplate.Builder(MATCH_WIFI)
|
||||||
.setSubscriberIds(subscriberId == null
|
.setSubscriberIds(setOf(subscriberId))
|
||||||
? Collections.emptySet()
|
|
||||||
: Set.of(subscriberId))
|
|
||||||
.setWifiNetworkKeys(wifiNetworkKey == null
|
.setWifiNetworkKeys(wifiNetworkKey == null
|
||||||
? Collections.emptySet()
|
? Collections.emptySet()
|
||||||
: Set.of(wifiNetworkKey))
|
: Set.of(wifiNetworkKey))
|
||||||
@@ -471,10 +455,6 @@ public final class NetworkTemplate implements Parcelable {
|
|||||||
if (matchRule == 6 || matchRule == 7) {
|
if (matchRule == 6 || matchRule == 7) {
|
||||||
Log.e(TAG, "Use MATCH_MOBILE with empty subscriberIds or MATCH_WIFI with empty "
|
Log.e(TAG, "Use MATCH_MOBILE with empty subscriberIds or MATCH_WIFI with empty "
|
||||||
+ "wifiNetworkKeys instead of template with matchRule=" + matchRule);
|
+ "wifiNetworkKeys instead of template with matchRule=" + matchRule);
|
||||||
if (SdkLevel.isAtLeastU()) {
|
|
||||||
throw new UnsupportedOperationException(
|
|
||||||
"Wildcard templates are not supported on Android U devices or above");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -508,10 +488,8 @@ public final class NetworkTemplate implements Parcelable {
|
|||||||
getMeterednessForBackwardsCompatibility(matchRule),
|
getMeterednessForBackwardsCompatibility(matchRule),
|
||||||
ROAMING_ALL, DEFAULT_NETWORK_ALL, NETWORK_TYPE_ALL,
|
ROAMING_ALL, DEFAULT_NETWORK_ALL, NETWORK_TYPE_ALL,
|
||||||
OEM_MANAGED_ALL);
|
OEM_MANAGED_ALL);
|
||||||
if (SdkLevel.isAtLeastU()) {
|
// TODO : this is part of hidden-o txt, does that mean it should be annotated with
|
||||||
throw new UnsupportedOperationException(
|
// @UnsupportedAppUsage(maxTargetSdk = O) ? If yes, can't throwAboveU().
|
||||||
"This constructor is not supported on Android U devices or above");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
@@ -526,10 +504,7 @@ public final class NetworkTemplate implements Parcelable {
|
|||||||
this(getBackwardsCompatibleMatchRule(matchRule),
|
this(getBackwardsCompatibleMatchRule(matchRule),
|
||||||
matchSubscriberIds == null ? new String[]{} : matchSubscriberIds,
|
matchSubscriberIds == null ? new String[]{} : matchSubscriberIds,
|
||||||
matchWifiNetworkKeys, metered, roaming, defaultNetwork, ratType, oemManaged);
|
matchWifiNetworkKeys, metered, roaming, defaultNetwork, ratType, oemManaged);
|
||||||
if (SdkLevel.isAtLeastU()) {
|
throwAboveU();
|
||||||
throw new UnsupportedOperationException(
|
|
||||||
"This constructor is not supported on Android U devices or above");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
@@ -636,10 +611,8 @@ public final class NetworkTemplate implements Parcelable {
|
|||||||
// including in OEM code which can access this by linking against the framework.
|
// including in OEM code which can access this by linking against the framework.
|
||||||
/** @hide */
|
/** @hide */
|
||||||
public boolean isMatchRuleMobile() {
|
public boolean isMatchRuleMobile() {
|
||||||
if (SdkLevel.isAtLeastU()) {
|
// TODO : this is part of hidden-o txt, does that mean it should be annotated with
|
||||||
throw new UnsupportedOperationException(
|
// @UnsupportedAppUsage(maxTargetSdk = O) ? If yes, can't throwAboveU().
|
||||||
"isMatchRuleMobile is not supported on Android U devices or above");
|
|
||||||
}
|
|
||||||
switch (mMatchRule) {
|
switch (mMatchRule) {
|
||||||
case MATCH_MOBILE:
|
case MATCH_MOBILE:
|
||||||
// Old MATCH_MOBILE_WILDCARD
|
// Old MATCH_MOBILE_WILDCARD
|
||||||
@@ -981,10 +954,7 @@ public final class NetworkTemplate implements Parcelable {
|
|||||||
// TODO(b/273963543): Remove this method. This can only be done after there are no more callers,
|
// TODO(b/273963543): Remove this method. This can only be done after there are no more callers,
|
||||||
// including in OEM code which can access this by linking against the framework.
|
// including in OEM code which can access this by linking against the framework.
|
||||||
public static NetworkTemplate normalize(NetworkTemplate template, List<String[]> mergedList) {
|
public static NetworkTemplate normalize(NetworkTemplate template, List<String[]> mergedList) {
|
||||||
if (SdkLevel.isAtLeastU()) {
|
throwAboveU();
|
||||||
throw new UnsupportedOperationException(
|
|
||||||
"normalize is not supported on Android U devices or above");
|
|
||||||
}
|
|
||||||
return normalizeImpl(template, mergedList);
|
return normalizeImpl(template, mergedList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user