Merge "[MS15.1] Remove get/setSubscriberIdMatchRule dependencies" am: d159c1ead7 am: d0c50a49e0
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1926944 Change-Id: I6336d13c19ad2e7089e68ba30b1da38df957a35d
This commit is contained in:
@@ -23,7 +23,6 @@ import static android.net.NetworkTemplate.MATCH_CARRIER;
|
|||||||
import static android.net.NetworkTemplate.MATCH_ETHERNET;
|
import static android.net.NetworkTemplate.MATCH_ETHERNET;
|
||||||
import static android.net.NetworkTemplate.MATCH_MOBILE;
|
import static android.net.NetworkTemplate.MATCH_MOBILE;
|
||||||
import static android.net.NetworkTemplate.MATCH_WIFI;
|
import static android.net.NetworkTemplate.MATCH_WIFI;
|
||||||
import static android.net.NetworkTemplate.SUBSCRIBER_ID_MATCH_RULE_EXACT;
|
|
||||||
|
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
@@ -45,6 +44,7 @@ import java.time.ZoneId;
|
|||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Policy for networks matching a {@link NetworkTemplate}, including usage cycle
|
* Policy for networks matching a {@link NetworkTemplate}, including usage cycle
|
||||||
@@ -62,15 +62,16 @@ public class NetworkPolicy implements Parcelable, Comparable<NetworkPolicy> {
|
|||||||
* Initial Version of the NetworkTemplate backup serializer.
|
* Initial Version of the NetworkTemplate backup serializer.
|
||||||
*/
|
*/
|
||||||
private static final int TEMPLATE_BACKUP_VERSION_1_INIT = 1;
|
private static final int TEMPLATE_BACKUP_VERSION_1_INIT = 1;
|
||||||
|
private static final int TEMPLATE_BACKUP_VERSION_2_UNSUPPORTED = 2;
|
||||||
/**
|
/**
|
||||||
* Version of the NetworkTemplate backup serializer that added carrier template support.
|
* Version of the NetworkTemplate backup serializer that added carrier template support.
|
||||||
*/
|
*/
|
||||||
private static final int TEMPLATE_BACKUP_VERSION_2_SUPPORT_CARRIER_TEMPLATE = 2;
|
private static final int TEMPLATE_BACKUP_VERSION_3_SUPPORT_CARRIER_TEMPLATE = 3;
|
||||||
/**
|
/**
|
||||||
* Latest Version of the NetworkTemplate Backup Serializer.
|
* Latest Version of the NetworkTemplate Backup Serializer.
|
||||||
*/
|
*/
|
||||||
private static final int TEMPLATE_BACKUP_VERSION_LATEST =
|
private static final int TEMPLATE_BACKUP_VERSION_LATEST =
|
||||||
TEMPLATE_BACKUP_VERSION_2_SUPPORT_CARRIER_TEMPLATE;
|
TEMPLATE_BACKUP_VERSION_3_SUPPORT_CARRIER_TEMPLATE;
|
||||||
|
|
||||||
public static final int CYCLE_NONE = -1;
|
public static final int CYCLE_NONE = -1;
|
||||||
public static final long WARNING_DISABLED = -1;
|
public static final long WARNING_DISABLED = -1;
|
||||||
@@ -337,10 +338,9 @@ public class NetworkPolicy implements Parcelable, Comparable<NetworkPolicy> {
|
|||||||
out.writeInt(TEMPLATE_BACKUP_VERSION_LATEST);
|
out.writeInt(TEMPLATE_BACKUP_VERSION_LATEST);
|
||||||
|
|
||||||
out.writeInt(template.getMatchRule());
|
out.writeInt(template.getMatchRule());
|
||||||
BackupUtils.writeString(out, template.getSubscriberId());
|
BackupUtils.writeString(out, template.getSubscriberIds().iterator().next());
|
||||||
BackupUtils.writeString(out, template.getNetworkId());
|
BackupUtils.writeString(out, template.getWifiNetworkKey());
|
||||||
out.writeInt(template.getMeteredness());
|
out.writeInt(template.getMeteredness());
|
||||||
out.writeInt(template.getSubscriberIdMatchRule());
|
|
||||||
|
|
||||||
return baos.toByteArray();
|
return baos.toByteArray();
|
||||||
}
|
}
|
||||||
@@ -349,33 +349,32 @@ public class NetworkPolicy implements Parcelable, Comparable<NetworkPolicy> {
|
|||||||
private static NetworkTemplate getNetworkTemplateFromBackup(DataInputStream in)
|
private static NetworkTemplate getNetworkTemplateFromBackup(DataInputStream in)
|
||||||
throws IOException, BackupUtils.BadVersionException {
|
throws IOException, BackupUtils.BadVersionException {
|
||||||
int version = in.readInt();
|
int version = in.readInt();
|
||||||
if (version < TEMPLATE_BACKUP_VERSION_1_INIT || version > TEMPLATE_BACKUP_VERSION_LATEST) {
|
if (version < TEMPLATE_BACKUP_VERSION_1_INIT || version > TEMPLATE_BACKUP_VERSION_LATEST
|
||||||
|
|| version == TEMPLATE_BACKUP_VERSION_2_UNSUPPORTED) {
|
||||||
throw new BackupUtils.BadVersionException("Unknown Backup Serialization Version");
|
throw new BackupUtils.BadVersionException("Unknown Backup Serialization Version");
|
||||||
}
|
}
|
||||||
|
|
||||||
int matchRule = in.readInt();
|
int matchRule = in.readInt();
|
||||||
final String subscriberId = BackupUtils.readString(in);
|
final String subscriberId = BackupUtils.readString(in);
|
||||||
final String networkId = BackupUtils.readString(in);
|
final String wifiNetworkKey = BackupUtils.readString(in);
|
||||||
|
|
||||||
final int metered;
|
final int metered;
|
||||||
final int subscriberIdMatchRule;
|
if (version >= TEMPLATE_BACKUP_VERSION_3_SUPPORT_CARRIER_TEMPLATE) {
|
||||||
if (version >= TEMPLATE_BACKUP_VERSION_2_SUPPORT_CARRIER_TEMPLATE) {
|
|
||||||
metered = in.readInt();
|
metered = in.readInt();
|
||||||
subscriberIdMatchRule = in.readInt();
|
|
||||||
} else {
|
} else {
|
||||||
// For backward compatibility, fill the missing filters from match rules.
|
// For backward compatibility, fill the missing filters from match rules.
|
||||||
metered = (matchRule == MATCH_MOBILE
|
metered = (matchRule == MATCH_MOBILE || matchRule == MATCH_CARRIER)
|
||||||
|| matchRule == NetworkTemplate.MATCH_MOBILE_WILDCARD
|
? METERED_YES : METERED_ALL;
|
||||||
|| matchRule == MATCH_CARRIER) ? METERED_YES : METERED_ALL;
|
|
||||||
subscriberIdMatchRule = SUBSCRIBER_ID_MATCH_RULE_EXACT;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return new NetworkTemplate(matchRule,
|
final NetworkTemplate.Builder builder = new NetworkTemplate.Builder(matchRule)
|
||||||
subscriberId, new String[]{subscriberId},
|
.setWifiNetworkKey(wifiNetworkKey)
|
||||||
networkId, metered, NetworkStats.ROAMING_ALL,
|
.setMeteredness(metered);
|
||||||
NetworkStats.DEFAULT_NETWORK_ALL, NetworkTemplate.NETWORK_TYPE_ALL,
|
if (subscriberId != null) {
|
||||||
NetworkTemplate.OEM_MANAGED_ALL, subscriberIdMatchRule);
|
builder.setSubscriberIds(Set.of(subscriberId));
|
||||||
|
}
|
||||||
|
return builder.build();
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
throw new BackupUtils.BadVersionException(
|
throw new BackupUtils.BadVersionException(
|
||||||
"Restored network template contains unknown match rule " + matchRule, e);
|
"Restored network template contains unknown match rule " + matchRule, e);
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ import android.util.ArraySet;
|
|||||||
|
|
||||||
import com.android.internal.util.ArrayUtils;
|
import com.android.internal.util.ArrayUtils;
|
||||||
import com.android.net.module.util.NetworkIdentityUtils;
|
import com.android.net.module.util.NetworkIdentityUtils;
|
||||||
|
import com.android.net.module.util.NetworkStatsUtils;
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
@@ -114,27 +115,6 @@ public final class NetworkTemplate implements Parcelable {
|
|||||||
*/
|
*/
|
||||||
public static final int MATCH_CARRIER = 10;
|
public static final int MATCH_CARRIER = 10;
|
||||||
|
|
||||||
/** @hide */
|
|
||||||
@Retention(RetentionPolicy.SOURCE)
|
|
||||||
@IntDef(prefix = { "SUBSCRIBER_ID_MATCH_RULE_" }, value = {
|
|
||||||
SUBSCRIBER_ID_MATCH_RULE_EXACT,
|
|
||||||
SUBSCRIBER_ID_MATCH_RULE_ALL
|
|
||||||
})
|
|
||||||
public @interface SubscriberIdMatchRule{}
|
|
||||||
/**
|
|
||||||
* Value of the match rule of the subscriberId to match networks with specific subscriberId.
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public static final int SUBSCRIBER_ID_MATCH_RULE_EXACT = 0;
|
|
||||||
/**
|
|
||||||
* Value of the match rule of the subscriberId to match networks with any subscriberId which
|
|
||||||
* includes null and non-null.
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public static final int SUBSCRIBER_ID_MATCH_RULE_ALL = 1;
|
|
||||||
|
|
||||||
// TODO: Remove this and replace all callers with WIFI_NETWORK_KEY_ALL.
|
// TODO: Remove this and replace all callers with WIFI_NETWORK_KEY_ALL.
|
||||||
/** @hide */
|
/** @hide */
|
||||||
public static final String WIFI_NETWORKID_ALL = null;
|
public static final String WIFI_NETWORKID_ALL = null;
|
||||||
@@ -235,11 +215,11 @@ public final class NetworkTemplate implements Parcelable {
|
|||||||
if (TextUtils.isEmpty(subscriberId)) {
|
if (TextUtils.isEmpty(subscriberId)) {
|
||||||
return new NetworkTemplate(MATCH_MOBILE_WILDCARD, null, null, null,
|
return new NetworkTemplate(MATCH_MOBILE_WILDCARD, null, null, null,
|
||||||
metered, ROAMING_ALL, DEFAULT_NETWORK_ALL, ratType, OEM_MANAGED_ALL,
|
metered, ROAMING_ALL, DEFAULT_NETWORK_ALL, ratType, OEM_MANAGED_ALL,
|
||||||
SUBSCRIBER_ID_MATCH_RULE_EXACT);
|
NetworkStatsUtils.SUBSCRIBER_ID_MATCH_RULE_EXACT);
|
||||||
}
|
}
|
||||||
return new NetworkTemplate(MATCH_MOBILE, subscriberId, new String[]{subscriberId}, null,
|
return new NetworkTemplate(MATCH_MOBILE, subscriberId, new String[]{subscriberId}, null,
|
||||||
metered, ROAMING_ALL, DEFAULT_NETWORK_ALL, ratType, OEM_MANAGED_ALL,
|
metered, ROAMING_ALL, DEFAULT_NETWORK_ALL, ratType, OEM_MANAGED_ALL,
|
||||||
SUBSCRIBER_ID_MATCH_RULE_EXACT);
|
NetworkStatsUtils.SUBSCRIBER_ID_MATCH_RULE_EXACT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -285,7 +265,7 @@ public final class NetworkTemplate implements Parcelable {
|
|||||||
new String[] { null } /* matchSubscriberIds */,
|
new String[] { null } /* matchSubscriberIds */,
|
||||||
networkId, METERED_ALL, ROAMING_ALL,
|
networkId, METERED_ALL, ROAMING_ALL,
|
||||||
DEFAULT_NETWORK_ALL, NETWORK_TYPE_ALL, OEM_MANAGED_ALL,
|
DEFAULT_NETWORK_ALL, NETWORK_TYPE_ALL, OEM_MANAGED_ALL,
|
||||||
SUBSCRIBER_ID_MATCH_RULE_ALL);
|
NetworkStatsUtils.SUBSCRIBER_ID_MATCH_RULE_ALL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -302,7 +282,7 @@ public final class NetworkTemplate implements Parcelable {
|
|||||||
return new NetworkTemplate(MATCH_WIFI, subscriberId, new String[] { subscriberId },
|
return new NetworkTemplate(MATCH_WIFI, subscriberId, new String[] { subscriberId },
|
||||||
networkId, METERED_ALL, ROAMING_ALL,
|
networkId, METERED_ALL, ROAMING_ALL,
|
||||||
DEFAULT_NETWORK_ALL, NETWORK_TYPE_ALL, OEM_MANAGED_ALL,
|
DEFAULT_NETWORK_ALL, NETWORK_TYPE_ALL, OEM_MANAGED_ALL,
|
||||||
SUBSCRIBER_ID_MATCH_RULE_EXACT);
|
NetworkStatsUtils.SUBSCRIBER_ID_MATCH_RULE_EXACT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -346,7 +326,7 @@ public final class NetworkTemplate implements Parcelable {
|
|||||||
return new NetworkTemplate(MATCH_CARRIER, subscriberId,
|
return new NetworkTemplate(MATCH_CARRIER, subscriberId,
|
||||||
new String[] { subscriberId }, null /* networkId */, METERED_YES, ROAMING_ALL,
|
new String[] { subscriberId }, null /* networkId */, METERED_YES, ROAMING_ALL,
|
||||||
DEFAULT_NETWORK_ALL, NETWORK_TYPE_ALL, OEM_MANAGED_ALL,
|
DEFAULT_NETWORK_ALL, NETWORK_TYPE_ALL, OEM_MANAGED_ALL,
|
||||||
SUBSCRIBER_ID_MATCH_RULE_EXACT);
|
NetworkStatsUtils.SUBSCRIBER_ID_MATCH_RULE_EXACT);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final int mMatchRule;
|
private final int mMatchRule;
|
||||||
@@ -384,7 +364,7 @@ public final class NetworkTemplate implements Parcelable {
|
|||||||
case MATCH_MOBILE:
|
case MATCH_MOBILE:
|
||||||
case MATCH_CARRIER:
|
case MATCH_CARRIER:
|
||||||
// MOBILE and CARRIER templates must always specify a subscriber ID.
|
// MOBILE and CARRIER templates must always specify a subscriber ID.
|
||||||
if (subscriberIdMatchRule == SUBSCRIBER_ID_MATCH_RULE_ALL) {
|
if (subscriberIdMatchRule == NetworkStatsUtils.SUBSCRIBER_ID_MATCH_RULE_ALL) {
|
||||||
throw new IllegalArgumentException("Invalid SubscriberIdMatchRule "
|
throw new IllegalArgumentException("Invalid SubscriberIdMatchRule "
|
||||||
+ "on match rule: " + getMatchRuleName(matchRule));
|
+ "on match rule: " + getMatchRuleName(matchRule));
|
||||||
}
|
}
|
||||||
@@ -411,7 +391,7 @@ public final class NetworkTemplate implements Parcelable {
|
|||||||
this(matchRule, subscriberId, matchSubscriberIds, networkId,
|
this(matchRule, subscriberId, matchSubscriberIds, networkId,
|
||||||
(matchRule == MATCH_MOBILE || matchRule == MATCH_MOBILE_WILDCARD) ? METERED_YES
|
(matchRule == MATCH_MOBILE || matchRule == MATCH_MOBILE_WILDCARD) ? METERED_YES
|
||||||
: METERED_ALL , ROAMING_ALL, DEFAULT_NETWORK_ALL, NETWORK_TYPE_ALL,
|
: METERED_ALL , ROAMING_ALL, DEFAULT_NETWORK_ALL, NETWORK_TYPE_ALL,
|
||||||
OEM_MANAGED_ALL, SUBSCRIBER_ID_MATCH_RULE_EXACT);
|
OEM_MANAGED_ALL, NetworkStatsUtils.SUBSCRIBER_ID_MATCH_RULE_EXACT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
@@ -420,7 +400,8 @@ public final class NetworkTemplate implements Parcelable {
|
|||||||
String networkId, int metered, int roaming, int defaultNetwork, int subType,
|
String networkId, int metered, int roaming, int defaultNetwork, int subType,
|
||||||
int oemManaged) {
|
int oemManaged) {
|
||||||
this(matchRule, subscriberId, matchSubscriberIds, networkId, metered, roaming,
|
this(matchRule, subscriberId, matchSubscriberIds, networkId, metered, roaming,
|
||||||
defaultNetwork, subType, oemManaged, SUBSCRIBER_ID_MATCH_RULE_EXACT);
|
defaultNetwork, subType, oemManaged,
|
||||||
|
NetworkStatsUtils.SUBSCRIBER_ID_MATCH_RULE_EXACT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
@@ -539,9 +520,9 @@ public final class NetworkTemplate implements Parcelable {
|
|||||||
|
|
||||||
private static String subscriberIdMatchRuleToString(int rule) {
|
private static String subscriberIdMatchRuleToString(int rule) {
|
||||||
switch (rule) {
|
switch (rule) {
|
||||||
case SUBSCRIBER_ID_MATCH_RULE_EXACT:
|
case NetworkStatsUtils.SUBSCRIBER_ID_MATCH_RULE_EXACT:
|
||||||
return "EXACT_MATCH";
|
return "EXACT_MATCH";
|
||||||
case SUBSCRIBER_ID_MATCH_RULE_ALL:
|
case NetworkStatsUtils.SUBSCRIBER_ID_MATCH_RULE_ALL:
|
||||||
return "ALL";
|
return "ALL";
|
||||||
default:
|
default:
|
||||||
return "Unknown rule " + rule;
|
return "Unknown rule " + rule;
|
||||||
@@ -608,15 +589,6 @@ public final class NetworkTemplate implements Parcelable {
|
|||||||
return mNetworkId;
|
return mNetworkId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Subscriber Id Match Rule of the template.
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
public int getSubscriberIdMatchRule() {
|
|
||||||
return mSubscriberIdMatchRule;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get meteredness filter of the template.
|
* Get meteredness filter of the template.
|
||||||
*/
|
*/
|
||||||
@@ -730,7 +702,7 @@ public final class NetworkTemplate implements Parcelable {
|
|||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public boolean matchesSubscriberId(@Nullable String subscriberId) {
|
public boolean matchesSubscriberId(@Nullable String subscriberId) {
|
||||||
return mSubscriberIdMatchRule == SUBSCRIBER_ID_MATCH_RULE_ALL
|
return mSubscriberIdMatchRule == NetworkStatsUtils.SUBSCRIBER_ID_MATCH_RULE_ALL
|
||||||
|| ArrayUtils.contains(mMatchSubscriberIds, subscriberId);
|
|| ArrayUtils.contains(mMatchSubscriberIds, subscriberId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1176,7 +1148,8 @@ public final class NetworkTemplate implements Parcelable {
|
|||||||
public NetworkTemplate build() {
|
public NetworkTemplate build() {
|
||||||
assertRequestableParameters();
|
assertRequestableParameters();
|
||||||
final int subscriberIdMatchRule = mMatchSubscriberIds.isEmpty()
|
final int subscriberIdMatchRule = mMatchSubscriberIds.isEmpty()
|
||||||
? SUBSCRIBER_ID_MATCH_RULE_ALL : SUBSCRIBER_ID_MATCH_RULE_EXACT;
|
? NetworkStatsUtils.SUBSCRIBER_ID_MATCH_RULE_ALL
|
||||||
|
: NetworkStatsUtils.SUBSCRIBER_ID_MATCH_RULE_EXACT;
|
||||||
return new NetworkTemplate(getWildcardDeducedMatchRule(),
|
return new NetworkTemplate(getWildcardDeducedMatchRule(),
|
||||||
mMatchSubscriberIds.isEmpty() ? null : mMatchSubscriberIds.iterator().next(),
|
mMatchSubscriberIds.isEmpty() ? null : mMatchSubscriberIds.iterator().next(),
|
||||||
mMatchSubscriberIds.toArray(new String[0]),
|
mMatchSubscriberIds.toArray(new String[0]),
|
||||||
|
|||||||
@@ -25,9 +25,7 @@ import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_ROAMING;
|
|||||||
import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
|
import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
|
||||||
import static android.net.NetworkPolicy.LIMIT_DISABLED;
|
import static android.net.NetworkPolicy.LIMIT_DISABLED;
|
||||||
import static android.net.NetworkPolicy.WARNING_DISABLED;
|
import static android.net.NetworkPolicy.WARNING_DISABLED;
|
||||||
import static android.net.NetworkTemplate.NETWORK_TYPE_ALL;
|
|
||||||
import static android.net.NetworkTemplate.OEM_MANAGED_ALL;
|
import static android.net.NetworkTemplate.OEM_MANAGED_ALL;
|
||||||
import static android.net.NetworkTemplate.SUBSCRIBER_ID_MATCH_RULE_EXACT;
|
|
||||||
import static android.provider.Settings.Global.NETWORK_DEFAULT_DAILY_MULTIPATH_QUOTA_BYTES;
|
import static android.provider.Settings.Global.NETWORK_DEFAULT_DAILY_MULTIPATH_QUOTA_BYTES;
|
||||||
import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||||
|
|
||||||
@@ -77,6 +75,8 @@ import java.time.ZoneId;
|
|||||||
import java.time.ZoneOffset;
|
import java.time.ZoneOffset;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@@ -224,12 +224,13 @@ public class MultipathPolicyTracker {
|
|||||||
"Can't get TelephonyManager for subId %d", subId));
|
"Can't get TelephonyManager for subId %d", subId));
|
||||||
}
|
}
|
||||||
|
|
||||||
subscriberId = tele.getSubscriberId();
|
subscriberId = Objects.requireNonNull(tele.getSubscriberId(),
|
||||||
mNetworkTemplate = new NetworkTemplate(
|
"Null subscriber Id for subId " + subId);
|
||||||
NetworkTemplate.MATCH_MOBILE, subscriberId, new String[] { subscriberId },
|
mNetworkTemplate = new NetworkTemplate.Builder(NetworkTemplate.MATCH_MOBILE)
|
||||||
null, NetworkStats.METERED_YES, NetworkStats.ROAMING_ALL,
|
.setSubscriberIds(Set.of(subscriberId))
|
||||||
NetworkStats.DEFAULT_NETWORK_NO, NETWORK_TYPE_ALL, OEM_MANAGED_ALL,
|
.setMeteredness(NetworkStats.METERED_YES)
|
||||||
SUBSCRIBER_ID_MATCH_RULE_EXACT);
|
.setDefaultNetworkStatus(NetworkStats.DEFAULT_NETWORK_NO)
|
||||||
|
.build();
|
||||||
mUsageCallback = new UsageCallback() {
|
mUsageCallback = new UsageCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onThresholdReached(int networkType, String subscriberId) {
|
public void onThresholdReached(int networkType, String subscriberId) {
|
||||||
|
|||||||
@@ -255,6 +255,7 @@ import com.android.internal.util.IndentingPrintWriter;
|
|||||||
import com.android.internal.util.StatLogger;
|
import com.android.internal.util.StatLogger;
|
||||||
import com.android.internal.util.XmlUtils;
|
import com.android.internal.util.XmlUtils;
|
||||||
import com.android.net.module.util.NetworkIdentityUtils;
|
import com.android.net.module.util.NetworkIdentityUtils;
|
||||||
|
import com.android.net.module.util.NetworkStatsUtils;
|
||||||
import com.android.net.module.util.PermissionUtils;
|
import com.android.net.module.util.PermissionUtils;
|
||||||
import com.android.server.EventLogTags;
|
import com.android.server.EventLogTags;
|
||||||
import com.android.server.LocalServices;
|
import com.android.server.LocalServices;
|
||||||
@@ -2388,7 +2389,8 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
templateMeteredness = readIntAttribute(in, ATTR_TEMPLATE_METERED);
|
templateMeteredness = readIntAttribute(in, ATTR_TEMPLATE_METERED);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
subscriberIdMatchRule = NetworkTemplate.SUBSCRIBER_ID_MATCH_RULE_EXACT;
|
subscriberIdMatchRule =
|
||||||
|
NetworkStatsUtils.SUBSCRIBER_ID_MATCH_RULE_EXACT;
|
||||||
if (templateType == MATCH_MOBILE) {
|
if (templateType == MATCH_MOBILE) {
|
||||||
Log.d(TAG, "Update template match rule from mobile to carrier and"
|
Log.d(TAG, "Update template match rule from mobile to carrier and"
|
||||||
+ " force to metered");
|
+ " force to metered");
|
||||||
@@ -2451,11 +2453,17 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
} else {
|
} else {
|
||||||
inferred = false;
|
inferred = false;
|
||||||
}
|
}
|
||||||
final NetworkTemplate template = new NetworkTemplate(templateType,
|
final NetworkTemplate.Builder builder =
|
||||||
subscriberId, new String[] { subscriberId },
|
new NetworkTemplate.Builder(templateType)
|
||||||
networkId, templateMeteredness, NetworkStats.ROAMING_ALL,
|
.setWifiNetworkKey(networkId)
|
||||||
NetworkStats.DEFAULT_NETWORK_ALL, NetworkTemplate.NETWORK_TYPE_ALL,
|
.setMeteredness(templateMeteredness);
|
||||||
NetworkTemplate.OEM_MANAGED_ALL, subscriberIdMatchRule);
|
if (subscriberIdMatchRule
|
||||||
|
== NetworkStatsUtils.SUBSCRIBER_ID_MATCH_RULE_EXACT) {
|
||||||
|
final ArraySet<String> ids = new ArraySet<>();
|
||||||
|
ids.add(subscriberId);
|
||||||
|
builder.setSubscriberIds(ids);
|
||||||
|
}
|
||||||
|
final NetworkTemplate template = builder.build();
|
||||||
if (NetworkPolicy.isTemplatePersistable(template)) {
|
if (NetworkPolicy.isTemplatePersistable(template)) {
|
||||||
mNetworkPolicy.put(template, new NetworkPolicy(template, cycleRule,
|
mNetworkPolicy.put(template, new NetworkPolicy(template, cycleRule,
|
||||||
warningBytes, limitBytes, lastWarningSnooze,
|
warningBytes, limitBytes, lastWarningSnooze,
|
||||||
@@ -2671,8 +2679,10 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
if (subscriberId != null) {
|
if (subscriberId != null) {
|
||||||
out.attribute(null, ATTR_SUBSCRIBER_ID, subscriberId);
|
out.attribute(null, ATTR_SUBSCRIBER_ID, subscriberId);
|
||||||
}
|
}
|
||||||
writeIntAttribute(out, ATTR_SUBSCRIBER_ID_MATCH_RULE,
|
final int subscriberIdMatchRule = template.getSubscriberIds().isEmpty()
|
||||||
template.getSubscriberIdMatchRule());
|
? NetworkStatsUtils.SUBSCRIBER_ID_MATCH_RULE_ALL
|
||||||
|
: NetworkStatsUtils.SUBSCRIBER_ID_MATCH_RULE_EXACT;
|
||||||
|
writeIntAttribute(out, ATTR_SUBSCRIBER_ID_MATCH_RULE, subscriberIdMatchRule);
|
||||||
final String networkId = template.getNetworkId();
|
final String networkId = template.getNetworkId();
|
||||||
if (networkId != null) {
|
if (networkId != null) {
|
||||||
out.attribute(null, ATTR_NETWORK_ID, networkId);
|
out.attribute(null, ATTR_NETWORK_ID, networkId);
|
||||||
|
|||||||
@@ -1986,9 +1986,8 @@ public class NetworkPolicyManagerServiceTest {
|
|||||||
assertEquals("Unexpected template match rule in network policies",
|
assertEquals("Unexpected template match rule in network policies",
|
||||||
NetworkTemplate.MATCH_CARRIER,
|
NetworkTemplate.MATCH_CARRIER,
|
||||||
actualPolicy.template.getMatchRule());
|
actualPolicy.template.getMatchRule());
|
||||||
assertEquals("Unexpected subscriberId match rule in network policies",
|
assertTrue("Unexpected subscriberIds size in network policies",
|
||||||
NetworkTemplate.SUBSCRIBER_ID_MATCH_RULE_EXACT,
|
actualPolicy.template.getSubscriberIds().size() > 0);
|
||||||
actualPolicy.template.getSubscriberIdMatchRule());
|
|
||||||
assertEquals("Unexpected template meteredness in network policies",
|
assertEquals("Unexpected template meteredness in network policies",
|
||||||
METERED_YES, actualPolicy.template.getMeteredness());
|
METERED_YES, actualPolicy.template.getMeteredness());
|
||||||
}
|
}
|
||||||
@@ -2003,9 +2002,8 @@ public class NetworkPolicyManagerServiceTest {
|
|||||||
assertEquals("Unexpected template match rule in network policies",
|
assertEquals("Unexpected template match rule in network policies",
|
||||||
NetworkTemplate.MATCH_WIFI,
|
NetworkTemplate.MATCH_WIFI,
|
||||||
actualPolicy.template.getMatchRule());
|
actualPolicy.template.getMatchRule());
|
||||||
assertEquals("Unexpected subscriberId match rule in network policies",
|
assertEquals("Unexpected subscriberIds size in network policies",
|
||||||
NetworkTemplate.SUBSCRIBER_ID_MATCH_RULE_ALL,
|
actualPolicy.template.getSubscriberIds().size(), 0);
|
||||||
actualPolicy.template.getSubscriberIdMatchRule());
|
|
||||||
assertEquals("Unexpected template meteredness in network policies",
|
assertEquals("Unexpected template meteredness in network policies",
|
||||||
METERED_NO, actualPolicy.template.getMeteredness());
|
METERED_NO, actualPolicy.template.getMeteredness());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user