diff options
Diffstat (limited to 'media')
-rw-r--r-- | media/java/android/media/AudioDevicePort.java | 5 | ||||
-rw-r--r-- | media/java/android/media/AudioManager.java | 4 | ||||
-rw-r--r-- | media/java/android/media/AudioMixPort.java | 5 | ||||
-rw-r--r-- | media/java/android/media/AudioPort.java | 17 | ||||
-rw-r--r-- | media/java/android/media/AudioRoutesInfo.java | 1 | ||||
-rw-r--r-- | media/java/android/media/AudioService.java | 116 | ||||
-rw-r--r-- | media/java/android/media/AudioSystem.java | 3 | ||||
-rw-r--r-- | media/java/android/media/IAudioService.aidl | 2 |
8 files changed, 115 insertions, 38 deletions
diff --git a/media/java/android/media/AudioDevicePort.java b/media/java/android/media/AudioDevicePort.java index b10736b..82da27d 100644 --- a/media/java/android/media/AudioDevicePort.java +++ b/media/java/android/media/AudioDevicePort.java @@ -36,12 +36,13 @@ public class AudioDevicePort extends AudioPort { private final int mType; private final String mAddress; - AudioDevicePort(AudioHandle handle, int[] samplingRates, int[] channelMasks, + AudioDevicePort(AudioHandle handle, String deviceName, + int[] samplingRates, int[] channelMasks, int[] formats, AudioGain[] gains, int type, String address) { super(handle, (AudioManager.isInputDevice(type) == true) ? AudioPort.ROLE_SOURCE : AudioPort.ROLE_SINK, - samplingRates, channelMasks, formats, gains); + deviceName, samplingRates, channelMasks, formats, gains); mType = type; mAddress = address; } diff --git a/media/java/android/media/AudioManager.java b/media/java/android/media/AudioManager.java index 986ae46..912d644 100644 --- a/media/java/android/media/AudioManager.java +++ b/media/java/android/media/AudioManager.java @@ -3199,10 +3199,10 @@ public class AudioManager { * @param name device name * {@hide} */ - public void setWiredDeviceConnectionState(int device, int state, String name) { + public void setWiredDeviceConnectionState(int type, int state, String address, String name) { IAudioService service = getService(); try { - service.setWiredDeviceConnectionState(device, state, name); + service.setWiredDeviceConnectionState(type, state, address, name); } catch (RemoteException e) { Log.e(TAG, "Dead object in setWiredDeviceConnectionState "+e); } diff --git a/media/java/android/media/AudioMixPort.java b/media/java/android/media/AudioMixPort.java index 1500a43..9fac8d1 100644 --- a/media/java/android/media/AudioMixPort.java +++ b/media/java/android/media/AudioMixPort.java @@ -26,9 +26,10 @@ package android.media; public class AudioMixPort extends AudioPort { - AudioMixPort(AudioHandle handle, int role, int[] samplingRates, int[] channelMasks, + AudioMixPort(AudioHandle handle, int role, String deviceName, + int[] samplingRates, int[] channelMasks, int[] formats, AudioGain[] gains) { - super(handle, role, samplingRates, channelMasks, formats, gains); + super(handle, role, deviceName, samplingRates, channelMasks, formats, gains); } /** diff --git a/media/java/android/media/AudioPort.java b/media/java/android/media/AudioPort.java index 1ab7e89..b046791 100644 --- a/media/java/android/media/AudioPort.java +++ b/media/java/android/media/AudioPort.java @@ -15,7 +15,7 @@ */ package android.media; - +import android.util.Slog; /** * An audio port is a node of the audio framework or hardware that can be connected to or @@ -37,6 +37,7 @@ package android.media; * @hide */ public class AudioPort { + private static final String TAG = "AudioPort"; /** * For use by the audio framework. @@ -68,16 +69,20 @@ public class AudioPort { AudioHandle mHandle; protected final int mRole; + private final String mName; private final int[] mSamplingRates; private final int[] mChannelMasks; private final int[] mFormats; private final AudioGain[] mGains; private AudioPortConfig mActiveConfig; - AudioPort(AudioHandle handle, int role, int[] samplingRates, int[] channelMasks, + AudioPort(AudioHandle handle, int role, String name, + int[] samplingRates, int[] channelMasks, int[] formats, AudioGain[] gains) { + mHandle = handle; mRole = role; + mName = name; mSamplingRates = samplingRates; mChannelMasks = channelMasks; mFormats = formats; @@ -96,6 +101,14 @@ public class AudioPort { } /** + * Get the human-readable name of this port. Perhaps an internal + * designation or an physical device. + */ + public String name() { + return mName; + } + + /** * Get the list of supported sampling rates * Empty array if sampling rate is not relevant for this audio port */ diff --git a/media/java/android/media/AudioRoutesInfo.java b/media/java/android/media/AudioRoutesInfo.java index df9fc06..3e0ec07 100644 --- a/media/java/android/media/AudioRoutesInfo.java +++ b/media/java/android/media/AudioRoutesInfo.java @@ -30,6 +30,7 @@ public class AudioRoutesInfo implements Parcelable { static final int MAIN_HEADPHONES = 1<<1; static final int MAIN_DOCK_SPEAKERS = 1<<2; static final int MAIN_HDMI = 1<<3; + static final int MAIN_USB = 1<<4; CharSequence mBluetoothName; int mMainType = MAIN_SPEAKER; diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java index 98a43a8..7c07fb5 100644 --- a/media/java/android/media/AudioService.java +++ b/media/java/android/media/AudioService.java @@ -536,6 +536,20 @@ public class AudioService extends IAudioService.Stub { private AudioManagerInternal.RingerModeDelegate mRingerModeDelegate; + // Intent "extra" data keys. + public static final String CONNECT_INTENT_KEY_PORT_NAME = "portName"; + public static final String CONNECT_INTENT_KEY_STATE = "state"; + public static final String CONNECT_INTENT_KEY_ADDRESS = "address"; + public static final String CONNECT_INTENT_KEY_HAS_PLAYBACK = "hasPlayback"; + public static final String CONNECT_INTENT_KEY_HAS_CAPTURE = "hasCapture"; + public static final String CONNECT_INTENT_KEY_HAS_MIDI = "hasMIDI"; + public static final String CONNECT_INTENT_KEY_DEVICE_CLASS = "class"; + + // Defines the format for the connection "address" for ALSA devices + public static String makeAlsaAddressString(int card, int device) { + return "card=" + card + ";device=" + device + ";"; + } + /////////////////////////////////////////////////////////////////////////// // Construction /////////////////////////////////////////////////////////////////////////// @@ -3433,14 +3447,32 @@ public class AudioService extends IAudioService.Stub { return device; } - public void setWiredDeviceConnectionState(int device, int state, String name) { + /* + * A class just for packaging up a set of connection parameters. + */ + private class WiredDeviceConnectionState { + public int mType; + public int mState; + public String mAddress; + public String mName; + + public WiredDeviceConnectionState(int type, int state, String address, String name) { + mType = type; + mState = state; + mAddress = address; + mName = name; + } + } + + public void setWiredDeviceConnectionState(int type, int state, String address, + String name) { synchronized (mConnectedDevices) { - int delay = checkSendBecomingNoisyIntent(device, state); + int delay = checkSendBecomingNoisyIntent(type, state); queueMsgUnderWakeLock(mAudioHandler, MSG_SET_WIRED_DEVICE_CONNECTION_STATE, - device, - state, - name, + 0, + 0, + new WiredDeviceConnectionState(type, state, address, name), delay); } } @@ -4172,7 +4204,8 @@ public class AudioService extends IAudioService.Stub { AudioSystem.setDeviceConnectionState( ((Integer)device.getKey()).intValue(), AudioSystem.DEVICE_STATE_AVAILABLE, - (String)device.getValue()); + (String)device.getValue(), + "unknown-device"); } } // Restore call state @@ -4274,8 +4307,12 @@ public class AudioService extends IAudioService.Stub { break; case MSG_SET_WIRED_DEVICE_CONNECTION_STATE: - onSetWiredDeviceConnectionState(msg.arg1, msg.arg2, (String)msg.obj); - mAudioEventWakeLock.release(); + { WiredDeviceConnectionState connectState = + (WiredDeviceConnectionState)msg.obj; + onSetWiredDeviceConnectionState(connectState.mType, connectState.mState, + connectState.mAddress, connectState.mName); + mAudioEventWakeLock.release(); + } break; case MSG_SET_A2DP_SRC_CONNECTION_STATE: @@ -4388,7 +4425,8 @@ public class AudioService extends IAudioService.Stub { setBluetoothA2dpOnInt(true); AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP, AudioSystem.DEVICE_STATE_AVAILABLE, - address); + address, + "a2dp-device"); // Reset A2DP suspend state each time a new sink is connected AudioSystem.setParameters("A2dpSuspended=false"); mConnectedDevices.put( new Integer(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP), @@ -4406,7 +4444,8 @@ public class AudioService extends IAudioService.Stub { } AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP, AudioSystem.DEVICE_STATE_UNAVAILABLE, - address); + address, + "a2dp-device"); mConnectedDevices.remove(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP); synchronized (mCurAudioRoutes) { // Remove A2DP routes as well @@ -4435,7 +4474,8 @@ public class AudioService extends IAudioService.Stub { private void makeA2dpSrcAvailable(String address) { AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_IN_BLUETOOTH_A2DP, AudioSystem.DEVICE_STATE_AVAILABLE, - address); + address, + "a2dp-device"); mConnectedDevices.put( new Integer(AudioSystem.DEVICE_IN_BLUETOOTH_A2DP), address); } @@ -4444,7 +4484,8 @@ public class AudioService extends IAudioService.Stub { private void makeA2dpSrcUnavailable(String address) { AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_IN_BLUETOOTH_A2DP, AudioSystem.DEVICE_STATE_UNAVAILABLE, - address); + address, + "a2dp-device"); mConnectedDevices.remove(AudioSystem.DEVICE_IN_BLUETOOTH_A2DP); } @@ -4560,22 +4601,26 @@ public class AudioService extends IAudioService.Stub { } } - private boolean handleDeviceConnection(boolean connected, int device, String params) { + private boolean handleDeviceConnection(boolean connect, int device, String address, String deviceName) { + Slog.i(TAG, "handleDeviceConnection(" + connect + + " dev:" + Integer.toHexString(device) + + " address:" + address + + " name:" + deviceName + ")"); synchronized (mConnectedDevices) { boolean isConnected = (mConnectedDevices.containsKey(device) && - (params.isEmpty() || mConnectedDevices.get(device).equals(params))); + (address.isEmpty() || mConnectedDevices.get(device).equals(address))); - if (isConnected && !connected) { + if (isConnected && !connect) { AudioSystem.setDeviceConnectionState(device, AudioSystem.DEVICE_STATE_UNAVAILABLE, - mConnectedDevices.get(device)); + address, deviceName); mConnectedDevices.remove(device); return true; - } else if (!isConnected && connected) { + } else if (!isConnected && connect) { AudioSystem.setDeviceConnectionState(device, AudioSystem.DEVICE_STATE_AVAILABLE, - params); - mConnectedDevices.put(new Integer(device), params); + address, deviceName); + mConnectedDevices.put(new Integer(device), address); return true; } } @@ -4628,12 +4673,18 @@ public class AudioService extends IAudioService.Stub { return delay; } - private void sendDeviceConnectionIntent(int device, int state, String name) + private void sendDeviceConnectionIntent(int device, int state, String address, String deviceName) { + Slog.i(TAG, "sendDeviceConnectionIntent(dev:0x" + Integer.toHexString(device) + + " state:0x" + Integer.toHexString(state) + + " address:" + address + + " name:" + deviceName + ");"); Intent intent = new Intent(); - intent.putExtra("state", state); - intent.putExtra("name", name); + intent.putExtra(CONNECT_INTENT_KEY_STATE, state); + intent.putExtra(CONNECT_INTENT_KEY_ADDRESS, address); + intent.putExtra(CONNECT_INTENT_KEY_PORT_NAME, deviceName); + intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); int connType = 0; @@ -4652,6 +4703,8 @@ public class AudioService extends IAudioService.Stub { device == AudioSystem.DEVICE_OUT_HDMI_ARC) { connType = AudioRoutesInfo.MAIN_HDMI; configureHdmiPlugIntent(intent, state); + } else if (device == AudioSystem.DEVICE_OUT_USB_DEVICE) { + connType = AudioRoutesInfo.MAIN_USB; } synchronized (mCurAudioRoutes) { @@ -4678,8 +4731,14 @@ public class AudioService extends IAudioService.Stub { } } - private void onSetWiredDeviceConnectionState(int device, int state, String name) + private void onSetWiredDeviceConnectionState(int device, int state, String address, + String deviceName) { + Slog.i(TAG, "onSetWiredDeviceConnectionState(dev:" + Integer.toHexString(device) + + " state:" + Integer.toHexString(state) + + " address:" + address + + " deviceName:" + deviceName + ");"); + synchronized (mConnectedDevices) { if ((state == 0) && ((device == AudioSystem.DEVICE_OUT_WIRED_HEADSET) || (device == AudioSystem.DEVICE_OUT_WIRED_HEADPHONE) || @@ -4689,7 +4748,7 @@ public class AudioService extends IAudioService.Stub { boolean isUsb = ((device & ~AudioSystem.DEVICE_OUT_ALL_USB) == 0) || (((device & AudioSystem.DEVICE_BIT_IN) != 0) && ((device & ~AudioSystem.DEVICE_IN_ALL_USB) == 0)); - handleDeviceConnection((state == 1), device, (isUsb ? name : "")); + handleDeviceConnection(state == 1, device, address, deviceName); if (state != 0) { if ((device == AudioSystem.DEVICE_OUT_WIRED_HEADSET) || (device == AudioSystem.DEVICE_OUT_WIRED_HEADPHONE) || @@ -4727,8 +4786,8 @@ public class AudioService extends IAudioService.Stub { } } } - if (!isUsb && (device != AudioSystem.DEVICE_IN_WIRED_HEADSET)) { - sendDeviceConnectionIntent(device, state, name); + if (!isUsb && device != AudioSystem.DEVICE_IN_WIRED_HEADSET) { + sendDeviceConnectionIntent(device, state, address, deviceName); } } } @@ -4852,8 +4911,9 @@ public class AudioService extends IAudioService.Stub { } boolean connected = (state == BluetoothProfile.STATE_CONNECTED); - boolean success = handleDeviceConnection(connected, outDevice, address) && - handleDeviceConnection(connected, inDevice, address); + boolean success = + handleDeviceConnection(connected, outDevice, address, "Bluetooth Headset") && + handleDeviceConnection(connected, inDevice, address, "Bluetooth Headset"); if (success) { synchronized (mScoClients) { if (connected) { diff --git a/media/java/android/media/AudioSystem.java b/media/java/android/media/AudioSystem.java index 46ab7e0..7084656 100644 --- a/media/java/android/media/AudioSystem.java +++ b/media/java/android/media/AudioSystem.java @@ -534,7 +534,8 @@ public class AudioSystem public static final int SYNC_EVENT_NONE = 0; public static final int SYNC_EVENT_PRESENTATION_COMPLETE = 1; - public static native int setDeviceConnectionState(int device, int state, String device_address); + public static native int setDeviceConnectionState(int device, int state, + String device_address, String device_name); public static native int getDeviceConnectionState(int device, String device_address); public static native int setPhoneState(int state); public static native int setForceUse(int usage, int config); diff --git a/media/java/android/media/IAudioService.aidl b/media/java/android/media/IAudioService.aidl index bfb78a1..dabd9c2 100644 --- a/media/java/android/media/IAudioService.aidl +++ b/media/java/android/media/IAudioService.aidl @@ -189,7 +189,7 @@ interface IAudioService { IRingtonePlayer getRingtonePlayer(); int getMasterStreamType(); - void setWiredDeviceConnectionState(int device, int state, String name); + void setWiredDeviceConnectionState(int type, int state, String address, String name); int setBluetoothA2dpDeviceConnectionState(in BluetoothDevice device, int state, int profile); AudioRoutesInfo startWatchingRoutes(in IAudioRoutesObserver observer); |