1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-22 12:21:15 +00:00

Fix crash in settings onApiChange call (fixes #1084)

This commit is contained in:
Felix Ableitner 2018-05-10 19:13:49 +02:00 committed by Audrius Butkevicius
parent 49853d77fc
commit 533557c135

View file

@ -93,6 +93,7 @@ public class SyncthingService extends Service {
private EventProcessor mEventProcessor;
private DeviceStateHolder mDeviceStateHolder;
private SyncthingRunnable mSyncthingRunnable;
private Handler mHandler;
private final HashSet<OnApiChangeListener> mOnApiChangeListeners = new HashSet<>();
private final SyncthingServiceBinder mBinder = new SyncthingServiceBinder(this);
@ -180,7 +181,8 @@ public class SyncthingService extends Service {
super.onCreate();
PRNGFixes.apply();
((SyncthingApp) getApplication()).component().inject(this);
mHandler = new Handler();
mDeviceStateHolder = new DeviceStateHolder(SyncthingService.this, this::updateState);
updateState();
mNotificationHandler.updatePersistentNotification(this);
@ -354,21 +356,21 @@ public class SyncthingService extends Service {
/**
* Called to notifiy listeners of an API change.
*
* Must only be called from SyncthingService or {@link RestApi} on the main thread.
*/
private void onApiChange(State newState) {
mCurrentState = newState;
mNotificationHandler.updatePersistentNotification(this);
for (Iterator<OnApiChangeListener> i = mOnApiChangeListeners.iterator();
i.hasNext(); ) {
OnApiChangeListener listener = i.next();
if (listener != null) {
listener.onApiChange(mCurrentState);
} else {
i.remove();
mHandler.post(() -> {
mCurrentState = newState;
mNotificationHandler.updatePersistentNotification(this);
for (Iterator<OnApiChangeListener> i = mOnApiChangeListeners.iterator();
i.hasNext(); ) {
OnApiChangeListener listener = i.next();
if (listener != null) {
listener.onApiChange(mCurrentState);
} else {
i.remove();
}
}
}
});
}
public URL getWebGuiUrl() {