Combine network subtypes by default.

Subtype controls (3G-vs-4G) aren't exposed in the UI, so tracking
data with that granularity creates unnecessary overhead. For example,
some GSM networks can regularly flap between two subtypes.

Bug: 6118868
Change-Id: Id098891dba52336d00d0f96632a7924e228b4713
This commit is contained in:
Jeff Sharkey
2012-03-16 11:11:54 -07:00
parent 69e1f3ae65
commit 8e38f3ddde
3 changed files with 33 additions and 8 deletions

View File

@@ -31,6 +31,14 @@ import com.android.internal.util.Objects;
* @hide
*/
public class NetworkIdentity {
/**
* When enabled, combine all {@link #mSubType} together under
* {@link #SUBTYPE_COMBINED}.
*/
public static final boolean COMBINE_SUBTYPE_ENABLED = true;
public static final int SUBTYPE_COMBINED = -1;
final int mType;
final int mSubType;
final String mSubscriberId;
@@ -38,7 +46,7 @@ public class NetworkIdentity {
public NetworkIdentity(int type, int subType, String subscriberId, boolean roaming) {
this.mType = type;
this.mSubType = subType;
this.mSubType = COMBINE_SUBTYPE_ENABLED ? SUBTYPE_COMBINED : subType;
this.mSubscriberId = subscriberId;
this.mRoaming = roaming;
}
@@ -52,9 +60,8 @@ public class NetworkIdentity {
public boolean equals(Object obj) {
if (obj instanceof NetworkIdentity) {
final NetworkIdentity ident = (NetworkIdentity) obj;
return mType == ident.mType && mSubType == ident.mSubType
&& Objects.equal(mSubscriberId, ident.mSubscriberId)
&& mRoaming == ident.mRoaming;
return mType == ident.mType && mSubType == ident.mSubType && mRoaming == ident.mRoaming
&& Objects.equal(mSubscriberId, ident.mSubscriberId);
}
return false;
}
@@ -63,7 +70,9 @@ public class NetworkIdentity {
public String toString() {
final String typeName = ConnectivityManager.getNetworkTypeName(mType);
final String subTypeName;
if (ConnectivityManager.isNetworkTypeMobile(mType)) {
if (COMBINE_SUBTYPE_ENABLED) {
subTypeName = "COMBINED";
} else if (ConnectivityManager.isNetworkTypeMobile(mType)) {
subTypeName = TelephonyManager.getNetworkTypeName(mSubType);
} else {
subTypeName = Integer.toString(mSubType);
@@ -130,5 +139,4 @@ public class NetworkIdentity {
}
return new NetworkIdentity(type, subType, subscriberId, roaming);
}
}

View File

@@ -20,6 +20,7 @@ import static android.net.ConnectivityManager.TYPE_ETHERNET;
import static android.net.ConnectivityManager.TYPE_WIFI;
import static android.net.ConnectivityManager.TYPE_WIFI_P2P;
import static android.net.ConnectivityManager.TYPE_WIMAX;
import static android.net.NetworkIdentity.COMBINE_SUBTYPE_ENABLED;
import static android.net.NetworkIdentity.scrubSubscriberId;
import static android.telephony.TelephonyManager.NETWORK_CLASS_2_G;
import static android.telephony.TelephonyManager.NETWORK_CLASS_3_G;
@@ -77,6 +78,7 @@ public class NetworkTemplate implements Parcelable {
* uses statistics for requested IMSI.
*/
public static NetworkTemplate buildTemplateMobile3gLower(String subscriberId) {
ensureSubtypeAvailable();
return new NetworkTemplate(MATCH_MOBILE_3G_LOWER, subscriberId);
}
@@ -86,6 +88,7 @@ public class NetworkTemplate implements Parcelable {
* requested IMSI.
*/
public static NetworkTemplate buildTemplateMobile4g(String subscriberId) {
ensureSubtypeAvailable();
return new NetworkTemplate(MATCH_MOBILE_4G, subscriberId);
}
@@ -199,6 +202,7 @@ public class NetworkTemplate implements Parcelable {
* Check if mobile network classified 3G or lower with matching IMSI.
*/
private boolean matchesMobile3gLower(NetworkIdentity ident) {
ensureSubtypeAvailable();
if (ident.mType == TYPE_WIMAX) {
return false;
} else if (matchesMobile(ident)) {
@@ -216,6 +220,7 @@ public class NetworkTemplate implements Parcelable {
* Check if mobile network classified 4G with matching IMSI.
*/
private boolean matchesMobile4g(NetworkIdentity ident) {
ensureSubtypeAvailable();
if (ident.mType == TYPE_WIMAX) {
// TODO: consider matching against WiMAX subscriber identity
return true;
@@ -268,6 +273,13 @@ public class NetworkTemplate implements Parcelable {
}
}
private static void ensureSubtypeAvailable() {
if (COMBINE_SUBTYPE_ENABLED) {
throw new IllegalArgumentException(
"Unable to enforce 3G_LOWER template on combined data.");
}
}
public static final Creator<NetworkTemplate> CREATOR = new Creator<NetworkTemplate>() {
public NetworkTemplate createFromParcel(Parcel in) {
return new NetworkTemplate(in);