Merge "To avoid the NullPointerException of UiccSlotInfo" into main

This commit is contained in:
SongFerng Wang
2023-11-01 06:21:49 +00:00
committed by Android (Google) Code Review
3 changed files with 16 additions and 8 deletions

View File

@@ -171,8 +171,11 @@ public class EnableMultiSimSidecar extends AsyncTaskSidecar<Void, Boolean> {
} }
int activePorts = 0; int activePorts = 0;
for (UiccSlotInfo slotInfo : slotsInfo) { for (UiccSlotInfo slotInfo : slotsInfo) {
if (slotInfo == null) {
continue;
}
for (UiccPortInfo portInfo : slotInfo.getPorts()) { for (UiccPortInfo portInfo : slotInfo.getPorts()) {
if (slotInfo != null && portInfo.isActive()) { if (portInfo.isActive()) {
activePorts++; activePorts++;
} }
} }
@@ -189,8 +192,11 @@ public class EnableMultiSimSidecar extends AsyncTaskSidecar<Void, Boolean> {
} }
Set<Integer> activeRemovableLogicalSlotIds = new ArraySet<>(); Set<Integer> activeRemovableLogicalSlotIds = new ArraySet<>();
for (UiccSlotInfo info : infos) { for (UiccSlotInfo info : infos) {
for (UiccPortInfo portInfo :info.getPorts()) { if (info == null) {
if (info != null && portInfo.isActive() && info.isRemovable()) { continue;
}
for (UiccPortInfo portInfo : info.getPorts()) {
if (portInfo.isActive() && info.isRemovable()) {
activeRemovableLogicalSlotIds.add(portInfo.getLogicalSlotIndex()); activeRemovableLogicalSlotIds.add(portInfo.getLogicalSlotIndex());
} }
} }

View File

@@ -378,11 +378,11 @@ public class MobileNetworkRepository extends SubscriptionManager.OnSubscriptions
return mMobileNetworkInfoDao.queryMobileNetworkInfoBySubId(subId); return mMobileNetworkInfoDao.queryMobileNetworkInfoBySubId(subId);
} }
private void getUiccInfoBySubscriptionInfo(UiccSlotInfo[] uiccSlotInfos, private void getUiccInfoBySubscriptionInfo(@NonNull UiccSlotInfo[] uiccSlotInfos,
SubscriptionInfo subInfo) { SubscriptionInfo subInfo) {
for (int i = 0; i < uiccSlotInfos.length; i++) { for (int i = 0; i < uiccSlotInfos.length; i++) {
UiccSlotInfo curSlotInfo = uiccSlotInfos[i]; UiccSlotInfo curSlotInfo = uiccSlotInfos[i];
if (curSlotInfo.getCardStateInfo() == CARD_STATE_INFO_PRESENT) { if (curSlotInfo != null && curSlotInfo.getCardStateInfo() == CARD_STATE_INFO_PRESENT) {
final int index = i; final int index = i;
mIsEuicc = curSlotInfo.getIsEuicc(); mIsEuicc = curSlotInfo.getIsEuicc();
mCardState = curSlotInfo.getCardStateInfo(); mCardState = curSlotInfo.getCardStateInfo();

View File

@@ -301,7 +301,8 @@ public class UiccSlotUtil {
} }
if (slotId == INVALID_PHYSICAL_SLOT_ID) { if (slotId == INVALID_PHYSICAL_SLOT_ID) {
for (int i = 0; i < slots.length; i++) { for (int i = 0; i < slots.length; i++) {
if (slots[i].isRemovable() if (slots[i] != null
&& slots[i].isRemovable()
&& !slots[i].getIsEuicc() && !slots[i].getIsEuicc()
&& !slots[i].getPorts().stream().findFirst().get().isActive() && !slots[i].getPorts().stream().findFirst().get().isActive()
&& slots[i].getCardStateInfo() != UiccSlotInfo.CARD_STATE_INFO_ERROR && slots[i].getCardStateInfo() != UiccSlotInfo.CARD_STATE_INFO_ERROR
@@ -310,8 +311,9 @@ public class UiccSlotUtil {
} }
} }
} else { } else {
if (slotId >= slots.length || !slots[slotId].isRemovable()) { if (slotId >= slots.length || slots[slotId] == null || !slots[slotId].isRemovable()) {
throw new UiccSlotsException("The given slotId is not a removable slot: " + slotId); Log.d(TAG, "The given slotId is not a removable slot: " + slotId);
return INVALID_PHYSICAL_SLOT_ID;
} }
if (!slots[slotId].getPorts().stream().findFirst().get().isActive()) { if (!slots[slotId].getPorts().stream().findFirst().get().isActive()) {
return slotId; return slotId;