Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 38d757b0 authored by Shen Lin's avatar Shen Lin
Browse files

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
parent 7fd8fcb3
Loading
Loading
Loading
Loading
+13 −10
Original line number Diff line number Diff line
@@ -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;
                        }

                        synchronized (mAdbConnectionInfo) {
                            // 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.");
                            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;
                            }
                        synchronized (mAdbConnectionInfo) {
                            if (!bssid.equals(mAdbConnectionInfo.getBSSID())) {
                            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;
            }