From ec65e54a90f10e9afa4393eea10392b36b7f0ef0 Mon Sep 17 00:00:00 2001 From: Nathan Harold Date: Thu, 18 Aug 2022 18:39:31 -0700 Subject: Ensure that onCellInfo is always NonNull During phone creation and phone count changes, it was possible to get a null value for onCellInfo(). Since the API is documented as NonNull, always return a non-null value, forcing an empty list in case there is still a null lurking somewhere else. Bug: 237964039 Test: atest TelephonyRegistryTest#testCellInfoChanged Change-Id: I3b46c211f5542a39187b9d3b137f8483c44ccd39 --- .../core/java/com/android/server/TelephonyRegistry.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/services/core/java/com/android/server/TelephonyRegistry.java b/services/core/java/com/android/server/TelephonyRegistry.java index 0807fbaf7cc3..1bf1c9faaacc 100644 --- a/services/core/java/com/android/server/TelephonyRegistry.java +++ b/services/core/java/com/android/server/TelephonyRegistry.java @@ -339,7 +339,7 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { private int[] mDataConnectionNetworkType; - private ArrayList> mCellInfo = null; + private ArrayList> mCellInfo; private Map> mEmergencyNumberList; @@ -725,7 +725,7 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { mMessageWaiting[i] = false; mCallForwarding[i] = false; mCellIdentity[i] = null; - mCellInfo.add(i, null); + mCellInfo.add(i, Collections.EMPTY_LIST); mImsReasonInfo.add(i, null); mSrvccState[i] = TelephonyManager.SRVCC_STATE_HANDOVER_NONE; mCallDisconnectCause[i] = DisconnectCause.NOT_VALID; @@ -802,7 +802,7 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { mCallNetworkType = new int[numPhones]; mCallAttributes = new CallAttributes[numPhones]; mPreciseDataConnectionStates = new ArrayList<>(); - mCellInfo = new ArrayList<>(); + mCellInfo = new ArrayList<>(numPhones); mImsReasonInfo = new ArrayList<>(); mEmergencyNumberList = new HashMap<>(); mOutgoingCallEmergencyNumber = new EmergencyNumber[numPhones]; @@ -832,7 +832,7 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { mMessageWaiting[i] = false; mCallForwarding[i] = false; mCellIdentity[i] = null; - mCellInfo.add(i, null); + mCellInfo.add(i, Collections.EMPTY_LIST); mImsReasonInfo.add(i, null); mSrvccState[i] = TelephonyManager.SRVCC_STATE_HANDOVER_NONE; mCallDisconnectCause[i] = DisconnectCause.NOT_VALID; @@ -1794,10 +1794,17 @@ public class TelephonyRegistry extends ITelephonyRegistry.Stub { if (!checkNotifyPermission("notifyCellInfoForSubscriber()")) { return; } + if (VDBG) { log("notifyCellInfoForSubscriber: subId=" + subId + " cellInfo=" + cellInfo); } + + if (cellInfo == null) { + loge("notifyCellInfoForSubscriber() received a null list"); + cellInfo = Collections.EMPTY_LIST; + } + int phoneId = getPhoneIdFromSubId(subId); synchronized (mRecords) { if (validatePhoneId(phoneId)) { -- cgit v1.2.3-59-g8ed1b