Loading android/app/src/com/android/bluetooth/btservice/AdapterProperties.java +3 −6 Original line number Diff line number Diff line Loading @@ -40,7 +40,6 @@ import android.content.IntentFilter; import android.os.ParcelUuid; import android.os.SystemProperties; import android.os.UserHandle; import android.provider.Settings.Secure; import android.util.Log; import android.util.Pair; import android.util.StatsLog; Loading Loading @@ -573,11 +572,9 @@ class AdapterProperties { Log.d(TAG, "PROFILE_CONNECTION_STATE_CHANGE: profile=" + profile + ", device=" + device + ", " + prevState + " -> " + state); String ssaid = Secure.getString(mService.getContentResolver(), Secure.ANDROID_ID); String combined = ssaid + device.getAddress(); int obfuscated_id = combined.hashCode() & 0xFFFF; // Last two bytes only StatsLog.write(StatsLog.BLUETOOTH_CONNECTION_STATE_CHANGED, state, obfuscated_id, profile); StatsLog.write(StatsLog.BLUETOOTH_CONNECTION_STATE_CHANGED, state, 0 /* deprecated */, profile, mService.obfuscateAddress(device)); if (!isNormalStateTransition(prevState, state)) { Log.w(TAG, "PROFILE_CONNECTION_STATE_CHANGE: unexpected transition for profile=" + profile Loading android/app/src/com/android/bluetooth/btservice/RemoteDevices.java +6 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ import android.os.Looper; import android.os.Message; import android.os.ParcelUuid; import android.util.Log; import android.util.StatsLog; import com.android.bluetooth.R; import com.android.bluetooth.Utils; Loading Loading @@ -630,6 +631,11 @@ final class RemoteDevices { + " Disconnected: " + device); } int connectionState = newState == AbstractionLayer.BT_ACL_STATE_CONNECTED ? BluetoothAdapter.STATE_CONNECTED : BluetoothAdapter.STATE_DISCONNECTED; StatsLog.write(StatsLog.BLUETOOTH_ACL_CONNECTION_STATE_CHANGED, sAdapterService.obfuscateAddress(device), connectionState); if (intent != null) { intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT Loading android/app/src/com/android/bluetooth/hfp/HeadsetStateMachine.java +22 −0 Original line number Diff line number Diff line Loading @@ -16,10 +16,12 @@ package com.android.bluetooth.hfp; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothAssignedNumbers; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothHeadset; import android.bluetooth.BluetoothProfile; import android.bluetooth.hfp.BluetoothHfpProtoEnums; import android.content.Intent; import android.media.AudioManager; import android.os.Looper; Loading @@ -28,7 +30,9 @@ import android.os.SystemClock; import android.os.UserHandle; import android.telephony.PhoneNumberUtils; import android.telephony.PhoneStateListener; import android.text.TextUtils; import android.util.Log; import android.util.StatsLog; import com.android.bluetooth.btservice.AdapterService; import com.android.bluetooth.btservice.ProfileService; Loading Loading @@ -299,6 +303,12 @@ public class HeadsetStateMachine extends StateMachine { // Should not be called from enter() method void broadcastAudioState(BluetoothDevice device, int fromState, int toState) { stateLogD("broadcastAudioState: " + device + ": " + fromState + "->" + toState); StatsLog.write(StatsLog.BLUETOOTH_SCO_CONNECTION_STATE_CHANGED, mAdapterService.obfuscateAddress(device), getConnectionStateFromAudioState(toState), TextUtils.equals(mAudioParams.get(HEADSET_WBS), HEADSET_AUDIO_FEATURE_ON) ? BluetoothHfpProtoEnums.SCO_CODEC_MSBC : BluetoothHfpProtoEnums.SCO_CODEC_CVSD); mHeadsetService.onAudioStateChangedFromStateMachine(device, fromState, toState); Intent intent = new Intent(BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED); intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, fromState); Loading Loading @@ -2013,6 +2023,18 @@ public class HeadsetStateMachine extends StateMachine { } } private static int getConnectionStateFromAudioState(int audioState) { switch (audioState) { case BluetoothHeadset.STATE_AUDIO_CONNECTED: return BluetoothAdapter.STATE_CONNECTED; case BluetoothHeadset.STATE_AUDIO_CONNECTING: return BluetoothAdapter.STATE_CONNECTING; case BluetoothHeadset.STATE_AUDIO_DISCONNECTED: return BluetoothAdapter.STATE_DISCONNECTED; } return BluetoothAdapter.STATE_DISCONNECTED; } private static String getMessageName(int what) { switch (what) { case CONNECT: Loading android/app/src/com/android/bluetooth/hfpclient/HeadsetClientStateMachine.java +19 −0 Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ import android.bluetooth.BluetoothHeadsetClient; import android.bluetooth.BluetoothHeadsetClientCall; import android.bluetooth.BluetoothProfile; import android.bluetooth.BluetoothUuid; import android.bluetooth.hfp.BluetoothHfpProtoEnums; import android.content.Intent; import android.media.AudioAttributes; import android.media.AudioFocusRequest; Loading @@ -50,6 +51,7 @@ import android.os.ParcelUuid; import android.os.SystemClock; import android.util.Log; import android.util.Pair; import android.util.StatsLog; import com.android.bluetooth.BluetoothMetricsProto; import com.android.bluetooth.R; Loading Loading @@ -1740,6 +1742,11 @@ public class HeadsetClientStateMachine extends StateMachine { } private void broadcastAudioState(BluetoothDevice device, int newState, int prevState) { StatsLog.write(StatsLog.BLUETOOTH_SCO_CONNECTION_STATE_CHANGED, AdapterService.getAdapterService().obfuscateAddress(device), getConnectionStateFromAudioState(newState), mAudioWbs ? BluetoothHfpProtoEnums.SCO_CODEC_MSBC : BluetoothHfpProtoEnums.SCO_CODEC_CVSD); Intent intent = new Intent(BluetoothHeadsetClient.ACTION_AUDIO_STATE_CHANGED); intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, prevState); intent.putExtra(BluetoothProfile.EXTRA_STATE, newState); Loading Loading @@ -1892,4 +1899,16 @@ public class HeadsetClientStateMachine extends StateMachine { b.putString(BluetoothHeadsetClient.EXTRA_SUBSCRIBER_INFO, mSubscriberInfo); return b; } private static int getConnectionStateFromAudioState(int audioState) { switch (audioState) { case BluetoothHeadsetClient.STATE_AUDIO_CONNECTED: return BluetoothAdapter.STATE_CONNECTED; case BluetoothHeadsetClient.STATE_AUDIO_CONNECTING: return BluetoothAdapter.STATE_CONNECTING; case BluetoothHeadsetClient.STATE_AUDIO_DISCONNECTED: return BluetoothAdapter.STATE_DISCONNECTED; } return BluetoothAdapter.STATE_DISCONNECTED; } } android/app/tests/unit/src/com/android/bluetooth/btservice/RemoteDevicesTest.java +1 −0 Original line number Diff line number Diff line Loading @@ -274,6 +274,7 @@ public class RemoteDevicesTest { // Verify ACTION_ACL_DISCONNECTED and BATTERY_LEVEL_CHANGED intent are sent verify(mAdapterService, times(3)).sendBroadcast(mIntentArgument.capture(), mStringArgument.capture()); verify(mAdapterService).obfuscateAddress(mDevice1); verifyBatteryLevelChangedIntent(mDevice1, BluetoothDevice.BATTERY_LEVEL_UNKNOWN, mIntentArgument.getAllValues().get(mIntentArgument.getAllValues().size() - 2)); Assert.assertEquals(AdapterService.BLUETOOTH_PERM, Loading Loading
android/app/src/com/android/bluetooth/btservice/AdapterProperties.java +3 −6 Original line number Diff line number Diff line Loading @@ -40,7 +40,6 @@ import android.content.IntentFilter; import android.os.ParcelUuid; import android.os.SystemProperties; import android.os.UserHandle; import android.provider.Settings.Secure; import android.util.Log; import android.util.Pair; import android.util.StatsLog; Loading Loading @@ -573,11 +572,9 @@ class AdapterProperties { Log.d(TAG, "PROFILE_CONNECTION_STATE_CHANGE: profile=" + profile + ", device=" + device + ", " + prevState + " -> " + state); String ssaid = Secure.getString(mService.getContentResolver(), Secure.ANDROID_ID); String combined = ssaid + device.getAddress(); int obfuscated_id = combined.hashCode() & 0xFFFF; // Last two bytes only StatsLog.write(StatsLog.BLUETOOTH_CONNECTION_STATE_CHANGED, state, obfuscated_id, profile); StatsLog.write(StatsLog.BLUETOOTH_CONNECTION_STATE_CHANGED, state, 0 /* deprecated */, profile, mService.obfuscateAddress(device)); if (!isNormalStateTransition(prevState, state)) { Log.w(TAG, "PROFILE_CONNECTION_STATE_CHANGE: unexpected transition for profile=" + profile Loading
android/app/src/com/android/bluetooth/btservice/RemoteDevices.java +6 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ import android.os.Looper; import android.os.Message; import android.os.ParcelUuid; import android.util.Log; import android.util.StatsLog; import com.android.bluetooth.R; import com.android.bluetooth.Utils; Loading Loading @@ -630,6 +631,11 @@ final class RemoteDevices { + " Disconnected: " + device); } int connectionState = newState == AbstractionLayer.BT_ACL_STATE_CONNECTED ? BluetoothAdapter.STATE_CONNECTED : BluetoothAdapter.STATE_DISCONNECTED; StatsLog.write(StatsLog.BLUETOOTH_ACL_CONNECTION_STATE_CHANGED, sAdapterService.obfuscateAddress(device), connectionState); if (intent != null) { intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT Loading
android/app/src/com/android/bluetooth/hfp/HeadsetStateMachine.java +22 −0 Original line number Diff line number Diff line Loading @@ -16,10 +16,12 @@ package com.android.bluetooth.hfp; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothAssignedNumbers; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothHeadset; import android.bluetooth.BluetoothProfile; import android.bluetooth.hfp.BluetoothHfpProtoEnums; import android.content.Intent; import android.media.AudioManager; import android.os.Looper; Loading @@ -28,7 +30,9 @@ import android.os.SystemClock; import android.os.UserHandle; import android.telephony.PhoneNumberUtils; import android.telephony.PhoneStateListener; import android.text.TextUtils; import android.util.Log; import android.util.StatsLog; import com.android.bluetooth.btservice.AdapterService; import com.android.bluetooth.btservice.ProfileService; Loading Loading @@ -299,6 +303,12 @@ public class HeadsetStateMachine extends StateMachine { // Should not be called from enter() method void broadcastAudioState(BluetoothDevice device, int fromState, int toState) { stateLogD("broadcastAudioState: " + device + ": " + fromState + "->" + toState); StatsLog.write(StatsLog.BLUETOOTH_SCO_CONNECTION_STATE_CHANGED, mAdapterService.obfuscateAddress(device), getConnectionStateFromAudioState(toState), TextUtils.equals(mAudioParams.get(HEADSET_WBS), HEADSET_AUDIO_FEATURE_ON) ? BluetoothHfpProtoEnums.SCO_CODEC_MSBC : BluetoothHfpProtoEnums.SCO_CODEC_CVSD); mHeadsetService.onAudioStateChangedFromStateMachine(device, fromState, toState); Intent intent = new Intent(BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED); intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, fromState); Loading Loading @@ -2013,6 +2023,18 @@ public class HeadsetStateMachine extends StateMachine { } } private static int getConnectionStateFromAudioState(int audioState) { switch (audioState) { case BluetoothHeadset.STATE_AUDIO_CONNECTED: return BluetoothAdapter.STATE_CONNECTED; case BluetoothHeadset.STATE_AUDIO_CONNECTING: return BluetoothAdapter.STATE_CONNECTING; case BluetoothHeadset.STATE_AUDIO_DISCONNECTED: return BluetoothAdapter.STATE_DISCONNECTED; } return BluetoothAdapter.STATE_DISCONNECTED; } private static String getMessageName(int what) { switch (what) { case CONNECT: Loading
android/app/src/com/android/bluetooth/hfpclient/HeadsetClientStateMachine.java +19 −0 Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ import android.bluetooth.BluetoothHeadsetClient; import android.bluetooth.BluetoothHeadsetClientCall; import android.bluetooth.BluetoothProfile; import android.bluetooth.BluetoothUuid; import android.bluetooth.hfp.BluetoothHfpProtoEnums; import android.content.Intent; import android.media.AudioAttributes; import android.media.AudioFocusRequest; Loading @@ -50,6 +51,7 @@ import android.os.ParcelUuid; import android.os.SystemClock; import android.util.Log; import android.util.Pair; import android.util.StatsLog; import com.android.bluetooth.BluetoothMetricsProto; import com.android.bluetooth.R; Loading Loading @@ -1740,6 +1742,11 @@ public class HeadsetClientStateMachine extends StateMachine { } private void broadcastAudioState(BluetoothDevice device, int newState, int prevState) { StatsLog.write(StatsLog.BLUETOOTH_SCO_CONNECTION_STATE_CHANGED, AdapterService.getAdapterService().obfuscateAddress(device), getConnectionStateFromAudioState(newState), mAudioWbs ? BluetoothHfpProtoEnums.SCO_CODEC_MSBC : BluetoothHfpProtoEnums.SCO_CODEC_CVSD); Intent intent = new Intent(BluetoothHeadsetClient.ACTION_AUDIO_STATE_CHANGED); intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, prevState); intent.putExtra(BluetoothProfile.EXTRA_STATE, newState); Loading Loading @@ -1892,4 +1899,16 @@ public class HeadsetClientStateMachine extends StateMachine { b.putString(BluetoothHeadsetClient.EXTRA_SUBSCRIBER_INFO, mSubscriberInfo); return b; } private static int getConnectionStateFromAudioState(int audioState) { switch (audioState) { case BluetoothHeadsetClient.STATE_AUDIO_CONNECTED: return BluetoothAdapter.STATE_CONNECTED; case BluetoothHeadsetClient.STATE_AUDIO_CONNECTING: return BluetoothAdapter.STATE_CONNECTING; case BluetoothHeadsetClient.STATE_AUDIO_DISCONNECTED: return BluetoothAdapter.STATE_DISCONNECTED; } return BluetoothAdapter.STATE_DISCONNECTED; } }
android/app/tests/unit/src/com/android/bluetooth/btservice/RemoteDevicesTest.java +1 −0 Original line number Diff line number Diff line Loading @@ -274,6 +274,7 @@ public class RemoteDevicesTest { // Verify ACTION_ACL_DISCONNECTED and BATTERY_LEVEL_CHANGED intent are sent verify(mAdapterService, times(3)).sendBroadcast(mIntentArgument.capture(), mStringArgument.capture()); verify(mAdapterService).obfuscateAddress(mDevice1); verifyBatteryLevelChangedIntent(mDevice1, BluetoothDevice.BATTERY_LEVEL_UNKNOWN, mIntentArgument.getAllValues().get(mIntentArgument.getAllValues().size() - 2)); Assert.assertEquals(AdapterService.BLUETOOTH_PERM, Loading