Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e1bf8efa authored by Chih-Chung Chang's avatar Chih-Chung Chang
Browse files

Fix 5224359: Add width and height to media store.

Change-Id: I27376285a551e648eb0ea010dfdf6b8ed873cdd8
parent f2ff20e0
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -283,6 +283,17 @@ public final class MediaStore {
         */
        public static final String IS_DRM = "is_drm";

        /**
         * The width of the image/video in pixels.
         * @hide
         */
        public static final String WIDTH = "width";

        /**
         * The height of the image/video in pixels.
         * @hide
         */
        public static final String HEIGHT = "height";
     }

    /**
+25 −0
Original line number Diff line number Diff line
@@ -470,6 +470,8 @@ public class MediaScanner
        private int mCompilation;
        private boolean mIsDrm;
        private boolean mNoMedia;   // flag to suppress file from appearing in media tables
        private int mWidth;
        private int mHeight;

        public FileCacheEntry beginFile(String path, String mimeType, long lastModified,
                long fileSize, boolean isDirectory, boolean noMedia) {
@@ -545,6 +547,8 @@ public class MediaScanner
            mWriter = null;
            mCompilation = 0;
            mIsDrm = false;
            mWidth = 0;
            mHeight = 0;

            return entry;
        }
@@ -583,6 +587,10 @@ public class MediaScanner
                            processFile(path, mimeType, this);
                        }

                        if (MediaFile.isImageFileType(mFileType)) {
                            processImageFile(path);
                        }

                        result = endFile(entry, ringtones, notifications, alarms, music, podcasts);
                    }
                }
@@ -697,6 +705,18 @@ public class MediaScanner
            return genreTagValue;
        }

        private void processImageFile(String path) {
            try {
                mBitmapOptions.outWidth = 0;
                mBitmapOptions.outHeight = 0;
                BitmapFactory.decodeFile(path, mBitmapOptions);
                mWidth = mBitmapOptions.outWidth;
                mHeight = mBitmapOptions.outHeight;
            } catch (Throwable th) {
                // ignore;
            }
        }

        public void setMimeType(String mimeType) {
            if ("audio/mp4".equals(mMimeType) &&
                    mimeType.startsWith("video")) {
@@ -725,6 +745,11 @@ public class MediaScanner
            map.put(MediaStore.MediaColumns.MIME_TYPE, mMimeType);
            map.put(MediaStore.MediaColumns.IS_DRM, mIsDrm);

            if (mWidth > 0 && mHeight > 0) {
                map.put(MediaStore.MediaColumns.WIDTH, mWidth);
                map.put(MediaStore.MediaColumns.HEIGHT, mHeight);
            }

            if (!mNoMedia) {
                if (MediaFile.isVideoFileType(mFileType)) {
                    map.put(Video.Media.ARTIST, (mArtist != null && mArtist.length() > 0