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

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

Fix GSM permanent failure handling.

Wait until all APN's have been tried before checking for permanent errors
and then, don't do retires only if all of the APN's had permanent errors.

Also, don't disable the requested apn type because if we do we won't
be able to setup data because there won't be an apn type.

This was tested by creating a new non existent APN, I chose:
  Name="badapn1"
  APN="badapn1"
  Server="noapn.com"

Then selecting "badapn1" will cause a permanent error.

bug: 3202729
Change-Id: I0a2160a852c5dcdd07ae06f93b3b77c29406af4b
parent 0dcea08a
Loading
Loading
Loading
Loading
+22 −13
Original line number Diff line number Diff line
@@ -106,7 +106,7 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
     * It is a subset of allApns and has the same format
     */
    private ArrayList<ApnSetting> mWaitingApns = null;

    private int mWaitingApnsPermanentFailureCountDown = 0;
    private ApnSetting mPreferredApn = null;

    /* Currently active APN */
@@ -361,6 +361,7 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {

            if (mState == State.IDLE) {
                mWaitingApns = buildWaitingApns(mRequestedApnType);
                mWaitingApnsPermanentFailureCountDown = mWaitingApns.size();
                if (mWaitingApns.isEmpty()) {
                    if (DBG) log("No APN found");
                    notifyNoData(GsmDataConnection.FailCause.MISSING_UNKNOWN_APN);
@@ -996,6 +997,9 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
        }

        if (ar.exception == null) {
            if(DBG) {
                log(String.format("onDataSetupComplete: success apn=%s", mWaitingApns.get(0).apn));
            }
            // TODO: We should clear LinkProperties/Capabilities when torn down or disconnected
            mLinkProperties = getLinkProperties(mPendingDataConnection);
            mLinkCapabilities = getLinkCapabilities(mPendingDataConnection);
@@ -1047,27 +1051,32 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
                log(String.format("onDataSetupComplete: error apn=%s cause=%s", apnString, cause));
            }
            if (cause.isEventLoggable()) {
                // Log this failure to the Event Logs.
                GsmCellLocation loc = ((GsmCellLocation)mPhone.getCellLocation());
                EventLog.writeEvent(EventLogTags.PDP_SETUP_FAIL,
                        cause.ordinal(), loc != null ? loc.getCid() : -1,
                        TelephonyManager.getDefault().getNetworkType());
            }

            // Do not retry on permanent failure
            // TODO: We should not fail permanently if more Apns to try!
            if (cause.isPermanentFail()) {
                notifyNoData(cause);
                notifyDataConnection(Phone.REASON_APN_FAILED);
                onEnableApn(apnTypeToId(mRequestedApnType), DISABLED);
                return;
            }

            // Count permanent failures and remove the APN we just tried
            mWaitingApnsPermanentFailureCountDown -= cause.isPermanentFail() ? 1 : 0;
            mWaitingApns.remove(0);
            if (DBG) log(String.format("onDataSetupComplete: mWaitingApns.size=%d" +
                            " mWaitingApnsPermanenatFailureCountDown=%d",
                            mWaitingApns.size(), mWaitingApnsPermanentFailureCountDown));

            // See if there are more APN's to try
            if (mWaitingApns.isEmpty()) {
                // No more to try, start delayed retry
                if (mWaitingApnsPermanentFailureCountDown == 0) {
                    if (DBG) log("onDataSetupComplete: Permanent failures stop retrying");
                    notifyNoData(cause);
                    notifyDataConnection(Phone.REASON_APN_FAILED);
                } else {
                    if (DBG) log("onDataSetupComplete: Not all permanent failures, retry");
                    startDelayedRetry(cause, reason);
                }
            } else {
                // we still have more apns to try
                if (DBG) log("onDataSetupComplete: Try next APN");
                setState(State.SCANNING);
                // Wait a bit before trying the next APN, so that
                // we're not tying up the RIL command channel