From bdcfaceeb293a2b61cb273d987b167848afc0bc0 Mon Sep 17 00:00:00 2001 From: Shen Lin Date: Tue, 3 Jan 2023 14:16:58 +0800 Subject: [PATCH] Fix NPE in BluetoothPairingController when comparing BluetoothClass Bug: 264162859 Test: atest BluetoothPairingControllerTest Change-Id: I7e3c913855d77983f4f8bc61f5b08f64fe9fae4d --- .../bluetooth/BluetoothPairingController.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/com/android/settings/bluetooth/BluetoothPairingController.java b/src/com/android/settings/bluetooth/BluetoothPairingController.java index a9e89e914cb..535e04086c0 100644 --- a/src/com/android/settings/bluetooth/BluetoothPairingController.java +++ b/src/com/android/settings/bluetooth/BluetoothPairingController.java @@ -31,6 +31,7 @@ import androidx.annotation.VisibleForTesting; import com.android.settings.R; import com.android.settings.bluetooth.BluetoothPairingDialogFragment.BluetoothPairingDialogListener; import com.android.settings.core.SettingsUIDeviceConfig; +import com.android.settingslib.bluetooth.BluetoothUtils; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.bluetooth.LocalBluetoothProfile; @@ -238,8 +239,8 @@ public class BluetoothPairingController implements OnCheckedChangeListener, case BluetoothDevice.ACCESS_REJECTED: return false; default: - if (mDevice.getBluetoothClass().getDeviceClass() - == BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE) { + if (BluetoothUtils.isDeviceClassMatched( + mDevice, BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE)) { return BluetoothDevice.EXTRA_PAIRING_INITIATOR_FOREGROUND == mInitiator; } return false; @@ -250,11 +251,12 @@ public class BluetoothPairingController implements OnCheckedChangeListener, * Update Phone book permission * */ - public void setContactSharingState() { + public void setContactSharingState() { final int permission = mDevice.getPhonebookAccessPermission(); if (permission == BluetoothDevice.ACCESS_ALLOWED - || (permission == BluetoothDevice.ACCESS_UNKNOWN && mDevice.getBluetoothClass(). - getDeviceClass() == BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE)) { + || (permission == BluetoothDevice.ACCESS_UNKNOWN + && BluetoothUtils.isDeviceClassMatched(mDevice, + BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE))) { onCheckedChanged(null, true); } else { onCheckedChanged(null, false);