Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d69f626d authored by Amit Mahajan's avatar Amit Mahajan
Browse files

Improve the check for SIM presence.

Earlier it was done based on SubscriptionsChangedListener which
timing wise is not a very appropriate trigger, particularly since
it can clear some values cached from the current SIM. Now the
check is based on querying SIM state.

Test: manual
Bug: 112333424
Change-Id: I2b49baf98c5aa2924318b6dc2e353c79390a47e8
parent c00372cc
Loading
Loading
Loading
Loading
+24 −17
Original line number Original line Diff line number Diff line
@@ -222,7 +222,6 @@ public class ServiceStateTracker extends Handler {
    protected static final int EVENT_ALL_DATA_DISCONNECTED             = 49;
    protected static final int EVENT_ALL_DATA_DISCONNECTED             = 49;
    protected static final int EVENT_PHONE_TYPE_SWITCHED               = 50;
    protected static final int EVENT_PHONE_TYPE_SWITCHED               = 50;
    protected static final int EVENT_RADIO_POWER_FROM_CARRIER          = 51;
    protected static final int EVENT_RADIO_POWER_FROM_CARRIER          = 51;
    protected static final int EVENT_SIM_NOT_INSERTED                  = 52;
    protected static final int EVENT_IMS_SERVICE_STATE_CHANGED         = 53;
    protected static final int EVENT_IMS_SERVICE_STATE_CHANGED         = 53;
    protected static final int EVENT_RADIO_POWER_OFF_DONE              = 54;
    protected static final int EVENT_RADIO_POWER_OFF_DONE              = 54;
    protected static final int EVENT_PHYSICAL_CHANNEL_CONFIG           = 55;
    protected static final int EVENT_PHYSICAL_CHANNEL_CONFIG           = 55;
@@ -343,14 +342,6 @@ public class ServiceStateTracker extends Handler {
                }
                }
                // update voicemail count and notify message waiting changed
                // update voicemail count and notify message waiting changed
                mPhone.updateVoiceMail();
                mPhone.updateVoiceMail();

                // cancel notifications if we see SIM_NOT_INSERTED (This happens on bootup before
                // the SIM is first detected and then subsequently on SIM removals)
                if (mSubscriptionController.getSlotIndex(subId)
                        == SubscriptionManager.SIM_NOT_INSERTED) {
                    // this is handled on the main thread to mitigate racing with setNotification().
                    sendMessage(obtainMessage(EVENT_SIM_NOT_INSERTED));
                }
            }
            }
        }
        }
    };
    };
@@ -1021,6 +1012,15 @@ public class ServiceStateTracker extends Handler {
                break;
                break;


            case EVENT_ICC_CHANGED:
            case EVENT_ICC_CHANGED:
                if (isSimAbsent()) {
                    if (DBG) log("EVENT_ICC_CHANGED: SIM absent");
                    // cancel notifications if SIM is removed/absent
                    cancelAllNotifications();
                    // clear cached values on SIM removal
                    mMdn = null;
                    mMin = null;
                    mIsMinInfoReady = false;
                }
                onUpdateIccAvailability();
                onUpdateIccAvailability();
                if (mUiccApplcation != null
                if (mUiccApplcation != null
                        && mUiccApplcation.getState() != AppState.APPSTATE_READY) {
                        && mUiccApplcation.getState() != AppState.APPSTATE_READY) {
@@ -1278,14 +1278,6 @@ public class ServiceStateTracker extends Handler {
                }
                }
                break;
                break;


            case EVENT_SIM_NOT_INSERTED:
                if (DBG) log("EVENT_SIM_NOT_INSERTED");
                cancelAllNotifications();
                mMdn = null;
                mMin = null;
                mIsMinInfoReady = false;
                break;

            case EVENT_ALL_DATA_DISCONNECTED:
            case EVENT_ALL_DATA_DISCONNECTED:
                int dds = SubscriptionManager.getDefaultDataSubscriptionId();
                int dds = SubscriptionManager.getDefaultDataSubscriptionId();
                ProxyController.getInstance().unregisterForAllDataDisconnected(dds, this);
                ProxyController.getInstance().unregisterForAllDataDisconnected(dds, this);
@@ -1482,6 +1474,21 @@ public class ServiceStateTracker extends Handler {
        }
        }
    }
    }


    private boolean isSimAbsent() {
        boolean simAbsent;
        if (mUiccController == null) {
            simAbsent = true;
        } else {
            UiccCard uiccCard = mUiccController.getUiccCard(mPhone.getPhoneId());
            if (uiccCard == null) {
                simAbsent = true;
            } else {
                simAbsent = (uiccCard.getCardState() == CardState.CARDSTATE_ABSENT);
            }
        }
        return simAbsent;
    }

    private int[] getBandwidthsFromConfigs(List<PhysicalChannelConfig> list) {
    private int[] getBandwidthsFromConfigs(List<PhysicalChannelConfig> list) {
        return list.stream()
        return list.stream()
                .map(PhysicalChannelConfig::getCellBandwidthDownlink)
                .map(PhysicalChannelConfig::getCellBandwidthDownlink)