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

Commit cedc246e authored by Chiachang Wang's avatar Chiachang Wang Committed by Automerger Merge Worker
Browse files

Merge "Set underlying network as soon as VPN tries using the network" into...

Merge "Set underlying network as soon as VPN tries using the network" into main am: 0b3c59e3 am: 87fa06b4 am: 06c1c3ed

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2719273



Change-Id: I3f5a5122e9041fd9613c7fb40f9657a30d909267
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 63979ebb 06c1c3ed
Loading
Loading
Loading
Loading
+20 −20
Original line number Diff line number Diff line
@@ -3296,13 +3296,6 @@ public class Vpn {
                        }
                        agentConnect(this::onValidationStatus);
                        return; // Link properties are already sent.
                    } else {
                        // Underlying networks also set in agentConnect()
                        doSetUnderlyingNetworks(networkAgent, Collections.singletonList(network));
                        mNetworkCapabilities =
                                new NetworkCapabilities.Builder(mNetworkCapabilities)
                                        .setUnderlyingNetworks(Collections.singletonList(network))
                                        .build();
                    }

                    lp = makeLinkProperties(); // Accesses VPN instance fields; must be locked
@@ -3384,8 +3377,6 @@ public class Vpn {

                    final LinkProperties oldLp = makeLinkProperties();

                    final boolean underlyingNetworkHasChanged =
                            !Arrays.equals(mConfig.underlyingNetworks, new Network[]{network});
                    mConfig.underlyingNetworks = new Network[] {network};
                    mConfig.mtu = calculateVpnMtu();

@@ -3417,18 +3408,9 @@ public class Vpn {
                                    removed.getAddress(), removed.getPrefixLength());
                        }
                    } else {
                        // Put below 3 updates into else block is because agentConnect() will do
                        // those things, so there is no need to do the redundant work.
                        // Put below update into else block is because agentConnect() will do
                        // the same things, so there is no need to do the redundant work.
                        if (!newLp.equals(oldLp)) doSendLinkProperties(mNetworkAgent, newLp);
                        if (underlyingNetworkHasChanged) {
                            mNetworkCapabilities =
                                    new NetworkCapabilities.Builder(mNetworkCapabilities)
                                            .setUnderlyingNetworks(
                                                    Collections.singletonList(network))
                                            .build();
                            doSetUnderlyingNetworks(mNetworkAgent,
                                    Collections.singletonList(network));
                        }
                    }
                }

@@ -3554,10 +3536,28 @@ public class Vpn {
         */
        private void startOrMigrateIkeSession(@Nullable Network underlyingNetwork) {
            if (underlyingNetwork == null) {
                // For null underlyingNetwork case, there will not be a NetworkAgent available so
                // no underlying network update is necessary here. Note that updating
                // mNetworkCapabilities here would also be reasonable, but it will be updated next
                // time the VPN connects anyway.
                Log.d(TAG, "There is no active network for starting an IKE session");
                return;
            }

            final List<Network> networks = Collections.singletonList(underlyingNetwork);
            // Update network capabilities if underlying network is changed.
            if (!networks.equals(mNetworkCapabilities.getUnderlyingNetworks())) {
                mNetworkCapabilities =
                        new NetworkCapabilities.Builder(mNetworkCapabilities)
                                .setUnderlyingNetworks(networks)
                                .build();
                // No NetworkAgent case happens when Vpn tries to start a new VPN. The underlying
                // network update will be done later with NetworkAgent connected event.
                if (mNetworkAgent != null) {
                    doSetUnderlyingNetworks(mNetworkAgent, networks);
                }
            }

            if (maybeMigrateIkeSessionAndUpdateVpnTransportInfo(underlyingNetwork)) return;

            startIkeSession(underlyingNetwork);