in Fido/app/src/main/java/com/fido/example/fido2apiexample/Fido2DemoActivity.java [202:248]
private void updateUI() {
// We check a boolean value in SharedPreferences to determine whether the user has been
// signed in. This value is false by default. It would be set to true after signing in and
// would be reset to false after user clicks "Sign out".
// After the users clicks "Sign out", we couldn't use
// GoogleSignInApi#silentSignIn(GoogleApiClient), because it silently signs in the user
// again. Thus, we rely on this boolean value in SharedPreferences.
if (!getAccountSignInStatus()) {
displayAccountNotSignedIn();
return;
}
OptionalPendingResult<GoogleSignInResult> pendingResult =
Auth.GoogleSignInApi.silentSignIn(googleApiClient);
if (pendingResult.isDone()) {
// If the user's cached credentials are valid, the OptionalPendingResult will be "done"
// and the GoogleSignInResult will be available instantly.
GoogleSignInResult result = pendingResult.get();
if (result.isSuccess()) {
googleSignInAccount = result.getSignInAccount();
displayAccountSignedIn(
result.getSignInAccount().getEmail(), result.getSignInAccount().getDisplayName());
} else {
displayAccountNotSignedIn();
}
} else {
// If the user has not previously signed in on this device or the sign-in has expired,
// this asynchronous branch will attempt to sign in the user silently. Cross-device
// single sign-on will occur in this branch.
displayAccountNotSignedIn();
pendingResult.setResultCallback(
new ResultCallback<GoogleSignInResult>() {
@Override
public void onResult(@NonNull GoogleSignInResult result) {
if (result.isSuccess()) {
googleSignInAccount = result.getSignInAccount();
displayAccountSignedIn(
result.getSignInAccount().getEmail(),
result.getSignInAccount().getDisplayName());
} else {
displayAccountNotSignedIn();
}
}
});
}
}