From bb815f25dd764b9654ab9e37138745cd0ff9feae Mon Sep 17 00:00:00 2001 From: Yuyang Huang Date: Fri, 29 Nov 2024 15:37:28 +0900 Subject: [PATCH] Add isDebuggable() to DeviceInfoUtils for Android R compatibility Introduced the isDebuggable() helper method in DeviceInfoUtils. This method provides a consistent way to determine if the device is in debuggable mode across different Android versions. Since Build.isDebuggable() is not available in Android R, the method checks the "ro.debuggable" system property as a fallback, ensuring compatibility. Bug: 381327071 Test: TH Change-Id: Ibf77bcfc50378d88458baf07683e7bf2065734de --- .../com/android/testutils/DeviceInfoUtils.java | 14 ++++++++++++++ .../android/net/cts/ConnectivityManagerTest.java | 3 +-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/staticlibs/testutils/devicetests/com/android/testutils/DeviceInfoUtils.java b/staticlibs/testutils/devicetests/com/android/testutils/DeviceInfoUtils.java index ce55fdc1d3..31879af3ae 100644 --- a/staticlibs/testutils/devicetests/com/android/testutils/DeviceInfoUtils.java +++ b/staticlibs/testutils/devicetests/com/android/testutils/DeviceInfoUtils.java @@ -16,6 +16,10 @@ package com.android.testutils; +import static com.android.modules.utils.build.SdkLevel.isAtLeastS; + +import android.os.Build; +import android.os.SystemProperties; import android.os.VintfRuntimeInfo; import android.text.TextUtils; import android.util.Pair; @@ -173,4 +177,14 @@ public class DeviceInfoUtils { final KVersion from = DeviceInfoUtils.getMajorMinorSubminorVersion(version); return current.isAtLeast(from); } + + /** + * Check if the current build is a debuggable build. + */ + public static boolean isDebuggable() { + if (isAtLeastS()) { + return Build.isDebuggable(); + } + return SystemProperties.getInt("ro.debuggable", 0) == 1; + } } diff --git a/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java index 88309ed0b0..feb46210e2 100644 --- a/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java +++ b/tests/cts/net/src/android/net/cts/ConnectivityManagerTest.java @@ -952,9 +952,8 @@ public class ConnectivityManagerTest { final List cellNetworkAddresses = cellLinkProperties.getAddresses(); // In userdebug build, on cellular network, if the onNetwork check failed, we also try to // re-verify it by obtaining the IP address through DNS query. - boolean isUserDebug = Build.isDebuggable(); if (cellAddress instanceof Inet6Address) { - if (isUserDebug && !cellNetworkAddresses.contains(cellAddress)) { + if (DeviceInfoUtils.isDebuggable() && !cellNetworkAddresses.contains(cellAddress)) { final InetAddress ipv6AddressThroughDns = InetAddresses.parseNumericAddress( getDeviceIpv6AddressThroughDnsQuery(cellNetwork)); assertContains(cellNetworkAddresses, ipv6AddressThroughDns);