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

Commit c2206a07 authored by Mike Lockwood's avatar Mike Lockwood
Browse files

Changes to support MediaProvider refactoring



Update table columns in MediaStore and adjust media scanner MTP support.

Change-Id: Ide41315a6d7650aadb703f93c7e022fc5c40d4dd
Signed-off-by: default avatarMike Lockwood <lockwood@android.com>
parent 0c2b04bb
Loading
Loading
Loading
Loading
+21 −25
Original line number Diff line number Diff line
@@ -254,13 +254,6 @@ public final class MediaStore {
         */
        public static final String MIME_TYPE = "mime_type";

        /**
         * The row ID in the MTP object table corresponding to this media file.
         * <P>Type: INTEGER</P>
         * @hide
         */
        public static final String MTP_OBJECT_ID = "object_id";

        /**
         * The MTP object handle of a newly transfered file.
         * Used to pass the new file's object handle through the media scanner
@@ -327,30 +320,33 @@ public final class MediaStore {
            public static final String PARENT = "parent";

            /**
             * Identifier for the media table containing the file.
             * Used internally by MediaProvider
             * <P>Type: INTEGER</P>
             * The MIME type of the file
             * <P>Type: TEXT</P>
             */
            public static final String MEDIA_TABLE = "media_table";
            public static final String MIME_TYPE = "mime_type";

            /**
             * The ID of the file in its media table.
             * <P>Type: INTEGER</P>
             * The title of the content
             * <P>Type: TEXT</P>
             */
            public static final String MEDIA_ID = "media_id";
        }
            public static final String TITLE = "title";

            /**
         * The MIME type of the file
             * The media type (audio, video, image or playlist)
             * of the file, or 0 for not a media file
             * <P>Type: TEXT</P>
             */
        public static final String MIME_TYPE = "mime_type";
            public static final String MEDIA_TYPE = "media_type";

            /**
         * The title of the content
         * <P>Type: TEXT</P>
             * Constants for MEDIA_TYPE
             */
        public static final String TITLE = "title";
            public static final int MEDIA_TYPE_NONE = 0;
            public static final int MEDIA_TYPE_IMAGE = 1;
            public static final int MEDIA_TYPE_AUDIO = 2;
            public static final int MEDIA_TYPE_VIDEO = 3;
            public static final int MEDIA_TYPE_PLAYLIST = 4;
        }
    }

    /**
+1 −131
Original line number Diff line number Diff line
@@ -695,7 +695,7 @@ public class MediaScanner
                }
            }
            long rowId = entry.mRowId;
            if (MediaFile.isAudioFileType(mFileType) && rowId == 0) {
            if (MediaFile.isAudioFileType(mFileType) && (rowId == 0 || mMtpObjectHandle != 0)) {
                // Only set these for new entries. For existing entries, they
                // may have been modified later, and we want to keep the current
                // values so that custom ringtones still show up in the ringtone
@@ -927,136 +927,6 @@ public class MediaScanner
                    c = null;
                }
            }

            // Read existing files from the audio table and update FileCacheEntry
            c = mMediaProvider.query(mAudioUri, MEDIA_PRESCAN_PROJECTION,
                    where, selectionArgs, null);
            if (c != null) {
                while (c.moveToNext()) {
                    long rowId = c.getLong(MEDIA_PRESCAN_ID_COLUMN_INDEX);
                    String path = c.getString(MEDIA_PRESCAN_PATH_COLUMN_INDEX);
                    long lastModified = c.getLong(MEDIA_PRESCAN_DATE_MODIFIED_COLUMN_INDEX);

                    // Only consider entries with absolute path names.
                    // This allows storing URIs in the database without the
                    // media scanner removing them.
                    if (path.startsWith("/")) {
                        String key = path;
                        if (mCaseInsensitivePaths) {
                            key = path.toLowerCase();
                        }
                        FileCacheEntry entry = mFileCache.get(path);
                        if (entry == null) {
                            mFileCache.put(key, new FileCacheEntry(mAudioUri, rowId, path,
                                    lastModified, 0));
                        } else {
                            // update the entry
                            entry.mTableUri = mAudioUri;
                            entry.mRowId = rowId;
                        }
                    }
                }
                c.close();
                c = null;
            }

            // Read existing files from the video table and update FileCacheEntry
            c = mMediaProvider.query(mVideoUri, MEDIA_PRESCAN_PROJECTION,
                    where, selectionArgs, null);
            if (c != null) {
                while (c.moveToNext()) {
                    long rowId = c.getLong(MEDIA_PRESCAN_ID_COLUMN_INDEX);
                    String path = c.getString(MEDIA_PRESCAN_PATH_COLUMN_INDEX);
                    long lastModified = c.getLong(MEDIA_PRESCAN_DATE_MODIFIED_COLUMN_INDEX);

                    // Only consider entries with absolute path names.
                    // This allows storing URIs in the database without the
                    // media scanner removing them.
                    if (path.startsWith("/")) {
                        String key = path;
                        if (mCaseInsensitivePaths) {
                            key = path.toLowerCase();
                        }
                        FileCacheEntry entry = mFileCache.get(path);
                        if (entry == null) {
                            mFileCache.put(key, new FileCacheEntry(mVideoUri, rowId, path,
                                    lastModified, 0));
                        } else {
                            // update the entry
                            entry.mTableUri = mVideoUri;
                            entry.mRowId = rowId;
                        }
                    }
                }
                c.close();
                c = null;
            }

            // Read existing files from the video table and update FileCacheEntry
            c = mMediaProvider.query(mImagesUri, MEDIA_PRESCAN_PROJECTION,
                    where, selectionArgs, null);
            if (c != null) {
                while (c.moveToNext()) {
                    long rowId = c.getLong(MEDIA_PRESCAN_ID_COLUMN_INDEX);
                    String path = c.getString(MEDIA_PRESCAN_PATH_COLUMN_INDEX);
                    long lastModified = c.getLong(MEDIA_PRESCAN_DATE_MODIFIED_COLUMN_INDEX);

                    // Only consider entries with absolute path names.
                    // This allows storing URIs in the database without the
                    // media scanner removing them.
                    if (path.startsWith("/")) {
                        String key = path;
                        if (mCaseInsensitivePaths) {
                            key = path.toLowerCase();
                        }
                        FileCacheEntry entry = mFileCache.get(path);
                        if (entry == null) {
                            mFileCache.put(key, new FileCacheEntry(mImagesUri, rowId, path,
                                    lastModified, 0));
                        } else {
                            // update the entry
                            entry.mTableUri = mImagesUri;
                            entry.mRowId = rowId;
                        }
                    }
                }
                c.close();
                c = null;
            }

            if (mProcessPlaylists) {
                // Read existing files from the playlists table and update FileCacheEntry
                c = mMediaProvider.query(mPlaylistsUri, MEDIA_PRESCAN_PROJECTION,
                        where, selectionArgs, null);
                if (c != null) {
                    while (c.moveToNext()) {
                        long rowId = c.getLong(MEDIA_PRESCAN_ID_COLUMN_INDEX);
                        String path = c.getString(MEDIA_PRESCAN_PATH_COLUMN_INDEX);
                        long lastModified = c.getLong(MEDIA_PRESCAN_DATE_MODIFIED_COLUMN_INDEX);

                        // Only consider entries with absolute path names.
                        // This allows storing URIs in the database without the
                        // media scanner removing them.
                        if (path.startsWith("/")) {
                            String key = path;
                            if (mCaseInsensitivePaths) {
                                key = path.toLowerCase();
                            }
                            FileCacheEntry entry = mFileCache.get(path);
                            if (entry == null) {
                                mFileCache.put(key, new FileCacheEntry(mPlaylistsUri, rowId, path,
                                        lastModified, 0));
                            } else {
                                // update the entry
                                entry.mTableUri = mPlaylistsUri;
                                entry.mRowId = rowId;
                            }
                        }
                    }
                    c.close();
                    c = null;
                }
            }
        }
        finally {
            if (c != null) {