OSDN Git Service

Support using ImageDecoder with ContentResolver + URI
authorLeon Scroggins III <scroggo@google.com>
Mon, 11 Dec 2017 18:47:23 +0000 (13:47 -0500)
committerLeon Scroggins III <scroggo@google.com>
Mon, 8 Jan 2018 17:41:39 +0000 (12:41 -0500)
commited074fd70011cf804a14b5cf53ffd4b529c5f367
tree86ee72779eb0ed8f5742d2dac992476c53e011c0
parent5c72a77bcaed8f399974f4edbf3d156a0ceb7cbb
Support using ImageDecoder with ContentResolver + URI

Bug: 63909536
Test: CTS: I0f36ce34c968fd7fae4d8edebabea3a421859615

Add ImageDecoder.createSource(ContentResolver, URI), allowing a client
to decode images from files, content, resources, etc.

Prefer using a file descriptor to using an InputStream so the input can
be cheaply seeked and rewound if necessary.

Make ImageDecoder implement AutoCloseable to handle closing the input.

Make decodeDrawable/decodeBitmap always return an object or throw an
IOException. Avoid checking for a file in the Source constructor.

Fix a bug where inner Exception classes were not static.

Update JavaInputStreamAdaptor to be usable by ImageDecoder:
- previously it always swallowed exceptions. Allow them to propagate
  (optionally) so that they can be reported back to the client.
- Add refs to the InputStream and byte[]. ImageDecoder returns from
  native and then uses the JavaInputStreamAdaptor again, making the
  local refs go out of scope.
- Hold on to the JavaVM and convert to the JNIEnv when necessary. Pass
  local env pointers to avoid looking it up multiple times in one call.
- If an exception is thrown inside the doRead() loop, return the number
  of bytes successfully read.

Change-Id: I869dad55521cf942efd010c06baf3f44c1c08374
core/jni/android/graphics/CreateJavaOutputStreamAdaptor.cpp
core/jni/android/graphics/CreateJavaOutputStreamAdaptor.h
core/jni/android/graphics/ImageDecoder.cpp
graphics/java/android/graphics/ImageDecoder.java