in auth/src/main/java/com/firebase/ui/auth/AuthUI.java [310:379]
public Task<AuthResult> silentSignIn(@NonNull Context context,
@NonNull List<IdpConfig> configs) {
if (mAuth.getCurrentUser() != null) {
throw new IllegalArgumentException("User already signed in!");
}
final Context appContext = context.getApplicationContext();
final IdpConfig google =
ProviderUtils.getConfigFromIdps(configs, GoogleAuthProvider.PROVIDER_ID);
final IdpConfig email =
ProviderUtils.getConfigFromIdps(configs, EmailAuthProvider.PROVIDER_ID);
if (google == null && email == null) {
throw new IllegalArgumentException("No supported providers were supplied. " +
"Add either Google or email support.");
}
final GoogleSignInOptions googleOptions;
if (google == null) {
googleOptions = null;
} else {
GoogleSignInAccount last = GoogleSignIn.getLastSignedInAccount(appContext);
if (last != null && last.getIdToken() != null) {
return mAuth.signInWithCredential(GoogleAuthProvider.getCredential(
last.getIdToken(), null));
}
googleOptions = google.getParams()
.getParcelable(ExtraConstants.GOOGLE_SIGN_IN_OPTIONS);
}
// If Play services are not available we can't attempt to use the credentials client.
if (!GoogleApiUtils.isPlayServicesAvailable(context)) {
return Tasks.forException(
new FirebaseUiException(ErrorCodes.PLAY_SERVICES_UPDATE_CANCELLED));
}
return GoogleApiUtils.getCredentialsClient(context)
.request(new CredentialRequest.Builder()
// We can support both email and Google at the same time here because they
// are mutually exclusive. If a user signs in with Google, their email
// account will automatically be upgraded (a.k.a. replaced) with the Google
// one, meaning Smart Lock won't have to show the picker UI.
.setPasswordLoginSupported(email != null)
.setAccountTypes(google == null ? null :
ProviderUtils.providerIdToAccountType(GoogleAuthProvider
.PROVIDER_ID))
.build())
.continueWithTask(task -> {
Credential credential = task.getResult().getCredential();
String email1 = credential.getId();
String password = credential.getPassword();
if (TextUtils.isEmpty(password)) {
return GoogleSignIn.getClient(appContext,
new GoogleSignInOptions.Builder(googleOptions)
.setAccountName(email1)
.build())
.silentSignIn()
.continueWithTask(task1 -> {
AuthCredential authCredential = GoogleAuthProvider
.getCredential(
task1.getResult().getIdToken(), null);
return mAuth.signInWithCredential(authCredential);
});
} else {
return mAuth.signInWithEmailAndPassword(email1, password);
}
});
}