Loading media/java/android/media/AudioDeviceAttributes.java +25 −1 Original line number Diff line number Diff line Loading @@ -68,7 +68,7 @@ public final class AudioDeviceAttributes implements Parcelable { /** * The unique address of the device. Some devices don't have addresses, only an empty string. */ private final @NonNull String mAddress; private @NonNull String mAddress; /** * The non-unique name of the device. Some devices don't have names, only an empty string. * Should not be used as a unique identifier for a device. Loading Loading @@ -186,6 +186,21 @@ public final class AudioDeviceAttributes implements Parcelable { mAudioDescriptors = new ArrayList<>(); } /** * @hide * Copy Constructor. * @param ada the copied AudioDeviceAttributes */ public AudioDeviceAttributes(AudioDeviceAttributes ada) { mRole = ada.getRole(); mType = ada.getType(); mAddress = ada.getAddress(); mName = ada.getName(); mNativeType = ada.getInternalType(); mAudioProfiles = ada.getAudioProfiles(); mAudioDescriptors = ada.getAudioDescriptors(); } /** * @hide * Returns the role of a device Loading Loading @@ -216,6 +231,15 @@ public final class AudioDeviceAttributes implements Parcelable { return mAddress; } /** * @hide * Sets the device address. Only used by audio service. */ public void setAddress(@NonNull String address) { Objects.requireNonNull(address); mAddress = address; } /** * @hide * Returns the name of the audio device, or an empty string for devices without one Loading services/core/java/com/android/server/audio/AdiDeviceState.java +2 −1 Original line number Diff line number Diff line Loading @@ -165,7 +165,8 @@ import java.util.Objects; @Override public String toString() { return "type: " + mDeviceType + "internal type: " + mInternalDeviceType return "type: " + mDeviceType + " internal type: 0x" + Integer.toHexString(mInternalDeviceType) + " addr: " + mDeviceAddress + " bt audio type: " + AudioManager.audioDeviceCategoryToString(mAudioDeviceCategory) + " enabled: " + mSAEnabled + " HT: " + mHasHeadTracker Loading services/core/java/com/android/server/audio/AudioDeviceBroker.java +12 −6 Original line number Diff line number Diff line Loading @@ -1252,8 +1252,8 @@ public class AudioDeviceBroker { } /*package*/ void registerStrategyPreferredDevicesDispatcher( @NonNull IStrategyPreferredDevicesDispatcher dispatcher) { mDeviceInventory.registerStrategyPreferredDevicesDispatcher(dispatcher); @NonNull IStrategyPreferredDevicesDispatcher dispatcher, boolean isPrivileged) { mDeviceInventory.registerStrategyPreferredDevicesDispatcher(dispatcher, isPrivileged); } /*package*/ void unregisterStrategyPreferredDevicesDispatcher( Loading @@ -1262,8 +1262,8 @@ public class AudioDeviceBroker { } /*package*/ void registerStrategyNonDefaultDevicesDispatcher( @NonNull IStrategyNonDefaultDevicesDispatcher dispatcher) { mDeviceInventory.registerStrategyNonDefaultDevicesDispatcher(dispatcher); @NonNull IStrategyNonDefaultDevicesDispatcher dispatcher, boolean isPrivileged) { mDeviceInventory.registerStrategyNonDefaultDevicesDispatcher(dispatcher, isPrivileged); } /*package*/ void unregisterStrategyNonDefaultDevicesDispatcher( Loading @@ -1281,8 +1281,8 @@ public class AudioDeviceBroker { } /*package*/ void registerCapturePresetDevicesRoleDispatcher( @NonNull ICapturePresetDevicesRoleDispatcher dispatcher) { mDeviceInventory.registerCapturePresetDevicesRoleDispatcher(dispatcher); @NonNull ICapturePresetDevicesRoleDispatcher dispatcher, boolean isPrivileged) { mDeviceInventory.registerCapturePresetDevicesRoleDispatcher(dispatcher, isPrivileged); } /*package*/ void unregisterCapturePresetDevicesRoleDispatcher( Loading @@ -1290,6 +1290,11 @@ public class AudioDeviceBroker { mDeviceInventory.unregisterCapturePresetDevicesRoleDispatcher(dispatcher); } /* package */ List<AudioDeviceAttributes> anonymizeAudioDeviceAttributesListUnchecked( List<AudioDeviceAttributes> devices) { return mAudioService.anonymizeAudioDeviceAttributesListUnchecked(devices); } /*package*/ void registerCommunicationDeviceDispatcher( @NonNull ICommunicationDeviceDispatcher dispatcher) { mCommDevDispatchers.register(dispatcher); Loading Loading @@ -2684,4 +2689,5 @@ public class AudioDeviceBroker { void clearDeviceInventory() { mDeviceInventory.clearDeviceInventory(); } } services/core/java/com/android/server/audio/AudioDeviceInventory.java +43 −9 Original line number Diff line number Diff line Loading @@ -120,6 +120,26 @@ public class AudioDeviceInventory { } } /** * Adds a new entry in mDeviceInventory if the AudioDeviceAttributes passed is an sink * Bluetooth device and no corresponding entry already exists. * @param ada the device to add if needed */ void addAudioDeviceInInventoryIfNeeded(AudioDeviceAttributes ada) { if (!AudioSystem.isBluetoothOutDevice(ada.getInternalType())) { return; } synchronized (mDeviceInventoryLock) { if (findDeviceStateForAudioDeviceAttributes(ada, ada.getType()) != null) { return; } AdiDeviceState ads = new AdiDeviceState( ada.getType(), ada.getInternalType(), ada.getAddress()); mDeviceInventory.put(ads.getDeviceId(), ads); } mDeviceBroker.persistAudioDeviceSettings(); } /** * Adds a new AdiDeviceState or updates the audio device cateogory of the matching * AdiDeviceState in the {@link AudioDeviceInventory#mDeviceInventory} list. Loading Loading @@ -992,8 +1012,8 @@ public class AudioDeviceInventory { /*package*/ void registerStrategyPreferredDevicesDispatcher( @NonNull IStrategyPreferredDevicesDispatcher dispatcher) { mPrefDevDispatchers.register(dispatcher); @NonNull IStrategyPreferredDevicesDispatcher dispatcher, boolean isPrivileged) { mPrefDevDispatchers.register(dispatcher, isPrivileged); } /*package*/ void unregisterStrategyPreferredDevicesDispatcher( Loading @@ -1002,8 +1022,8 @@ public class AudioDeviceInventory { } /*package*/ void registerStrategyNonDefaultDevicesDispatcher( @NonNull IStrategyNonDefaultDevicesDispatcher dispatcher) { mNonDefDevDispatchers.register(dispatcher); @NonNull IStrategyNonDefaultDevicesDispatcher dispatcher, boolean isPrivileged) { mNonDefDevDispatchers.register(dispatcher, isPrivileged); } /*package*/ void unregisterStrategyNonDefaultDevicesDispatcher( Loading Loading @@ -1084,8 +1104,8 @@ public class AudioDeviceInventory { } /*package*/ void registerCapturePresetDevicesRoleDispatcher( @NonNull ICapturePresetDevicesRoleDispatcher dispatcher) { mDevRoleCapturePresetDispatchers.register(dispatcher); @NonNull ICapturePresetDevicesRoleDispatcher dispatcher, boolean isPrivileged) { mDevRoleCapturePresetDispatchers.register(dispatcher, isPrivileged); } /*package*/ void unregisterCapturePresetDevicesRoleDispatcher( Loading Loading @@ -1414,6 +1434,8 @@ public class AudioDeviceInventory { updateBluetoothPreferredModes_l(connect ? btDevice : null /*connectedDevice*/); if (!connect) { purgeDevicesRoles_l(); } else { addAudioDeviceInInventoryIfNeeded(attributes); } } mmi.set(MediaMetrics.Property.STATE, MediaMetrics.Value.CONNECTED).record(); Loading Loading @@ -1702,6 +1724,7 @@ public class AudioDeviceInventory { setCurrentAudioRouteNameIfPossible(name, true /*fromA2dp*/); updateBluetoothPreferredModes_l(btInfo.mDevice /*connectedDevice*/); addAudioDeviceInInventoryIfNeeded(ada); } static final int[] CAPTURE_PRESETS = new int[] {AudioSource.MIC, AudioSource.CAMCORDER, Loading Loading @@ -2006,9 +2029,9 @@ public class AudioDeviceInventory { final int hearingAidVolIndex = mDeviceBroker.getVssVolumeForDevice(streamType, AudioSystem.DEVICE_OUT_HEARING_AID); mDeviceBroker.postSetHearingAidVolumeIndex(hearingAidVolIndex, streamType); mAudioSystem.setDeviceConnectionState(new AudioDeviceAttributes( AudioSystem.DEVICE_OUT_HEARING_AID, address, name), AudioDeviceAttributes ada = new AudioDeviceAttributes( AudioSystem.DEVICE_OUT_HEARING_AID, address, name); mAudioSystem.setDeviceConnectionState(ada, AudioSystem.DEVICE_STATE_AVAILABLE, AudioSystem.AUDIO_FORMAT_DEFAULT); mConnectedDevices.put( Loading @@ -2018,6 +2041,7 @@ public class AudioDeviceInventory { mDeviceBroker.postApplyVolumeOnDevice(streamType, AudioSystem.DEVICE_OUT_HEARING_AID, "makeHearingAidDeviceAvailable"); setCurrentAudioRouteNameIfPossible(name, false /*fromA2dp*/); addAudioDeviceInInventoryIfNeeded(ada); new MediaMetrics.Item(mMetricsId + "makeHearingAidDeviceAvailable") .set(MediaMetrics.Property.ADDRESS, address != null ? address : "") .set(MediaMetrics.Property.DEVICE, Loading Loading @@ -2128,6 +2152,7 @@ public class AudioDeviceInventory { sensorUuid)); mDeviceBroker.postAccessoryPlugMediaUnmute(device); setCurrentAudioRouteNameIfPossible(name, /*fromA2dp=*/false); addAudioDeviceInInventoryIfNeeded(ada); } if (streamType == AudioSystem.STREAM_DEFAULT) { Loading Loading @@ -2462,6 +2487,9 @@ public class AudioDeviceInventory { final int nbDispatchers = mPrefDevDispatchers.beginBroadcast(); for (int i = 0; i < nbDispatchers; i++) { try { if (!((Boolean) mPrefDevDispatchers.getBroadcastCookie(i))) { devices = mDeviceBroker.anonymizeAudioDeviceAttributesListUnchecked(devices); } mPrefDevDispatchers.getBroadcastItem(i).dispatchPrefDevicesChanged( strategy, devices); } catch (RemoteException e) { Loading @@ -2475,6 +2503,9 @@ public class AudioDeviceInventory { final int nbDispatchers = mNonDefDevDispatchers.beginBroadcast(); for (int i = 0; i < nbDispatchers; i++) { try { if (!((Boolean) mNonDefDevDispatchers.getBroadcastCookie(i))) { devices = mDeviceBroker.anonymizeAudioDeviceAttributesListUnchecked(devices); } mNonDefDevDispatchers.getBroadcastItem(i).dispatchNonDefDevicesChanged( strategy, devices); } catch (RemoteException e) { Loading @@ -2488,6 +2519,9 @@ public class AudioDeviceInventory { final int nbDispatchers = mDevRoleCapturePresetDispatchers.beginBroadcast(); for (int i = 0; i < nbDispatchers; ++i) { try { if (!((Boolean) mDevRoleCapturePresetDispatchers.getBroadcastCookie(i))) { devices = mDeviceBroker.anonymizeAudioDeviceAttributesListUnchecked(devices); } mDevRoleCapturePresetDispatchers.getBroadcastItem(i).dispatchDevicesRoleChanged( capturePreset, role, devices); } catch (RemoteException e) { Loading services/core/java/com/android/server/audio/AudioService.java +189 −27 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
media/java/android/media/AudioDeviceAttributes.java +25 −1 Original line number Diff line number Diff line Loading @@ -68,7 +68,7 @@ public final class AudioDeviceAttributes implements Parcelable { /** * The unique address of the device. Some devices don't have addresses, only an empty string. */ private final @NonNull String mAddress; private @NonNull String mAddress; /** * The non-unique name of the device. Some devices don't have names, only an empty string. * Should not be used as a unique identifier for a device. Loading Loading @@ -186,6 +186,21 @@ public final class AudioDeviceAttributes implements Parcelable { mAudioDescriptors = new ArrayList<>(); } /** * @hide * Copy Constructor. * @param ada the copied AudioDeviceAttributes */ public AudioDeviceAttributes(AudioDeviceAttributes ada) { mRole = ada.getRole(); mType = ada.getType(); mAddress = ada.getAddress(); mName = ada.getName(); mNativeType = ada.getInternalType(); mAudioProfiles = ada.getAudioProfiles(); mAudioDescriptors = ada.getAudioDescriptors(); } /** * @hide * Returns the role of a device Loading Loading @@ -216,6 +231,15 @@ public final class AudioDeviceAttributes implements Parcelable { return mAddress; } /** * @hide * Sets the device address. Only used by audio service. */ public void setAddress(@NonNull String address) { Objects.requireNonNull(address); mAddress = address; } /** * @hide * Returns the name of the audio device, or an empty string for devices without one Loading
services/core/java/com/android/server/audio/AdiDeviceState.java +2 −1 Original line number Diff line number Diff line Loading @@ -165,7 +165,8 @@ import java.util.Objects; @Override public String toString() { return "type: " + mDeviceType + "internal type: " + mInternalDeviceType return "type: " + mDeviceType + " internal type: 0x" + Integer.toHexString(mInternalDeviceType) + " addr: " + mDeviceAddress + " bt audio type: " + AudioManager.audioDeviceCategoryToString(mAudioDeviceCategory) + " enabled: " + mSAEnabled + " HT: " + mHasHeadTracker Loading
services/core/java/com/android/server/audio/AudioDeviceBroker.java +12 −6 Original line number Diff line number Diff line Loading @@ -1252,8 +1252,8 @@ public class AudioDeviceBroker { } /*package*/ void registerStrategyPreferredDevicesDispatcher( @NonNull IStrategyPreferredDevicesDispatcher dispatcher) { mDeviceInventory.registerStrategyPreferredDevicesDispatcher(dispatcher); @NonNull IStrategyPreferredDevicesDispatcher dispatcher, boolean isPrivileged) { mDeviceInventory.registerStrategyPreferredDevicesDispatcher(dispatcher, isPrivileged); } /*package*/ void unregisterStrategyPreferredDevicesDispatcher( Loading @@ -1262,8 +1262,8 @@ public class AudioDeviceBroker { } /*package*/ void registerStrategyNonDefaultDevicesDispatcher( @NonNull IStrategyNonDefaultDevicesDispatcher dispatcher) { mDeviceInventory.registerStrategyNonDefaultDevicesDispatcher(dispatcher); @NonNull IStrategyNonDefaultDevicesDispatcher dispatcher, boolean isPrivileged) { mDeviceInventory.registerStrategyNonDefaultDevicesDispatcher(dispatcher, isPrivileged); } /*package*/ void unregisterStrategyNonDefaultDevicesDispatcher( Loading @@ -1281,8 +1281,8 @@ public class AudioDeviceBroker { } /*package*/ void registerCapturePresetDevicesRoleDispatcher( @NonNull ICapturePresetDevicesRoleDispatcher dispatcher) { mDeviceInventory.registerCapturePresetDevicesRoleDispatcher(dispatcher); @NonNull ICapturePresetDevicesRoleDispatcher dispatcher, boolean isPrivileged) { mDeviceInventory.registerCapturePresetDevicesRoleDispatcher(dispatcher, isPrivileged); } /*package*/ void unregisterCapturePresetDevicesRoleDispatcher( Loading @@ -1290,6 +1290,11 @@ public class AudioDeviceBroker { mDeviceInventory.unregisterCapturePresetDevicesRoleDispatcher(dispatcher); } /* package */ List<AudioDeviceAttributes> anonymizeAudioDeviceAttributesListUnchecked( List<AudioDeviceAttributes> devices) { return mAudioService.anonymizeAudioDeviceAttributesListUnchecked(devices); } /*package*/ void registerCommunicationDeviceDispatcher( @NonNull ICommunicationDeviceDispatcher dispatcher) { mCommDevDispatchers.register(dispatcher); Loading Loading @@ -2684,4 +2689,5 @@ public class AudioDeviceBroker { void clearDeviceInventory() { mDeviceInventory.clearDeviceInventory(); } }
services/core/java/com/android/server/audio/AudioDeviceInventory.java +43 −9 Original line number Diff line number Diff line Loading @@ -120,6 +120,26 @@ public class AudioDeviceInventory { } } /** * Adds a new entry in mDeviceInventory if the AudioDeviceAttributes passed is an sink * Bluetooth device and no corresponding entry already exists. * @param ada the device to add if needed */ void addAudioDeviceInInventoryIfNeeded(AudioDeviceAttributes ada) { if (!AudioSystem.isBluetoothOutDevice(ada.getInternalType())) { return; } synchronized (mDeviceInventoryLock) { if (findDeviceStateForAudioDeviceAttributes(ada, ada.getType()) != null) { return; } AdiDeviceState ads = new AdiDeviceState( ada.getType(), ada.getInternalType(), ada.getAddress()); mDeviceInventory.put(ads.getDeviceId(), ads); } mDeviceBroker.persistAudioDeviceSettings(); } /** * Adds a new AdiDeviceState or updates the audio device cateogory of the matching * AdiDeviceState in the {@link AudioDeviceInventory#mDeviceInventory} list. Loading Loading @@ -992,8 +1012,8 @@ public class AudioDeviceInventory { /*package*/ void registerStrategyPreferredDevicesDispatcher( @NonNull IStrategyPreferredDevicesDispatcher dispatcher) { mPrefDevDispatchers.register(dispatcher); @NonNull IStrategyPreferredDevicesDispatcher dispatcher, boolean isPrivileged) { mPrefDevDispatchers.register(dispatcher, isPrivileged); } /*package*/ void unregisterStrategyPreferredDevicesDispatcher( Loading @@ -1002,8 +1022,8 @@ public class AudioDeviceInventory { } /*package*/ void registerStrategyNonDefaultDevicesDispatcher( @NonNull IStrategyNonDefaultDevicesDispatcher dispatcher) { mNonDefDevDispatchers.register(dispatcher); @NonNull IStrategyNonDefaultDevicesDispatcher dispatcher, boolean isPrivileged) { mNonDefDevDispatchers.register(dispatcher, isPrivileged); } /*package*/ void unregisterStrategyNonDefaultDevicesDispatcher( Loading Loading @@ -1084,8 +1104,8 @@ public class AudioDeviceInventory { } /*package*/ void registerCapturePresetDevicesRoleDispatcher( @NonNull ICapturePresetDevicesRoleDispatcher dispatcher) { mDevRoleCapturePresetDispatchers.register(dispatcher); @NonNull ICapturePresetDevicesRoleDispatcher dispatcher, boolean isPrivileged) { mDevRoleCapturePresetDispatchers.register(dispatcher, isPrivileged); } /*package*/ void unregisterCapturePresetDevicesRoleDispatcher( Loading Loading @@ -1414,6 +1434,8 @@ public class AudioDeviceInventory { updateBluetoothPreferredModes_l(connect ? btDevice : null /*connectedDevice*/); if (!connect) { purgeDevicesRoles_l(); } else { addAudioDeviceInInventoryIfNeeded(attributes); } } mmi.set(MediaMetrics.Property.STATE, MediaMetrics.Value.CONNECTED).record(); Loading Loading @@ -1702,6 +1724,7 @@ public class AudioDeviceInventory { setCurrentAudioRouteNameIfPossible(name, true /*fromA2dp*/); updateBluetoothPreferredModes_l(btInfo.mDevice /*connectedDevice*/); addAudioDeviceInInventoryIfNeeded(ada); } static final int[] CAPTURE_PRESETS = new int[] {AudioSource.MIC, AudioSource.CAMCORDER, Loading Loading @@ -2006,9 +2029,9 @@ public class AudioDeviceInventory { final int hearingAidVolIndex = mDeviceBroker.getVssVolumeForDevice(streamType, AudioSystem.DEVICE_OUT_HEARING_AID); mDeviceBroker.postSetHearingAidVolumeIndex(hearingAidVolIndex, streamType); mAudioSystem.setDeviceConnectionState(new AudioDeviceAttributes( AudioSystem.DEVICE_OUT_HEARING_AID, address, name), AudioDeviceAttributes ada = new AudioDeviceAttributes( AudioSystem.DEVICE_OUT_HEARING_AID, address, name); mAudioSystem.setDeviceConnectionState(ada, AudioSystem.DEVICE_STATE_AVAILABLE, AudioSystem.AUDIO_FORMAT_DEFAULT); mConnectedDevices.put( Loading @@ -2018,6 +2041,7 @@ public class AudioDeviceInventory { mDeviceBroker.postApplyVolumeOnDevice(streamType, AudioSystem.DEVICE_OUT_HEARING_AID, "makeHearingAidDeviceAvailable"); setCurrentAudioRouteNameIfPossible(name, false /*fromA2dp*/); addAudioDeviceInInventoryIfNeeded(ada); new MediaMetrics.Item(mMetricsId + "makeHearingAidDeviceAvailable") .set(MediaMetrics.Property.ADDRESS, address != null ? address : "") .set(MediaMetrics.Property.DEVICE, Loading Loading @@ -2128,6 +2152,7 @@ public class AudioDeviceInventory { sensorUuid)); mDeviceBroker.postAccessoryPlugMediaUnmute(device); setCurrentAudioRouteNameIfPossible(name, /*fromA2dp=*/false); addAudioDeviceInInventoryIfNeeded(ada); } if (streamType == AudioSystem.STREAM_DEFAULT) { Loading Loading @@ -2462,6 +2487,9 @@ public class AudioDeviceInventory { final int nbDispatchers = mPrefDevDispatchers.beginBroadcast(); for (int i = 0; i < nbDispatchers; i++) { try { if (!((Boolean) mPrefDevDispatchers.getBroadcastCookie(i))) { devices = mDeviceBroker.anonymizeAudioDeviceAttributesListUnchecked(devices); } mPrefDevDispatchers.getBroadcastItem(i).dispatchPrefDevicesChanged( strategy, devices); } catch (RemoteException e) { Loading @@ -2475,6 +2503,9 @@ public class AudioDeviceInventory { final int nbDispatchers = mNonDefDevDispatchers.beginBroadcast(); for (int i = 0; i < nbDispatchers; i++) { try { if (!((Boolean) mNonDefDevDispatchers.getBroadcastCookie(i))) { devices = mDeviceBroker.anonymizeAudioDeviceAttributesListUnchecked(devices); } mNonDefDevDispatchers.getBroadcastItem(i).dispatchNonDefDevicesChanged( strategy, devices); } catch (RemoteException e) { Loading @@ -2488,6 +2519,9 @@ public class AudioDeviceInventory { final int nbDispatchers = mDevRoleCapturePresetDispatchers.beginBroadcast(); for (int i = 0; i < nbDispatchers; ++i) { try { if (!((Boolean) mDevRoleCapturePresetDispatchers.getBroadcastCookie(i))) { devices = mDeviceBroker.anonymizeAudioDeviceAttributesListUnchecked(devices); } mDevRoleCapturePresetDispatchers.getBroadcastItem(i).dispatchDevicesRoleChanged( capturePreset, role, devices); } catch (RemoteException e) { Loading
services/core/java/com/android/server/audio/AudioService.java +189 −27 File changed.Preview size limit exceeded, changes collapsed. Show changes