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

Commit 61d7ab94 authored by Benedict Wong's avatar Benedict Wong
Browse files

Add additional dump information for UnderlyingNetworkTracker

This change adds additional dump information to facilitate the
resolution of bug reports.

Additionally, this method cleans up dump formatting.

Bug: 188842647
Test: atest FrameworksVcnTests
Test: adb shell dumpsys vcn_management
Change-Id: I5ce7fe05eb21a89c2034079223ef44f05db2a087
Merged-In: I5ce7fe05eb21a89c2034079223ef44f05db2a087
(cherry picked from commit 02cb0d7b)
parent e237e35d
Loading
Loading
Loading
Loading
+1 −15
Original line number Diff line number Diff line
@@ -1000,30 +1000,18 @@ 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, "| ");

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

            pw.println("mNetworkProvider:");
            pw.increaseIndent();
            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:");
@@ -1043,8 +1031,6 @@ public class VcnManagementService extends IVcnManagementService.Stub {
                pw.decreaseIndent();
                pw.println();
            }

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

+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();
+2 −8
Original line number Diff line number Diff line
@@ -2187,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();