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

Commit 6de15357 authored by Pengquan Meng's avatar Pengquan Meng Committed by android-build-merger
Browse files

Merge "Change data connection state logic"

am: 0bc2cefb

Change-Id: I4f9ca1df910531d5e8f641434c134a152173fae3
parents 02e72785 0bc2cefb
Loading
Loading
Loading
Loading
+4 −10
Original line number Diff line number Diff line
@@ -530,12 +530,6 @@ public class GsmCdmaPhone extends Phone {
            ret = PhoneConstants.DataState.DISCONNECTED;
        } else { /* mSST.gprsState == ServiceState.STATE_IN_SERVICE */
            switch (mDcTracker.getState(apnType)) {
                case RETRYING:
                case FAILED:
                case IDLE:
                    ret = PhoneConstants.DataState.DISCONNECTED;
                break;

                case CONNECTED:
                case DISCONNECTING:
                    if ( mCT.mState != PhoneConstants.State.IDLE
@@ -545,11 +539,11 @@ public class GsmCdmaPhone extends Phone {
                        ret = PhoneConstants.DataState.CONNECTED;
                    }
                    break;

                case CONNECTING:
                case SCANNING:
                    ret = PhoneConstants.DataState.CONNECTING;
                    break;
                default:
                    ret = PhoneConstants.DataState.DISCONNECTED;
            }
        }

+14 −2
Original line number Diff line number Diff line
@@ -298,10 +298,22 @@ public class DataConnection extends StateMachine {
        return new LinkProperties(mLinkProperties);
    }

    boolean getIsInactive() {
    boolean isInactive() {
        return getCurrentState() == mInactiveState;
    }

    boolean isDisconnecting() {
        return getCurrentState() == mDisconnectingState;
    }

    boolean isActive() {
        return getCurrentState() == mActiveState;
    }

    boolean isActivating() {
        return getCurrentState() == mActivatingState;
    }

    int getCid() {
        return mCid;
    }
@@ -1265,7 +1277,7 @@ public class DataConnection extends StateMachine {
                    break;
                }
                case DcAsyncChannel.REQ_IS_INACTIVE: {
                    boolean val = getIsInactive();
                    boolean val = isInactive();
                    if (VDBG) log("REQ_IS_INACTIVE  isInactive=" + val);
                    mAc.replyToMessage(msg, DcAsyncChannel.RSP_IS_INACTIVE, val ? 1 : 0);
                    break;
+1 −1
Original line number Diff line number Diff line
@@ -153,7 +153,7 @@ public class DcAsyncChannel extends AsyncChannel {
                value = false;
            }
        } else {
            value = mDc.getIsInactive();
            value = mDc.isInactive();
        }
        return value;
    }
+22 −5
Original line number Diff line number Diff line
@@ -1083,13 +1083,30 @@ public class DcTracker extends Handler {
        return null;
    }

    // Return state of specific apn type
    /**
     * Returns {@link DctConstants.State} based on the state of the {@link DataConnection} that
     * contains a {@link ApnSetting} that supported the given apn type {@code anpType}.
     *
     * <p>
     * Assumes there is less than one {@link ApnSetting} can support the given apn type.
     */
    public DctConstants.State getState(String apnType) {
        ApnContext apnContext = mApnContexts.get(apnType);
        if (apnContext != null) {
            return apnContext.getState();
        for (DataConnection dc : mDataConnections.values()) {
            ApnSetting apnSetting = dc.getApnSetting();
            if (apnSetting != null && apnSetting.canHandleType(apnType)) {
                if (dc.isActive()) {
                    return DctConstants.State.CONNECTED;
                } else if (dc.isActivating()) {
                    return DctConstants.State.CONNECTING;
                } else if (dc.isInactive()) {
                    return DctConstants.State.IDLE;
                } else if (dc.isDisconnecting()) {
                    return DctConstants.State.DISCONNECTING;
                }
        return DctConstants.State.FAILED;
            }
        }

        return DctConstants.State.IDLE;
    }

    // Return if apn type is a provisioning apn.
+40 −12
Original line number Diff line number Diff line
@@ -604,7 +604,7 @@ public class DcTrackerTest extends TelephonyTest {

        logd("Sending EVENT_ENABLE_NEW_APN");
        // APN id 0 is APN_TYPE_DEFAULT
        mDct.setEnabled(0, true);
        mDct.setEnabled(DctConstants.APN_DEFAULT_ID, true);
        waitForMs(200);

        dataConnectionReasons = new DataConnectionReasons();
@@ -678,7 +678,7 @@ public class DcTrackerTest extends TelephonyTest {

        logd("Sending EVENT_ENABLE_NEW_APN");
        // APN id 0 is APN_TYPE_DEFAULT
        mDct.setEnabled(0, true);
        mDct.setEnabled(DctConstants.APN_DEFAULT_ID, true);
        waitForMs(200);


@@ -737,8 +737,8 @@ public class DcTrackerTest extends TelephonyTest {
        boolean dataEnabled = mDct.isUserDataEnabled();
        mBundle.putStringArray(CarrierConfigManager.KEY_CARRIER_METERED_APN_TYPES_STRINGS,
                new String[]{PhoneConstants.APN_TYPE_DEFAULT, PhoneConstants.APN_TYPE_MMS});
        mDct.setEnabled(5, true);
        mDct.setEnabled(0, true);
        mDct.setEnabled(DctConstants.APN_IMS_ID, true);
        mDct.setEnabled(DctConstants.APN_DEFAULT_ID, true);

        logd("Sending EVENT_RECORDS_LOADED");
        mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_RECORDS_LOADED, null));
@@ -791,8 +791,9 @@ public class DcTrackerTest extends TelephonyTest {

        mBundle.putStringArray(CarrierConfigManager.KEY_CARRIER_METERED_ROAMING_APN_TYPES_STRINGS,
                new String[]{PhoneConstants.APN_TYPE_DEFAULT, PhoneConstants.APN_TYPE_MMS});
        mDct.setEnabled(5, true);
        mDct.setEnabled(0, true);

        mDct.setEnabled(DctConstants.APN_IMS_ID, true);
        mDct.setEnabled(DctConstants.APN_DEFAULT_ID, true);

        logd("Sending EVENT_RECORDS_LOADED");
        mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_RECORDS_LOADED, null));
@@ -849,8 +850,8 @@ public class DcTrackerTest extends TelephonyTest {
        //set Default and MMS to be metered in the CarrierConfigManager
        mBundle.putStringArray(CarrierConfigManager.KEY_CARRIER_METERED_ROAMING_APN_TYPES_STRINGS,
                new String[]{PhoneConstants.APN_TYPE_DEFAULT, PhoneConstants.APN_TYPE_MMS});
        mDct.setEnabled(5, true);
        mDct.setEnabled(0, true);
        mDct.setEnabled(DctConstants.APN_IMS_ID, true);
        mDct.setEnabled(DctConstants.APN_DEFAULT_ID, true);

        logd("Sending DATA_ENABLED_CMD");
        mDct.setUserDataEnabled(true);
@@ -964,8 +965,8 @@ public class DcTrackerTest extends TelephonyTest {
        boolean dataEnabled = mDct.isUserDataEnabled();
        mDct.setUserDataEnabled(true);

        mDct.setEnabled(5, true);
        mDct.setEnabled(0, true);
        mDct.setEnabled(DctConstants.APN_IMS_ID, true);
        mDct.setEnabled(DctConstants.APN_DEFAULT_ID, true);

        logd("Sending EVENT_RECORDS_LOADED");
        mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_RECORDS_LOADED, null));
@@ -1030,6 +1031,33 @@ public class DcTrackerTest extends TelephonyTest {
                any(Message.class));
    }

    @Test
    @SmallTest
    public void testGetDataConnectionState() throws Exception {
        initApns(PhoneConstants.APN_TYPE_SUPL,
                new String[]{PhoneConstants.APN_TYPE_SUPL, PhoneConstants.APN_TYPE_DEFAULT});
        mDct.setUserDataEnabled(false);

        mBundle.putStringArray(CarrierConfigManager.KEY_CARRIER_METERED_APN_TYPES_STRINGS,
                new String[]{PhoneConstants.APN_TYPE_DEFAULT});

        logd("Sending EVENT_RECORDS_LOADED");
        mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_RECORDS_LOADED, null));
        waitForMs(200);

        logd("Sending EVENT_DATA_CONNECTION_ATTACHED");
        mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_DATA_CONNECTION_ATTACHED, null));
        waitForMs(200);

        mDct.sendMessage(mDct.obtainMessage(DctConstants.EVENT_TRY_SETUP_DATA, mApnContext));
        waitForMs(200);

        // Assert that both APN_TYPE_SUPL & APN_TYPE_DEFAULT are connected even we only setup data
        // for APN_TYPE_SUPL
        assertEquals(DctConstants.State.CONNECTED, mDct.getState(PhoneConstants.APN_TYPE_SUPL));
        assertEquals(DctConstants.State.CONNECTED, mDct.getState(PhoneConstants.APN_TYPE_DEFAULT));
    }

    // Test the unmetered APN setup when data is disabled.
    @Test
    @SmallTest
