mirror of
https://github.com/moparisthebest/Conversations
synced 2024-11-28 03:32:15 -05:00
more safety checks for listener counts
This commit is contained in:
parent
71905ef2b4
commit
46e319b241
@ -209,11 +209,11 @@ public class XmppConnectionService extends Service {
|
||||
getNotificationService().updateErrorNotification();
|
||||
}
|
||||
};
|
||||
private Integer accountChangedListenerCount = 0;
|
||||
private int accountChangedListenerCount = 0;
|
||||
private OnRosterUpdate mOnRosterUpdate = null;
|
||||
private Integer rosterChangedListenerCount = 0;
|
||||
private int rosterChangedListenerCount = 0;
|
||||
private OnMucRosterUpdate mOnMucRosterUpdate = null;
|
||||
private Integer mucRosterChangedListenerCount = 0;
|
||||
private int mucRosterChangedListenerCount = 0;
|
||||
private SecureRandom mRandom;
|
||||
private FileObserver fileObserver = new FileObserver(
|
||||
FileBackend.getConversationsImageDirectory()) {
|
||||
@ -1095,72 +1095,21 @@ public class XmppConnectionService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
private void removeStaleListeners() {
|
||||
boolean removedListener = false;
|
||||
synchronized (this.convChangedListenerCount) {
|
||||
if (this.mOnConversationUpdate != null) {
|
||||
this.mOnConversationUpdate = null;
|
||||
this.convChangedListenerCount = 0;
|
||||
this.mNotificationService.setIsInForeground(false);
|
||||
removedListener = true;
|
||||
}
|
||||
}
|
||||
synchronized (this.accountChangedListenerCount) {
|
||||
if (this.mOnAccountUpdate != null) {
|
||||
this.mOnAccountUpdate = null;
|
||||
this.accountChangedListenerCount = 0;
|
||||
removedListener = true;
|
||||
}
|
||||
}
|
||||
synchronized (this.rosterChangedListenerCount) {
|
||||
if (this.mOnRosterUpdate != null) {
|
||||
this.mOnRosterUpdate = null;
|
||||
this.rosterChangedListenerCount = 0;
|
||||
removedListener = true;
|
||||
}
|
||||
}
|
||||
synchronized (this.mucRosterChangedListenerCount) {
|
||||
if (this.mOnMucRosterUpdate != null) {
|
||||
this.mOnMucRosterUpdate = null;
|
||||
this.mucRosterChangedListenerCount = 0;
|
||||
removedListener = true;
|
||||
}
|
||||
}
|
||||
if (removedListener) {
|
||||
final String msg = "removed stale listeners";
|
||||
Log.d(Config.LOGTAG, msg);
|
||||
checkListeners();
|
||||
try {
|
||||
OutputStream os = openFileOutput("stacktrace.txt", MODE_PRIVATE);
|
||||
os.write(msg.getBytes());
|
||||
os.flush();
|
||||
os.close();
|
||||
} catch (final FileNotFoundException ignored) {
|
||||
|
||||
} catch (final IOException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setOnConversationListChangedListener(
|
||||
OnConversationUpdate listener) {
|
||||
/*if (!isScreenOn()) {
|
||||
Log.d(Config.LOGTAG,
|
||||
"ignoring setOnConversationListChangedListener");
|
||||
return;
|
||||
}*/
|
||||
synchronized (this.convChangedListenerCount) {
|
||||
public void setOnConversationListChangedListener(OnConversationUpdate listener) {
|
||||
synchronized (this) {
|
||||
if (checkListeners()) {
|
||||
switchToForeground();
|
||||
}
|
||||
this.mOnConversationUpdate = listener;
|
||||
this.mNotificationService.setIsInForeground(true);
|
||||
if (this.convChangedListenerCount < 2) {
|
||||
this.convChangedListenerCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeOnConversationListChangedListener() {
|
||||
synchronized (this.convChangedListenerCount) {
|
||||
synchronized (this) {
|
||||
this.convChangedListenerCount--;
|
||||
if (this.convChangedListenerCount <= 0) {
|
||||
this.convChangedListenerCount = 0;
|
||||
@ -1174,21 +1123,19 @@ public class XmppConnectionService extends Service {
|
||||
}
|
||||
|
||||
public void setOnAccountListChangedListener(OnAccountUpdate listener) {
|
||||
/*if (!isScreenOn()) {
|
||||
Log.d(Config.LOGTAG, "ignoring setOnAccountListChangedListener");
|
||||
return;
|
||||
}*/
|
||||
synchronized (this.accountChangedListenerCount) {
|
||||
synchronized (this) {
|
||||
if (checkListeners()) {
|
||||
switchToForeground();
|
||||
}
|
||||
this.mOnAccountUpdate = listener;
|
||||
if (this.accountChangedListenerCount < 2) {
|
||||
this.accountChangedListenerCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeOnAccountListChangedListener() {
|
||||
synchronized (this.accountChangedListenerCount) {
|
||||
synchronized (this) {
|
||||
this.accountChangedListenerCount--;
|
||||
if (this.accountChangedListenerCount <= 0) {
|
||||
this.mOnAccountUpdate = null;
|
||||
@ -1201,21 +1148,19 @@ public class XmppConnectionService extends Service {
|
||||
}
|
||||
|
||||
public void setOnRosterUpdateListener(OnRosterUpdate listener) {
|
||||
/*if (!isScreenOn()) {
|
||||
Log.d(Config.LOGTAG, "ignoring setOnRosterUpdateListener");
|
||||
return;
|
||||
}*/
|
||||
synchronized (this.rosterChangedListenerCount) {
|
||||
synchronized (this) {
|
||||
if (checkListeners()) {
|
||||
switchToForeground();
|
||||
}
|
||||
this.mOnRosterUpdate = listener;
|
||||
if (this.rosterChangedListenerCount < 2) {
|
||||
this.rosterChangedListenerCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeOnRosterUpdateListener() {
|
||||
synchronized (this.rosterChangedListenerCount) {
|
||||
synchronized (this) {
|
||||
this.rosterChangedListenerCount--;
|
||||
if (this.rosterChangedListenerCount <= 0) {
|
||||
this.rosterChangedListenerCount = 0;
|
||||
@ -1228,17 +1173,19 @@ public class XmppConnectionService extends Service {
|
||||
}
|
||||
|
||||
public void setOnMucRosterUpdateListener(OnMucRosterUpdate listener) {
|
||||
synchronized (this.mucRosterChangedListenerCount) {
|
||||
synchronized (this) {
|
||||
if (checkListeners()) {
|
||||
switchToForeground();
|
||||
}
|
||||
this.mOnMucRosterUpdate = listener;
|
||||
if (this.mucRosterChangedListenerCount < 2) {
|
||||
this.mucRosterChangedListenerCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeOnMucRosterUpdateListener() {
|
||||
synchronized (this.mucRosterChangedListenerCount) {
|
||||
synchronized (this) {
|
||||
this.mucRosterChangedListenerCount--;
|
||||
if (this.mucRosterChangedListenerCount <= 0) {
|
||||
this.mucRosterChangedListenerCount = 0;
|
||||
@ -1280,12 +1227,6 @@ public class XmppConnectionService extends Service {
|
||||
Log.d(Config.LOGTAG, "app switched into background");
|
||||
}
|
||||
|
||||
private boolean isScreenOn() {
|
||||
PowerManager pm = (PowerManager) this
|
||||
.getSystemService(Context.POWER_SERVICE);
|
||||
return pm.isScreenOn();
|
||||
}
|
||||
|
||||
public void connectMultiModeConversations(Account account) {
|
||||
List<Conversation> conversations = getConversations();
|
||||
for (Conversation conversation : conversations) {
|
||||
|
Loading…
Reference in New Issue
Block a user