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

Commit a7a1e7f2 authored by Jack Yu's avatar Jack Yu Committed by android-build-merger
Browse files

Merge "Cleaned up code"

am: 0cf02ed2

Change-Id: I5f7a754dc6de54ff93d6bb3bdd450ced9484b9f3
parents 341bfc88 0cf02ed2
Loading
Loading
Loading
Loading
+5 −14
Original line number Diff line number Diff line
@@ -598,24 +598,13 @@ public class DataConnection extends StateMachine {
            ApnContext apnContext = cp.mApnContext;
            if (apnContext == alreadySent) continue;
            if (reason != null) apnContext.setReason(reason);
            Pair<ApnContext, Integer> pair =
                    new Pair<ApnContext, Integer>(apnContext, cp.mConnectionGeneration);
            Pair<ApnContext, Integer> pair = new Pair<>(apnContext, cp.mConnectionGeneration);
            Message msg = mDct.obtainMessage(event, pair);
            AsyncResult.forMessage(msg);
            msg.sendToTarget();
        }
    }

    private void notifyAllOfConnected(String reason) {
        notifyAllWithEvent(null, DctConstants.EVENT_DATA_SETUP_COMPLETE, reason);
    }

    private void notifyAllDisconnectCompleted(@DataFailCause.FailCause int cause) {
        notifyAllWithEvent(null, DctConstants.EVENT_DISCONNECT_DONE,
                DataFailCause.toString(cause));
    }


    /**
     * Send the connectionCompletedMsg.
     *
@@ -1507,7 +1496,8 @@ public class DataConnection extends StateMachine {
                    log("DcInactiveState: enter notifyAllDisconnectCompleted failCause="
                            + mDcFailCause);
                }
                notifyAllDisconnectCompleted(mDcFailCause);
                notifyAllWithEvent(null, DctConstants.EVENT_DISCONNECT_DONE,
                        DataFailCause.toString(mDcFailCause));
            }

            // Remove ourselves from cid mapping, before clearSettings
@@ -1705,7 +1695,8 @@ public class DataConnection extends StateMachine {
            updateNetworkInfo();

            // If we were retrying there maybe more than one, otherwise they'll only be one.
            notifyAllOfConnected(Phone.REASON_CONNECTED);
            notifyAllWithEvent(null, DctConstants.EVENT_DATA_SETUP_COMPLETE,
                    Phone.REASON_CONNECTED);

            mPhone.getCallTracker().registerForVoiceCallStarted(getHandler(),
                    DataConnection.EVENT_DATA_CONNECTION_VOICE_CALL_STARTED, null);
+49 −58
Original line number Diff line number Diff line
@@ -2571,15 +2571,8 @@ public class DcTracker extends Handler {
     * A SETUP (aka bringUp) has completed, possibly with an error. If
     * there is an error this method will call {@link #onDataSetupCompleteError}.
     */
    private void onDataSetupComplete(AsyncResult ar) {

        int cause = DataFailCause.UNKNOWN;
        boolean handleError = false;
        ApnContext apnContext = getValidApnContext(ar, "onDataSetupComplete");

        if (apnContext == null) return;

        if (ar.exception == null) {
    private void onDataSetupComplete(ApnContext apnContext, boolean success, int cause) {
        if (success) {
            DataConnection dataConnection = apnContext.getDataConnection();

            if (RADIO_TESTS) {
@@ -2602,8 +2595,7 @@ public class DcTracker extends Handler {
            }
            if (dataConnection == null) {
                log("onDataSetupComplete: no connection to DC, handle as error");
                cause = DataFailCause.CONNECTION_TO_DATACONNECTIONAC_BROKEN;
                handleError = true;
                onDataSetupCompleteError(apnContext);
            } else {
                ApnSetting apn = apnContext.getApnSetting();
                if (DBG) {
@@ -2714,7 +2706,6 @@ public class DcTracker extends Handler {
                }
            }
        } else {
            cause = (int) (ar.result);
            if (DBG) {
                ApnSetting apn = apnContext.getApnSetting();
                log(String.format("onDataSetupComplete: error apn=%s cause=%s",
@@ -2749,51 +2740,17 @@ public class DcTracker extends Handler {
                log("cause = " + cause + ", mark apn as permanent failed. apn = " + apn);
                apnContext.markApnPermanentFailed(apn);
            }

            handleError = true;
        }

        if (handleError) {
            onDataSetupCompleteError(ar);
            onDataSetupCompleteError(apnContext);
        }
    }

    /**
     * check for obsolete messages.  Return ApnContext if valid, null if not
     */
    private ApnContext getValidApnContext(AsyncResult ar, String logString) {
        if (ar != null && ar.userObj instanceof Pair) {
            Pair<ApnContext, Integer>pair = (Pair<ApnContext, Integer>)ar.userObj;
            ApnContext apnContext = pair.first;
            if (apnContext != null) {
                final int generation = apnContext.getConnectionGeneration();
                if (DBG) {
                    log("getValidApnContext (" + logString + ") on " + apnContext + " got " +
                            generation + " vs " + pair.second);
                }
                if (generation == pair.second) {
                    return apnContext;
                } else {
                    log("ignoring obsolete " + logString);
                    return null;
                }
            }
        }
        throw new RuntimeException(logString + ": No apnContext");
    }

    /**
     * Error has occurred during the SETUP {aka bringUP} request and the DCT
     * should either try the next waiting APN or start over from the
     * beginning if the list is empty. Between each SETUP request there will
     * be a delay defined by {@link #getApnDelay()}.
     */
    private void onDataSetupCompleteError(AsyncResult ar) {

        ApnContext apnContext = getValidApnContext(ar, "onDataSetupCompleteError");

        if (apnContext == null) return;

    private void onDataSetupCompleteError(ApnContext apnContext) {
        long delay = apnContext.getDelayForNextApn(mFailFast);

        // Check if we need to retry or not.
@@ -2828,10 +2785,7 @@ public class DcTracker extends Handler {
    /**
     * Called when EVENT_DISCONNECT_DONE is received.
     */
    private void onDisconnectDone(AsyncResult ar) {
        ApnContext apnContext = getValidApnContext(ar, "onDisconnectDone");
        if (apnContext == null) return;

    private void onDisconnectDone(ApnContext apnContext) {
        if(DBG) log("onDisconnectDone: EVENT_DISCONNECT_DONE apnContext=" + apnContext);
        apnContext.setState(DctConstants.State.IDLE);

@@ -3323,6 +3277,10 @@ public class DcTracker extends Handler {
    public void handleMessage (Message msg) {
        if (VDBG) log("handleMessage msg=" + msg);

        AsyncResult ar;
        Pair<ApnContext, Integer> pair;
        ApnContext apnContext;
        int generation;
        switch (msg.what) {
            case DctConstants.EVENT_RECORDS_LOADED:
                // If onRecordsLoadedOrSubIdChanged() is not called here, it should be called on
@@ -3380,7 +3338,7 @@ public class DcTracker extends Handler {
                        cleanUpAllConnectionsInternal(false, Phone.REASON_PS_RESTRICT_ENABLED);
                        mReregisterOnReconnectFailure = false;
                    }
                    ApnContext apnContext = mApnContextsByType.get(ApnSetting.TYPE_DEFAULT);
                    apnContext = mApnContextsByType.get(ApnSetting.TYPE_DEFAULT);
                    if (apnContext != null) {
                        apnContext.setReason(Phone.REASON_PS_RESTRICT_ENABLED);
                        trySetupData(apnContext);
@@ -3465,16 +3423,49 @@ public class DcTracker extends Handler {
                break;

            case DctConstants.EVENT_DATA_SETUP_COMPLETE:
                onDataSetupComplete((AsyncResult) msg.obj);
                ar = (AsyncResult) msg.obj;
                pair = (Pair<ApnContext, Integer>) ar.userObj;
                apnContext = pair.first;
                generation = pair.second;
                if (apnContext.getConnectionGeneration() == generation) {
                    boolean success = true;
                    int cause = DataFailCause.UNKNOWN;
                    if (ar.exception != null) {
                        success = false;
                        cause = (int) ar.result;
                    }
                    onDataSetupComplete(apnContext, success, cause);
                } else {
                    loge("EVENT_DATA_SETUP_COMPLETE: Dropped the event because generation "
                            + "did not match.");
                }
                break;

            case DctConstants.EVENT_DATA_SETUP_COMPLETE_ERROR:
                onDataSetupCompleteError((AsyncResult) msg.obj);
                ar = (AsyncResult) msg.obj;
                pair = (Pair<ApnContext, Integer>) ar.userObj;
                apnContext = pair.first;
                generation = pair.second;
                if (apnContext.getConnectionGeneration() == generation) {
                    onDataSetupCompleteError(apnContext);
                } else {
                    loge("EVENT_DATA_SETUP_COMPLETE_ERROR: Dropped the event because generation "
                            + "did not match.");
                }
                break;

            case DctConstants.EVENT_DISCONNECT_DONE:
                log("DataConnectionTracker.handleMessage: EVENT_DISCONNECT_DONE msg=" + msg);
                onDisconnectDone((AsyncResult) msg.obj);
                log("EVENT_DISCONNECT_DONE msg=" + msg);
                ar = (AsyncResult) msg.obj;
                pair = (Pair<ApnContext, Integer>) ar.userObj;
                apnContext = pair.first;
                generation = pair.second;
                if (apnContext.getConnectionGeneration() == generation) {
                    onDisconnectDone(apnContext);
                } else {
                    loge("EVENT_DISCONNECT_DONE: Dropped the event because generation "
                            + "did not match.");
                }
                break;

            case DctConstants.EVENT_VOICE_CALL_STARTED:
@@ -3615,7 +3606,7 @@ public class DcTracker extends Handler {
                onDataServiceBindingChanged((Boolean) ((AsyncResult) msg.obj).result);
                break;
            case DctConstants.EVENT_DATA_ENABLED_CHANGED:
                AsyncResult ar = (AsyncResult) msg.obj;
                ar = (AsyncResult) msg.obj;
                if (ar.result instanceof Pair) {
                    Pair<Boolean, Integer> p = (Pair<Boolean, Integer>) ar.result;
                    boolean enabled = p.first;