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

View File

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