File tree Expand file tree Collapse file tree 1 file changed +24
-6
lines changed
Parse/src/main/java/com/parse Expand file tree Collapse file tree 1 file changed +24
-6
lines changed Original file line number Diff line number Diff line change 2222import java .io .UnsupportedEncodingException ;
2323import java .util .Arrays ;
2424import java .util .HashMap ;
25+ import java .util .concurrent .Callable ;
2526import java .util .logging .Level ;
2627import java .util .logging .Logger ;
2728
@@ -93,13 +94,30 @@ public static int getPendingCount() {
9394 ConnectivityNotifier .ConnectivityListener listener = new ConnectivityNotifier .ConnectivityListener () {
9495 @ Override
9596 public void networkConnectivityStatusChanged (Context context , Intent intent ) {
96- boolean connectionLost =
97+ final boolean connectionLost =
9798 intent .getBooleanExtra (ConnectivityManager .EXTRA_NO_CONNECTIVITY , false );
98- if (connectionLost ) {
99- setConnected (false );
100- } else {
101- setConnected (ConnectivityNotifier .isConnected (context ));
102- }
99+ final boolean isConnected = ConnectivityNotifier .isConnected (context );
100+
101+ /*
102+ Hack to avoid blocking the UI thread with disk I/O
103+
104+ setConnected uses the same lock we use for synchronizing disk I/O, so there's a possibility
105+ that we can block the UI thread on disk I/O, so we're going to bump the lock usage to a
106+ different thread.
107+
108+ TODO(grantland): Convert to TaskQueue, similar to ParsePinningEventuallyQueue
109+ */
110+ Task .call (new Callable <Void >() {
111+ @ Override
112+ public Void call () throws Exception {
113+ if (connectionLost ) {
114+ setConnected (false );
115+ } else {
116+ setConnected (isConnected );
117+ }
118+ return null ;
119+ }
120+ }, ParseExecutors .io ());
103121 }
104122 };
105123
You can’t perform that action at this time.
0 commit comments