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

Commit f9f563f5 authored by Zach Johnson's avatar Zach Johnson Committed by Gerrit Code Review
Browse files

Merge "Add InitFlags and pipe down from java"

parents e612afa2 8ba246ee
Loading
Loading
Loading
Loading
+4 −6
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@
#include "common/metric_id_allocator.h"
#include "common/metrics.h"
#include "device/include/interop.h"
#include "gd/common/init_flags.h"
#include "main/shim/dumpsys.h"
#include "main/shim/shim.h"
#include "osi/include/alarm.h"
@@ -140,15 +141,12 @@ static bool is_profile(const char* p1, const char* p2) {
 ****************************************************************************/

static int init(bt_callbacks_t* callbacks, bool start_restricted,
                bool is_niap_mode, int config_compare_result) {
                bool is_niap_mode, int config_compare_result,
                const char** init_flags) {
  LOG_INFO("%s: start restricted = %d ; niap = %d, config compare result = %d",
           __func__, start_restricted, is_niap_mode, config_compare_result);

  if (bluetooth::shim::is_gd_shim_enabled()) {
    LOG_INFO("%s Enable Gd bluetooth functionality", __func__);
  } else {
    LOG_INFO("%s Preserving legacy bluetooth functionality", __func__);
  }
  bluetooth::common::InitFlags::Load(init_flags);

  if (interface_ready()) return BT_STATUS_DONE;

+2 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ filegroup {
    name: "BluetoothCommonSources",
    srcs: [
        "link_key.cc",
        "init_flags.cc",
    ],
}

@@ -12,5 +13,6 @@ filegroup {
        "bidi_queue_unittest.cc",
        "observer_registry_test.cc",
        "link_key_unittest.cc",
        "init_flags_test.cc",
    ],
}
+44 −0
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 <string>

#include "os/log.h"

namespace bluetooth {
namespace common {

const std::string kGdCoreFlag = "INIT_gd_core";
bool InitFlags::gd_core_enabled = false;

void InitFlags::Load(const char** flags) {
  gd_core_enabled = false;
  while (flags != nullptr && *flags != nullptr) {
    if (kGdCoreFlag == *flags) {
      gd_core_enabled = true;
    }
    flags++;
  }

  LOG_INFO("Flags loaded: gd_core_enabled: %s", gd_core_enabled ? "true" : "false");
}

}  // namespace common
}  // namespace bluetooth
+35 −0
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.
 */

#pragma once

namespace bluetooth {
namespace common {

class InitFlags final {
 public:
  static void Load(const char** flags);

  static bool GdCoreEnabled() {
    return gd_core_enabled;
  }

 private:
  static bool gd_core_enabled;
};

}  // namespace common
}  // namespace bluetooth
+46 −0
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 "common/init_flags.h"

#include <gtest/gtest.h>

using bluetooth::common::InitFlags;

TEST(InitFlagsTest, test_load_nullptr) {
  InitFlags::Load(nullptr);
  ASSERT_EQ(false, InitFlags::GdCoreEnabled());
}

TEST(InitFlagsTest, test_load_empty) {
  const char* input[] = {nullptr};
  InitFlags::Load(input);
  ASSERT_EQ(false, InitFlags::GdCoreEnabled());
}

TEST(InitFlagsTest, test_load_garbage) {
  const char* input[] = {"some random non-existent flag", nullptr};
  InitFlags::Load(input);
  ASSERT_EQ(false, InitFlags::GdCoreEnabled());
}

TEST(InitFlagsTest, test_load_good_case) {
  const char* input[] = {"INIT_gd_core", nullptr};
  InitFlags::Load(input);
  ASSERT_EQ(true, InitFlags::GdCoreEnabled());
}
Loading