diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index de1df56ba100e..733ab32d75e33 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -2374,6 +2374,16 @@ public final class Settings { */ public static final String VIBRATE_WHEN_RINGING = "vibrate_when_ringing"; + /** + * Whether automatic routing of system audio to USB audio peripheral is disabled. + * The value is boolean (1 or 0), where 1 means automatic routing is disabled, + * and 0 means automatic routing is enabled. + * + * @hide + */ + public static final String USB_AUDIO_AUTOMATIC_ROUTING_DISABLED = + "usb_audio_automatic_routing_disabled"; + /** * Whether the audible DTMF tones are played by the dialer when dialing. The value is * boolean (1 or 0). diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java index 705d9c04ce7c6..a41d4da80001c 100644 --- a/media/java/android/media/AudioService.java +++ b/media/java/android/media/AudioService.java @@ -4573,6 +4573,17 @@ public class AudioService extends IAudioService.Stub { outDevice = AudioSystem.DEVICE_OUT_USB_ACCESSORY; setWiredDeviceConnectionState(outDevice, state, params); } else if (action.equals(Intent.ACTION_USB_AUDIO_DEVICE_PLUG)) { + // FIXME Does not yet handle the case where the setting is changed + // after device connection. Ideally we should handle the settings change + // in SettingsObserver. Here we should log that a USB device is connected + // and disconnected with its address (card , device) and force the + // connection or disconnection when the setting changes. + int isDisabled = Settings.System.getInt(mContentResolver, + Settings.System.USB_AUDIO_AUTOMATIC_ROUTING_DISABLED, 0); + if (isDisabled != 0) { + return; + } + state = intent.getIntExtra("state", 0); int alsaCard = intent.getIntExtra("card", -1);