summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Mike Lockwood <lockwood@android.com> 2011-10-20 12:54:05 -0400
committer Mike Lockwood <lockwood@google.com> 2012-02-10 09:01:28 -0800
commitcbdb49dc5e1b993a0bc5c68dbfb9486bfa0cd762 (patch)
treee62c37fec71b48b9ecb7fedaca997d9b7214a447
parentc62242a55a5cfb82f69c7db5208e90667da7ec56 (diff)
Simple master volume support
Still needs integration with Settings (for persistence) and VolumePanel UI. Change-Id: I9eca92c4b1ef2df2564411006a35753ab9618dce Signed-off-by: Mike Lockwood <lockwood@android.com>
-rw-r--r--core/jni/android_media_AudioSystem.cpp36
-rwxr-xr-xcore/res/res/values/config.xml4
-rw-r--r--core/res/res/values/public.xml1
-rw-r--r--media/java/android/media/AudioManager.java75
-rw-r--r--media/java/android/media/AudioService.java20
-rw-r--r--media/java/android/media/AudioSystem.java4
-rw-r--r--media/java/android/media/IAudioService.aidl6
7 files changed, 125 insertions, 21 deletions
diff --git a/core/jni/android_media_AudioSystem.cpp b/core/jni/android_media_AudioSystem.cpp
index 6b4c5e8e5f10..31c5ed482a3d 100644
--- a/core/jni/android_media_AudioSystem.cpp
+++ b/core/jni/android_media_AudioSystem.cpp
@@ -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)
{
@@ -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},
};
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index 0511b7501328..adde69b6c590 100755
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -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>
diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml
index 1b9164322be2..19e852e477ac 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -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" />
diff --git a/media/java/android/media/AudioManager.java b/media/java/android/media/AudioManager.java
index 78eb89f3dc2a..d13117627e46 100644
--- a/media/java/android/media/AudioManager.java
+++ b/media/java/android/media/AudioManager.java
@@ -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";
/**
@@ -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()
@@ -382,8 +385,12 @@ 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);
+ }
}
}
@@ -399,16 +406,23 @@ public class AudioManager {
* responsive to the user.
*/
int flags = FLAG_SHOW_UI | FLAG_VIBRATE;
- if (mVolumeControlStream != -1) {
- stream = mVolumeControlStream;
- flags |= FLAG_FORCE_STREAM;
+ if (mUseMasterVolume) {
+ adjustMasterVolume(
+ keyCode == KeyEvent.KEYCODE_VOLUME_UP
+ ? ADJUST_RAISE
+ : ADJUST_LOWER);
+ } else {
+ if (mVolumeControlStream != -1) {
+ stream = mVolumeControlStream;
+ flags |= FLAG_FORCE_STREAM;
+ }
+ adjustSuggestedStreamVolume(
+ keyCode == KeyEvent.KEYCODE_VOLUME_UP
+ ? ADJUST_RAISE
+ : ADJUST_LOWER,
+ stream,
+ flags);
}
- adjustSuggestedStreamVolume(
- keyCode == KeyEvent.KEYCODE_VOLUME_UP
- ? ADJUST_RAISE
- : ADJUST_LOWER,
- stream,
- flags);
break;
case KeyEvent.KEYCODE_VOLUME_MUTE:
// TODO: Actually handle MUTE.
@@ -427,15 +441,21 @@ 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.
*/
- int flags = FLAG_PLAY_SOUND;
- if (mVolumeControlStream != -1) {
- stream = mVolumeControlStream;
- flags |= FLAG_FORCE_STREAM;
+ if (mUseMasterVolume) {
+ if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
+ adjustMasterVolume(ADJUST_SAME);
+ }
+ } else {
+ int flags = FLAG_PLAY_SOUND;
+ if (mVolumeControlStream != -1) {
+ stream = mVolumeControlStream;
+ flags |= FLAG_FORCE_STREAM;
+ }
+ adjustSuggestedStreamVolume(
+ ADJUST_SAME,
+ stream,
+ flags);
}
- adjustSuggestedStreamVolume(
- ADJUST_SAME,
- stream,
- flags);
mVolumeKeyUpTime = SystemClock.uptimeMillis();
break;
@@ -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);
}
}
diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java
index 13e3982541ac..be409b269c8e 100644
--- a/media/java/android/media/AudioService.java
+++ b/media/java/android/media/AudioService.java
@@ -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;
@@ -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);
diff --git a/media/java/android/media/AudioSystem.java b/media/java/android/media/AudioSystem.java
index 308049798a8b..d354cdb77cba 100644
--- a/media/java/android/media/AudioSystem.java
+++ b/media/java/android/media/AudioSystem.java
@@ -318,5 +318,9 @@ public class AudioSystem
public static native int initStreamVolume(int stream, int indexMin, int indexMax);
public static native int setStreamVolumeIndex(int stream, int index, int device);
public static native int getStreamVolumeIndex(int stream, int device);
+ public static native int setMasterVolume(float value);
+ public static native float getMasterVolume();
+ public static native int setMasterMute(boolean mute);
+ public static native boolean getMasterMute();
public static native int getDevicesForStream(int stream);
}
diff --git a/media/java/android/media/IAudioService.aidl b/media/java/android/media/IAudioService.aidl
index 5294d36ae03b..fd15c692eda9 100644
--- a/media/java/android/media/IAudioService.aidl
+++ b/media/java/android/media/IAudioService.aidl
@@ -30,9 +30,11 @@ interface IAudioService {
void adjustVolume(int direction, int flags);
void adjustSuggestedStreamVolume(int direction, int suggestedStreamType, int flags);
-
+
void adjustStreamVolume(int streamType, int direction, int flags);
-
+
+ void adjustMasterVolume(int direction);
+
void setStreamVolume(int streamType, int index, int flags);
void setStreamSolo(int streamType, boolean state, IBinder cb);