mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-26 14:21:16 +00:00
Fix crash in settings onApiChange call (fixes #1084)
This commit is contained in:
parent
49853d77fc
commit
533557c135
1 changed files with 15 additions and 13 deletions
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue