diff options
| author | 2024-02-12 23:35:51 +0000 | |
|---|---|---|
| committer | 2024-02-12 23:35:51 +0000 | |
| commit | 48165939b653afe03215859666f01e7bdd667c9f (patch) | |
| tree | b933b6964e7b5947ac2f478241a69daddfb26ec1 /graphics/java/android | |
| parent | cb1487b4cd8f84fa9f5d20b09b41727ca83a31f3 (diff) | |
| parent | 39d091bc118177a2b08109204060cc65c7a08ff5 (diff) | |
Merge "Use a file descriptor in decodeFile." into main
Diffstat (limited to 'graphics/java/android')
| -rw-r--r-- | graphics/java/android/graphics/BitmapFactory.java | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/graphics/java/android/graphics/BitmapFactory.java b/graphics/java/android/graphics/BitmapFactory.java index 1da8e189d768..d915b746e0cc 100644 --- a/graphics/java/android/graphics/BitmapFactory.java +++ b/graphics/java/android/graphics/BitmapFactory.java @@ -25,10 +25,13 @@ import android.content.res.AssetManager; import android.content.res.Resources; import android.os.Build; import android.os.Trace; +import android.system.OsConstants; import android.util.DisplayMetrics; import android.util.Log; import android.util.TypedValue; +import libcore.io.IoBridge; + import java.io.FileDescriptor; import java.io.FileInputStream; import java.io.IOException; @@ -523,19 +526,19 @@ public class BitmapFactory { public static Bitmap decodeFile(String pathName, Options opts) { validate(opts); Bitmap bm = null; - InputStream stream = null; + FileDescriptor fd = null; try { - stream = new FileInputStream(pathName); - bm = decodeStream(stream, null, opts); + fd = IoBridge.open(pathName, OsConstants.O_RDONLY); + bm = decodeFileDescriptor(fd, null, opts); } catch (Exception e) { /* do nothing. If the exception happened on open, bm will be null. */ - Log.e("BitmapFactory", "Unable to decode stream: " + e); + Log.e("BitmapFactory", "Unable to decode file: " + e); } finally { - if (stream != null) { + if (fd != null) { try { - stream.close(); + IoBridge.closeAndSignalBlockedThreads(fd); } catch (IOException e) { // do nothing here } |