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

Commit e13f66a3 authored by Wei Wang's avatar Wei Wang
Browse files

Clean up advertise and scan clients upon bluetooth down.

Fixes b/16528460

This allows Advertiser and Scanner to be reused after bluetooth recycle,
which follows same behavior for BluetoothAdapter.

Also prints manufacturer data array for ScanRecord.

Change-Id: I78bca40ac294433782a054bf2a00a775dac02d96
parent 13d89896
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -1428,6 +1428,9 @@ public final class BluetoothAdapter {
                if (VDBG) Log.d(TAG, "onBluetoothServiceDown: " + mService);
                synchronized (mManagerCallback) {
                    mService = null;
                    mLeScanClients.clear();
                    if (sBluetoothLeAdvertiser != null) sBluetoothLeAdvertiser.cleanup();
                    if (sBluetoothLeScanner != null) sBluetoothLeScanner.cleanup();
                    for (IBluetoothManagerCallback cb : mProxyServiceStateCallbacks ){
                        try {
                            if (cb != null) {
+9 −0
Original line number Diff line number Diff line
@@ -175,6 +175,15 @@ public final class BluetoothLeAdvertiser {
        }
    }

    /**
     * Cleans up advertise clients. Should be called when bluetooth is down.
     *
     * @hide
     */
    public void cleanup() {
        mLeAdvertisers.clear();
    }

    // Compute the size of the advertise data.
    private int totalBytes(AdvertiseData data) {
        if (data == null) {
+9 −0
Original line number Diff line number Diff line
@@ -208,6 +208,15 @@ public final class BluetoothLeScanner {
        startScan(scanFilters, settings, callback, scanStorages);
    }

    /**
     * Cleans up scan clients. Should be called when bluetooth is down.
     *
     * @hide
     */
    public void cleanup() {
        mLeScanClients.clear();
    }

    /**
     * Bluetooth GATT interface callbacks
     */
+1 −1
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ public class Utils {
        StringBuilder buffer = new StringBuilder();
        buffer.append('{');
        for (int i = 0; i < array.size(); ++i) {
            buffer.append(array.keyAt(i)).append("=").append(array.valueAt(i));
            buffer.append(array.keyAt(i)).append("=").append(Arrays.toString(array.valueAt(i)));
        }
        buffer.append('}');
        return buffer.toString();