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

Commit c861411d authored by Marco Nelissen's avatar Marco Nelissen
Browse files

Bypass emulated storage for metadata extraction

b/6543148

Change-Id: Ic65957870199a2592ebe53b32517166f96e48ef2
parent 218eb9c0
Loading
Loading
Loading
Loading
+20 −4
Original line number Original line Diff line number Diff line
@@ -314,6 +314,7 @@ public class MediaScanner
    private int mMtpObjectHandle;
    private int mMtpObjectHandle;


    private final String mExternalStoragePath;
    private final String mExternalStoragePath;
    private final boolean mExternalIsEmulated;


    /** whether to use bulk inserts or individual inserts for each item */
    /** whether to use bulk inserts or individual inserts for each item */
    private static final boolean ENABLE_BULK_INSERTS = true;
    private static final boolean ENABLE_BULK_INSERTS = true;
@@ -392,6 +393,7 @@ public class MediaScanner
        setDefaultRingtoneFileNames();
        setDefaultRingtoneFileNames();


        mExternalStoragePath = Environment.getExternalStorageDirectory().getAbsolutePath();
        mExternalStoragePath = Environment.getExternalStorageDirectory().getAbsolutePath();
        mExternalIsEmulated = Environment.isExternalStorageEmulated();
        //mClient.testGenreNameConverter();
        //mClient.testGenreNameConverter();
    }
    }


@@ -543,13 +545,28 @@ public class MediaScanner
                        boolean music = (lowpath.indexOf(MUSIC_DIR) > 0) ||
                        boolean music = (lowpath.indexOf(MUSIC_DIR) > 0) ||
                            (!ringtones && !notifications && !alarms && !podcasts);
                            (!ringtones && !notifications && !alarms && !podcasts);


                        boolean isaudio = MediaFile.isAudioFileType(mFileType);
                        boolean isvideo = MediaFile.isVideoFileType(mFileType);
                        boolean isimage = MediaFile.isImageFileType(mFileType);

                        if (isaudio || isvideo || isimage) {
                            if (mExternalIsEmulated && path.startsWith(mExternalStoragePath)) {
                                // try to rewrite the path to bypass the sd card fuse layer
                                String directPath = Environment.getMediaStorageDirectory() +
                                        path.substring(mExternalStoragePath.length());
                                File f = new File(directPath);
                                if (f.exists()) {
                                    path = directPath;
                                }
                            }
                        }

                        // we only extract metadata for audio and video files
                        // we only extract metadata for audio and video files
                        if (MediaFile.isAudioFileType(mFileType)
                        if (isaudio || isvideo) {
                                || MediaFile.isVideoFileType(mFileType)) {
                            processFile(path, mimeType, this);
                            processFile(path, mimeType, this);
                        }
                        }


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


@@ -972,7 +989,6 @@ public class MediaScanner
                    }
                    }
                    values.put(FileColumns.MEDIA_TYPE, mediaType);
                    values.put(FileColumns.MEDIA_TYPE, mediaType);
                }
                }

                mMediaProvider.update(result, values, null, null);
                mMediaProvider.update(result, values, null, null);
            }
            }