File tree 1 file changed +24
-6
lines changed
Parse/src/main/java/com/parse
1 file changed +24
-6
lines changed Original file line number Diff line number Diff line change 22
22
import java .io .UnsupportedEncodingException ;
23
23
import java .util .Arrays ;
24
24
import java .util .HashMap ;
25
+ import java .util .concurrent .Callable ;
25
26
import java .util .logging .Level ;
26
27
import java .util .logging .Logger ;
27
28
@@ -93,13 +94,30 @@ public static int getPendingCount() {
93
94
ConnectivityNotifier .ConnectivityListener listener = new ConnectivityNotifier .ConnectivityListener () {
94
95
@ Override
95
96
public void networkConnectivityStatusChanged (Context context , Intent intent ) {
96
- boolean connectionLost =
97
+ final boolean connectionLost =
97
98
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 ());
103
121
}
104
122
};
105
123
You can’t perform that action at this time.
0 commit comments