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

Commit 11becab6 authored by Chalard Jean's avatar Chalard Jean
Browse files

[NS A20] Cleanup

A lot of this code can't be triggered at all.
• newNetwork.created in l.6488 is implied by newNetwork.everConnected
  in l.6357
• !newNetwork.isVPN() in l.6488 is implied by the fact that VPNs are
  always foreground, so oldPermission can't != newPermission in l.6488
• updateUids in l.6502 is useless because uids can't change during a
  rematch (because there is no code doing that). Metered state and
  roaming state similarly can't change during a rematch, so
  meteredChanged and roamingChanged are always false
• updateAllVpnCapabilities in l.6537 is useless because VPN do not
  inherit the foreground state of their underlying networks, which
  would be the only reason to call that in l.6537
• Object.equals() in l.6480 is necessary false because at this line
  it is known that the foreground state has changed, which must have
  caused the NET_CAPABILITY_FOREGROUND to be different, so the objects
  can't be equal

Test: FrameworksNetTests NetworkStackTest
Change-Id: I2a52f7f4a085f3eea22a1dd170af8f04671250ff
parent 04872c7b
Loading
Loading
Loading
Loading
+5 −47
Original line number Diff line number Diff line
@@ -6470,17 +6470,12 @@ public class ConnectivityService extends IConnectivityManager.Stub

        // Second pass: process all listens.
        if (wasBackgroundNetwork != newNetwork.isBackgroundNetwork()) {
            // TODO : most of the following is useless because the only thing that changed
            // here is whether the network is a background network. Clean this up.

            NetworkCapabilities newNc = mixInCapabilities(newNetwork,
            final NetworkCapabilities newNc = mixInCapabilities(newNetwork,
                    newNetwork.networkCapabilities);

            if (Objects.equals(newNetwork.networkCapabilities, newNc)) return;

            final int oldPermission = getNetworkPermission(newNetwork.networkCapabilities);
            final int newPermission = getNetworkPermission(newNc);
            if (oldPermission != newPermission && newNetwork.created && !newNetwork.isVPN()) {
            if (oldPermission != newPermission) {
                try {
                    mNMS.setNetworkPermission(newNetwork.network.netId, newPermission);
                } catch (RemoteException e) {
@@ -6488,50 +6483,13 @@ public class ConnectivityService extends IConnectivityManager.Stub
                }
            }

            final NetworkCapabilities prevNc;
            synchronized (newNetwork) {
                prevNc = newNetwork.networkCapabilities;
                newNetwork.setNetworkCapabilities(newNc);
            }

            updateUids(newNetwork, prevNc, newNc);

            if (newNetwork.getCurrentScore() == score
                    && newNc.equalRequestableCapabilities(prevNc)) {
                // If the requestable capabilities haven't changed, and the score hasn't changed,
                // then the change we're processing can't affect any requests, it can only affect
                // the listens on this network.
            // The requestable capabilities and the score can't have changed, therefore the change
            // in background can't affect any requests. Only processing the listens is fine.
            processListenRequests(newNetwork, true);
            } else {
                rematchAllNetworksAndRequests();
                notifyNetworkCallbacks(newNetwork, ConnectivityManager.CALLBACK_CAP_CHANGED);
            }

            if (prevNc != null) {
                final boolean oldMetered = prevNc.isMetered();
                final boolean newMetered = newNc.isMetered();
                final boolean meteredChanged = oldMetered != newMetered;

                if (meteredChanged) {
                    maybeNotifyNetworkBlocked(newNetwork, oldMetered, newMetered,
                            mRestrictBackground, mRestrictBackground);
                }

                final boolean roamingChanged = prevNc.hasCapability(NET_CAPABILITY_NOT_ROAMING)
                        != newNc.hasCapability(NET_CAPABILITY_NOT_ROAMING);

                // Report changes that are interesting for network statistics tracking.
                if (meteredChanged || roamingChanged) {
                    notifyIfacesChangedForNetworkStats();
                }
            }

            if (!newNc.hasTransport(TRANSPORT_VPN)) {
                // Tell VPNs about updated capabilities, since they may need to
                // bubble those changes through.
                updateAllVpnsCapabilities();
            }

        } else {
            processListenRequests(newNetwork, false);
        }