@@ -68,6 +68,8 @@ public class FirebaseInstallations implements FirebaseInstallationsApi {
68
68
private final ExecutorService backgroundExecutor ;
69
69
private final ExecutorService networkExecutor ;
70
70
71
+ private String cachedFid = null ;
72
+
71
73
@ GuardedBy ("lock" )
72
74
private final List <StateListener > listeners = new ArrayList <>();
73
75
@@ -215,7 +217,11 @@ String getName() {
215
217
public Task <String > getId () {
216
218
preConditionChecks ();
217
219
TaskCompletionSource <String > taskCompletionSource = new TaskCompletionSource <>();
218
- taskCompletionSource .trySetResult (doGetId ());
220
+ if (cachedFid != null ) {
221
+ taskCompletionSource .trySetResult (cachedFid );
222
+ } else {
223
+ taskCompletionSource .trySetResult (doGetId ());
224
+ }
219
225
return taskCompletionSource .getTask ();
220
226
}
221
227
@@ -454,6 +460,7 @@ private PersistedInstallationEntry registerFidWithServer(PersistedInstallationEn
454
460
455
461
switch (response .getResponseCode ()) {
456
462
case OK :
463
+ cachedFid = response .getFid ();
457
464
return prefs .withRegisteredFid (
458
465
response .getFid (),
459
466
response .getRefreshToken (),
@@ -493,6 +500,7 @@ private PersistedInstallationEntry fetchAuthTokenFromServer(
493
500
case AUTH_ERROR :
494
501
// The the server refused to generate a new auth token due to bad credentials, clear the
495
502
// FID to force the generation of a new one.
503
+ cachedFid = null ;
496
504
return prefs .withNoGeneratedFid ();
497
505
default :
498
506
throw new IOException ();
@@ -519,7 +527,7 @@ private Void deleteFirebaseInstallationId() throws FirebaseInstallationsExceptio
519
527
"Failed to delete a Firebase Installation." , Status .BAD_CONFIG );
520
528
}
521
529
}
522
-
530
+ cachedFid = null ;
523
531
insertOrUpdatePrefs (entry .withNoGeneratedFid ());
524
532
return null ;
525
533
}
0 commit comments