Loading core/jni/android_media_AudioSystem.cpp +36 −0 Original line number Diff line number Diff line Loading @@ -204,6 +204,38 @@ android_media_AudioSystem_getStreamVolumeIndex(JNIEnv *env, return index; } static int android_media_AudioSystem_setMasterVolume(JNIEnv *env, jobject thiz, jfloat value) { return check_AudioSystem_Command(AudioSystem::setMasterVolume(value)); } static jfloat android_media_AudioSystem_getMasterVolume(JNIEnv *env, jobject thiz) { float value; if (AudioSystem::getMasterVolume(&value) != NO_ERROR) { value = -1.0; } return value; } static int android_media_AudioSystem_setMasterMute(JNIEnv *env, jobject thiz, jboolean mute) { return check_AudioSystem_Command(AudioSystem::setMasterMute(mute)); } static jfloat android_media_AudioSystem_getMasterMute(JNIEnv *env, jobject thiz) { bool mute; if (AudioSystem::getMasterMute(&mute) != NO_ERROR) { mute = false; } return mute; } static jint android_media_AudioSystem_getDevicesForStream(JNIEnv *env, jobject thiz, jint stream) { Loading @@ -226,6 +258,10 @@ static JNINativeMethod gMethods[] = { {"initStreamVolume", "(III)I", (void *)android_media_AudioSystem_initStreamVolume}, {"setStreamVolumeIndex","(III)I", (void *)android_media_AudioSystem_setStreamVolumeIndex}, {"getStreamVolumeIndex","(II)I", (void *)android_media_AudioSystem_getStreamVolumeIndex}, {"setMasterVolume", "(F)I", (void *)android_media_AudioSystem_setMasterVolume}, {"getMasterVolume", "()F", (void *)android_media_AudioSystem_getMasterVolume}, {"setMasterMute", "(Z)I", (void *)android_media_AudioSystem_setMasterMute}, {"getMasterMute", "()Z", (void *)android_media_AudioSystem_getMasterMute}, {"getDevicesForStream", "(I)I", (void *)android_media_AudioSystem_getDevicesForStream}, }; Loading core/res/res/values/config.xml +4 −0 Original line number Diff line number Diff line Loading @@ -61,6 +61,10 @@ As of Honeycomb, blurring is not supported anymore. --> <bool name="config_sf_slowBlur">true</bool> <!-- Flag indicating that the media framework should allow changing master volume stream and nothing else . --> <bool name="config_useMasterVolume">false</bool> <!-- The duration (in milliseconds) of a short animation. --> <integer name="config_shortAnimTime">200</integer> Loading core/res/res/values/public.xml +1 −0 Original line number Diff line number Diff line Loading @@ -234,6 +234,7 @@ <java-symbol type="bool" name="preferences_prefer_dual_pane" /> <java-symbol type="bool" name="skip_restoring_network_selection" /> <java-symbol type="bool" name="split_action_bar_is_narrow" /> <java-symbol type="bool" name="config_useMasterVolume" /> <java-symbol type="integer" name="config_cursorWindowSize" /> <java-symbol type="integer" name="config_longPressOnPowerBehavior" /> Loading media/java/android/media/AudioManager.java +56 −19 Original line number Diff line number Diff line Loading @@ -48,6 +48,7 @@ public class AudioManager { private final Context mContext; private long mVolumeKeyUpTime; private int mVolumeControlStream = -1; private final boolean mUseMasterVolume; private static String TAG = "AudioManager"; /** Loading Loading @@ -354,6 +355,8 @@ public class AudioManager { */ public AudioManager(Context context) { mContext = context; mUseMasterVolume = mContext.getResources().getBoolean( com.android.internal.R.bool.config_useMasterVolume); } private static IAudioService getService() Loading Loading @@ -382,10 +385,14 @@ public class AudioManager { * The user has hit another key during the delay (e.g., 300ms) * since the last volume key up, so cancel any sounds. */ adjustSuggestedStreamVolume(AudioManager.ADJUST_SAME, if (mUseMasterVolume) { adjustMasterVolume(ADJUST_SAME); } else { adjustSuggestedStreamVolume(ADJUST_SAME, stream, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE); } } } /** * @hide Loading @@ -399,6 +406,12 @@ public class AudioManager { * responsive to the user. */ int flags = FLAG_SHOW_UI | FLAG_VIBRATE; if (mUseMasterVolume) { adjustMasterVolume( keyCode == KeyEvent.KEYCODE_VOLUME_UP ? ADJUST_RAISE : ADJUST_LOWER); } else { if (mVolumeControlStream != -1) { stream = mVolumeControlStream; flags |= FLAG_FORCE_STREAM; Loading @@ -409,6 +422,7 @@ public class AudioManager { : ADJUST_LOWER, stream, flags); } break; case KeyEvent.KEYCODE_VOLUME_MUTE: // TODO: Actually handle MUTE. Loading @@ -427,6 +441,11 @@ public class AudioManager { * Play a sound. This is done on key up since we don't want the * sound to play when a user holds down volume down to mute. */ if (mUseMasterVolume) { if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { adjustMasterVolume(ADJUST_SAME); } } else { int flags = FLAG_PLAY_SOUND; if (mVolumeControlStream != -1) { stream = mVolumeControlStream; Loading @@ -436,6 +455,7 @@ public class AudioManager { ADJUST_SAME, stream, flags); } mVolumeKeyUpTime = SystemClock.uptimeMillis(); break; Loading Loading @@ -518,7 +538,24 @@ public class AudioManager { try { service.adjustSuggestedStreamVolume(direction, suggestedStreamType, flags); } catch (RemoteException e) { Log.e(TAG, "Dead object in adjustVolume", e); Log.e(TAG, "Dead object in adjustSuggestedStreamVolume", e); } } /** * Adjusts the master volume for the device's audio amplifier. * <p> * * @param direction The direction to adjust the volume. One of * {@link #ADJUST_LOWER}, {@link #ADJUST_RAISE}, or * {@link #ADJUST_SAME}. */ private void adjustMasterVolume(int direction) { IAudioService service = getService(); try { service.adjustMasterVolume(direction); } catch (RemoteException e) { Log.e(TAG, "Dead object in adjustMasterVolume", e); } } Loading media/java/android/media/AudioService.java +20 −0 Original line number Diff line number Diff line Loading @@ -136,6 +136,9 @@ public class AudioService extends IAudioService.Stub { // Timeout for connection to bluetooth headset service private static final int BT_HEADSET_CNCT_TIMEOUT_MS = 3000; // Amount to raise/lower master volume // FIXME - this should probably be in a resource private static final float MASTER_VOLUME_INCREMENT = 0.05f; /** @see AudioSystemThread */ private AudioSystemThread mAudioSystemThread; Loading Loading @@ -602,6 +605,23 @@ public class AudioService extends IAudioService.Stub { sendVolumeUpdate(streamType, oldIndex, index, flags); } /** @see AudioManager#adjustMasterVolume(int) */ public void adjustMasterVolume(int direction) { ensureValidDirection(direction); float volume = AudioSystem.getMasterVolume(); if (volume >= 0.0) { if (direction == AudioManager.ADJUST_RAISE) { volume += MASTER_VOLUME_INCREMENT; if (volume > 1.0f) volume = 1.0f; } else if (direction == AudioManager.ADJUST_LOWER) { volume -= MASTER_VOLUME_INCREMENT; if (volume < 0.0f) volume = 0.0f; } AudioSystem.setMasterVolume(volume); } } /** @see AudioManager#setStreamVolume(int, int, int) */ public void setStreamVolume(int streamType, int index, int flags) { ensureValidStreamType(streamType); Loading Loading
core/jni/android_media_AudioSystem.cpp +36 −0 Original line number Diff line number Diff line Loading @@ -204,6 +204,38 @@ android_media_AudioSystem_getStreamVolumeIndex(JNIEnv *env, return index; } static int android_media_AudioSystem_setMasterVolume(JNIEnv *env, jobject thiz, jfloat value) { return check_AudioSystem_Command(AudioSystem::setMasterVolume(value)); } static jfloat android_media_AudioSystem_getMasterVolume(JNIEnv *env, jobject thiz) { float value; if (AudioSystem::getMasterVolume(&value) != NO_ERROR) { value = -1.0; } return value; } static int android_media_AudioSystem_setMasterMute(JNIEnv *env, jobject thiz, jboolean mute) { return check_AudioSystem_Command(AudioSystem::setMasterMute(mute)); } static jfloat android_media_AudioSystem_getMasterMute(JNIEnv *env, jobject thiz) { bool mute; if (AudioSystem::getMasterMute(&mute) != NO_ERROR) { mute = false; } return mute; } static jint android_media_AudioSystem_getDevicesForStream(JNIEnv *env, jobject thiz, jint stream) { Loading @@ -226,6 +258,10 @@ static JNINativeMethod gMethods[] = { {"initStreamVolume", "(III)I", (void *)android_media_AudioSystem_initStreamVolume}, {"setStreamVolumeIndex","(III)I", (void *)android_media_AudioSystem_setStreamVolumeIndex}, {"getStreamVolumeIndex","(II)I", (void *)android_media_AudioSystem_getStreamVolumeIndex}, {"setMasterVolume", "(F)I", (void *)android_media_AudioSystem_setMasterVolume}, {"getMasterVolume", "()F", (void *)android_media_AudioSystem_getMasterVolume}, {"setMasterMute", "(Z)I", (void *)android_media_AudioSystem_setMasterMute}, {"getMasterMute", "()Z", (void *)android_media_AudioSystem_getMasterMute}, {"getDevicesForStream", "(I)I", (void *)android_media_AudioSystem_getDevicesForStream}, }; Loading
core/res/res/values/config.xml +4 −0 Original line number Diff line number Diff line Loading @@ -61,6 +61,10 @@ As of Honeycomb, blurring is not supported anymore. --> <bool name="config_sf_slowBlur">true</bool> <!-- Flag indicating that the media framework should allow changing master volume stream and nothing else . --> <bool name="config_useMasterVolume">false</bool> <!-- The duration (in milliseconds) of a short animation. --> <integer name="config_shortAnimTime">200</integer> Loading
core/res/res/values/public.xml +1 −0 Original line number Diff line number Diff line Loading @@ -234,6 +234,7 @@ <java-symbol type="bool" name="preferences_prefer_dual_pane" /> <java-symbol type="bool" name="skip_restoring_network_selection" /> <java-symbol type="bool" name="split_action_bar_is_narrow" /> <java-symbol type="bool" name="config_useMasterVolume" /> <java-symbol type="integer" name="config_cursorWindowSize" /> <java-symbol type="integer" name="config_longPressOnPowerBehavior" /> Loading
media/java/android/media/AudioManager.java +56 −19 Original line number Diff line number Diff line Loading @@ -48,6 +48,7 @@ public class AudioManager { private final Context mContext; private long mVolumeKeyUpTime; private int mVolumeControlStream = -1; private final boolean mUseMasterVolume; private static String TAG = "AudioManager"; /** Loading Loading @@ -354,6 +355,8 @@ public class AudioManager { */ public AudioManager(Context context) { mContext = context; mUseMasterVolume = mContext.getResources().getBoolean( com.android.internal.R.bool.config_useMasterVolume); } private static IAudioService getService() Loading Loading @@ -382,10 +385,14 @@ public class AudioManager { * The user has hit another key during the delay (e.g., 300ms) * since the last volume key up, so cancel any sounds. */ adjustSuggestedStreamVolume(AudioManager.ADJUST_SAME, if (mUseMasterVolume) { adjustMasterVolume(ADJUST_SAME); } else { adjustSuggestedStreamVolume(ADJUST_SAME, stream, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE); } } } /** * @hide Loading @@ -399,6 +406,12 @@ public class AudioManager { * responsive to the user. */ int flags = FLAG_SHOW_UI | FLAG_VIBRATE; if (mUseMasterVolume) { adjustMasterVolume( keyCode == KeyEvent.KEYCODE_VOLUME_UP ? ADJUST_RAISE : ADJUST_LOWER); } else { if (mVolumeControlStream != -1) { stream = mVolumeControlStream; flags |= FLAG_FORCE_STREAM; Loading @@ -409,6 +422,7 @@ public class AudioManager { : ADJUST_LOWER, stream, flags); } break; case KeyEvent.KEYCODE_VOLUME_MUTE: // TODO: Actually handle MUTE. Loading @@ -427,6 +441,11 @@ public class AudioManager { * Play a sound. This is done on key up since we don't want the * sound to play when a user holds down volume down to mute. */ if (mUseMasterVolume) { if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { adjustMasterVolume(ADJUST_SAME); } } else { int flags = FLAG_PLAY_SOUND; if (mVolumeControlStream != -1) { stream = mVolumeControlStream; Loading @@ -436,6 +455,7 @@ public class AudioManager { ADJUST_SAME, stream, flags); } mVolumeKeyUpTime = SystemClock.uptimeMillis(); break; Loading Loading @@ -518,7 +538,24 @@ public class AudioManager { try { service.adjustSuggestedStreamVolume(direction, suggestedStreamType, flags); } catch (RemoteException e) { Log.e(TAG, "Dead object in adjustVolume", e); Log.e(TAG, "Dead object in adjustSuggestedStreamVolume", e); } } /** * Adjusts the master volume for the device's audio amplifier. * <p> * * @param direction The direction to adjust the volume. One of * {@link #ADJUST_LOWER}, {@link #ADJUST_RAISE}, or * {@link #ADJUST_SAME}. */ private void adjustMasterVolume(int direction) { IAudioService service = getService(); try { service.adjustMasterVolume(direction); } catch (RemoteException e) { Log.e(TAG, "Dead object in adjustMasterVolume", e); } } Loading
media/java/android/media/AudioService.java +20 −0 Original line number Diff line number Diff line Loading @@ -136,6 +136,9 @@ public class AudioService extends IAudioService.Stub { // Timeout for connection to bluetooth headset service private static final int BT_HEADSET_CNCT_TIMEOUT_MS = 3000; // Amount to raise/lower master volume // FIXME - this should probably be in a resource private static final float MASTER_VOLUME_INCREMENT = 0.05f; /** @see AudioSystemThread */ private AudioSystemThread mAudioSystemThread; Loading Loading @@ -602,6 +605,23 @@ public class AudioService extends IAudioService.Stub { sendVolumeUpdate(streamType, oldIndex, index, flags); } /** @see AudioManager#adjustMasterVolume(int) */ public void adjustMasterVolume(int direction) { ensureValidDirection(direction); float volume = AudioSystem.getMasterVolume(); if (volume >= 0.0) { if (direction == AudioManager.ADJUST_RAISE) { volume += MASTER_VOLUME_INCREMENT; if (volume > 1.0f) volume = 1.0f; } else if (direction == AudioManager.ADJUST_LOWER) { volume -= MASTER_VOLUME_INCREMENT; if (volume < 0.0f) volume = 0.0f; } AudioSystem.setMasterVolume(volume); } } /** @see AudioManager#setStreamVolume(int, int, int) */ public void setStreamVolume(int streamType, int index, int flags) { ensureValidStreamType(streamType); Loading