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

Commit 6c8ff0ca authored by William Escande's avatar William Escande
Browse files

Flagging: Wrap static flag usage

Provide macro to use static flag while not having to deal with floss not
supporting it.
Usage is like follow:
      #include <android_bluetooth_flags.h>
      if (IS_ENABLED(myStaticFlag)) {
        // new code
      }

Bug: 309697497
Fix: 309697497
Test: m Bluetooth | build change does not impact device code
Change-Id: I660b8e772b36b261da534d918a2d6f46e8ed3863
parent 000e876a
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -36,6 +36,7 @@ java_aconfig_library {
cc_aconfig_library {
cc_aconfig_library {
    name: "bluetooth_flags_c_lib",
    name: "bluetooth_flags_c_lib",
    aconfig_declarations: "bluetooth_aconfig_flags",
    aconfig_declarations: "bluetooth_aconfig_flags",
    export_include_dirs: ["exported_include"],
    host_supported: true,
    host_supported: true,
    visibility: [
    visibility: [
        "//packages/modules/Bluetooth/system:__subpackages__",
        "//packages/modules/Bluetooth/system:__subpackages__",
+30 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#ifndef TARGET_FLOSS

#include <com_android_bluetooth_flags.h>

#define IS_FLAG_ENABLED(flag_name) com::android::bluetooth::flags::flag_name()

#else

// FLOSS does not yet support android aconfig flags
#define IS_FLAG_ENABLED(flag_name) false

#endif
+1 −0
Original line number Original line Diff line number Diff line
@@ -75,6 +75,7 @@ if (defined(use.android) && use.android) {
config("target_defaults") {
config("target_defaults") {
  include_dirs = [
  include_dirs = [
    "//bt/system",
    "//bt/system",
    "//bt/flags/exported_include",
    "//bt/system/linux_include",
    "//bt/system/linux_include",
    "//bt/system/types",
    "//bt/system/types",
    "//bt/system/include",
    "//bt/system/include",
+2 −10
Original line number Original line Diff line number Diff line
@@ -15,11 +15,9 @@
 * limitations under the License.
 * limitations under the License.
 */
 */


#include <android_bluetooth_flags.h>
#include <base/functional/bind.h>
#include <base/functional/bind.h>
#include <base/strings/string_number_conversions.h>
#include <base/strings/string_number_conversions.h>
#ifndef TARGET_FLOSS
#include <com_android_bluetooth_flags.h>
#endif
#include <lc3.h>
#include <lc3.h>


#include <deque>
#include <deque>
@@ -166,11 +164,9 @@ std::ostream& operator<<(std::ostream& os, const AudioState& audio_state) {
namespace {
namespace {
void le_audio_gattc_callback(tBTA_GATTC_EVT event, tBTA_GATTC* p_data);
void le_audio_gattc_callback(tBTA_GATTC_EVT event, tBTA_GATTC* p_data);


#ifndef TARGET_FLOSS
static void le_audio_health_status_callback(const RawAddress& addr,
static void le_audio_health_status_callback(const RawAddress& addr,
                                            int group_id,
                                            int group_id,
                                            LeAudioHealthBasedAction action);
                                            LeAudioHealthBasedAction action);
#endif


class LeAudioClientImpl;
class LeAudioClientImpl;
LeAudioClientImpl* instance;
LeAudioClientImpl* instance;
@@ -254,14 +250,12 @@ class LeAudioClientImpl : public LeAudioClient {
      reconnection_mode_ = BTM_BLE_BKG_CONNECT_ALLOW_LIST;
      reconnection_mode_ = BTM_BLE_BKG_CONNECT_ALLOW_LIST;
    }
    }


#ifndef TARGET_FLOSS
    if (IS_FLAG_ENABLED(leaudio_enable_health_based_actions)) {
    if (com::android::bluetooth::flags::leaudio_enable_health_based_actions()) {
      LOG_INFO("Loading health status module");
      LOG_INFO("Loading health status module");
      leAudioHealthStatus_ = LeAudioHealthStatus::Get();
      leAudioHealthStatus_ = LeAudioHealthStatus::Get();
      leAudioHealthStatus_->RegisterCallback(
      leAudioHealthStatus_->RegisterCallback(
          base::BindRepeating(le_audio_health_status_callback));
          base::BindRepeating(le_audio_health_status_callback));
    }
    }
#endif


    BTA_GATTC_AppRegister(
    BTA_GATTC_AppRegister(
        le_audio_gattc_callback,
        le_audio_gattc_callback,
@@ -5477,7 +5471,6 @@ class LeAudioClientImpl : public LeAudioClient {
  }
  }
};
};


#ifndef TARGET_FLOSS
static void le_audio_health_status_callback(const RawAddress& addr,
static void le_audio_health_status_callback(const RawAddress& addr,
                                            int group_id,
                                            int group_id,
                                            LeAudioHealthBasedAction action) {
                                            LeAudioHealthBasedAction action) {
@@ -5485,7 +5478,6 @@ static void le_audio_health_status_callback(const RawAddress& addr,
    instance->LeAudioHealthSendRecommendation(addr, group_id, action);
    instance->LeAudioHealthSendRecommendation(addr, group_id, action);
  }
  }
}
}
#endif


/* This is a generic callback method for gatt client which handles every client
/* This is a generic callback method for gatt client which handles every client
 * application events.
 * application events.
+2 −7
Original line number Original line Diff line number Diff line
@@ -17,12 +17,10 @@


#include "state_machine.h"
#include "state_machine.h"


#include <android_bluetooth_flags.h>
#include <base/functional/bind.h>
#include <base/functional/bind.h>
#include <base/functional/callback.h>
#include <base/functional/callback.h>
#include <base/strings/string_number_conversions.h>
#include <base/strings/string_number_conversions.h>
#ifndef TARGET_FLOSS
#include <com_android_bluetooth_flags.h>
#endif


#include "bta_gatt_queue.h"
#include "bta_gatt_queue.h"
#include "btm_iso_api.h"
#include "btm_iso_api.h"
@@ -307,9 +305,7 @@ class LeAudioGroupStateMachineImpl : public LeAudioGroupStateMachine {


  void notifyLeAudioHealth(LeAudioDeviceGroup* group,
  void notifyLeAudioHealth(LeAudioDeviceGroup* group,
                           le_audio::LeAudioHealthGroupStatType stat) {
                           le_audio::LeAudioHealthGroupStatType stat) {
#ifndef TARGET_FLOSS
    if (!IS_FLAG_ENABLED(leaudio_enable_health_based_actions)) {
    if (!com::android::bluetooth::flags::
            leaudio_enable_health_based_actions()) {
      return;
      return;
    }
    }


@@ -317,7 +313,6 @@ class LeAudioGroupStateMachineImpl : public LeAudioGroupStateMachine {
    if (leAudioHealthStatus) {
    if (leAudioHealthStatus) {
      leAudioHealthStatus->AddStatisticForGroup(group, stat);
      leAudioHealthStatus->AddStatisticForGroup(group, stat);
    }
    }
#endif
  }
  }


  void ProcessGattCtpNotification(LeAudioDeviceGroup* group, uint8_t* value,
  void ProcessGattCtpNotification(LeAudioDeviceGroup* group, uint8_t* value,