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

Commit 7ed0ae8f authored by William Escande's avatar William Escande Committed by Gerrit Code Review
Browse files

Merge changes Ia4408e51,I54c3555f,Id18d9784,I3ca86dcf,I4dd286ee, ... into main

* changes:
  MetricsLogger: fix pbap connection metrics
  MetricsLogger: sort connection change logs
  Uniformize times(1) mockito usage
  MetricsLogger: listen to connection change
  AdapterProperties use correct looper
  Flag: add adapter_properties_looper
parents 7f1376fc cee50eb6
Loading
Loading
Loading
Loading
+22 −136
Original line number Diff line number Diff line
@@ -23,31 +23,20 @@ import static android.Manifest.permission.BLUETOOTH_SCAN;
import android.annotation.NonNull;
import android.app.BroadcastOptions;
import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothA2dpSink;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothAvrcpController;
import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothHeadsetClient;
import android.bluetooth.BluetoothHearingAid;
import android.bluetooth.BluetoothHidDevice;
import android.bluetooth.BluetoothHidHost;
import android.bluetooth.BluetoothLeAudio;
import android.bluetooth.BluetoothManager;
import android.bluetooth.BluetoothMap;
import android.bluetooth.BluetoothMapClient;
import android.bluetooth.BluetoothPan;
import android.bluetooth.BluetoothPbap;
import android.bluetooth.BluetoothPbapClient;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothSap;
import android.bluetooth.BufferConstraint;
import android.bluetooth.BufferConstraints;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.ParcelUuid;
import android.os.SystemProperties;
import android.os.UserHandle;
@@ -72,7 +61,7 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CopyOnWriteArrayList;

class AdapterProperties {
    private static final String TAG = "AdapterProperties";
    private static final String TAG = AdapterProperties.class.getSimpleName();

