3939import com .google .android .gms .auth .api .signin .GoogleSignIn ;
4040import com .google .android .gms .auth .api .signin .GoogleSignInAccount ;
4141import com .google .android .gms .auth .api .signin .GoogleSignInOptions ;
42+ import com .google .android .gms .common .ConnectionResult ;
43+ import com .google .android .gms .common .GoogleApiAvailability ;
4244import com .google .android .gms .common .api .ApiException ;
4345import com .google .android .gms .common .api .CommonStatusCodes ;
46+ import com .google .android .gms .common .api .GoogleApi ;
4447import com .google .android .gms .common .api .Scope ;
4548import com .google .android .gms .tasks .Continuation ;
4649import com .google .android .gms .tasks .Task ;
@@ -340,6 +343,12 @@ public Task<AuthResult> silentSignIn(@NonNull Context context,
340343 .getParcelable (ExtraConstants .GOOGLE_SIGN_IN_OPTIONS );
341344 }
342345
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+
343352 return GoogleApiUtils .getCredentialsClient (context )
344353 .request (new CredentialRequest .Builder ()
345354 // We can support both email and Google at the same time here because they
@@ -392,8 +401,16 @@ public Task<AuthResult> then(
392401 */
393402 @ NonNull
394403 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
397414 .continueWith (new Continuation <Void , Void >() {
398415 @ Override
399416 public Void then (@ NonNull Task <Void > task ) {
@@ -434,7 +451,7 @@ public Void then(@NonNull Task<Void> task) {
434451 * @param context the calling {@link Context}.
435452 */
436453 @ NonNull
437- public Task <Void > delete (@ NonNull Context context ) {
454+ public Task <Void > delete (@ NonNull final Context context ) {
438455 final FirebaseUser currentUser = mAuth .getCurrentUser ();
439456 if (currentUser == null ) {
440457 return Tasks .forException (new FirebaseAuthInvalidUserException (
@@ -443,14 +460,19 @@ public Task<Void> delete(@NonNull Context context) {
443460 }
444461
445462 final List <Credential > credentials = getCredentialsFromFirebaseUser (currentUser );
446- final CredentialsClient client = GoogleApiUtils .getCredentialsClient (context );
447463
448464 // Ensure the order in which tasks are executed properly destructures the user.
449465 return signOutIdps (context ).continueWithTask (new Continuation <Void , Task <Void >>() {
450466 @ Override
451467 public Task <Void > then (@ NonNull Task <Void > task ) {
452468 task .getResult (); // Propagate exception if there was one
453469
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 );
454476 List <Task <?>> credentialTasks = new ArrayList <>();
455477 for (Credential credential : credentials ) {
456478 credentialTasks .add (client .delete (credential ));
@@ -516,7 +538,11 @@ private Task<Void> signOutIdps(@NonNull Context context) {
516538 if (ProviderAvailability .IS_FACEBOOK_AVAILABLE ) {
517539 LoginManager .getInstance ().logOut ();
518540 }
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+ }
520546 }
521547
522548 /**
0 commit comments