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

Commit 03045e65 authored by Hall Liu's avatar Hall Liu Committed by android-build-merger
Browse files

Merge "Add persistent logging for BT events" am: 067d5ac2

am: 47c68f78

Change-Id: Ib26db69ee998bf78706f2886137b46641e597fca
parents a21118ab 47c68f78
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -526,6 +526,13 @@ public class CallAudioManager extends CallsManagerListenerBase {
        pw.increaseIndent();
        mCallAudioRouteStateMachine.dumpPendingMessages(pw);
        pw.decreaseIndent();

        pw.println("BluetoothDeviceManager:");
        pw.increaseIndent();
        if (mBluetoothStateReceiver.getBluetoothDeviceManager() != null) {
            mBluetoothStateReceiver.getBluetoothDeviceManager().dump(pw);
        }
        pw.decreaseIndent();
    }

    @VisibleForTesting
+26 −11
Original line number Diff line number Diff line
@@ -22,7 +22,9 @@ import android.bluetooth.BluetoothHearingAid;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
import android.telecom.Log;
import android.util.LocalLog;

import com.android.internal.util.IndentingPrintWriter;
import com.android.server.telecom.BluetoothAdapterProxy;
import com.android.server.telecom.BluetoothHeadsetProxy;

@@ -43,18 +45,21 @@ public class BluetoothDeviceManager {
                    Log.startSession("BMSL.oSC");
                    try {
                        synchronized (mLock) {
                            String logString;
                            if (profile == BluetoothProfile.HEADSET) {
                                mBluetoothHeadsetService =
                                        new BluetoothHeadsetProxy((BluetoothHeadset) proxy);
                                Log.i(this, "- Got BluetoothHeadset: " + mBluetoothHeadsetService);
                                logString = "Got BluetoothHeadset: " + mBluetoothHeadsetService;
                            } else if (profile == BluetoothProfile.HEARING_AID) {
                                mBluetoothHearingAidService = (BluetoothHearingAid) proxy;
                                Log.i(this, "- Got BluetoothHearingAid: "
                                        + mBluetoothHearingAidService);
                                logString = "Got BluetoothHearingAid: "
                                        + mBluetoothHearingAidService;
                            } else {
                                Log.w(this, "Connected to non-requested bluetooth service." +
                                        " Not changing bluetooth headset.");
                                logString = "Connected to non-requested bluetooth service." +
                                        " Not changing bluetooth headset.";
                            }
                            Log.i(BluetoothDeviceManager.this, logString);
                            mLocalLog.log(logString);
                        }
                    } finally {
                        Log.endSession();
@@ -67,23 +72,25 @@ public class BluetoothDeviceManager {
                    try {
                        synchronized (mLock) {
                            LinkedHashMap<String, BluetoothDevice> lostServiceDevices;
                            String logString;
                            if (profile == BluetoothProfile.HEADSET) {
                                mBluetoothHeadsetService = null;
                                Log.i(BluetoothDeviceManager.this,
                                        "Lost BluetoothHeadset service. " +
                                                "Removing all tracked devices.");
                                lostServiceDevices = mHfpDevicesByAddress;
                                mBluetoothRouteManager.onActiveDeviceChanged(null, false);
                                logString = "Lost BluetoothHeadset service. " +
                                        "Removing all tracked devices";
                            } else if (profile == BluetoothProfile.HEARING_AID) {
                                mBluetoothHearingAidService = null;
                                Log.i(BluetoothDeviceManager.this,
                                        "Lost BluetoothHearingAid service. " +
                                                "Removing all tracked devices.");
                                logString = "Lost BluetoothHearingAid service. " +
                                        "Removing all tracked devices.";
                                lostServiceDevices = mHearingAidDevicesByAddress;
                                mBluetoothRouteManager.onActiveDeviceChanged(null, true);
                            } else {
                                return;
                            }
                            Log.i(BluetoothDeviceManager.this, logString);
                            mLocalLog.log(logString);

                            List<BluetoothDevice> devicesToRemove = new LinkedList<>(
                                    lostServiceDevices.values());
                            lostServiceDevices.clear();
@@ -103,6 +110,7 @@ public class BluetoothDeviceManager {
            new LinkedHashMap<>();
    private final LinkedHashMap<BluetoothDevice, Long> mHearingAidDeviceSyncIds =
            new LinkedHashMap<>();
    private final LocalLog mLocalLog = new LocalLog(20);

    // This lock only protects internal state -- it doesn't lock on anything going into Telecom.
    private final Object mLock = new Object();
@@ -188,6 +196,8 @@ public class BluetoothDeviceManager {
    }

    void onDeviceConnected(BluetoothDevice device, boolean isHearingAid) {
        mLocalLog.log("Device connected -- address: " + device.getAddress() + " isHeadingAid: "
                + isHearingAid);
        synchronized (mLock) {
            LinkedHashMap<String, BluetoothDevice> targetDeviceMap;
            if (isHearingAid) {
@@ -213,6 +223,8 @@ public class BluetoothDeviceManager {
    }

    void onDeviceDisconnected(BluetoothDevice device, boolean isHearingAid) {
        mLocalLog.log("Device disconnected -- address: " + device.getAddress() + " isHeadingAid: "
                + isHearingAid);
        synchronized (mLock) {
            LinkedHashMap<String, BluetoothDevice> targetDeviceMap;
            if (isHearingAid) {
@@ -297,4 +309,7 @@ public class BluetoothDeviceManager {
        }
    }

    public void dump(IndentingPrintWriter pw) {
        mLocalLog.dump(pw);
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -152,6 +152,10 @@ public class BluetoothStateReceiver extends BroadcastReceiver {
        }
    }

    public BluetoothDeviceManager getBluetoothDeviceManager() {
        return mBluetoothDeviceManager;
    }

    public BluetoothStateReceiver(BluetoothDeviceManager deviceManager,
            BluetoothRouteManager routeManager) {
        mBluetoothDeviceManager = deviceManager;