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

Commit c31033f4 authored by Jaekyun Seok's avatar Jaekyun Seok
Browse files

Read media files from /product/media/audio

Bug: 64195575
Test: tested reading media files from /product/media/audio after moving
files from /system/media/audio to /product/media/audio

Change-Id: Ic690965e2b5f0e237d21df1db0fd0354a76d7c90
parent 1713d9e9
Loading
Loading
Loading
Loading
+18 −9
Original line number Diff line number Diff line
@@ -47,11 +47,16 @@ public class MediaActionSound {
    private SoundPool mSoundPool;
    private SoundState[] mSounds;

    private static final String[] SOUND_DIRS = {
        "/product/media/audio/ui/",
        "/system/media/audio/ui/",
    };

    private static final String[] SOUND_FILES = {
        "/system/media/audio/ui/camera_click.ogg",
        "/system/media/audio/ui/camera_focus.ogg",
        "/system/media/audio/ui/VideoRecord.ogg",
        "/system/media/audio/ui/VideoStop.ogg"
        "camera_click.ogg",
        "camera_focus.ogg",
        "VideoRecord.ogg",
        "VideoStop.ogg"
    };

    private static final String TAG = "MediaActionSound";
@@ -132,13 +137,17 @@ public class MediaActionSound {
    }

    private int loadSound(SoundState sound) {
        int id = mSoundPool.load(SOUND_FILES[sound.name], 1);
        final String soundFileName = SOUND_FILES[sound.name];
        for (String soundDir : SOUND_DIRS) {
            int id = mSoundPool.load(soundDir + soundFileName, 1);
            if (id > 0) {
                sound.state = STATE_LOADING;
                sound.id = id;
        }
                return id;
            }
        }
        return 0;
    }

    /**
     * Preload a predefined platform sound to minimize latency when the sound is
+5 −1
Original line number Diff line number Diff line
@@ -158,6 +158,7 @@ public class MediaScanner implements AutoCloseable {
    public static final String SCANNED_BUILD_PREFS_NAME = "MediaScanBuild";
    public static final String LAST_INTERNAL_SCAN_FINGERPRINT = "lastScanFingerprint";
    private static final String SYSTEM_SOUNDS_DIR = "/system/media/audio";
    private static final String PRODUCT_SOUNDS_DIR = "/product/media/audio";
    private static String sLastInternalScanFingerprint;

    private static final String[] ID3_GENRES = {
@@ -1153,7 +1154,10 @@ public class MediaScanner implements AutoCloseable {
    private static boolean isSystemSoundWithMetadata(String path) {
        if (path.startsWith(SYSTEM_SOUNDS_DIR + ALARMS_DIR)
                || path.startsWith(SYSTEM_SOUNDS_DIR + RINGTONES_DIR)
                || path.startsWith(SYSTEM_SOUNDS_DIR + NOTIFICATIONS_DIR)) {
                || path.startsWith(SYSTEM_SOUNDS_DIR + NOTIFICATIONS_DIR)
                || path.startsWith(PRODUCT_SOUNDS_DIR + ALARMS_DIR)
                || path.startsWith(PRODUCT_SOUNDS_DIR + RINGTONES_DIR)
                || path.startsWith(PRODUCT_SOUNDS_DIR + NOTIFICATIONS_DIR)) {
            return true;
        }
        return false;
+13 −5
Original line number Diff line number Diff line
@@ -133,6 +133,7 @@ import com.android.server.pm.UserManagerService;

import org.xmlpull.v1.XmlPullParserException;

import java.io.File;
import java.io.FileDescriptor;
import java.io.IOException;
import java.io.PrintWriter;
@@ -4767,6 +4768,16 @@ public class AudioService extends IAudioService.Stub
            Settings.Global.putInt(mContentResolver, Settings.Global.MODE_RINGER, ringerMode);
        }

        private String getSoundEffectFilePath(int effectType) {
            String filePath = Environment.getProductDirectory() + SOUND_EFFECTS_PATH
                    + SOUND_EFFECT_FILES.get(SOUND_EFFECT_FILES_MAP[effectType][0]);
            if (!new File(filePath).isFile()) {
                filePath = Environment.getRootDirectory() + SOUND_EFFECTS_PATH
                        + SOUND_EFFECT_FILES.get(SOUND_EFFECT_FILES_MAP[effectType][0]);
            }
            return filePath;
        }

        private boolean onLoadSoundEffects() {
            int status;

@@ -4836,9 +4847,7 @@ public class AudioService extends IAudioService.Stub
                        continue;
                    }
                    if (poolId[SOUND_EFFECT_FILES_MAP[effect][0]] == -1) {
                        String filePath = Environment.getRootDirectory()
                                + SOUND_EFFECTS_PATH
                                + SOUND_EFFECT_FILES.get(SOUND_EFFECT_FILES_MAP[effect][0]);
                        String filePath = getSoundEffectFilePath(effect);
                        int sampleId = mSoundPool.load(filePath, 0);
                        if (sampleId <= 0) {
                            Log.w(TAG, "Soundpool could not load file: "+filePath);
@@ -4944,8 +4953,7 @@ public class AudioService extends IAudioService.Stub
                } else {
                    MediaPlayer mediaPlayer = new MediaPlayer();
                    try {
                        String filePath = Environment.getRootDirectory() + SOUND_EFFECTS_PATH +
                                    SOUND_EFFECT_FILES.get(SOUND_EFFECT_FILES_MAP[effectType][0]);
                        String filePath = getSoundEffectFilePath(effectType);
                        mediaPlayer.setDataSource(filePath);
                        mediaPlayer.setAudioStreamType(AudioSystem.STREAM_SYSTEM);
                        mediaPlayer.prepare();