Merge "Teach NetworkIdentity about roaming."
diff --git a/core/java/android/net/NetworkIdentity.java b/core/java/android/net/NetworkIdentity.java
index 23ebbab..ccef122 100644
--- a/core/java/android/net/NetworkIdentity.java
+++ b/core/java/android/net/NetworkIdentity.java
@@ -33,11 +33,13 @@
final int mType;
final int mSubType;
final String mSubscriberId;
+ final boolean mRoaming;
- public NetworkIdentity(int type, int subType, String subscriberId) {
+ public NetworkIdentity(int type, int subType, String subscriberId, boolean roaming) {
this.mType = type;
this.mSubType = subType;
this.mSubscriberId = subscriberId;
+ this.mRoaming = roaming;
}
@Override
@@ -50,7 +52,8 @@
if (obj instanceof NetworkIdentity) {
final NetworkIdentity ident = (NetworkIdentity) obj;
return mType == ident.mType && mSubType == ident.mSubType
- && Objects.equal(mSubscriberId, ident.mSubscriberId);
+ && Objects.equal(mSubscriberId, ident.mSubscriberId)
+ && mRoaming == ident.mRoaming;
}
return false;
}
@@ -66,8 +69,9 @@
}
final String scrubSubscriberId = mSubscriberId != null ? "valid" : "null";
+ final String roaming = mRoaming ? ", ROAMING" : "";
return "[type=" + typeName + ", subType=" + subTypeName + ", subscriberId="
- + scrubSubscriberId + "]";
+ + scrubSubscriberId + roaming + "]";
}
public int getType() {
@@ -82,6 +86,10 @@
return mSubscriberId;
}
+ public boolean getRoaming() {
+ return mRoaming;
+ }
+
/**
* Build a {@link NetworkIdentity} from the given {@link NetworkState},
* assuming that any mobile networks are using the current IMSI.
@@ -94,18 +102,21 @@
// comes from an authoritative source.
final String subscriberId;
+ final boolean roaming;
if (isNetworkTypeMobile(type)) {
+ final TelephonyManager telephony = (TelephonyManager) context.getSystemService(
+ Context.TELEPHONY_SERVICE);
+ roaming = telephony.isNetworkRoaming();
if (state.subscriberId != null) {
subscriberId = state.subscriberId;
} else {
- final TelephonyManager telephony = (TelephonyManager) context.getSystemService(
- Context.TELEPHONY_SERVICE);
subscriberId = telephony.getSubscriberId();
}
} else {
subscriberId = null;
+ roaming = false;
}
- return new NetworkIdentity(type, subType, subscriberId);
+ return new NetworkIdentity(type, subType, subscriberId, roaming);
}
}
diff --git a/services/java/com/android/server/net/NetworkIdentitySet.java b/services/java/com/android/server/net/NetworkIdentitySet.java
index 757d3bc..af03fb3 100644
--- a/services/java/com/android/server/net/NetworkIdentitySet.java
+++ b/services/java/com/android/server/net/NetworkIdentitySet.java
@@ -32,6 +32,7 @@
*/
public class NetworkIdentitySet extends HashSet<NetworkIdentity> {
private static final int VERSION_INIT = 1;
+ private static final int VERSION_ADD_ROAMING = 2;
public NetworkIdentitySet() {
}
@@ -46,7 +47,18 @@
final int type = in.readInt();
final int subType = in.readInt();
final String subscriberId = readOptionalString(in);
- add(new NetworkIdentity(type, subType, subscriberId));
+ add(new NetworkIdentity(type, subType, subscriberId, false));
+ }
+ break;
+ }
+ case VERSION_ADD_ROAMING: {
+ final int size = in.readInt();
+ for (int i = 0; i < size; i++) {
+ final int type = in.readInt();
+ final int subType = in.readInt();
+ final String subscriberId = readOptionalString(in);
+ final boolean roaming = in.readBoolean();
+ add(new NetworkIdentity(type, subType, subscriberId, roaming));
}
break;
}
@@ -57,13 +69,13 @@
}
public void writeToStream(DataOutputStream out) throws IOException {
- out.writeInt(VERSION_INIT);
+ out.writeInt(VERSION_ADD_ROAMING);
out.writeInt(size());
for (NetworkIdentity ident : this) {
- out.writeInt(VERSION_INIT);
out.writeInt(ident.getType());
out.writeInt(ident.getSubType());
writeOptionalString(out, ident.getSubscriberId());
+ out.writeBoolean(ident.getRoaming());
}
}
diff --git a/services/java/com/android/server/net/NetworkPolicyManagerService.java b/services/java/com/android/server/net/NetworkPolicyManagerService.java
index 55d83a5..584cd03 100644
--- a/services/java/com/android/server/net/NetworkPolicyManagerService.java
+++ b/services/java/com/android/server/net/NetworkPolicyManagerService.java
@@ -623,7 +623,7 @@
if (LOGV) Slog.v(TAG, "ensureActiveMobilePolicyLocked()");
final String subscriberId = getActiveSubscriberId();
final NetworkIdentity probeIdent = new NetworkIdentity(
- TYPE_MOBILE, TelephonyManager.NETWORK_TYPE_UNKNOWN, subscriberId);
+ TYPE_MOBILE, TelephonyManager.NETWORK_TYPE_UNKNOWN, subscriberId, false);
// examine to see if any policy is defined for active mobile
boolean mobileDefined = false;