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

Commit f54d520e authored by Wink Saville's avatar Wink Saville
Browse files

Fix ArrayOutOfBounds bug, tighten parameter checking.

Also, make logging consistent.

Bug: 17424200
Change-Id: Ie5bef1f557bf88b01eeb97c117807a40689c28e4
parent 691b8d29
Loading
Loading
Loading
Loading
+31 −14
Original line number Original line Diff line number Diff line
@@ -143,11 +143,16 @@ public class DctController extends Handler {


                    long subId = intent.getLongExtra(PhoneConstants.SUBSCRIPTION_KEY, PhoneConstants.SUB1);
                    long subId = intent.getLongExtra(PhoneConstants.SUBSCRIPTION_KEY, PhoneConstants.SUB1);
                    int phoneId = SubscriptionManager.getPhoneId(subId);
                    int phoneId = SubscriptionManager.getPhoneId(subId);
                    logd("DataStateReceiver phoneId= " + phoneId);
                    logd("DataStateReceiver: phoneId= " + phoneId);


                    // for the case of network out of service when bootup
                    // for the case of network out of service when bootup (ignore dummy values too)
                    if (subId == -1 || subId == -2) {
                    if (!SubscriptionManager.isValidSubId(subId) || (subId < 0)) {
                        logd("Network out of service and return");
                        // FIXME: Maybe add SM.isRealSubId(subId)??
                        logd("DataStateReceiver: ignore invalid subId=" + subId);
                        return;
                    }
                    if (!SubscriptionManager.isValidPhoneId(phoneId)) {
                        logd("DataStateReceiver: ignore invalid phoneId=" + phoneId);
                        return;
                        return;
                    }
                    }


@@ -157,31 +162,35 @@ public class DctController extends Handler {
                        switch (state) {
                        switch (state) {
                            case ServiceState.STATE_POWER_OFF:
                            case ServiceState.STATE_POWER_OFF:
                                mServicePowerOffFlag[phoneId] = true;
                                mServicePowerOffFlag[phoneId] = true;
                                logd("Recv STATE_POWER_OFF Intent from phoneId=" + phoneId);
                                logd("DataStateReceiver: STATE_POWER_OFF Intent from phoneId="
                                        + phoneId);
                                break;
                                break;
                            case ServiceState.STATE_IN_SERVICE:
                            case ServiceState.STATE_IN_SERVICE:
                                mServicePowerOffFlag[phoneId] = false;
                                mServicePowerOffFlag[phoneId] = false;
                                logd("Recv STATE_IN_SERVICE Intent from phoneId=" + phoneId);
                                logd("DataStateReceiver: STATE_IN_SERVICE Intent from phoneId="
                                        + phoneId);
                                break;
                                break;
                            case ServiceState.STATE_OUT_OF_SERVICE:
                            case ServiceState.STATE_OUT_OF_SERVICE:
                                logd("Recv STATE_OUT_OF_SERVICE Intent from phoneId=" + phoneId);
                                logd("DataStateReceiver: STATE_OUT_OF_SERVICE Intent from phoneId="
                                        + phoneId);
                                if (mServicePowerOffFlag[phoneId]) {
                                if (mServicePowerOffFlag[phoneId]) {
                                    mServicePowerOffFlag[phoneId] = false;
                                    mServicePowerOffFlag[phoneId] = false;
                                }
                                }
                                break;
                                break;
                            case ServiceState.STATE_EMERGENCY_ONLY:
                            case ServiceState.STATE_EMERGENCY_ONLY:
                                logd("Recv STATE_EMERGENCY_ONLY Intent from phoneId=" + phoneId);
                                logd("DataStateReceiver: STATE_EMERGENCY_ONLY Intent from phoneId="
                                        + phoneId);
                                break;
                                break;
                            default:
                            default:
                                logd("Recv SERVICE_STATE_CHANGED invalid state");
                                logd("DataStateReceiver: SERVICE_STATE_CHANGED invalid state");
                                break;
                                break;
                        }
                        }


                        if (prevPowerOff && mServicePowerOffFlag[phoneId] == false &&
                        if (prevPowerOff && mServicePowerOffFlag[phoneId] == false &&
                                mCurrentDataPhone == PHONE_NONE &&
                                mCurrentDataPhone == PHONE_NONE &&
                                phoneId == getDataConnectionFromSetting()) {
                                phoneId == getDataConnectionFromSetting()) {
                            logd("Current Phone is none and default Phone is " +
                            logd("DataStateReceiver: Current Phone is none and default phoneId="
                                    phoneId + ", then enableApnType()");
                                    + phoneId + ", then enableApnType()");
                            enableApnType(subId, PhoneConstants.APN_TYPE_DEFAULT);
                            enableApnType(subId, PhoneConstants.APN_TYPE_DEFAULT);
                        }
                        }
                    }
                    }
@@ -210,7 +219,15 @@ public class DctController extends Handler {
    }
    }


    private DctController(PhoneProxy[] phones) {
    private DctController(PhoneProxy[] phones) {
        mPhoneNum = TelephonyManager.getDefault().getPhoneCount();
        if (phones == null || phones.length == 0) {
            if (phones == null) {
                loge("DctController(phones): UNEXPECTED phones=null, ignore");
            } else {
                loge("DctController(phones): UNEXPECTED phones.length=0, ignore");
            }
            return;
        }
        mPhoneNum = phones.length;
        mServicePowerOffFlag = new boolean[mPhoneNum];
        mServicePowerOffFlag = new boolean[mPhoneNum];
        mPhones = phones;
        mPhones = phones;


@@ -232,9 +249,9 @@ public class DctController extends Handler {
                mDcSwitchStateHandler[i], mDcSwitchState[i].getHandler());
                mDcSwitchStateHandler[i], mDcSwitchState[i].getHandler());


            if (status == AsyncChannel.STATUS_SUCCESSFUL) {
            if (status == AsyncChannel.STATUS_SUCCESSFUL) {
                logd("Connect success: " + i);
                logd("DctController(phones): Connect success: " + i);
            } else {
            } else {
                loge("Could not connect to " + i);
                loge("DctController(phones): Could not connect to " + i);
            }
            }


            mDcSwitchState[i].registerForIdle(mRspHander, EVENT_PHONE1_DETACH + i, null);
            mDcSwitchState[i].registerForIdle(mRspHander, EVENT_PHONE1_DETACH + i, null);