    private static final String MAX_CONNECTED_AUDIO_DEVICES_PROPERTY =
            "persist.bluetooth.maxconnectedaudiodevices";
@@ -95,8 +84,7 @@ class AdapterProperties {
    private volatile int mDiscoverableTimeout;
    private volatile ParcelUuid[] mUuids;

    private CopyOnWriteArrayList<BluetoothDevice> mBondedDevices =
            new CopyOnWriteArrayList<BluetoothDevice>();
    private CopyOnWriteArrayList<BluetoothDevice> mBondedDevices = new CopyOnWriteArrayList<>();

    private int mProfilesConnecting, mProfilesConnected, mProfilesDisconnecting;
    private final HashMap<Integer, Pair<Integer, Integer>> mProfileConnectionState =
@@ -111,10 +99,12 @@ class AdapterProperties {
    private boolean mA2dpOffloadEnabled = false;

    private final AdapterService mService;
    private final BluetoothAdapter mAdapter;
    private final RemoteDevices mRemoteDevices;
    private final Handler mHandler;

    private boolean mDiscovering;
    private long mDiscoveryEndMs; // < Time (ms since epoch) that discovery ended or will end.
    private RemoteDevices mRemoteDevices;
    private BluetoothAdapter mAdapter;
    // TODO - all hw capabilities to be exposed as a class
    private int mNumOfAdvertisementInstancesSupported;
    private boolean mRpaOffloadSupported;
@@ -143,84 +133,21 @@ class AdapterProperties {
    private boolean mIsLeIsochronousBroadcasterSupported;
    private boolean mIsLeChannelSoundingSupported;

    private boolean mReceiverRegistered;

    private final BroadcastReceiver mReceiver =
            new BroadcastReceiver() {
                @Override
                public void onReceive(Context context, Intent intent) {
                    String action = intent.getAction();
                    if (action == null) {
                        Log.w(TAG, "Received intent with null action");
                        return;
                    }
                    switch (action) {
                        case BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED:
                            logConnectionStateChanges(BluetoothProfile.HEADSET, intent);
                            break;
                        case BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED:
                            logConnectionStateChanges(BluetoothProfile.A2DP, intent);
                            break;
                        case BluetoothHeadsetClient.ACTION_CONNECTION_STATE_CHANGED:
                            logConnectionStateChanges(BluetoothProfile.HEADSET_CLIENT, intent);
                            break;
                        case BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED:
                            logConnectionStateChanges(BluetoothProfile.HEARING_AID, intent);
                            break;
                        case BluetoothA2dpSink.ACTION_CONNECTION_STATE_CHANGED:
                            logConnectionStateChanges(BluetoothProfile.A2DP_SINK, intent);
                            break;
                        case BluetoothHidDevice.ACTION_CONNECTION_STATE_CHANGED:
                            logConnectionStateChanges(BluetoothProfile.HID_DEVICE, intent);
                            break;
                        case BluetoothHidHost.ACTION_CONNECTION_STATE_CHANGED:
                            logConnectionStateChanges(BluetoothProfile.HID_HOST, intent);
                            break;
                        case BluetoothAvrcpController.ACTION_CONNECTION_STATE_CHANGED:
                            logConnectionStateChanges(BluetoothProfile.AVRCP_CONTROLLER, intent);
                            break;
                        case BluetoothPan.ACTION_CONNECTION_STATE_CHANGED:
                            logConnectionStateChanges(BluetoothProfile.PAN, intent);
                            break;
                        case BluetoothMap.ACTION_CONNECTION_STATE_CHANGED:
                            logConnectionStateChanges(BluetoothProfile.MAP, intent);
                            break;
                        case BluetoothMapClient.ACTION_CONNECTION_STATE_CHANGED:
                            logConnectionStateChanges(BluetoothProfile.MAP_CLIENT, intent);
                            break;
                        case BluetoothSap.ACTION_CONNECTION_STATE_CHANGED:
                            logConnectionStateChanges(BluetoothProfile.SAP, intent);
                            break;
                        case BluetoothPbapClient.ACTION_CONNECTION_STATE_CHANGED:
                            logConnectionStateChanges(BluetoothProfile.PBAP_CLIENT, intent);
                            break;
                        case BluetoothPbap.ACTION_CONNECTION_STATE_CHANGED:
                            logConnectionStateChanges(BluetoothProfile.PBAP, intent);
                            break;
                        case BluetoothLeAudio.ACTION_LE_AUDIO_CONNECTION_STATE_CHANGED:
                            logConnectionStateChanges(BluetoothProfile.LE_AUDIO, intent);
                            break;
                        default:
                            Log.w(TAG, "Received unknown intent " + intent);
                            break;
                    }
                }
            };

    // Lock for all getters and setters.
    // If finer grained locking is needer, more locks
    // can be added here.
    private final Object mObject = new Object();

    AdapterProperties(AdapterService service) {
    AdapterProperties(AdapterService service, RemoteDevices remoteDevices, Looper looper) {
        mAdapter = ((Context) service).getSystemService(BluetoothManager.class).getAdapter();
        mRemoteDevices = remoteDevices;
        mService = service;
        mAdapter = BluetoothAdapter.getDefaultAdapter();
        mHandler = new Handler(looper);
        invalidateBluetoothCaches();
    }

    public void init(RemoteDevices remoteDevices) {
    public void init() {
        mProfileConnectionState.clear();
        mRemoteDevices = remoteDevices;

        // Get default max connected audio devices from config.xml
        int configDefaultMaxConnectedAudioDevices =
@@ -253,35 +180,12 @@ class AdapterProperties {
                SystemProperties.getBoolean(A2DP_OFFLOAD_SUPPORTED_PROPERTY, false)
                        && !SystemProperties.getBoolean(A2DP_OFFLOAD_DISABLED_PROPERTY, false);

        IntentFilter filter = new IntentFilter();
        filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
        filter.addAction(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothHeadsetClient.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothA2dpSink.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothHidDevice.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothHidHost.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothAvrcpController.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothPan.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothMap.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothMapClient.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothSap.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothPbapClient.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothLeAudio.ACTION_LE_AUDIO_CONNECTION_STATE_CHANGED);
        mService.registerReceiver(mReceiver, filter);
        mReceiverRegistered = true;
        invalidateBluetoothCaches();
    }

    public void cleanup() {
        mRemoteDevices = null;
        mProfileConnectionState.clear();

        if (mReceiverRegistered) {
            mService.unregisterReceiver(mReceiver);
            mReceiverRegistered = false;
        }
        mBondedDevices.clear();
        invalidateBluetoothCaches();
    }
@@ -705,32 +609,6 @@ class AdapterProperties {
        return mDiscovering;
    }

    private void logConnectionStateChanges(int profile, Intent connIntent) {
        BluetoothDevice device = connIntent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
        int state = connIntent.getIntExtra(BluetoothProfile.EXTRA_STATE, -1);
        int metricId = mService.getMetricId(device);
        byte[] remoteDeviceInfoBytes = MetricsLogger.getInstance().getRemoteDeviceInfoProto(device);
        if (state == BluetoothProfile.STATE_CONNECTING) {
            String deviceName = mRemoteDevices.getName(device);
            BluetoothStatsLog.write(
                    BluetoothStatsLog.BLUETOOTH_DEVICE_NAME_REPORTED, metricId, deviceName);
            BluetoothStatsLog.write(
                    BluetoothStatsLog.REMOTE_DEVICE_INFORMATION_WITH_METRIC_ID,
                    metricId,
                    remoteDeviceInfoBytes);

            MetricsLogger.getInstance().logAllowlistedDeviceNameHash(metricId, deviceName, true);
        }
        BluetoothStatsLog.write(
                BluetoothStatsLog.BLUETOOTH_CONNECTION_STATE_CHANGED,
                state,
                0 /* deprecated */,
                profile,
                mService.obfuscateAddress(device),
                metricId,
                0,
                -1);
    }

    void updateOnProfileConnectionChanged(
            BluetoothDevice device, int profile, int newState, int prevState) {
@@ -959,6 +837,14 @@ class AdapterProperties {
    }

    void adapterPropertyChangedCallback(int[] types, byte[][] values) {
        if (Flags.adapterPropertiesLooper()) {
            mHandler.post(() -> adapterPropertyChangedCallbackInternal(types, values));
        } else {
            adapterPropertyChangedCallbackInternal(types, values);
        }
    }

    private void adapterPropertyChangedCallbackInternal(int[] types, byte[][] values) {
        Intent intent;
        int type;
        byte[] val;
+15 −32
Original line number Diff line number Diff line
@@ -335,8 +335,6 @@ public class AdapterService extends Service {

    private volatile boolean mTestModeEnabled = false;

    private MetricsLogger mMetricsLogger;

    /** Handlers for incoming service calls */
    private AdapterServiceBinder mBinder;

@@ -631,7 +629,7 @@ public class AdapterService extends Service {
        }
        // OnCreate must perform the minimum of infaillible and mandatory initialization
        mRemoteDevices = new RemoteDevices(this, mLooper);
        mAdapterProperties = new AdapterProperties(this);
        mAdapterProperties = new AdapterProperties(this, mRemoteDevices, mLooper);
        mAdapterStateMachine = new AdapterState(this, mLooper);
        mBinder = new AdapterServiceBinder(this);
        mUserManager = getNonNullSystemService(UserManager.class);
@@ -646,7 +644,6 @@ public class AdapterService extends Service {
    private void init() {
        Log.d(TAG, "init()");
        Config.init(this);
        initMetricsLogger();
        mDeviceConfigListener.start();

        if (!Flags.fastBindToApp()) {
@@ -658,6 +655,7 @@ public class AdapterService extends Service {
            mCompanionDeviceManager = getNonNullSystemService(CompanionDeviceManager.class);
            mRemoteDevices = new RemoteDevices(this, mLooper);
        }
        MetricsLogger.getInstance().init(this, mRemoteDevices);

        clearDiscoveringPackages();
        if (!Flags.fastBindToApp()) {
@@ -666,7 +664,7 @@ public class AdapterService extends Service {
        mAdapter = BluetoothAdapter.getDefaultAdapter();
        if (!Flags.fastBindToApp()) {
            // Moved to OnCreate
            mAdapterProperties = new AdapterProperties(this);
            mAdapterProperties = new AdapterProperties(this, mRemoteDevices, mLooper);
            mAdapterStateMachine = new AdapterState(this, mLooper);
        }
        boolean isCommonCriteriaMode =
@@ -822,23 +820,6 @@ public class AdapterService extends Service {
        return mSilenceDeviceManager;
    }

    private boolean initMetricsLogger() {
        if (mMetricsLogger != null) {
            return false;
        }
        mMetricsLogger = MetricsLogger.getInstance();
        return mMetricsLogger.init(this);
    }

    private boolean closeMetricsLogger() {
        if (mMetricsLogger == null) {
            return false;
        }
        boolean result = mMetricsLogger.close();
        mMetricsLogger = null;
        return result;
    }

    /**
     * Log L2CAP CoC Server Connection Metrics
     *
@@ -891,10 +872,6 @@ public class AdapterService extends Service {
                socketAcceptanceLatencyMillis);
    }

    public void setMetricsLogger(MetricsLogger metricsLogger) {
        mMetricsLogger = metricsLogger;
    }

    /**
     * Log L2CAP CoC Client Connection Metrics
     *
@@ -1001,7 +978,7 @@ public class AdapterService extends Service {
        // calling cleanup but this may not be necessary at all
        // We should figure out why this is needed later
        mRemoteDevices.reset();
        mAdapterProperties.init(mRemoteDevices);
        mAdapterProperties.init();

        Log.d(TAG, "bleOnProcessStart() - Make Bond State Machine");
        mBondStateMachine = BondStateMachine.make(this, mAdapterProperties, mRemoteDevices);
@@ -1200,9 +1177,12 @@ public class AdapterService extends Service {
    }

    void updateAdapterName(String name) {
        // TODO: b/372775662 - remove post once caller is on correct thread
        if (Flags.adapterPropertiesLooper()) {
            updateAdapterNameInternal(name);
        } else {
            mHandler.post(() -> updateAdapterNameInternal(name));
        }
    }

    private void updateAdapterNameInternal(String name) {
        int n = mRemoteCallbacks.beginBroadcast();
@@ -1218,9 +1198,12 @@ public class AdapterService extends Service {
    }

    void updateAdapterAddress(String address) {
        // TODO: b/372775662 - remove post once caller is on correct thread
        if (Flags.adapterPropertiesLooper()) {
            updateAdapterAddressInternal(address);
        } else {
            mHandler.post(() -> updateAdapterAddressInternal(address));
        }
    }

    private void updateAdapterAddressInternal(String address) {
        int n = mRemoteCallbacks.beginBroadcast();
@@ -1451,7 +1434,7 @@ public class AdapterService extends Service {
            return;
        }

        closeMetricsLogger();
        MetricsLogger.getInstance().close();

        clearAdapterService(this);

+3 −4
Original line number Diff line number Diff line
@@ -21,9 +21,10 @@ import android.bluetooth.UidTraffic;

class JniCallbacks {

    private final AdapterProperties mAdapterProperties;
    private final AdapterService mAdapterService;

    private RemoteDevices mRemoteDevices;
    private AdapterProperties mAdapterProperties;
    private AdapterService mAdapterService;
    private BondStateMachine mBondStateMachine;

    JniCallbacks(AdapterService adapterService, AdapterProperties adapterProperties) {
@@ -38,8 +39,6 @@ class JniCallbacks {

    void cleanup() {
        mRemoteDevices = null;
        mAdapterProperties = null;
        mAdapterService = null;
        mBondStateMachine = null;
    }

+135 −7
Original line number Diff line number Diff line
@@ -18,9 +18,28 @@ package com.android.bluetooth.btservice;
import static com.android.bluetooth.BtRestrictedStatsLog.RESTRICTED_BLUETOOTH_DEVICE_NAME_REPORTED;

import android.app.AlarmManager;
import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothA2dpSink;
import android.bluetooth.BluetoothAvrcpController;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothHeadset;
import android.bluetooth.BluetoothHeadsetClient;
import android.bluetooth.BluetoothHearingAid;
import android.bluetooth.BluetoothHidDevice;
import android.bluetooth.BluetoothHidHost;
import android.bluetooth.BluetoothLeAudio;
import android.bluetooth.BluetoothMap;
import android.bluetooth.BluetoothMapClient;
import android.bluetooth.BluetoothPan;
import android.bluetooth.BluetoothPbap;
import android.bluetooth.BluetoothPbapClient;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothProtoEnums;
import android.bluetooth.BluetoothSap;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import android.os.SystemClock;
import android.util.Log;
@@ -71,6 +90,7 @@ public class MetricsLogger {
    HashMap<Integer, Long> mCounters = new HashMap<>();
    private static volatile MetricsLogger sInstance = null;
    private AdapterService mAdapterService = null;
    private RemoteDevices mRemoteDevices = null;
    private AlarmManager mAlarmManager = null;
    private boolean mInitialized = false;
    private static final Object sLock = new Object();
@@ -111,7 +131,8 @@ public class MetricsLogger {
        }
    }

    public boolean isInitialized() {
    @VisibleForTesting
    boolean isInitialized() {
        return mInitialized;
    }

@@ -151,12 +172,13 @@ public class MetricsLogger {
        mBloomFilter = bloomfilter;
    }

    public boolean init(AdapterService adapterService) {
    void init(AdapterService adapterService, RemoteDevices remoteDevices) {
        if (mInitialized) {
            return false;
            return;
        }
        mInitialized = true;
        mAdapterService = adapterService;
        mRemoteDevices = remoteDevices;
        scheduleDrains();
        if (!initBloomFilter(BLOOMFILTER_FULL_PATH)) {
            Log.w(TAG, "MetricsLogger can't initialize the bloomfilter");
@@ -164,7 +186,113 @@ public class MetricsLogger {
            // We still want to use this class even if the bloomfilter isn't initialized
            // so still return true here.
        }
        return true;
        IntentFilter filter = new IntentFilter();
        filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
        filter.addAction(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothA2dpSink.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothAvrcpController.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothHeadsetClient.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothHidDevice.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothHidHost.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothLeAudio.ACTION_LE_AUDIO_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothMap.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothMapClient.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothPan.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothPbap.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothPbapClient.ACTION_CONNECTION_STATE_CHANGED);
        filter.addAction(BluetoothSap.ACTION_CONNECTION_STATE_CHANGED);
        mAdapterService.registerReceiver(mReceiver, filter);
    }

    private final BroadcastReceiver mReceiver =
            new BroadcastReceiver() {
                @Override
                public void onReceive(Context context, Intent intent) {
                    String action = intent.getAction();
                    if (action == null) {
                        Log.w(TAG, "Received intent with null action");
                        return;
                    }
                    switch (action) {
                        case BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED:
                            logConnectionStateChanges(BluetoothProfile.A2DP, intent);
                            break;
                        case BluetoothA2dpSink.ACTION_CONNECTION_STATE_CHANGED:
                            logConnectionStateChanges(BluetoothProfile.A2DP_SINK, intent);
                            break;
                        case BluetoothAvrcpController.ACTION_CONNECTION_STATE_CHANGED:
                            logConnectionStateChanges(BluetoothProfile.AVRCP_CONTROLLER, intent);
                            break;
                        case BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED:
                            logConnectionStateChanges(BluetoothProfile.HEADSET, intent);
                            break;
                        case BluetoothHeadsetClient.ACTION_CONNECTION_STATE_CHANGED:
                            logConnectionStateChanges(BluetoothProfile.HEADSET_CLIENT, intent);
                            break;
                        case BluetoothHearingAid.ACTION_CONNECTION_STATE_CHANGED:
                            logConnectionStateChanges(BluetoothProfile.HEARING_AID, intent);
                            break;
                        case BluetoothHidDevice.ACTION_CONNECTION_STATE_CHANGED:
                            logConnectionStateChanges(BluetoothProfile.HID_DEVICE, intent);
                            break;
                        case BluetoothHidHost.ACTION_CONNECTION_STATE_CHANGED:
                            logConnectionStateChanges(BluetoothProfile.HID_HOST, intent);
                            break;
                        case BluetoothLeAudio.ACTION_LE_AUDIO_CONNECTION_STATE_CHANGED:
                            logConnectionStateChanges(BluetoothProfile.LE_AUDIO, intent);
                            break;
                        case BluetoothMap.ACTION_CONNECTION_STATE_CHANGED:
                            logConnectionStateChanges(BluetoothProfile.MAP, intent);
                            break;
                        case BluetoothMapClient.ACTION_CONNECTION_STATE_CHANGED:
                            logConnectionStateChanges(BluetoothProfile.MAP_CLIENT, intent);
                            break;
                        case BluetoothPan.ACTION_CONNECTION_STATE_CHANGED:
                            logConnectionStateChanges(BluetoothProfile.PAN, intent);
                            break;
                        case BluetoothPbap.ACTION_CONNECTION_STATE_CHANGED:
                            logConnectionStateChanges(BluetoothProfile.PBAP, intent);
                            break;
                        case BluetoothPbapClient.ACTION_CONNECTION_STATE_CHANGED:
                            logConnectionStateChanges(BluetoothProfile.PBAP_CLIENT, intent);
                            break;
                        case BluetoothSap.ACTION_CONNECTION_STATE_CHANGED:
                            logConnectionStateChanges(BluetoothProfile.SAP, intent);
                            break;
                        default:
                            Log.w(TAG, "Received unknown intent " + intent);
                            break;
                    }
                }
            };

    private void logConnectionStateChanges(int profile, Intent connIntent) {
        BluetoothDevice device = connIntent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
        int state = connIntent.getIntExtra(BluetoothProfile.EXTRA_STATE, -1);
        int metricId = mAdapterService.getMetricId(device);
        byte[] remoteDeviceInfoBytes = getRemoteDeviceInfoProto(device);
        if (state == BluetoothProfile.STATE_CONNECTING) {
            String deviceName = mRemoteDevices.getName(device);
            BluetoothStatsLog.write(
                    BluetoothStatsLog.BLUETOOTH_DEVICE_NAME_REPORTED, metricId, deviceName);
            BluetoothStatsLog.write(
                    BluetoothStatsLog.REMOTE_DEVICE_INFORMATION_WITH_METRIC_ID,
                    metricId,
                    remoteDeviceInfoBytes);

            logAllowlistedDeviceNameHash(metricId, deviceName, true);
        }
        BluetoothStatsLog.write(
                BluetoothStatsLog.BLUETOOTH_CONNECTION_STATE_CHANGED,
                state,
                0 /* deprecated */,
                profile,
                mAdapterService.obfuscateAddress(device),
                metricId,
                0,
                -1);
    }

    public boolean cacheCount(int key, long count) {
@@ -260,18 +388,18 @@ public class MetricsLogger {
        }
    }

    public boolean close() {
    void close() {
        if (!mInitialized) {
            return false;
            return;
        }
        Log.d(TAG, "close()");
        mAdapterService.unregisterReceiver(mReceiver);
        cancelPendingDrain();
        drainBufferedCounters();
        mAlarmManager = null;
        mAdapterService = null;
        mInitialized = false;
        mBloomFilterInitialized = false;
        return true;
    }

    protected void cancelPendingDrain() {
+2 −4

File changed.

Preview size limit exceeded, changes collapsed.

Loading