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

Commit 708aab72 authored by Ling Ma's avatar Ling Ma Committed by Jack Yu
Browse files

Unregister after replacement for network agent to avoid onLost

When immutable properties change, the original behavior will unregister the networkagent, causing apps receiving onLost. Using the new API unregisterAfterReplacement will not cause onLost but being replaced by a equivalent or better network.

Test: basic phone call + data browsing
Bug: 253219539
Merged-In: I816a1b6e3a7ee77b9158ef9ee2331168076ba2c2
Change-Id: I816a1b6e3a7ee77b9158ef9ee2331168076ba2c2
parent cb940a62
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -50,6 +50,9 @@ public class TelephonyNetworkAgent extends NetworkAgent {
    private final String mLogTag;
    private final LocalLog mLocalLog = new LocalLog(128);

    /** Max unregister network agent delay. */
    private static final int NETWORK_AGENT_TEARDOWN_DELAY_MS = 5_000;

    /** The parent data network. */
    private final @NonNull DataNetwork mDataNetwork;

@@ -296,14 +299,15 @@ public class TelephonyNetworkAgent extends NetworkAgent {

    /**
     * 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()}.
     * immutable capabilities got changed, where telephony calls
     * {@link NetworkAgent#unregisterAfterReplacement} 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#unregisterAfterReplacement}.
     */
    public void abandon() {
        mAbandoned = true;
        unregister();
        unregisterAfterReplacement(NETWORK_AGENT_TEARDOWN_DELAY_MS);
    }

    /**