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

Commit caaf4e7b authored by Jack Yu's avatar Jack Yu Committed by Sarah Chin
Browse files

Avoid tear down when re-creating the network agent

When telephony needs to re-create the network agent
with new immutable capabilities, it should also ignore
the unwanted request from connectivity service, otherwise
the underlying network will be torn down.

Fix: 216637428
Test: Manual
Change-Id: I7b715e75e85cfc38320fa0d4aff6c51dd286f802
Merged-In: I7b715e75e85cfc38320fa0d4aff6c51dd286f802
parent b1b9f3b7
Loading
Loading
Loading
Loading
+4 −2
Original line number Original line 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
                // suggested to de-register and re-register the network agent if it is needed to
                // add/remove immutable capabilities.
                // add/remove immutable capabilities.
                logl("updateNetworkCapabilities: Immutable capabilities changed. Re-create the "
                logl("updateNetworkCapabilities: Immutable capabilities changed. Re-create the "
                        + "network agent.");
                        + "network agent. Attempted to change from " + mNetworkCapabilities + " to "
                mNetworkAgent.unregister();
                        + 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
                // Update the capabilities first so the new network agent would be created with the
                // new capabilities.
                // new capabilities.
                mNetworkCapabilities = nc;
                mNetworkCapabilities = nc;
+42 −0
Original line number Original line Diff line number Diff line
@@ -58,6 +58,12 @@ public class TelephonyNetworkAgent extends NetworkAgent implements NotifyQosSess
    /** This is the id from {@link NetworkAgent#register()}. */
    /** This is the id from {@link NetworkAgent#register()}. */
    private final int mId;
    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
     * The callbacks that are used to pass information to {@link DataNetwork} and
     * {@link QosCallbackTracker}.
     * {@link QosCallbackTracker}.
@@ -163,6 +169,10 @@ public class TelephonyNetworkAgent extends NetworkAgent implements NotifyQosSess
     */
     */
    @Override
    @Override
    public void onNetworkUnwanted() {
    public void onNetworkUnwanted() {
        if (mAbandoned) {
            log("The agent is already abandoned. Ignored onNetworkUnwanted.");
            return;
        }
        mDataNetwork.tearDown(DataNetwork.TEAR_DOWN_REASON_CONNECTIVITY_SERVICE_UNWANTED);
        mDataNetwork.tearDown(DataNetwork.TEAR_DOWN_REASON_CONNECTIVITY_SERVICE_UNWANTED);
    }
    }


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