Assigned
Status Update
Comments
bl...@google.com <bl...@google.com> #2
Automated by Blunderbuss job android-credential-manager-autoassigner for config android_credman_config for component 1301097.
jb...@google.com <jb...@google.com>
ma...@cookielab.io <ma...@cookielab.io> #3
The error you posted state "activity is cancelled by the user". This implies the request was cancelled somehow during the request.
Can you grab a bugreport and attach it to this bug?
Description
Version used:
implementation "androidx.credentials:credentials:1.3.0"
implementation "androidx.credentials:credentials-play-services-auth:1.3.0"
implementation "com.google.android.libraries.identity.googleid:googleid:1.1.1"
implementation 'com.google.api-client:google-api-client:2.7.0'
Devices/Android versions reproduced on:
Xiaomi note 3, android 9
If this is a bug in the library, we would appreciate if you could attach:
- Sample project to trigger the issue.
- A screenrecord or screenshots showing the issue (if UI related).
here is my code, i repleaced "my web client id" for security
private void loginGoogleWithCredentialManagerButton()
{
GetSignInWithGoogleOption googleIdOption = new GetSignInWithGoogleOption.Builder("my web client id")
.build();
CredentialManager credentialManager = CredentialManager.create(activity);
GetCredentialRequest getCredRequest = new GetCredentialRequest.Builder()
.addCredentialOption(googleIdOption)
.build();
CancellationSignal cancellationSignal = new CancellationSignal();
cancellationSignal.setOnCancelListener(new CancellationSignal.OnCancelListener() {
@Override
public void onCancel() {
Log.e("google_login", "signin failed with cancel");
}
});
credentialManager.getCredentialAsync(
// Use activity based context to avoid undefined
// system UI launching behavior
activity,
getCredRequest,
cancellationSignal,
Executors.newSingleThreadExecutor(),
new CredentialManagerCallback<GetCredentialResponse, GetCredentialException>() {
@Override
public void onResult(GetCredentialResponse result) {
handleSignIn(result);
}
@Override
public void onError(GetCredentialException e) {
Log.e("google_login", "signin failed:"+e.toString());
e.printStackTrace();
}
}
);
}
the method works well on our other devices(sumsung, pixel), but i always got "androidx.credentials.exceptions.GetCredentialCancellationException: activity is cancelled by the user" error on Xiaomi note 3(OS version Android 9) without any UI popup.
but the Xiaomi device works well with implementation 'com.google.android.gms:play-services-auth:20.2.0'
i also tried the latest version of androidx.credentials:credentials/androidx.credentials:credentials-play-services-auth/com.google.android.libraries.identity.googleid:googleid, still got same error.
i also tried login with GetGoogleIdOption, still got same error.
here is the Xiaomi note 3(OS version Android 9)'s google version "isGooglePlayServicesAvaiable:0 clientversion:12451000" with these code
void isGooglePlayServicesAvaiable(){
//ConnectionResult.SUCCESS ==
Log.e("google_login", "isGooglePlayServicesAvaiable:"+GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this.getApplicationContext())
+" clientversion:"+GoogleApiAvailability.getInstance().getClientVersion(this));
}
and the Xiaomi's google play service version is 24.44.33 which i checked from settings.
and here is the code work well with implementation 'com.google.android.gms:play-services-auth:20.2.0'
private void loginGoogle(){
try {
if (0 < isGoogleAlreadyLogin()) {
Log.d("google_login", "loginGoogle: already login");
} else {
if (null == activity) {
return;
}
GoogleSignInOptions signInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestId()
.requestEmail()
.requestProfile()
.build();
GoogleSignInClient mGoogleSignInClient = GoogleSignIn.getClient(activity, signInOptions);
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
activity.startActivityForResult(signInIntent, requestCodeLoginGoogle);
}
}catch (Exception ignore){}
}
private int isGoogleAlreadyLogin() {
GoogleSignInOptions signInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestId()
.requestEmail()
.requestProfile()
.build();
GoogleSignInAccount signedInAccount = GoogleSignIn.getLastSignedInAccount(activity.getApplicationContext());
if (null != signedInAccount && GoogleSignIn.hasPermissions(signedInAccount, signInOptions.getScopeArray()))
{
Log.d("google_login", "isGoogleAlreadyLogin id:"+signedInAccount.getId()+" name:"+signedInAccount.getDisplayName());
return 1;
}
return 0;
}
after call loginGoogle() method, i can see popup UI let me choose a google account, and if i choose my gmail account, i can login successfully, so everything is ok if i use com.google.android.gms:play-services-auth:20.2.0, but not work with credentialmanager,
i tested with same device(Xiaomi note 3, android 9), same android project(it's a sample project), i create two button, click buton1 call loginGoogle() method and click button2 call loginGoogleWithCredentialManagerButton() method,
i have no idea how to resolve this issue, please help.