/**
  * Called to notifiy listeners of an API change.
  *
  * <p>Must only be called from SyncthingService or {@link RestApi} on the main thread.
  */
 private void onApiChange() {
   for (Iterator<OnApiChangeListener> i = mOnApiChangeListeners.iterator(); i.hasNext(); ) {
     OnApiChangeListener listener = i.next();
     if (listener != null) {
       listener.onApiChange(mCurrentState);
     } else {
       i.remove();
     }
   }
 }
 /**
  * Register a listener for the syncthing API state changing.
  *
  * <p>The listener is called immediately with the current state, and again whenever the state
  * changes.
  */
 public void registerOnApiChangeListener(OnApiChangeListener listener) {
   listener.onApiChange((mApi != null) ? mApi.isApiAvailable() : false);
   mOnApiAvailableListeners.add(new WeakReference<OnApiChangeListener>(listener));
 }
 /**
  * Register a listener for the syncthing API state changing.
  *
  * <p>The listener is called immediately with the current state, and again whenever the state
  * changes. The call is always from the GUI thread.
  *
  * @see #unregisterOnApiChangeListener
  */
 public void registerOnApiChangeListener(OnApiChangeListener listener) {
   // Make sure we don't send an invalid state or syncthing might show a "disabled" message
   // when it's just starting up.
   listener.onApiChange(mCurrentState);
   mOnApiChangeListeners.add(listener);
 }