Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
192 views
in Technique[技术] by (71.8m points)

google oauth - Android SignInHubActivity hangs with blank view except for a progress bar when requesting scopes

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. Hanging Scope Request

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...