Avoid NPE when DeviceInfo is null

(when a notification comes in while we're connected, but not initialized yet)
This commit is contained in:
cpfeiffer 2015-12-09 17:55:46 +01:00
parent 794ae6d800
commit 854a7ee1ac
2 changed files with 29 additions and 0 deletions

View File

@ -171,6 +171,10 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
}
private NotificationStrategy getNotificationStrategy() {
if (mDeviceInfo == null) {
// not initialized yet?
return new NoNotifcationStrategy();
}
if (mDeviceInfo.getFirmwareVersion() < MiBandFWHelper.FW_16779790) {
return new V1NotificationStrategy(this);
} else {

View File

@ -0,0 +1,25 @@
package nodomain.freeyourgadget.gadgetbridge.service.devices.miband;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import nodomain.freeyourgadget.gadgetbridge.devices.miband.VibrationProfile;
import nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEAction;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
/**
* Does not do anything.
*/
public class NoNotifcationStrategy implements NotificationStrategy {
private static final Logger LOG = LoggerFactory.getLogger(NoNotifcationStrategy.class);
@Override
public void sendDefaultNotification(TransactionBuilder builder, BtLEAction extraAction) {
LOG.info("dummy notification stragegy: default notification");
}
@Override
public void sendCustomNotification(VibrationProfile vibrationProfile, int flashTimes, int flashColour, int originalColour, long flashDuration, BtLEAction extraAction, TransactionBuilder builder) {
LOG.info("dummy notification stragegy: custom notification");
}
}