Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 96ca9384 authored by Jack He's avatar Jack He Committed by android-build-merger
Browse files

Merge "Metrics: Log ACL and SCO connection state change"

am: f5a6b6f3

Change-Id: Id48098b3a0a1a2882c8ba39e99db8ca7824b9a27
parents ab6b060e f5a6b6f3
Loading
Loading
Loading
Loading
+3 −6
Original line number Original line Diff line number Diff line
@@ -40,7 +40,6 @@ import android.content.IntentFilter;
import android.os.ParcelUuid;
import android.os.ParcelUuid;
import android.os.SystemProperties;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserHandle;
import android.provider.Settings.Secure;
import android.util.Log;
import android.util.Log;
import android.util.Pair;
import android.util.Pair;
import android.util.StatsLog;
import android.util.StatsLog;
@@ -573,11 +572,9 @@ class AdapterProperties {
        Log.d(TAG,
        Log.d(TAG,
                "PROFILE_CONNECTION_STATE_CHANGE: profile=" + profile + ", device=" + device + ", "
                "PROFILE_CONNECTION_STATE_CHANGE: profile=" + profile + ", device=" + device + ", "
                        + prevState + " -> " + state);
                        + prevState + " -> " + state);
        String ssaid = Secure.getString(mService.getContentResolver(), Secure.ANDROID_ID);
        StatsLog.write(StatsLog.BLUETOOTH_CONNECTION_STATE_CHANGED, state, 0 /* deprecated */,
        String combined = ssaid + device.getAddress();
                profile, mService.obfuscateAddress(device));
        int obfuscated_id = combined.hashCode() & 0xFFFF; // Last two bytes only

        StatsLog.write(StatsLog.BLUETOOTH_CONNECTION_STATE_CHANGED,
                state, obfuscated_id, profile);
        if (!isNormalStateTransition(prevState, state)) {
        if (!isNormalStateTransition(prevState, state)) {
            Log.w(TAG,
            Log.w(TAG,
                    "PROFILE_CONNECTION_STATE_CHANGE: unexpected transition for profile=" + profile
                    "PROFILE_CONNECTION_STATE_CHANGE: unexpected transition for profile=" + profile
+6 −0
Original line number Original line Diff line number Diff line
@@ -31,6 +31,7 @@ import android.os.Looper;
import android.os.Message;
import android.os.Message;
import android.os.ParcelUuid;
import android.os.ParcelUuid;
import android.util.Log;
import android.util.Log;
import android.util.StatsLog;


import com.android.bluetooth.R;
import com.android.bluetooth.R;
import com.android.bluetooth.Utils;
import com.android.bluetooth.Utils;
@@ -630,6 +631,11 @@ final class RemoteDevices {
                            + " Disconnected: " + device);
                            + " 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) {
        if (intent != null) {
            intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
            intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
            intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT
            intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT
+22 −0
Original line number Original line Diff line number Diff line
@@ -16,10 +16,12 @@


package com.android.bluetooth.hfp;
package com.android.bluetooth.hfp;


import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothAssignedNumbers;
import android.bluetooth.BluetoothAssignedNumbers;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.hfp.BluetoothHfpProtoEnums;
import android.content.Intent;
import android.content.Intent;
import android.media.AudioManager;
import android.media.AudioManager;
import android.os.Looper;
import android.os.Looper;
@@ -28,7 +30,9 @@ import android.os.SystemClock;
import android.os.UserHandle;
import android.os.UserHandle;
import android.telephony.PhoneNumberUtils;
import android.telephony.PhoneNumberUtils;
import android.telephony.PhoneStateListener;
import android.telephony.PhoneStateListener;
import android.text.TextUtils;
import android.util.Log;
import android.util.Log;
import android.util.StatsLog;


import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.btservice.ProfileService;
import com.android.bluetooth.btservice.ProfileService;
@@ -299,6 +303,12 @@ public class HeadsetStateMachine extends StateMachine {
        // Should not be called from enter() method
        // Should not be called from enter() method
        void broadcastAudioState(BluetoothDevice device, int fromState, int toState) {
        void broadcastAudioState(BluetoothDevice device, int fromState, int toState) {
            stateLogD("broadcastAudioState: " + device + ": " + fromState + "->" + 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);
            mHeadsetService.onAudioStateChangedFromStateMachine(device, fromState, toState);
            Intent intent = new Intent(BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED);
            Intent intent = new Intent(BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED);
            intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, fromState);
            intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, fromState);
@@ -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) {
    private static String getMessageName(int what) {
        switch (what) {
        switch (what) {
            case CONNECT:
            case CONNECT:
+19 −0
Original line number Original line Diff line number Diff line
@@ -39,6 +39,7 @@ import android.bluetooth.BluetoothHeadsetClient;
import android.bluetooth.BluetoothHeadsetClientCall;
import android.bluetooth.BluetoothHeadsetClientCall;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothUuid;
import android.bluetooth.BluetoothUuid;
import android.bluetooth.hfp.BluetoothHfpProtoEnums;
import android.content.Intent;
import android.content.Intent;
import android.media.AudioAttributes;
import android.media.AudioAttributes;
import android.media.AudioFocusRequest;
import android.media.AudioFocusRequest;
@@ -50,6 +51,7 @@ import android.os.ParcelUuid;
import android.os.SystemClock;
import android.os.SystemClock;
import android.util.Log;
import android.util.Log;
import android.util.Pair;
import android.util.Pair;
import android.util.StatsLog;


import com.android.bluetooth.BluetoothMetricsProto;
import com.android.bluetooth.BluetoothMetricsProto;
import com.android.bluetooth.R;
import com.android.bluetooth.R;
@@ -1740,6 +1742,11 @@ public class HeadsetClientStateMachine extends StateMachine {
    }
    }


    private void broadcastAudioState(BluetoothDevice device, int newState, int prevState) {
    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 intent = new Intent(BluetoothHeadsetClient.ACTION_AUDIO_STATE_CHANGED);
        intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, prevState);
        intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, prevState);
        intent.putExtra(BluetoothProfile.EXTRA_STATE, newState);
        intent.putExtra(BluetoothProfile.EXTRA_STATE, newState);
@@ -1892,4 +1899,16 @@ public class HeadsetClientStateMachine extends StateMachine {
        b.putString(BluetoothHeadsetClient.EXTRA_SUBSCRIBER_INFO, mSubscriberInfo);
        b.putString(BluetoothHeadsetClient.EXTRA_SUBSCRIBER_INFO, mSubscriberInfo);
        return b;
        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;
    }
}
}
+1 −0
Original line number Original line Diff line number Diff line
@@ -274,6 +274,7 @@ public class RemoteDevicesTest {
        // Verify ACTION_ACL_DISCONNECTED and BATTERY_LEVEL_CHANGED intent are sent
        // Verify ACTION_ACL_DISCONNECTED and BATTERY_LEVEL_CHANGED intent are sent
        verify(mAdapterService, times(3)).sendBroadcast(mIntentArgument.capture(),
        verify(mAdapterService, times(3)).sendBroadcast(mIntentArgument.capture(),
                mStringArgument.capture());
                mStringArgument.capture());
        verify(mAdapterService).obfuscateAddress(mDevice1);
        verifyBatteryLevelChangedIntent(mDevice1, BluetoothDevice.BATTERY_LEVEL_UNKNOWN,
        verifyBatteryLevelChangedIntent(mDevice1, BluetoothDevice.BATTERY_LEVEL_UNKNOWN,
                mIntentArgument.getAllValues().get(mIntentArgument.getAllValues().size() - 2));
                mIntentArgument.getAllValues().get(mIntentArgument.getAllValues().size() - 2));
        Assert.assertEquals(AdapterService.BLUETOOTH_PERM,
        Assert.assertEquals(AdapterService.BLUETOOTH_PERM,