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

Commit 7eb41a4a authored by Caitlin Shkuratov's avatar Caitlin Shkuratov Committed by Automerger Merge Worker
Browse files

Merge "[Bluetooth] Convert BluetoothController logs to log buffer so we'll...

Merge "[Bluetooth] Convert BluetoothController logs to log buffer so we'll always have them." into tm-qpr-dev am: 33c9d7b2

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/19969290



Change-Id: If70964d872663ecd340cdb4db332eee524051cad
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents a3cb49b2 33c9d7b2
Loading
Loading
Loading
Loading
+50 −10
Original line number Diff line number Diff line
@@ -16,6 +16,22 @@

package com.android.settingslib.bluetooth;

import static android.bluetooth.BluetoothAdapter.STATE_CONNECTED;
import static android.bluetooth.BluetoothAdapter.STATE_CONNECTING;
import static android.bluetooth.BluetoothAdapter.STATE_DISCONNECTED;
import static android.bluetooth.BluetoothAdapter.STATE_DISCONNECTING;
import static android.bluetooth.BluetoothAdapter.STATE_OFF;
import static android.bluetooth.BluetoothAdapter.STATE_ON;
import static android.bluetooth.BluetoothAdapter.STATE_TURNING_OFF;
import static android.bluetooth.BluetoothAdapter.STATE_TURNING_ON;

import android.annotation.IntDef;
import android.annotation.Nullable;

import androidx.annotation.NonNull;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * BluetoothCallback provides a callback interface for the settings
@@ -33,7 +49,7 @@ public interface BluetoothCallback {
     * {@link android.bluetooth.BluetoothAdapter#STATE_ON},
     * {@link android.bluetooth.BluetoothAdapter#STATE_TURNING_OFF}.
     */
    default void onBluetoothStateChanged(int bluetoothState) {}
    default void onBluetoothStateChanged(@AdapterState int bluetoothState) {}

    /**
     * It will be called when the local Bluetooth adapter has started
@@ -54,14 +70,14 @@ public interface BluetoothCallback {
     *
     * @param cachedDevice the Bluetooth device.
     */
    default void onDeviceAdded(CachedBluetoothDevice cachedDevice) {}
    default void onDeviceAdded(@NonNull CachedBluetoothDevice cachedDevice) {}

    /**
     * It will be called when requiring to remove a remote device from CachedBluetoothDevice list
     *
     * @param cachedDevice the Bluetooth device.
     */
    default void onDeviceDeleted(CachedBluetoothDevice cachedDevice) {}
    default void onDeviceDeleted(@NonNull CachedBluetoothDevice cachedDevice) {}

    /**
     * It will be called when bond state of a remote device is changed.
@@ -73,7 +89,8 @@ public interface BluetoothCallback {
     * {@link android.bluetooth.BluetoothDevice#BOND_BONDING},
     * {@link android.bluetooth.BluetoothDevice#BOND_BONDED}.
     */
    default void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState) {}
    default void onDeviceBondStateChanged(
            @NonNull CachedBluetoothDevice cachedDevice, int bondState) {}

    /**
     * It will be called in following situations:
@@ -89,7 +106,9 @@ public interface BluetoothCallback {
     * {@link android.bluetooth.BluetoothAdapter#STATE_CONNECTED},
     * {@link android.bluetooth.BluetoothAdapter#STATE_DISCONNECTING}.
     */
    default void onConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state) {}
    default void onConnectionStateChanged(
            @Nullable CachedBluetoothDevice cachedDevice,
            @ConnectionState int state) {}

    /**
     * It will be called when device been set as active for {@code bluetoothProfile}
@@ -101,7 +120,8 @@ public interface BluetoothCallback {
     * @param activeDevice the active Bluetooth device.
     * @param bluetoothProfile the profile of active Bluetooth device.
     */
    default void onActiveDeviceChanged(CachedBluetoothDevice activeDevice, int bluetoothProfile) {}
    default void onActiveDeviceChanged(
            @Nullable CachedBluetoothDevice activeDevice, int bluetoothProfile) {}

    /**
     * It will be called in following situations:
@@ -124,8 +144,10 @@ public interface BluetoothCallback {
     * {@link android.bluetooth.BluetoothProfile#STATE_DISCONNECTING}.
     * @param bluetoothProfile the BluetoothProfile id.
     */
    default void onProfileConnectionStateChanged(CachedBluetoothDevice cachedDevice,
            int state, int bluetoothProfile) {
    default void onProfileConnectionStateChanged(
            @NonNull CachedBluetoothDevice cachedDevice,
            @ConnectionState int state,
            int bluetoothProfile) {
    }

    /**
@@ -138,6 +160,24 @@ public interface BluetoothCallback {
     *                     {@link android.bluetooth.BluetoothAdapter#STATE_DISCONNECTED},
     *                     {@link android.bluetooth.BluetoothAdapter#STATE_CONNECTED}
     */
    default void onAclConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state) {
    }
    default void onAclConnectionStateChanged(
            @NonNull CachedBluetoothDevice cachedDevice, int state) {}

    @Retention(RetentionPolicy.SOURCE)
    @IntDef(prefix = { "STATE_" }, value = {
            STATE_DISCONNECTED,
            STATE_CONNECTING,
            STATE_CONNECTED,
            STATE_DISCONNECTING,
    })
    @interface ConnectionState {}

    @IntDef(prefix = { "STATE_" }, value = {
            STATE_OFF,
            STATE_TURNING_ON,
            STATE_ON,
            STATE_TURNING_OFF,
    })
    @Retention(RetentionPolicy.SOURCE)
    @interface AdapterState {}
}
+8 −5
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.os.UserHandle;
import android.telephony.TelephonyManager;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;

@@ -193,19 +194,19 @@ public class BluetoothEventManager {
        return deviceAdded;
    }

    void dispatchDeviceAdded(CachedBluetoothDevice cachedDevice) {
    void dispatchDeviceAdded(@NonNull CachedBluetoothDevice cachedDevice) {
        for (BluetoothCallback callback : mCallbacks) {
            callback.onDeviceAdded(cachedDevice);
        }
    }

    void dispatchDeviceRemoved(CachedBluetoothDevice cachedDevice) {
    void dispatchDeviceRemoved(@NonNull CachedBluetoothDevice cachedDevice) {
        for (BluetoothCallback callback : mCallbacks) {
            callback.onDeviceDeleted(cachedDevice);
        }
    }

    void dispatchProfileConnectionStateChanged(CachedBluetoothDevice device, int state,
    void dispatchProfileConnectionStateChanged(@NonNull CachedBluetoothDevice device, int state,
            int bluetoothProfile) {
        for (BluetoothCallback callback : mCallbacks) {
            callback.onProfileConnectionStateChanged(device, state, bluetoothProfile);
@@ -228,7 +229,8 @@ public class BluetoothEventManager {
    }

    @VisibleForTesting
    void dispatchActiveDeviceChanged(CachedBluetoothDevice activeDevice,
    void dispatchActiveDeviceChanged(
            @Nullable CachedBluetoothDevice activeDevice,
            int bluetoothProfile) {
        for (CachedBluetoothDevice cachedDevice : mDeviceManager.getCachedDevicesCopy()) {
            boolean isActive = Objects.equals(cachedDevice, activeDevice);
@@ -239,7 +241,7 @@ public class BluetoothEventManager {
        }
    }

    private void dispatchAclStateChanged(CachedBluetoothDevice activeDevice, int state) {
    private void dispatchAclStateChanged(@NonNull CachedBluetoothDevice activeDevice, int state) {
        for (BluetoothCallback callback : mCallbacks) {
            callback.onAclConnectionStateChanged(activeDevice, state);
        }
@@ -456,6 +458,7 @@ public class BluetoothEventManager {
                Log.w(TAG, "ActiveDeviceChangedHandler: action is null");
                return;
            }
            @Nullable
            CachedBluetoothDevice activeDevice = mDeviceManager.findDevice(device);
            int bluetoothProfile = 0;
            if (Objects.equals(action, BluetoothA2dp.ACTION_ACTIVE_DEVICE_CHANGED)) {
+102 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.bluetooth

import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.LogLevel
import com.android.systemui.log.dagger.BluetoothLog
import javax.inject.Inject

/** Helper class for logging bluetooth events. */
@SysUISingleton
class BluetoothLogger @Inject constructor(@BluetoothLog private val logBuffer: LogBuffer) {
    fun logActiveDeviceChanged(address: String?, profileId: Int) =
        logBuffer.log(
            TAG,
            LogLevel.DEBUG,
            {
                str1 = address
                int1 = profileId
            },
            { "ActiveDeviceChanged. address=$str1 profileId=$int1" }
        )

    fun logDeviceConnectionStateChanged(address: String?, state: String) =
        logBuffer.log(
            TAG,
            LogLevel.DEBUG,
            {
                str1 = address
                str2 = state
            },
            { "DeviceConnectionStateChanged. address=$str1 state=$str2" }
        )

    fun logAclConnectionStateChanged(address: String, state: String) =
        logBuffer.log(
            TAG,
            LogLevel.DEBUG,
            {
                str1 = address
                str2 = state
            },
            { "AclConnectionStateChanged. address=$str1 state=$str2" }
        )

    fun logProfileConnectionStateChanged(address: String?, state: String, profileId: Int) =
        logBuffer.log(
            TAG,
            LogLevel.DEBUG,
            {
                str1 = address
                str2 = state
                int1 = profileId
            },
            { "ProfileConnectionStateChanged. address=$str1 state=$str2 profileId=$int1" }
        )

    fun logStateChange(state: String) =
        logBuffer.log(
            TAG,
            LogLevel.DEBUG,
            { str1 = state },
            { "BluetoothStateChanged. state=$str1" }
        )

    fun logBondStateChange(address: String, state: Int) =
        logBuffer.log(
            TAG,
            LogLevel.DEBUG,
            {
                str1 = address
                int1 = state
            },
            { "DeviceBondStateChanged. address=$str1 state=$int1" }
        )

    fun logDeviceAdded(address: String) =
        logBuffer.log(TAG, LogLevel.DEBUG, { str1 = address }, { "DeviceAdded. address=$str1" })

    fun logDeviceDeleted(address: String) =
        logBuffer.log(TAG, LogLevel.DEBUG, { str1 = address }, { "DeviceDeleted. address=$str1" })

    fun logDeviceAttributesChanged() =
        logBuffer.log(TAG, LogLevel.DEBUG, {}, { "DeviceAttributesChanged." })
}

private const val TAG = "BluetoothLog"
+5 −2
Original line number Diff line number Diff line
@@ -42,6 +42,8 @@ import android.util.Pair;
import android.util.Slog;
import android.widget.Toast;

import androidx.annotation.NonNull;

import com.android.settingslib.bluetooth.BluetoothCallback;
import com.android.settingslib.bluetooth.BluetoothUtils;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
@@ -601,13 +603,14 @@ public class KeyboardUI extends CoreStartable implements InputManager.OnTabletMo

    private final class BluetoothCallbackHandler implements BluetoothCallback {
        @Override
        public void onBluetoothStateChanged(int bluetoothState) {
        public void onBluetoothStateChanged(@BluetoothCallback.AdapterState int bluetoothState) {
            mHandler.obtainMessage(MSG_ON_BLUETOOTH_STATE_CHANGED,
                    bluetoothState, 0).sendToTarget();
        }

        @Override
        public void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState) {
        public void onDeviceBondStateChanged(
                @NonNull CachedBluetoothDevice cachedDevice, int bondState) {
            mHandler.obtainMessage(MSG_ON_DEVICE_BOND_STATE_CHANGED,
                    bondState, 0, cachedDevice).sendToTarget();
        }
+22 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.log.dagger

import javax.inject.Qualifier

/** A [com.android.systemui.log.LogBuffer] for bluetooth. */
@Qualifier @MustBeDocumented @Retention(AnnotationRetention.RUNTIME) annotation class BluetoothLog
Loading