35
35
import java .util .concurrent .ThreadPoolExecutor ;
36
36
import java .util .concurrent .TimeUnit ;
37
37
38
- /**
39
- * Background task to perform sync operations with the Firebase backend using a bg thread
40
- */
38
+ /** Background task to perform sync operations with the Firebase backend using a bg thread */
41
39
class SyncTask implements Runnable {
42
40
43
41
private final long nextDelaySeconds ;
@@ -115,9 +113,9 @@ public void run() {
115
113
* Refreshes the token if needed
116
114
*
117
115
* @return {@code true} if successful, {@code false} if needs to be rescheduled.
118
- * @throws IOException on a hard failure that should not be retried. Hard failures are
119
- * failures except {@link GmsRpc#ERROR_SERVICE_NOT_AVAILABLE} and
120
- * {@link GmsRpc#ERROR_INTERNAL_SERVER_ERROR}
116
+ * @throws IOException on a hard failure that should not be retried. Hard failures are failures
117
+ * except {@link GmsRpc#ERROR_SERVICE_NOT_AVAILABLE} and {@link
118
+ * GmsRpc#ERROR_INTERNAL_SERVER_ERROR}
121
119
*/
122
120
@ VisibleForTesting
123
121
boolean maybeRefreshToken () throws IOException {
@@ -162,10 +160,8 @@ boolean isDeviceConnected() {
162
160
@ VisibleForTesting
163
161
static class ConnectivityChangeReceiver extends BroadcastReceiver {
164
162
165
- @ Nullable
166
- private SyncTask task ; // task is set to null after it has been fired.
167
- @ Nullable
168
- private Context context ;
163
+ @ Nullable private SyncTask task ; // task is set to null after it has been fired.
164
+ @ Nullable private Context context ;
169
165
170
166
public ConnectivityChangeReceiver (SyncTask task ) {
171
167
this .task = task ;
@@ -176,8 +172,10 @@ public void registerReceiver() {
176
172
Log .d (TAG , "Connectivity change received registered" );
177
173
}
178
174
IntentFilter intentFilter = new IntentFilter (ConnectivityManager .CONNECTIVITY_ACTION );
179
- context = task .getContext ();
180
- context .registerReceiver (this , intentFilter );
175
+ if (task != null ) {
176
+ context = task .getContext ();
177
+ context .registerReceiver (this , intentFilter );
178
+ }
181
179
}
182
180
183
181
@ Override
@@ -197,8 +195,8 @@ public void onReceive(Context context, Intent intent) {
197
195
Log .d (TAG , "Connectivity changed. Starting background sync." );
198
196
}
199
197
task .firebaseMessaging .enqueueTaskWithDelaySeconds (task , 0 );
200
- if (context != null ) {
201
- context .unregisterReceiver (this );
198
+ if (this . context != null ) {
199
+ this . context .unregisterReceiver (this );
202
200
task = null ;
203
201
}
204
202
}
0 commit comments