Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions Parse/src/main/java/com/parse/ParseCommandCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.concurrent.Callable;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -93,13 +94,30 @@ public static int getPendingCount() {
ConnectivityNotifier.ConnectivityListener listener = new ConnectivityNotifier.ConnectivityListener() {
@Override
public void networkConnectivityStatusChanged(Context context, Intent intent) {
boolean connectionLost =
final boolean connectionLost =
intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
if (connectionLost) {
setConnected(false);
} else {
setConnected(ConnectivityNotifier.isConnected(context));
}
final boolean isConnected = ConnectivityNotifier.isConnected(context);

/*
Hack to avoid blocking the UI thread with disk I/O

setConnected uses the same lock we use for synchronizing disk I/O, so there's a possibility
that we can block the UI thread on disk I/O, so we're going to bump the lock usage to a
different thread.

TODO(grantland): Convert to TaskQueue, similar to ParsePinningEventuallyQueue
*/
Task.call(new Callable<Void>() {
@Override
public Void call() throws Exception {
if (connectionLost) {
setConnected(false);
} else {
setConnected(isConnected);
}
return null;
}
}, ParseExecutors.io());
}
};

Expand Down