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

Commit 49d81085 authored by Chalard Jean's avatar Chalard Jean
Browse files

Destroy networks as soon as they are disconnected.

...as opposed to after the async channel finished disconnecting.

Clean cherry-pick of ag/4043255

Bug: 78308259
Test: runtest frameworks-net
      also used a device with this patch over the weekend and
      tried all I could think of
Merged-In: Ic4c7520e907de353a01c2a3a8a50d661dee4a994
Merged-In: I0617f0ff6e46a1d3764335a1e7ad01b34c8cc5a8

Change-Id: I4e4b41bbdf25d7d7bea4124cb58da004d47f1090
parent 6d89a786
Loading
Loading
Loading
Loading
+93 −82
Original line number Original line Diff line number Diff line
@@ -2404,9 +2404,23 @@ public class ConnectivityService extends IConnectivityManager.Stub
        }
        }
    }
    }


    // This is a no-op if it's called with a message designating a network that has
    // already been destroyed, because its reference will not be found in the relevant
    // maps.
    private void handleAsyncChannelDisconnected(Message msg) {
    private void handleAsyncChannelDisconnected(Message msg) {
        NetworkAgentInfo nai = mNetworkAgentInfos.get(msg.replyTo);
        NetworkAgentInfo nai = mNetworkAgentInfos.get(msg.replyTo);
        if (nai != null) {
        if (nai != null) {
            disconnectAndDestroyNetwork(nai);
        } else {
            NetworkFactoryInfo nfi = mNetworkFactoryInfos.remove(msg.replyTo);
            if (DBG && nfi != null) log("unregisterNetworkFactory for " + nfi.name);
        }
    }

    // Destroys a network, remove references to it from the internal state managed by
    // ConnectivityService, free its interfaces and clean up.
    // Must be called on the Handler thread.
    private void disconnectAndDestroyNetwork(NetworkAgentInfo nai) {
        if (DBG) {
        if (DBG) {
            log(nai.name() + " got DISCONNECTED, was satisfying " + nai.numNetworkRequests());
            log(nai.name() + " got DISCONNECTED, was satisfying " + nai.numNetworkRequests());
        }
        }
@@ -2442,7 +2456,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
            wakeupModifyInterface(iface, nai.networkCapabilities, false);
            wakeupModifyInterface(iface, nai.networkCapabilities, false);
        }
        }
        nai.networkMonitor.sendMessage(NetworkMonitor.CMD_NETWORK_DISCONNECTED);
        nai.networkMonitor.sendMessage(NetworkMonitor.CMD_NETWORK_DISCONNECTED);
            mNetworkAgentInfos.remove(msg.replyTo);
        mNetworkAgentInfos.remove(nai.messenger);
        nai.maybeStopClat();
        nai.maybeStopClat();
        synchronized (mNetworkForNetId) {
        synchronized (mNetworkForNetId) {
            // Remove the NetworkAgent, but don't mark the netId as
            // Remove the NetworkAgent, but don't mark the netId as
@@ -2489,10 +2503,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
        synchronized (mNetworkForNetId) {
        synchronized (mNetworkForNetId) {
            mNetIdInUse.delete(nai.network.netId);
            mNetIdInUse.delete(nai.network.netId);
        }
        }
        } else {
            NetworkFactoryInfo nfi = mNetworkFactoryInfos.remove(msg.replyTo);
            if (DBG && nfi != null) log("unregisterNetworkFactory for " + nfi.name);
        }
    }
    }


    // If this method proves to be too slow then we can maintain a separate
    // If this method proves to be too slow then we can maintain a separate
@@ -5577,6 +5587,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
                }
                }
                updateUids(networkAgent, networkAgent.networkCapabilities, null);
                updateUids(networkAgent, networkAgent.networkCapabilities, null);
            }
            }
            disconnectAndDestroyNetwork(networkAgent);
        } else if ((oldInfo != null && oldInfo.getState() == NetworkInfo.State.SUSPENDED) ||
        } else if ((oldInfo != null && oldInfo.getState() == NetworkInfo.State.SUSPENDED) ||
                state == NetworkInfo.State.SUSPENDED) {
                state == NetworkInfo.State.SUSPENDED) {
            // going into or coming out of SUSPEND: rescore and notify
            // going into or coming out of SUSPEND: rescore and notify