Fix possible race condition when availableSlots == 3

(There are two difficult things...)
here
Daniele Gobbetti 2015-12-29 09:18:02 +01:00
parent 9ea2977143
commit 1d9e1d7caf
1 changed files with 3 additions and 2 deletions

View File

@ -811,16 +811,17 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
int iteration = 0;
ArrayList<GBAlarm> alarmList = new ArrayList<>();
for(CalendarEvents.CalendarEvent mEvt : mEvents) {
if (iteration >= availableSlots) {
if (iteration >= availableSlots || iteration > 2) {
break;
}
int slotToUse = 2 - iteration;
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(mEvt.getBegin());
byte[] calBytes = MiBandDateConverter.calendarToRawBytes(calendar);
byte[] alarmMessage = new byte[]{
MiBandService.COMMAND_SET_TIMER,
(byte)(2-iteration),
(byte) slotToUse,
(byte) 1,
calBytes[0],
calBytes[1],