Initial Entry for le advertising shim

Bug: 142501909
Test: Compiles
Change-Id: Iaf1cde67d0c3e92163495e883c76714cc7705b02
diff --git a/gd/shim/Android.bp b/gd/shim/Android.bp
index 4ef329d..ae85b94 100644
--- a/gd/shim/Android.bp
+++ b/gd/shim/Android.bp
@@ -1,6 +1,7 @@
 filegroup {
     name: "BluetoothShimSources",
     srcs: [
+            "advertising.cc",
             "controller.cc",
             "connectability.cc",
             "discoverability.cc",
diff --git a/gd/shim/advertising.cc b/gd/shim/advertising.cc
new file mode 100644
index 0000000..b7e0b4e
--- /dev/null
+++ b/gd/shim/advertising.cc
@@ -0,0 +1,61 @@
+/*
+ * 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.
+ */
+#define LOG_TAG "bt_gd_shim"
+
+#include <functional>
+#include <memory>
+
+#include "hci/address.h"
+#include "hci/hci_packets.h"
+#include "hci/le_advertising_manager.h"
+#include "module.h"
+#include "os/handler.h"
+#include "os/log.h"
+#include "shim/advertising.h"
+
+namespace bluetooth {
+namespace shim {
+
+struct Advertising::impl {
+  hci::LeAdvertisingManager* module_{nullptr};
+
+  impl(hci::LeAdvertisingManager* module);
+  ~impl();
+};
+
+const ModuleFactory Advertising::Factory = ModuleFactory([]() { return new Advertising(); });
+
+Advertising::impl::impl(hci::LeAdvertisingManager* advertising_manager) : module_(advertising_manager) {}
+
+Advertising::impl::~impl() {}
+
+/**
+ * Module methods
+ */
+void Advertising::ListDependencies(ModuleList* list) {
+  list->add<hci::LeAdvertisingManager>();
+}
+
+void Advertising::Start() {
+  pimpl_ = std::make_unique<impl>(GetDependency<hci::LeAdvertisingManager>());
+}
+
+void Advertising::Stop() {
+  pimpl_.reset();
+}
+
+}  // namespace shim
+}  // namespace bluetooth
diff --git a/gd/shim/advertising.h b/gd/shim/advertising.h
new file mode 100644
index 0000000..17c094a
--- /dev/null
+++ b/gd/shim/advertising.h
@@ -0,0 +1,46 @@
+/*
+ * 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
+
+#include <memory>
+#include <string>
+
+#include "module.h"
+#include "shim/iadvertising.h"
+
+namespace bluetooth {
+namespace shim {
+
+class Advertising : public bluetooth::Module, public bluetooth::shim::IAdvertising {
+ public:
+  Advertising() = default;
+  ~Advertising() = default;
+
+  static const ModuleFactory Factory;
+
+ protected:
+  void ListDependencies(ModuleList* list) override;  // Module
+  void Start() override;                             // Module
+  void Stop() override;                              // Module
+
+ private:
+  struct impl;
+  std::unique_ptr<impl> pimpl_;
+  DISALLOW_COPY_AND_ASSIGN(Advertising);
+};
+
+}  // namespace shim
+}  // namespace bluetooth
diff --git a/gd/shim/iadvertising.h b/gd/shim/iadvertising.h
new file mode 100644
index 0000000..85a75c6
--- /dev/null
+++ b/gd/shim/iadvertising.h
@@ -0,0 +1,29 @@
+/*
+ * 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
+
+/**
+ * The gd API exported to the legacy api
+ */
+namespace bluetooth {
+namespace shim {
+
+struct IAdvertising {
+  virtual ~IAdvertising() {}
+};
+
+}  // namespace shim
+}  // namespace bluetooth
diff --git a/gd/shim/istack.h b/gd/shim/istack.h
index af2b62d..37751a1 100644
--- a/gd/shim/istack.h
+++ b/gd/shim/istack.h
@@ -23,6 +23,7 @@
 namespace bluetooth {
 namespace shim {
 
+struct IAdvertising;
 struct IController;
 struct IConnectability;
 struct IDiscoverability;
@@ -35,6 +36,7 @@
   virtual void Start() = 0;
   virtual void Stop() = 0;
 
+  virtual IAdvertising* GetAdvertising() = 0;
   virtual IController* GetController() = 0;
   virtual IConnectability* GetConnectability() = 0;
   virtual IDiscoverability* GetDiscoverability() = 0;
diff --git a/gd/shim/only_include_this_file_into_legacy_stack___ever.h b/gd/shim/only_include_this_file_into_legacy_stack___ever.h
index bce2a66..3b07cfc 100644
--- a/gd/shim/only_include_this_file_into_legacy_stack___ever.h
+++ b/gd/shim/only_include_this_file_into_legacy_stack___ever.h
@@ -24,6 +24,7 @@
  * Only common data structures should be used to pass data between the stacks.
  *
  */
+#include "gd/shim/iadvertising.h"
 #include "gd/shim/iconnectability.h"
 #include "gd/shim/icontroller.h"
 #include "gd/shim/idiscoverability.h"
diff --git a/gd/shim/stack.cc b/gd/shim/stack.cc
index 8b02e6b..db0b774 100644
--- a/gd/shim/stack.cc
+++ b/gd/shim/stack.cc
@@ -20,6 +20,7 @@
 #include "hal/hci_hal.h"
 #include "hci/acl_manager.h"
 #include "hci/classic_security_manager.h"
+#include "hci/le_advertising_manager.h"
 #include "l2cap/classic/l2cap_classic_module.h"
 #include "l2cap/le/l2cap_le_module.h"
 #include "neighbor/connectability.h"
@@ -30,6 +31,7 @@
 #include "os/log.h"
 #include "os/thread.h"
 #include "security/security_module.h"
+#include "shim/advertising.h"
 #include "shim/connectability.h"
 #include "shim/controller.h"
 #include "shim/discoverability.h"
@@ -52,6 +54,7 @@
     ModuleList modules;
     modules.add<::bluetooth::hal::HciHal>();
     modules.add<::bluetooth::hci::AclManager>();
+    modules.add<::bluetooth::hci::LeAdvertisingManager>();
     modules.add<::bluetooth::l2cap::classic::L2capClassicModule>();
     modules.add<::bluetooth::l2cap::le::L2capLeModule>();
     modules.add<::bluetooth::neighbor::ConnectabilityModule>();
@@ -62,6 +65,7 @@
     modules.add<::bluetooth::shim::Controller>();
     modules.add<::bluetooth::shim::HciLayer>();
     modules.add<::bluetooth::security::SecurityModule>();
+    modules.add<::bluetooth::shim::Advertising>();
     modules.add<::bluetooth::shim::Connectability>();
     modules.add<::bluetooth::shim::Discoverability>();
     modules.add<::bluetooth::shim::Inquiry>();
@@ -88,6 +92,10 @@
     LOG_INFO("%s Successfully shut down Gd stack", __func__);
   }
 
+  IAdvertising* GetAdvertising() {
+    return stack_manager_.GetInstance<bluetooth::shim::Advertising>();
+  }
+
   IController* GetController() {
     return stack_manager_.GetInstance<bluetooth::shim::Controller>();
   }
@@ -135,6 +143,10 @@
   pimpl_->Stop();
 }
 
+bluetooth::shim::IAdvertising* bluetooth::shim::Stack::GetAdvertising() {
+  return pimpl_->GetAdvertising();
+}
+
 bluetooth::shim::IConnectability* bluetooth::shim::Stack::GetConnectability() {
   return pimpl_->GetConnectability();
 }
diff --git a/gd/shim/stack.h b/gd/shim/stack.h
index f56852a..dc35780 100644
--- a/gd/shim/stack.h
+++ b/gd/shim/stack.h
@@ -18,6 +18,7 @@
 
 #include <memory>
 
+#include "shim/iadvertising.h"
 #include "shim/iconnectability.h"
 #include "shim/icontroller.h"
 #include "shim/idiscoverability.h"
@@ -41,6 +42,7 @@
   void Start() override;  // IStack
   void Stop() override;   // IStack
 
+  IAdvertising* GetAdvertising() override;  // IStack
   IController* GetController() override;  // IStack
   IConnectability* GetConnectability() override;  // IStack
   IHciLayer* GetHciLayer() override;      // IStack
diff --git a/main/shim/test_stack.cc b/main/shim/test_stack.cc
index 5d4ede5..bd3b8ff 100644
--- a/main/shim/test_stack.cc
+++ b/main/shim/test_stack.cc
@@ -72,6 +72,8 @@
 
 void TestStack::Stop() {}
 
+bluetooth::shim::IAdvertising* TestStack::GetAdvertising() { return nullptr; }
+
 bluetooth::shim::IController* TestStack::GetController() { return nullptr; }
 
 bluetooth::shim::IConnectability* TestStack::GetConnectability() {
diff --git a/main/shim/test_stack.h b/main/shim/test_stack.h
index ee0986a..23b90cd 100644
--- a/main/shim/test_stack.h
+++ b/main/shim/test_stack.h
@@ -54,6 +54,7 @@
  public:
   TestStack() = default;
 
+  bluetooth::shim::IAdvertising* GetAdvertising();
   bluetooth::shim::IController* GetController();
   bluetooth::shim::IConnectability* GetConnectability();
   bluetooth::shim::IDiscoverability* GetDiscoverability();