Attribute data usage to virtual RAT type for 5G non-standalone mode

Test: atest NetworkStatsSubscriptionsMonitorTest#test5g
Bug: 160727498
Change-Id: I8753e68140c0993773017c9a49bd8a666a364071
Merged-In: I8753e68140c0993773017c9a49bd8a666a364071
(cherry-picked from ag/12167624)
This commit is contained in:
junyulai
2020-07-16 13:48:09 +08:00
parent cdf050d08f
commit 7fd64dee0f
2 changed files with 26 additions and 1 deletions

View File

@@ -84,6 +84,15 @@ public class NetworkTemplate implements Parcelable {
* @hide
*/
public static final int NETWORK_TYPE_ALL = -1;
/**
* Virtual RAT type to represent 5G NSA (Non Stand Alone) mode, where the primary cell is
* still LTE and network allocates a secondary 5G cell so telephony reports RAT = LTE along
* with NR state as connected. This should not be overlapped with any of the
* {@code TelephonyManager.NETWORK_TYPE_*} constants.
*
* @hide
*/
public static final int NETWORK_TYPE_5G_NSA = -2;
private static boolean isKnownMatchRule(final int rule) {
switch (rule) {
@@ -472,6 +481,9 @@ public class NetworkTemplate implements Parcelable {
return TelephonyManager.NETWORK_TYPE_LTE;
case TelephonyManager.NETWORK_TYPE_NR:
return TelephonyManager.NETWORK_TYPE_NR;
// Virtual RAT type for 5G NSA mode, see {@link NetworkTemplate#NETWORK_TYPE_5G_NSA}.
case NetworkTemplate.NETWORK_TYPE_5G_NSA:
return NetworkTemplate.NETWORK_TYPE_5G_NSA;
default:
return TelephonyManager.NETWORK_TYPE_UNKNOWN;
}

View File

@@ -16,12 +16,14 @@
package com.android.server.net;
import static android.net.NetworkTemplate.NETWORK_TYPE_5G_NSA;
import static android.net.NetworkTemplate.getCollapsedRatType;
import android.annotation.NonNull;
import android.content.Context;
import android.os.Looper;
import android.telephony.Annotation;
import android.telephony.NetworkRegistrationInfo;
import android.telephony.PhoneStateListener;
import android.telephony.ServiceState;
import android.telephony.SubscriptionManager;
@@ -196,7 +198,18 @@ public class NetworkStatsSubscriptionsMonitor extends
@Override
public void onServiceStateChanged(@NonNull ServiceState ss) {
final int networkType = ss.getDataNetworkType();
// In 5G SA (Stand Alone) mode, the primary cell itself will be 5G hence telephony
// would report RAT = 5G_NR.
// However, in 5G NSA (Non Stand Alone) mode, the primary cell is still LTE and
// network allocates a secondary 5G cell so telephony reports RAT = LTE along with
// NR state as connected. In such case, attributes the data usage to NR.
// See b/160727498.
final boolean is5GNsa = (ss.getDataNetworkType() == TelephonyManager.NETWORK_TYPE_LTE
|| ss.getDataNetworkType() == TelephonyManager.NETWORK_TYPE_LTE_CA)
&& ss.getNrState() == NetworkRegistrationInfo.NR_STATE_CONNECTED;
final int networkType =
(is5GNsa ? NETWORK_TYPE_5G_NSA : ss.getDataNetworkType());
final int collapsedRatType = getCollapsedRatType(networkType);
if (collapsedRatType == mLastCollapsedRatType) return;