An Android app uses the Google REST API to access Google Drive and Calendar. The play library provided activity started to sign in works as expected, but the same activity started to request scopes only puts up an normally sized view that should show what scopes were being requested, but instead is blank except for a perpetual circular progress bar. Hitting the back button results in the launching fragment getting an 'activity cancelled' result code.
The profiler shows that for both sign in and scope permission requests com.google.android.gms.auth.api.signin.internal.SignInHubActivity
is launched. Sign in is drawn correctly and the user can sign in. Scope permission requests just hang.
The essential parts of the test app are shown below. The sign in and scopes requests are actually more similar than the GoogleSignIn.requestPermissions
convenience method implies. The requestScopesDirectly
method below derived from GoogleSignIn.requestPermissions
shows the actual equivalence.
private fun initiateSignIn() {
val gsic = GoogleSignIn.getClient(requireActivity(), signInOptions)
val signInIntent = gsic.signInIntent
startActivityForResult(signInIntent, requestCodeSignIn)
}
private fun requestScopes() {
val sia = GoogleSignIn.getLastSignedInAccount(requireActivity())
if (sia != null) {
GoogleSignIn.requestPermissions(
this,
requestCodeScopes,
sia,
Scope(DriveScopes.DRIVE_FILE)
)
}
}
private fun requestScopesDirectly() {
val act = requireActivity()
val gsia = GoogleSignIn.getLastSignedInAccount(act)
if (gsia != null) {
val sio = GoogleSignInOptions.Builder().let { b ->
b.requestScopes(Scope(DriveScopes.DRIVE_FILE))
b.setAccountName(gsia.email)
b.build()
}
val gsic = GoogleSignIn.getClient(act, sio)
val signInIntent = gsic.signInIntent
startActivityForResult(signInIntent, requestCodeScopes)
}
}
It has proven very difficult to debug why this is happening. The behavior does not depend on whether or not the scope being requested is from an API that the app has as "enabled". If the scope request only includes already granted scopes the started activity show no UI but does return OK as expected.
If the app for some reason is not permitted to make a scope request then at least some error indication should be returned.
How can this issue be further debugged?
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.2'
implementation 'com.google.android.gms:play-services-auth:19.0.0'
implementation 'com.google.api-client:google-api-client:1.31.2'
implementation 'com.google.api-client:google-api-client-android:1.31.2'
implementation 'com.google.apis:google-api-services-drive:v3-rev20201130-1.31.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
question from:
https://stackoverflow.com/questions/65849541/android-signinhubactivity-hangs-with-blank-view-except-for-a-progress-bar-when-r 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…