Fix NPE in BluetoothPairingController when comparing BluetoothClass

Bug: 264162859
Test: atest BluetoothPairingControllerTest
Change-Id: I7e3c913855d77983f4f8bc61f5b08f64fe9fae4d
This commit is contained in:
Shen Lin
2023-01-03 14:16:58 +08:00
parent 749c2dddbc
commit bdcfaceeb2

View File

@@ -31,6 +31,7 @@ import androidx.annotation.VisibleForTesting;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.bluetooth.BluetoothPairingDialogFragment.BluetoothPairingDialogListener; import com.android.settings.bluetooth.BluetoothPairingDialogFragment.BluetoothPairingDialogListener;
import com.android.settings.core.SettingsUIDeviceConfig; import com.android.settings.core.SettingsUIDeviceConfig;
import com.android.settingslib.bluetooth.BluetoothUtils;
import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.bluetooth.LocalBluetoothProfile; import com.android.settingslib.bluetooth.LocalBluetoothProfile;
@@ -238,8 +239,8 @@ public class BluetoothPairingController implements OnCheckedChangeListener,
case BluetoothDevice.ACCESS_REJECTED: case BluetoothDevice.ACCESS_REJECTED:
return false; return false;
default: default:
if (mDevice.getBluetoothClass().getDeviceClass() if (BluetoothUtils.isDeviceClassMatched(
== BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE) { mDevice, BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE)) {
return BluetoothDevice.EXTRA_PAIRING_INITIATOR_FOREGROUND == mInitiator; return BluetoothDevice.EXTRA_PAIRING_INITIATOR_FOREGROUND == mInitiator;
} }
return false; return false;
@@ -253,8 +254,9 @@ public class BluetoothPairingController implements OnCheckedChangeListener,
public void setContactSharingState() { public void setContactSharingState() {
final int permission = mDevice.getPhonebookAccessPermission(); final int permission = mDevice.getPhonebookAccessPermission();
if (permission == BluetoothDevice.ACCESS_ALLOWED if (permission == BluetoothDevice.ACCESS_ALLOWED
|| (permission == BluetoothDevice.ACCESS_UNKNOWN && mDevice.getBluetoothClass(). || (permission == BluetoothDevice.ACCESS_UNKNOWN
getDeviceClass() == BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE)) { && BluetoothUtils.isDeviceClassMatched(mDevice,
BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE))) {
onCheckedChanged(null, true); onCheckedChanged(null, true);
} else { } else {
onCheckedChanged(null, false); onCheckedChanged(null, false);