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

Commit 63ab2fd0 authored by Automerger Merge Worker's avatar Automerger Merge Worker
Browse files

Merge "[NS A43] Separate updating the linger timer and sending LOSING" am:...

Merge "[NS A43] Separate updating the linger timer and sending LOSING" am: 7abb6f60 am: aaa07c64

Change-Id: Id7ed8f80307d2e1252195a6aef62e51d0c4e7f27
parents acd77928 aaa07c64
Loading
Loading
Loading
Loading
+35 −7
Original line number Original line Diff line number Diff line
@@ -3113,7 +3113,13 @@ public class ConnectivityService extends IConnectivityManager.Stub
        handleUpdateLinkProperties(nai, new LinkProperties(nai.linkProperties));
        handleUpdateLinkProperties(nai, new LinkProperties(nai.linkProperties));
    }
    }


    private void updateLingerState(NetworkAgentInfo nai, long now) {
    /**
     * Updates the linger state from the network requests inside the NAI.
     * @param nai the agent info to update
     * @param now the timestamp of the event causing this update
     * @return whether the network was lingered as a result of this update
     */
    private boolean updateLingerState(@NonNull final NetworkAgentInfo nai, final long now) {
        // 1. Update the linger timer. If it's changed, reschedule or cancel the alarm.
        // 1. Update the linger timer. If it's changed, reschedule or cancel the alarm.
        // 2. If the network was lingering and there are now requests, unlinger it.
        // 2. If the network was lingering and there are now requests, unlinger it.
        // 3. If this network is unneeded (which implies it is not lingering), and there is at least
        // 3. If this network is unneeded (which implies it is not lingering), and there is at least
@@ -3124,12 +3130,15 @@ public class ConnectivityService extends IConnectivityManager.Stub
            nai.unlinger();
            nai.unlinger();
            logNetworkEvent(nai, NetworkEvent.NETWORK_UNLINGER);
            logNetworkEvent(nai, NetworkEvent.NETWORK_UNLINGER);
        } else if (unneeded(nai, UnneededFor.LINGER) && nai.getLingerExpiry() > 0) {
        } else if (unneeded(nai, UnneededFor.LINGER) && nai.getLingerExpiry() > 0) {
            int lingerTime = (int) (nai.getLingerExpiry() - now);
            if (DBG) {
            if (DBG) log("Lingering " + nai.name() + " for " + lingerTime + "ms");
                final int lingerTime = (int) (nai.getLingerExpiry() - now);
                log("Lingering " + nai.name() + " for " + lingerTime + "ms");
            }
            nai.linger();
            nai.linger();
            logNetworkEvent(nai, NetworkEvent.NETWORK_LINGER);
            logNetworkEvent(nai, NetworkEvent.NETWORK_LINGER);
            notifyNetworkCallbacks(nai, ConnectivityManager.CALLBACK_LOSING, lingerTime);
            return true;
        }
        }
        return false;
    }
    }


    private void handleAsyncChannelHalfConnect(Message msg) {
    private void handleAsyncChannelHalfConnect(Message msg) {
@@ -3473,7 +3482,10 @@ public class ConnectivityService extends IConnectivityManager.Stub
                }
                }
                // If there are still lingered requests on this network, don't tear it down,
                // If there are still lingered requests on this network, don't tear it down,
                // but resume lingering instead.
                // but resume lingering instead.
                updateLingerState(nai, SystemClock.elapsedRealtime());
                final long now = SystemClock.elapsedRealtime();
                if (updateLingerState(nai, now)) {
                    notifyNetworkLosing(nai, now);
                }
                if (unneeded(nai, UnneededFor.TEARDOWN)) {
                if (unneeded(nai, UnneededFor.TEARDOWN)) {
                    if (DBG) log("no live requests for " + nai.name() + "; disconnecting");
                    if (DBG) log("no live requests for " + nai.name() + "; disconnecting");
                    teardownUnneededNetwork(nai);
                    teardownUnneededNetwork(nai);
@@ -6629,6 +6641,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
                        nri, currentNetwork, null));
                        nri, currentNetwork, null));
            }
            }
        }
        }

        return reassignedRequests;
        return reassignedRequests;
    }
    }


@@ -6775,13 +6788,20 @@ public class ConnectivityService extends IConnectivityManager.Stub
            processNewlySatisfiedListenRequests(event.mNetwork);
            processNewlySatisfiedListenRequests(event.mNetwork);
        }
        }


        final ArrayList<NetworkAgentInfo> lingeredNetworks = new ArrayList<>();
        for (final NetworkAgentInfo nai : nais) {
        for (final NetworkAgentInfo nai : nais) {
            // Rematching may have altered the linger state of some networks, so update all linger
            // Rematching may have altered the linger state of some networks, so update all linger
            // timers. updateLingerState reads the state from the network agent and does nothing
            // timers. updateLingerState reads the state from the network agent and does nothing
            // if the state has not changed : the source of truth is controlled with
            // if the state has not changed : the source of truth is controlled with
            // NetworkAgentInfo#lingerRequest and NetworkAgentInfo#unlingerRequest, which have been
            // NetworkAgentInfo#lingerRequest and NetworkAgentInfo#unlingerRequest, which have been
            // called while rematching the individual networks above.
            // called while rematching the individual networks above.
            updateLingerState(nai, now);
            if (updateLingerState(nai, now)) {
                lingeredNetworks.add(nai);
            }
        }

        for (final NetworkAgentInfo nai : lingeredNetworks) {
            notifyNetworkLosing(nai, now);
        }
        }


        updateLegacyTypeTrackerAndVpnLockdownForRematch(oldDefaultNetwork, newDefaultNetwork, nais);
        updateLegacyTypeTrackerAndVpnLockdownForRematch(oldDefaultNetwork, newDefaultNetwork, nais);
@@ -6797,7 +6817,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
                    // and became unneeded due to another network improving its score to the
                    // and became unneeded due to another network improving its score to the
                    // point where this network will no longer be able to satisfy any requests
                    // point where this network will no longer be able to satisfy any requests
                    // even if it validates.
                    // even if it validates.
                    updateLingerState(nai, now);
                    if (updateLingerState(nai, now)) {
                        notifyNetworkLosing(nai, now);
                    }
                } else {
                } else {
                    if (DBG) log("Reaping " + nai.name());
                    if (DBG) log("Reaping " + nai.name());
                    teardownUnneededNetwork(nai);
                    teardownUnneededNetwork(nai);
@@ -7050,6 +7072,12 @@ public class ConnectivityService extends IConnectivityManager.Stub
        callCallbackForRequest(nri, nai, ConnectivityManager.CALLBACK_AVAILABLE, blocked ? 1 : 0);
        callCallbackForRequest(nri, nai, ConnectivityManager.CALLBACK_AVAILABLE, blocked ? 1 : 0);
    }
    }


    // Notify the requests on this NAI that the network is now lingered.
    private void notifyNetworkLosing(@NonNull final NetworkAgentInfo nai, final long now) {
        final int lingerTime = (int) (nai.getLingerExpiry() - now);
        notifyNetworkCallbacks(nai, ConnectivityManager.CALLBACK_LOSING, lingerTime);
    }

    /**
    /**
     * Notify of the blocked state apps with a registered callback matching a given NAI.
     * Notify of the blocked state apps with a registered callback matching a given NAI.
     *
     *