diff options
author | StevenHarperUK <StevenHarperUK@gmail.com> | 2012-03-27 03:17:29 +0100 |
---|---|---|
committer | Steve Kondik <shade@chemlab.org> | 2012-04-10 11:13:10 -0700 |
commit | 77080983ebd5b5871e6af0c8d1300d7087530709 (patch) | |
tree | 080c7012303689ff9310fb751668c7d760419241 | |
parent | 4a56820ca643ce668433b1529c8383c5a5049191 (diff) | |
download | frameworks_base-77080983ebd5b5871e6af0c8d1300d7087530709.zip frameworks_base-77080983ebd5b5871e6af0c8d1300d7087530709.tar.gz frameworks_base-77080983ebd5b5871e6af0c8d1300d7087530709.tar.bz2 |
Added support for a fourth audio device - dock
Adding persistant setting to choose to use usb audio
Change-Id: I3860c04c8f14e8e98d79d82a354a92b78565c3d1
5 files changed, 32 insertions, 5 deletions
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index 7009848..4bdf631 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -1973,6 +1973,12 @@ public final class Settings { public static final String POWER_SOUNDS_ENABLED = "power_sounds_enabled"; /** + * Whether to route USB Audio when docked. + * @hide + */ + public static final String DOCK_USB_AUDIO_ENABLED = "dock_usb_audio_enabled"; + + /** * Whether to play a sound for dock events. * @hide */ diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java index 78ccf30..0785798 100644 --- a/media/java/android/media/AudioService.java +++ b/media/java/android/media/AudioService.java @@ -2638,12 +2638,17 @@ public class AudioService extends IAudioService.Stub { ""); mConnectedDevices.remove(AudioSystem.DEVICE_OUT_ANLG_DOCK_HEADSET); } else if (state == 1 && !isConnected) { - AudioSystem.setDeviceConnectionState( + // Only Route the Audio if enabled in Dock Settings + if (Settings.System.getInt(mContentResolver,Settings.System.DOCK_USB_AUDIO_ENABLED, 0) == 1) { + AudioSystem.setDeviceConnectionState( AudioSystem.DEVICE_OUT_ANLG_DOCK_HEADSET, AudioSystem.DEVICE_STATE_AVAILABLE, ""); - mConnectedDevices.put( + mConnectedDevices.put( new Integer(AudioSystem.DEVICE_OUT_ANLG_DOCK_HEADSET), ""); + } else { + Log.v(TAG, "Broadcast Receiver: Not using USB audio by request"); + } } } } else if (action.equals(Intent.ACTION_HDMI_AUDIO_PLUG)) { diff --git a/packages/SettingsProvider/res/values/defaults.xml b/packages/SettingsProvider/res/values/defaults.xml index 1ebed1f..7b20586 100644 --- a/packages/SettingsProvider/res/values/defaults.xml +++ b/packages/SettingsProvider/res/values/defaults.xml @@ -62,6 +62,7 @@ <!-- user interface sound effects --> <integer name="def_power_sounds_enabled">1</integer> <string name="def_low_battery_sound" translatable="false">/system/media/audio/ui/LowBattery.ogg</string> + <integer name="def_dock_usb_audio_enabled">0</integer> <integer name="def_dock_sounds_enabled">0</integer> <string name="def_desk_dock_sound" translatable="false">/system/media/audio/ui/Dock.ogg</string> <string name="def_desk_undock_sound" translatable="false">/system/media/audio/ui/Undock.ogg</string> diff --git a/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java b/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java index a5e3483..adfda49 100644 --- a/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java +++ b/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java @@ -1415,6 +1415,8 @@ public class DatabaseHelper extends SQLiteOpenHelper { loadBooleanSetting(stmt, Settings.System.HAPTIC_FEEDBACK_ENABLED, R.bool.def_haptic_feedback); + loadIntegerSetting(stmt, Settings.System.DOCK_USB_AUDIO_ENABLED, + R.integer.def_dock_usb_audio_enabled); loadIntegerSetting(stmt, Settings.System.DOCK_SOUNDS_ENABLED, R.integer.def_dock_sounds_enabled); loadStringSetting(stmt, Settings.System.DESK_DOCK_SOUND, diff --git a/services/java/com/android/server/WiredAccessoryObserver.java b/services/java/com/android/server/WiredAccessoryObserver.java index 7364978..a2ef54e 100644 --- a/services/java/com/android/server/WiredAccessoryObserver.java +++ b/services/java/com/android/server/WiredAccessoryObserver.java @@ -39,10 +39,13 @@ import java.io.FileNotFoundException; class WiredAccessoryObserver extends UEventObserver { private static final String TAG = WiredAccessoryObserver.class.getSimpleName(); private static final boolean LOG = true; - private static final int MAX_AUDIO_PORTS = 3; /* h2w, USB Audio & hdmi */ + private static final int MAX_AUDIO_PORTS = 4; /* h2w, dock, USB Audio & hdmi */ private static final String uEventInfo[][] = { {"DEVPATH=/devices/virtual/switch/h2w", "/sys/class/switch/h2w/state", "/sys/class/switch/h2w/name"}, + {"DEVPATH=/devices/virtual/switch/dock", + "/sys/class/switch/dock/state", + "/sys/class/switch/dock/name"}, {"DEVPATH=/devices/virtual/switch/usb_audio", "/sys/class/switch/usb_audio/state", "/sys/class/switch/usb_audio/name"}, @@ -106,10 +109,21 @@ class WiredAccessoryObserver extends UEventObserver { private synchronized final void updateState(String name, int state) { + if (LOG) Slog.v(TAG, "updateState name: " + name + " state " + state); if (name.equals("usb_audio")) { switchState = ((mHeadsetState & (BIT_HEADSET|BIT_HEADSET_NO_MIC|BIT_HDMI_AUDIO)) | ((state == 1) ? BIT_USB_HEADSET_ANLG : ((state == 2) ? BIT_USB_HEADSET_DGTL : 0))); + } else if (name.equals("dock")) { + switchState = ((mHeadsetState & (BIT_HEADSET|BIT_HEADSET_NO_MIC|BIT_HDMI_AUDIO)) | + ((state == 2) ? BIT_USB_HEADSET_ANLG : 0)); + // This sets the switchsate to 4 (for USB HEADSET - BIT_USB_HEADSET_ANLG) + // Looking at the other types, maybe the state that emitted should be a 1 and at + // /devices/virtual/switch/usb_audio + // + // However the we need to deal with changes at + // /devices/virtual/switch/dock + // for this the state of 2 - means that we have a USB ANLG headset } else if (name.equals("hdmi")) { switchState = ((mHeadsetState & (BIT_HEADSET|BIT_HEADSET_NO_MIC| BIT_USB_HEADSET_DGTL|BIT_USB_HEADSET_ANLG)) | @@ -124,6 +138,7 @@ class WiredAccessoryObserver extends UEventObserver { ((state == 1) ? BIT_HEADSET : ((state == 2) ? BIT_HEADSET_NO_MIC : 0))); } + if (LOG) Slog.v(TAG, "updateState switchState: " + switchState); update(name, switchState); } @@ -230,7 +245,6 @@ class WiredAccessoryObserver extends UEventObserver { private final void sendIntent(int headset, int headsetState, int prevHeadsetState, String headsetName) { if ((headsetState & headset) != (prevHeadsetState & headset)) { - int state = 0; if ((headsetState & headset) != 0) { state = 1; @@ -238,7 +252,6 @@ class WiredAccessoryObserver extends UEventObserver { if((headset == BIT_USB_HEADSET_ANLG) || (headset == BIT_USB_HEADSET_DGTL) || (headset == BIT_HDMI_AUDIO)) { Intent intent; - // Pack up the values and broadcast them to everyone if (headset == BIT_USB_HEADSET_ANLG) { intent = new Intent(Intent.ACTION_USB_ANLG_HEADSET_PLUG); |