39
39
import com .google .android .gms .auth .api .signin .GoogleSignIn ;
40
40
import com .google .android .gms .auth .api .signin .GoogleSignInAccount ;
41
41
import com .google .android .gms .auth .api .signin .GoogleSignInOptions ;
42
+ import com .google .android .gms .common .ConnectionResult ;
43
+ import com .google .android .gms .common .GoogleApiAvailability ;
42
44
import com .google .android .gms .common .api .ApiException ;
43
45
import com .google .android .gms .common .api .CommonStatusCodes ;
46
+ import com .google .android .gms .common .api .GoogleApi ;
44
47
import com .google .android .gms .common .api .Scope ;
45
48
import com .google .android .gms .tasks .Continuation ;
46
49
import com .google .android .gms .tasks .Task ;
@@ -340,6 +343,12 @@ public Task<AuthResult> silentSignIn(@NonNull Context context,
340
343
.getParcelable (ExtraConstants .GOOGLE_SIGN_IN_OPTIONS );
341
344
}
342
345
346
+ // If Play services are not available we can't attempt to use the credentials client.
347
+ if (!GoogleApiUtils .isPlayServicesAvailable (context )) {
348
+ return Tasks .forException (
349
+ new FirebaseUiException (ErrorCodes .PLAY_SERVICES_UPDATE_CANCELLED ));
350
+ }
351
+
343
352
return GoogleApiUtils .getCredentialsClient (context )
344
353
.request (new CredentialRequest .Builder ()
345
354
// We can support both email and Google at the same time here because they
@@ -392,8 +401,16 @@ public Task<AuthResult> then(
392
401
*/
393
402
@ NonNull
394
403
public Task <Void > signOut (@ NonNull Context context ) {
395
- Task <Void > maybeDisableAutoSignIn = GoogleApiUtils .getCredentialsClient (context )
396
- .disableAutoSignIn ()
404
+ boolean playServicesAvailable = GoogleApiUtils .isPlayServicesAvailable (context );
405
+ if (!playServicesAvailable ) {
406
+ Log .w (TAG , "Google Play services not available during signOut" );
407
+ }
408
+
409
+ Task <Void > maybeDisableAutoSignIn = playServicesAvailable
410
+ ? GoogleApiUtils .getCredentialsClient (context ).disableAutoSignIn ()
411
+ : Tasks .forResult ((Void ) null );
412
+
413
+ maybeDisableAutoSignIn
397
414
.continueWith (new Continuation <Void , Void >() {
398
415
@ Override
399
416
public Void then (@ NonNull Task <Void > task ) {
@@ -434,7 +451,7 @@ public Void then(@NonNull Task<Void> task) {
434
451
* @param context the calling {@link Context}.
435
452
*/
436
453
@ NonNull
437
- public Task <Void > delete (@ NonNull Context context ) {
454
+ public Task <Void > delete (@ NonNull final Context context ) {
438
455
final FirebaseUser currentUser = mAuth .getCurrentUser ();
439
456
if (currentUser == null ) {
440
457
return Tasks .forException (new FirebaseAuthInvalidUserException (
@@ -443,14 +460,19 @@ public Task<Void> delete(@NonNull Context context) {
443
460
}
444
461
445
462
final List <Credential > credentials = getCredentialsFromFirebaseUser (currentUser );
446
- final CredentialsClient client = GoogleApiUtils .getCredentialsClient (context );
447
463
448
464
// Ensure the order in which tasks are executed properly destructures the user.
449
465
return signOutIdps (context ).continueWithTask (new Continuation <Void , Task <Void >>() {
450
466
@ Override
451
467
public Task <Void > then (@ NonNull Task <Void > task ) {
452
468
task .getResult (); // Propagate exception if there was one
453
469
470
+ if (!GoogleApiUtils .isPlayServicesAvailable (context )) {
471
+ Log .w (TAG , "Google Play services not available during delete" );
472
+ return Tasks .forResult ((Void ) null );
473
+ }
474
+
475
+ final CredentialsClient client = GoogleApiUtils .getCredentialsClient (context );
454
476
List <Task <?>> credentialTasks = new ArrayList <>();
455
477
for (Credential credential : credentials ) {
456
478
credentialTasks .add (client .delete (credential ));
@@ -516,7 +538,11 @@ private Task<Void> signOutIdps(@NonNull Context context) {
516
538
if (ProviderAvailability .IS_FACEBOOK_AVAILABLE ) {
517
539
LoginManager .getInstance ().logOut ();
518
540
}
519
- return GoogleSignIn .getClient (context , GoogleSignInOptions .DEFAULT_SIGN_IN ).signOut ();
541
+ if (GoogleApiUtils .isPlayServicesAvailable (context )) {
542
+ return GoogleSignIn .getClient (context , GoogleSignInOptions .DEFAULT_SIGN_IN ).signOut ();
543
+ } else {
544
+ return Tasks .forResult ((Void ) null );
545
+ }
520
546
}
521
547
522
548
/**
@@ -732,6 +758,17 @@ public EmailBuilder setForceSameDevice() {
732
758
return this ;
733
759
}
734
760
761
+ /**
762
+ * Sets a default sign in email, if the given email has been registered before, then
763
+ * it will ask the user for password, if the given email it's not registered, then
764
+ * it starts signing up the default email.
765
+ */
766
+ @ NonNull
767
+ public EmailBuilder setDefaultEmail (String email ) {
768
+ getParams ().putString (ExtraConstants .DEFAULT_EMAIL , email );
769
+ return this ;
770
+ }
771
+
735
772
@ Override
736
773
public IdpConfig build () {
737
774
if (super .mProviderId .equals (EMAIL_LINK_PROVIDER )) {
0 commit comments