RESTRICT AUTOMERGE - Revert "AudioService: anonymize Bluetooth MAC addresses"
Revert submission 25188138-anon_bt_address_udc_dev
Reason for revert: b/329515274
Reverted changes: /q/submissionid:25188138-anon_bt_address_udc_dev
Change-Id: I76e24a7e981c01e71464db1ce65b1f32ffb08fbc
Merged-In: Icd435c99c8a4f2d1e6053f35cd509b3f8f34ae24
diff --git a/media/java/android/media/AudioDeviceAttributes.java b/media/java/android/media/AudioDeviceAttributes.java
index 5a27435..af3c295 100644
--- a/media/java/android/media/AudioDeviceAttributes.java
+++ b/media/java/android/media/AudioDeviceAttributes.java
@@ -68,7 +68,7 @@
/**
* The unique address of the device. Some devices don't have addresses, only an empty string.
*/
- private @NonNull String mAddress;
+ private final @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.
@@ -188,21 +188,6 @@
/**
* @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
* @return the role
*/
@@ -233,15 +218,6 @@
/**
* @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
* @return the device name
*/
diff --git a/services/core/java/com/android/server/audio/AdiDeviceState.java b/services/core/java/com/android/server/audio/AdiDeviceState.java
index 1c456a7..683b3eb 100644
--- a/services/core/java/com/android/server/audio/AdiDeviceState.java
+++ b/services/core/java/com/android/server/audio/AdiDeviceState.java
@@ -25,7 +25,6 @@
import android.media.AudioDeviceInfo;
import android.text.TextUtils;
import android.util.Log;
-import android.util.Pair;
import java.util.Objects;
@@ -44,8 +43,6 @@
private final int mInternalDeviceType;
@NonNull
private final String mDeviceAddress;
- /** Unique device id from internal device type and address. */
- private final Pair<Integer, String> mDeviceId;
private boolean mSAEnabled;
private boolean mHasHeadTracker = false;
private boolean mHeadTrackerEnabled;
@@ -71,11 +68,6 @@
}
mDeviceAddress = isBluetoothDevice(mInternalDeviceType) ? Objects.requireNonNull(
address) : "";
- mDeviceId = new Pair<>(mInternalDeviceType, mDeviceAddress);
- }
-
- public Pair<Integer, String> getDeviceId() {
- return mDeviceId;
}
@AudioDeviceInfo.AudioDeviceType
@@ -146,8 +138,7 @@
@Override
public String toString() {
- return "type: " + mDeviceType
- + " internal type: 0x" + Integer.toHexString(mInternalDeviceType)
+ return "type: " + mDeviceType + "internal type: " + mInternalDeviceType
+ " addr: " + mDeviceAddress + " enabled: " + mSAEnabled
+ " HT: " + mHasHeadTracker + " HTenabled: " + mHeadTrackerEnabled;
}
diff --git a/services/core/java/com/android/server/audio/AudioDeviceBroker.java b/services/core/java/com/android/server/audio/AudioDeviceBroker.java
index 054a26f..bba85fd 100644
--- a/services/core/java/com/android/server/audio/AudioDeviceBroker.java
+++ b/services/core/java/com/android/server/audio/AudioDeviceBroker.java
@@ -1153,8 +1153,8 @@
}
/*package*/ void registerStrategyPreferredDevicesDispatcher(
- @NonNull IStrategyPreferredDevicesDispatcher dispatcher, boolean isPrivileged) {
- mDeviceInventory.registerStrategyPreferredDevicesDispatcher(dispatcher, isPrivileged);
+ @NonNull IStrategyPreferredDevicesDispatcher dispatcher) {
+ mDeviceInventory.registerStrategyPreferredDevicesDispatcher(dispatcher);
}
/*package*/ void unregisterStrategyPreferredDevicesDispatcher(
@@ -1163,8 +1163,8 @@
}
/*package*/ void registerStrategyNonDefaultDevicesDispatcher(
- @NonNull IStrategyNonDefaultDevicesDispatcher dispatcher, boolean isPrivileged) {
- mDeviceInventory.registerStrategyNonDefaultDevicesDispatcher(dispatcher, isPrivileged);
+ @NonNull IStrategyNonDefaultDevicesDispatcher dispatcher) {
+ mDeviceInventory.registerStrategyNonDefaultDevicesDispatcher(dispatcher);
}
/*package*/ void unregisterStrategyNonDefaultDevicesDispatcher(
@@ -1182,8 +1182,8 @@
}
/*package*/ void registerCapturePresetDevicesRoleDispatcher(
- @NonNull ICapturePresetDevicesRoleDispatcher dispatcher, boolean isPrivileged) {
- mDeviceInventory.registerCapturePresetDevicesRoleDispatcher(dispatcher, isPrivileged);
+ @NonNull ICapturePresetDevicesRoleDispatcher dispatcher) {
+ mDeviceInventory.registerCapturePresetDevicesRoleDispatcher(dispatcher);
}
/*package*/ void unregisterCapturePresetDevicesRoleDispatcher(
@@ -1191,11 +1191,6 @@
mDeviceInventory.unregisterCapturePresetDevicesRoleDispatcher(dispatcher);
}
- /* package */ List<AudioDeviceAttributes> anonymizeAudioDeviceAttributesListUnchecked(
- List<AudioDeviceAttributes> devices) {
- return mAudioService.anonymizeAudioDeviceAttributesListUnchecked(devices);
- }
-
/*package*/ void registerCommunicationDeviceDispatcher(
@NonNull ICommunicationDeviceDispatcher dispatcher) {
mCommDevDispatchers.register(dispatcher);
diff --git a/services/core/java/com/android/server/audio/AudioDeviceInventory.java b/services/core/java/com/android/server/audio/AudioDeviceInventory.java
index 5332aca..387646c 100644
--- a/services/core/java/com/android/server/audio/AudioDeviceInventory.java
+++ b/services/core/java/com/android/server/audio/AudioDeviceInventory.java
@@ -61,7 +61,6 @@
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
@@ -92,59 +91,31 @@
private final Object mDeviceInventoryLock = new Object();
@GuardedBy("mDeviceInventoryLock")
- private final HashMap<Pair<Integer, String>, AdiDeviceState> mDeviceInventory = new HashMap<>();
+ private final ArrayList<AdiDeviceState> mDeviceInventory = new ArrayList<>(0);
+
List<AdiDeviceState> getImmutableDeviceInventory() {
synchronized (mDeviceInventoryLock) {
- return new ArrayList<AdiDeviceState>(mDeviceInventory.values());
+ return List.copyOf(mDeviceInventory);
}
}
void addDeviceStateToInventory(AdiDeviceState deviceState) {
synchronized (mDeviceInventoryLock) {
- mDeviceInventory.put(deviceState.getDeviceId(), deviceState);
+ mDeviceInventory.add(deviceState);
}
}
- /**
- * 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();
- }
-
- /**
- * Finds the device state that matches the passed {@link AudioDeviceAttributes} and device
- * type. Note: currently this method only returns a valid device for A2DP and BLE devices.
- *
- * @param ada attributes of device to match
- * @param canonicalDeviceType external device type to match
- * @return the found {@link AdiDeviceState} matching a cached A2DP or BLE device or
- * {@code null} otherwise.
- */
- @Nullable
AdiDeviceState findDeviceStateForAudioDeviceAttributes(AudioDeviceAttributes ada,
int canonicalDeviceType) {
final boolean isWireless = isBluetoothDevice(ada.getInternalType());
+
synchronized (mDeviceInventoryLock) {
- for (AdiDeviceState deviceState : mDeviceInventory.values()) {
- if (deviceState.getDeviceType() == canonicalDeviceType
+ for (AdiDeviceState deviceSetting : mDeviceInventory) {
+ if (deviceSetting.getDeviceType() == canonicalDeviceType
&& (!isWireless || ada.getAddress().equals(
- deviceState.getDeviceAddress()))) {
- return deviceState;
+ deviceSetting.getDeviceAddress()))) {
+ return deviceSetting;
}
}
}
@@ -416,7 +387,7 @@
+ " role:" + key.second + " devices:" + devices); });
pw.println("\ndevices:\n");
synchronized (mDeviceInventoryLock) {
- for (AdiDeviceState device : mDeviceInventory.values()) {
+ for (AdiDeviceState device : mDeviceInventory) {
pw.println("\t" + device + "\n");
}
}
@@ -963,8 +934,8 @@
/*package*/ void registerStrategyPreferredDevicesDispatcher(
- @NonNull IStrategyPreferredDevicesDispatcher dispatcher, boolean isPrivileged) {
- mPrefDevDispatchers.register(dispatcher, isPrivileged);
+ @NonNull IStrategyPreferredDevicesDispatcher dispatcher) {
+ mPrefDevDispatchers.register(dispatcher);
}
/*package*/ void unregisterStrategyPreferredDevicesDispatcher(
@@ -973,8 +944,8 @@
}
/*package*/ void registerStrategyNonDefaultDevicesDispatcher(
- @NonNull IStrategyNonDefaultDevicesDispatcher dispatcher, boolean isPrivileged) {
- mNonDefDevDispatchers.register(dispatcher, isPrivileged);
+ @NonNull IStrategyNonDefaultDevicesDispatcher dispatcher) {
+ mNonDefDevDispatchers.register(dispatcher);
}
/*package*/ void unregisterStrategyNonDefaultDevicesDispatcher(
@@ -1055,8 +1026,8 @@
}
/*package*/ void registerCapturePresetDevicesRoleDispatcher(
- @NonNull ICapturePresetDevicesRoleDispatcher dispatcher, boolean isPrivileged) {
- mDevRoleCapturePresetDispatchers.register(dispatcher, isPrivileged);
+ @NonNull ICapturePresetDevicesRoleDispatcher dispatcher) {
+ mDevRoleCapturePresetDispatchers.register(dispatcher);
}
/*package*/ void unregisterCapturePresetDevicesRoleDispatcher(
@@ -1383,8 +1354,6 @@
updateBluetoothPreferredModes_l(connect ? btDevice : null /*connectedDevice*/);
if (!connect) {
purgeDevicesRoles_l();
- } else {
- addAudioDeviceInInventoryIfNeeded(attributes);
}
}
mmi.set(MediaMetrics.Property.STATE, MediaMetrics.Value.CONNECTED).record();
@@ -1651,7 +1620,6 @@
setCurrentAudioRouteNameIfPossible(name, true /*fromA2dp*/);
updateBluetoothPreferredModes_l(btInfo.mDevice /*connectedDevice*/);
- addAudioDeviceInInventoryIfNeeded(ada);
}
static final int[] CAPTURE_PRESETS = new int[] {AudioSource.MIC, AudioSource.CAMCORDER,
@@ -1951,9 +1919,9 @@
final int hearingAidVolIndex = mDeviceBroker.getVssVolumeForDevice(streamType,
AudioSystem.DEVICE_OUT_HEARING_AID);
mDeviceBroker.postSetHearingAidVolumeIndex(hearingAidVolIndex, streamType);
- AudioDeviceAttributes ada = new AudioDeviceAttributes(
- AudioSystem.DEVICE_OUT_HEARING_AID, address, name);
- mAudioSystem.setDeviceConnectionState(ada,
+
+ mAudioSystem.setDeviceConnectionState(new AudioDeviceAttributes(
+ AudioSystem.DEVICE_OUT_HEARING_AID, address, name),
AudioSystem.DEVICE_STATE_AVAILABLE,
AudioSystem.AUDIO_FORMAT_DEFAULT);
mConnectedDevices.put(
@@ -1963,7 +1931,6 @@
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,
@@ -2066,7 +2033,6 @@
sensorUuid));
mDeviceBroker.postAccessoryPlugMediaUnmute(device);
setCurrentAudioRouteNameIfPossible(name, /*fromA2dp=*/false);
- addAudioDeviceInInventoryIfNeeded(ada);
}
if (streamType == AudioSystem.STREAM_DEFAULT) {
@@ -2397,9 +2363,6 @@
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) {
@@ -2413,9 +2376,6 @@
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) {
@@ -2429,9 +2389,6 @@
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) {
@@ -2456,20 +2413,19 @@
int deviceCatalogSize = 0;
synchronized (mDeviceInventoryLock) {
deviceCatalogSize = mDeviceInventory.size();
-
- final StringBuilder settingsBuilder = new StringBuilder(
+ }
+ final StringBuilder settingsBuilder = new StringBuilder(
deviceCatalogSize * AdiDeviceState.getPeristedMaxSize());
- Iterator<AdiDeviceState> iterator = mDeviceInventory.values().iterator();
- if (iterator.hasNext()) {
- settingsBuilder.append(iterator.next().toPersistableString());
+ synchronized (mDeviceInventoryLock) {
+ for (int i = 0; i < mDeviceInventory.size(); i++) {
+ settingsBuilder.append(mDeviceInventory.get(i).toPersistableString());
+ if (i != mDeviceInventory.size() - 1) {
+ settingsBuilder.append(SETTING_DEVICE_SEPARATOR_CHAR);
+ }
}
- while (iterator.hasNext()) {
- settingsBuilder.append(SETTING_DEVICE_SEPARATOR_CHAR);
- settingsBuilder.append(iterator.next().toPersistableString());
- }
- return settingsBuilder.toString();
}
+ return settingsBuilder.toString();
}
/*package*/ void setDeviceSettings(String settings) {
diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java
index d82cef5..e2e979e 100644
--- a/services/core/java/com/android/server/audio/AudioService.java
+++ b/services/core/java/com/android/server/audio/AudioService.java
@@ -2831,11 +2831,8 @@
if (devices == null) {
return AudioSystem.ERROR;
}
-
- devices = retrieveBluetoothAddresses(devices);
-
final String logString = String.format(
- "setPreferredDevicesForStrategy u/pid:%d/%d strat:%d dev:%s",
+ "setPreferredDeviceForStrategy u/pid:%d/%d strat:%d dev:%s",
Binder.getCallingUid(), Binder.getCallingPid(), strategy,
devices.stream().map(e -> e.toString()).collect(Collectors.joining(",")));
sDeviceLogger.enqueue(new EventLogger.StringEvent(logString).printLog(TAG));
@@ -2891,7 +2888,7 @@
status, strategy));
return new ArrayList<AudioDeviceAttributes>();
} else {
- return anonymizeAudioDeviceAttributesList(devices);
+ return devices;
}
}
@@ -2906,9 +2903,6 @@
@NonNull AudioDeviceAttributes device) {
super.setDeviceAsNonDefaultForStrategy_enforcePermission();
Objects.requireNonNull(device);
-
- device = retrieveBluetoothAddress(device);
-
final String logString = String.format(
"setDeviceAsNonDefaultForStrategy u/pid:%d/%d strat:%d dev:%s",
Binder.getCallingUid(), Binder.getCallingPid(), strategy, device.toString());
@@ -2935,9 +2929,6 @@
AudioDeviceAttributes device) {
super.removeDeviceAsNonDefaultForStrategy_enforcePermission();
Objects.requireNonNull(device);
-
- device = retrieveBluetoothAddress(device);
-
final String logString = String.format(
"removeDeviceAsNonDefaultForStrategy strat:%d dev:%s", strategy, device.toString());
sDeviceLogger.enqueue(new EventLogger.StringEvent(logString).printLog(TAG));
@@ -2972,7 +2963,7 @@
status, strategy));
return new ArrayList<AudioDeviceAttributes>();
} else {
- return anonymizeAudioDeviceAttributesList(devices);
+ return devices;
}
}
@@ -2985,8 +2976,7 @@
return;
}
enforceModifyAudioRoutingPermission();
- mDeviceBroker.registerStrategyPreferredDevicesDispatcher(
- dispatcher, isBluetoothPrividged());
+ mDeviceBroker.registerStrategyPreferredDevicesDispatcher(dispatcher);
}
/** @see AudioManager#removeOnPreferredDevicesForStrategyChangedListener(
@@ -3010,8 +3000,7 @@
return;
}
enforceModifyAudioRoutingPermission();
- mDeviceBroker.registerStrategyNonDefaultDevicesDispatcher(
- dispatcher, isBluetoothPrividged());
+ mDeviceBroker.registerStrategyNonDefaultDevicesDispatcher(dispatcher);
}
/** @see AudioManager#removeOnNonDefaultDevicesForStrategyChangedListener(
@@ -3027,7 +3016,7 @@
}
/**
- * @see AudioManager#setPreferredDevicesForCapturePreset(int, AudioDeviceAttributes)
+ * @see AudioManager#setPreferredDeviceForCapturePreset(int, AudioDeviceAttributes)
*/
public int setPreferredDevicesForCapturePreset(
int capturePreset, List<AudioDeviceAttributes> devices) {
@@ -3046,8 +3035,6 @@
return AudioSystem.ERROR;
}
- devices = retrieveBluetoothAddresses(devices);
-
final int status = mDeviceBroker.setPreferredDevicesForCapturePresetSync(
capturePreset, devices);
if (status != AudioSystem.SUCCESS) {
@@ -3094,7 +3081,7 @@
status, capturePreset));
return new ArrayList<AudioDeviceAttributes>();
} else {
- return anonymizeAudioDeviceAttributesList(devices);
+ return devices;
}
}
@@ -3108,8 +3095,7 @@
return;
}
enforceModifyAudioRoutingPermission();
- mDeviceBroker.registerCapturePresetDevicesRoleDispatcher(
- dispatcher, isBluetoothPrividged());
+ mDeviceBroker.registerCapturePresetDevicesRoleDispatcher(dispatcher);
}
/**
@@ -3129,9 +3115,7 @@
public @NonNull ArrayList<AudioDeviceAttributes> getDevicesForAttributes(
@NonNull AudioAttributes attributes) {
enforceQueryStateOrModifyRoutingPermission();
-
- return new ArrayList<AudioDeviceAttributes>(anonymizeAudioDeviceAttributesList(
- getDevicesForAttributesInt(attributes, false /* forVolume */)));
+ return getDevicesForAttributesInt(attributes, false /* forVolume */);
}
/** @see AudioManager#getAudioDevicesForAttributes(AudioAttributes)
@@ -3141,8 +3125,7 @@
*/
public @NonNull ArrayList<AudioDeviceAttributes> getDevicesForAttributesUnprotected(
@NonNull AudioAttributes attributes) {
- return new ArrayList<AudioDeviceAttributes>(anonymizeAudioDeviceAttributesList(
- getDevicesForAttributesInt(attributes, false /* forVolume */)));
+ return getDevicesForAttributesInt(attributes, false /* forVolume */);
}
/**
@@ -7335,8 +7318,6 @@
Objects.requireNonNull(device);
AudioManager.enforceValidVolumeBehavior(deviceVolumeBehavior);
- device = retrieveBluetoothAddress(device);
-
sVolumeLogger.enqueue(new EventLogger.StringEvent("setDeviceVolumeBehavior: dev:"
+ AudioSystem.getOutputDeviceName(device.getInternalType()) + " addr:"
+ device.getAddress() + " behavior:"
@@ -7420,8 +7401,6 @@
// verify parameters
Objects.requireNonNull(device);
- device = retrieveBluetoothAddress(device);
-
return getDeviceVolumeBehaviorInt(device);
}
@@ -7496,12 +7475,9 @@
/**
* see AudioManager.setWiredDeviceConnectionState()
*/
- public void setWiredDeviceConnectionState(@NonNull AudioDeviceAttributes attributes,
+ public void setWiredDeviceConnectionState(AudioDeviceAttributes attributes,
@ConnectionState int state, String caller) {
super.setWiredDeviceConnectionState_enforcePermission();
- Objects.requireNonNull(attributes);
-
- attributes = retrieveBluetoothAddress(attributes);
if (state != CONNECTION_STATE_CONNECTED
&& state != CONNECTION_STATE_DISCONNECTED) {
@@ -7542,9 +7518,6 @@
boolean connected) {
Objects.requireNonNull(device);
enforceModifyAudioRoutingPermission();
-
- device = retrieveBluetoothAddress(device);
-
mDeviceBroker.setTestDeviceConnectionState(device,
connected ? CONNECTION_STATE_CONNECTED : CONNECTION_STATE_DISCONNECTED);
// simulate a routing update from native
@@ -10301,100 +10274,6 @@
mSpatializerHelper.setFeatureEnabled(mHasSpatializerEffect);
}
- private boolean isBluetoothPrividged() {
- return PackageManager.PERMISSION_GRANTED == mContext.checkCallingOrSelfPermission(
- android.Manifest.permission.BLUETOOTH_CONNECT)
- || Binder.getCallingUid() == Process.SYSTEM_UID;
- }
-
- List<AudioDeviceAttributes> retrieveBluetoothAddresses(List<AudioDeviceAttributes> devices) {
- if (isBluetoothPrividged()) {
- return devices;
- }
-
- List<AudioDeviceAttributes> checkedDevices = new ArrayList<AudioDeviceAttributes>();
- for (AudioDeviceAttributes ada : devices) {
- if (ada == null) {
- continue;
- }
- checkedDevices.add(retrieveBluetoothAddressUncheked(ada));
- }
- return checkedDevices;
- }
-
- AudioDeviceAttributes retrieveBluetoothAddress(@NonNull AudioDeviceAttributes ada) {
- if (isBluetoothPrividged()) {
- return ada;
- }
- return retrieveBluetoothAddressUncheked(ada);
- }
-
- AudioDeviceAttributes retrieveBluetoothAddressUncheked(@NonNull AudioDeviceAttributes ada) {
- Objects.requireNonNull(ada);
- if (AudioSystem.isBluetoothDevice(ada.getInternalType())) {
- String anonymizedAddress = anonymizeBluetoothAddress(ada.getAddress());
- for (AdiDeviceState ads : mDeviceBroker.getImmutableDeviceInventory()) {
- if (!(AudioSystem.isBluetoothDevice(ads.getInternalDeviceType())
- && (ada.getInternalType() == ads.getInternalDeviceType())
- && anonymizedAddress.equals(anonymizeBluetoothAddress(
- ads.getDeviceAddress())))) {
- continue;
- }
- ada.setAddress(ads.getDeviceAddress());
- break;
- }
- }
- return ada;
- }
-
- /**
- * Convert a Bluetooth MAC address to an anonymized one when exposed to a non privileged app
- * Must match the implementation of BluetoothUtils.toAnonymizedAddress()
- * @param address Mac address to be anonymized
- * @return anonymized mac address
- */
- static String anonymizeBluetoothAddress(String address) {
- if (address == null || address.length() != "AA:BB:CC:DD:EE:FF".length()) {
- return null;
- }
- return "XX:XX:XX:XX" + address.substring("XX:XX:XX:XX".length());
- }
-
- private List<AudioDeviceAttributes> anonymizeAudioDeviceAttributesList(
- List<AudioDeviceAttributes> devices) {
- if (isBluetoothPrividged()) {
- return devices;
- }
- return anonymizeAudioDeviceAttributesListUnchecked(devices);
- }
-
- /* package */ List<AudioDeviceAttributes> anonymizeAudioDeviceAttributesListUnchecked(
- List<AudioDeviceAttributes> devices) {
- List<AudioDeviceAttributes> anonymizedDevices = new ArrayList<AudioDeviceAttributes>();
- for (AudioDeviceAttributes ada : devices) {
- anonymizedDevices.add(anonymizeAudioDeviceAttributesUnchecked(ada));
- }
- return anonymizedDevices;
- }
-
- private AudioDeviceAttributes anonymizeAudioDeviceAttributesUnchecked(
- AudioDeviceAttributes ada) {
- if (!AudioSystem.isBluetoothDevice(ada.getInternalType())) {
- return ada;
- }
- AudioDeviceAttributes res = new AudioDeviceAttributes(ada);
- res.setAddress(anonymizeBluetoothAddress(ada.getAddress()));
- return res;
- }
-
- private AudioDeviceAttributes anonymizeAudioDeviceAttributes(AudioDeviceAttributes ada) {
- if (isBluetoothPrividged()) {
- return ada;
- }
-
- return anonymizeAudioDeviceAttributesUnchecked(ada);
- }
-
//==========================================================================================
// camera sound is forced if any of the resources corresponding to one active SIM
@@ -10442,16 +10321,13 @@
Objects.requireNonNull(usages);
Objects.requireNonNull(device);
enforceModifyAudioRoutingPermission();
-
- final AudioDeviceAttributes ada = retrieveBluetoothAddress(device);
-
if (timeOutMs <= 0 || usages.length == 0) {
throw new IllegalArgumentException("Invalid timeOutMs/usagesToMute");
}
Log.i(TAG, "muteAwaitConnection dev:" + device + " timeOutMs:" + timeOutMs
+ " usages:" + Arrays.toString(usages));
- if (mDeviceBroker.isDeviceConnected(ada)) {
+ if (mDeviceBroker.isDeviceConnected(device)) {
// not throwing an exception as there could be a race between a connection (server-side,
// notification of connection in flight) and a mute operation (client-side)
Log.i(TAG, "muteAwaitConnection ignored, device (" + device + ") already connected");
@@ -10463,19 +10339,12 @@
+ mMutingExpectedDevice);
throw new IllegalStateException("muteAwaitConnection already in progress");
}
- mMutingExpectedDevice = ada;
+ mMutingExpectedDevice = device;
mMutedUsagesAwaitingConnection = usages;
- mPlaybackMonitor.muteAwaitConnection(usages, ada, timeOutMs);
+ mPlaybackMonitor.muteAwaitConnection(usages, device, timeOutMs);
}
- dispatchMuteAwaitConnection((cb, isPrivileged) -> {
- try {
- AudioDeviceAttributes dev = ada;
- if (!isPrivileged) {
- dev = anonymizeAudioDeviceAttributesUnchecked(ada);
- }
- cb.dispatchOnMutedUntilConnection(dev, usages);
- } catch (RemoteException e) { }
- });
+ dispatchMuteAwaitConnection(cb -> { try {
+ cb.dispatchOnMutedUntilConnection(device, usages); } catch (RemoteException e) { } });
}
@android.annotation.EnforcePermission(android.Manifest.permission.MODIFY_AUDIO_ROUTING)
@@ -10484,7 +10353,7 @@
super.getMutingExpectedDevice_enforcePermission();
synchronized (mMuteAwaitConnectionLock) {
- return anonymizeAudioDeviceAttributes(mMutingExpectedDevice);
+ return mMutingExpectedDevice;
}
}
@@ -10493,9 +10362,6 @@
public void cancelMuteAwaitConnection(@NonNull AudioDeviceAttributes device) {
Objects.requireNonNull(device);
enforceModifyAudioRoutingPermission();
-
- final AudioDeviceAttributes ada = retrieveBluetoothAddress(device);
-
Log.i(TAG, "cancelMuteAwaitConnection for device:" + device);
final int[] mutedUsages;
synchronized (mMuteAwaitConnectionLock) {
@@ -10505,7 +10371,7 @@
Log.i(TAG, "cancelMuteAwaitConnection ignored, no expected device");
return;
}
- if (!ada.equalTypeAddress(mMutingExpectedDevice)) {
+ if (!device.equalTypeAddress(mMutingExpectedDevice)) {
Log.e(TAG, "cancelMuteAwaitConnection ignored, got " + device
+ "] but expected device is" + mMutingExpectedDevice);
throw new IllegalStateException("cancelMuteAwaitConnection for wrong device");
@@ -10515,14 +10381,8 @@
mMutedUsagesAwaitingConnection = null;
mPlaybackMonitor.cancelMuteAwaitConnection("cancelMuteAwaitConnection dev:" + device);
}
- dispatchMuteAwaitConnection((cb, isPrivileged) -> {
- try {
- AudioDeviceAttributes dev = ada;
- if (!isPrivileged) {
- dev = anonymizeAudioDeviceAttributesUnchecked(ada);
- }
- cb.dispatchOnUnmutedEvent(
- AudioManager.MuteAwaitConnectionCallback.EVENT_CANCEL, dev, mutedUsages);
+ dispatchMuteAwaitConnection(cb -> { try { cb.dispatchOnUnmutedEvent(
+ AudioManager.MuteAwaitConnectionCallback.EVENT_CANCEL, device, mutedUsages);
} catch (RemoteException e) { } });
}
@@ -10536,7 +10396,7 @@
super.registerMuteAwaitConnectionDispatcher_enforcePermission();
if (register) {
- mMuteAwaitConnectionDispatchers.register(cb, isBluetoothPrividged());
+ mMuteAwaitConnectionDispatchers.register(cb);
} else {
mMuteAwaitConnectionDispatchers.unregister(cb);
}
@@ -10560,14 +10420,8 @@
mPlaybackMonitor.cancelMuteAwaitConnection(
"checkMuteAwaitConnection device " + device + " connected, unmuting");
}
- dispatchMuteAwaitConnection((cb, isPrivileged) -> {
- try {
- AudioDeviceAttributes ada = device;
- if (!isPrivileged) {
- ada = anonymizeAudioDeviceAttributesUnchecked(device);
- }
- cb.dispatchOnUnmutedEvent(AudioManager.MuteAwaitConnectionCallback.EVENT_CONNECTION,
- ada, mutedUsages);
+ dispatchMuteAwaitConnection(cb -> { try { cb.dispatchOnUnmutedEvent(
+ AudioManager.MuteAwaitConnectionCallback.EVENT_CONNECTION, device, mutedUsages);
} catch (RemoteException e) { } });
}
@@ -10587,8 +10441,7 @@
mMutingExpectedDevice = null;
mMutedUsagesAwaitingConnection = null;
}
- dispatchMuteAwaitConnection((cb, isPrivileged) -> {
- try {
+ dispatchMuteAwaitConnection(cb -> { try {
cb.dispatchOnUnmutedEvent(
AudioManager.MuteAwaitConnectionCallback.EVENT_TIMEOUT,
timedOutDevice, mutedUsages);
@@ -10596,14 +10449,13 @@
}
private void dispatchMuteAwaitConnection(
- java.util.function.BiConsumer<IMuteAwaitConnectionCallback, Boolean> callback) {
+ java.util.function.Consumer<IMuteAwaitConnectionCallback> callback) {
final int nbDispatchers = mMuteAwaitConnectionDispatchers.beginBroadcast();
// lazy initialization as errors unlikely
ArrayList<IMuteAwaitConnectionCallback> errorList = null;
for (int i = 0; i < nbDispatchers; i++) {
try {
- callback.accept(mMuteAwaitConnectionDispatchers.getBroadcastItem(i),
- (Boolean) mMuteAwaitConnectionDispatchers.getBroadcastCookie(i));
+ callback.accept(mMuteAwaitConnectionDispatchers.getBroadcastItem(i));
} catch (Exception e) {
if (errorList == null) {
errorList = new ArrayList<>(1);
@@ -13069,9 +12921,6 @@
@NonNull AudioDeviceAttributes device, @IntRange(from = 0) long delayMillis) {
Objects.requireNonNull(device, "device must not be null");
enforceModifyAudioRoutingPermission();
-
- device = retrieveBluetoothAddress(device);
-
final String getterKey = "additional_output_device_delay="
+ device.getInternalType() + "," + device.getAddress(); // "getter" key as an id.
final String setterKey = getterKey + "," + delayMillis; // append the delay for setter
@@ -13092,9 +12941,6 @@
@IntRange(from = 0)
public long getAdditionalOutputDeviceDelay(@NonNull AudioDeviceAttributes device) {
Objects.requireNonNull(device, "device must not be null");
-
- device = retrieveBluetoothAddress(device);
-
final String key = "additional_output_device_delay";
final String reply = AudioSystem.getParameters(
key + "=" + device.getInternalType() + "," + device.getAddress());
@@ -13122,9 +12968,6 @@
@IntRange(from = 0)
public long getMaxAdditionalOutputDeviceDelay(@NonNull AudioDeviceAttributes device) {
Objects.requireNonNull(device, "device must not be null");
-
- device = retrieveBluetoothAddress(device);
-
final String key = "max_additional_output_device_delay";
final String reply = AudioSystem.getParameters(
key + "=" + device.getInternalType() + "," + device.getAddress());