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

Commit 161a3e3e authored by Jack He's avatar Jack He
Browse files

Metrics: Log A2DP playback related metrics through StatsLog

* BluetoothActiveDeviceChanged event for A2DP, HFP, and HEARING_AID
* BluetoothA2dpPlaybackStateChanged event
* BluetoothA2dpCodecConfigChanged event
* BluetoothA2dpCodecCapabilityChanged for selectable capability that is
  defined as capability supported by both Android and remote device

Bug: 112969790
Test: unit test, test drive with statsd
Change-Id: Iaff053536d4802e0780303382203e51150df98bb
parent 11a891e3
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.content.IntentFilter;
import android.media.AudioManager;
import android.os.HandlerThread;
import android.util.Log;
import android.util.StatsLog;

import com.android.bluetooth.BluetoothMetricsProto;
import com.android.bluetooth.Utils;
@@ -810,6 +811,24 @@ public class A2dpService extends ProfileService {
     */
    void codecConfigUpdated(BluetoothDevice device, BluetoothCodecStatus codecStatus,
                            boolean sameAudioFeedingParameters) {
        // Log codec config and capability metrics
        BluetoothCodecConfig codecConfig = codecStatus.getCodecConfig();
        StatsLog.write(StatsLog.BLUETOOTH_A2DP_CODEC_CONFIG_CHANGED,
                mAdapterService.obfuscateAddress(device), codecConfig.getCodecType(),
                codecConfig.getCodecPriority(), codecConfig.getSampleRate(),
                codecConfig.getBitsPerSample(), codecConfig.getChannelMode(),
                codecConfig.getCodecSpecific1(), codecConfig.getCodecSpecific2(),
                codecConfig.getCodecSpecific3(), codecConfig.getCodecSpecific4());
        BluetoothCodecConfig[] codecCapabilities = codecStatus.getCodecsSelectableCapabilities();
        for (BluetoothCodecConfig codecCapability : codecCapabilities) {
            StatsLog.write(StatsLog.BLUETOOTH_A2DP_CODEC_CAPABILITY_CHANGED,
                    mAdapterService.obfuscateAddress(device), codecCapability.getCodecType(),
                    codecCapability.getCodecPriority(), codecCapability.getSampleRate(),
                    codecCapability.getBitsPerSample(), codecCapability.getChannelMode(),
                    codecConfig.getCodecSpecific1(), codecConfig.getCodecSpecific2(),
                    codecConfig.getCodecSpecific3(), codecConfig.getCodecSpecific4());
        }

        broadcastCodecConfig(device, codecStatus);

        // Inform the Audio Service about the codec configuration change,
@@ -866,6 +885,8 @@ public class A2dpService extends ProfileService {
            mActiveDevice = device;
        }

        StatsLog.write(StatsLog.BLUETOOTH_ACTIVE_DEVICE_CHANGED, BluetoothProfile.A2DP,
                mAdapterService.obfuscateAddress(device));
        Intent intent = new Intent(BluetoothA2dp.ACTION_ACTIVE_DEVICE_CHANGED);
        intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
        intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT
+2 −1
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ import android.content.Intent;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.util.StatsLog;

import com.android.bluetooth.btservice.ProfileService;
import com.android.internal.annotations.VisibleForTesting;
@@ -672,7 +673,7 @@ final class A2dpStateMachine extends StateMachine {
    private void broadcastAudioState(int newState, int prevState) {
        log("A2DP Playing state : device: " + mDevice + " State:" + audioStateToString(prevState)
                + "->" + audioStateToString(newState));

        StatsLog.write(StatsLog.BLUETOOTH_A2DP_PLAYBACK_STATE_CHANGED, newState);
        Intent intent = new Intent(BluetoothA2dp.ACTION_PLAYING_STATE_CHANGED);
        intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice);
        intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, prevState);
+3 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.media.AudioManager;
import android.os.HandlerThread;
import android.os.ParcelUuid;
import android.util.Log;
import android.util.StatsLog;

import com.android.bluetooth.BluetoothMetricsProto;
import com.android.bluetooth.Utils;
@@ -605,6 +606,8 @@ public class HearingAidService extends ProfileService {
            Log.d(TAG, "reportActiveDevice(" + device + ")");
        }

        StatsLog.write(StatsLog.BLUETOOTH_ACTIVE_DEVICE_CHANGED, BluetoothProfile.HEARING_AID,
                mAdapterService.obfuscateAddress(device));
        Intent intent = new Intent(BluetoothHearingAid.ACTION_ACTIVE_DEVICE_CHANGED);
        intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
        intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT
+3 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import android.os.SystemProperties;
import android.os.UserHandle;
import android.telecom.PhoneAccount;
import android.util.Log;
import android.util.StatsLog;

import com.android.bluetooth.BluetoothMetricsProto;
import com.android.bluetooth.Utils;
@@ -1699,6 +1700,8 @@ public class HeadsetService extends ProfileService {

    private void broadcastActiveDevice(BluetoothDevice device) {
        logD("broadcastActiveDevice: " + device);
        StatsLog.write(StatsLog.BLUETOOTH_ACTIVE_DEVICE_CHANGED, BluetoothProfile.HEADSET,
                mAdapterService.obfuscateAddress(device));
        Intent intent = new Intent(BluetoothHeadset.ACTION_ACTIVE_DEVICE_CHANGED);
        intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
        intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT