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

Commit 7fe91d40 authored by James Mattis's avatar James Mattis Committed by Gerrit Code Review
Browse files

Merge "Adding log history for setOemNetworkPreference()"

parents 6b35a8ac 57363f54
Loading
Loading
Loading
Loading
+15 −3
Original line number Diff line number Diff line
@@ -2884,13 +2884,13 @@ public class ConnectivityService extends IConnectivityManager.Stub
            pw.println();
            pw.println("mNetworkRequestInfoLogs (most recent first):");
            pw.increaseIndent();
            mNetworkRequestInfoLogs.reverseDump(fd, pw, args);
            mNetworkRequestInfoLogs.reverseDump(pw);
            pw.decreaseIndent();

            pw.println();
            pw.println("mNetworkInfoBlockingLogs (most recent first):");
            pw.increaseIndent();
            mNetworkInfoBlockingLogs.reverseDump(fd, pw, args);
            mNetworkInfoBlockingLogs.reverseDump(pw);
            pw.decreaseIndent();

            pw.println();
@@ -2904,7 +2904,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
                long duration = SystemClock.elapsedRealtime() - mLastWakeLockAcquireTimestamp;
                pw.println("currently holding WakeLock for: " + (duration / 1000) + "s");
            }
            mWakelockLogs.reverseDump(fd, pw, args);
            mWakelockLogs.reverseDump(pw);

            pw.println();
            pw.println("bandwidth update requests (by uid):");
@@ -2916,7 +2916,12 @@ public class ConnectivityService extends IConnectivityManager.Stub
                }
            }
            pw.decreaseIndent();
            pw.decreaseIndent();

            pw.println();
            pw.println("mOemNetworkPreferencesLogs (most recent first):");
            pw.increaseIndent();
            mOemNetworkPreferencesLogs.reverseDump(pw);
            pw.decreaseIndent();
        }

@@ -6205,6 +6210,12 @@ public class ConnectivityService extends IConnectivityManager.Stub
    @NonNull
    private ProfileNetworkPreferences mProfileNetworkPreferences = new ProfileNetworkPreferences();

    // OemNetworkPreferences activity String log entries.
    private static final int MAX_OEM_NETWORK_PREFERENCE_LOGS = 20;
    @NonNull
    private final LocalLog mOemNetworkPreferencesLogs =
            new LocalLog(MAX_OEM_NETWORK_PREFERENCE_LOGS);

    /**
     * Determine whether a given package has a mapping in the current OemNetworkPreferences.
     * @param packageName the package name to check existence of a mapping for.
@@ -9637,6 +9648,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
            return;
        }

        mOemNetworkPreferencesLogs.log("UPDATE INITIATED: " + preference);
        final ArraySet<NetworkRequestInfo> nris =
                new OemNetworkRequestFactory().createNrisFromOemNetworkPreferences(preference);
        replaceDefaultNetworkRequestsForPreference(nris);
+31 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.server;
import static android.Manifest.permission.CHANGE_NETWORK_STATE;
import static android.Manifest.permission.CONNECTIVITY_USE_RESTRICTED_NETWORKS;
import static android.Manifest.permission.DUMP;
import static android.Manifest.permission.NETWORK_FACTORY;
import static android.Manifest.permission.NETWORK_SETTINGS;
import static android.app.PendingIntent.FLAG_IMMUTABLE;
@@ -356,6 +357,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import kotlin.reflect.KClass;
@@ -9950,6 +9953,7 @@ public class ConnectivityServiceTest {
    @Test
    public void testDumpDoesNotCrash() {
        mServiceContext.setPermission(DUMP, PERMISSION_GRANTED);
        // Filing a couple requests prior to testing the dump.
        final TestNetworkCallback genericNetworkCallback = new TestNetworkCallback();
        final TestNetworkCallback wifiNetworkCallback = new TestNetworkCallback();
@@ -11705,6 +11709,33 @@ public class ConnectivityServiceTest {
        // default callbacks will be unregistered in tearDown
    }
    @Test
    public void testSetOemNetworkPreferenceLogsRequest() throws Exception {
        mServiceContext.setPermission(DUMP, PERMISSION_GRANTED);
        @OemNetworkPreferences.OemNetworkPreference final int networkPref =
                OEM_NETWORK_PREFERENCE_OEM_PAID;
        final StringWriter stringWriter = new StringWriter();
        final String logIdentifier = "UPDATE INITIATED: OemNetworkPreferences";
        final Pattern pattern = Pattern.compile(logIdentifier);
        final int expectedNumLogs = 2;
        final UidRangeParcel[] uidRanges =
                toUidRangeStableParcels(uidRangesForUids(TEST_PACKAGE_UID));
        // Call twice to generate two logs.
        setupSetOemNetworkPreferenceForPreferenceTest(networkPref, uidRanges, TEST_PACKAGE_NAME);
        setupSetOemNetworkPreferenceForPreferenceTest(networkPref, uidRanges, TEST_PACKAGE_NAME);
        mService.dump(new FileDescriptor(), new PrintWriter(stringWriter), new String[0]);
        final String dumpOutput = stringWriter.toString();
        final Matcher matcher = pattern.matcher(dumpOutput);
        int count = 0;
        while (matcher.find()) {
            count++;
        }
        assertEquals(expectedNumLogs, count);
    }
    @Test
    public void testGetAllNetworkStateSnapshot() throws Exception {
        verifyNoNetwork();