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

Commit f4832dc3 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Avoid tear down when re-creating the network agent"

parents cef2b1a6 f00ce1b1
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -1355,8 +1355,10 @@ public class DataNetwork extends StateMachine {
                // suggested to de-register and re-register the network agent if it is needed to
                // add/remove immutable capabilities.
                logl("updateNetworkCapabilities: Immutable capabilities changed. Re-create the "
                        + "network agent.");
                mNetworkAgent.unregister();
                        + "network agent. Attempted to change from " + mNetworkCapabilities + " to "
                        + nc);
                // Abandon the network agent because we are going to create a new one.
                mNetworkAgent.abandon();
                // Update the capabilities first so the new network agent would be created with the
                // new capabilities.
                mNetworkCapabilities = nc;
+42 −0
Original line number Diff line number Diff line
@@ -58,6 +58,12 @@ public class TelephonyNetworkAgent extends NetworkAgent implements NotifyQosSess
    /** This is the id from {@link NetworkAgent#register()}. */
    private final int mId;

    /**
     * Indicates if this network agent is abandoned. if {@code true}, it ignores the
     * @link NetworkAgent#onNetworkUnwanted()} calls from connectivity service.
     */
    private boolean mAbandoned = false;

    /**
     * The callbacks that are used to pass information to {@link DataNetwork} and
     * {@link QosCallbackTracker}.
@@ -163,6 +169,10 @@ public class TelephonyNetworkAgent extends NetworkAgent implements NotifyQosSess
     */
    @Override
    public void onNetworkUnwanted() {
        if (mAbandoned) {
            log("The agent is already abandoned. Ignored onNetworkUnwanted.");
            return;
        }
        mDataNetwork.tearDown(DataNetwork.TEAR_DOWN_REASON_CONNECTIVITY_SERVICE_UNWANTED);
    }

@@ -186,6 +196,10 @@ public class TelephonyNetworkAgent extends NetworkAgent implements NotifyQosSess
    @Override
    public void onValidationStatus(@android.telephony.Annotation.ValidationStatus int status,
            @Nullable Uri redirectUri) {
        if (mAbandoned) {
            log("The agent is already abandoned. Ignored onValidationStatus.");
            return;
        }
        mTelephonyNetworkAgentCallbacks.forEach(callback -> callback.invokeFromExecutor(
                () -> callback.onValidationStatus(status, redirectUri)));
    }
@@ -212,6 +226,10 @@ public class TelephonyNetworkAgent extends NetworkAgent implements NotifyQosSess
    @Override
    public void onStartSocketKeepalive(int slot, @NonNull Duration interval,
            @NonNull KeepalivePacketData packet) {
        if (mAbandoned) {
            log("The agent is already abandoned. Ignored onStartSocketKeepalive.");
            return;
        }
        mTelephonyNetworkAgentCallbacks.forEach(callback -> callback.invokeFromExecutor(
                () -> callback.onStartSocketKeepalive(slot, interval, packet)));
    }
@@ -224,6 +242,10 @@ public class TelephonyNetworkAgent extends NetworkAgent implements NotifyQosSess
     */
    @Override
    public void onStopSocketKeepalive(int slot) {
        if (mAbandoned) {
            log("The agent is already abandoned. Ignored onStopSocketKeepalive.");
            return;
        }
        mTelephonyNetworkAgentCallbacks.forEach(callback -> callback.invokeFromExecutor(
                () -> callback.onStopSocketKeepalive(slot)));
    }
@@ -236,6 +258,10 @@ public class TelephonyNetworkAgent extends NetworkAgent implements NotifyQosSess
     */
    @Override
    public void onQosCallbackRegistered(final int qosCallbackId, final @NonNull QosFilter filter) {
        if (mAbandoned) {
            log("The agent is already abandoned. Ignored onQosCallbackRegistered.");
            return;
        }
        mTelephonyNetworkAgentCallbacks.forEach(callback -> callback.invokeFromExecutor(
                () -> callback.onQosCallbackRegistered(qosCallbackId, filter)));
    }
@@ -250,6 +276,10 @@ public class TelephonyNetworkAgent extends NetworkAgent implements NotifyQosSess
     */
    @Override
    public void onQosCallbackUnregistered(final int qosCallbackId) {
        if (mAbandoned) {
            log("The agent is already abandoned. Ignored onQosCallbackUnregistered.");
            return;
        }
        mTelephonyNetworkAgentCallbacks.forEach(callback -> callback.invokeFromExecutor(
                () -> callback.onQosCallbackUnregistered(qosCallbackId)));
    }
@@ -285,6 +315,18 @@ public class TelephonyNetworkAgent extends NetworkAgent implements NotifyQosSess
        super.sendQosSessionLost(qosCallbackId, sessionId, qosSessionType);
    }

    /**
     * Abandon the network agent. This is used for telephony to re-create the network agent when
     * immutable capabilities got changed, where telephony calls {@link NetworkAgent#unregister()}
     * and then create another network agent with new capabilities. Abandon this network agent
     * allowing it ignore the subsequent {@link #onNetworkUnwanted()} invocation caused by
     * {@link NetworkAgent#unregister()}.
     */
    public void abandon() {
        mAbandoned = true;
        unregister();
    }

    /**
     * Register the callback for receiving information from {@link TelephonyNetworkAgent}.
     *