Enable strict_updatability_linting for NetworkStackApi30Shims
Fix the linter errors and enable strict_updatability_linting
Also use modules-utils method to check SDK version because
ShimUtils do not define the min_sdk and will be treated as
SDK 30 and conflict with the target SDK version(Q) if both
newInstance() and useApiAboveQ() are both defined as requires Q.
Thus, remove the reference for ShimUtils to align with other
usage and update corresponding usage accordingly.
Bug: 188851867
Test: m lint-check
Change-Id: Id6f7c2a4b919d76def1d3b022995e680d88022a4
diff --git a/Android.bp b/Android.bp
index 643b043..ac074fd 100644
--- a/Android.bp
+++ b/Android.bp
@@ -123,7 +123,7 @@
sdk_version: "system_30",
visibility: ["//visibility:private"],
lint: {
- baseline_filename: "lint-baseline-api-30-shims.xml",
+ strict_updatability_linting: true,
},
}
diff --git a/apishim/30/com/android/networkstack/apishim/api30/CaptivePortalDataShimImpl.java b/apishim/30/com/android/networkstack/apishim/api30/CaptivePortalDataShimImpl.java
index 5825021..4c471ca 100644
--- a/apishim/30/com/android/networkstack/apishim/api30/CaptivePortalDataShimImpl.java
+++ b/apishim/30/com/android/networkstack/apishim/api30/CaptivePortalDataShimImpl.java
@@ -130,7 +130,7 @@
@Override
public CaptivePortalDataShim withVenueFriendlyName(String friendlyName)
throws UnsupportedApiLevelException {
- // Not supported in API level 29
+ // Not supported in API level 30
throw new UnsupportedApiLevelException("FriendlyName not supported on API 30");
}
@@ -149,7 +149,7 @@
public CaptivePortalDataShim withPasspointInfo(@NonNull String friendlyName,
@NonNull Uri venueInfoUrl, @NonNull Uri termsAndConditionsUrl)
throws UnsupportedApiLevelException {
- // Not supported in API level 29
+ // Not supported in API level 30
throw new UnsupportedApiLevelException("PasspointInfo not supported on API 30");
}
}
diff --git a/apishim/30/com/android/networkstack/apishim/api30/NetworkInformationShimImpl.java b/apishim/30/com/android/networkstack/apishim/api30/NetworkInformationShimImpl.java
index 477dd42..a73f852 100644
--- a/apishim/30/com/android/networkstack/apishim/api30/NetworkInformationShimImpl.java
+++ b/apishim/30/com/android/networkstack/apishim/api30/NetworkInformationShimImpl.java
@@ -16,6 +16,8 @@
package com.android.networkstack.apishim.api30;
+import static com.android.modules.utils.build.SdkLevel.isAtLeastR;
+
import android.net.IpPrefix;
import android.net.LinkProperties;
import android.net.NetworkCapabilities;
@@ -25,17 +27,17 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
-import androidx.annotation.VisibleForTesting;
+import androidx.annotation.RequiresApi;
import com.android.networkstack.apishim.common.CaptivePortalDataShim;
import com.android.networkstack.apishim.common.NetworkInformationShim;
-import com.android.networkstack.apishim.common.ShimUtils;
import java.net.Inet4Address;
/**
* Compatibility implementation of {@link NetworkInformationShim}.
*/
+@RequiresApi(Build.VERSION_CODES.R)
public class NetworkInformationShimImpl extends
com.android.networkstack.apishim.api29.NetworkInformationShimImpl {
private static final String TAG = "api30.NetworkInformationShimImpl";
@@ -45,21 +47,14 @@
/**
* Get a new instance of {@link NetworkInformationShim}.
*/
+ @RequiresApi(Build.VERSION_CODES.Q)
public static NetworkInformationShim newInstance() {
- if (!useApiAboveQ()) {
+ if (!isAtLeastR()) {
return com.android.networkstack.apishim.api29.NetworkInformationShimImpl.newInstance();
}
return new NetworkInformationShimImpl();
}
- /**
- * Indicates whether the shim can use APIs above the Q SDK.
- */
- @VisibleForTesting
- public static boolean useApiAboveQ() {
- return ShimUtils.isReleaseOrDevelopmentApiAbove(Build.VERSION_CODES.Q);
- }
-
@Nullable
@Override
public Uri getCaptivePortalApiUrl(@Nullable LinkProperties lp) {
diff --git a/lint-baseline-api-30-shims.xml b/lint-baseline-api-30-shims.xml
deleted file mode 100644
index da541cd..0000000
--- a/lint-baseline-api-30-shims.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<issues format="5" by="lint 4.1.0" client="cli" variant="all" version="4.1.0">
-
- <issue
- id="NewApi"
- message="Call requires API level R (current min is 29): `android.net.LinkProperties#getNat64Prefix`"
- errorLine1=" return lp.getNat64Prefix();"
- errorLine2=" ~~~~~~~~~~~~~~">
- <location
- file="packages/modules/NetworkStack/apishim/30/com/android/networkstack/apishim/api30/NetworkInformationShimImpl.java"
- line="85"
- column="19"/>
- </issue>
-
- <issue
- id="NewApi"
- message="Call requires API level R (current min is 29): `android.net.LinkProperties#setNat64Prefix`"
- errorLine1=" lp.setNat64Prefix(prefix);"
- errorLine2=" ~~~~~~~~~~~~~~">
- <location
- file="packages/modules/NetworkStack/apishim/30/com/android/networkstack/apishim/api30/NetworkInformationShimImpl.java"
- line="90"
- column="12"/>
- </issue>
-
- <issue
- id="NewApi"
- message="Call requires API level R (current min is 29): `android.net.LinkProperties#setDhcpServerAddress`"
- errorLine1=" lp.setDhcpServerAddress(serverAddress);"
- errorLine2=" ~~~~~~~~~~~~~~~~~~~~">
- <location
- file="packages/modules/NetworkStack/apishim/30/com/android/networkstack/apishim/api30/NetworkInformationShimImpl.java"
- line="109"
- column="12"/>
- </issue>
-
-</issues>
diff --git a/tests/unit/src/com/android/networkstack/NetworkStackNotifierTest.kt b/tests/unit/src/com/android/networkstack/NetworkStackNotifierTest.kt
index 3b44597..9fda189 100644
--- a/tests/unit/src/com/android/networkstack/NetworkStackNotifierTest.kt
+++ b/tests/unit/src/com/android/networkstack/NetworkStackNotifierTest.kt
@@ -50,6 +50,8 @@
import com.android.networkstack.NetworkStackNotifier.CONNECTED_NOTIFICATION_TIMEOUT_MS
import com.android.networkstack.NetworkStackNotifier.Dependencies
import com.android.networkstack.apishim.NetworkInformationShimImpl
+import com.android.modules.utils.build.SdkLevel.isAtLeastR
+import com.android.modules.utils.build.SdkLevel.isAtLeastS
import org.junit.Assume.assumeTrue
import org.junit.Before
import org.junit.Test
@@ -235,7 +237,7 @@
@Test
fun testConnectedNotification_WithSsid() {
// NetworkCapabilities#getSSID is not available for API <= Q
- assumeTrue(NetworkInformationShimImpl.useApiAboveQ())
+ assumeTrue(isAtLeastR())
val capabilities = NetworkCapabilities(VALIDATED_CAPABILITIES).setSSID(TEST_SSID)
onCapabilitiesChanged(EMPTY_CAPABILITIES)
@@ -252,7 +254,7 @@
@Test
fun testConnectedVenueInfoNotification() {
// Venue info (CaptivePortalData) is not available for API <= Q
- assumeTrue(NetworkInformationShimImpl.useApiAboveQ())
+ assumeTrue(isAtLeastR())
mNotifier.notifyCaptivePortalValidationPending(TEST_NETWORK)
onLinkPropertiesChanged(mTestCapportLp)
onDefaultNetworkAvailable(TEST_NETWORK)
@@ -270,7 +272,7 @@
@Test
fun testConnectedVenueInfoNotification_VenueInfoDisabled() {
// Venue info (CaptivePortalData) is not available for API <= Q
- assumeTrue(NetworkInformationShimImpl.useApiAboveQ())
+ assumeTrue(isAtLeastR())
val channel = NotificationChannel(CHANNEL_VENUE_INFO, "test channel", IMPORTANCE_NONE)
doReturn(channel).`when`(mNotificationChannelsNm).getNotificationChannel(CHANNEL_VENUE_INFO)
mNotifier.notifyCaptivePortalValidationPending(TEST_NETWORK)
@@ -289,7 +291,7 @@
@Test
fun testVenueInfoNotification() {
// Venue info (CaptivePortalData) is not available for API <= Q
- assumeTrue(NetworkInformationShimImpl.useApiAboveQ())
+ assumeTrue(isAtLeastR())
onLinkPropertiesChanged(mTestCapportLp)
onDefaultNetworkAvailable(TEST_NETWORK)
val capabilities = NetworkCapabilities(VALIDATED_CAPABILITIES).setSSID(TEST_SSID)
@@ -307,7 +309,7 @@
@Test
fun testVenueInfoNotification_VenueInfoDisabled() {
// Venue info (CaptivePortalData) is not available for API <= Q
- assumeTrue(NetworkInformationShimImpl.useApiAboveQ())
+ assumeTrue(isAtLeastR())
doReturn(null).`when`(mNm).getNotificationChannel(CHANNEL_VENUE_INFO)
onLinkPropertiesChanged(mTestCapportLp)
onDefaultNetworkAvailable(TEST_NETWORK)
@@ -320,7 +322,7 @@
@Test
fun testNonDefaultVenueInfoNotification() {
// Venue info (CaptivePortalData) is not available for API <= Q
- assumeTrue(NetworkInformationShimImpl.useApiAboveQ())
+ assumeTrue(isAtLeastR())
onLinkPropertiesChanged(mTestCapportLp)
onCapabilitiesChanged(VALIDATED_CAPABILITIES)
mLooper.processAllMessages()
@@ -331,7 +333,7 @@
@Test
fun testEmptyCaptivePortalDataVenueInfoNotification() {
// Venue info (CaptivePortalData) is not available for API <= Q
- assumeTrue(NetworkInformationShimImpl.useApiAboveQ())
+ assumeTrue(isAtLeastR())
onLinkPropertiesChanged(EMPTY_CAPPORT_LP)
onCapabilitiesChanged(VALIDATED_CAPABILITIES)
mLooper.processAllMessages()
@@ -342,7 +344,7 @@
@Test
fun testUnvalidatedNetworkVenueInfoNotification() {
// Venue info (CaptivePortalData) is not available for API <= Q
- assumeTrue(NetworkInformationShimImpl.useApiAboveQ())
+ assumeTrue(isAtLeastR())
onLinkPropertiesChanged(mTestCapportLp)
onCapabilitiesChanged(EMPTY_CAPABILITIES)
mLooper.processAllMessages()
@@ -353,7 +355,7 @@
@Test
fun testConnectedVenueInfoWithFriendlyNameNotification() {
// Venue info (CaptivePortalData) with friendly name is not available for API <= R
- assumeTrue(NetworkInformationShimImpl.useApiAboveR())
+ assumeTrue(isAtLeastS())
mNotifier.notifyCaptivePortalValidationPending(TEST_NETWORK)
onLinkPropertiesChanged(mTestCapportVenueUrlWithFriendlyNameLp)
onDefaultNetworkAvailable(TEST_NETWORK)