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

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

Media scanner support for tracking files of arbitrary type.



The native media scanner no longer filters files based on file extension.
Audio, video, image and playlist files are handled as before, but non-media
files are now inserted into the "files" table, which was originally added
to support MTP.

Change-Id: I9053218fb6d2671a3bb181405c34442b94678afc
Signed-off-by: default avatarMike Lockwood <lockwood@android.com>
parent 6d000d4e
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -339,6 +339,18 @@ public final class MediaStore {
             */
            public static final String MEDIA_ID = "media_id";
        }

        /**
         * The MIME type of the file
         * <P>Type: TEXT</P>
         */
        public static final String MIME_TYPE = "mime_type";

        /**
         * The title of the content
         * <P>Type: TEXT</P>
         */
        public static final String TITLE = "title";
    }

    /**
+3 −5
Original line number Diff line number Diff line
@@ -38,8 +38,7 @@ struct MediaScanner {

    typedef bool (*ExceptionCheck)(void* env);
    virtual status_t processDirectory(
            const char *path, const char *extensions,
            MediaScannerClient &client,
            const char *path, MediaScannerClient &client,
            ExceptionCheck exceptionCheck, void *exceptionEnv);

    void setLocale(const char *locale);
@@ -55,9 +54,8 @@ private:
    char *mLocale;

    status_t doProcessDirectory(
            char *path, int pathRemaining, const char *extensions,
            MediaScannerClient &client, ExceptionCheck exceptionCheck,
            void *exceptionEnv);
            char *path, int pathRemaining, MediaScannerClient &client,
            ExceptionCheck exceptionCheck, void *exceptionEnv);

    MediaScanner(const MediaScanner &);
    MediaScanner &operator=(const MediaScanner &);
+29 −20
Original line number Diff line number Diff line
@@ -34,8 +34,6 @@ import java.util.List;
 * {@hide}
 */
public class MediaFile {
    // comma separated list of all file extensions supported by the media scanner
    public final static String sFileExtensions;

    // Audio file types
    public static final int FILE_TYPE_MP3     = 1;
@@ -191,18 +189,6 @@ public class MediaFile {
        addFileType("M3U", FILE_TYPE_M3U, "audio/x-mpegurl", MtpConstants.FORMAT_M3U_PLAYLIST);
        addFileType("PLS", FILE_TYPE_PLS, "audio/x-scpls", MtpConstants.FORMAT_PLS_PLAYLIST);
        addFileType("WPL", FILE_TYPE_WPL, "application/vnd.ms-wpl", MtpConstants.FORMAT_WPL_PLAYLIST);

        // compute file extensions list for native Media Scanner
        StringBuilder builder = new StringBuilder();
        Iterator<String> iterator = sFileTypeMap.keySet().iterator();
        
        while (iterator.hasNext()) {
            if (builder.length() > 0) {
                builder.append(',');
            }
            builder.append(iterator.next());
        } 
        sFileExtensions = builder.toString();
    }

    public static boolean isAudioFileType(int fileType) {
@@ -234,11 +220,34 @@ public class MediaFile {
        return sFileTypeMap.get(path.substring(lastDot + 1).toUpperCase());
    }

    // generates a title based on file name
    public static String getFileTitle(String path) {
        // extract file name after last slash
        int lastSlash = path.lastIndexOf('/');
        if (lastSlash >= 0) {
            lastSlash++;
            if (lastSlash < path.length()) {
                path = path.substring(lastSlash);
            }
        }
        // truncate the file extension (if any)
        int lastDot = path.lastIndexOf('.');
        if (lastDot > 0) {
            path = path.substring(0, lastDot);
        }
        return path;
    }

    public static int getFileTypeForMimeType(String mimeType) {
        Integer value = sMimeTypeMap.get(mimeType);
        return (value == null ? 0 : value.intValue());
    }

    public static String getMimeTypeForFile(String path) {
        MediaFileType mediaFileType = getFileType(path);
        return (mediaFileType == null ? null : mediaFileType.mimeType);
    }

    public static int getFormatCode(String fileName, String mimeType) {
        if (mimeType != null) {
            Integer value = sMimeTypeToFormatMap.get(mimeType);
+191 −171

File changed.

Preview size limit exceeded, changes collapsed.

+1 −1
Original line number Diff line number Diff line
@@ -170,7 +170,7 @@ public class MtpDatabase {
                    Log.e(TAG, "RemoteException in endSendObject", e);
                }
            } else {
                Uri uri = mMediaScanner.scanMtpFile(path, mVolumeName, handle, format);
                mMediaScanner.scanMtpFile(path, mVolumeName, handle, format);
            }
        } else {
            deleteFile(handle);
Loading