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

Commit 3892583c authored by Chalard Jean's avatar Chalard Jean
Browse files

[NS A12] Move some legacy type tracker handling to a function

It's fine to do this out of the if() clause because :
• If the network newly satisfies a request it is sure to have
  it in the list of requests it satisfies
• If it does not newly satisfy a request and there is still
  a request with a legacy type that it satisfies, then it
  is already remembered by LegacyTypeTracker

As for the VPN, the code always enters the condition anyway.

Test: ConnectivityServiceTest
Change-Id: I8bd668ad27043d6a5036b1b3c52fa5a3146abcfa
parent 587758be
Loading
Loading
Loading
Loading
+34 −30
Original line number Diff line number Diff line
@@ -6520,6 +6520,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
                }
            } catch (RemoteException ignored) {
            }
        }

        // This has to happen after the notifyNetworkCallbacks as that tickles each
        // ConnectivityManager instance so that legacy requests correctly bind dns
@@ -6535,22 +6536,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
        // (notification callbacks) and then uses the old api (getNetworkInfo(type))
        // they may get old info.  Reverse this after the old startUsing api is removed.
        // This is on top of the multiple intent sequencing referenced in the todo above.
            for (int i = 0; i < newNetwork.numNetworkRequests(); i++) {
                NetworkRequest nr = newNetwork.requestAt(i);
                if (nr.legacyType != TYPE_NONE && nr.isRequest()) {
                    // legacy type tracker filters out repeat adds
                    mLegacyTypeTracker.add(nr.legacyType, newNetwork);
                }
            }

            // A VPN generally won't get added to the legacy tracker in the "for (nri)" loop above,
            // because usually there are no NetworkRequests it satisfies (e.g., mDefaultRequest
            // wants the NOT_VPN capability, so it will never be satisfied by a VPN). So, add the
            // newNetwork to the tracker explicitly (it's a no-op if it has already been added).
            if (newNetwork.isVPN()) {
                mLegacyTypeTracker.add(TYPE_VPN, newNetwork);
            }
        }
        addNetworkToLegacyTypeTracker(newNetwork);
    }

    /**
@@ -6592,6 +6578,24 @@ public class ConnectivityService extends IConnectivityManager.Stub
        }
    }

    private void addNetworkToLegacyTypeTracker(@NonNull final NetworkAgentInfo nai) {
        for (int i = 0; i < nai.numNetworkRequests(); i++) {
            NetworkRequest nr = nai.requestAt(i);
            if (nr.legacyType != TYPE_NONE && nr.isRequest()) {
                // legacy type tracker filters out repeat adds
                mLegacyTypeTracker.add(nr.legacyType, nai);
            }
        }

        // A VPN generally won't get added to the legacy tracker in the "for (nri)" loop above,
        // because usually there are no NetworkRequests it satisfies (e.g., mDefaultRequest
        // wants the NOT_VPN capability, so it will never be satisfied by a VPN). So, add the
        // newNetwork to the tracker explicitly (it's a no-op if it has already been added).
        if (nai.isVPN()) {
            mLegacyTypeTracker.add(TYPE_VPN, nai);
        }
    }

    private void updateInetCondition(NetworkAgentInfo nai) {
        // Don't bother updating until we've graduated to validated at least once.
        if (!nai.everValidated) return;