diff options
author | Yao Chen <yaochen@google.com> | 2016-04-08 11:33:47 -0700 |
---|---|---|
committer | Yao Chen <yaochen@google.com> | 2016-04-18 16:58:14 -0700 |
commit | c4d442f4a0d3acf90b1c7a1dd7c222a8f32a193f (patch) | |
tree | 9a4681b75173c143dbd2cf94fda4521bbbcea7a1 /car-lib/src/android/car/media | |
parent | 57708444f4bdc623339227766335f56ed666f85a (diff) | |
download | Car-c4d442f4a0d3acf90b1c7a1dd7c222a8f32a193f.tar.gz |
Add CarVolumeService
Things added in this cl:
+ Hook up hardware volume keys to CarVolumeService to directly update
volume for current audio context.
+ Added volume control apis in AudioManager, and the real implementation
is done in CarVolumeService
+ The volume updates from car is broadcast to listeners through
IVolumeController api which is already in framework. SystemUI is using
this api to listen to volume changes (through AudioManager).
+ Added new permission for volume controls
Main TODOs left:
+ Multi stream playing at the same time. This can be done through
adjustign software mixer gain on Android side. Utility functions to
compute the gain is added in VolumeUtils, but it's not used yet in
CarVolumeService.
+ Hook up with Settings so per stream volume can be persisted across
multiple boots.
Bug: 27595951
Change-Id: I3a63e423d4e0a347215af65e79926212e4503d1b
Diffstat (limited to 'car-lib/src/android/car/media')
-rw-r--r-- | car-lib/src/android/car/media/CarAudioManager.java | 102 | ||||
-rw-r--r-- | car-lib/src/android/car/media/ICarAudio.aidl | 6 |
2 files changed, 108 insertions, 0 deletions
diff --git a/car-lib/src/android/car/media/CarAudioManager.java b/car-lib/src/android/car/media/CarAudioManager.java index 0a92c045d1..be4bfba89d 100644 --- a/car-lib/src/android/car/media/CarAudioManager.java +++ b/car-lib/src/android/car/media/CarAudioManager.java @@ -16,13 +16,18 @@ package android.car.media; import android.annotation.IntDef; +import android.annotation.SystemApi; +import android.car.CarLibLog; +import android.car.CarNotConnectedException; import android.content.Context; import android.media.AudioAttributes; import android.media.AudioManager; import android.media.AudioManager.OnAudioFocusChangeListener; +import android.media.IVolumeController; import android.os.IBinder; import android.os.RemoteException; import android.car.CarManagerBase; +import android.util.Log; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -127,6 +132,103 @@ public class CarAudioManager implements CarManagerBase { return mAudioManager.abandonAudioFocus(l, aa); } + /** + * Sets the volume index for a particular stream. + * + * Requires {@link android.car.Car.PERMISSION_CAR_CONTROL_AUDIO_VOLUME} permission. + * + * @param streamType The stream whose volume index should be set. + * @param index The volume index to set. See + * {@link #getStreamMaxVolume(int)} for the largest valid value. + * @param flags One or more flags (e.g., {@link android.media.AudioManager#FLAG_SHOW_UI}, + * {@link android.media.AudioManager#FLAG_PLAY_SOUND}) + */ + @SystemApi + public void setStreamVolume(int streamType, int index, int flags) + throws CarNotConnectedException { + try { + mService.setStreamVolume(streamType, index, flags); + } catch (RemoteException e) { + Log.e(CarLibLog.TAG_CAR, "setStreamVolume failed", e); + throw new CarNotConnectedException(e); + } + } + + /** + * Registers a global volume controller interface. + * + * Requires {@link android.car.Car.PERMISSION_CAR_CONTROL_AUDIO_VOLUME} permission. + * + * @hide + */ + @SystemApi + public void setVolumeController(IVolumeController controller) + throws CarNotConnectedException { + try { + mService.setVolumeController(controller); + } catch (RemoteException e) { + Log.e(CarLibLog.TAG_CAR, "setVolumeController failed", e); + throw new CarNotConnectedException(e); + } + } + + /** + * Returns the maximum volume index for a particular stream. + * + * Requires {@link android.car.Car.PERMISSION_CAR_CONTROL_AUDIO_VOLUME} permission. + * + * @param stream The stream type whose maximum volume index is returned. + * @return The maximum valid volume index for the stream. + */ + @SystemApi + public int getStreamMaxVolume(int stream) throws CarNotConnectedException { + try { + return mService.getStreamMaxVolume(stream); + } catch (RemoteException e) { + Log.e(CarLibLog.TAG_CAR, "getStreamMaxVolume failed", e); + throw new CarNotConnectedException(e); + } + } + + /** + * Returns the minimum volume index for a particular stream. + * + * Requires {@link android.car.Car.PERMISSION_CAR_CONTROL_AUDIO_VOLUME} permission. + * + * @param stream The stream type whose maximum volume index is returned. + * @return The maximum valid volume index for the stream. + */ + @SystemApi + public int getStreamMinVolume(int stream) throws CarNotConnectedException { + try { + return mService.getStreamMinVolume(stream); + } catch (RemoteException e) { + Log.e(CarLibLog.TAG_CAR, "getStreamMaxVolume failed", e); + throw new CarNotConnectedException(e); + } + } + + /** + * Returns the current volume index for a particular stream. + * + * Requires {@link android.car.Car.PERMISSION_CAR_CONTROL_AUDIO_VOLUME} permission. + * + * @param stream The stream type whose volume index is returned. + * @return The current volume index for the stream. + * + * @see #getStreamMaxVolume(int) + * @see #setStreamVolume(int, int, int) + */ + @SystemApi + public int getStreamVolume(int stream) throws CarNotConnectedException { + try { + return mService.getStreamVolume(stream); + } catch (RemoteException e) { + Log.e(CarLibLog.TAG_CAR, "getStreamVolume failed", e); + throw new CarNotConnectedException(e); + } + } + @Override public void onCarDisconnected() { // TODO Auto-generated method stub diff --git a/car-lib/src/android/car/media/ICarAudio.aidl b/car-lib/src/android/car/media/ICarAudio.aidl index 7a5e43d304..dfa257331a 100644 --- a/car-lib/src/android/car/media/ICarAudio.aidl +++ b/car-lib/src/android/car/media/ICarAudio.aidl @@ -17,6 +17,7 @@ package android.car.media; import android.media.AudioAttributes; +import android.media.IVolumeController; /** * Binder interface for {@link android.car.media.CarAudioManager}. @@ -26,4 +27,9 @@ import android.media.AudioAttributes; */ interface ICarAudio { AudioAttributes getAudioAttributesForCarUsage(int carUsage) = 0; + void setStreamVolume(int streamType, int index, int flags) = 1; + void setVolumeController(IVolumeController controller) = 2; + int getStreamMaxVolume(int streamType) = 3; + int getStreamMinVolume(int streamType) = 4; + int getStreamVolume(int streamType) = 5; } |