@@ -1233,7 +1261,7 @@ public class DcTrackerTest extends TelephonyTest {
                .getRilDataRadioTechnology();
        mBundle.putStringArray(CarrierConfigManager.KEY_CARRIER_METERED_APN_TYPES_STRINGS,
                new String[]{PhoneConstants.APN_TYPE_DEFAULT});
        mDct.setEnabled(0, true);
        mDct.setEnabled(DctConstants.APN_DEFAULT_ID, true);
        mDct.setUserDataEnabled(true);
        initApns(PhoneConstants.APN_TYPE_DEFAULT, new String[]{PhoneConstants.APN_TYPE_ALL});

@@ -1353,7 +1381,7 @@ public class DcTrackerTest extends TelephonyTest {
                .getRilDataRadioTechnology();
        mBundle.putStringArray(CarrierConfigManager.KEY_CARRIER_METERED_APN_TYPES_STRINGS,
                new String[]{PhoneConstants.APN_TYPE_DEFAULT});
        mDct.setEnabled(0, true);
        mDct.setEnabled(DctConstants.APN_DEFAULT_ID, true);
        mDct.setUserDataEnabled(true);
        initApns(PhoneConstants.APN_TYPE_DEFAULT, new String[]{PhoneConstants.APN_TYPE_ALL});