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

Commit c3ea8e99 authored by Benedict Wong's avatar Benedict Wong Committed by Automerger Merge Worker
Browse files

Merge changes I5ce7fe05,I2d5dc5b9,Ibcc4bdc0 into sc-dev am: 211f7f9e am: 401c314f

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

Change-Id: I58b317ab7899923a283e950572e20741480c87c6
parents 6f4f8294 401c314f
Loading
Loading
Loading
Loading
+27 −36
Original line number Diff line number Diff line
@@ -148,6 +148,7 @@ import java.util.concurrent.TimeUnit;
// TODO(b/180451994): ensure all incoming + outgoing calls have a cleared calling identity
public class VcnManagementService extends IVcnManagementService.Stub {
    @NonNull private static final String TAG = VcnManagementService.class.getSimpleName();
    private static final long DUMP_TIMEOUT_MILLIS = TimeUnit.SECONDS.toMillis(5);

    public static final boolean VDBG = false; // STOPSHIP: if true

@@ -997,34 +998,25 @@ public class VcnManagementService extends IVcnManagementService.Stub {
    protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
        mContext.enforceCallingOrSelfPermission(DUMP, TAG);

        final IndentingPrintWriter pw = new IndentingPrintWriter(writer, "  ");
        final IndentingPrintWriter pw = new IndentingPrintWriter(writer, "| ");

        pw.println("VcnManagementService dump:");
        pw.increaseIndent();

        pw.println("mNetworkProvider:");
        pw.increaseIndent();
        // Post to handler thread to prevent ConcurrentModificationExceptions, and avoid lock-hell.
        mHandler.runWithScissors(() -> {
            mNetworkProvider.dump(pw);
        pw.decreaseIndent();
            pw.println();

        pw.println("mTrackingNetworkCallback:");
        pw.increaseIndent();
            mTrackingNetworkCallback.dump(pw);
        pw.decreaseIndent();
            pw.println();

            synchronized (mLock) {
            pw.println("mLastSnapshot:");
            pw.increaseIndent();
                mLastSnapshot.dump(pw);
            pw.decreaseIndent();
                pw.println();

                pw.println("mConfigs:");
                pw.increaseIndent();
                for (Entry<ParcelUuid, VcnConfig> entry : mConfigs.entrySet()) {
                pw.println(entry.getKey() + ": " + entry.getValue().getProvisioningPackageName());
                    pw.println(entry.getKey() + ": "
                            + entry.getValue().getProvisioningPackageName());
                }
                pw.decreaseIndent();
                pw.println();
@@ -1037,8 +1029,7 @@ public class VcnManagementService extends IVcnManagementService.Stub {
                pw.decreaseIndent();
                pw.println();
            }

        pw.decreaseIndent();
        }, DUMP_TIMEOUT_MILLIS);
    }

    // TODO(b/180452282): Make name more generic and implement directly with VcnManagementService
+63 −10
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import android.telephony.TelephonyCallback;
import android.telephony.TelephonyManager;
import android.util.ArrayMap;
import android.util.Slog;
import android.util.SparseArray;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting.Visibility;
@@ -106,6 +107,17 @@ public class UnderlyingNetworkTracker {
    @VisibleForTesting(visibility = Visibility.PRIVATE)
    static final int PRIORITY_ANY = Integer.MAX_VALUE;

    private static final SparseArray<String> PRIORITY_TO_STRING_MAP = new SparseArray<>();

    static {
        PRIORITY_TO_STRING_MAP.put(
                PRIORITY_OPPORTUNISTIC_CELLULAR, "PRIORITY_OPPORTUNISTIC_CELLULAR");
        PRIORITY_TO_STRING_MAP.put(PRIORITY_WIFI_IN_USE, "PRIORITY_WIFI_IN_USE");
        PRIORITY_TO_STRING_MAP.put(PRIORITY_WIFI_PROSPECTIVE, "PRIORITY_WIFI_PROSPECTIVE");
        PRIORITY_TO_STRING_MAP.put(PRIORITY_MACRO_CELLULAR, "PRIORITY_MACRO_CELLULAR");
        PRIORITY_TO_STRING_MAP.put(PRIORITY_ANY, "PRIORITY_ANY");
    }

    @NonNull private final VcnContext mVcnContext;
    @NonNull private final ParcelUuid mSubscriptionGroup;
    @NonNull private final UnderlyingNetworkTrackerCallback mCb;
@@ -395,12 +407,12 @@ public class UnderlyingNetworkTracker {
    }

    private void reevaluateNetworks() {
        TreeSet<UnderlyingNetworkRecord> sorted =
                new TreeSet<>(
                        UnderlyingNetworkRecord.getComparator(
                                mSubscriptionGroup, mLastSnapshot, mCurrentRecord, mCarrierConfig));
        sorted.addAll(mRouteSelectionCallback.getUnderlyingNetworks());
        if (mRouteSelectionCallback == null) {
            return; // UnderlyingNetworkTracker has quit.
        }

        TreeSet<UnderlyingNetworkRecord> sorted =
                mRouteSelectionCallback.getSortedUnderlyingNetworks();
        UnderlyingNetworkRecord candidate = sorted.isEmpty() ? null : sorted.first();
        if (Objects.equals(mCurrentRecord, candidate)) {
            return;
@@ -446,17 +458,23 @@ public class UnderlyingNetworkTracker {
        private final Map<Network, UnderlyingNetworkRecord.Builder>
                mUnderlyingNetworkRecordBuilders = new ArrayMap<>();

        private List<UnderlyingNetworkRecord> getUnderlyingNetworks() {
            final List<UnderlyingNetworkRecord> records = new ArrayList<>();
        private TreeSet<UnderlyingNetworkRecord> getSortedUnderlyingNetworks() {
            TreeSet<UnderlyingNetworkRecord> sorted =
                    new TreeSet<>(
                            UnderlyingNetworkRecord.getComparator(
                                    mSubscriptionGroup,
                                    mLastSnapshot,
                                    mCurrentRecord,
                                    mCarrierConfig));

            for (UnderlyingNetworkRecord.Builder builder :
                    mUnderlyingNetworkRecordBuilders.values()) {
                if (builder.isValid()) {
                    records.add(builder.build());
                    sorted.add(builder.build());
                }
            }

            return records;
            return sorted;
        }

        @Override
@@ -660,10 +678,21 @@ public class UnderlyingNetworkTracker {
        }

        /** Dumps the state of this record for logging and debugging purposes. */
        public void dump(IndentingPrintWriter pw) {
        private void dump(
                IndentingPrintWriter pw,
                ParcelUuid subscriptionGroup,
                TelephonySubscriptionSnapshot snapshot,
                UnderlyingNetworkRecord currentlySelected,
                PersistableBundle carrierConfig) {
            pw.println("UnderlyingNetworkRecord:");
            pw.increaseIndent();

            final int priorityClass =
                    calculatePriorityClass(
                            subscriptionGroup, snapshot, currentlySelected, carrierConfig);
            pw.println(
                    "Priority class: " + PRIORITY_TO_STRING_MAP.get(priorityClass) + " ("
                            + priorityClass + ")");
            pw.println("mNetwork: " + network);
            pw.println("mNetworkCapabilities: " + networkCapabilities);
            pw.println("mLinkProperties: " + linkProperties);
@@ -733,6 +762,30 @@ public class UnderlyingNetworkTracker {
        }
    }

    /** Dumps the state of this record for logging and debugging purposes. */
    public void dump(IndentingPrintWriter pw) {
        pw.println("UnderlyingNetworkTracker:");
        pw.increaseIndent();

        pw.println("Carrier WiFi Entry Threshold: " + getWifiEntryRssiThreshold(mCarrierConfig));
        pw.println("Carrier WiFi Exit Threshold: " + getWifiExitRssiThreshold(mCarrierConfig));
        pw.println(
                "Currently selected: " + (mCurrentRecord == null ? null : mCurrentRecord.network));

        pw.println("Underlying networks:");
        pw.increaseIndent();
        if (mRouteSelectionCallback != null) {
            for (UnderlyingNetworkRecord record :
                    mRouteSelectionCallback.getSortedUnderlyingNetworks()) {
                record.dump(pw, mSubscriptionGroup, mLastSnapshot, mCurrentRecord, mCarrierConfig);
            }
        }
        pw.decreaseIndent();
        pw.println();

        pw.decreaseIndent();
    }

    private class VcnActiveDataSubscriptionIdListener extends TelephonyCallback
            implements ActiveDataSubscriptionIdListener {
        @Override
+3 −0
Original line number Diff line number Diff line
@@ -557,11 +557,14 @@ public class Vcn extends Handler {

        pw.println("mCurrentStatus: " + mCurrentStatus);
        pw.println("mIsMobileDataEnabled: " + mIsMobileDataEnabled);
        pw.println();

        pw.println("mVcnGatewayConnections:");
        pw.increaseIndent();
        for (VcnGatewayConnection gw : mVcnGatewayConnections.values()) {
            gw.dump(pw);
        }
        pw.decreaseIndent();
        pw.println();

        pw.decreaseIndent();
+22 −9
Original line number Diff line number Diff line
@@ -1969,6 +1969,9 @@ public class VcnGatewayConnection extends StateMachine {
            }
            builder.setAdministratorUids(adminUids);

            builder.setLinkUpstreamBandwidthKbps(underlyingCaps.getLinkUpstreamBandwidthKbps());
            builder.setLinkDownstreamBandwidthKbps(underlyingCaps.getLinkDownstreamBandwidthKbps());

            // Set TransportInfo for SysUI use (never parcelled out of SystemServer).
            if (underlyingCaps.hasTransport(TRANSPORT_WIFI)
                    && underlyingCaps.getTransportInfo() instanceof WifiInfo) {
@@ -1985,6 +1988,11 @@ public class VcnGatewayConnection extends StateMachine {
                        "Unknown transport type or missing TransportInfo/NetworkSpecifier for"
                                + " non-null underlying network");
            }
        } else {
            Slog.wtf(
                    TAG,
                    "No underlying network while building network capabilities",
                    new IllegalStateException());
        }

        return builder.build();
@@ -2012,7 +2020,18 @@ public class VcnGatewayConnection extends StateMachine {
        lp.addRoute(new RouteInfo(new IpPrefix(Inet6Address.ANY, 0), null /*gateway*/,
                null /*iface*/, RouteInfo.RTN_UNICAST));

        final int underlyingMtu = (underlying == null) ? 0 : underlying.linkProperties.getMtu();
        int underlyingMtu = 0;
        if (underlying != null) {
            final LinkProperties underlyingLp = underlying.linkProperties;

            lp.setTcpBufferSizes(underlyingLp.getTcpBufferSizes());
            underlyingMtu = underlyingLp.getMtu();
        } else {
            Slog.wtf(
                    TAG,
                    "No underlying network while building link properties",
                    new IllegalStateException());
        }
        lp.setMtu(
                MtuUtils.getMtu(
                        ikeTunnelParams.getTunnelModeChildSessionParams().getSaProposals(),
@@ -2168,15 +2187,9 @@ public class VcnGatewayConnection extends StateMachine {
        pw.println(
                "mNetworkAgent.getNetwork(): "
                        + (mNetworkAgent == null ? null : mNetworkAgent.getNetwork()));
        pw.println();

        pw.println("mUnderlying:");
        pw.increaseIndent();
        if (mUnderlying != null) {
            mUnderlying.dump(pw);
        } else {
            pw.println("null");
        }
        pw.decreaseIndent();
        mUnderlyingNetworkTracker.dump(pw);
        pw.println();

        pw.decreaseIndent();
+9 −3
Original line number Diff line number Diff line
@@ -200,6 +200,9 @@ public class VcnGatewayConnectionConnectedStateTest extends VcnGatewayConnection
    public void testMigration() throws Exception {
        triggerChildOpened();

        mGatewayConnection
                .getUnderlyingNetworkTrackerCallback()
                .onSelectedUnderlyingNetworkChanged(TEST_UNDERLYING_NETWORK_RECORD_2);
        getChildSessionCallback()
                .onIpSecTransformsMigrated(makeDummyIpSecTransform(), makeDummyIpSecTransform());
        mTestLooper.dispatchAll();
@@ -207,7 +210,7 @@ public class VcnGatewayConnectionConnectedStateTest extends VcnGatewayConnection
        verify(mIpSecSvc, times(2))
                .setNetworkForTunnelInterface(
                        eq(TEST_IPSEC_TUNNEL_RESOURCE_ID),
                        eq(TEST_UNDERLYING_NETWORK_RECORD_1.network),
                        eq(TEST_UNDERLYING_NETWORK_RECORD_2.network),
                        any());

        for (int direction : new int[] {DIRECTION_IN, DIRECTION_OUT}) {
@@ -226,8 +229,10 @@ public class VcnGatewayConnectionConnectedStateTest extends VcnGatewayConnection
                MtuUtils.getMtu(
                        saProposals,
                        mConfig.getMaxMtu(),
                        TEST_UNDERLYING_NETWORK_RECORD_1.linkProperties.getMtu());
        verify(mNetworkAgent).sendLinkProperties(argThat(lp -> expectedMtu == lp.getMtu()));
                        TEST_UNDERLYING_NETWORK_RECORD_2.linkProperties.getMtu());
        verify(mNetworkAgent).sendLinkProperties(
                argThat(lp -> expectedMtu == lp.getMtu()
                        && TEST_TCP_BUFFER_SIZES_2.equals(lp.getTcpBufferSizes())));
    }

    private void triggerChildOpened() {
@@ -297,6 +302,7 @@ public class VcnGatewayConnectionConnectedStateTest extends VcnGatewayConnection
        final LinkProperties lp = lpCaptor.getValue();
        assertEquals(Collections.singletonList(TEST_INTERNAL_ADDR), lp.getLinkAddresses());
        assertEquals(Collections.singletonList(TEST_DNS_ADDR), lp.getDnsServers());
        assertEquals(TEST_TCP_BUFFER_SIZES_1, lp.getTcpBufferSizes());

        final NetworkCapabilities nc = ncCaptor.getValue();
        assertTrue(nc.hasTransport(TRANSPORT_CELLULAR));
Loading