Merge "[SUBID01-0]Grow NetworkIdentity to include a new mSubId field" am: 8e7b0f1a00
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1894970 Change-Id: I8000c63c159d50d032853abb91723eab20da1e0a
This commit is contained in:
@@ -24,6 +24,7 @@ import static android.net.ConnectivityManager.TYPE_MOBILE_MMS;
|
|||||||
import static android.net.ConnectivityManager.TYPE_MOBILE_SUPL;
|
import static android.net.ConnectivityManager.TYPE_MOBILE_SUPL;
|
||||||
import static android.net.NetworkStats.SET_DEFAULT;
|
import static android.net.NetworkStats.SET_DEFAULT;
|
||||||
import static android.net.NetworkStats.TAG_NONE;
|
import static android.net.NetworkStats.TAG_NONE;
|
||||||
|
import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||||
|
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.SystemApi;
|
import android.annotation.SystemApi;
|
||||||
@@ -108,6 +109,7 @@ public class NetworkStatsDataMigrationUtils {
|
|||||||
static final int VERSION_ADD_METERED = 4;
|
static final int VERSION_ADD_METERED = 4;
|
||||||
static final int VERSION_ADD_DEFAULT_NETWORK = 5;
|
static final int VERSION_ADD_DEFAULT_NETWORK = 5;
|
||||||
static final int VERSION_ADD_OEM_MANAGED_NETWORK = 6;
|
static final int VERSION_ADD_OEM_MANAGED_NETWORK = 6;
|
||||||
|
static final int VERSION_ADD_SUB_ID = 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -448,6 +450,13 @@ public class NetworkStatsDataMigrationUtils {
|
|||||||
oemNetCapabilities = NetworkTemplate.OEM_MANAGED_NO;
|
oemNetCapabilities = NetworkTemplate.OEM_MANAGED_NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final int subId;
|
||||||
|
if (version >= IdentitySetVersion.VERSION_ADD_SUB_ID) {
|
||||||
|
subId = in.readInt();
|
||||||
|
} else {
|
||||||
|
subId = INVALID_SUBSCRIPTION_ID;
|
||||||
|
}
|
||||||
|
|
||||||
// Legacy files might contain TYPE_MOBILE_* types which were deprecated in later
|
// Legacy files might contain TYPE_MOBILE_* types which were deprecated in later
|
||||||
// releases. For backward compatibility, record them as TYPE_MOBILE instead.
|
// releases. For backward compatibility, record them as TYPE_MOBILE instead.
|
||||||
final int collapsedLegacyType = getCollapsedLegacyType(type);
|
final int collapsedLegacyType = getCollapsedLegacyType(type);
|
||||||
@@ -457,7 +466,8 @@ public class NetworkStatsDataMigrationUtils {
|
|||||||
.setWifiNetworkKey(networkId)
|
.setWifiNetworkKey(networkId)
|
||||||
.setRoaming(roaming).setMetered(metered)
|
.setRoaming(roaming).setMetered(metered)
|
||||||
.setDefaultNetwork(defaultNetwork)
|
.setDefaultNetwork(defaultNetwork)
|
||||||
.setOemManaged(oemNetCapabilities);
|
.setOemManaged(oemNetCapabilities)
|
||||||
|
.setSubId(subId);
|
||||||
if (type == TYPE_MOBILE && ratType != NetworkTemplate.NETWORK_TYPE_ALL) {
|
if (type == TYPE_MOBILE && ratType != NetworkTemplate.NETWORK_TYPE_ALL) {
|
||||||
builder.setRatType(ratType);
|
builder.setRatType(ratType);
|
||||||
}
|
}
|
||||||
@@ -501,10 +511,10 @@ public class NetworkStatsDataMigrationUtils {
|
|||||||
* This is copied from {@code NetworkStatsCollection#readLegacyUid}.
|
* This is copied from {@code NetworkStatsCollection#readLegacyUid}.
|
||||||
* See {@code NetworkStatsService#maybeUpgradeLegacyStatsLocked}.
|
* See {@code NetworkStatsService#maybeUpgradeLegacyStatsLocked}.
|
||||||
*
|
*
|
||||||
* @param taggedData whether to read tagged data. For legacy uid files, the tagged
|
* @param taggedData whether to read only tagged data (true) or only non-tagged data
|
||||||
* data was stored in the same binary file with non-tagged data.
|
* (false). For legacy uid files, the tagged data was stored in
|
||||||
* But in later releases, these data should be kept in different
|
* the same binary file with non-tagged data. But in later releases,
|
||||||
* recorders.
|
* these data should be kept in different recorders.
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import static android.annotation.SystemApi.Client.MODULE_LIBRARIES;
|
|||||||
import static android.net.ConnectivityManager.TYPE_MOBILE;
|
import static android.net.ConnectivityManager.TYPE_MOBILE;
|
||||||
import static android.net.ConnectivityManager.TYPE_WIFI;
|
import static android.net.ConnectivityManager.TYPE_WIFI;
|
||||||
import static android.net.NetworkTemplate.NETWORK_TYPE_ALL;
|
import static android.net.NetworkTemplate.NETWORK_TYPE_ALL;
|
||||||
|
import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||||
|
|
||||||
import android.annotation.IntDef;
|
import android.annotation.IntDef;
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
@@ -86,6 +87,7 @@ public class NetworkIdentity {
|
|||||||
|
|
||||||
final int mType;
|
final int mType;
|
||||||
final int mRatType;
|
final int mRatType;
|
||||||
|
final int mSubId;
|
||||||
final String mSubscriberId;
|
final String mSubscriberId;
|
||||||
final String mWifiNetworkKey;
|
final String mWifiNetworkKey;
|
||||||
final boolean mRoaming;
|
final boolean mRoaming;
|
||||||
@@ -96,7 +98,7 @@ public class NetworkIdentity {
|
|||||||
/** @hide */
|
/** @hide */
|
||||||
public NetworkIdentity(
|
public NetworkIdentity(
|
||||||
int type, int ratType, @Nullable String subscriberId, @Nullable String wifiNetworkKey,
|
int type, int ratType, @Nullable String subscriberId, @Nullable String wifiNetworkKey,
|
||||||
boolean roaming, boolean metered, boolean defaultNetwork, int oemManaged) {
|
boolean roaming, boolean metered, boolean defaultNetwork, int oemManaged, int subId) {
|
||||||
mType = type;
|
mType = type;
|
||||||
mRatType = ratType;
|
mRatType = ratType;
|
||||||
mSubscriberId = subscriberId;
|
mSubscriberId = subscriberId;
|
||||||
@@ -105,12 +107,13 @@ public class NetworkIdentity {
|
|||||||
mMetered = metered;
|
mMetered = metered;
|
||||||
mDefaultNetwork = defaultNetwork;
|
mDefaultNetwork = defaultNetwork;
|
||||||
mOemManaged = oemManaged;
|
mOemManaged = oemManaged;
|
||||||
|
mSubId = subId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(mType, mRatType, mSubscriberId, mWifiNetworkKey, mRoaming, mMetered,
|
return Objects.hash(mType, mRatType, mSubscriberId, mWifiNetworkKey, mRoaming, mMetered,
|
||||||
mDefaultNetwork, mOemManaged);
|
mDefaultNetwork, mOemManaged, mSubId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -122,7 +125,8 @@ public class NetworkIdentity {
|
|||||||
&& Objects.equals(mWifiNetworkKey, ident.mWifiNetworkKey)
|
&& Objects.equals(mWifiNetworkKey, ident.mWifiNetworkKey)
|
||||||
&& mMetered == ident.mMetered
|
&& mMetered == ident.mMetered
|
||||||
&& mDefaultNetwork == ident.mDefaultNetwork
|
&& mDefaultNetwork == ident.mDefaultNetwork
|
||||||
&& mOemManaged == ident.mOemManaged;
|
&& mOemManaged == ident.mOemManaged
|
||||||
|
&& mSubId == ident.mSubId;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -150,6 +154,7 @@ public class NetworkIdentity {
|
|||||||
builder.append(", metered=").append(mMetered);
|
builder.append(", metered=").append(mMetered);
|
||||||
builder.append(", defaultNetwork=").append(mDefaultNetwork);
|
builder.append(", defaultNetwork=").append(mDefaultNetwork);
|
||||||
builder.append(", oemManaged=").append(getOemManagedNames(mOemManaged));
|
builder.append(", oemManaged=").append(getOemManagedNames(mOemManaged));
|
||||||
|
builder.append(", subId=").append(mSubId);
|
||||||
return builder.append("}").toString();
|
return builder.append("}").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -256,6 +261,11 @@ public class NetworkIdentity {
|
|||||||
return mOemManaged;
|
return mOemManaged;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Get the SubId of this instance. */
|
||||||
|
public int getSubId() {
|
||||||
|
return mSubId;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assemble a {@link NetworkIdentity} from the passed arguments.
|
* Assemble a {@link NetworkIdentity} from the passed arguments.
|
||||||
*
|
*
|
||||||
@@ -276,7 +286,8 @@ public class NetworkIdentity {
|
|||||||
public static NetworkIdentity buildNetworkIdentity(Context context,
|
public static NetworkIdentity buildNetworkIdentity(Context context,
|
||||||
@NonNull NetworkStateSnapshot snapshot, boolean defaultNetwork, int ratType) {
|
@NonNull NetworkStateSnapshot snapshot, boolean defaultNetwork, int ratType) {
|
||||||
final NetworkIdentity.Builder builder = new NetworkIdentity.Builder()
|
final NetworkIdentity.Builder builder = new NetworkIdentity.Builder()
|
||||||
.setNetworkStateSnapshot(snapshot).setDefaultNetwork(defaultNetwork);
|
.setNetworkStateSnapshot(snapshot).setDefaultNetwork(defaultNetwork)
|
||||||
|
.setSubId(snapshot.getSubId());
|
||||||
if (snapshot.getLegacyType() == TYPE_MOBILE && ratType != NETWORK_TYPE_ALL) {
|
if (snapshot.getLegacyType() == TYPE_MOBILE && ratType != NETWORK_TYPE_ALL) {
|
||||||
builder.setRatType(ratType);
|
builder.setRatType(ratType);
|
||||||
}
|
}
|
||||||
@@ -325,6 +336,9 @@ public class NetworkIdentity {
|
|||||||
if (res == 0) {
|
if (res == 0) {
|
||||||
res = Integer.compare(left.mOemManaged, right.mOemManaged);
|
res = Integer.compare(left.mOemManaged, right.mOemManaged);
|
||||||
}
|
}
|
||||||
|
if (res == 0) {
|
||||||
|
res = Integer.compare(left.mSubId, right.mSubId);
|
||||||
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -345,6 +359,7 @@ public class NetworkIdentity {
|
|||||||
private boolean mMetered;
|
private boolean mMetered;
|
||||||
private boolean mDefaultNetwork;
|
private boolean mDefaultNetwork;
|
||||||
private int mOemManaged;
|
private int mOemManaged;
|
||||||
|
private int mSubId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new Builder.
|
* Creates a new Builder.
|
||||||
@@ -359,6 +374,7 @@ public class NetworkIdentity {
|
|||||||
mMetered = false;
|
mMetered = false;
|
||||||
mDefaultNetwork = false;
|
mDefaultNetwork = false;
|
||||||
mOemManaged = NetworkTemplate.OEM_MANAGED_NO;
|
mOemManaged = NetworkTemplate.OEM_MANAGED_NO;
|
||||||
|
mSubId = INVALID_SUBSCRIPTION_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -537,6 +553,19 @@ public class NetworkIdentity {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the Subscription Id.
|
||||||
|
*
|
||||||
|
* @param subId the Subscription Id of the network. Or INVALID_SUBSCRIPTION_ID if not
|
||||||
|
* applicable.
|
||||||
|
* @return this builder.
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
public Builder setSubId(int subId) {
|
||||||
|
mSubId = subId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
private void ensureValidParameters() {
|
private void ensureValidParameters() {
|
||||||
// Assert non-mobile network cannot have a ratType.
|
// Assert non-mobile network cannot have a ratType.
|
||||||
if (mType != TYPE_MOBILE && mRatType != NetworkTemplate.NETWORK_TYPE_ALL) {
|
if (mType != TYPE_MOBILE && mRatType != NetworkTemplate.NETWORK_TYPE_ALL) {
|
||||||
@@ -559,7 +588,7 @@ public class NetworkIdentity {
|
|||||||
public NetworkIdentity build() {
|
public NetworkIdentity build() {
|
||||||
ensureValidParameters();
|
ensureValidParameters();
|
||||||
return new NetworkIdentity(mType, mRatType, mSubscriberId, mWifiNetworkKey,
|
return new NetworkIdentity(mType, mRatType, mSubscriberId, mWifiNetworkKey,
|
||||||
mRoaming, mMetered, mDefaultNetwork, mOemManaged);
|
mRoaming, mMetered, mDefaultNetwork, mOemManaged, mSubId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package android.net;
|
package android.net;
|
||||||
|
|
||||||
import static android.net.ConnectivityManager.TYPE_MOBILE;
|
import static android.net.ConnectivityManager.TYPE_MOBILE;
|
||||||
|
import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||||
|
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.service.NetworkIdentitySetProto;
|
import android.service.NetworkIdentitySetProto;
|
||||||
@@ -42,6 +43,7 @@ public class NetworkIdentitySet extends HashSet<NetworkIdentity> {
|
|||||||
private static final int VERSION_ADD_METERED = 4;
|
private static final int VERSION_ADD_METERED = 4;
|
||||||
private static final int VERSION_ADD_DEFAULT_NETWORK = 5;
|
private static final int VERSION_ADD_DEFAULT_NETWORK = 5;
|
||||||
private static final int VERSION_ADD_OEM_MANAGED_NETWORK = 6;
|
private static final int VERSION_ADD_OEM_MANAGED_NETWORK = 6;
|
||||||
|
private static final int VERSION_ADD_SUB_ID = 7;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a {@link NetworkIdentitySet} object.
|
* Construct a {@link NetworkIdentitySet} object.
|
||||||
@@ -103,8 +105,15 @@ public class NetworkIdentitySet extends HashSet<NetworkIdentity> {
|
|||||||
oemNetCapabilities = NetworkIdentity.OEM_NONE;
|
oemNetCapabilities = NetworkIdentity.OEM_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final int subId;
|
||||||
|
if (version >= VERSION_ADD_SUB_ID) {
|
||||||
|
subId = in.readInt();
|
||||||
|
} else {
|
||||||
|
subId = INVALID_SUBSCRIPTION_ID;
|
||||||
|
}
|
||||||
|
|
||||||
add(new NetworkIdentity(type, ratType, subscriberId, networkId, roaming, metered,
|
add(new NetworkIdentity(type, ratType, subscriberId, networkId, roaming, metered,
|
||||||
defaultNetwork, oemNetCapabilities));
|
defaultNetwork, oemNetCapabilities, subId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,7 +122,7 @@ public class NetworkIdentitySet extends HashSet<NetworkIdentity> {
|
|||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public void writeToStream(DataOutput out) throws IOException {
|
public void writeToStream(DataOutput out) throws IOException {
|
||||||
out.writeInt(VERSION_ADD_OEM_MANAGED_NETWORK);
|
out.writeInt(VERSION_ADD_SUB_ID);
|
||||||
out.writeInt(size());
|
out.writeInt(size());
|
||||||
for (NetworkIdentity ident : this) {
|
for (NetworkIdentity ident : this) {
|
||||||
out.writeInt(ident.getType());
|
out.writeInt(ident.getType());
|
||||||
@@ -124,6 +133,7 @@ public class NetworkIdentitySet extends HashSet<NetworkIdentity> {
|
|||||||
out.writeBoolean(ident.isMetered());
|
out.writeBoolean(ident.isMetered());
|
||||||
out.writeBoolean(ident.isDefaultNetwork());
|
out.writeBoolean(ident.isDefaultNetwork());
|
||||||
out.writeInt(ident.getOemManaged());
|
out.writeInt(ident.getOemManaged());
|
||||||
|
out.writeInt(ident.getSubId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,8 @@
|
|||||||
package android.net;
|
package android.net;
|
||||||
|
|
||||||
import static android.annotation.SystemApi.Client.MODULE_LIBRARIES;
|
import static android.annotation.SystemApi.Client.MODULE_LIBRARIES;
|
||||||
|
import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
|
||||||
|
import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||||
|
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
@@ -98,12 +100,29 @@ public final class NetworkStateSnapshot implements Parcelable {
|
|||||||
return mLinkProperties;
|
return mLinkProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get the Subscriber Id of the network associated with this snapshot. */
|
/**
|
||||||
|
* Get the Subscriber Id of the network associated with this snapshot.
|
||||||
|
* @deprecated Please use #getSubId, which doesn't return personally identifiable
|
||||||
|
* information.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
@Nullable
|
@Nullable
|
||||||
public String getSubscriberId() {
|
public String getSubscriberId() {
|
||||||
return mSubscriberId;
|
return mSubscriberId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Get the subId of the network associated with this snapshot. */
|
||||||
|
public int getSubId() {
|
||||||
|
if (mNetworkCapabilities.hasTransport(TRANSPORT_CELLULAR)) {
|
||||||
|
final NetworkSpecifier spec = mNetworkCapabilities.getNetworkSpecifier();
|
||||||
|
if (spec instanceof TelephonyNetworkSpecifier) {
|
||||||
|
return ((TelephonyNetworkSpecifier) spec).getSubscriptionId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return INVALID_SUBSCRIPTION_ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the legacy type of the network associated with this snapshot.
|
* Get the legacy type of the network associated with this snapshot.
|
||||||
* @return the legacy network type. See {@code ConnectivityManager#TYPE_*}.
|
* @return the legacy network type. See {@code ConnectivityManager#TYPE_*}.
|
||||||
|
|||||||
@@ -1540,10 +1540,15 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
NetworkCapabilities.NET_CAPABILITY_IMS) && !ident.isMetered()) {
|
NetworkCapabilities.NET_CAPABILITY_IMS) && !ident.isMetered()) {
|
||||||
|
|
||||||
// Copy the identify from IMS one but mark it as metered.
|
// Copy the identify from IMS one but mark it as metered.
|
||||||
NetworkIdentity vtIdent = new NetworkIdentity(ident.getType(),
|
NetworkIdentity vtIdent = new NetworkIdentity.Builder()
|
||||||
ident.getRatType(), ident.getSubscriberId(), ident.getWifiNetworkKey(),
|
.setType(ident.getType())
|
||||||
ident.isRoaming(), true /* metered */,
|
.setRatType(ident.getRatType())
|
||||||
true /* onDefaultNetwork */, ident.getOemManaged());
|
.setSubscriberId(ident.getSubscriberId())
|
||||||
|
.setWifiNetworkKey(ident.getWifiNetworkKey())
|
||||||
|
.setRoaming(ident.isRoaming()).setMetered(true)
|
||||||
|
.setDefaultNetwork(true)
|
||||||
|
.setOemManaged(ident.getOemManaged())
|
||||||
|
.setSubId(ident.getSubId()).build();
|
||||||
final String ifaceVt = IFACE_VT + getSubIdForMobile(snapshot);
|
final String ifaceVt = IFACE_VT + getSubIdForMobile(snapshot);
|
||||||
findOrCreateNetworkIdentitySet(mActiveIfaces, ifaceVt).add(vtIdent);
|
findOrCreateNetworkIdentitySet(mActiveIfaces, ifaceVt).add(vtIdent);
|
||||||
findOrCreateNetworkIdentitySet(mActiveUidIfaces, ifaceVt).add(vtIdent);
|
findOrCreateNetworkIdentitySet(mActiveUidIfaces, ifaceVt).add(vtIdent);
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ 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.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 com.android.server.net.NetworkPolicyManagerInternal.QUOTA_TYPE_MULTIPATH;
|
import static com.android.server.net.NetworkPolicyManagerInternal.QUOTA_TYPE_MULTIPATH;
|
||||||
import static com.android.server.net.NetworkPolicyManagerService.OPPORTUNISTIC_QUOTA_UNKNOWN;
|
import static com.android.server.net.NetworkPolicyManagerService.OPPORTUNISTIC_QUOTA_UNKNOWN;
|
||||||
@@ -191,6 +190,7 @@ public class MultipathPolicyTracker {
|
|||||||
class MultipathTracker {
|
class MultipathTracker {
|
||||||
final Network network;
|
final Network network;
|
||||||
final String subscriberId;
|
final String subscriberId;
|
||||||
|
private final int mSubId;
|
||||||
|
|
||||||
private long mQuota;
|
private long mQuota;
|
||||||
/** Current multipath budget. Nonzero iff we have budget and a UsageCallback is armed. */
|
/** Current multipath budget. Nonzero iff we have budget and a UsageCallback is armed. */
|
||||||
@@ -204,9 +204,8 @@ public class MultipathPolicyTracker {
|
|||||||
this.network = network;
|
this.network = network;
|
||||||
this.mNetworkCapabilities = new NetworkCapabilities(nc);
|
this.mNetworkCapabilities = new NetworkCapabilities(nc);
|
||||||
NetworkSpecifier specifier = nc.getNetworkSpecifier();
|
NetworkSpecifier specifier = nc.getNetworkSpecifier();
|
||||||
int subId = INVALID_SUBSCRIPTION_ID;
|
|
||||||
if (specifier instanceof TelephonyNetworkSpecifier) {
|
if (specifier instanceof TelephonyNetworkSpecifier) {
|
||||||
subId = ((TelephonyNetworkSpecifier) specifier).getSubscriptionId();
|
mSubId = ((TelephonyNetworkSpecifier) specifier).getSubscriptionId();
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalStateException(String.format(
|
throw new IllegalStateException(String.format(
|
||||||
"Can't get subId from mobile network %s (%s)",
|
"Can't get subId from mobile network %s (%s)",
|
||||||
@@ -217,14 +216,14 @@ public class MultipathPolicyTracker {
|
|||||||
if (tele == null) {
|
if (tele == null) {
|
||||||
throw new IllegalStateException(String.format("Missing TelephonyManager"));
|
throw new IllegalStateException(String.format("Missing TelephonyManager"));
|
||||||
}
|
}
|
||||||
tele = tele.createForSubscriptionId(subId);
|
tele = tele.createForSubscriptionId(mSubId);
|
||||||
if (tele == null) {
|
if (tele == null) {
|
||||||
throw new IllegalStateException(String.format(
|
throw new IllegalStateException(String.format(
|
||||||
"Can't get TelephonyManager for subId %d", subId));
|
"Can't get TelephonyManager for subId %d", mSubId));
|
||||||
}
|
}
|
||||||
|
|
||||||
subscriberId = Objects.requireNonNull(tele.getSubscriberId(),
|
subscriberId = Objects.requireNonNull(tele.getSubscriberId(),
|
||||||
"Null subscriber Id for subId " + subId);
|
"Null subscriber Id for subId " + mSubId);
|
||||||
mNetworkTemplate = new NetworkTemplate.Builder(NetworkTemplate.MATCH_MOBILE)
|
mNetworkTemplate = new NetworkTemplate.Builder(NetworkTemplate.MATCH_MOBILE)
|
||||||
.setSubscriberIds(Set.of(subscriberId))
|
.setSubscriberIds(Set.of(subscriberId))
|
||||||
.setMeteredness(NetworkStats.METERED_YES)
|
.setMeteredness(NetworkStats.METERED_YES)
|
||||||
@@ -282,6 +281,7 @@ public class MultipathPolicyTracker {
|
|||||||
.setSubscriberId(subscriberId)
|
.setSubscriberId(subscriberId)
|
||||||
.setRoaming(!nc.hasCapability(NET_CAPABILITY_NOT_ROAMING))
|
.setRoaming(!nc.hasCapability(NET_CAPABILITY_NOT_ROAMING))
|
||||||
.setMetered(!nc.hasCapability(NET_CAPABILITY_NOT_METERED))
|
.setMetered(!nc.hasCapability(NET_CAPABILITY_NOT_METERED))
|
||||||
|
.setSubId(mSubId)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,6 @@ import static android.net.INetd.FIREWALL_RULE_ALLOW;
|
|||||||
import static android.net.INetd.FIREWALL_RULE_DENY;
|
import static android.net.INetd.FIREWALL_RULE_DENY;
|
||||||
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_METERED;
|
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_METERED;
|
||||||
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_ROAMING;
|
import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_ROAMING;
|
||||||
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.SNOOZE_NEVER;
|
import static android.net.NetworkPolicy.SNOOZE_NEVER;
|
||||||
import static android.net.NetworkPolicy.WARNING_DISABLED;
|
import static android.net.NetworkPolicy.WARNING_DISABLED;
|
||||||
@@ -173,11 +172,9 @@ import android.net.NetworkPolicy;
|
|||||||
import android.net.NetworkPolicyManager;
|
import android.net.NetworkPolicyManager;
|
||||||
import android.net.NetworkPolicyManager.UidState;
|
import android.net.NetworkPolicyManager.UidState;
|
||||||
import android.net.NetworkRequest;
|
import android.net.NetworkRequest;
|
||||||
import android.net.NetworkSpecifier;
|
|
||||||
import android.net.NetworkStack;
|
import android.net.NetworkStack;
|
||||||
import android.net.NetworkStateSnapshot;
|
import android.net.NetworkStateSnapshot;
|
||||||
import android.net.NetworkTemplate;
|
import android.net.NetworkTemplate;
|
||||||
import android.net.TelephonyNetworkSpecifier;
|
|
||||||
import android.net.wifi.WifiConfiguration;
|
import android.net.wifi.WifiConfiguration;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.BestClock;
|
import android.os.BestClock;
|
||||||
@@ -1512,7 +1509,8 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
.setType(TYPE_MOBILE)
|
.setType(TYPE_MOBILE)
|
||||||
.setSubscriberId(subscriberId)
|
.setSubscriberId(subscriberId)
|
||||||
.setMetered(true)
|
.setMetered(true)
|
||||||
.setDefaultNetwork(true).build();
|
.setDefaultNetwork(true)
|
||||||
|
.setSubId(subId).build();
|
||||||
if (template.matches(probeIdent)) {
|
if (template.matches(probeIdent)) {
|
||||||
return subId;
|
return subId;
|
||||||
}
|
}
|
||||||
@@ -1749,7 +1747,8 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
.setType(TYPE_MOBILE)
|
.setType(TYPE_MOBILE)
|
||||||
.setSubscriberId(subscriberId)
|
.setSubscriberId(subscriberId)
|
||||||
.setMetered(true)
|
.setMetered(true)
|
||||||
.setDefaultNetwork(true).build();
|
.setDefaultNetwork(true)
|
||||||
|
.setSubId(subId).build();
|
||||||
for (int i = mNetworkPolicy.size() - 1; i >= 0; i--) {
|
for (int i = mNetworkPolicy.size() - 1; i >= 0; i--) {
|
||||||
final NetworkTemplate template = mNetworkPolicy.keyAt(i);
|
final NetworkTemplate template = mNetworkPolicy.keyAt(i);
|
||||||
if (template.matches(probeIdent)) {
|
if (template.matches(probeIdent)) {
|
||||||
@@ -1981,7 +1980,8 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
.setType(TYPE_MOBILE)
|
.setType(TYPE_MOBILE)
|
||||||
.setSubscriberId(subscriberId)
|
.setSubscriberId(subscriberId)
|
||||||
.setMetered(true)
|
.setMetered(true)
|
||||||
.setDefaultNetwork(true).build();
|
.setDefaultNetwork(true)
|
||||||
|
.setSubId(subId).build();
|
||||||
// Template is matched when subscriber id matches.
|
// Template is matched when subscriber id matches.
|
||||||
if (template.matches(probeIdent)) {
|
if (template.matches(probeIdent)) {
|
||||||
matchingSubIds.add(subId);
|
matchingSubIds.add(subId);
|
||||||
@@ -2083,7 +2083,8 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
mNetIdToSubId.clear();
|
mNetIdToSubId.clear();
|
||||||
final ArrayMap<NetworkStateSnapshot, NetworkIdentity> identified = new ArrayMap<>();
|
final ArrayMap<NetworkStateSnapshot, NetworkIdentity> identified = new ArrayMap<>();
|
||||||
for (final NetworkStateSnapshot snapshot : snapshots) {
|
for (final NetworkStateSnapshot snapshot : snapshots) {
|
||||||
mNetIdToSubId.put(snapshot.getNetwork().getNetId(), parseSubId(snapshot));
|
final int subId = snapshot.getSubId();
|
||||||
|
mNetIdToSubId.put(snapshot.getNetwork().getNetId(), subId);
|
||||||
|
|
||||||
// Policies matched by NPMS only match by subscriber ID or by network ID.
|
// Policies matched by NPMS only match by subscriber ID or by network ID.
|
||||||
final NetworkIdentity ident = new NetworkIdentity.Builder()
|
final NetworkIdentity ident = new NetworkIdentity.Builder()
|
||||||
@@ -2288,7 +2289,8 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
.setType(TYPE_MOBILE)
|
.setType(TYPE_MOBILE)
|
||||||
.setSubscriberId(subscriberId)
|
.setSubscriberId(subscriberId)
|
||||||
.setMetered(true)
|
.setMetered(true)
|
||||||
.setDefaultNetwork(true).build();
|
.setDefaultNetwork(true)
|
||||||
|
.setSubId(subId).build();
|
||||||
for (int i = mNetworkPolicy.size() - 1; i >= 0; i--) {
|
for (int i = mNetworkPolicy.size() - 1; i >= 0; i--) {
|
||||||
final NetworkTemplate template = mNetworkPolicy.keyAt(i);
|
final NetworkTemplate template = mNetworkPolicy.keyAt(i);
|
||||||
if (template.matches(probeIdent)) {
|
if (template.matches(probeIdent)) {
|
||||||
@@ -5807,17 +5809,6 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int parseSubId(@NonNull NetworkStateSnapshot snapshot) {
|
|
||||||
int subId = INVALID_SUBSCRIPTION_ID;
|
|
||||||
if (snapshot.getNetworkCapabilities().hasTransport(TRANSPORT_CELLULAR)) {
|
|
||||||
NetworkSpecifier spec = snapshot.getNetworkCapabilities().getNetworkSpecifier();
|
|
||||||
if (spec instanceof TelephonyNetworkSpecifier) {
|
|
||||||
subId = ((TelephonyNetworkSpecifier) spec).getSubscriptionId();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return subId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@GuardedBy("mNetworkPoliciesSecondLock")
|
@GuardedBy("mNetworkPoliciesSecondLock")
|
||||||
private int getSubIdLocked(Network network) {
|
private int getSubIdLocked(Network network) {
|
||||||
return mNetIdToSubId.get(network.getNetId(), INVALID_SUBSCRIPTION_ID);
|
return mNetIdToSubId.get(network.getNetId(), INVALID_SUBSCRIPTION_ID);
|
||||||
|
|||||||
Reference in New Issue
Block a user