15
15
package com .google .firebase .appdistribution ;
16
16
17
17
import static com .google .firebase .appdistribution .FirebaseAppDistributionException .Status .AUTHENTICATION_CANCELED ;
18
- import static com .google .firebase .appdistribution .FirebaseAppDistributionException .Status .AUTHENTICATION_FAILURE ;
19
18
import static com .google .firebase .appdistribution .TaskUtils .combineWithResultOf ;
20
19
import static com .google .firebase .appdistribution .TaskUtils .safeSetTaskException ;
21
20
import static com .google .firebase .appdistribution .TaskUtils .safeSetTaskResult ;
29
28
import androidx .annotation .NonNull ;
30
29
import androidx .annotation .VisibleForTesting ;
31
30
import androidx .browser .customtabs .CustomTabsIntent ;
31
+ import com .google .android .gms .tasks .OnFailureListener ;
32
32
import com .google .android .gms .tasks .Task ;
33
33
import com .google .android .gms .tasks .TaskCompletionSource ;
34
34
import com .google .android .gms .tasks .Tasks ;
35
35
import com .google .firebase .FirebaseApp ;
36
36
import com .google .firebase .appdistribution .Constants .ErrorMessages ;
37
+ import com .google .firebase .appdistribution .FirebaseAppDistributionException .Status ;
37
38
import com .google .firebase .appdistribution .internal .InstallActivity ;
38
39
import com .google .firebase .appdistribution .internal .LogWrapper ;
39
40
import com .google .firebase .appdistribution .internal .SignInResultActivity ;
@@ -120,7 +121,6 @@ void onActivityStarted(Activity activity) {
120
121
121
122
@ NonNull
122
123
public Task <Void > signInTester () {
123
-
124
124
if (signInStorage .getSignInStatus ()) {
125
125
LogWrapper .getInstance ().v (TAG + "Tester is already signed in." );
126
126
return Tasks .forResult (null );
@@ -140,6 +140,7 @@ public Task<Void> signInTester() {
140
140
firebaseInstallationsApiProvider
141
141
.get ()
142
142
.getId ()
143
+ .addOnFailureListener (handleTaskFailure (ErrorMessages .AUTHENTICATION_ERROR , Status .AUTHENTICATION_FAILURE ))
143
144
.onSuccessTask (combineWithResultOf (lifecycleNotifier .getForegroundActivity ()))
144
145
.addOnSuccessListener (
145
146
fidAndActivity -> {
@@ -148,18 +149,22 @@ public Task<Void> signInTester() {
148
149
hasBeenSentToBrowserForCurrentTask = true ;
149
150
}
150
151
})
151
- .addOnFailureListener (
152
- e -> {
153
- LogWrapper .getInstance ().e (TAG + "Fid retrieval failed." , e );
154
- setSignInTaskCompletionError (
155
- new FirebaseAppDistributionException (
156
- ErrorMessages .AUTHENTICATION_ERROR , AUTHENTICATION_FAILURE , e ));
157
- });
152
+ // No failures expected here, since getForegroundActivity() will wait indefinitely for a
153
+ // foreground activity, but catch any unexpected failures to be safe.
154
+ .addOnFailureListener (handleTaskFailure (ErrorMessages .UNKNOWN_ERROR , Status .UNKNOWN ));
158
155
159
156
return signInTaskCompletionSource .getTask ();
160
157
}
161
158
}
162
159
160
+ private OnFailureListener handleTaskFailure (String message , Status status ) {
161
+ return e -> {
162
+ LogWrapper .getInstance ().e (TAG + message , e );
163
+ setSignInTaskCompletionError (
164
+ new FirebaseAppDistributionException (message , status , e ));
165
+ };
166
+ }
167
+
163
168
private boolean awaitingResultFromBrowser () {
164
169
synchronized (signInTaskLock ) {
165
170
return signInTaskCompletionSource != null
@@ -168,15 +173,15 @@ private boolean awaitingResultFromBrowser() {
168
173
}
169
174
}
170
175
171
- private void setSuccessfulSignInResult ( ) {
176
+ private void setSignInTaskCompletionError ( FirebaseAppDistributionException e ) {
172
177
synchronized (signInTaskLock ) {
173
- safeSetTaskResult (signInTaskCompletionSource , null );
178
+ safeSetTaskException (signInTaskCompletionSource , e );
174
179
}
175
180
}
176
181
177
- private void setSignInTaskCompletionError ( FirebaseAppDistributionException e ) {
182
+ private void setSuccessfulSignInResult ( ) {
178
183
synchronized (signInTaskLock ) {
179
- safeSetTaskException (signInTaskCompletionSource , e );
184
+ safeSetTaskResult (signInTaskCompletionSource , null );
180
185
}
181
186
}
182
187
0 commit comments