{ "id": "170657", "key": "TIMOB-25619", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [ { "id": "19957", "description": "", "name": "Release 7.1.0", "archived": false, "released": true, "releaseDate": "2018-03-14" } ], "resolution": { "id": "1", "description": "A fix for this issue is checked into the tree and tested.", "name": "Fixed" }, "resolutiondate": "2018-02-28T18:17:14.000+0000", "created": "2017-12-20T02:33:36.000+0000", "priority": { "name": "Medium", "id": "3" }, "labels": [ "android", "blob", "media", "preview" ], "versions": [ { "id": "16980", "description": "New V8", "name": "Release 6.0.0", "archived": false, "released": true, "releaseDate": "2016-11-15" } ], "issuelinks": [], "assignee": { "name": "gmathews", "key": "gmathews", "displayName": "Gary Mathews", "active": true, "timeZone": "America/Los_Angeles" }, "updated": "2018-03-02T16:40:28.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "10202", "name": "Android", "description": "Android Platform" } ], "description": "*Summary:*\r\nThe media.previewImage() method will crash if given a blob whose image is not file based, such as a screenshot returned by View.toImage().\r\n\r\n*Steps to Reproduce:*\r\n# Build and run the below code on an Android device.\r\n# Tap the \"Preview\" button.\r\n# Select an app to preview the screenshot, if asked.\r\n\r\n{code:javascript}\r\nvar window = Ti.UI.createWindow();\r\nvar button = Ti.UI.createButton({ title: \"Preview\" });\r\nbutton.addEventListener(\"click\", function(e) {\r\n\twindow.toImage(function(imageBlob) {\r\n\t\tif (!imageBlob) {\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tTi.Media.previewImage(\r\n\t\t{\r\n\t\t\timage: imageBlob,\r\n\t\t\tsuccess: function(e) {\r\n\t\t\t\tTi.API.info(\"@@@ Successfully displayed preview.\");\r\n\t\t\t},\r\n\t\t\terror: function(e) {\r\n\t\t\t\tTi.API.error(\"@@@ Failed to display preview\");\r\n\t\t\t},\r\n\t\t});\r\n\t});\r\n});\r\nwindow.add(button);\r\nwindow.open();\r\n{code}\r\n\r\n*Result:*\r\nApp crashes with the following stack trace...\r\n\r\n{code}\r\nW/System.err( 5003): java.lang.ClassCastException: byte[] cannot be cast to org.appcelerator.titanium.io.TiBaseFile\r\nW/System.err( 5003): \tat ti.modules.titanium.media.MediaModule.previewImage(MediaModule.java:1148)\r\nW/System.err( 5003): \tat org.appcelerator.kroll.runtime.v8.V8Function.nativeInvoke(Native Method)\r\nW/System.err( 5003): \tat org.appcelerator.kroll.runtime.v8.V8Function.callSync(V8Function.java:55)\r\nW/System.err( 5003): \tat org.appcelerator.kroll.runtime.v8.V8Function.call(V8Function.java:41)\r\nW/System.err( 5003): \tat org.appcelerator.kroll.runtime.v8.V8Function$1.run(V8Function.java:68)\r\nW/System.err( 5003): \tat android.os.Handler.handleCallback(Handler.java:615)\r\nW/System.err( 5003): \tat android.os.Handler.dispatchMessage(Handler.java:92)\r\nW/System.err( 5003): \tat android.os.Looper.loop(Looper.java:137)\r\nW/System.err( 5003): \tat android.app.ActivityThread.main(ActivityThread.java:4745)\r\nW/System.err( 5003): \tat java.lang.reflect.Method.invokeNative(Native Method)\r\nW/System.err( 5003): \tat java.lang.reflect.Method.invoke(Method.java:511)\r\nW/System.err( 5003): \tat com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)\r\nW/System.err( 5003): \tat com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)\r\nW/System.err( 5003): \tat dalvik.system.NativeStart.main(Native Method)\r\n{code}\r\n\r\n*Expected Result:*\r\nShould not crash. Should either display the in-memory image or invoke the error callback stating that the given blob must be file based. Ideally, the given memory based blob should be stored to a temp file and displayed.\r\n\r\n*Work-Around:*\r\nTitanium developer can save the blob to a temp file and preview the file instead.\r\n\r\n*Note:*\r\nThe following pending PR will fix the \"TiBaseFile\" exception mentioned in the above stack trace...\r\nhttps://github.com/appcelerator/titanium_mobile/pull/9223\r\n\r\nHowever, the Java code proceeding the image.getData() method call in MediaModule.previewImage() still needs to be changed to handle a blob that'll return a null for its native file path.\r\nhttps://github.com/appcelerator/titanium_mobile/blob/7_0_X/android/modules/media/src/java/ti/modules/titanium/media/MediaModule.java#L1148", "attachment": [], "flagged": false, "summary": "Android: previewImage() crashes when given a non-file based blob", "creator": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "subtasks": [], "reporter": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "environment": null, "closedSprints": [ { "id": 997, "state": "closed", "name": "2018 Sprint 03 SDK", "startDate": "2018-01-28T16:23:12.178Z", "endDate": "2018-02-11T16:23:00.000Z", "completeDate": "2018-02-12T04:22:49.354Z", "originBoardId": 114 }, { "id": 990, "state": "closed", "name": "2018 Sprint 02 SDK", "startDate": "2018-01-14T22:48:43.544Z", "endDate": "2018-01-28T22:48:00.000Z", "completeDate": "2018-01-29T16:22:42.911Z", "originBoardId": 114 } ], "comment": { "comments": [ { "id": "433698", "author": { "name": "gmathews", "key": "gmathews", "displayName": "Gary Mathews", "active": true, "timeZone": "America/Los_Angeles" }, "body": "The documentation for [PreviewImageOptions|http://docs.appcelerator.com/platform/latest/#!/api/PreviewImageOptions-property-image] states _'Must be a blob based on a file, such as from Titanium.Filesystem.File.read'_\r\n\r\nThe native path of TiBlob is used to create the preview intent.", "updateAuthor": { "name": "gmathews", "key": "gmathews", "displayName": "Gary Mathews", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2018-01-26T00:06:40.000+0000", "updated": "2018-01-26T00:06:40.000+0000" }, { "id": "433699", "author": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "body": "It still shouldn't crash.\r\nPerhaps log a warning and no-op instead?\r\nOr save to temp file (that we clean up later) and then preview it?\r\n\r\nHere's a real case where this issue can happen. If you use Ti.Media.openPhotoGallery() to select a photo, but the photo comes from the cloud, then the gallery's listener might return the photo in memory-only blob form here...\r\nhttps://github.com/appcelerator/titanium_mobile/blob/master/android/modules/media/src/java/ti/modules/titanium/media/MediaModule.java#L1108\r\n", "updateAuthor": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2018-01-26T00:17:44.000+0000", "updated": "2018-01-26T00:17:44.000+0000" }, { "id": "433700", "author": { "name": "gmathews", "key": "gmathews", "displayName": "Gary Mathews", "active": true, "timeZone": "America/Los_Angeles" }, "body": "master: https://github.com/appcelerator/titanium_mobile/pull/9771", "updateAuthor": { "name": "gmathews", "key": "gmathews", "displayName": "Gary Mathews", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2018-01-26T00:30:48.000+0000", "updated": "2018-01-26T00:30:48.000+0000" }, { "id": "434543", "author": { "name": "gmathews", "key": "gmathews", "displayName": "Gary Mathews", "active": true, "timeZone": "America/Los_Angeles" }, "body": "7_1_X: https://github.com/appcelerator/titanium_mobile/pull/9833", "updateAuthor": { "name": "gmathews", "key": "gmathews", "displayName": "Gary Mathews", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2018-02-15T21:08:51.000+0000", "updated": "2018-02-15T21:08:51.000+0000" }, { "id": "435115", "author": { "name": "smohammed", "key": "smohammed", "displayName": "Samir Mohammed", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Closing ticket; Verified fix in SDK Version: 7.1.0.v20180228160738 and SDK Version: 7.2.0.v20180301101144.\r\n\r\nTest and other information can be found at: \r\nMaster: https://github.com/appcelerator/titanium_mobile/pull/9771\r\n7_1_X: https://github.com/appcelerator/titanium_mobile/pull/9833 ", "updateAuthor": { "name": "smohammed", "key": "smohammed", "displayName": "Samir Mohammed", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2018-03-02T16:40:16.000+0000", "updated": "2018-03-02T16:40:16.000+0000" } ], "maxResults": 6, "total": 6, "startAt": 0 } } }