@@ -231,7 +231,7 @@ public Task<String> getId() {
231
231
}
232
232
233
233
Task <String > task = addGetIdListener ();
234
- backgroundExecutor .execute (this :: doGetId );
234
+ backgroundExecutor .execute (() -> doRegistrationInternal ( false ) );
235
235
return task ;
236
236
}
237
237
@@ -248,11 +248,7 @@ public Task<String> getId() {
248
248
public Task <InstallationTokenResult > getToken (boolean forceRefresh ) {
249
249
preConditionChecks ();
250
250
Task <InstallationTokenResult > task = addGetAuthTokenListener ();
251
- if (forceRefresh ) {
252
- backgroundExecutor .execute (this ::doGetAuthTokenForceRefresh );
253
- } else {
254
- backgroundExecutor .execute (this ::doGetAuthTokenWithoutForceRefresh );
255
- }
251
+ backgroundExecutor .execute (() -> doRegistrationInternal (forceRefresh ));
256
252
return task ;
257
253
}
258
254
@@ -270,20 +266,22 @@ public Task<Void> delete() {
270
266
private Task <String > addGetIdListener () {
271
267
TaskCompletionSource <String > taskCompletionSource = new TaskCompletionSource <>();
272
268
StateListener l = new GetIdListener (taskCompletionSource );
273
- synchronized (lock ) {
274
- listeners .add (l );
275
- }
269
+ addStateListeners (l );
276
270
return taskCompletionSource .getTask ();
277
271
}
278
272
279
273
private Task <InstallationTokenResult > addGetAuthTokenListener () {
280
274
TaskCompletionSource <InstallationTokenResult > taskCompletionSource =
281
275
new TaskCompletionSource <>();
282
276
StateListener l = new GetAuthTokenListener (utils , taskCompletionSource );
277
+ addStateListeners (l );
278
+ return taskCompletionSource .getTask ();
279
+ }
280
+
281
+ private void addStateListeners (StateListener l ) {
283
282
synchronized (lock ) {
284
283
listeners .add (l );
285
284
}
286
- return taskCompletionSource .getTask ();
287
285
}
288
286
289
287
private void triggerOnStateReached (PersistedInstallationEntry persistedInstallationEntry ) {
@@ -320,18 +318,6 @@ private synchronized String getCacheFid() {
320
318
return cachedFid ;
321
319
}
322
320
323
- private final void doGetAuthTokenForceRefresh () {
324
- doRegistrationInternal (true );
325
- }
326
-
327
- private final void doGetAuthTokenWithoutForceRefresh () {
328
- doRegistrationInternal (false );
329
- }
330
-
331
- private final void doGetId () {
332
- doRegistrationInternal (false );
333
- }
334
-
335
321
/**
336
322
* Logic for handling get id and the two forms of get auth token. This handles all the work,
337
323
* including creating a new FID if one hasn't been generated yet and making the network calls to
0 commit comments