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

Commit 1be97a1f authored by Rahul Arya's avatar Rahul Arya Committed by Android (Google) Code Review
Browse files

Merge changes Ifa570dd8,Id7367461,Id5f60e7a,I0244c598,I317db266 into tm-qpr-dev

* changes:
  init_flags small fixup
  Clear init_flags dumpsys and add lint
  GD: use one source as init_flag
  GD Rust: init_flag add remaining flags types
  GD: Init flags default in native
parents 70e2a974 cdbb7c55
Loading
Loading
Loading
Loading
+8 −115
Original line number Diff line number Diff line
@@ -5163,123 +5163,16 @@ public class AdapterService extends Service {
        }
    }

    // Boolean flags
    private static final String SDP_SKIP_RNR_IF_KNOWN = "INIT_sdp_skip_rnr_if_known";
    private static final String SDP_SERIALIZATION_FLAG = "INIT_sdp_serialization";
    private static final String GD_CORE_FLAG = "INIT_gd_core";
    private static final String GD_ADVERTISING_FLAG = "INIT_gd_advertising";
    private static final String GD_SCANNING_FLAG = "INIT_gd_scanning";
    private static final String GD_HCI_FLAG = "INIT_gd_hci";
    private static final String GD_CONTROLLER_FLAG = "INIT_gd_controller";
    private static final String GD_ACL_FLAG = "INIT_gd_acl";
    private static final String GD_L2CAP_FLAG = "INIT_gd_l2cap";
    private static final String GD_RUST_FLAG = "INIT_gd_rust";
    private static final String GD_LINK_POLICY_FLAG = "INIT_gd_link_policy";
    private static final String GATT_ROBUST_CACHING_CLIENT_FLAG = "INIT_gatt_robust_caching_client";
    private static final String GATT_ROBUST_CACHING_SERVER_FLAG = "INIT_gatt_robust_caching_server";
    private static final String IRK_ROTATION_FLAG = "INIT_irk_rotation";
    private static final String PASS_PHY_UPDATE_CALLBACK_FLAG = "INIT_pass_phy_update_callback";
    private static final String BTM_DM_FLUSH_DISCOVERY_QUEUE_ON_SEARCH_CANCEL =
                                    "INIT_btm_dm_flush_discovery_queue_on_search_cancel";

    /**
     * Logging flags logic (only applies to DEBUG and VERBOSE levels):
     * if LOG_TAG in LOGGING_DEBUG_DISABLED_FOR_TAGS_FLAG:
     *   DO NOT LOG
     * else if LOG_TAG in LOGGING_DEBUG_ENABLED_FOR_TAGS_FLAG:
     *   DO LOG
     * else if LOGGING_DEBUG_ENABLED_FOR_ALL_FLAG:
     *   DO LOG
     * else:
     *   DO NOT LOG
     */
    private static final String LOGGING_DEBUG_ENABLED_FOR_ALL_FLAG =
            "INIT_logging_debug_enabled_for_all";
    // String flags
    // Comma separated tags
    private static final String LOGGING_DEBUG_ENABLED_FOR_TAGS_FLAG =
            "INIT_logging_debug_enabled_for_tags";
    private static final String LOGGING_DEBUG_DISABLED_FOR_TAGS_FLAG =
            "INIT_logging_debug_disabled_for_tags";
    private static final String BTAA_HCI_LOG_FLAG = "INIT_btaa_hci";

    @RequiresPermission(android.Manifest.permission.READ_DEVICE_CONFIG)
    private String[] getInitFlags() {
        final DeviceConfig.Properties properties =
                DeviceConfig.getProperties(DeviceConfig.NAMESPACE_BLUETOOTH);
        ArrayList<String> initFlags = new ArrayList<>();
        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH, GD_CORE_FLAG, false)) {
            initFlags.add(String.format("%s=%s", GD_CORE_FLAG, "true"));
        }
        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH,
                    SDP_SKIP_RNR_IF_KNOWN, true)) {
            initFlags.add(String.format("%s=%s", SDP_SKIP_RNR_IF_KNOWN, "true"));
        }
        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH,
                    SDP_SERIALIZATION_FLAG, true)) {
            initFlags.add(String.format("%s=%s", SDP_SERIALIZATION_FLAG, "true"));
        }
        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH, GD_ADVERTISING_FLAG, false)) {
            initFlags.add(String.format("%s=%s", GD_ADVERTISING_FLAG, "true"));
        }
        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH, GD_SCANNING_FLAG,
                Config.isGdEnabledUpToScanningLayer())) {
            initFlags.add(String.format("%s=%s", GD_SCANNING_FLAG, "true"));
        }
        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH, GD_HCI_FLAG, false)) {
            initFlags.add(String.format("%s=%s", GD_HCI_FLAG, "true"));
        }
        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH, GD_CONTROLLER_FLAG, false)) {
            initFlags.add(String.format("%s=%s", GD_CONTROLLER_FLAG, "true"));
        }
        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH, GD_ACL_FLAG, false)) {
            initFlags.add(String.format("%s=%s", GD_ACL_FLAG, "true"));
        }
        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH, GD_L2CAP_FLAG, false)) {
            initFlags.add(String.format("%s=%s", GD_L2CAP_FLAG, "true"));
        }
        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH, GD_RUST_FLAG, false)) {
            initFlags.add(String.format("%s=%s", GD_RUST_FLAG, "true"));
        }
        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH, GD_LINK_POLICY_FLAG, false)) {
            initFlags.add(String.format("%s=%s", GD_LINK_POLICY_FLAG, "true"));
        }
        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH,
                GATT_ROBUST_CACHING_CLIENT_FLAG, true)) {
            initFlags.add(String.format("%s=%s", GATT_ROBUST_CACHING_CLIENT_FLAG, "true"));
        }
        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH,
                GATT_ROBUST_CACHING_SERVER_FLAG, false)) {
            initFlags.add(String.format("%s=%s", GATT_ROBUST_CACHING_SERVER_FLAG, "true"));
        }
        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH, IRK_ROTATION_FLAG, false)) {
            initFlags.add(String.format("%s=%s", IRK_ROTATION_FLAG, "true"));
        }
        if (DeviceConfig.getBoolean(
                DeviceConfig.NAMESPACE_BLUETOOTH, PASS_PHY_UPDATE_CALLBACK_FLAG, true)) {
            initFlags.add(String.format("%s=%s", PASS_PHY_UPDATE_CALLBACK_FLAG, "true"));
        }
        if (DeviceConfig.getBoolean(
                DeviceConfig.NAMESPACE_BLUETOOTH,
                BTM_DM_FLUSH_DISCOVERY_QUEUE_ON_SEARCH_CANCEL, false)) {
            initFlags.add(String.format("%s=%s",
                    BTM_DM_FLUSH_DISCOVERY_QUEUE_ON_SEARCH_CANCEL, "true"));
        }
        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH,
                LOGGING_DEBUG_ENABLED_FOR_ALL_FLAG, false)) {
            initFlags.add(String.format("%s=%s", LOGGING_DEBUG_ENABLED_FOR_ALL_FLAG, "true"));
        }
        String debugLoggingEnabledTags = DeviceConfig.getString(DeviceConfig.NAMESPACE_BLUETOOTH,
                LOGGING_DEBUG_ENABLED_FOR_TAGS_FLAG, "");
        if (!debugLoggingEnabledTags.isEmpty()) {
            initFlags.add(String.format("%s=%s", LOGGING_DEBUG_ENABLED_FOR_TAGS_FLAG,
                    debugLoggingEnabledTags));
        }
        String debugLoggingDisabledTags = DeviceConfig.getString(DeviceConfig.NAMESPACE_BLUETOOTH,
                LOGGING_DEBUG_DISABLED_FOR_TAGS_FLAG, "");
        if (!debugLoggingDisabledTags.isEmpty()) {
            initFlags.add(String.format("%s=%s", LOGGING_DEBUG_DISABLED_FOR_TAGS_FLAG,
                    debugLoggingDisabledTags));
        for (String property: properties.getKeyset()) {
            if (property.startsWith("INIT_")) {
                initFlags.add(String.format("%s=%s", property,
                            properties.getString(property, null)));
            }
        if (DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_BLUETOOTH, BTAA_HCI_LOG_FLAG, true)) {
            initFlags.add(String.format("%s=%s", BTAA_HCI_LOG_FLAG, "true"));
        }
        return initFlags.toArray(new String[0]);
    }
