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

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

Merge changes If2476236,Ic4ec20d2,I89bf79f0

* changes:
  Stop btif queue to get stuck on the same node
  Query current calls until new outgoing HF associated with valid call
  New logs for debugging scan mode issues
parents 9aeb48bb c621a3a0
Loading
Loading
Loading
Loading
+30 −4
Original line number Diff line number Diff line
@@ -56,6 +56,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;
@@ -92,6 +94,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<>();
@@ -201,6 +206,7 @@ class AdapterProperties {
    AdapterProperties(AdapterService service) {
        mService = service;
        mAdapter = BluetoothAdapter.getDefaultAdapter();
        mScanModeChanges = EvictingQueue.create(SCAN_MODE_CHANGES_MAX_SIZE);
        invalidateBluetoothCaches();
    }

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

@@ -390,15 +397,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
     */
@@ -1077,7 +1097,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);
        }
@@ -1087,7 +1107,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) {
@@ -1141,6 +1161,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
@@ -729,7 +729,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
@@ -2025,7 +2025,7 @@ public class AdapterService extends Service {
            }
            enforceBluetoothPrivilegedPermission(service);

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

@@ -5186,7 +5186,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;
+6 −1
Original line number Diff line number Diff line
@@ -539,7 +539,12 @@ public class HeadsetClientStateMachine extends StateMachine {
        }

        if (mCalls.size() > 0) {
            if (mService.getResources().getBoolean(R.bool.hfp_clcc_poll_during_call)) {
            // Continue polling even if not enabled until the new outgoing call is associated with
            // a valid call on the phone. The polling would at most continue until
            // OUTGOING_TIMEOUT_MILLI. This handles the potential scenario where the phone creates
            // and terminates a call before the first QUERY_CURRENT_CALLS completes.
            if (mService.getResources().getBoolean(R.bool.hfp_clcc_poll_during_call)
                    || (mCalls.containsKey(HF_ORIGINATED_CALL_ID))) {
                sendMessageDelayed(QUERY_CURRENT_CALLS,
                        mService.getResources().getInteger(
                        R.integer.hfp_clcc_poll_interval_during_call));
+4 −3
Original line number Diff line number Diff line
@@ -80,17 +80,17 @@ void BTA_HfClientDisable(void) { bta_hf_client_api_disable(); }
 * Description      Opens up a RF connection to the remote device and
 *                  subsequently set it up for a HF SLC
 *
 * Returns          void
 * Returns          bt_status_t
 *
 ******************************************************************************/
void BTA_HfClientOpen(const RawAddress& bd_addr, uint16_t* p_handle) {
bt_status_t BTA_HfClientOpen(const RawAddress& bd_addr, uint16_t* p_handle) {
  APPL_TRACE_DEBUG("%s", __func__);
  tBTA_HF_CLIENT_API_OPEN* p_buf =
      (tBTA_HF_CLIENT_API_OPEN*)osi_malloc(sizeof(tBTA_HF_CLIENT_API_OPEN));

  if (!bta_hf_client_allocate_handle(bd_addr, p_handle)) {
    APPL_TRACE_ERROR("%s: could not allocate handle", __func__);
    return;
    return BT_STATUS_FAIL;
  }

  p_buf->hdr.event = BTA_HF_CLIENT_API_OPEN_EVT;
@@ -98,6 +98,7 @@ void BTA_HfClientOpen(const RawAddress& bd_addr, uint16_t* p_handle) {
  p_buf->bd_addr = bd_addr;

  bta_sys_sendmsg(p_buf);
  return BT_STATUS_SUCCESS;
}

/*******************************************************************************
+2 −2
Original line number Diff line number Diff line
@@ -322,10 +322,10 @@ void BTA_HfClientDisable(void);
 *                  calls to do any AT operations
 *
 *
 * Returns          void
 * Returns          bt_status_t
 *
 ******************************************************************************/
void BTA_HfClientOpen(const RawAddress& bd_addr, uint16_t* p_handle);
bt_status_t BTA_HfClientOpen(const RawAddress& bd_addr, uint16_t* p_handle);

/*******************************************************************************
 *
Loading