call switchTo(Fore|Back)ground() outside synchronized block

This commit is contained in:
Daniel Gultsch 2018-07-16 21:35:52 +02:00
parent a4004904fe
commit 1764656ff9

View file

@ -1902,164 +1902,196 @@ public class XmppConnectionService extends Service {
} }
public void setOnConversationListChangedListener(OnConversationUpdate listener) { public void setOnConversationListChangedListener(OnConversationUpdate listener) {
final boolean remainingListeners;
synchronized (LISTENER_LOCK) { synchronized (LISTENER_LOCK) {
if (checkListeners()) { remainingListeners = checkListeners();
switchToForeground();
}
if (!this.mOnConversationUpdates.add(listener)) { if (!this.mOnConversationUpdates.add(listener)) {
Log.w(Config.LOGTAG,listener.getClass().getName()+" is already registered as ConversationListChangedListener"); Log.w(Config.LOGTAG,listener.getClass().getName()+" is already registered as ConversationListChangedListener");
} }
this.mNotificationService.setIsInForeground(this.mOnConversationUpdates.size() > 0); this.mNotificationService.setIsInForeground(this.mOnConversationUpdates.size() > 0);
} }
if (remainingListeners) {
switchToForeground();
}
} }
public void removeOnConversationListChangedListener(OnConversationUpdate listener) { public void removeOnConversationListChangedListener(OnConversationUpdate listener) {
final boolean remainingListeners;
synchronized (LISTENER_LOCK) { synchronized (LISTENER_LOCK) {
this.mOnConversationUpdates.remove(listener); this.mOnConversationUpdates.remove(listener);
this.mNotificationService.setIsInForeground(this.mOnConversationUpdates.size() > 0); this.mNotificationService.setIsInForeground(this.mOnConversationUpdates.size() > 0);
if (checkListeners()) { remainingListeners = checkListeners();
switchToBackground();
} }
if (remainingListeners) {
switchToBackground();
} }
} }
public void setOnShowErrorToastListener(OnShowErrorToast listener) { public void setOnShowErrorToastListener(OnShowErrorToast listener) {
final boolean remainingListeners;
synchronized (LISTENER_LOCK) { synchronized (LISTENER_LOCK) {
if (checkListeners()) { remainingListeners = checkListeners();
switchToForeground();
}
if (!this.mOnShowErrorToasts.add(listener)) { if (!this.mOnShowErrorToasts.add(listener)) {
Log.w(Config.LOGTAG,listener.getClass().getName()+" is already registered as OnShowErrorToastListener"); Log.w(Config.LOGTAG,listener.getClass().getName()+" is already registered as OnShowErrorToastListener");
} }
} }
if (remainingListeners) {
switchToForeground();
}
} }
public void removeOnShowErrorToastListener(OnShowErrorToast onShowErrorToast) { public void removeOnShowErrorToastListener(OnShowErrorToast onShowErrorToast) {
final boolean remainingListeners;
synchronized (LISTENER_LOCK) { synchronized (LISTENER_LOCK) {
this.mOnShowErrorToasts.remove(onShowErrorToast); this.mOnShowErrorToasts.remove(onShowErrorToast);
if (checkListeners()) { remainingListeners = checkListeners();
switchToBackground();
} }
if (remainingListeners) {
switchToBackground();
} }
} }
public void setOnAccountListChangedListener(OnAccountUpdate listener) { public void setOnAccountListChangedListener(OnAccountUpdate listener) {
final boolean remainingListeners;
synchronized (LISTENER_LOCK) { synchronized (LISTENER_LOCK) {
if (checkListeners()) { remainingListeners = checkListeners();
switchToForeground();
}
if (!this.mOnAccountUpdates.add(listener)) { if (!this.mOnAccountUpdates.add(listener)) {
Log.w(Config.LOGTAG,listener.getClass().getName()+" is already registered as OnAccountListChangedtListener"); Log.w(Config.LOGTAG,listener.getClass().getName()+" is already registered as OnAccountListChangedtListener");
} }
} }
if (remainingListeners) {
switchToForeground();
}
} }
public void removeOnAccountListChangedListener(OnAccountUpdate listener) { public void removeOnAccountListChangedListener(OnAccountUpdate listener) {
final boolean remainingListeners;
synchronized (LISTENER_LOCK) { synchronized (LISTENER_LOCK) {
this.mOnAccountUpdates.remove(listener); this.mOnAccountUpdates.remove(listener);
if (checkListeners()) { remainingListeners = checkListeners();
switchToBackground();
} }
if (remainingListeners) {
switchToBackground();
} }
} }
public void setOnCaptchaRequestedListener(OnCaptchaRequested listener) { public void setOnCaptchaRequestedListener(OnCaptchaRequested listener) {
final boolean remainingListeners;
synchronized (LISTENER_LOCK) { synchronized (LISTENER_LOCK) {
if (checkListeners()) { remainingListeners = checkListeners();
switchToForeground();
}
if (!this.mOnCaptchaRequested.add(listener)) { if (!this.mOnCaptchaRequested.add(listener)) {
Log.w(Config.LOGTAG,listener.getClass().getName()+" is already registered as OnCaptchaRequestListener"); Log.w(Config.LOGTAG,listener.getClass().getName()+" is already registered as OnCaptchaRequestListener");
} }
} }
if (remainingListeners) {
switchToForeground();
}
} }
public void removeOnCaptchaRequestedListener(OnCaptchaRequested listener) { public void removeOnCaptchaRequestedListener(OnCaptchaRequested listener) {
final boolean remainingListeners;
synchronized (LISTENER_LOCK) { synchronized (LISTENER_LOCK) {
this.mOnCaptchaRequested.remove(listener); this.mOnCaptchaRequested.remove(listener);
if (checkListeners()) { remainingListeners = checkListeners();
switchToBackground();
} }
if (remainingListeners) {
switchToBackground();
} }
} }
public void setOnRosterUpdateListener(final OnRosterUpdate listener) { public void setOnRosterUpdateListener(final OnRosterUpdate listener) {
final boolean remainingListeners;
synchronized (LISTENER_LOCK) { synchronized (LISTENER_LOCK) {
if (checkListeners()) { remainingListeners = checkListeners();
switchToForeground();
}
if (!this.mOnRosterUpdates.add(listener)) { if (!this.mOnRosterUpdates.add(listener)) {
Log.w(Config.LOGTAG,listener.getClass().getName()+" is already registered as OnRosterUpdateListener"); Log.w(Config.LOGTAG,listener.getClass().getName()+" is already registered as OnRosterUpdateListener");
} }
} }
if (remainingListeners) {
switchToForeground();
}
} }
public void removeOnRosterUpdateListener(final OnRosterUpdate listener) { public void removeOnRosterUpdateListener(final OnRosterUpdate listener) {
final boolean remainingListeners;
synchronized (LISTENER_LOCK) { synchronized (LISTENER_LOCK) {
this.mOnRosterUpdates.remove(listener); this.mOnRosterUpdates.remove(listener);
if (checkListeners()) { remainingListeners = checkListeners();
switchToBackground();
} }
if (remainingListeners) {
switchToBackground();
} }
} }
public void setOnUpdateBlocklistListener(final OnUpdateBlocklist listener) { public void setOnUpdateBlocklistListener(final OnUpdateBlocklist listener) {
final boolean remainingListeners;
synchronized (LISTENER_LOCK) { synchronized (LISTENER_LOCK) {
if (checkListeners()) { remainingListeners = checkListeners();
switchToForeground();
}
if (!this.mOnUpdateBlocklist.add(listener)) { if (!this.mOnUpdateBlocklist.add(listener)) {
Log.w(Config.LOGTAG,listener.getClass().getName()+" is already registered as OnUpdateBlocklistListener"); Log.w(Config.LOGTAG,listener.getClass().getName()+" is already registered as OnUpdateBlocklistListener");
} }
} }
if (remainingListeners) {
switchToForeground();
}
} }
public void removeOnUpdateBlocklistListener(final OnUpdateBlocklist listener) { public void removeOnUpdateBlocklistListener(final OnUpdateBlocklist listener) {
final boolean remainingListeners;
synchronized (LISTENER_LOCK) { synchronized (LISTENER_LOCK) {
this.mOnUpdateBlocklist.remove(listener); this.mOnUpdateBlocklist.remove(listener);
if (checkListeners()) { remainingListeners = checkListeners();
switchToBackground();
} }
if (remainingListeners) {
switchToBackground();
} }
} }
public void setOnKeyStatusUpdatedListener(final OnKeyStatusUpdated listener) { public void setOnKeyStatusUpdatedListener(final OnKeyStatusUpdated listener) {
final boolean remainingListeners;
synchronized (LISTENER_LOCK) { synchronized (LISTENER_LOCK) {
if (checkListeners()) { remainingListeners = checkListeners();
switchToForeground();
}
if (!this.mOnKeyStatusUpdated.add(listener)) { if (!this.mOnKeyStatusUpdated.add(listener)) {
Log.w(Config.LOGTAG,listener.getClass().getName()+" is already registered as OnKeyStatusUpdateListener"); Log.w(Config.LOGTAG,listener.getClass().getName()+" is already registered as OnKeyStatusUpdateListener");
} }
} }
if (remainingListeners) {
switchToForeground();
}
} }
public void removeOnNewKeysAvailableListener(final OnKeyStatusUpdated listener) { public void removeOnNewKeysAvailableListener(final OnKeyStatusUpdated listener) {
final boolean remainingListeners;
synchronized (LISTENER_LOCK) { synchronized (LISTENER_LOCK) {
this.mOnKeyStatusUpdated.remove(listener); this.mOnKeyStatusUpdated.remove(listener);
if (checkListeners()) { remainingListeners = checkListeners();
switchToBackground();
} }
if (remainingListeners) {
switchToBackground();
} }
} }
public void setOnMucRosterUpdateListener(OnMucRosterUpdate listener) { public void setOnMucRosterUpdateListener(OnMucRosterUpdate listener) {
final boolean remainingListeners;
synchronized (LISTENER_LOCK) { synchronized (LISTENER_LOCK) {
if (checkListeners()) { remainingListeners = checkListeners();
switchToForeground();
}
if (!this.mOnMucRosterUpdate.add(listener)) { if (!this.mOnMucRosterUpdate.add(listener)) {
Log.w(Config.LOGTAG,listener.getClass().getName()+" is already registered as OnMucRosterListener"); Log.w(Config.LOGTAG,listener.getClass().getName()+" is already registered as OnMucRosterListener");
} }
} }
if (remainingListeners) {
switchToForeground();
}
} }
public void removeOnMucRosterUpdateListener(final OnMucRosterUpdate listener) { public void removeOnMucRosterUpdateListener(final OnMucRosterUpdate listener) {
final boolean remainingListeners;
synchronized (LISTENER_LOCK) { synchronized (LISTENER_LOCK) {
this.mOnMucRosterUpdate.remove(listener); this.mOnMucRosterUpdate.remove(listener);
if (checkListeners()) { remainingListeners = checkListeners();
switchToBackground();
} }
if (remainingListeners) {
switchToBackground();
} }
} }