From 144b6c742a6cd699413153a1d91c0c6fd89f960a Mon Sep 17 00:00:00 2001 From: Junyu Lai Date: Fri, 25 Jun 2021 03:50:39 +0000 Subject: [PATCH] Check null NetworkSpecifier before redacting Do null check before redacting, since NetworkSpecifier will not always be attached. For example, NetworkSpecifier of wifi network is only attached when a wifi network is created in response to a network request with specifier attached. Test: atest CtsNetTestCases:android.net.cts.ConnectivityManagerTest#testGetAllNetworkStateSnapshots \ --rerun-until-failure 100 (tested on cuttlefish mobile and wifi) Bug: 191944987 Change-Id: I5df3547995111fe6340facb94a577296d2228694 --- .../cts/net/src/android/net/cts/ConnectivityManagerTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java index 3220565e84..24ecf7dea5 100644 --- a/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java +++ b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java @@ -536,8 +536,10 @@ public class ConnectivityManagerTest { Objects.requireNonNull(mCm.getNetworkCapabilities(network)); // Redact specifier of the capabilities of the snapshot before comparing since // the result returned from getNetworkCapabilities always get redacted. + final NetworkSpecifier snapshotCapSpecifier = + snapshot.getNetworkCapabilities().getNetworkSpecifier(); final NetworkSpecifier redactedSnapshotCapSpecifier = - snapshot.getNetworkCapabilities().getNetworkSpecifier().redact(); + snapshotCapSpecifier == null ? null : snapshotCapSpecifier.redact(); assertEquals("", caps.describeImmutableDifferences( snapshot.getNetworkCapabilities() .setNetworkSpecifier(redactedSnapshotCapSpecifier)));