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
[TIMOB-24605] Android: Fixed crashes caused by loading image URLs when JS is running on main thread #10222
Conversation
…Image" to url while JS running on main thread - Fixed [TIMOB-26249] where setting ImageView "image" to a URL while "autorotate" is true would cause a crash. - Fixed crash with ImageView "defaultImage" set to a URL while JS is running on main thread. - Modified "TiImageHelper" to read exif orientation from a stream. Can now acquire exif info from url based image. - Added new Java class "TiInputStreamWrapper".
if (TiApplication.isUIThread()) { | ||
// Anonymous class used to call this blockingDownload() method on another thread. | ||
// Downloaded content will be made available via Titanium's "TiResponseCache". | ||
class DownloadOperation implements Runnable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of creating an anonymous class, you should be able to do this:
public InputStream blockingDownload(final URI uri)
{
...
// Perform the blocking download.
try {
Thread downloadThread = new Thread(new Runnable() {
@Override
public void run() {
try (InputStream stream = blockingDownload(uri)) {
if (stream != null) {
KrollStreamHelper.pump(stream, null);
}
} catch (Exception ex) {
}
}
});
downloadThread.start();
// wait for thread to finish
downloadThread.join();
} catch (Exception ex) {
}
...
...
// Close the connection and attempt to connect to the redirect URL. | ||
httpConnection.disconnect(); | ||
continue; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe log a warning if there's a bad response (404?), or throw an exception?
You can test with https://httpbin.org/status/404
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. The image
property used to log a 404 warning and now it doesn't. I'll add some log messages.
Also, backgroundImage
used to crash the app for a 404 response when "run-on-main-thread" was false
. I've inadvertently fixed that. :)
- Add more logging messages. - Simplified Threaded blocking download code.
Updated PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CR: PASS
Generated by 🚫 dangerJS |
JIRA:
Summary:
View
object's "backgroundImage" property.ImageView
object'simage
property while "autorotate" istrue
.ImageView
object's "defaultImage" property.ImageView
to auto-rotate JPEG downloaded from the Internet if needed.HttpUrlConnection
when the stream has been closed.Test 1:
true
.Test 2:
true
.