From d8afb66b1171e4836c12926b6d99c6e18ca81600 Mon Sep 17 00:00:00 2001 From: James Mattis Date: Tue, 8 Feb 2022 19:18:48 -0800 Subject: [PATCH] Add @SupressLint to get around incorrect warning. EthernetNetworkSpecifier is being moved from being @SystemApi to public. This is causing the linter to incorrectly throw errors when building on erro prone. Add @SupressLint to the method causing the errors prevents the incorrect warning from causing build failures. Tracking bug b/193460475 - TODO to remove once fixed. cherry pick of http://ag/16822701 Bug: 210485380 Test: build errorprone Change-Id: Id297e739a2288ccc232c6b989ec7fee41837a910 Merged-In: Id297e739a2288ccc232c6b989ec7fee41837a910 --- framework/src/android/net/NetworkRequest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/framework/src/android/net/NetworkRequest.java b/framework/src/android/net/NetworkRequest.java index b7a6076c34..4f9d8455b5 100644 --- a/framework/src/android/net/NetworkRequest.java +++ b/framework/src/android/net/NetworkRequest.java @@ -423,6 +423,7 @@ public class NetworkRequest implements Parcelable { * * @deprecated Use {@link #setNetworkSpecifier(NetworkSpecifier)} instead. */ + @SuppressLint("NewApi") // TODO: b/193460475 remove once fixed @Deprecated public Builder setNetworkSpecifier(String networkSpecifier) { try { @@ -439,6 +440,15 @@ public class NetworkRequest implements Parcelable { } else if (mNetworkCapabilities.hasTransport(TRANSPORT_TEST)) { return setNetworkSpecifier(new TestNetworkSpecifier(networkSpecifier)); } else { + // TODO: b/193460475 remove comment once fixed + // @SuppressLint("NewApi") is due to EthernetNetworkSpecifier being changed + // from @SystemApi to public. EthernetNetworkSpecifier was introduced in Android + // 12 as @SystemApi(client = MODULE_LIBRARIES) and made public in Android 13. + // b/193460475 means in the above situation the tools will think + // EthernetNetworkSpecifier didn't exist in Android 12, causing the NewApi lint + // to fail. In this case, this is actually safe because this code was + // modularized in Android 12, so it can't run on SDKs before Android 12 and is + // therefore guaranteed to always have this class available to it. return setNetworkSpecifier(new EthernetNetworkSpecifier(networkSpecifier)); } }