Avoid NPEs when device-name is null

master
cpfeiffer 2016-07-12 00:24:23 +02:00
parent 76895aa2b1
commit aa00d2f93a
2 changed files with 7 additions and 3 deletions

View File

@ -1,6 +1,7 @@
package nodomain.freeyourgadget.gadgetbridge.devices.miband;
import android.app.Activity;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.net.Uri;
@ -39,8 +40,10 @@ public class MiBandCoordinator extends AbstractDeviceCoordinator {
}
// and a heuristic
try {
if (isHealthWearable(candidate.getDevice())) {
return candidate.getDevice().getName().toUpperCase().startsWith(MiBandConst.MI_GENERAL_NAME_PREFIX.toUpperCase());
BluetoothDevice device = candidate.getDevice();
if (isHealthWearable(device)) {
String name = device.getName();
return name != null && name.toUpperCase().startsWith(MiBandConst.MI_GENERAL_NAME_PREFIX.toUpperCase());
}
} catch (Exception ex) {
LOG.error("unable to check device support", ex);

View File

@ -23,7 +23,8 @@ public class PebbleCoordinator extends AbstractDeviceCoordinator {
@Override
public boolean supports(GBDeviceCandidate candidate) {
return candidate.getDevice().getName().startsWith("Pebble");
String name = candidate.getDevice().getName();
return name != null && name.startsWith("Pebble");
}
@Override