Fix race condition in alert service

This commit is contained in:
TebbeUbben 2019-01-19 05:36:02 +01:00
parent 437dee288e
commit f0a2307517

View file

@ -79,9 +79,11 @@ public class InsightAlertService extends Service implements InsightConnectionSer
} }
public void ignore(AlertType alertType) { public void ignore(AlertType alertType) {
synchronized ($alertLock) {
ignoreTimestamp = System.currentTimeMillis(); ignoreTimestamp = System.currentTimeMillis();
ignoreType = alertType; ignoreType = alertType;
} }
}
@Nullable @Nullable
@Override @Override
@ -132,7 +134,6 @@ public class InsightAlertService extends Service implements InsightConnectionSer
if (alertActivity != null && alert != null) if (alertActivity != null && alert != null)
new Handler(Looper.getMainLooper()).post(() -> alertActivity.update(alert)); new Handler(Looper.getMainLooper()).post(() -> alertActivity.update(alert));
} }
}
if (alert == null) { if (alert == null) {
stopAlerting(); stopAlerting();
if (connectionRequested) { if (connectionRequested) {
@ -154,6 +155,7 @@ public class InsightAlertService extends Service implements InsightConnectionSer
new Handler(Looper.getMainLooper()).post(() -> startActivity(intent)); new Handler(Looper.getMainLooper()).post(() -> startActivity(intent));
} }
} }
}
} catch (InterruptedException ignored) { } catch (InterruptedException ignored) {
connectionService.withdrawConnectionRequest(thread); connectionService.withdrawConnectionRequest(thread);
break; break;