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

Commit a0eb5bb4 authored by cretin45's avatar cretin45
Browse files

Setupwizard: Fix msim NPE where sim only in slot 2

Change-Id: I919129185cb49c51f9f02d9718e116e7d02b0d2c
parent 9a610892
Loading
Loading
Loading
Loading
+6 −2
Original line number Original line Diff line number Diff line
@@ -20,12 +20,15 @@ import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.ConnectivityManager;
import android.telephony.SubInfoRecord;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.telephony.TelephonyManager;


import com.android.internal.telephony.TelephonyIntents;
import com.android.internal.telephony.TelephonyIntents;
import com.cyanogenmod.setupwizard.util.SetupWizardUtils;
import com.cyanogenmod.setupwizard.util.SetupWizardUtils;


import java.util.ArrayList;
import java.util.ArrayList;
import java.util.List;


public class CMSetupWizardData extends AbstractSetupData {
public class CMSetupWizardData extends AbstractSetupData {


@@ -122,7 +125,7 @@ public class CMSetupWizardData extends AbstractSetupData {
        ChooseDataSimPage chooseDataSimPage =
        ChooseDataSimPage chooseDataSimPage =
                (ChooseDataSimPage) getPage(ChooseDataSimPage.TAG);
                (ChooseDataSimPage) getPage(ChooseDataSimPage.TAG);
        if (chooseDataSimPage != null) {
        if (chooseDataSimPage != null) {
            chooseDataSimPage.setHidden(!isSimInserted());
            chooseDataSimPage.setHidden(!allSimsInserted());
        }
        }
    }
    }


@@ -174,13 +177,14 @@ public class CMSetupWizardData extends AbstractSetupData {
    private boolean allSimsInserted() {
    private boolean allSimsInserted() {
        TelephonyManager tm = TelephonyManager.from(mContext);
        TelephonyManager tm = TelephonyManager.from(mContext);
        int simSlotCount = tm.getSimCount();
        int simSlotCount = tm.getSimCount();
        List<SubInfoRecord> subInfoRecords =  SubscriptionManager.getActiveSubInfoList();
        for (int i = 0; i < simSlotCount; i++) {
        for (int i = 0; i < simSlotCount; i++) {
            int state = tm.getSimState(i);
            int state = tm.getSimState(i);
            if (state == TelephonyManager.SIM_STATE_ABSENT) {
            if (state == TelephonyManager.SIM_STATE_ABSENT) {
                return false;
                return false;
            }
            }
        }
        }
        return true;
        return simSlotCount == subInfoRecords.size();
    }
    }


}
}
 No newline at end of file
