From d32aa193fdee6c2be5e5e4cb67e80f57299f1c04 Mon Sep 17 00:00:00 2001 From: Chiachang Wang Date: Fri, 23 Oct 2020 09:58:18 +0800 Subject: [PATCH] Expose NetworkRegistrationInfo.getNrState() as public API ConnectivityService is going to become a mainline module which will not able to access hidden APIs. DataConnectionStat needs to get the NR 5G state of the mobile data network for checking if the network type is 5G or not. API in NetworkRegistrationInfo is suggested to replace the original one in ServiceState. Thus, expose it as a public API to support it. Bug: 171183530 Test: make update-api ; m Test: atest CtsTelephonyTestCases Change-Id: I965499792286de4f1447559be66ca4be80bd0e6f --- api/current.txt | 1 + non-updatable-api/current.txt | 1 + .../com/android/server/connectivity/DataConnectionStats.java | 4 +--- telephony/java/android/telephony/NetworkRegistrationInfo.java | 1 - 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/api/current.txt b/api/current.txt index 22b8c456f6552..1b85521f78514 100644 --- a/api/current.txt +++ b/api/current.txt @@ -47669,6 +47669,7 @@ package android.telephony { method @NonNull public java.util.List getAvailableServices(); method @Nullable public android.telephony.CellIdentity getCellIdentity(); method public int getDomain(); + method public int getNrState(); method @Nullable public String getRegisteredPlmn(); method public int getTransportType(); method public boolean isRegistered(); diff --git a/non-updatable-api/current.txt b/non-updatable-api/current.txt index da3d0f7ff0599..b858b7b224243 100644 --- a/non-updatable-api/current.txt +++ b/non-updatable-api/current.txt @@ -45837,6 +45837,7 @@ package android.telephony { method @NonNull public java.util.List getAvailableServices(); method @Nullable public android.telephony.CellIdentity getCellIdentity(); method public int getDomain(); + method public int getNrState(); method @Nullable public String getRegisteredPlmn(); method public int getTransportType(); method public boolean isRegistered(); diff --git a/services/core/java/com/android/server/connectivity/DataConnectionStats.java b/services/core/java/com/android/server/connectivity/DataConnectionStats.java index 0304cdc475153..e50fb7be523ab 100644 --- a/services/core/java/com/android/server/connectivity/DataConnectionStats.java +++ b/services/core/java/com/android/server/connectivity/DataConnectionStats.java @@ -49,7 +49,6 @@ public class DataConnectionStats extends BroadcastReceiver { private SignalStrength mSignalStrength; private ServiceState mServiceState; private int mDataState = TelephonyManager.DATA_DISCONNECTED; - private int mNrState = NetworkRegistrationInfo.NR_STATE_NONE; public DataConnectionStats(Context context, Handler listenerHandler) { mContext = context; @@ -96,7 +95,7 @@ public class DataConnectionStats extends BroadcastReceiver { : regInfo.getAccessNetworkTechnology(); // If the device is in NSA NR connection the networkType will report as LTE. // For cell dwell rate metrics, this should report NR instead. - if (mNrState == NetworkRegistrationInfo.NR_STATE_CONNECTED) { + if (regInfo != null && regInfo.getNrState() == NetworkRegistrationInfo.NR_STATE_CONNECTED) { networkType = TelephonyManager.NETWORK_TYPE_NR; } if (DEBUG) Log.d(TAG, String.format("Noting data connection for network type %s: %svisible", @@ -153,7 +152,6 @@ public class DataConnectionStats extends BroadcastReceiver { @Override public void onServiceStateChanged(ServiceState state) { mServiceState = state; - mNrState = state.getNrState(); notePhoneDataConnectionState(); } diff --git a/telephony/java/android/telephony/NetworkRegistrationInfo.java b/telephony/java/android/telephony/NetworkRegistrationInfo.java index aee1e84ca3563..3be33a3f51570 100644 --- a/telephony/java/android/telephony/NetworkRegistrationInfo.java +++ b/telephony/java/android/telephony/NetworkRegistrationInfo.java @@ -370,7 +370,6 @@ public final class NetworkRegistrationInfo implements Parcelable { * Get the 5G NR connection state. * * @return the 5G NR connection state. - * @hide */ public @NRState int getNrState() { return mNrState;