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

Commit 87fa06b4 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 main am: 0b3c59e3

parents 4abf02bc 0b3c59e3
Loading
Loading
Loading
Loading
+20 −20
Original line number Original line Diff line number Diff line
@@ -3296,13 +3296,6 @@ public class Vpn {
                        }
                        }
                        agentConnect(this::onValidationStatus);
                        agentConnect(this::onValidationStatus);
                        return; // Link properties are already sent.
                        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
                    lp = makeLinkProperties(); // Accesses VPN instance fields; must be locked
@@ -3384,8 +3377,6 @@ public class Vpn {


                    final LinkProperties oldLp = makeLinkProperties();
                    final LinkProperties oldLp = makeLinkProperties();


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


@@ -3417,18 +3408,9 @@ public class Vpn {
                                    removed.getAddress(), removed.getPrefixLength());
                                    removed.getAddress(), removed.getPrefixLength());
                        }
                        }
                    } else {
                    } else {
                        // Put below 3 updates into else block is because agentConnect() will do
                        // Put below update into else block is because agentConnect() will do
                        // those things, so there is no need to do the redundant work.
                        // the same things, so there is no need to do the redundant work.
                        if (!newLp.equals(oldLp)) doSendLinkProperties(mNetworkAgent, newLp);
                        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) {
        private void startOrMigrateIkeSession(@Nullable Network underlyingNetwork) {
            if (underlyingNetwork == null) {
            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");
                Log.d(TAG, "There is no active network for starting an IKE session");
                return;
                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;
            if (maybeMigrateIkeSessionAndUpdateVpnTransportInfo(underlyingNetwork)) return;


            startIkeSession(underlyingNetwork);
            startIkeSession(underlyingNetwork);