From 4ad09c4a74048b26569a101f983e681912ab5943 Mon Sep 17 00:00:00 2001 From: Junyu Lai Date: Fri, 25 Jun 2021 15:41:35 +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 Original-Change: https://android-review.googlesource.com/1747893 Merged-In: I5df3547995111fe6340facb94a577296d2228694 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 4c967b8c30..ed477a2ee8 100644 --- a/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java +++ b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java @@ -537,8 +537,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)));