From 38d757b09be4a3f0330705d8c23f7dccb0010040 Mon Sep 17 00:00:00 2001 From: Shen Lin Date: Fri, 8 Dec 2023 11:34:26 +0800 Subject: Align the time of bssid comparison to avoid NPE caused by value changes. This CL contributes the follwing refinements: - The return value of `wifiInfo.getBSSID()` may change when calling outside or inside `synchronized`, so it would be better to migrate the whole `bssid` comparison inside that `synchronized`. - Use `TextUtils` to handle `bssid` Bug: 315308336 Test: m Change-Id: Ie6fce634c9f097e9a866ec44d6de1e5d811a6b3f --- .../android/server/adb/AdbDebuggingManager.java | 23 ++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/services/core/java/com/android/server/adb/AdbDebuggingManager.java b/services/core/java/com/android/server/adb/AdbDebuggingManager.java index 3280afdf6703..627a62ee0496 100644 --- a/services/core/java/com/android/server/adb/AdbDebuggingManager.java +++ b/services/core/java/com/android/server/adb/AdbDebuggingManager.java @@ -42,6 +42,7 @@ import android.debug.AdbManager; import android.debug.AdbNotifications; import android.debug.AdbProtoEnums; import android.debug.AdbTransportType; +import android.debug.IAdbTransport; import android.debug.PairDevice; import android.net.ConnectivityManager; import android.net.LocalSocket; @@ -66,6 +67,7 @@ import android.os.UserHandle; import android.os.UserManager; import android.provider.Settings; import android.service.adb.AdbDebuggingManagerProto; +import android.text.TextUtils; import android.util.AtomicFile; import android.util.Base64; import android.util.Slog; @@ -679,16 +681,17 @@ public class AdbDebuggingManager { return; } - // Check for network change - String bssid = wifiInfo.getBSSID(); - if (bssid == null || bssid.isEmpty()) { - Slog.e(TAG, "Unable to get the wifi ap's BSSID. Disabling adbwifi."); - Settings.Global.putInt(mContentResolver, - Settings.Global.ADB_WIFI_ENABLED, 0); - return; - } synchronized (mAdbConnectionInfo) { - if (!bssid.equals(mAdbConnectionInfo.getBSSID())) { + // Check for network change + final String bssid = wifiInfo.getBSSID(); + if (TextUtils.isEmpty(bssid)) { + Slog.e(TAG, + "Unable to get the wifi ap's BSSID. Disabling adbwifi."); + Settings.Global.putInt(mContentResolver, + Settings.Global.ADB_WIFI_ENABLED, 0); + return; + } + if (!TextUtils.equals(bssid, mAdbConnectionInfo.getBSSID())) { Slog.i(TAG, "Detected wifi network change. Disabling adbwifi."); Settings.Global.putInt(mContentResolver, Settings.Global.ADB_WIFI_ENABLED, 0); @@ -1397,7 +1400,7 @@ public class AdbDebuggingManager { } String bssid = wifiInfo.getBSSID(); - if (bssid == null || bssid.isEmpty()) { + if (TextUtils.isEmpty(bssid)) { Slog.e(TAG, "Unable to get the wifi ap's BSSID."); return null; } -- cgit v1.2.3-59-g8ed1b