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

Commit 1a477a04 authored by William Escande's avatar William Escande
Browse files

Add hfp sysprop for hf services

The `define` cannot be override on runtime and some target need to
configure the available services (Eg: Wear OS)

Test: manual | set the property and check new behavior
Bug: 263323082
Change-Id: I39e474b2a0d167c1098ba9df15d5518644786e9e
parent fa8a18c7
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -8,6 +8,7 @@ sysprop_library {
  srcs: [
  srcs: [
    "avrcp.sysprop",
    "avrcp.sysprop",
    "bta.sysprop",
    "bta.sysprop",
    "hfp.sysprop",
  ],
  ],
  property_owner: "Platform",
  property_owner: "Platform",
  api_packages: ["android.sysprop"],
  api_packages: ["android.sysprop"],

sysprop/hfp.sysprop

0 → 100644
+12 −0
Original line number Original line Diff line number Diff line
module: "android.sysprop.bluetooth.Hfp"
owner: Platform

prop {
    api_name: "hf_services"
    type: Integer
    scope: Internal
    access: Readonly
    prop_name: "bluetooth.hfp.hf_services_mask.config"
}

+29 −18
Original line number Original line Diff line number Diff line
@@ -30,6 +30,9 @@
#include <base/functional/callback.h>
#include <base/functional/callback.h>
#include <base/logging.h>
#include <base/logging.h>
#include <frameworks/proto_logging/stats/enums/bluetooth/enums.pb.h>
#include <frameworks/proto_logging/stats/enums/bluetooth/enums.pb.h>
#ifdef OS_ANDROID
#include <hfp.sysprop.h>
#endif


#include <cstdint>
#include <cstdint>
#include <string>
#include <string>
@@ -69,10 +72,6 @@ namespace headset {
#define BTIF_HFAG_SERVICE_NAME ("Handsfree Gateway")
#define BTIF_HFAG_SERVICE_NAME ("Handsfree Gateway")
#endif
#endif


#ifndef BTIF_HF_SERVICES
#define BTIF_HF_SERVICES (BTA_HSP_SERVICE_MASK | BTA_HFP_SERVICE_MASK)
#endif

#ifndef BTIF_HF_SERVICE_NAMES
#ifndef BTIF_HF_SERVICE_NAMES
#define BTIF_HF_SERVICE_NAMES \
#define BTIF_HF_SERVICE_NAMES \
  { BTIF_HSAG_SERVICE_NAME, BTIF_HFAG_SERVICE_NAME }
  { BTIF_HSAG_SERVICE_NAME, BTIF_HFAG_SERVICE_NAME }
@@ -150,6 +149,17 @@ static bool is_active_device(const RawAddress& bd_addr) {
  return !active_bda.IsEmpty() && active_bda == bd_addr;
  return !active_bda.IsEmpty() && active_bda == bd_addr;
}
}


static tBTA_SERVICE_MASK get_BTIF_HF_SERVICES() {
#ifdef OS_ANDROID
  static const tBTA_SERVICE_MASK hf_services =
      android::sysprop::bluetooth::Hfp::hf_services().value_or(
          BTA_HSP_SERVICE_MASK | BTA_HFP_SERVICE_MASK);
  return hf_services;
#else
  return BTA_HSP_SERVICE_MASK | BTA_HFP_SERVICE_MASK;
#endif
}

/*******************************************************************************
/*******************************************************************************
 *
 *
 * Function         is_connected
 * Function         is_connected
@@ -843,11 +853,11 @@ bt_status_t HeadsetInterface::Init(Callbacks* callbacks, int max_hf_clients,
// Invoke the enable service API to the core to set the appropriate service_id
// Invoke the enable service API to the core to set the appropriate service_id
// Internally, the HSP_SERVICE_ID shall also be enabled if HFP is enabled
// Internally, the HSP_SERVICE_ID shall also be enabled if HFP is enabled
// (phone) otherwise only HSP is enabled (tablet)
// (phone) otherwise only HSP is enabled (tablet)
#if (defined(BTIF_HF_SERVICES) && (BTIF_HF_SERVICES & BTA_HFP_SERVICE_MASK))
  if (get_BTIF_HF_SERVICES() & BTA_HFP_SERVICE_MASK) {
    btif_enable_service(BTA_HFP_SERVICE_ID);
    btif_enable_service(BTA_HFP_SERVICE_ID);
#else
  } else {
    btif_enable_service(BTA_HSP_SERVICE_ID);
    btif_enable_service(BTA_HSP_SERVICE_ID);
#endif
  }


  return BT_STATUS_SUCCESS;
  return BT_STATUS_SUCCESS;
}
}
@@ -1484,15 +1494,15 @@ void HeadsetInterface::Cleanup() {
  btif_queue_cleanup(UUID_SERVCLASS_AG_HANDSFREE);
  btif_queue_cleanup(UUID_SERVCLASS_AG_HANDSFREE);


  tBTA_SERVICE_MASK mask = btif_get_enabled_services_mask();
  tBTA_SERVICE_MASK mask = btif_get_enabled_services_mask();
#if (defined(BTIF_HF_SERVICES) && (BTIF_HF_SERVICES & BTA_HFP_SERVICE_MASK))
  if (get_BTIF_HF_SERVICES() & BTA_HFP_SERVICE_MASK) {
    if ((mask & (1 << BTA_HFP_SERVICE_ID)) != 0) {
    if ((mask & (1 << BTA_HFP_SERVICE_ID)) != 0) {
      btif_disable_service(BTA_HFP_SERVICE_ID);
      btif_disable_service(BTA_HFP_SERVICE_ID);
    }
    }
#else
  } else {
    if ((mask & (1 << BTA_HSP_SERVICE_ID)) != 0) {
    if ((mask & (1 << BTA_HSP_SERVICE_ID)) != 0) {
      btif_disable_service(BTA_HSP_SERVICE_ID);
      btif_disable_service(BTA_HSP_SERVICE_ID);
    }
    }
#endif
  }


  bt_hf_callbacks = nullptr;
  bt_hf_callbacks = nullptr;
}
}
@@ -1556,7 +1566,8 @@ bt_status_t ExecuteService(bool b_enable) {
    /* Enable and register with BTA-AG */
    /* Enable and register with BTA-AG */
    BTA_AgEnable(bte_hf_evt);
    BTA_AgEnable(bte_hf_evt);
    for (uint8_t app_id = 0; app_id < btif_max_hf_clients; app_id++) {
    for (uint8_t app_id = 0; app_id < btif_max_hf_clients; app_id++) {
      BTA_AgRegister(BTIF_HF_SERVICES, btif_hf_features, service_names, app_id);
      BTA_AgRegister(get_BTIF_HF_SERVICES(), btif_hf_features, service_names,
                     app_id);
    }
    }
  } else {
  } else {
    /* De-register AG */
    /* De-register AG */