Skip to content

Commit 6fbe224

Browse files
authored
Ignore the no accounts error for Credentials disable (#1158)
1 parent 6a0441c commit 6fbe224

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

app/src/main/java/com/firebase/uidemo/auth/SignedInActivity.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import android.support.v7.app.AlertDialog;
2828
import android.support.v7.app.AppCompatActivity;
2929
import android.text.TextUtils;
30+
import android.util.Log;
3031
import android.view.View;
3132
import android.widget.ImageView;
3233
import android.widget.TextView;
@@ -56,6 +57,8 @@
5657

5758
public class SignedInActivity extends AppCompatActivity {
5859

60+
private static final String TAG = "SignedInActivity";
61+
5962
private static final String EXTRA_IDP_RESPONSE = "extra_idp_response";
6063
private static final String EXTRA_SIGNED_IN_CONFIG = "extra_signed_in_config";
6164

@@ -126,6 +129,7 @@ public void onComplete(@NonNull Task<Void> task) {
126129
startActivity(AuthUiActivity.createIntent(SignedInActivity.this));
127130
finish();
128131
} else {
132+
Log.w(TAG, "signOut:failure", task.getException());
129133
showSnackbar(R.string.sign_out_failed);
130134
}
131135
}

auth/src/main/java/com/firebase/ui/auth/AuthUI.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@
8181
* for examples on how to get started with FirebaseUI Auth.
8282
*/
8383
public class AuthUI {
84+
85+
private static final String TAG = "AuthUI";
86+
8487
@StringDef({
8588
EmailAuthProvider.PROVIDER_ID,
8689
PhoneAuthProvider.PROVIDER_ID,
@@ -268,9 +271,31 @@ public static int getDefaultTheme() {
268271
@NonNull
269272
public Task<Void> signOut(@NonNull Context context) {
270273
mAuth.signOut();
274+
275+
Task<Void> maybeDisableAutoSignIn = GoogleApiUtils.getCredentialsClient(context)
276+
.disableAutoSignIn()
277+
.continueWithTask(new Continuation<Void, Task<Void>>() {
278+
@Override
279+
public Task<Void> then(@NonNull Task<Void> task) throws Exception {
280+
// We want to ignore a specific exception, since it's not a good reason
281+
// to fail (see Issue 1156).
282+
if (!task.isSuccessful() && (task.getException() instanceof ApiException)) {
283+
ApiException ae = (ApiException) task.getException();
284+
if (ae.getStatusCode() == CommonStatusCodes.CANCELED) {
285+
Log.w(TAG, "Could not disable auto-sign in, maybe there are no " +
286+
"SmartLock accounts available?", ae);
287+
288+
return Tasks.forResult(null);
289+
}
290+
}
291+
292+
return task;
293+
}
294+
});
295+
271296
return Tasks.whenAll(
272297
signOutIdps(context),
273-
GoogleApiUtils.getCredentialsClient(context).disableAutoSignIn());
298+
maybeDisableAutoSignIn);
274299
}
275300

276301
/**

0 commit comments

Comments
 (0)