From 96f8e1b787d548d113fa8be42d6a016f6871df1e Mon Sep 17 00:00:00 2001 From: Quang Anh Luong Date: Tue, 11 Mar 2025 08:12:22 +0900 Subject: [PATCH] Use SdkLevel.isAtLeastB() instead of SDK_INT Replace the explicit SDK_INT checks with the helper function SdkLevel.isAtLeastB(). Bug: 216524590 Test: covered by existing tests Change-Id: I32ae771d5b157d97dfbe3c37caf62e734eaa250e --- Tethering/common/TetheringLib/Android.bp | 1 + .../TetheringLib/src/android/net/TetheringManager.java | 3 ++- .../com/android/networkstack/tethering/Tethering.java | 10 +++++----- .../networkstack/tethering/TetheringDependencies.java | 3 +-- .../android/tethering/cts/TetheringManagerTest.java | 8 +++----- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/Tethering/common/TetheringLib/Android.bp b/Tethering/common/TetheringLib/Android.bp index e2498e41e5..d2a8c13dfe 100644 --- a/Tethering/common/TetheringLib/Android.bp +++ b/Tethering/common/TetheringLib/Android.bp @@ -111,6 +111,7 @@ java_defaults { "sdk_module-lib_current_framework-wifi", ], static_libs: [ + "modules-utils-build", "com.android.net.flags-aconfig-java", ], aidl: { diff --git a/Tethering/common/TetheringLib/src/android/net/TetheringManager.java b/Tethering/common/TetheringLib/src/android/net/TetheringManager.java index 0ac97f06e5..0a66f01c7e 100644 --- a/Tethering/common/TetheringLib/src/android/net/TetheringManager.java +++ b/Tethering/common/TetheringLib/src/android/net/TetheringManager.java @@ -42,6 +42,7 @@ import android.util.ArraySet; import android.util.Log; import com.android.internal.annotations.GuardedBy; +import com.android.modules.utils.build.SdkLevel; import com.android.net.flags.Flags; import java.lang.annotation.Retention; @@ -664,7 +665,7 @@ public class TetheringManager { } private void unsupportedAfterV() { - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.VANILLA_ICE_CREAM) { + if (SdkLevel.isAtLeastB()) { throw new UnsupportedOperationException("Not supported after SDK version " + Build.VERSION_CODES.VANILLA_ICE_CREAM); } diff --git a/Tethering/src/com/android/networkstack/tethering/Tethering.java b/Tethering/src/com/android/networkstack/tethering/Tethering.java index 1589509ea9..cd2a871d11 100644 --- a/Tethering/src/com/android/networkstack/tethering/Tethering.java +++ b/Tethering/src/com/android/networkstack/tethering/Tethering.java @@ -117,7 +117,6 @@ import android.net.wifi.p2p.WifiP2pGroup; import android.net.wifi.p2p.WifiP2pInfo; import android.net.wifi.p2p.WifiP2pManager; import android.os.Binder; -import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.Looper; @@ -146,6 +145,7 @@ import com.android.internal.util.MessageUtils; import com.android.internal.util.State; import com.android.internal.util.StateMachine; import com.android.modules.utils.build.SdkLevel; +import com.android.net.flags.Flags; import com.android.net.module.util.BaseNetdUnsolicitedEventListener; import com.android.net.module.util.CollectionUtils; import com.android.net.module.util.HandlerUtils; @@ -463,7 +463,7 @@ public class Tethering { } boolean isTetheringWithSoftApConfigEnabled() { - return mDeps.isTetheringWithSoftApConfigEnabled(); + return SdkLevel.isAtLeastB() && Flags.tetheringWithSoftApConfig(); } /** @@ -637,7 +637,7 @@ public class Tethering { // TODO: fix the teardown path to stop depending on interface state notifications. // These are not necessary since most/all link layers have their own teardown // notifications, and can race with those notifications. - if (enabled && Build.VERSION.SDK_INT > Build.VERSION_CODES.VANILLA_ICE_CREAM) { + if (enabled && SdkLevel.isAtLeastB()) { return; } @@ -1078,7 +1078,7 @@ public class Tethering { } private void handleLegacyTether(String iface, final IIntResultListener listener) { - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.VANILLA_ICE_CREAM) { + if (SdkLevel.isAtLeastB()) { // After V, the TetheringManager and ConnectivityManager tether and untether methods // throw UnsupportedOperationException, so this cannot happen in normal use. Ensure // that this code cannot run even if callers use raw binder calls or other @@ -1179,7 +1179,7 @@ public class Tethering { } void legacyUntether(String iface, final IIntResultListener listener) { - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.VANILLA_ICE_CREAM) { + if (SdkLevel.isAtLeastB()) { // After V, the TetheringManager and ConnectivityManager tether and untether methods // throw UnsupportedOperationException, so this cannot happen in normal use. Ensure // that this code cannot run even if callers use raw binder calls or other diff --git a/Tethering/src/com/android/networkstack/tethering/TetheringDependencies.java b/Tethering/src/com/android/networkstack/tethering/TetheringDependencies.java index 8e170856cc..bd35cf20d0 100644 --- a/Tethering/src/com/android/networkstack/tethering/TetheringDependencies.java +++ b/Tethering/src/com/android/networkstack/tethering/TetheringDependencies.java @@ -214,7 +214,6 @@ public abstract class TetheringDependencies { * Wrapper for tethering_with_soft_ap_config feature flag. */ public boolean isTetheringWithSoftApConfigEnabled() { - return Build.VERSION.SDK_INT > Build.VERSION_CODES.VANILLA_ICE_CREAM - && Flags.tetheringWithSoftApConfig(); + return SdkLevel.isAtLeastB() && Flags.tetheringWithSoftApConfig(); } } diff --git a/tests/cts/tethering/src/android/tethering/cts/TetheringManagerTest.java b/tests/cts/tethering/src/android/tethering/cts/TetheringManagerTest.java index 9e49926fca..e645f671ae 100644 --- a/tests/cts/tethering/src/android/tethering/cts/TetheringManagerTest.java +++ b/tests/cts/tethering/src/android/tethering/cts/TetheringManagerTest.java @@ -73,7 +73,6 @@ import android.net.cts.util.CtsTetheringUtils.TestTetheringEventCallback; import android.net.wifi.SoftApConfiguration; import android.net.wifi.WifiManager; import android.net.wifi.WifiSsid; -import android.os.Build; import android.os.Bundle; import android.os.PersistableBundle; import android.os.ResultReceiver; @@ -391,7 +390,7 @@ public class TetheringManagerTest { mCtsTetheringUtils.stopWifiTethering(tetherEventCallback); - if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.VANILLA_ICE_CREAM) { + if (!SdkLevel.isAtLeastB()) { try { final int ret = runAsShell(TETHER_PRIVILEGED, () -> mTM.tether(wifiTetheringIface)); @@ -480,8 +479,7 @@ public class TetheringManagerTest { } private boolean isTetheringWithSoftApConfigEnabled() { - return Build.VERSION.SDK_INT > Build.VERSION_CODES.VANILLA_ICE_CREAM - && Flags.tetheringWithSoftApConfig(); + return SdkLevel.isAtLeastB() && Flags.tetheringWithSoftApConfig(); } @Test @@ -636,7 +634,7 @@ public class TetheringManagerTest { @Test public void testLegacyTetherApisThrowUnsupportedOperationExceptionAfterV() { - assumeTrue(Build.VERSION.SDK_INT > Build.VERSION_CODES.VANILLA_ICE_CREAM); + assumeTrue(SdkLevel.isAtLeastB()); assertThrows(UnsupportedOperationException.class, () -> mTM.tether("iface")); assertThrows(UnsupportedOperationException.class, () -> mTM.untether("iface")); }