• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <cstdint>
18 
19 #define LOG_TAG "bt_shim"
20 
21 #include "common/message_loop_thread.h"
22 #include "main/shim/entry.h"
23 #include "main/shim/shim.h"
24 #include "osi/include/log.h"
25 #include "osi/include/properties.h"
26 
27 static const char* kPropertyKey = "bluetooth.gd.enabled";
28 
29 static bluetooth::common::MessageLoopThread bt_shim_thread("bt_shim_thread");
30 
31 static bool gd_shim_enabled_ = false;
32 static bool gd_shim_property_checked_ = false;
33 static bool gd_stack_started_up_ = false;
34 
ShimModuleStartUp()35 future_t* ShimModuleStartUp() {
36   bt_shim_thread.StartUp();
37   CHECK(bt_shim_thread.IsRunning())
38       << "Unable to start bt shim message loop thread.";
39   module_start_up(get_module(GD_SHIM_BTM_MODULE));
40   bluetooth::shim::StartGabeldorscheStack();
41   gd_stack_started_up_ = true;
42   return kReturnImmediate;
43 }
44 
ShimModuleShutDown()45 future_t* ShimModuleShutDown() {
46   gd_stack_started_up_ = false;
47   bluetooth::shim::StopGabeldorscheStack();
48   module_shut_down(get_module(GD_SHIM_BTM_MODULE));
49   bt_shim_thread.ShutDown();
50   return kReturnImmediate;
51 }
52 
53 EXPORT_SYMBOL extern const module_t gd_shim_module = {
54     .name = GD_SHIM_MODULE,
55     .init = kUnusedModuleApi,
56     .start_up = ShimModuleStartUp,
57     .shut_down = ShimModuleShutDown,
58     .clean_up = kUnusedModuleApi,
59     .dependencies = {kUnusedModuleDependencies}};
60 
Post(base::OnceClosure task)61 void bluetooth::shim::Post(base::OnceClosure task) {
62   bt_shim_thread.DoInThread(FROM_HERE, std::move(task));
63 }
64 
is_gd_shim_enabled()65 bool bluetooth::shim::is_gd_shim_enabled() {
66   if (!gd_shim_property_checked_) {
67     gd_shim_property_checked_ = true;
68     gd_shim_enabled_ = osi_property_get_bool(kPropertyKey, false);
69   }
70   return gd_shim_enabled_;
71 }
72 
is_gd_stack_started_up()73 bool bluetooth::shim::is_gd_stack_started_up() { return gd_stack_started_up_; }
74