java.lang.AssertionError: could not bind to KeyChainService

1

I am trying to use digital certificate in Android to log in a Webview. In all the devices that I have used I do not find a problem but in the Huawei this exception jumps me:

java.lang.AssertionError: could not bind to KeyChainService

Does anyone sound like it?

Thank you.

API 24 (Android 7.0) EMUI 5.1, Code:

@SuppressLint("WrongConstant")
    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    override fun onReceivedClientCertRequest(view: WebView, request: ClientCertRequest) {
        var keyTypes: Array<String>? = request.keyTypes
        if (keyTypes == null)
            keyTypes = arrayOf()

        KeyChain.choosePrivateKeyAlias(
                this@LoginClaveActivity,
                KeyChainAliasCallback { alias ->
                    if (alias == null) {
                        request.cancel()
                        return@KeyChainAliasCallback
                    }
                    object : AsyncTask<Void, Void, Void>() {
                        override fun doInBackground(vararg params: Void): Void? {
                            val privateKey: PrivateKey?
                            val certificateChain: Array<X509Certificate>?
                            try {
                                privateKey = KeyChain.getPrivateKey(this@LoginClaveActivity, alias)
                                certificateChain = KeyChain.getCertificateChain(this@LoginClaveActivity, alias)
                            } catch (e: InterruptedException) {
                                request.ignore()
                                return null
                            } catch (e: KeyChainException) {
                                request.ignore()
                                return null
                            }

                            request.proceed(privateKey, certificateChain)
                            return null
                        }
                    }.execute()
                },
                keyTypes,
                request.principals,
                request.host,
                request.port, null)
    }
    
asked by FangusK 28.08.2018 в 14:21
source

1 answer

1

I already found the error, the problem was here: this@LoginClaveActivity . To be more specific the solution I found was to pass applicationContext instead of the activity and it was perfectly solved.

    
answered by 02.09.2018 / 03:09
source