Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow MemorizingTrustManager to be called on the UI thread #50

Closed
klassm opened this issue Mar 6, 2016 · 4 comments
Closed

Allow MemorizingTrustManager to be called on the UI thread #50

klassm opened this issue Mar 6, 2016 · 4 comments

Comments

@klassm
Copy link

klassm commented Mar 6, 2016

Currently this will result in an ANR, as wait() is called on the UI thread.

@ge0rg
Copy link
Owner

ge0rg commented Mar 7, 2016

Sorry, but MTM is always called on the thread of your network connection, and if you do networking on the UI thread, nobody can help you. You should refactor your networking code into a background thread, Service or AsyncTask.

@ge0rg ge0rg closed this as completed Mar 7, 2016
@klassm
Copy link
Author

klassm commented Mar 7, 2016

Not really. See #51

@ge0rg
Copy link
Owner

ge0rg commented Mar 9, 2016

I presume you are handling the [onReceivedSslError()](http://developer.android.com/reference/android/webkit/WebViewClient.html#onReceivedSslError%28android.webkit.WebView, android.webkit.SslErrorHandler, android.net.http.SslError%29) callback? That method provides you with an SslErrorHandler instance that you need to forward the decision to, asynchronously.

To allow async usage, either MTM needs to be rewritten, with a blocker thread introduced to handle the existing primary case, or a wrapper Thread needs to be added that can be blocked by MTM and call the correct response handler after the user's decision.

Such a wrapper would be very tiny (an anonymous Thread instance should suffice), and it would need to expose some callback API to the application. As you already have a case-specific callback API (SslErrorHandler), you will be writing a thin wrapper around a thin wrapper around a blocking thread.

To reduce complexity, it would be easier and more straight-forward to just wrap MTM in a Thread that does call the appropriate SslErrorHandler method after MTM's (blocking) completion.

@klassm
Copy link
Author

klassm commented Mar 9, 2016

This is exactly what I currently do - but at least exposing the Api method for mtm would be great ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants