3434import com .firebase .ui .auth .data .remote .FacebookSignInHandler ;
3535import com .firebase .ui .auth .data .remote .TwitterSignInHandler ;
3636import com .firebase .ui .auth .ui .idp .AuthMethodPickerActivity ;
37+ import com .firebase .ui .auth .util .CredentialUtils ;
3738import com .firebase .ui .auth .util .ExtraConstants ;
3839import com .firebase .ui .auth .util .GoogleApiUtils ;
3940import com .firebase .ui .auth .util .Preconditions ;
@@ -210,7 +211,11 @@ private AuthUI(FirebaseApp app) {
210211 mApp = app ;
211212 mAuth = FirebaseAuth .getInstance (mApp );
212213
213- mAuth .setFirebaseUIVersion (BuildConfig .VERSION_NAME );
214+ try {
215+ mAuth .setFirebaseUIVersion (BuildConfig .VERSION_NAME );
216+ } catch (Exception e ) {
217+ Log .e (TAG , "Couldn't set the FUI version." , e );
218+ }
214219 mAuth .useAppLanguage ();
215220 }
216221
@@ -272,32 +277,36 @@ public static int getDefaultTheme() {
272277 */
273278 @ NonNull
274279 public Task <Void > signOut (@ NonNull Context context ) {
275- mAuth .signOut ();
276-
277280 Task <Void > maybeDisableAutoSignIn = GoogleApiUtils .getCredentialsClient (context )
278281 .disableAutoSignIn ()
279- .continueWithTask (new Continuation <Void , Task < Void > >() {
282+ .continueWith (new Continuation <Void , Void >() {
280283 @ Override
281- public Task < Void > then (@ NonNull Task <Void > task ) {
284+ public Void then (@ NonNull Task <Void > task ) {
282285 // We want to ignore a specific exception, since it's not a good reason
283286 // to fail (see Issue 1156).
284- if (!task .isSuccessful () && (task .getException () instanceof ApiException )) {
285- ApiException ae = (ApiException ) task .getException ();
286- if (ae .getStatusCode () == CommonStatusCodes .CANCELED ) {
287- Log .w (TAG , "Could not disable auto-sign in, maybe there are no " +
288- "SmartLock accounts available?" , ae );
289-
290- return Tasks .forResult (null );
291- }
287+ Exception e = task .getException ();
288+ if (e instanceof ApiException
289+ && ((ApiException ) e ).getStatusCode () == CommonStatusCodes .CANCELED ) {
290+ Log .w (TAG , "Could not disable auto-sign in, maybe there are no " +
291+ "SmartLock accounts available?" , e );
292+ return null ;
292293 }
293294
294- return task ;
295+ return task . getResult () ;
295296 }
296297 });
297298
298299 return Tasks .whenAll (
299300 signOutIdps (context ),
300- maybeDisableAutoSignIn );
301+ maybeDisableAutoSignIn
302+ ).continueWith (new Continuation <Void , Void >() {
303+ @ Override
304+ public Void then (@ NonNull Task <Void > task ) {
305+ task .getResult (); // Propagate exceptions
306+ mAuth .signOut ();
307+ return null ;
308+ }
309+ });
301310 }
302311
303312 /**
@@ -322,12 +331,6 @@ public Task<Void> delete(@NonNull Context context) {
322331
323332 // Ensure the order in which tasks are executed properly destructures the user.
324333 return signOutIdps (context ).continueWithTask (new Continuation <Void , Task <Void >>() {
325- @ Override
326- public Task <Void > then (@ NonNull Task <Void > task ) {
327- task .getResult (); // Propagate exception if there was one
328- return currentUser .delete ();
329- }
330- }).continueWithTask (new Continuation <Void , Task <Void >>() {
331334 @ Override
332335 public Task <Void > then (@ NonNull Task <Void > task ) {
333336 task .getResult (); // Propagate exception if there was one
@@ -337,9 +340,9 @@ public Task<Void> then(@NonNull Task<Void> task) {
337340 credentialTasks .add (client .delete (credential ));
338341 }
339342 return Tasks .whenAll (credentialTasks )
340- .continueWithTask (new Continuation <Void , Task < Void > >() {
343+ .continueWith (new Continuation <Void , Void >() {
341344 @ Override
342- public Task < Void > then (@ NonNull Task <Void > task ) {
345+ public Void then (@ NonNull Task <Void > task ) {
343346 Exception e = task .getException ();
344347 Throwable t = e == null ? null : e .getCause ();
345348 if (!(t instanceof ApiException )
@@ -348,13 +351,19 @@ public Task<Void> then(@NonNull Task<Void> task) {
348351 // one. This can occur if we failed to save the credential or it
349352 // was deleted elsewhere. However, a lack of stored credential
350353 // doesn't mean fully deleting the user failed.
351- task .getResult ();
354+ return task .getResult ();
352355 }
353356
354- return Tasks . forResult ( null ) ;
357+ return null ;
355358 }
356359 });
357360 }
361+ }).continueWithTask (new Continuation <Void , Task <Void >>() {
362+ @ Override
363+ public Task <Void > then (@ NonNull Task <Void > task ) {
364+ task .getResult (); // Propagate exception if there was one
365+ return currentUser .delete ();
366+ }
358367 });
359368 }
360369
@@ -384,11 +393,13 @@ private static List<Credential> getCredentialsFromFirebaseUser(@NonNull Firebase
384393 }
385394
386395 String type = ProviderUtils .providerIdToAccountType (userInfo .getProviderId ());
387-
388- credentials .add (new Credential .Builder (
389- user .getEmail () == null ? user .getPhoneNumber () : user .getEmail ())
390- .setAccountType (type )
391- .build ());
396+ if (type == null ) {
397+ // Since the account type is null, we've got an email credential. Adding a fake
398+ // password is the only way to tell Smart Lock that this is an email credential.
399+ credentials .add (CredentialUtils .buildCredentialOrThrow (user , "pass" , null ));
400+ } else {
401+ credentials .add (CredentialUtils .buildCredentialOrThrow (user , null , type ));
402+ }
392403 }
393404
394405 return credentials ;
@@ -623,8 +634,8 @@ public EmailBuilder setAllowNewAccounts(boolean allow) {
623634 }
624635
625636 /**
626- * Configures the requirement for the user to enter first and last name
627- * in the email sign up flow.
637+ * Configures the requirement for the user to enter first and last name in the email
638+ * sign up flow.
628639 * <p>
629640 * Name is required by default.
630641 */
0 commit comments