1717import android .content .Context ;
1818import android .content .Intent ;
1919import android .os .Bundle ;
20+ import android .os .CancellationSignal ;
2021import android .os .Parcel ;
2122import android .os .Parcelable ;
2223import android .text .TextUtils ;
3233import com .firebase .ui .auth .util .data .PhoneNumberUtils ;
3334import com .firebase .ui .auth .util .data .ProviderAvailability ;
3435import com .firebase .ui .auth .util .data .ProviderUtils ;
36+ import com .google .android .gms .auth .api .identity .Identity ;
3537import com .google .android .gms .auth .api .signin .GoogleSignIn ;
3638import com .google .android .gms .auth .api .signin .GoogleSignInAccount ;
3739import com .google .android .gms .auth .api .signin .GoogleSignInOptions ;
3840import com .google .android .gms .common .api .ApiException ;
3941import com .google .android .gms .common .api .CommonStatusCodes ;
4042import com .google .android .gms .common .api .Scope ;
4143import com .google .android .gms .tasks .Task ;
44+ import com .google .android .gms .tasks .TaskCompletionSource ;
4245import com .google .android .gms .tasks .Tasks ;
4346import com .google .firebase .FirebaseApp ;
4447import com .google .firebase .auth .ActionCodeSettings ;
6871import java .util .Locale ;
6972import java .util .Map ;
7073import java .util .Set ;
74+ import java .util .concurrent .Executor ;
75+ import java .util .concurrent .Executors ;
7176
7277import androidx .annotation .CallSuper ;
7378import androidx .annotation .DrawableRes ;
7681import androidx .annotation .RestrictTo ;
7782import androidx .annotation .StringDef ;
7883import androidx .annotation .StyleRes ;
84+ import androidx .credentials .ClearCredentialStateRequest ;
85+ import androidx .credentials .CredentialManagerCallback ;
86+ import androidx .credentials .exceptions .ClearCredentialException ;
7987
8088/**
8189 * The entry point to the AuthUI authentication flow, and related utility methods. If your
@@ -280,8 +288,9 @@ public Task<Void> signOut(@NonNull Context context) {
280288 if (!playServicesAvailable ) {
281289 Log .w (TAG , "Google Play services not available during signOut" );
282290 }
283-
284- return signOutIdps (context ).continueWith (task -> {
291+ signOutIdps (context );
292+ Executor singleThreadExecutor = Executors .newSingleThreadExecutor ();
293+ return clearCredentialState (context , singleThreadExecutor ).continueWith (task -> {
285294 task .getResult (); // Propagate exceptions if any.
286295 mAuth .signOut ();
287296 return null ;
@@ -303,9 +312,10 @@ public Task<Void> delete(@NonNull final Context context) {
303312 String .valueOf (CommonStatusCodes .SIGN_IN_REQUIRED ),
304313 "No currently signed in user." ));
305314 }
306-
307- return signOutIdps (context ).continueWithTask (task -> {
308- task .getResult (); // Propagate exception if there was one.
315+ signOutIdps (context );
316+ Executor singleThreadExecutor = Executors .newSingleThreadExecutor ();
317+ return clearCredentialState (context , singleThreadExecutor ).continueWithTask (task -> {
318+ task .getResult (); // Propagate exceptions if any.
309319 return currentUser .delete ();
310320 });
311321 }
@@ -338,15 +348,43 @@ public int getEmulatorPort() {
338348 return mEmulatorPort ;
339349 }
340350
341- private Task < Void > signOutIdps (@ NonNull Context context ) {
351+ private void signOutIdps (@ NonNull Context context ) {
342352 if (ProviderAvailability .IS_FACEBOOK_AVAILABLE ) {
343353 LoginManager .getInstance ().logOut ();
344354 }
345- if (GoogleApiUtils .isPlayServicesAvailable (context )) {
346- return GoogleSignIn .getClient (context , GoogleSignInOptions .DEFAULT_SIGN_IN ).signOut ();
347- } else {
348- return Tasks .forResult ((Void ) null );
349- }
355+ }
356+
357+ /**
358+ * A Task to clear the credential state in Credential Manager.
359+ * @param context
360+ * @param executor
361+ * @return
362+ */
363+ private Task <Void > clearCredentialState (
364+ @ NonNull Context context ,
365+ @ NonNull Executor executor
366+ ) {
367+ TaskCompletionSource <Void > completionSource = new TaskCompletionSource <>();
368+
369+ ClearCredentialStateRequest clearRequest = new ClearCredentialStateRequest ();
370+ GoogleApiUtils .getCredentialManager (context )
371+ .clearCredentialStateAsync (
372+ clearRequest ,
373+ new CancellationSignal (),
374+ executor ,
375+ new CredentialManagerCallback <>() {
376+ @ Override
377+ public void onResult (Void unused ) {
378+ completionSource .setResult (unused );
379+ }
380+
381+ @ Override
382+ public void onError (@ NonNull ClearCredentialException e ) {
383+ completionSource .setException (e );
384+ }
385+ }
386+ );
387+ return completionSource .getTask ();
350388 }
351389
352390 /**
0 commit comments