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
This commit is contained in:
Quang Anh Luong 2025-03-11 08:12:22 +09:00
commit 96f8e1b787
5 changed files with 12 additions and 13 deletions

View file

@ -111,6 +111,7 @@ java_defaults {
"sdk_module-lib_current_framework-wifi",
],
static_libs: [
"modules-utils-build",
"com.android.net.flags-aconfig-java",
],
aidl: {

View file

@ -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);
}

View file

@ -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

View file

@ -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();
}
}

View file

@ -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"));
}