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

Commit 7590dfc1 authored by Scott Mertz's avatar Scott Mertz
Browse files

msim: initialize sim icon to the known state

- When system ui gets killed (for instance, during a theme change),
  MultiSimNetworkController may not receive the SIM_STATE_CHANGED
  for both sim cards.  Instead of initializing the sim to "ready",
  query for the actual state at initialization

Change-Id: Ia7f63827bbddca77de3daf4d5d149ec79ab91d5d
parent 5744ab14
Loading
Loading
Loading
Loading
+23 −4
Original line number Diff line number Diff line
@@ -110,7 +110,8 @@ public class MSimNetworkController extends NetworkController {
    public MSimNetworkController(Context context) {
        super(context);

        int numPhones = MSimTelephonyManager.getDefault().getPhoneCount();
        MSimTelephonyManager tm = MSimTelephonyManager.getDefault();
        int numPhones = tm.getPhoneCount();
        mMSimSignalStrength = new SignalStrength[numPhones];
        mMSimDataServiceState = new int[numPhones];
        mMSimServiceState = new ServiceState[numPhones];
@@ -143,11 +144,10 @@ public class MSimNetworkController extends NetworkController {
        mShowPlmn = new boolean[numPhones];
        mSpn = new String[numPhones];
        mPlmn = new String[numPhones];
        MSimTelephonyManager tm = MSimTelephonyManager.getDefault();
        for (int i=0; i < numPhones; i++) {
            mMSimSignalStrength[i] = new SignalStrength();
            mMSimServiceState[i] = new ServiceState();
            mMSimState[i] = IccCardConstants.State.READY;
            mMSimState[i] = simStateToIccState(tm.getSimState(i));
            // phone_signal
            mMSimPhoneSignalIconId[i] = R.drawable.stat_sys_signal_null;
            mMSimLastPhoneSignalIconId[i] = -1;
@@ -165,7 +165,7 @@ public class MSimNetworkController extends NetworkController {
            mMSimDataServiceState[i] = ServiceState.STATE_OUT_OF_SERVICE;
        }

        mDefaultSubscription = MSimTelephonyManager.getDefault().getDefaultSubscription();
        mDefaultSubscription = tm.getDefaultSubscription();
        mDataConnected = mMSimDataConnected[mDefaultSubscription];
        mSimState = mMSimState[mDefaultSubscription];
        mDataActivity = mMSimDataActivity[mDefaultSubscription];
@@ -300,6 +300,7 @@ public class MSimNetworkController extends NetworkController {
        } else if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
            updateSimState(intent);
            for (int sub = 0; sub < MSimTelephonyManager.getDefault().getPhoneCount(); sub++) {
                updateSimIcon(sub);
                updateDataIcon(sub);
                refreshViews(sub);
            }
@@ -558,6 +559,24 @@ public class MSimNetworkController extends NetworkController {
        updateDataIcon(sub);
    }

    private IccCardConstants.State simStateToIccState(int state) {
        switch(state) {
        case TelephonyManager.SIM_STATE_ABSENT:
            return IccCardConstants.State.ABSENT;
        case TelephonyManager.SIM_STATE_READY:
            return IccCardConstants.State.READY;
        case TelephonyManager.SIM_STATE_PIN_REQUIRED:
            return IccCardConstants.State.PIN_REQUIRED;
        case TelephonyManager.SIM_STATE_PUK_REQUIRED:
            return IccCardConstants.State.PUK_REQUIRED;
        case TelephonyManager.SIM_STATE_CARD_IO_ERROR:
        case TelephonyManager.SIM_STATE_NETWORK_LOCKED:
        case TelephonyManager.SIM_STATE_UNKNOWN:
        default:
            return IccCardConstants.State.UNKNOWN;
        }
    }

    private boolean isCdma(int subscription) {
        return (mMSimSignalStrength[subscription] != null) &&
                !mMSimSignalStrength[subscription].isGsm();