Commit | Line | Data |
---|---|---|
a7bdce84 | 1 | From a75f5eb1c3f793200f12fe0c38ce83019b1cd16e Mon Sep 17 00:00:00 2001 |
6bcbafcd L |
2 | From: Nicholas Chum <nicholaschum@gmail.com> |
3 | Date: Sun, 17 Jul 2016 17:56:40 -0400 | |
c00f212d | 4 | Subject: [PATCH 26/39] N-Extras: AudioService: Allow system effect sounds to |
6bcbafcd L |
5 | be themed |
6 | ||
7 | This commit checks whether there is a preexisting file in the themed | |
8 | directory "/data/system/theme/audio/ui/" and if so, change the base | |
9 | file paths for the sound. If the file does not exist in the theme | |
10 | directory, then use the default sounds. | |
11 | ||
12 | At the current moment, this will require a soft reboot to work. | |
13 | ||
14 | Change-Id: I7666c2bd259443ccec442bf6059786bea3dc069e | |
15 | --- | |
16 | .../com/android/server/audio/AudioService.java | 26 +++++++++++++++++----- | |
17 | 1 file changed, 21 insertions(+), 5 deletions(-) | |
18 | ||
19 | diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java | |
5596c080 | 20 | index f5db48806de..c6144d0b0b9 100644 |
6bcbafcd L |
21 | --- a/services/core/java/com/android/server/audio/AudioService.java |
22 | +++ b/services/core/java/com/android/server/audio/AudioService.java | |
23 | @@ -123,6 +123,7 @@ import com.android.server.pm.UserManagerService; | |
24 | ||
25 | import org.xmlpull.v1.XmlPullParserException; | |
26 | ||
27 | +import java.io.File; | |
28 | import java.io.FileDescriptor; | |
29 | import java.io.IOException; | |
30 | import java.io.PrintWriter; | |
31 | @@ -281,6 +282,7 @@ public class AudioService extends IAudioService.Stub { | |
32 | ||
33 | /* Sound effect file names */ | |
34 | private static final String SOUND_EFFECTS_PATH = "/media/audio/ui/"; | |
35 | + private static final String SOUND_EFFECTS_THEMED_PATH = "/data/system/theme/audio/ui/"; | |
36 | private static final List<String> SOUND_EFFECT_FILES = new ArrayList<String>(); | |
37 | ||
38 | /* Sound effect file name mapping sound effect id (AudioManager.FX_xxx) to | |
39 | @@ -4679,9 +4681,16 @@ public class AudioService extends IAudioService.Stub { | |
40 | continue; | |
41 | } | |
42 | if (poolId[SOUND_EFFECT_FILES_MAP[effect][0]] == -1) { | |
43 | - String filePath = Environment.getRootDirectory() | |
44 | - + SOUND_EFFECTS_PATH | |
45 | - + SOUND_EFFECT_FILES.get(SOUND_EFFECT_FILES_MAP[effect][0]); | |
46 | + String filePath = ""; | |
47 | + File theme_file = new File(SOUND_EFFECTS_THEMED_PATH + | |
48 | + SOUND_EFFECT_FILES.get(SOUND_EFFECT_FILES_MAP[effect][0])); | |
49 | + if (theme_file.exists()) { | |
50 | + filePath = theme_file.getAbsolutePath(); | |
51 | + } else { | |
52 | + filePath = Environment.getRootDirectory() | |
53 | + + SOUND_EFFECTS_PATH | |
54 | + + SOUND_EFFECT_FILES.get(SOUND_EFFECT_FILES_MAP[effect][0]); | |
55 | + } | |
56 | int sampleId = mSoundPool.load(filePath, 0); | |
57 | if (sampleId <= 0) { | |
58 | Log.w(TAG, "Soundpool could not load file: "+filePath); | |
59 | @@ -4787,8 +4796,15 @@ public class AudioService extends IAudioService.Stub { | |
60 | } else { | |
61 | MediaPlayer mediaPlayer = new MediaPlayer(); | |
62 | try { | |
63 | - String filePath = Environment.getRootDirectory() + SOUND_EFFECTS_PATH + | |
64 | - SOUND_EFFECT_FILES.get(SOUND_EFFECT_FILES_MAP[effectType][0]); | |
65 | + String filePath = ""; | |
66 | + File theme_file = new File(SOUND_EFFECTS_THEMED_PATH + | |
67 | + SOUND_EFFECT_FILES.get(SOUND_EFFECT_FILES_MAP[effectType][0])); | |
68 | + if (theme_file.exists()) { | |
69 | + filePath = theme_file.getAbsolutePath(); | |
70 | + } else { | |
71 | + filePath = Environment.getRootDirectory() + SOUND_EFFECTS_PATH + | |
72 | + SOUND_EFFECT_FILES.get(SOUND_EFFECT_FILES_MAP[effectType][0]); | |
73 | + } | |
74 | mediaPlayer.setDataSource(filePath); | |
75 | mediaPlayer.setAudioStreamType(AudioSystem.STREAM_SYSTEM); | |
76 | mediaPlayer.prepare(); | |
77 | -- | |
5596c080 | 78 | 2.11.1 |
6bcbafcd | 79 |