+19 −15
Original line number Original line Diff line number Diff line
@@ -123,8 +123,7 @@ public class ChooseDataSimPage extends SetupPage {
            List<SubInfoRecord> subInfoRecords =  SubscriptionManager.getActiveSubInfoList();
            List<SubInfoRecord> subInfoRecords =  SubscriptionManager.getActiveSubInfoList();
            int simCount = subInfoRecords.size();
            int simCount = subInfoRecords.size();
            mSubInfoRecords = new SparseArray<SubInfoRecord>(simCount);
            mSubInfoRecords = new SparseArray<SubInfoRecord>(simCount);
            for (int i = 0; i < simCount; i++) {
            for (SubInfoRecord subInfoRecord : subInfoRecords) {
                SubInfoRecord subInfoRecord = subInfoRecords.get(i);
                mSubInfoRecords.put(subInfoRecord.slotId, subInfoRecord);
                mSubInfoRecords.put(subInfoRecord.slotId, subInfoRecord);
            }
            }
            mNameViews = new SparseArray<TextView>(simCount);
            mNameViews = new SparseArray<TextView>(simCount);
@@ -137,13 +136,17 @@ public class ChooseDataSimPage extends SetupPage {
            for (int i = 0; i < simCount; i++) {
            for (int i = 0; i < simCount; i++) {
                View simRow = inflater.inflate(R.layout.data_sim_row, null);
                View simRow = inflater.inflate(R.layout.data_sim_row, null);
                mPageView.addView(simRow);
                mPageView.addView(simRow);
                SubInfoRecord subInfoRecord = mSubInfoRecords.get(i);
                SubInfoRecord subInfoRecord = mSubInfoRecords.valueAt(i);
                simRow.setTag(subInfoRecord);
                simRow.setTag(subInfoRecord);
                simRow.setOnClickListener(mSetDataSimClickListener);
                simRow.setOnClickListener(mSetDataSimClickListener);
                mNameViews.put(i, (TextView) simRow.findViewById(R.id.sim_title));
                mNameViews.put(subInfoRecord.slotId,
                mSignalViews.put(i, (ImageView) simRow.findViewById(R.id.signal));
                        (TextView) simRow.findViewById(R.id.sim_title));
                mCheckBoxes.put(i, (CheckBox) simRow.findViewById(R.id.enable_check));
                mSignalViews.put(subInfoRecord.slotId,
                mPhoneStateListeners.put(i, createPhoneStateListener(subInfoRecord));
                        (ImageView) simRow.findViewById(R.id.signal));
                mCheckBoxes.put(subInfoRecord.slotId,
                        (CheckBox) simRow.findViewById(R.id.enable_check));
                mPhoneStateListeners.put(subInfoRecord.slotId,
                        createPhoneStateListener(subInfoRecord));
                mPageView.addView(inflater.inflate(R.layout.divider, null));
                mPageView.addView(inflater.inflate(R.layout.divider, null));
            }
            }
            updateSignalStrengths();
            updateSignalStrengths();
@@ -162,7 +165,7 @@ public class ChooseDataSimPage extends SetupPage {
            mContext = getActivity().getApplicationContext();
            mContext = getActivity().getApplicationContext();
            mPhone = (TelephonyManager)getActivity().getSystemService(Context.TELEPHONY_SERVICE);
            mPhone = (TelephonyManager)getActivity().getSystemService(Context.TELEPHONY_SERVICE);
            for (int i = 0; i < mPhoneStateListeners.size(); i++) {
            for (int i = 0; i < mPhoneStateListeners.size(); i++) {
                mPhone.listen(mPhoneStateListeners.get(i),
                mPhone.listen(mPhoneStateListeners.valueAt(i),
                        PhoneStateListener.LISTEN_SERVICE_STATE
                        PhoneStateListener.LISTEN_SERVICE_STATE
                                | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
                                | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
            }
            }
@@ -181,7 +184,7 @@ public class ChooseDataSimPage extends SetupPage {
            super.onPause();
            super.onPause();
            mIsAttached = false;
            mIsAttached = false;
            for (int i = 0; i < mPhoneStateListeners.size(); i++) {
            for (int i = 0; i < mPhoneStateListeners.size(); i++) {
                mPhone.listen(mPhoneStateListeners.get(i), PhoneStateListener.LISTEN_NONE);
                mPhone.listen(mPhoneStateListeners.valueAt(i), PhoneStateListener.LISTEN_NONE);
            }
            }
        }
        }


@@ -222,7 +225,7 @@ public class ChooseDataSimPage extends SetupPage {
        private void updateSignalStrengths() {
        private void updateSignalStrengths() {
            if (mIsAttached) {
            if (mIsAttached) {
                for (int i = 0; i < mSubInfoRecords.size(); i++) {
                for (int i = 0; i < mSubInfoRecords.size(); i++) {
                    updateSignalStrength(mSubInfoRecords.get(i));
                    updateSignalStrength(mSubInfoRecords.valueAt(i));
                }
                }
            }
            }
        }
        }
@@ -231,10 +234,10 @@ public class ChooseDataSimPage extends SetupPage {
            if (mIsAttached) {
            if (mIsAttached) {
                for (int i = 0; i < mCheckBoxes.size(); i++) {
                for (int i = 0; i < mCheckBoxes.size(); i++) {
                    if (subInfoRecord.slotId == i) {
                    if (subInfoRecord.slotId == i) {
                        mCheckBoxes.get(i).setChecked(true);
                        mCheckBoxes.get(subInfoRecord.slotId).setChecked(true);
                        SetupStats.addEvent(SetupStats.Categories.SETTING_CHANGED,
                        SetupStats.addEvent(SetupStats.Categories.SETTING_CHANGED,
                                SetupStats.Action.PREFERRED_DATA_SIM,
                                SetupStats.Action.PREFERRED_DATA_SIM,
                                SetupStats.Label.SLOT, String.valueOf(i + 1));
                                SetupStats.Label.SLOT, String.valueOf(subInfoRecord.slotId + 1));
                    } else {
                    } else {
                        mCheckBoxes.get(i).setChecked(false);
                        mCheckBoxes.get(i).setChecked(false);
                    }
                    }
@@ -246,9 +249,10 @@ public class ChooseDataSimPage extends SetupPage {
        private void updateCurrentDataSub() {
        private void updateCurrentDataSub() {
            if (mIsAttached) {
            if (mIsAttached) {
                for (int i = 0; i < mSubInfoRecords.size(); i++) {
                for (int i = 0; i < mSubInfoRecords.size(); i++) {
                    SubInfoRecord subInfoRecord = mSubInfoRecords.get(i);
                    SubInfoRecord subInfoRecord = mSubInfoRecords.valueAt(i);
                    mCheckBoxes.get(i).setChecked(SubscriptionManager.getDefaultDataSubId()
                    final long defaultDataSubId =  SubscriptionManager.getDefaultDataSubId();
                            == subInfoRecord.subId);
                    mCheckBoxes.get(subInfoRecord.slotId)
                            .setChecked(defaultDataSubId == subInfoRecord.subId);


                }
                }
            }
            }