File tree 5 files changed +36
-11
lines changed
firebase-installations/src
androidTest/java/com/google/firebase/installations
main/java/com/google/firebase/installations
5 files changed +36
-11
lines changed Original file line number Diff line number Diff line change @@ -386,7 +386,7 @@ public void testGetAuthToken_PersistedFidError_failure() throws Exception {
386
386
.isInstanceOf (FirebaseInstallationsException .class );
387
387
assertWithMessage ("Exception status doesn't match" )
388
388
.that (((FirebaseInstallationsException ) expected .getCause ()).getStatus ())
389
- .isEqualTo (FirebaseInstallationsException .Status .SDK_INTERNAL_ERROR );
389
+ .isEqualTo (FirebaseInstallationsException .Status .CLIENT_ERROR );
390
390
}
391
391
}
392
392
Original file line number Diff line number Diff line change @@ -197,6 +197,19 @@ private void triggerOnStateReached(PersistedFidEntry persistedFidEntry) {
197
197
}
198
198
}
199
199
200
+ private void triggerOnException (PersistedFidEntry persistedFidEntry , Exception exception ) {
201
+ synchronized (lock ) {
202
+ Iterator <StateListener > it = listeners .iterator ();
203
+ while (it .hasNext ()) {
204
+ StateListener l = it .next ();
205
+ boolean doneListening = l .onException (persistedFidEntry , exception );
206
+ if (doneListening ) {
207
+ it .remove ();
208
+ }
209
+ }
210
+ }
211
+ }
212
+
200
213
private final void doRegistration () {
201
214
try {
202
215
PersistedFidEntry persistedFidEntry = persistedFid .readPersistedFidEntryValue ();
@@ -248,7 +261,7 @@ private final void doRegistration() {
248
261
.setRegistrationStatus (RegistrationStatus .REGISTER_ERROR )
249
262
.build ();
250
263
persistedFid .insertOrUpdatePersistedFidEntry (errorFidEntry );
251
- triggerOnStateReached (errorFidEntry );
264
+ triggerOnException (errorFidEntry , e );
252
265
}
253
266
}
254
267
Original file line number Diff line number Diff line change @@ -42,12 +42,13 @@ public boolean onStateReached(
42
42
.build ());
43
43
return true ;
44
44
}
45
+ return false ;
46
+ }
45
47
48
+ @ Override
49
+ public boolean onException (PersistedFidEntry persistedFidEntry , Exception exception ) {
46
50
if (persistedFidEntry .isErrored ()) {
47
- resultTaskCompletionSource .setException (
48
- new FirebaseInstallationsException (
49
- "Firebase Installation is not registered." ,
50
- FirebaseInstallationsException .Status .SDK_INTERNAL_ERROR ));
51
+ resultTaskCompletionSource .trySetException (exception );
51
52
return true ;
52
53
}
53
54
return false ;
Original file line number Diff line number Diff line change @@ -27,15 +27,16 @@ public GetIdListener(TaskCompletionSource<String> taskCompletionSource) {
27
27
@ Override
28
28
public boolean onStateReached (PersistedFidEntry persistedFidEntry , boolean unused ) {
29
29
if (persistedFidEntry .isUnregistered () || persistedFidEntry .isRegistered ()) {
30
- taskCompletionSource .setResult (persistedFidEntry .getFirebaseInstallationId ());
30
+ taskCompletionSource .trySetResult (persistedFidEntry .getFirebaseInstallationId ());
31
31
return true ;
32
32
}
33
+ return false ;
34
+ }
33
35
36
+ @ Override
37
+ public boolean onException (PersistedFidEntry persistedFidEntry , Exception exception ) {
34
38
if (persistedFidEntry .isErrored ()) {
35
- taskCompletionSource .setException (
36
- new FirebaseInstallationsException (
37
- "Failed to update client side cache." ,
38
- FirebaseInstallationsException .Status .CLIENT_ERROR ));
39
+ taskCompletionSource .trySetException (exception );
39
40
return true ;
40
41
}
41
42
return false ;
Original file line number Diff line number Diff line change 17
17
import com .google .firebase .installations .local .PersistedFidEntry ;
18
18
19
19
interface StateListener {
20
+ /**
21
+ * Returns {@code true} if the defined {@link PersistedFidEntry} state is reached, {@code false}
22
+ * otherwise.
23
+ */
20
24
boolean onStateReached (PersistedFidEntry persistedFidEntry , boolean shouldRefreshAuthToken );
25
+
26
+ /**
27
+ * Returns {@code true} if an exception is thrown while registering a Firebase Installation,
28
+ * {@code false} otherwise.
29
+ */
30
+ boolean onException (PersistedFidEntry persistedFidEntry , Exception exception );
21
31
}
You can’t perform that action at this time.
0 commit comments