+0 −1
Original line number Diff line number Diff line
@@ -11,7 +11,6 @@ filegroup {
    name: "BluetoothCommonSources",
    srcs: [
        "audit_log.cc",
        "init_flags.cc",
        "metric_id_manager.cc",
        "strings.cc",
        "stop_watch.cc",
+0 −1
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
source_set("BluetoothCommonSources") {
  sources = [
    "audit_log.cc",
    "init_flags.cc",
    "metric_id_manager.cc",
    "stop_watch.cc",
    "strings.cc",

system/gd/common/init_flags.cc

deleted100644 → 0
+0 −128
Original line number Diff line number Diff line
/******************************************************************************
 *
 *  Copyright 2019 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.
 *
 ******************************************************************************/

#include "init_flags.h"

#include <cstdlib>
#include <string>

#include "common/strings.h"
#include "os/log.h"

namespace bluetooth {
namespace common {

bool InitFlags::logging_debug_enabled_for_all = false;
int InitFlags::hci_adapter = 0;
std::unordered_map<std::string, bool> InitFlags::logging_debug_explicit_tag_settings = {};
bool InitFlags::btm_dm_flush_discovery_queue_on_search_cancel = false;

bool ParseBoolFlag(const std::vector<std::string>& flag_pair, const std::string& flag, bool* variable) {
  if (flag != flag_pair[0]) {
    return false;
  }
  auto value = BoolFromString(flag_pair[1]);
  if (!value) {
    return false;
  }
  *variable = *value;
  return true;
}

bool ParseIntFlag(const std::vector<std::string>& flag_pair, const std::string& flag, int* variable) {
  if (flag != flag_pair[0]) {
    return false;
  }
  auto value = Int64FromString(flag_pair[1]);
  if (!value || *value > INT32_MAX) {
    return false;
  }

  *variable = *value;
  return true;
}

void InitFlags::Load(const char** flags) {
  const char** flags_copy = flags;
  SetAll(false);
  while (flags != nullptr && *flags != nullptr) {
    std::string flag_element = *flags;
    auto flag_pair = StringSplit(flag_element, "=", 2);
    if (flag_pair.size() != 2) {
      flags++;
      continue;
    }

    // Parse adapter index (defaults to 0)
    ParseIntFlag(flag_pair, "--hci", &hci_adapter);

    ParseBoolFlag(
        flag_pair,
        "INIT_btm_dm_flush_discovery_queue_on_search_cancel",
        &btm_dm_flush_discovery_queue_on_search_cancel);

    ParseBoolFlag(flag_pair, "INIT_logging_debug_enabled_for_all", &logging_debug_enabled_for_all);
    if ("INIT_logging_debug_enabled_for_tags" == flag_pair[0]) {
      auto tags = StringSplit(flag_pair[1], ",");
      for (const auto& tag : tags) {
        auto setting = logging_debug_explicit_tag_settings.find(tag);
        if (setting == logging_debug_explicit_tag_settings.end()) {
          logging_debug_explicit_tag_settings.insert_or_assign(tag, true);
        }
      }
    }
    if ("INIT_logging_debug_disabled_for_tags" == flag_pair[0]) {
      auto tags = StringSplit(flag_pair[1], ",");
      for (const auto& tag : tags) {
        logging_debug_explicit_tag_settings.insert_or_assign(tag, false);
      }
    }
    flags++;
  }

  std::vector<std::string> logging_debug_enabled_tags;
  std::vector<std::string> logging_debug_disabled_tags;
  for (const auto& tag_setting : logging_debug_explicit_tag_settings) {
    if (tag_setting.second) {
      logging_debug_enabled_tags.emplace_back(tag_setting.first);
    } else {
      logging_debug_disabled_tags.emplace_back(tag_setting.first);
    }
  }

  flags = flags_copy;
  rust::Vec<rust::String> rusted_flags = rust::Vec<rust::String>();
  while (flags != nullptr && *flags != nullptr) {
    rusted_flags.push_back(rust::String(*flags));
    flags++;
  }
  init_flags::load(std::move(rusted_flags));
}

void InitFlags::SetAll(bool value) {
  logging_debug_enabled_for_all = value;
  logging_debug_explicit_tag_settings.clear();
}

void InitFlags::SetAllForTesting() {
  init_flags::set_all_for_testing();
  SetAll(true);
}

}  // namespace common
}  // namespace bluetooth
+19 −4
Original line number Diff line number Diff line
@@ -2,18 +2,33 @@ namespace bluetooth.common;

attribute "privacy";

// LINT.IfChange
table InitFlagsData {
    title:string (privacy:"Any");
    // Legacy flags
    gd_advertising_enabled:bool (privacy:"Any");
    gd_scanning_enabled:bool (privacy:"Any");
    gd_security_enabled:bool (privacy:"Any");
    gd_acl_enabled:bool (privacy:"Any");
    gd_hci_enabled:bool (privacy:"Any");
    gd_controller_enabled:bool (privacy:"Any");
    gd_core_enabled:bool (privacy:"Any");
    btaa_hci_log_enabled:bool (privacy:"Any");
    btm_dm_flush_discovery_queue_on_search_cancel:bool (privacy:"Any");
    btaa_hci_is_enabled:bool (privacy:"Any");
    btm_dm_flush_discovery_queue_on_search_cancel_is_enabled:bool (privacy:"Any");
    gatt_robust_caching_client_is_enabled:bool (privacy:"Any");
    gatt_robust_caching_server_is_enabled:bool (privacy:"Any");
    gd_core_is_enabled:bool (privacy:"Any");
    gd_l2cap_is_enabled:bool (privacy:"Any");
    gd_link_policy_is_enabled:bool (privacy:"Any");
    gd_remote_name_request_is_enabled:bool (privacy:"Any");
    gd_rust_is_enabled:bool (privacy:"Any");
    gd_security_is_enabled:bool (privacy:"Any");
    get_hci_adapter:int (privacy:"Any");
    irk_rotation_is_enabled:bool (privacy:"Any");
    // is_debug_logging_enabled_for_tag -- skipped in dumpsys
    logging_debug_enabled_for_all_is_enabled:bool (privacy:"Any");
    pass_phy_update_callback_is_enabled:bool (privacy:"Any");
    sdp_serialization_is_enabled:bool (privacy:"Any");
    sdp_skip_rnr_if_known_is_enabled:bool (privacy:"Any");
}
// LINT.ThenChange(/system/gd/dumpsys/init_flags.cc)

root_type InitFlagsData;
Loading