[SM02] Support record mobile network stats by collapsed rat type
Previously network stats could be recorded by different rat type.
However, the feature was disabled by ag/173504 since rat type
frequently flapping between HSPA+ and UMTS.
Given that this feature might be useful for collecting metrics,
re-implement it based on current architecture and reduce the
overhead introduced by frequently flapping by:
1. only react when rat type changes between 2G/3G/4G/5G.
2. reduce the number of records by only recording a subset
of rat type that represented for a given network class.
3. enforce 1 second rate limit if flapping too much.
Note that the feature is still disabled but will be enabled
in follow-up patches.
Test: manual test
Bug: 129082217
Change-Id: Ic6b2f10f2c8b082820e0662eb9cee70d70d28cd6
Merged-In: Ic6b2f10f2c8b082820e0662eb9cee70d70d28cd6
(cherry picked from commit 15ab452e7e3f00289fbedbdb86c512ad560dda7e)
This commit is contained in:
@@ -25,6 +25,7 @@ import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Build;
|
||||
import android.service.NetworkIdentityProto;
|
||||
import android.telephony.Annotation.NetworkType;
|
||||
import android.util.Slog;
|
||||
import android.util.proto.ProtoOutputStream;
|
||||
|
||||
@@ -42,11 +43,8 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
|
||||
/**
|
||||
* When enabled, combine all {@link #mSubType} together under
|
||||
* {@link #SUBTYPE_COMBINED}.
|
||||
*
|
||||
* @deprecated we no longer offer to collect statistics on a per-subtype
|
||||
* basis; this is always disabled.
|
||||
*/
|
||||
@Deprecated
|
||||
// TODO: make this flag configurable through settings. See http://b/146415925
|
||||
public static final boolean COMBINE_SUBTYPE_ENABLED = true;
|
||||
|
||||
public static final int SUBTYPE_COMBINED = -1;
|
||||
@@ -187,13 +185,14 @@ public class NetworkIdentity implements Comparable<NetworkIdentity> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a {@link NetworkIdentity} from the given {@link NetworkState},
|
||||
* assuming that any mobile networks are using the current IMSI.
|
||||
* Build a {@link NetworkIdentity} from the given {@link NetworkState} and {@code subType},
|
||||
* assuming that any mobile networks are using the current IMSI. The subType if applicable,
|
||||
* should be set as one of the TelephonyManager.NETWORK_TYPE_* constants, or
|
||||
* {@link android.telephony.TelephonyManager#NETWORK_TYPE_UNKNOWN} if not.
|
||||
*/
|
||||
public static NetworkIdentity buildNetworkIdentity(Context context, NetworkState state,
|
||||
boolean defaultNetwork) {
|
||||
boolean defaultNetwork, @NetworkType int subType) {
|
||||
final int type = state.networkInfo.getType();
|
||||
final int subType = state.networkInfo.getSubtype();
|
||||
|
||||
String subscriberId = null;
|
||||
String networkId = null;
|
||||
|
||||
@@ -37,6 +37,7 @@ import static android.net.wifi.WifiInfo.sanitizeSsid;
|
||||
import android.compat.annotation.UnsupportedAppUsage;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.util.BackupUtils;
|
||||
import android.util.Log;
|
||||
|
||||
@@ -394,6 +395,45 @@ public class NetworkTemplate implements Parcelable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Radio Access Technology(RAT) type that is representative of a group of RAT types.
|
||||
* The mapping is corresponding to {@code TelephonyManager#NETWORK_CLASS_BIT_MASK_*}.
|
||||
*
|
||||
* @param ratType An integer defined in {@code TelephonyManager#NETWORK_TYPE_*}.
|
||||
*/
|
||||
// TODO: 1. Consider move this to TelephonyManager if used by other modules.
|
||||
// 2. Consider make this configurable.
|
||||
// 3. Use TelephonyManager APIs when available.
|
||||
public static int getCollapsedRatType(int ratType) {
|
||||
switch (ratType) {
|
||||
case TelephonyManager.NETWORK_TYPE_GPRS:
|
||||
case TelephonyManager.NETWORK_TYPE_GSM:
|
||||
case TelephonyManager.NETWORK_TYPE_EDGE:
|
||||
case TelephonyManager.NETWORK_TYPE_IDEN:
|
||||
case TelephonyManager.NETWORK_TYPE_CDMA:
|
||||
case TelephonyManager.NETWORK_TYPE_1xRTT:
|
||||
return TelephonyManager.NETWORK_TYPE_GSM;
|
||||
case TelephonyManager.NETWORK_TYPE_EVDO_0:
|
||||
case TelephonyManager.NETWORK_TYPE_EVDO_A:
|
||||
case TelephonyManager.NETWORK_TYPE_EVDO_B:
|
||||
case TelephonyManager.NETWORK_TYPE_EHRPD:
|
||||
case TelephonyManager.NETWORK_TYPE_UMTS:
|
||||
case TelephonyManager.NETWORK_TYPE_HSDPA:
|
||||
case TelephonyManager.NETWORK_TYPE_HSUPA:
|
||||
case TelephonyManager.NETWORK_TYPE_HSPA:
|
||||
case TelephonyManager.NETWORK_TYPE_HSPAP:
|
||||
case TelephonyManager.NETWORK_TYPE_TD_SCDMA:
|
||||
return TelephonyManager.NETWORK_TYPE_UMTS;
|
||||
case TelephonyManager.NETWORK_TYPE_LTE:
|
||||
case TelephonyManager.NETWORK_TYPE_IWLAN:
|
||||
return TelephonyManager.NETWORK_TYPE_LTE;
|
||||
case TelephonyManager.NETWORK_TYPE_NR:
|
||||
return TelephonyManager.NETWORK_TYPE_NR;
|
||||
default:
|
||||
return TelephonyManager.NETWORK_TYPE_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if matches Wi-Fi network template.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user