Loading media/java/android/media/AudioDeviceAttributes.java +1 −1 Original line number Diff line number Diff line Loading @@ -325,7 +325,7 @@ public final class AudioDeviceAttributes implements Parcelable { + " role:" + roleToString(mRole) + " type:" + (mRole == ROLE_OUTPUT ? AudioSystem.getOutputDeviceName(mNativeType) : AudioSystem.getInputDeviceName(mNativeType)) + " addr:" + mAddress + " addr:" + Utils.anonymizeBluetoothAddress(mNativeType, mAddress) + " name:" + mName + " profiles:" + mAudioProfiles.toString() + " descriptors:" + mAudioDescriptors.toString()); Loading media/java/android/media/AudioDevicePort.java +1 −1 Original line number Diff line number Diff line Loading @@ -156,7 +156,7 @@ public class AudioDevicePort extends AudioPort { AudioSystem.getOutputDeviceName(mType)); return "{" + super.toString() + ", mType: " + type + ", mAddress: " + mAddress + ", mAddress: " + Utils.anonymizeBluetoothAddress(mType, mAddress) + "}"; } } media/java/android/media/Utils.java +31 −0 Original line number Diff line number Diff line Loading @@ -657,4 +657,35 @@ public class Utils { // on the fly. private final boolean mForceRemoveConsistency; // default false } /** * 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 */ public static @Nullable String anonymizeBluetoothAddress(@Nullable String address) { if (address == null) { return null; } if (address.length() != "AA:BB:CC:DD:EE:FF".length()) { return address; } return "XX:XX:XX:XX" + address.substring("XX:XX:XX:XX".length()); } /** * Convert a Bluetooth MAC address to an anonymized one if the internal device type corresponds * to a Bluetooth. * @param deviceType the internal type of the audio device * @param address MAC address to be anonymized * @return anonymized MAC address */ public static @Nullable String anonymizeBluetoothAddress( int deviceType, @Nullable String address) { if (!AudioSystem.isBluetoothDevice(deviceType)) { return address; } return anonymizeBluetoothAddress(address); } } services/core/java/com/android/server/audio/AdiDeviceState.java +4 −2 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import android.annotation.Nullable; import android.media.AudioDeviceAttributes; import android.media.AudioDeviceInfo; import android.media.AudioManager; import android.media.Utils; import android.text.TextUtils; import android.util.Log; import android.util.Pair; Loading Loading @@ -167,7 +168,8 @@ import java.util.Objects; public String toString() { return "type: " + mDeviceType + " internal type: 0x" + Integer.toHexString(mInternalDeviceType) + " addr: " + mDeviceAddress + " bt audio type: " + " addr: " + Utils.anonymizeBluetoothAddress(mInternalDeviceType, mDeviceAddress) + " bt audio type: " + AudioManager.audioDeviceCategoryToString(mAudioDeviceCategory) + " enabled: " + mSAEnabled + " HT: " + mHasHeadTracker + " HTenabled: " + mHeadTrackerEnabled; Loading services/core/java/com/android/server/audio/AudioDeviceInventory.java +15 −8 Original line number Diff line number Diff line Loading @@ -48,6 +48,7 @@ import android.media.IStrategyNonDefaultDevicesDispatcher; import android.media.IStrategyPreferredDevicesDispatcher; import android.media.MediaMetrics; import android.media.MediaRecorder.AudioSource; import android.media.Utils; import android.media.audiopolicy.AudioProductStrategy; import android.media.permission.ClearCallingIdentityContext; import android.media.permission.SafeCloseable; Loading Loading @@ -477,7 +478,7 @@ public class AudioDeviceInventory { return "[DeviceInfo: type:0x" + Integer.toHexString(mDeviceType) + " (" + AudioSystem.getDeviceName(mDeviceType) + ") name:" + mDeviceName + " addr:" + mDeviceAddress + " addr:" + Utils.anonymizeBluetoothAddress(mDeviceType, mDeviceAddress) + " codec: " + Integer.toHexString(mDeviceCodecFormat) + " peer addr:" + mPeerDeviceAddress + " group:" + mGroupId Loading Loading @@ -532,7 +533,7 @@ public class AudioDeviceInventory { mApmConnectedDevices.forEach((keyType, valueAddress) -> { pw.println(" " + prefix + " type:0x" + Integer.toHexString(keyType) + " (" + AudioSystem.getDeviceName(keyType) + ") addr:" + valueAddress); }); + ") addr:" + Utils.anonymizeBluetoothAddress(keyType, valueAddress)); }); pw.println("\n" + prefix + "Preferred devices for capture preset:"); mPreferredDevicesForCapturePreset.forEach((capturePreset, devices) -> { pw.println(" " + prefix + "capturePreset:" + capturePreset Loading Loading @@ -1789,7 +1790,8 @@ public class AudioDeviceInventory { // TODO: return; } else { AudioService.sDeviceLogger.enqueue(new EventLogger.StringEvent( "A2DP device addr=" + address + " now available").printLog(TAG)); "A2DP device addr=" + Utils.anonymizeBluetoothAddress(address) + " now available").printLog(TAG)); } // Reset A2DP suspend state each time a new sink is connected Loading Loading @@ -2027,7 +2029,8 @@ public class AudioDeviceInventory { .equals(mApmConnectedDevices.get(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP))) { // removing A2DP device not currently used by AudioPolicy, log but don't act on it AudioService.sDeviceLogger.enqueue((new EventLogger.StringEvent( "A2DP device " + address + " made unavailable, was not used")).printLog(TAG)); "A2DP device " + Utils.anonymizeBluetoothAddress(address) + " made unavailable, was not used")).printLog(TAG)); mmi.set(MediaMetrics.Property.EARLY_RETURN, "A2DP device made unavailable, was not used") .record(); Loading @@ -2043,13 +2046,15 @@ public class AudioDeviceInventory { if (res != AudioSystem.AUDIO_STATUS_OK) { AudioService.sDeviceLogger.enqueue(new EventLogger.StringEvent( "APM failed to make unavailable A2DP device addr=" + address "APM failed to make unavailable A2DP device addr=" + Utils.anonymizeBluetoothAddress(address) + " error=" + res).printLog(TAG)); // TODO: failed to disconnect, stop here // TODO: return; } else { AudioService.sDeviceLogger.enqueue((new EventLogger.StringEvent( "A2DP device addr=" + address + " made unavailable")).printLog(TAG)); "A2DP device addr=" + Utils.anonymizeBluetoothAddress(address) + " made unavailable")).printLog(TAG)); } mApmConnectedDevices.remove(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP); Loading Loading @@ -2238,7 +2243,8 @@ public class AudioDeviceInventory { // TODO: return; } else { AudioService.sDeviceLogger.enqueue(new EventLogger.StringEvent( "LE Audio device addr=" + address + " now available").printLog(TAG)); "LE Audio device addr=" + Utils.anonymizeBluetoothAddress(address) + " now available").printLog(TAG)); } // Reset LEA suspend state each time a new sink is connected mDeviceBroker.clearLeAudioSuspended(true /* internalOnly */); Loading Loading @@ -2282,7 +2288,8 @@ public class AudioDeviceInventory { // TODO: return; } else { AudioService.sDeviceLogger.enqueue(new EventLogger.StringEvent( "LE Audio device addr=" + address + " made unavailable").printLog(TAG)); "LE Audio device addr=" + Utils.anonymizeBluetoothAddress(address) + " made unavailable").printLog(TAG)); } mConnectedDevices.remove(DeviceInfo.makeDeviceListKey(device, address)); } Loading Loading
media/java/android/media/AudioDeviceAttributes.java +1 −1 Original line number Diff line number Diff line Loading @@ -325,7 +325,7 @@ public final class AudioDeviceAttributes implements Parcelable { + " role:" + roleToString(mRole) + " type:" + (mRole == ROLE_OUTPUT ? AudioSystem.getOutputDeviceName(mNativeType) : AudioSystem.getInputDeviceName(mNativeType)) + " addr:" + mAddress + " addr:" + Utils.anonymizeBluetoothAddress(mNativeType, mAddress) + " name:" + mName + " profiles:" + mAudioProfiles.toString() + " descriptors:" + mAudioDescriptors.toString()); Loading
media/java/android/media/AudioDevicePort.java +1 −1 Original line number Diff line number Diff line Loading @@ -156,7 +156,7 @@ public class AudioDevicePort extends AudioPort { AudioSystem.getOutputDeviceName(mType)); return "{" + super.toString() + ", mType: " + type + ", mAddress: " + mAddress + ", mAddress: " + Utils.anonymizeBluetoothAddress(mType, mAddress) + "}"; } }
media/java/android/media/Utils.java +31 −0 Original line number Diff line number Diff line Loading @@ -657,4 +657,35 @@ public class Utils { // on the fly. private final boolean mForceRemoveConsistency; // default false } /** * 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 */ public static @Nullable String anonymizeBluetoothAddress(@Nullable String address) { if (address == null) { return null; } if (address.length() != "AA:BB:CC:DD:EE:FF".length()) { return address; } return "XX:XX:XX:XX" + address.substring("XX:XX:XX:XX".length()); } /** * Convert a Bluetooth MAC address to an anonymized one if the internal device type corresponds * to a Bluetooth. * @param deviceType the internal type of the audio device * @param address MAC address to be anonymized * @return anonymized MAC address */ public static @Nullable String anonymizeBluetoothAddress( int deviceType, @Nullable String address) { if (!AudioSystem.isBluetoothDevice(deviceType)) { return address; } return anonymizeBluetoothAddress(address); } }
services/core/java/com/android/server/audio/AdiDeviceState.java +4 −2 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import android.annotation.Nullable; import android.media.AudioDeviceAttributes; import android.media.AudioDeviceInfo; import android.media.AudioManager; import android.media.Utils; import android.text.TextUtils; import android.util.Log; import android.util.Pair; Loading Loading @@ -167,7 +168,8 @@ import java.util.Objects; public String toString() { return "type: " + mDeviceType + " internal type: 0x" + Integer.toHexString(mInternalDeviceType) + " addr: " + mDeviceAddress + " bt audio type: " + " addr: " + Utils.anonymizeBluetoothAddress(mInternalDeviceType, mDeviceAddress) + " bt audio type: " + AudioManager.audioDeviceCategoryToString(mAudioDeviceCategory) + " enabled: " + mSAEnabled + " HT: " + mHasHeadTracker + " HTenabled: " + mHeadTrackerEnabled; Loading
services/core/java/com/android/server/audio/AudioDeviceInventory.java +15 −8 Original line number Diff line number Diff line Loading @@ -48,6 +48,7 @@ import android.media.IStrategyNonDefaultDevicesDispatcher; import android.media.IStrategyPreferredDevicesDispatcher; import android.media.MediaMetrics; import android.media.MediaRecorder.AudioSource; import android.media.Utils; import android.media.audiopolicy.AudioProductStrategy; import android.media.permission.ClearCallingIdentityContext; import android.media.permission.SafeCloseable; Loading Loading @@ -477,7 +478,7 @@ public class AudioDeviceInventory { return "[DeviceInfo: type:0x" + Integer.toHexString(mDeviceType) + " (" + AudioSystem.getDeviceName(mDeviceType) + ") name:" + mDeviceName + " addr:" + mDeviceAddress + " addr:" + Utils.anonymizeBluetoothAddress(mDeviceType, mDeviceAddress) + " codec: " + Integer.toHexString(mDeviceCodecFormat) + " peer addr:" + mPeerDeviceAddress + " group:" + mGroupId Loading Loading @@ -532,7 +533,7 @@ public class AudioDeviceInventory { mApmConnectedDevices.forEach((keyType, valueAddress) -> { pw.println(" " + prefix + " type:0x" + Integer.toHexString(keyType) + " (" + AudioSystem.getDeviceName(keyType) + ") addr:" + valueAddress); }); + ") addr:" + Utils.anonymizeBluetoothAddress(keyType, valueAddress)); }); pw.println("\n" + prefix + "Preferred devices for capture preset:"); mPreferredDevicesForCapturePreset.forEach((capturePreset, devices) -> { pw.println(" " + prefix + "capturePreset:" + capturePreset Loading Loading @@ -1789,7 +1790,8 @@ public class AudioDeviceInventory { // TODO: return; } else { AudioService.sDeviceLogger.enqueue(new EventLogger.StringEvent( "A2DP device addr=" + address + " now available").printLog(TAG)); "A2DP device addr=" + Utils.anonymizeBluetoothAddress(address) + " now available").printLog(TAG)); } // Reset A2DP suspend state each time a new sink is connected Loading Loading @@ -2027,7 +2029,8 @@ public class AudioDeviceInventory { .equals(mApmConnectedDevices.get(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP))) { // removing A2DP device not currently used by AudioPolicy, log but don't act on it AudioService.sDeviceLogger.enqueue((new EventLogger.StringEvent( "A2DP device " + address + " made unavailable, was not used")).printLog(TAG)); "A2DP device " + Utils.anonymizeBluetoothAddress(address) + " made unavailable, was not used")).printLog(TAG)); mmi.set(MediaMetrics.Property.EARLY_RETURN, "A2DP device made unavailable, was not used") .record(); Loading @@ -2043,13 +2046,15 @@ public class AudioDeviceInventory { if (res != AudioSystem.AUDIO_STATUS_OK) { AudioService.sDeviceLogger.enqueue(new EventLogger.StringEvent( "APM failed to make unavailable A2DP device addr=" + address "APM failed to make unavailable A2DP device addr=" + Utils.anonymizeBluetoothAddress(address) + " error=" + res).printLog(TAG)); // TODO: failed to disconnect, stop here // TODO: return; } else { AudioService.sDeviceLogger.enqueue((new EventLogger.StringEvent( "A2DP device addr=" + address + " made unavailable")).printLog(TAG)); "A2DP device addr=" + Utils.anonymizeBluetoothAddress(address) + " made unavailable")).printLog(TAG)); } mApmConnectedDevices.remove(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP); Loading Loading @@ -2238,7 +2243,8 @@ public class AudioDeviceInventory { // TODO: return; } else { AudioService.sDeviceLogger.enqueue(new EventLogger.StringEvent( "LE Audio device addr=" + address + " now available").printLog(TAG)); "LE Audio device addr=" + Utils.anonymizeBluetoothAddress(address) + " now available").printLog(TAG)); } // Reset LEA suspend state each time a new sink is connected mDeviceBroker.clearLeAudioSuspended(true /* internalOnly */); Loading Loading @@ -2282,7 +2288,8 @@ public class AudioDeviceInventory { // TODO: return; } else { AudioService.sDeviceLogger.enqueue(new EventLogger.StringEvent( "LE Audio device addr=" + address + " made unavailable").printLog(TAG)); "LE Audio device addr=" + Utils.anonymizeBluetoothAddress(address) + " made unavailable").printLog(TAG)); } mConnectedDevices.remove(DeviceInfo.makeDeviceListKey(device, address)); } Loading