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

Commit 656b1009 authored by Zach Lee's avatar Zach Lee Committed by Automerger Merge Worker
Browse files

New logs for debugging scan mode issues am: cb2a2acc

parents bbcd7c92 cb2a2acc
Loading
Loading
Loading
Loading
+30 −4
Original line number Diff line number Diff line
@@ -55,6 +55,8 @@ import com.android.bluetooth.BluetoothStatsLog;
import com.android.bluetooth.Utils;
import com.android.bluetooth.btservice.RemoteDevices.DeviceProperties;

import com.google.common.collect.EvictingQueue;

import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;
@@ -91,6 +93,9 @@ class AdapterProperties {
    private CopyOnWriteArrayList<BluetoothDevice> mBondedDevices =
            new CopyOnWriteArrayList<BluetoothDevice>();

    private static final int SCAN_MODE_CHANGES_MAX_SIZE = 10;
    private EvictingQueue<String> mScanModeChanges;

    private int mProfilesConnecting, mProfilesConnected, mProfilesDisconnecting;
    private final HashMap<Integer, Pair<Integer, Integer>> mProfileConnectionState =
            new HashMap<>();
@@ -200,6 +205,7 @@ class AdapterProperties {
    AdapterProperties(AdapterService service) {
        mService = service;
        mAdapter = BluetoothAdapter.getDefaultAdapter();
        mScanModeChanges = EvictingQueue.create(SCAN_MODE_CHANGES_MAX_SIZE);
        invalidateBluetoothCaches();
    }

@@ -254,6 +260,7 @@ class AdapterProperties {
        }
        mService = null;
        mBondedDevices.clear();
        mScanModeChanges.clear();
        invalidateBluetoothCaches();
    }

@@ -389,15 +396,28 @@ class AdapterProperties {
    /**
     * Set the local adapter property - scanMode
     *
     * @param scanMode the ScanMode to set
     * @param scanMode the ScanMode to set, valid values are: {
     *     BluetoothAdapter.SCAN_MODE_NONE,
     *     BluetoothAdapter.SCAN_MODE_CONNECTABLE,
     *     BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE,
     *   }
     */
    boolean setScanMode(int scanMode) {
        addScanChangeLog(scanMode);
        synchronized (mObject) {
            return mService.setAdapterPropertyNative(AbstractionLayer.BT_PROPERTY_ADAPTER_SCAN_MODE,
                    Utils.intToByteArray(scanMode));
                    Utils.intToByteArray(AdapterService.convertScanModeToHal(scanMode)));
        }
    }

    private void addScanChangeLog(int scanMode) {
        String time = Utils.getLocalTimeString();
        String uidPid = Utils.getUidPidString();
        String scanModeString = dumpScanMode(scanMode);

        mScanModeChanges.add(time + " (" + uidPid + ") " + scanModeString);
    }

    /**
     * @return the mUuids
     */
@@ -1073,7 +1093,7 @@ class AdapterProperties {
            mProfilesConnecting = 0;
            mProfilesDisconnecting = 0;
            // adapterPropertyChangedCallback has already been received.  Set the scan mode.
            setScanMode(AbstractionLayer.BT_SCAN_MODE_CONNECTABLE);
            setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE);
            // This keeps NV up-to date on first-boot after flash.
            setDiscoverableTimeout(mDiscoverableTimeout);
        }
@@ -1083,7 +1103,7 @@ class AdapterProperties {
        // Sequence BLE_ON to STATE_OFF - that is _complete_ OFF state.
        debugLog("onBleDisable");
        // Set the scan_mode to NONE (no incoming connections).
        setScanMode(AbstractionLayer.BT_SCAN_MODE_NONE);
        setScanMode(BluetoothAdapter.SCAN_MODE_NONE);
    }

    void discoveryStateChangeCallback(int state) {
@@ -1136,6 +1156,12 @@ class AdapterProperties {
            }
        }
        writer.println(sb.toString());

        writer.println("  " + "Scan Mode Changes:");
        for (String log : mScanModeChanges) {
            writer.println("    " + log);
        }

    }

    private String dumpDeviceType(int deviceType) {
+3 −3
Original line number Diff line number Diff line
@@ -712,7 +712,7 @@ public class AdapterService extends Service {
    void stopProfileServices() {
        // Make sure to stop classic background tasks now
        cancelDiscoveryNative();
        mAdapterProperties.setScanMode(AbstractionLayer.BT_SCAN_MODE_NONE);
        mAdapterProperties.setScanMode(BluetoothAdapter.SCAN_MODE_NONE);

        Class[] supportedProfileServices = Config.getSupportedProfiles();
        // TODO(b/228875190): GATT is assumed supported. If we support no profiles then just move on
@@ -1967,7 +1967,7 @@ public class AdapterService extends Service {
            }
            enforceBluetoothPrivilegedPermission(service);

            return service.mAdapterProperties.setScanMode(convertScanModeToHal(mode))
            return service.mAdapterProperties.setScanMode(mode)
                    ? BluetoothStatusCodes.SUCCESS : BluetoothStatusCodes.ERROR_UNKNOWN;
        }

@@ -4863,7 +4863,7 @@ public class AdapterService extends Service {
                source.getUid(), source.getPackageName(), deviceAddress);
    }

    private static int convertScanModeToHal(int mode) {
    static int convertScanModeToHal(int mode) {
        switch (mode) {
            case BluetoothAdapter.SCAN_MODE_NONE:
                return AbstractionLayer.BT_SCAN_MODE_NONE;