From bacecee90b63c582538db65573335208187c2097 Mon Sep 17 00:00:00 2001 From: jiabin Date: Fri, 31 Jul 2020 11:05:01 -0700 Subject: [PATCH] Do not log sensitive information in AudioService. Sensitive information, such as IP and MAC address, should not be logged. In AudioService, only log the last 3 octets of BT device address. Test: make, connect BT device and log Bug: 162299985 Change-Id: I99db812efc327e6f3ebe791274998291a140a5b6 --- core/java/android/bluetooth/BluetoothDevice.java | 12 ++++++++++++ .../java/com/android/server/audio/BtHelper.java | 16 ++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/core/java/android/bluetooth/BluetoothDevice.java b/core/java/android/bluetooth/BluetoothDevice.java index fb9746830d4ee..548bca485681d 100644 --- a/core/java/android/bluetooth/BluetoothDevice.java +++ b/core/java/android/bluetooth/BluetoothDevice.java @@ -1032,6 +1032,18 @@ public final class BluetoothDevice implements Parcelable { return mAddress; } + /** + * Returns the anonymized hardware address of this BluetoothDevice. The first three octets + * will be suppressed for anonymization. + *

For example, "XX:XX:XX:AA:BB:CC". + * + * @return Anonymized bluetooth hardware address as string + * @hide + */ + public String getAnonymizedAddress() { + return "XX:XX:XX" + getAddress().substring(8); + } + /** * Get the friendly Bluetooth name of the remote device. * diff --git a/services/core/java/com/android/server/audio/BtHelper.java b/services/core/java/com/android/server/audio/BtHelper.java index b4c41b274dbe4..5e8f1ef0db855 100644 --- a/services/core/java/com/android/server/audio/BtHelper.java +++ b/services/core/java/com/android/server/audio/BtHelper.java @@ -632,21 +632,28 @@ public class BtHelper { return result; } + // Return `(null)` if given BluetoothDevice is null. Otherwise, return the anonymized address. + private String getAnonymizedAddress(BluetoothDevice btDevice) { + return btDevice == null ? "(null)" : btDevice.getAnonymizedAddress(); + } + // @GuardedBy("AudioDeviceBroker.mSetModeLock") //@GuardedBy("AudioDeviceBroker.mDeviceStateLock") @GuardedBy("BtHelper.this") private void setBtScoActiveDevice(BluetoothDevice btDevice) { - Log.i(TAG, "setBtScoActiveDevice: " + mBluetoothHeadsetDevice + " -> " + btDevice); + Log.i(TAG, "setBtScoActiveDevice: " + getAnonymizedAddress(mBluetoothHeadsetDevice) + + " -> " + getAnonymizedAddress(btDevice)); final BluetoothDevice previousActiveDevice = mBluetoothHeadsetDevice; if (Objects.equals(btDevice, previousActiveDevice)) { return; } if (!handleBtScoActiveDeviceChange(previousActiveDevice, false)) { Log.w(TAG, "setBtScoActiveDevice() failed to remove previous device " - + previousActiveDevice); + + getAnonymizedAddress(previousActiveDevice)); } if (!handleBtScoActiveDeviceChange(btDevice, true)) { - Log.e(TAG, "setBtScoActiveDevice() failed to add new device " + btDevice); + Log.e(TAG, "setBtScoActiveDevice() failed to add new device " + + getAnonymizedAddress(btDevice)); // set mBluetoothHeadsetDevice to null when failing to add new device btDevice = null; } @@ -826,7 +833,8 @@ public class BtHelper { mBluetoothHeadsetDevice, mScoAudioMode)) { mScoAudioState = SCO_STATE_ACTIVE_INTERNAL; } else { - Log.w(TAG, "requestScoState: connect to " + mBluetoothHeadsetDevice + Log.w(TAG, "requestScoState: connect to " + + getAnonymizedAddress(mBluetoothHeadsetDevice) + " failed, mScoAudioMode=" + mScoAudioMode); broadcastScoConnectionState( AudioManager.SCO_AUDIO_STATE_DISCONNECTED);