Loading media/java/android/media/AudioSystem.java +0 −63 Original line number Diff line number Diff line Loading @@ -1237,9 +1237,6 @@ public class AudioSystem public static final Set<Integer> DEVICE_IN_ALL_SCO_SET; /** @hide */ public static final Set<Integer> DEVICE_IN_ALL_USB_SET; /** @hide */ public static final Set<Integer> DEVICE_IN_ALL_BLE_SET; static { DEVICE_IN_ALL_SET = new HashSet<>(); DEVICE_IN_ALL_SET.add(DEVICE_IN_COMMUNICATION); Loading Loading @@ -1279,66 +1276,6 @@ public class AudioSystem DEVICE_IN_ALL_USB_SET.add(DEVICE_IN_USB_ACCESSORY); DEVICE_IN_ALL_USB_SET.add(DEVICE_IN_USB_DEVICE); DEVICE_IN_ALL_USB_SET.add(DEVICE_IN_USB_HEADSET); DEVICE_IN_ALL_BLE_SET = new HashSet<>(); DEVICE_IN_ALL_BLE_SET.add(DEVICE_IN_BLE_HEADSET); } /** @hide */ public static boolean isBluetoothDevice(int deviceType) { return isBluetoothA2dpOutDevice(deviceType) || isBluetoothScoDevice(deviceType) || isBluetoothLeDevice(deviceType); } /** @hide */ public static boolean isBluetoothOutDevice(int deviceType) { return isBluetoothA2dpOutDevice(deviceType) || isBluetoothScoOutDevice(deviceType) || isBluetoothLeOutDevice(deviceType); } /** @hide */ public static boolean isBluetoothInDevice(int deviceType) { return isBluetoothScoInDevice(deviceType) || isBluetoothLeInDevice(deviceType); } /** @hide */ public static boolean isBluetoothA2dpOutDevice(int deviceType) { return DEVICE_OUT_ALL_A2DP_SET.contains(deviceType); } /** @hide */ public static boolean isBluetoothScoOutDevice(int deviceType) { return DEVICE_OUT_ALL_SCO_SET.contains(deviceType); } /** @hide */ public static boolean isBluetoothScoInDevice(int deviceType) { return DEVICE_IN_ALL_SCO_SET.contains(deviceType); } /** @hide */ public static boolean isBluetoothScoDevice(int deviceType) { return isBluetoothScoOutDevice(deviceType) || isBluetoothScoInDevice(deviceType); } /** @hide */ public static boolean isBluetoothLeOutDevice(int deviceType) { return DEVICE_OUT_ALL_BLE_SET.contains(deviceType); } /** @hide */ public static boolean isBluetoothLeInDevice(int deviceType) { return DEVICE_IN_ALL_BLE_SET.contains(deviceType); } /** @hide */ public static boolean isBluetoothLeDevice(int deviceType) { return isBluetoothLeOutDevice(deviceType) || isBluetoothLeInDevice(deviceType); } /** @hide */ Loading services/core/java/com/android/server/audio/AudioDeviceBroker.java +25 −49 Original line number Diff line number Diff line Loading @@ -87,14 +87,14 @@ import java.util.concurrent.atomic.AtomicBoolean; private final @NonNull Context mContext; /** ID for Communication strategy retrieved form audio policy manager */ /*package*/ int mCommunicationStrategyId = -1; private int mCommunicationStrategyId = -1; /** ID for Accessibility strategy retrieved form audio policy manager */ private int mAccessibilityStrategyId = -1; /** Active communication device reported by audio policy manager */ /*package*/ AudioDeviceInfo mActiveCommunicationDevice; private AudioDeviceInfo mActiveCommunicationDevice; /** Last preferred device set for communication strategy */ private AudioDeviceAttributes mPreferredCommunicationDevice; Loading Loading @@ -750,19 +750,6 @@ import java.util.concurrent.atomic.AtomicBoolean; mIsLeOutput = false; } BtDeviceInfo(@NonNull BtDeviceInfo src, int state) { mDevice = src.mDevice; mState = state; mProfile = src.mProfile; mSupprNoisy = src.mSupprNoisy; mVolume = src.mVolume; mIsLeOutput = src.mIsLeOutput; mEventSource = src.mEventSource; mAudioSystemDevice = src.mAudioSystemDevice; mMusicDevice = src.mMusicDevice; mCodec = src.mCodec; } // redefine equality op so we can match messages intended for this device @Override public boolean equals(Object o) { Loading Loading @@ -829,7 +816,7 @@ import java.util.concurrent.atomic.AtomicBoolean; * @param info struct with the (dis)connection information */ /*package*/ void queueOnBluetoothActiveDeviceChanged(@NonNull BtDeviceChangedData data) { if (data.mPreviousDevice != null if (data.mInfo.getProfile() == BluetoothProfile.A2DP && data.mPreviousDevice != null && data.mPreviousDevice.equals(data.mNewDevice)) { final String name = TextUtils.emptyIfNull(data.mNewDevice.getName()); new MediaMetrics.Item(MediaMetrics.Name.AUDIO_DEVICE + MediaMetrics.SEPARATOR Loading @@ -838,8 +825,7 @@ import java.util.concurrent.atomic.AtomicBoolean; .set(MediaMetrics.Property.STATUS, data.mInfo.getProfile()) .record(); synchronized (mDeviceStateLock) { postBluetoothDeviceConfigChange(createBtDeviceInfo(data, data.mNewDevice, BluetoothProfile.STATE_CONNECTED)); postBluetoothA2dpDeviceConfigChange(data.mNewDevice); } } else { synchronized (mDeviceStateLock) { Loading Loading @@ -1064,8 +1050,8 @@ import java.util.concurrent.atomic.AtomicBoolean; new AudioModeInfo(mode, pid, uid)); } /*package*/ void postBluetoothDeviceConfigChange(@NonNull BtDeviceInfo info) { sendLMsgNoDelay(MSG_L_BLUETOOTH_DEVICE_CONFIG_CHANGE, SENDMSG_QUEUE, info); /*package*/ void postBluetoothA2dpDeviceConfigChange(@NonNull BluetoothDevice device) { sendLMsgNoDelay(MSG_L_A2DP_DEVICE_CONFIG_CHANGE, SENDMSG_QUEUE, device); } /*package*/ void startBluetoothScoForClient(IBinder cb, int pid, int scoAudioMode, Loading Loading @@ -1322,10 +1308,6 @@ import java.util.concurrent.atomic.AtomicBoolean; sendIMsgNoDelay(MSG_I_SCO_AUDIO_STATE_CHANGED, SENDMSG_QUEUE, state); } /*package*/ void postNotifyPreferredAudioProfileApplied(BluetoothDevice btDevice) { sendLMsgNoDelay(MSG_L_NOTIFY_PREFERRED_AUDIOPROFILE_APPLIED, SENDMSG_QUEUE, btDevice); } /*package*/ static final class CommunicationDeviceInfo { final @NonNull IBinder mCb; // Identifies the requesting client for death handler final int mPid; // Requester process ID Loading Loading @@ -1401,11 +1383,9 @@ import java.util.concurrent.atomic.AtomicBoolean; } } /*package*/ boolean handleDeviceConnection(AudioDeviceAttributes attributes, boolean connect, @Nullable BluetoothDevice btDevice) { /*package*/ boolean handleDeviceConnection(AudioDeviceAttributes attributes, boolean connect) { synchronized (mDeviceStateLock) { return mDeviceInventory.handleDeviceConnection( attributes, connect, false /*for test*/, btDevice); return mDeviceInventory.handleDeviceConnection(attributes, connect, false /*for test*/); } } Loading Loading @@ -1646,10 +1626,13 @@ import java.util.concurrent.atomic.AtomicBoolean; (String) msg.obj, msg.arg1); } break; case MSG_L_BLUETOOTH_DEVICE_CONFIG_CHANGE: case MSG_L_A2DP_DEVICE_CONFIG_CHANGE: final BluetoothDevice btDevice = (BluetoothDevice) msg.obj; synchronized (mDeviceStateLock) { mDeviceInventory.onBluetoothDeviceConfigChange( (BtDeviceInfo) msg.obj, BtHelper.EVENT_DEVICE_CONFIG_CHANGE); final int a2dpCodec = mBtHelper.getA2dpCodec(btDevice); mDeviceInventory.onBluetoothA2dpDeviceConfigChange( new BtHelper.BluetoothA2dpDeviceInfo(btDevice, -1, a2dpCodec), BtHelper.EVENT_DEVICE_CONFIG_CHANGE); } break; case MSG_BROADCAST_AUDIO_BECOMING_NOISY: Loading Loading @@ -1807,10 +1790,6 @@ import java.util.concurrent.atomic.AtomicBoolean; final int capturePreset = msg.arg1; mDeviceInventory.onSaveClearPreferredDevicesForCapturePreset(capturePreset); } break; case MSG_L_NOTIFY_PREFERRED_AUDIOPROFILE_APPLIED: { final BluetoothDevice btDevice = (BluetoothDevice) msg.obj; BtHelper.onNotifyPreferredAudioProfileApplied(btDevice); } break; default: Log.wtf(TAG, "Invalid message " + msg.what); } Loading Loading @@ -1846,7 +1825,7 @@ import java.util.concurrent.atomic.AtomicBoolean; private static final int MSG_IL_BTA2DP_TIMEOUT = 10; // process change of A2DP device configuration, obj is BluetoothDevice private static final int MSG_L_BLUETOOTH_DEVICE_CONFIG_CHANGE = 11; private static final int MSG_L_A2DP_DEVICE_CONFIG_CHANGE = 11; private static final int MSG_BROADCAST_AUDIO_BECOMING_NOISY = 12; private static final int MSG_REPORT_NEW_ROUTES = 13; Loading Loading @@ -1886,15 +1865,13 @@ import java.util.concurrent.atomic.AtomicBoolean; private static final int MSG_IL_SAVE_REMOVE_NDEF_DEVICE_FOR_STRATEGY = 48; private static final int MSG_IL_BTLEAUDIO_TIMEOUT = 49; private static final int MSG_L_NOTIFY_PREFERRED_AUDIOPROFILE_APPLIED = 50; private static boolean isMessageHandledUnderWakelock(int msgId) { switch(msgId) { case MSG_L_SET_WIRED_DEVICE_CONNECTION_STATE: case MSG_L_SET_BT_ACTIVE_DEVICE: case MSG_IL_BTA2DP_TIMEOUT: case MSG_IL_BTLEAUDIO_TIMEOUT: case MSG_L_BLUETOOTH_DEVICE_CONFIG_CHANGE: case MSG_L_A2DP_DEVICE_CONFIG_CHANGE: case MSG_TOGGLE_HDMI: case MSG_L_A2DP_DEVICE_CONNECTION_CHANGE_EXT: case MSG_L_HEARING_AID_DEVICE_CONNECTION_CHANGE_EXT: Loading Loading @@ -1986,7 +1963,7 @@ import java.util.concurrent.atomic.AtomicBoolean; case MSG_L_SET_WIRED_DEVICE_CONNECTION_STATE: case MSG_IL_BTA2DP_TIMEOUT: case MSG_IL_BTLEAUDIO_TIMEOUT: case MSG_L_BLUETOOTH_DEVICE_CONFIG_CHANGE: case MSG_L_A2DP_DEVICE_CONFIG_CHANGE: if (sLastDeviceConnectMsgTime >= time) { // add a little delay to make sure messages are ordered as expected time = sLastDeviceConnectMsgTime + 30; Loading @@ -2006,7 +1983,7 @@ import java.util.concurrent.atomic.AtomicBoolean; static { MESSAGES_MUTE_MUSIC = new HashSet<>(); MESSAGES_MUTE_MUSIC.add(MSG_L_SET_BT_ACTIVE_DEVICE); MESSAGES_MUTE_MUSIC.add(MSG_L_BLUETOOTH_DEVICE_CONFIG_CHANGE); MESSAGES_MUTE_MUSIC.add(MSG_L_A2DP_DEVICE_CONFIG_CHANGE); MESSAGES_MUTE_MUSIC.add(MSG_L_A2DP_DEVICE_CONNECTION_CHANGE_EXT); MESSAGES_MUTE_MUSIC.add(MSG_IIL_SET_FORCE_BT_A2DP_USE); } Loading @@ -2027,7 +2004,7 @@ import java.util.concurrent.atomic.AtomicBoolean; // Do not mute on bluetooth event if music is playing on a wired headset. if ((message == MSG_L_SET_BT_ACTIVE_DEVICE || message == MSG_L_A2DP_DEVICE_CONNECTION_CHANGE_EXT || message == MSG_L_BLUETOOTH_DEVICE_CONFIG_CHANGE) || message == MSG_L_A2DP_DEVICE_CONFIG_CHANGE) && AudioSystem.isStreamActive(AudioSystem.STREAM_MUSIC, 0) && hasIntersection(mDeviceInventory.DEVICE_OVERRIDE_A2DP_ROUTE_ON_PLUG_SET, mAudioService.getDeviceSetForStream(AudioSystem.STREAM_MUSIC))) { Loading Loading @@ -2166,19 +2143,18 @@ import java.util.concurrent.atomic.AtomicBoolean; if (preferredCommunicationDevice == null) { AudioDeviceAttributes defaultDevice = getDefaultCommunicationDevice(); if (defaultDevice != null) { mDeviceInventory.setPreferredDevicesForStrategy( setPreferredDevicesForStrategySync( mCommunicationStrategyId, Arrays.asList(defaultDevice)); mDeviceInventory.setPreferredDevicesForStrategy( setPreferredDevicesForStrategySync( mAccessibilityStrategyId, Arrays.asList(defaultDevice)); } else { mDeviceInventory.removePreferredDevicesForStrategy(mCommunicationStrategyId); mDeviceInventory.removePreferredDevicesForStrategy(mAccessibilityStrategyId); removePreferredDevicesForStrategySync(mCommunicationStrategyId); removePreferredDevicesForStrategySync(mAccessibilityStrategyId); } mDeviceInventory.applyConnectedDevicesRoles(); } else { mDeviceInventory.setPreferredDevicesForStrategy( setPreferredDevicesForStrategySync( mCommunicationStrategyId, Arrays.asList(preferredCommunicationDevice)); mDeviceInventory.setPreferredDevicesForStrategy( setPreferredDevicesForStrategySync( mAccessibilityStrategyId, Arrays.asList(preferredCommunicationDevice)); } onUpdatePhoneStrategyDevice(preferredCommunicationDevice); Loading services/core/java/com/android/server/audio/AudioDeviceInventory.java +132 −669 File changed.Preview size limit exceeded, changes collapsed. Show changes services/core/java/com/android/server/audio/AudioSystemAdapter.java +1 −14 Original line number Diff line number Diff line Loading @@ -435,7 +435,7 @@ public class AudioSystemAdapter implements AudioSystem.RoutingUpdateCallback, } /** * Same as {@link AudioSystem#removeDevicesRoleForCapturePreset(int, int, List)} * Same as {@link AudioSystem#removeDevicesRoleForCapturePreset(int, int, int[], String[])} * @param capturePreset * @param role * @param devicesToRemove Loading @@ -447,19 +447,6 @@ public class AudioSystemAdapter implements AudioSystem.RoutingUpdateCallback, return AudioSystem.removeDevicesRoleForCapturePreset(capturePreset, role, devicesToRemove); } /** * Same as {@link AudioSystem#addDevicesRoleForCapturePreset(int, int, List)} * @param capturePreset the capture preset to configure * @param role the role of the devices * @param devices the list of devices to be added as role for the given capture preset * @return {@link #SUCCESS} if successfully add */ public int addDevicesRoleForCapturePreset( int capturePreset, int role, @NonNull List<AudioDeviceAttributes> devices) { invalidateRoutingCache(); return AudioSystem.addDevicesRoleForCapturePreset(capturePreset, role, devices); } /** * Same as {@link AudioSystem#} * @param capturePreset Loading services/core/java/com/android/server/audio/BtHelper.java +59 −34 Original line number Diff line number Diff line Loading @@ -33,7 +33,6 @@ import android.media.AudioManager; import android.media.AudioSystem; import android.media.BluetoothProfileConnectionInfo; import android.os.Binder; import android.os.Bundle; import android.os.UserHandle; import android.provider.Settings; import android.text.TextUtils; Loading Loading @@ -151,12 +150,60 @@ public class BtHelper { } } //---------------------------------------------------------------------- /*package*/ static class BluetoothA2dpDeviceInfo { private final @NonNull BluetoothDevice mBtDevice; private final int mVolume; private final @AudioSystem.AudioFormatNativeEnumForBtCodec int mCodec; BluetoothA2dpDeviceInfo(@NonNull BluetoothDevice btDevice) { this(btDevice, -1, AudioSystem.AUDIO_FORMAT_DEFAULT); } BluetoothA2dpDeviceInfo(@NonNull BluetoothDevice btDevice, int volume, int codec) { mBtDevice = btDevice; mVolume = volume; mCodec = codec; } public @NonNull BluetoothDevice getBtDevice() { return mBtDevice; } public int getVolume() { return mVolume; } public @AudioSystem.AudioFormatNativeEnumForBtCodec int getCodec() { return mCodec; } // redefine equality op so we can match messages intended for this device @Override public boolean equals(Object o) { if (o == null) { return false; } if (this == o) { return true; } if (o instanceof BluetoothA2dpDeviceInfo) { return mBtDevice.equals(((BluetoothA2dpDeviceInfo) o).getBtDevice()); } return false; } } // A2DP device events /*package*/ static final int EVENT_DEVICE_CONFIG_CHANGE = 0; /*package*/ static final int EVENT_ACTIVE_DEVICE_CHANGE = 1; /*package*/ static String deviceEventToString(int event) { /*package*/ static String a2dpDeviceEventToString(int event) { switch (event) { case EVENT_DEVICE_CONFIG_CHANGE: return "DEVICE_CONFIG_CHANGE"; case EVENT_ACTIVE_DEVICE_CHANGE: return "ACTIVE_DEVICE_CHANGE"; default: return new String("invalid event:" + event); } Loading Loading @@ -573,12 +620,11 @@ public class BtHelper { return btHeadsetDeviceToAudioDevice(mBluetoothHeadsetDevice); } private static AudioDeviceAttributes btHeadsetDeviceToAudioDevice(BluetoothDevice btDevice) { private AudioDeviceAttributes btHeadsetDeviceToAudioDevice(BluetoothDevice btDevice) { if (btDevice == null) { return new AudioDeviceAttributes(AudioSystem.DEVICE_OUT_BLUETOOTH_SCO, ""); } String address = btDevice.getAddress(); String name = getName(btDevice); if (!BluetoothAdapter.checkBluetoothAddress(address)) { address = ""; } Loading @@ -600,7 +646,7 @@ public class BtHelper { + " btClass: " + (btClass == null ? "Unknown" : btClass) + " nativeType: " + nativeType + " address: " + address); } return new AudioDeviceAttributes(nativeType, address, name); return new AudioDeviceAttributes(nativeType, address); } private boolean handleBtScoActiveDeviceChange(BluetoothDevice btDevice, boolean isActive) { Loading @@ -609,9 +655,12 @@ public class BtHelper { } int inDevice = AudioSystem.DEVICE_IN_BLUETOOTH_SCO_HEADSET; AudioDeviceAttributes audioDevice = btHeadsetDeviceToAudioDevice(btDevice); String btDeviceName = getName(btDevice); boolean result = false; if (isActive) { result |= mDeviceBroker.handleDeviceConnection(audioDevice, isActive, btDevice); result |= mDeviceBroker.handleDeviceConnection(new AudioDeviceAttributes( audioDevice.getInternalType(), audioDevice.getAddress(), btDeviceName), isActive); } else { int[] outDeviceTypes = { AudioSystem.DEVICE_OUT_BLUETOOTH_SCO, Loading @@ -620,14 +669,14 @@ public class BtHelper { }; for (int outDeviceType : outDeviceTypes) { result |= mDeviceBroker.handleDeviceConnection(new AudioDeviceAttributes( outDeviceType, audioDevice.getAddress(), audioDevice.getName()), isActive, btDevice); outDeviceType, audioDevice.getAddress(), btDeviceName), isActive); } } // handleDeviceConnection() && result to make sure the method get executed result = mDeviceBroker.handleDeviceConnection(new AudioDeviceAttributes( inDevice, audioDevice.getAddress(), audioDevice.getName()), isActive, btDevice) && result; inDevice, audioDevice.getAddress(), btDeviceName), isActive) && result; return result; } Loading Loading @@ -924,30 +973,6 @@ public class BtHelper { } } /*package */ static int getProfileFromType(int deviceType) { if (AudioSystem.isBluetoothA2dpOutDevice(deviceType)) { return BluetoothProfile.A2DP; } else if (AudioSystem.isBluetoothScoDevice(deviceType)) { return BluetoothProfile.HEADSET; } else if (AudioSystem.isBluetoothLeDevice(deviceType)) { return BluetoothProfile.LE_AUDIO; } return 0; // 0 is not a valid profile } /*package */ static Bundle getPreferredAudioProfiles(String address) { BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); return adapter.getPreferredAudioProfiles(adapter.getRemoteDevice(address)); } /** * Notifies Bluetooth framework that new preferred audio profiles for Bluetooth devices * have been applied. */ public static void onNotifyPreferredAudioProfileApplied(BluetoothDevice btDevice) { BluetoothAdapter.getDefaultAdapter().notifyActiveDeviceChangeApplied(btDevice); } /** * Returns the string equivalent for the btDeviceClass class. */ Loading Loading
media/java/android/media/AudioSystem.java +0 −63 Original line number Diff line number Diff line Loading @@ -1237,9 +1237,6 @@ public class AudioSystem public static final Set<Integer> DEVICE_IN_ALL_SCO_SET; /** @hide */ public static final Set<Integer> DEVICE_IN_ALL_USB_SET; /** @hide */ public static final Set<Integer> DEVICE_IN_ALL_BLE_SET; static { DEVICE_IN_ALL_SET = new HashSet<>(); DEVICE_IN_ALL_SET.add(DEVICE_IN_COMMUNICATION); Loading Loading @@ -1279,66 +1276,6 @@ public class AudioSystem DEVICE_IN_ALL_USB_SET.add(DEVICE_IN_USB_ACCESSORY); DEVICE_IN_ALL_USB_SET.add(DEVICE_IN_USB_DEVICE); DEVICE_IN_ALL_USB_SET.add(DEVICE_IN_USB_HEADSET); DEVICE_IN_ALL_BLE_SET = new HashSet<>(); DEVICE_IN_ALL_BLE_SET.add(DEVICE_IN_BLE_HEADSET); } /** @hide */ public static boolean isBluetoothDevice(int deviceType) { return isBluetoothA2dpOutDevice(deviceType) || isBluetoothScoDevice(deviceType) || isBluetoothLeDevice(deviceType); } /** @hide */ public static boolean isBluetoothOutDevice(int deviceType) { return isBluetoothA2dpOutDevice(deviceType) || isBluetoothScoOutDevice(deviceType) || isBluetoothLeOutDevice(deviceType); } /** @hide */ public static boolean isBluetoothInDevice(int deviceType) { return isBluetoothScoInDevice(deviceType) || isBluetoothLeInDevice(deviceType); } /** @hide */ public static boolean isBluetoothA2dpOutDevice(int deviceType) { return DEVICE_OUT_ALL_A2DP_SET.contains(deviceType); } /** @hide */ public static boolean isBluetoothScoOutDevice(int deviceType) { return DEVICE_OUT_ALL_SCO_SET.contains(deviceType); } /** @hide */ public static boolean isBluetoothScoInDevice(int deviceType) { return DEVICE_IN_ALL_SCO_SET.contains(deviceType); } /** @hide */ public static boolean isBluetoothScoDevice(int deviceType) { return isBluetoothScoOutDevice(deviceType) || isBluetoothScoInDevice(deviceType); } /** @hide */ public static boolean isBluetoothLeOutDevice(int deviceType) { return DEVICE_OUT_ALL_BLE_SET.contains(deviceType); } /** @hide */ public static boolean isBluetoothLeInDevice(int deviceType) { return DEVICE_IN_ALL_BLE_SET.contains(deviceType); } /** @hide */ public static boolean isBluetoothLeDevice(int deviceType) { return isBluetoothLeOutDevice(deviceType) || isBluetoothLeInDevice(deviceType); } /** @hide */ Loading
services/core/java/com/android/server/audio/AudioDeviceBroker.java +25 −49 Original line number Diff line number Diff line Loading @@ -87,14 +87,14 @@ import java.util.concurrent.atomic.AtomicBoolean; private final @NonNull Context mContext; /** ID for Communication strategy retrieved form audio policy manager */ /*package*/ int mCommunicationStrategyId = -1; private int mCommunicationStrategyId = -1; /** ID for Accessibility strategy retrieved form audio policy manager */ private int mAccessibilityStrategyId = -1; /** Active communication device reported by audio policy manager */ /*package*/ AudioDeviceInfo mActiveCommunicationDevice; private AudioDeviceInfo mActiveCommunicationDevice; /** Last preferred device set for communication strategy */ private AudioDeviceAttributes mPreferredCommunicationDevice; Loading Loading @@ -750,19 +750,6 @@ import java.util.concurrent.atomic.AtomicBoolean; mIsLeOutput = false; } BtDeviceInfo(@NonNull BtDeviceInfo src, int state) { mDevice = src.mDevice; mState = state; mProfile = src.mProfile; mSupprNoisy = src.mSupprNoisy; mVolume = src.mVolume; mIsLeOutput = src.mIsLeOutput; mEventSource = src.mEventSource; mAudioSystemDevice = src.mAudioSystemDevice; mMusicDevice = src.mMusicDevice; mCodec = src.mCodec; } // redefine equality op so we can match messages intended for this device @Override public boolean equals(Object o) { Loading Loading @@ -829,7 +816,7 @@ import java.util.concurrent.atomic.AtomicBoolean; * @param info struct with the (dis)connection information */ /*package*/ void queueOnBluetoothActiveDeviceChanged(@NonNull BtDeviceChangedData data) { if (data.mPreviousDevice != null if (data.mInfo.getProfile() == BluetoothProfile.A2DP && data.mPreviousDevice != null && data.mPreviousDevice.equals(data.mNewDevice)) { final String name = TextUtils.emptyIfNull(data.mNewDevice.getName()); new MediaMetrics.Item(MediaMetrics.Name.AUDIO_DEVICE + MediaMetrics.SEPARATOR Loading @@ -838,8 +825,7 @@ import java.util.concurrent.atomic.AtomicBoolean; .set(MediaMetrics.Property.STATUS, data.mInfo.getProfile()) .record(); synchronized (mDeviceStateLock) { postBluetoothDeviceConfigChange(createBtDeviceInfo(data, data.mNewDevice, BluetoothProfile.STATE_CONNECTED)); postBluetoothA2dpDeviceConfigChange(data.mNewDevice); } } else { synchronized (mDeviceStateLock) { Loading Loading @@ -1064,8 +1050,8 @@ import java.util.concurrent.atomic.AtomicBoolean; new AudioModeInfo(mode, pid, uid)); } /*package*/ void postBluetoothDeviceConfigChange(@NonNull BtDeviceInfo info) { sendLMsgNoDelay(MSG_L_BLUETOOTH_DEVICE_CONFIG_CHANGE, SENDMSG_QUEUE, info); /*package*/ void postBluetoothA2dpDeviceConfigChange(@NonNull BluetoothDevice device) { sendLMsgNoDelay(MSG_L_A2DP_DEVICE_CONFIG_CHANGE, SENDMSG_QUEUE, device); } /*package*/ void startBluetoothScoForClient(IBinder cb, int pid, int scoAudioMode, Loading Loading @@ -1322,10 +1308,6 @@ import java.util.concurrent.atomic.AtomicBoolean; sendIMsgNoDelay(MSG_I_SCO_AUDIO_STATE_CHANGED, SENDMSG_QUEUE, state); } /*package*/ void postNotifyPreferredAudioProfileApplied(BluetoothDevice btDevice) { sendLMsgNoDelay(MSG_L_NOTIFY_PREFERRED_AUDIOPROFILE_APPLIED, SENDMSG_QUEUE, btDevice); } /*package*/ static final class CommunicationDeviceInfo { final @NonNull IBinder mCb; // Identifies the requesting client for death handler final int mPid; // Requester process ID Loading Loading @@ -1401,11 +1383,9 @@ import java.util.concurrent.atomic.AtomicBoolean; } } /*package*/ boolean handleDeviceConnection(AudioDeviceAttributes attributes, boolean connect, @Nullable BluetoothDevice btDevice) { /*package*/ boolean handleDeviceConnection(AudioDeviceAttributes attributes, boolean connect) { synchronized (mDeviceStateLock) { return mDeviceInventory.handleDeviceConnection( attributes, connect, false /*for test*/, btDevice); return mDeviceInventory.handleDeviceConnection(attributes, connect, false /*for test*/); } } Loading Loading @@ -1646,10 +1626,13 @@ import java.util.concurrent.atomic.AtomicBoolean; (String) msg.obj, msg.arg1); } break; case MSG_L_BLUETOOTH_DEVICE_CONFIG_CHANGE: case MSG_L_A2DP_DEVICE_CONFIG_CHANGE: final BluetoothDevice btDevice = (BluetoothDevice) msg.obj; synchronized (mDeviceStateLock) { mDeviceInventory.onBluetoothDeviceConfigChange( (BtDeviceInfo) msg.obj, BtHelper.EVENT_DEVICE_CONFIG_CHANGE); final int a2dpCodec = mBtHelper.getA2dpCodec(btDevice); mDeviceInventory.onBluetoothA2dpDeviceConfigChange( new BtHelper.BluetoothA2dpDeviceInfo(btDevice, -1, a2dpCodec), BtHelper.EVENT_DEVICE_CONFIG_CHANGE); } break; case MSG_BROADCAST_AUDIO_BECOMING_NOISY: Loading Loading @@ -1807,10 +1790,6 @@ import java.util.concurrent.atomic.AtomicBoolean; final int capturePreset = msg.arg1; mDeviceInventory.onSaveClearPreferredDevicesForCapturePreset(capturePreset); } break; case MSG_L_NOTIFY_PREFERRED_AUDIOPROFILE_APPLIED: { final BluetoothDevice btDevice = (BluetoothDevice) msg.obj; BtHelper.onNotifyPreferredAudioProfileApplied(btDevice); } break; default: Log.wtf(TAG, "Invalid message " + msg.what); } Loading Loading @@ -1846,7 +1825,7 @@ import java.util.concurrent.atomic.AtomicBoolean; private static final int MSG_IL_BTA2DP_TIMEOUT = 10; // process change of A2DP device configuration, obj is BluetoothDevice private static final int MSG_L_BLUETOOTH_DEVICE_CONFIG_CHANGE = 11; private static final int MSG_L_A2DP_DEVICE_CONFIG_CHANGE = 11; private static final int MSG_BROADCAST_AUDIO_BECOMING_NOISY = 12; private static final int MSG_REPORT_NEW_ROUTES = 13; Loading Loading @@ -1886,15 +1865,13 @@ import java.util.concurrent.atomic.AtomicBoolean; private static final int MSG_IL_SAVE_REMOVE_NDEF_DEVICE_FOR_STRATEGY = 48; private static final int MSG_IL_BTLEAUDIO_TIMEOUT = 49; private static final int MSG_L_NOTIFY_PREFERRED_AUDIOPROFILE_APPLIED = 50; private static boolean isMessageHandledUnderWakelock(int msgId) { switch(msgId) { case MSG_L_SET_WIRED_DEVICE_CONNECTION_STATE: case MSG_L_SET_BT_ACTIVE_DEVICE: case MSG_IL_BTA2DP_TIMEOUT: case MSG_IL_BTLEAUDIO_TIMEOUT: case MSG_L_BLUETOOTH_DEVICE_CONFIG_CHANGE: case MSG_L_A2DP_DEVICE_CONFIG_CHANGE: case MSG_TOGGLE_HDMI: case MSG_L_A2DP_DEVICE_CONNECTION_CHANGE_EXT: case MSG_L_HEARING_AID_DEVICE_CONNECTION_CHANGE_EXT: Loading Loading @@ -1986,7 +1963,7 @@ import java.util.concurrent.atomic.AtomicBoolean; case MSG_L_SET_WIRED_DEVICE_CONNECTION_STATE: case MSG_IL_BTA2DP_TIMEOUT: case MSG_IL_BTLEAUDIO_TIMEOUT: case MSG_L_BLUETOOTH_DEVICE_CONFIG_CHANGE: case MSG_L_A2DP_DEVICE_CONFIG_CHANGE: if (sLastDeviceConnectMsgTime >= time) { // add a little delay to make sure messages are ordered as expected time = sLastDeviceConnectMsgTime + 30; Loading @@ -2006,7 +1983,7 @@ import java.util.concurrent.atomic.AtomicBoolean; static { MESSAGES_MUTE_MUSIC = new HashSet<>(); MESSAGES_MUTE_MUSIC.add(MSG_L_SET_BT_ACTIVE_DEVICE); MESSAGES_MUTE_MUSIC.add(MSG_L_BLUETOOTH_DEVICE_CONFIG_CHANGE); MESSAGES_MUTE_MUSIC.add(MSG_L_A2DP_DEVICE_CONFIG_CHANGE); MESSAGES_MUTE_MUSIC.add(MSG_L_A2DP_DEVICE_CONNECTION_CHANGE_EXT); MESSAGES_MUTE_MUSIC.add(MSG_IIL_SET_FORCE_BT_A2DP_USE); } Loading @@ -2027,7 +2004,7 @@ import java.util.concurrent.atomic.AtomicBoolean; // Do not mute on bluetooth event if music is playing on a wired headset. if ((message == MSG_L_SET_BT_ACTIVE_DEVICE || message == MSG_L_A2DP_DEVICE_CONNECTION_CHANGE_EXT || message == MSG_L_BLUETOOTH_DEVICE_CONFIG_CHANGE) || message == MSG_L_A2DP_DEVICE_CONFIG_CHANGE) && AudioSystem.isStreamActive(AudioSystem.STREAM_MUSIC, 0) && hasIntersection(mDeviceInventory.DEVICE_OVERRIDE_A2DP_ROUTE_ON_PLUG_SET, mAudioService.getDeviceSetForStream(AudioSystem.STREAM_MUSIC))) { Loading Loading @@ -2166,19 +2143,18 @@ import java.util.concurrent.atomic.AtomicBoolean; if (preferredCommunicationDevice == null) { AudioDeviceAttributes defaultDevice = getDefaultCommunicationDevice(); if (defaultDevice != null) { mDeviceInventory.setPreferredDevicesForStrategy( setPreferredDevicesForStrategySync( mCommunicationStrategyId, Arrays.asList(defaultDevice)); mDeviceInventory.setPreferredDevicesForStrategy( setPreferredDevicesForStrategySync( mAccessibilityStrategyId, Arrays.asList(defaultDevice)); } else { mDeviceInventory.removePreferredDevicesForStrategy(mCommunicationStrategyId); mDeviceInventory.removePreferredDevicesForStrategy(mAccessibilityStrategyId); removePreferredDevicesForStrategySync(mCommunicationStrategyId); removePreferredDevicesForStrategySync(mAccessibilityStrategyId); } mDeviceInventory.applyConnectedDevicesRoles(); } else { mDeviceInventory.setPreferredDevicesForStrategy( setPreferredDevicesForStrategySync( mCommunicationStrategyId, Arrays.asList(preferredCommunicationDevice)); mDeviceInventory.setPreferredDevicesForStrategy( setPreferredDevicesForStrategySync( mAccessibilityStrategyId, Arrays.asList(preferredCommunicationDevice)); } onUpdatePhoneStrategyDevice(preferredCommunicationDevice); Loading
services/core/java/com/android/server/audio/AudioDeviceInventory.java +132 −669 File changed.Preview size limit exceeded, changes collapsed. Show changes
services/core/java/com/android/server/audio/AudioSystemAdapter.java +1 −14 Original line number Diff line number Diff line Loading @@ -435,7 +435,7 @@ public class AudioSystemAdapter implements AudioSystem.RoutingUpdateCallback, } /** * Same as {@link AudioSystem#removeDevicesRoleForCapturePreset(int, int, List)} * Same as {@link AudioSystem#removeDevicesRoleForCapturePreset(int, int, int[], String[])} * @param capturePreset * @param role * @param devicesToRemove Loading @@ -447,19 +447,6 @@ public class AudioSystemAdapter implements AudioSystem.RoutingUpdateCallback, return AudioSystem.removeDevicesRoleForCapturePreset(capturePreset, role, devicesToRemove); } /** * Same as {@link AudioSystem#addDevicesRoleForCapturePreset(int, int, List)} * @param capturePreset the capture preset to configure * @param role the role of the devices * @param devices the list of devices to be added as role for the given capture preset * @return {@link #SUCCESS} if successfully add */ public int addDevicesRoleForCapturePreset( int capturePreset, int role, @NonNull List<AudioDeviceAttributes> devices) { invalidateRoutingCache(); return AudioSystem.addDevicesRoleForCapturePreset(capturePreset, role, devices); } /** * Same as {@link AudioSystem#} * @param capturePreset Loading
services/core/java/com/android/server/audio/BtHelper.java +59 −34 Original line number Diff line number Diff line Loading @@ -33,7 +33,6 @@ import android.media.AudioManager; import android.media.AudioSystem; import android.media.BluetoothProfileConnectionInfo; import android.os.Binder; import android.os.Bundle; import android.os.UserHandle; import android.provider.Settings; import android.text.TextUtils; Loading Loading @@ -151,12 +150,60 @@ public class BtHelper { } } //---------------------------------------------------------------------- /*package*/ static class BluetoothA2dpDeviceInfo { private final @NonNull BluetoothDevice mBtDevice; private final int mVolume; private final @AudioSystem.AudioFormatNativeEnumForBtCodec int mCodec; BluetoothA2dpDeviceInfo(@NonNull BluetoothDevice btDevice) { this(btDevice, -1, AudioSystem.AUDIO_FORMAT_DEFAULT); } BluetoothA2dpDeviceInfo(@NonNull BluetoothDevice btDevice, int volume, int codec) { mBtDevice = btDevice; mVolume = volume; mCodec = codec; } public @NonNull BluetoothDevice getBtDevice() { return mBtDevice; } public int getVolume() { return mVolume; } public @AudioSystem.AudioFormatNativeEnumForBtCodec int getCodec() { return mCodec; } // redefine equality op so we can match messages intended for this device @Override public boolean equals(Object o) { if (o == null) { return false; } if (this == o) { return true; } if (o instanceof BluetoothA2dpDeviceInfo) { return mBtDevice.equals(((BluetoothA2dpDeviceInfo) o).getBtDevice()); } return false; } } // A2DP device events /*package*/ static final int EVENT_DEVICE_CONFIG_CHANGE = 0; /*package*/ static final int EVENT_ACTIVE_DEVICE_CHANGE = 1; /*package*/ static String deviceEventToString(int event) { /*package*/ static String a2dpDeviceEventToString(int event) { switch (event) { case EVENT_DEVICE_CONFIG_CHANGE: return "DEVICE_CONFIG_CHANGE"; case EVENT_ACTIVE_DEVICE_CHANGE: return "ACTIVE_DEVICE_CHANGE"; default: return new String("invalid event:" + event); } Loading Loading @@ -573,12 +620,11 @@ public class BtHelper { return btHeadsetDeviceToAudioDevice(mBluetoothHeadsetDevice); } private static AudioDeviceAttributes btHeadsetDeviceToAudioDevice(BluetoothDevice btDevice) { private AudioDeviceAttributes btHeadsetDeviceToAudioDevice(BluetoothDevice btDevice) { if (btDevice == null) { return new AudioDeviceAttributes(AudioSystem.DEVICE_OUT_BLUETOOTH_SCO, ""); } String address = btDevice.getAddress(); String name = getName(btDevice); if (!BluetoothAdapter.checkBluetoothAddress(address)) { address = ""; } Loading @@ -600,7 +646,7 @@ public class BtHelper { + " btClass: " + (btClass == null ? "Unknown" : btClass) + " nativeType: " + nativeType + " address: " + address); } return new AudioDeviceAttributes(nativeType, address, name); return new AudioDeviceAttributes(nativeType, address); } private boolean handleBtScoActiveDeviceChange(BluetoothDevice btDevice, boolean isActive) { Loading @@ -609,9 +655,12 @@ public class BtHelper { } int inDevice = AudioSystem.DEVICE_IN_BLUETOOTH_SCO_HEADSET; AudioDeviceAttributes audioDevice = btHeadsetDeviceToAudioDevice(btDevice); String btDeviceName = getName(btDevice); boolean result = false; if (isActive) { result |= mDeviceBroker.handleDeviceConnection(audioDevice, isActive, btDevice); result |= mDeviceBroker.handleDeviceConnection(new AudioDeviceAttributes( audioDevice.getInternalType(), audioDevice.getAddress(), btDeviceName), isActive); } else { int[] outDeviceTypes = { AudioSystem.DEVICE_OUT_BLUETOOTH_SCO, Loading @@ -620,14 +669,14 @@ public class BtHelper { }; for (int outDeviceType : outDeviceTypes) { result |= mDeviceBroker.handleDeviceConnection(new AudioDeviceAttributes( outDeviceType, audioDevice.getAddress(), audioDevice.getName()), isActive, btDevice); outDeviceType, audioDevice.getAddress(), btDeviceName), isActive); } } // handleDeviceConnection() && result to make sure the method get executed result = mDeviceBroker.handleDeviceConnection(new AudioDeviceAttributes( inDevice, audioDevice.getAddress(), audioDevice.getName()), isActive, btDevice) && result; inDevice, audioDevice.getAddress(), btDeviceName), isActive) && result; return result; } Loading Loading @@ -924,30 +973,6 @@ public class BtHelper { } } /*package */ static int getProfileFromType(int deviceType) { if (AudioSystem.isBluetoothA2dpOutDevice(deviceType)) { return BluetoothProfile.A2DP; } else if (AudioSystem.isBluetoothScoDevice(deviceType)) { return BluetoothProfile.HEADSET; } else if (AudioSystem.isBluetoothLeDevice(deviceType)) { return BluetoothProfile.LE_AUDIO; } return 0; // 0 is not a valid profile } /*package */ static Bundle getPreferredAudioProfiles(String address) { BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); return adapter.getPreferredAudioProfiles(adapter.getRemoteDevice(address)); } /** * Notifies Bluetooth framework that new preferred audio profiles for Bluetooth devices * have been applied. */ public static void onNotifyPreferredAudioProfileApplied(BluetoothDevice btDevice) { BluetoothAdapter.getDefaultAdapter().notifyActiveDeviceChangeApplied(btDevice); } /** * Returns the string equivalent for the btDeviceClass class. */ Loading