Titanium JIRA Archive
Appcelerator Modules (MOD)

[MOD-2421] Ti.Map Android: Remote Marker Image throws exception

GitHub Issuen/a
TypeBug
PriorityMedium
StatusOpen
ResolutionUnresolved
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelsti.map
ReporterRene Pot
AssigneeYordan Banev
Created2018-05-08T21:28:15.000+0000
Updated2018-05-09T11:35:51.000+0000

Description

From Git ticket: https://github.com/appcelerator-modules/ti.map/issues/229 When using remote images for a marker, a java exception is thrown that seems like some sort of security issue. This doesn't seem to be present in pre-3.0 versions. Have tried this two different ways. The first is using an image view.
var view = Ti.UI.createImageView(
{
        width: 85,
        height: 85,
        itemId : itemId,
	image : image
});
var ann = MapModule.createAnnotation({
	customView: view,
	latitude: lat,
	longitude: lon,
	itemId: itemId,
	canShowCallout: false
});
And the second is a simple url added to the marker.
var ann = MapModule.createAnnotation({
	image: "https://someurl.com/images/someimage.jpg",
	latitude: lat,
	longitude: lon,
	itemId: itemId,
	canShowCallout: false
});
Either way, the result it the same. The following exception will be thrown.
[WARN] :   W/System.err: android.os.NetworkOnMainThreadException
[WARN] :   W/System.err: 	at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1317)
[WARN] :   W/System.err: 	at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:86)
[WARN] :   W/System.err: 	at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:74)
[WARN] :   W/System.err: 	at java.net.InetAddress.getAllByName(InetAddress.java:752)
[WARN] :   W/System.err: 	at com.android.okhttp.internal.Network$1.resolveInetAddresses(Network.java:29)
[WARN] :   W/System.err: 	at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:187)
[WARN] :   W/System.err: 	at com.android.okhttp.internal.http.RouteSelector.nextProxy(RouteSelector.java:156)
[WARN] :   W/System.err: 	at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:98)
[WARN] :   W/System.err: 	at com.android.okhttp.internal.http.HttpEngine.createNextConnection(HttpEngine.java:345)
[WARN] :   W/System.err: 	at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:328)
[WARN] :   W/System.err: 	at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:246)
[WARN] :   W/System.err: 	at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:457)
[WARN] :   W/System.err: 	at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:405)
[WARN] :   W/System.err: 	at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:243)
[WARN] :   W/System.err: 	at java.net.URL.openStream(URL.java:1057)
[WARN] :   W/System.err: 	at org.appcelerator.titanium.util.TiFileHelper.handleNetworkURL(TiFileHelper.java:248)
[WARN] :   W/System.err: 	at org.appcelerator.titanium.util.TiFileHelper.handleMessage(TiFileHelper.java:783)
[WARN] :   W/System.err: 	at android.os.Handler.dispatchMessage(Handler.java:98)
[WARN] :   W/System.err: 	at org.appcelerator.kroll.common.TiMessenger.sendMessage(TiMessenger.java:322)
[WARN] :   W/System.err: 	at org.appcelerator.kroll.common.TiMessenger.sendBlockingMessage(TiMessenger.java:288)
[WARN] :   W/System.err: 	at org.appcelerator.kroll.common.TiMessenger.sendBlockingRuntimeMessage(TiMessenger.java:190)
[WARN] :   W/System.err: 	at org.appcelerator.titanium.util.TiFileHelper.openInputStream(TiFileHelper.java:183)
[WARN] :   W/System.err: 	at org.appcelerator.titanium.view.TiDrawableReference.getInputStream(TiDrawableReference.java:896)
[WARN] :   W/System.err: 	at org.appcelerator.titanium.view.TiDrawableReference.getBitmap(TiDrawableReference.java:346)
[WARN] :   W/System.err: 	at org.appcelerator.titanium.view.TiDrawableReference.getBitmap(TiDrawableReference.java:330)
[WARN] :   W/System.err: 	at ti.modules.titanium.ui.widget.TiUIImageView.toBlob(TiUIImageView.java:968)
[WARN] :   W/System.err: 	at ti.modules.titanium.ui.ImageViewProxy.toBlob(ImageViewProxy.java:117)
[WARN] :   W/System.err: 	at ti.modules.titanium.ui.ImageViewProxy.toImage(ImageViewProxy.java:46)
[WARN] :   W/System.err: 	at ti.map.AnnotationProxy.handleCustomView(AnnotationProxy.java:259)
[WARN] :   W/System.err: 	at ti.map.AnnotationProxy.processOptions(AnnotationProxy.java:236)
[WARN] :   W/System.err: 	at ti.map.TiUIMapView.addAnnotation(TiUIMapView.java:438)
[WARN] :   W/System.err: 	at ti.map.ViewProxy.handleAddAnnotation(ViewProxy.java:291)
[WARN] :   W/System.err: 	at ti.map.ViewProxy.addAnnotation(ViewProxy.java:280)
[WARN] :   W/System.err: 	at org.appcelerator.kroll.runtime.v8.V8Object.nativeCallProperty(Native Method)
[WARN] :   W/System.err: 	at org.appcelerator.kroll.runtime.v8.V8Object.callProperty(V8Object.java:75)
[WARN] :   W/System.err: 	at org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1200)
[WARN] :   W/System.err: 	at android.os.Handler.dispatchMessage(Handler.java:98)
[WARN] :   W/System.err: 	at android.os.Looper.loop(Looper.java:154)
[WARN] :   W/System.err: 	at android.app.ActivityThread.main(ActivityThread.java:6123)
[WARN] :   W/System.err: 	at java.lang.reflect.Method.invoke(Native Method)
[WARN] :   W/System.err: 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
[WARN] :   W/System.err: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)

Comments

  1. Joshua Quick 2018-05-08

    [~topener], [~ybanev], this is a known issue that happens with all of our UI such as View.backgroundImage, except for ImageView.image. It only happens if Titanium's JavaScript runtime is setup to run on the UI thread, which unfortunately is the default setting. The reason is because our core image loading code is attempting to a blocking download, but Google's network API throws this exception while running on the UI thread. So, the module doesn't need to be fixed. We need to fix it in our core code here... [TiFileHelper.java#handleNetworkURL()](https://github.com/appcelerator/titanium_mobile/blob/master/android/titanium/src/java/org/appcelerator/titanium/util/TiFileHelper.java#L232) I actually came up with a solution to this issue last year, but it was part of my giant PR that was intended to refactor all of our image loading code. This PR has been put on hold. But I can extract the needed fix out of it in the near future. Note that referencing an image via a URL is a blocking download on both Android and iOS for all APIs except ImageView.image. This is the downside of doing it this way and I don't really suggest using it for the moment. That is, the UI may block for 60 seconds until timing out if you have a network problem on iOS as well. (I think this is an undocumented gotcha.)
  2. Rene Pot 2018-05-09

    [~jquick] sounds like something that could go into the first version after 7.2.0.GA

JSON Source