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

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

Merge "Destroy networks as soon as they are disconnected." into pi-dev

parents 05a6e771 392971cf
Loading
Loading
Loading
Loading
+93 −82
Original line number Diff line number Diff line
@@ -2442,9 +2442,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) {
        NetworkAgentInfo nai = mNetworkAgentInfos.get(msg.replyTo);
        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) {
            log(nai.name() + " got DISCONNECTED, was satisfying " + nai.numNetworkRequests());
        }
@@ -2480,7 +2494,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
            wakeupModifyInterface(iface, nai.networkCapabilities, false);
        }
        nai.networkMonitor.sendMessage(NetworkMonitor.CMD_NETWORK_DISCONNECTED);
            mNetworkAgentInfos.remove(msg.replyTo);
        mNetworkAgentInfos.remove(nai.messenger);
        nai.maybeStopClat();
        synchronized (mNetworkForNetId) {
            // Remove the NetworkAgent, but don't mark the netId as
@@ -2527,10 +2541,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
        synchronized (mNetworkForNetId) {
            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
@@ -5618,6 +5628,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
                }
                updateUids(networkAgent, networkAgent.networkCapabilities, null);
            }
            disconnectAndDestroyNetwork(networkAgent);
        } else if ((oldInfo != null && oldInfo.getState() == NetworkInfo.State.SUSPENDED) ||
                state == NetworkInfo.State.SUSPENDED) {
            // going into or coming out of SUSPEND: rescore and notify