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 * @hide
*/ */
public class NetworkIdentity { 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 mType;
final int mSubType; final int mSubType;
final String mSubscriberId; final String mSubscriberId;
@@ -38,7 +46,7 @@ public class NetworkIdentity {
public NetworkIdentity(int type, int subType, String subscriberId, boolean roaming) { public NetworkIdentity(int type, int subType, String subscriberId, boolean roaming) {
this.mType = type; this.mType = type;
this.mSubType = subType; this.mSubType = COMBINE_SUBTYPE_ENABLED ? SUBTYPE_COMBINED : subType;
this.mSubscriberId = subscriberId; this.mSubscriberId = subscriberId;
this.mRoaming = roaming; this.mRoaming = roaming;
} }
@@ -52,9 +60,8 @@ public class NetworkIdentity {
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj instanceof NetworkIdentity) { if (obj instanceof NetworkIdentity) {
final NetworkIdentity ident = (NetworkIdentity) obj; final NetworkIdentity ident = (NetworkIdentity) obj;
return mType == ident.mType && mSubType == ident.mSubType return mType == ident.mType && mSubType == ident.mSubType && mRoaming == ident.mRoaming
&& Objects.equal(mSubscriberId, ident.mSubscriberId) && Objects.equal(mSubscriberId, ident.mSubscriberId);
&& mRoaming == ident.mRoaming;
} }
return false; return false;
} }
@@ -63,7 +70,9 @@ public class NetworkIdentity {
public String toString() { public String toString() {
final String typeName = ConnectivityManager.getNetworkTypeName(mType); final String typeName = ConnectivityManager.getNetworkTypeName(mType);
final String subTypeName; final String subTypeName;
if (ConnectivityManager.isNetworkTypeMobile(mType)) { if (COMBINE_SUBTYPE_ENABLED) {
subTypeName = "COMBINED";
} else if (ConnectivityManager.isNetworkTypeMobile(mType)) {
subTypeName = TelephonyManager.getNetworkTypeName(mSubType); subTypeName = TelephonyManager.getNetworkTypeName(mSubType);
} else { } else {
subTypeName = Integer.toString(mSubType); subTypeName = Integer.toString(mSubType);
@@ -130,5 +139,4 @@ public class NetworkIdentity {
} }
return new NetworkIdentity(type, subType, subscriberId, roaming); 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;
import static android.net.ConnectivityManager.TYPE_WIFI_P2P; import static android.net.ConnectivityManager.TYPE_WIFI_P2P;
import static android.net.ConnectivityManager.TYPE_WIMAX; import static android.net.ConnectivityManager.TYPE_WIMAX;
import static android.net.NetworkIdentity.COMBINE_SUBTYPE_ENABLED;
import static android.net.NetworkIdentity.scrubSubscriberId; import static android.net.NetworkIdentity.scrubSubscriberId;
import static android.telephony.TelephonyManager.NETWORK_CLASS_2_G; import static android.telephony.TelephonyManager.NETWORK_CLASS_2_G;
import static android.telephony.TelephonyManager.NETWORK_CLASS_3_G; import static android.telephony.TelephonyManager.NETWORK_CLASS_3_G;
@@ -77,6 +78,7 @@ public class NetworkTemplate implements Parcelable {
* uses statistics for requested IMSI. * uses statistics for requested IMSI.
*/ */
public static NetworkTemplate buildTemplateMobile3gLower(String subscriberId) { public static NetworkTemplate buildTemplateMobile3gLower(String subscriberId) {
ensureSubtypeAvailable();
return new NetworkTemplate(MATCH_MOBILE_3G_LOWER, subscriberId); return new NetworkTemplate(MATCH_MOBILE_3G_LOWER, subscriberId);
} }
@@ -86,6 +88,7 @@ public class NetworkTemplate implements Parcelable {
* requested IMSI. * requested IMSI.
*/ */
public static NetworkTemplate buildTemplateMobile4g(String subscriberId) { public static NetworkTemplate buildTemplateMobile4g(String subscriberId) {
ensureSubtypeAvailable();
return new NetworkTemplate(MATCH_MOBILE_4G, subscriberId); 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. * Check if mobile network classified 3G or lower with matching IMSI.
*/ */
private boolean matchesMobile3gLower(NetworkIdentity ident) { private boolean matchesMobile3gLower(NetworkIdentity ident) {
ensureSubtypeAvailable();
if (ident.mType == TYPE_WIMAX) { if (ident.mType == TYPE_WIMAX) {
return false; return false;
} else if (matchesMobile(ident)) { } else if (matchesMobile(ident)) {
@@ -216,6 +220,7 @@ public class NetworkTemplate implements Parcelable {
* Check if mobile network classified 4G with matching IMSI. * Check if mobile network classified 4G with matching IMSI.
*/ */
private boolean matchesMobile4g(NetworkIdentity ident) { private boolean matchesMobile4g(NetworkIdentity ident) {
ensureSubtypeAvailable();
if (ident.mType == TYPE_WIMAX) { if (ident.mType == TYPE_WIMAX) {
// TODO: consider matching against WiMAX subscriber identity // TODO: consider matching against WiMAX subscriber identity
return true; 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 static final Creator<NetworkTemplate> CREATOR = new Creator<NetworkTemplate>() {
public NetworkTemplate createFromParcel(Parcel in) { public NetworkTemplate createFromParcel(Parcel in) {
return new NetworkTemplate(in); return new NetworkTemplate(in);

View File

@@ -26,6 +26,7 @@ import static android.content.Intent.ACTION_UID_REMOVED;
import static android.content.Intent.EXTRA_UID; import static android.content.Intent.EXTRA_UID;
import static android.net.ConnectivityManager.ACTION_TETHER_STATE_CHANGED; import static android.net.ConnectivityManager.ACTION_TETHER_STATE_CHANGED;
import static android.net.ConnectivityManager.CONNECTIVITY_ACTION_IMMEDIATE; import static android.net.ConnectivityManager.CONNECTIVITY_ACTION_IMMEDIATE;
import static android.net.NetworkIdentity.COMBINE_SUBTYPE_ENABLED;
import static android.net.NetworkStats.IFACE_ALL; import static android.net.NetworkStats.IFACE_ALL;
import static android.net.NetworkStats.SET_ALL; import static android.net.NetworkStats.SET_ALL;
import static android.net.NetworkStats.SET_DEFAULT; import static android.net.NetworkStats.SET_DEFAULT;
@@ -304,7 +305,9 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
// watch for networkType changes that aren't broadcast through // watch for networkType changes that aren't broadcast through
// CONNECTIVITY_ACTION_IMMEDIATE above. // CONNECTIVITY_ACTION_IMMEDIATE above.
mTeleManager.listen(mPhoneListener, LISTEN_DATA_CONNECTION_STATE); if (!COMBINE_SUBTYPE_ENABLED) {
mTeleManager.listen(mPhoneListener, LISTEN_DATA_CONNECTION_STATE);
}
registerPollAlarmLocked(); registerPollAlarmLocked();
registerGlobalAlert(); registerGlobalAlert();
@@ -325,7 +328,9 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
mContext.unregisterReceiver(mRemovedReceiver); mContext.unregisterReceiver(mRemovedReceiver);
mContext.unregisterReceiver(mShutdownReceiver); mContext.unregisterReceiver(mShutdownReceiver);
mTeleManager.listen(mPhoneListener, LISTEN_NONE); if (!COMBINE_SUBTYPE_ENABLED) {
mTeleManager.listen(mPhoneListener, LISTEN_NONE);
}
final long currentTime = mTime.hasCache() ? mTime.currentTimeMillis() final long currentTime = mTime.hasCache() ? mTime.currentTimeMillis()
: System.currentTimeMillis(); : System.currentTimeMillis();