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

Commit 553b3074 authored by Pengquan Meng's avatar Pengquan Meng
Browse files

Correct the state of the given APN type

The data connection can serve multiple apn, therefore we should find the
best state among the connection that can serve the given apn type.

Bug: 137600663
Test: manual test
Change-Id: Ic59b13250a2d67c681d32e0818fc2cf621768dbf
parent f9f3936c
Loading
Loading
Loading
Loading
+25 −5
Original line number Diff line number Diff line
@@ -268,6 +268,14 @@ public class DcTracker extends Handler {
    private static final String INTENT_DATA_STALL_ALARM_EXTRA_TRANSPORT_TYPE =
            "data_stall_alarm_extra_transport_type";

    /** The higher index has higher priority. */
    private static final DctConstants.State[] DATA_CONNECTION_STATE_PRIORITIES = {
            DctConstants.State.IDLE,
            DctConstants.State.DISCONNECTING,
            DctConstants.State.CONNECTING,
            DctConstants.State.CONNECTED,
    };

    private DcTesterFailBringUpAll mDcTesterFailBringUpAll;
    private DcController mDcc;

@@ -1118,23 +1126,35 @@ public class DcTracker extends Handler {
     * Assumes there is less than one {@link ApnSetting} can support the given apn type.
     */
    public DctConstants.State getState(String apnType) {
        DctConstants.State state = DctConstants.State.IDLE;
        final int apnTypeBitmask = ApnSetting.getApnTypesBitmaskFromString(apnType);
        for (DataConnection dc : mDataConnections.values()) {
            ApnSetting apnSetting = dc.getApnSetting();
            if (apnSetting != null && apnSetting.canHandleType(apnTypeBitmask)) {
                if (dc.isActive()) {
                    return DctConstants.State.CONNECTED;
                    state = getBetterConnectionState(state, DctConstants.State.CONNECTED);
                } else if (dc.isActivating()) {
                    return DctConstants.State.CONNECTING;
                    state = getBetterConnectionState(state, DctConstants.State.CONNECTING);
                } else if (dc.isInactive()) {
                    return DctConstants.State.IDLE;
                    state = getBetterConnectionState(state, DctConstants.State.IDLE);
                } else if (dc.isDisconnecting()) {
                    return DctConstants.State.DISCONNECTING;
                    state = getBetterConnectionState(state, DctConstants.State.DISCONNECTING);
                }
            }
        }
        return state;
    }

        return DctConstants.State.IDLE;
    /**
     * Return a better connection state between {@code stateA} and {@code stateB}. Check
     * {@link #DATA_CONNECTION_STATE_PRIORITIES} for the details.
     * @return the better connection state between {@code stateA} and {@code stateB}.
     */
    private static DctConstants.State getBetterConnectionState(
            DctConstants.State stateA, DctConstants.State stateB) {
        int idxA = ArrayUtils.indexOf(DATA_CONNECTION_STATE_PRIORITIES, stateA);
        int idxB = ArrayUtils.indexOf(DATA_CONNECTION_STATE_PRIORITIES, stateB);
        return idxA >= idxB ? stateA : stateB;
    }

    // Return if apn type is a provisioning apn.