DanaR: Fix NPE

This commit is contained in:
Milos Kozak 2022-03-30 10:01:28 +02:00
parent 75cb6d466c
commit c383f471a7

View file

@ -191,22 +191,23 @@ public abstract class AbstractDanaRExecutionService extends DaggerService {
protected void getBTSocketForSelectedPump() { protected void getBTSocketForSelectedPump() {
mDevName = sp.getString(R.string.key_danar_bt_name, ""); mDevName = sp.getString(R.string.key_danar_bt_name, "");
BluetoothAdapter bluetoothAdapter = ((BluetoothManager)context.getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter(); BluetoothAdapter bluetoothAdapter = ((BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter();
if (bluetoothAdapter != null) { if (bluetoothAdapter != null) {
Set<BluetoothDevice> bondedDevices = bluetoothAdapter.getBondedDevices(); Set<BluetoothDevice> bondedDevices = bluetoothAdapter.getBondedDevices();
for (BluetoothDevice device : bondedDevices) { if (bondedDevices != null)
if (mDevName.equals(device.getName())) { for (BluetoothDevice device : bondedDevices) {
mBTDevice = device; if (mDevName.equals(device.getName())) {
try { mBTDevice = device;
mRfcommSocket = mBTDevice.createRfcommSocketToServiceRecord(SPP_UUID); try {
} catch (IOException e) { mRfcommSocket = mBTDevice.createRfcommSocketToServiceRecord(SPP_UUID);
aapsLogger.error("Error creating socket: ", e); } catch (IOException e) {
aapsLogger.error("Error creating socket: ", e);
}
break;
} }
break;
} }
}
} else { } else {
ToastUtils.INSTANCE.showToastInUiThread(context.getApplicationContext(), ToastUtils.INSTANCE.showToastInUiThread(context.getApplicationContext(),
rh.gs(R.string.nobtadapter)); rh.gs(R.string.nobtadapter));