OSDN Git Service

Remove redundant Bluetooth from internal class names
authorZach Johnson <zachoverflow@google.com>
Mon, 29 Apr 2019 19:07:23 +0000 (12:07 -0700)
committerHansong Zhang <hsz@google.com>
Mon, 29 Apr 2019 20:49:11 +0000 (13:49 -0700)
Test: atest --host bluetooth_test_gd and ./cert/run_cert.sh
Change-Id: I55b2c1ecc1ec254a197d6fde70968a9aa8c06c00

gd/hal/Android.bp
gd/hal/facade/facade.cc
gd/hal/hci_hal.h
gd/hal/hci_hal_android_hidl.cc
gd/hal/hci_hal_android_hidl_test.cc
gd/hal/hci_hal_host_rootcanal.cc
gd/hal/hci_hal_host_rootcanal_test.cc
gd/hal/snoop_logger.cc [moved from gd/hal/bluetooth_snoop_logger.cc with 94% similarity]
gd/hal/snoop_logger.h [moved from gd/hal/bluetooth_snoop_logger.h with 92% similarity]

index 8dd4eaa..cb4ca82 100644 (file)
@@ -1,7 +1,7 @@
 filegroup {
     name: "BluetoothHalSources",
     srcs: [
-        "bluetooth_snoop_logger.cc",
+        "snoop_logger.cc",
     ],
 }
 
index 7542931..815ff8f 100644 (file)
@@ -37,9 +37,9 @@ namespace facade {
 
 class HciTransportationService
     : public HciTransportation::Service,
-      public ::bluetooth::hal::BluetoothHciHalCallbacks {
+      public ::bluetooth::hal::HciHalCallbacks {
  public:
-  HciTransportationService(BluetoothHciHal* hal) : hal_(hal) {
+  HciTransportationService(HciHal* hal) : hal_(hal) {
   }
 
   ::grpc::Status SetLoopbackMode(::grpc::ServerContext* context,
@@ -88,17 +88,17 @@ class HciTransportationService
     // TODO
   }
  private:
-  BluetoothHciHal* hal_;
+  HciHal* hal_;
 };
 
 void HalFacadeModule::ListDependencies(ModuleList* list) {
   ::bluetooth::grpc::GrpcFacadeModule::ListDependencies(list);
-  list->add<BluetoothHciHal>();
+  list->add<HciHal>();
 }
 
 void HalFacadeModule::Start(const ModuleRegistry* registry) {
   ::bluetooth::grpc::GrpcFacadeModule::Start(registry);
-  auto hal = registry->GetInstance<BluetoothHciHal>();
+  auto hal = registry->GetInstance<HciHal>();
 
   service_ = new HciTransportationService(hal);
   hal->registerIncomingPacketCallback(service_);
index b8d6849..88c0d9e 100644 (file)
@@ -31,9 +31,9 @@ enum class Status : int32_t { SUCCESS, TRANSPORT_ERROR, INITIALIZATION_ERROR, UN
 // callback to BluetoothInitializationCompleteCallback
 
 // The interface from the Bluetooth Controller to the stack
-class BluetoothHciHalCallbacks {
+class HciHalCallbacks {
  public:
-  virtual ~BluetoothHciHalCallbacks() = default;
+  virtual ~HciHalCallbacks() = default;
 
   // This function is invoked when an HCI event is received from the
   // Bluetooth controller to be forwarded to the Bluetooth stack
@@ -56,11 +56,11 @@ class BluetoothHciHalCallbacks {
 // Abstraction Layer (HAL). Dealing only in HCI packets and events simplifies
 // the stack and abstracts away power management, initialization, and other
 // implementation-specific details related to the hardware.
-class BluetoothHciHal : public ::bluetooth::Module {
+class HciHal : public ::bluetooth::Module {
  public:
   static const ModuleFactory Factory;
 
-  virtual ~BluetoothHciHal() = default;
+  virtual ~HciHal() = default;
 
   // Register the callback for incoming packets. All incoming packets are dropped before
   // this callback is registered. Callback can only be registered once, but will be reset
@@ -71,7 +71,7 @@ class BluetoothHciHal : public ::bluetooth::Module {
   // @param callback implements BluetoothHciHalCallbacks which will
   //    receive callbacks when incoming HCI packets are received
   //    from the controller to be sent to the host.
-  virtual void registerIncomingPacketCallback(BluetoothHciHalCallbacks* callback) = 0;
+  virtual void registerIncomingPacketCallback(HciHalCallbacks* callback) = 0;
 
   // Send an HCI command (as specified in the Bluetooth Specification
   // V4.2, Vol 2, Part 5, Section 5.4.1) to the Bluetooth controller.
index 0c2b56f..ca24746 100644 (file)
@@ -24,7 +24,7 @@
 #include <android/hardware/bluetooth/1.0/IBluetoothHciCallbacks.h>
 #include <android/hardware/bluetooth/1.0/types.h>
 
-#include "hal/bluetooth_snoop_logger.h"
+#include "hal/snoop_logger.h"
 #include "os/log.h"
 
 using ::android::hardware::hidl_vec;
@@ -39,7 +39,7 @@ namespace hal {
 namespace {
 constexpr char kDefaultBtsnoopPath[] = "/data/misc/bluetooth/logs/btsnoop_hci.log";
 
-class BluetoothHciDeathRecipient : public ::android::hardware::hidl_death_recipient {
+class HciDeathRecipient : public ::android::hardware::hidl_death_recipient {
  public:
   virtual void serviceDied(uint64_t /*cookie*/, const android::wp<::android::hidl::base::V1_0::IBase>& /*who*/) {
     LOG_ERROR("Bluetooth HAL service died!");
@@ -47,16 +47,16 @@ class BluetoothHciDeathRecipient : public ::android::hardware::hidl_death_recipi
   }
 };
 
-android::sp<BluetoothHciDeathRecipient> bluetooth_hci_death_recipient_ = new BluetoothHciDeathRecipient();
+android::sp<HciDeathRecipient> hci_death_recipient_ = new HciDeathRecipient();
 
-class HciHalBluetoothHciCallbacks : public IBluetoothHciCallbacks {
+class InternalHciCallbacks : public IBluetoothHciCallbacks {
  public:
-  HciHalBluetoothHciCallbacks(BluetoothSnoopLogger* btsnoop_logger)
+  InternalHciCallbacks(SnoopLogger* btsnoop_logger)
       : btsnoop_logger_(btsnoop_logger) {
     init_promise_ = new std::promise<void>();
   }
 
-  void SetCallback(BluetoothHciHalCallbacks* callback) {
+  void SetCallback(HciHalCallbacks* callback) {
     ASSERT(callback_ == nullptr && callback != nullptr);
     callback_ = callback;
   }
@@ -77,8 +77,8 @@ class HciHalBluetoothHciCallbacks : public IBluetoothHciCallbacks {
 
   Return<void> hciEventReceived(const hidl_vec<uint8_t>& event) {
     std::vector<uint8_t> received_hci_packet(event.begin(), event.end());
-    btsnoop_logger_->capture(received_hci_packet, BluetoothSnoopLogger::Direction::INCOMING,
-                             BluetoothSnoopLogger::PacketType::EVT);
+    btsnoop_logger_->capture(received_hci_packet, SnoopLogger::Direction::INCOMING,
+                             SnoopLogger::PacketType::EVT);
     if (callback_ != nullptr) {
       callback_->hciEventReceived(std::move(received_hci_packet));
     }
@@ -87,8 +87,8 @@ class HciHalBluetoothHciCallbacks : public IBluetoothHciCallbacks {
 
   Return<void> aclDataReceived(const hidl_vec<uint8_t>& data) {
     std::vector<uint8_t> received_hci_packet(data.begin(), data.end());
-    btsnoop_logger_->capture(received_hci_packet, BluetoothSnoopLogger::Direction::INCOMING,
-                             BluetoothSnoopLogger::PacketType::ACL);
+    btsnoop_logger_->capture(received_hci_packet, SnoopLogger::Direction::INCOMING,
+                             SnoopLogger::PacketType::ACL);
     if (callback_ != nullptr) {
       callback_->aclDataReceived(std::move(received_hci_packet));
     }
@@ -97,8 +97,8 @@ class HciHalBluetoothHciCallbacks : public IBluetoothHciCallbacks {
 
   Return<void> scoDataReceived(const hidl_vec<uint8_t>& data) {
     std::vector<uint8_t> received_hci_packet(data.begin(), data.end());
-    btsnoop_logger_->capture(received_hci_packet, BluetoothSnoopLogger::Direction::INCOMING,
-                             BluetoothSnoopLogger::PacketType::SCO);
+    btsnoop_logger_->capture(received_hci_packet, SnoopLogger::Direction::INCOMING,
+                             SnoopLogger::PacketType::SCO);
     if (callback_ != nullptr) {
       callback_->scoDataReceived(std::move(received_hci_packet));
     }
@@ -107,30 +107,30 @@ class HciHalBluetoothHciCallbacks : public IBluetoothHciCallbacks {
 
  private:
   std::promise<void>* init_promise_ = nullptr;
-  BluetoothHciHalCallbacks* callback_ = nullptr;
-  BluetoothSnoopLogger* btsnoop_logger_ = nullptr;
+  HciHalCallbacks* callback_ = nullptr;
+  SnoopLogger* btsnoop_logger_ = nullptr;
 };
 
 }  // namespace
 
-class BluetoothHciHalHidl : public BluetoothHciHal {
+class HciHalHidl : public HciHal {
  public:
-  void registerIncomingPacketCallback(BluetoothHciHalCallbacks* callback) override {
+  void registerIncomingPacketCallback(HciHalCallbacks* callback) override {
     callbacks_->SetCallback(callback);
   }
 
   void sendHciCommand(HciPacket command) override {
-    btsnoop_logger_->capture(command, BluetoothSnoopLogger::Direction::OUTGOING, BluetoothSnoopLogger::PacketType::CMD);
+    btsnoop_logger_->capture(command, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::CMD);
     bt_hci_->sendHciCommand(command);
   }
 
   void sendAclData(HciPacket packet) override {
-    btsnoop_logger_->capture(packet, BluetoothSnoopLogger::Direction::OUTGOING, BluetoothSnoopLogger::PacketType::ACL);
+    btsnoop_logger_->capture(packet, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::ACL);
     bt_hci_->sendAclData(packet);
   }
 
   void sendScoData(HciPacket packet) override {
-    btsnoop_logger_->capture(packet, BluetoothSnoopLogger::Direction::OUTGOING, BluetoothSnoopLogger::PacketType::SCO);
+    btsnoop_logger_->capture(packet, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::SCO);
     bt_hci_->sendScoData(packet);
   }
 
@@ -140,14 +140,14 @@ class BluetoothHciHalHidl : public BluetoothHciHal {
   }
 
   void Start(const ModuleRegistry* registry) override {
-    btsnoop_logger_ = new BluetoothSnoopLogger(kDefaultBtsnoopPath);
+    btsnoop_logger_ = new SnoopLogger(kDefaultBtsnoopPath);
     bt_hci_ = IBluetoothHci::getService();
     ASSERT(bt_hci_ != nullptr);
-    auto death_link = bt_hci_->linkToDeath(bluetooth_hci_death_recipient_, 0);
+    auto death_link = bt_hci_->linkToDeath(hci_death_recipient_, 0);
     ASSERT_LOG(death_link.isOk(), "Unable to set the death recipient for the Bluetooth HAL");
     // Block allows allocation of a variable that might be bypassed by goto.
     {
-      callbacks_ = new HciHalBluetoothHciCallbacks(btsnoop_logger_);
+      callbacks_ = new InternalHciCallbacks(btsnoop_logger_);
       bt_hci_->initialize(callbacks_);
       // Don't timeout here, time out at a higher layer
       callbacks_->GetInitPromise()->get_future().wait();
@@ -156,7 +156,7 @@ class BluetoothHciHalHidl : public BluetoothHciHal {
 
   void Stop(const ModuleRegistry* registry) override {
     ASSERT(bt_hci_ != nullptr);
-    auto death_unlink = bt_hci_->unlinkToDeath(bluetooth_hci_death_recipient_);
+    auto death_unlink = bt_hci_->unlinkToDeath(hci_death_recipient_);
     if (!death_unlink.isOk()) {
       LOG_ERROR("Error unlinking death recipient from the Bluetooth HAL");
     }
@@ -168,13 +168,13 @@ class BluetoothHciHalHidl : public BluetoothHciHal {
   }
 
  private:
-  android::sp<HciHalBluetoothHciCallbacks> callbacks_;
+  android::sp<InternalHciCallbacks> callbacks_;
   android::sp<IBluetoothHci> bt_hci_;
-  BluetoothSnoopLogger* btsnoop_logger_;
+  SnoopLogger* btsnoop_logger_;
 };
 
-const ModuleFactory BluetoothHciHal::Factory = ModuleFactory([]() {
-  return new BluetoothHciHalHidl();
+const ModuleFactory HciHal::Factory = ModuleFactory([]() {
+  return new HciHalHidl();
 });
 
 }  // namespace hal
index 01eaa2d..0a302ed 100644 (file)
@@ -37,7 +37,7 @@ class HciHalHidlTest : public ::testing::Test {
 };
 
 TEST_F(HciHalHidlTest, init_and_close) {
-  fake_registry_.Start<BluetoothHciHal>();
+  fake_registry_.Start<HciHal>();
   fake_registry_.StopAll();
 }
 }  // namespace
index 94afad7..b169447 100644 (file)
@@ -24,7 +24,7 @@
 #include <mutex>
 #include <queue>
 
-#include "hal/bluetooth_snoop_logger.h"
+#include "hal/snoop_logger.h"
 #include "os/log.h"
 #include "os/reactor.h"
 #include "os/thread.h"
@@ -84,9 +84,9 @@ int ConnectToRootCanal(const std::string& server, int port) {
 namespace bluetooth {
 namespace hal {
 
-class BluetoothHciHalHostRootcanal : public BluetoothHciHal {
+class HciHalHostRootcanal : public HciHal {
  public:
-  void registerIncomingPacketCallback(BluetoothHciHalCallbacks* callback) override {
+  void registerIncomingPacketCallback(HciHalCallbacks* callback) override {
     std::lock_guard<std::mutex> lock(mutex_);
     ASSERT(incoming_packet_callback_ == nullptr && callback != nullptr);
     incoming_packet_callback_ = callback;
@@ -96,7 +96,7 @@ class BluetoothHciHalHostRootcanal : public BluetoothHciHal {
     std::lock_guard<std::mutex> lock(mutex_);
     ASSERT(sock_fd_ != INVALID_FD);
     std::vector<uint8_t> packet = std::move(command);
-    btsnoop_logger_->capture(packet, BluetoothSnoopLogger::Direction::OUTGOING, BluetoothSnoopLogger::PacketType::CMD);
+    btsnoop_logger_->capture(packet, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::CMD);
     packet.insert(packet.cbegin(), kH4Command);
     write_to_rootcanal_fd(packet);
   }
@@ -105,7 +105,7 @@ class BluetoothHciHalHostRootcanal : public BluetoothHciHal {
     std::lock_guard<std::mutex> lock(mutex_);
     ASSERT(sock_fd_ != INVALID_FD);
     std::vector<uint8_t> packet = std::move(data);
-    btsnoop_logger_->capture(packet, BluetoothSnoopLogger::Direction::OUTGOING, BluetoothSnoopLogger::PacketType::ACL);
+    btsnoop_logger_->capture(packet, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::ACL);
     packet.insert(packet.cbegin(), kH4Acl);
     write_to_rootcanal_fd(packet);
   }
@@ -114,7 +114,7 @@ class BluetoothHciHalHostRootcanal : public BluetoothHciHal {
     std::lock_guard<std::mutex> lock(mutex_);
     ASSERT(sock_fd_ != INVALID_FD);
     std::vector<uint8_t> packet = std::move(data);
-    btsnoop_logger_->capture(packet, BluetoothSnoopLogger::Direction::OUTGOING, BluetoothSnoopLogger::PacketType::SCO);
+    btsnoop_logger_->capture(packet, SnoopLogger::Direction::OUTGOING, SnoopLogger::PacketType::SCO);
     packet.insert(packet.cbegin(), kH4Sco);
     write_to_rootcanal_fd(packet);
   }
@@ -131,7 +131,7 @@ class BluetoothHciHalHostRootcanal : public BluetoothHciHal {
     ASSERT(sock_fd_ != INVALID_FD);
     reactable_ =
         hci_incoming_thread_.GetReactor()->Register(sock_fd_, [this]() { this->incoming_packet_received(); }, nullptr);
-    btsnoop_logger_ = new BluetoothSnoopLogger(kDefaultBtsnoopPath);
+    btsnoop_logger_ = new SnoopLogger(kDefaultBtsnoopPath);
     LOG_INFO("Rootcanal HAL opened successfully");
   }
 
@@ -153,13 +153,13 @@ class BluetoothHciHalHostRootcanal : public BluetoothHciHal {
  private:
   std::mutex mutex_;
   HciHalHostRootcanalConfig* config_ = HciHalHostRootcanalConfig::Get();
-  BluetoothHciHalCallbacks* incoming_packet_callback_ = nullptr;
+  HciHalCallbacks* incoming_packet_callback_ = nullptr;
   int sock_fd_ = INVALID_FD;
   bluetooth::os::Thread hci_incoming_thread_ =
       bluetooth::os::Thread("hci_incoming_thread", bluetooth::os::Thread::Priority::NORMAL);
   bluetooth::os::Reactor::Reactable* reactable_ = nullptr;
   std::queue<std::vector<uint8_t>> hci_outgoing_queue_;
-  BluetoothSnoopLogger* btsnoop_logger_;
+  SnoopLogger* btsnoop_logger_;
 
   void write_to_rootcanal_fd(HciPacket packet) {
     // TODO: replace this with new queue when it's ready
@@ -211,8 +211,8 @@ class BluetoothHciHalHostRootcanal : public BluetoothHciHal {
 
       HciPacket receivedHciPacket;
       receivedHciPacket.assign(buf + kH4HeaderSize, buf + kH4HeaderSize + kHciEvtHeaderSize + payload_size);
-      btsnoop_logger_->capture(receivedHciPacket, BluetoothSnoopLogger::Direction::INCOMING,
-                               BluetoothSnoopLogger::PacketType::EVT);
+      btsnoop_logger_->capture(receivedHciPacket, SnoopLogger::Direction::INCOMING,
+                               SnoopLogger::PacketType::EVT);
       incoming_packet_callback_->hciEventReceived(receivedHciPacket);
     }
 
@@ -229,8 +229,8 @@ class BluetoothHciHalHostRootcanal : public BluetoothHciHal {
 
       HciPacket receivedHciPacket;
       receivedHciPacket.assign(buf + kH4HeaderSize, buf + kH4HeaderSize + kHciAclHeaderSize + payload_size);
-      btsnoop_logger_->capture(receivedHciPacket, BluetoothSnoopLogger::Direction::INCOMING,
-                               BluetoothSnoopLogger::PacketType::ACL);
+      btsnoop_logger_->capture(receivedHciPacket, SnoopLogger::Direction::INCOMING,
+                               SnoopLogger::PacketType::ACL);
       incoming_packet_callback_->aclDataReceived(receivedHciPacket);
     }
 
@@ -244,16 +244,16 @@ class BluetoothHciHalHostRootcanal : public BluetoothHciHal {
 
       HciPacket receivedHciPacket;
       receivedHciPacket.assign(buf + kH4HeaderSize, buf + kH4HeaderSize + kHciScoHeaderSize + payload_size);
-      btsnoop_logger_->capture(receivedHciPacket, BluetoothSnoopLogger::Direction::INCOMING,
-                               BluetoothSnoopLogger::PacketType::SCO);
+      btsnoop_logger_->capture(receivedHciPacket, SnoopLogger::Direction::INCOMING,
+                               SnoopLogger::PacketType::SCO);
       incoming_packet_callback_->scoDataReceived(receivedHciPacket);
     }
     memset(buf, 0, kBufSize);
   }
 };
 
-const ModuleFactory BluetoothHciHal::Factory = ModuleFactory([]() {
-  return new BluetoothHciHalHostRootcanal();
+const ModuleFactory HciHal::Factory = ModuleFactory([]() {
+  return new HciHalHostRootcanal();
 });
 
 }  // namespace hal
index 33b6221..bb4649e 100644 (file)
@@ -50,7 +50,7 @@ using H4Packet = std::vector<uint8_t>;
 
 std::queue<std::pair<uint8_t, HciPacket>> incoming_packets_queue_;
 
-class TestBluetoothHciHalCallbacks : public BluetoothHciHalCallbacks {
+class TestHciHalCallbacks : public HciHalCallbacks {
  public:
   void hciEventReceived(HciPacket packet) override {
     incoming_packets_queue_.emplace(kH4Event, packet);
@@ -134,8 +134,8 @@ class HciHalRootcanalTest : public ::testing::Test {
   void SetUp() override {
     HciHalHostRootcanalConfig::Get()->SetPort(kTestPort);
     fake_server_ = new FakeRootcanalDesktopHciServer;
-    fake_registry_.Start<BluetoothHciHal>();
-    hal_ = fake_registry_.GetInstance<BluetoothHciHal>();
+    fake_registry_.Start<HciHal>();
+    hal_ = fake_registry_.GetInstance<HciHal>();
     hal_->registerIncomingPacketCallback(&callbacks_);
     fake_server_socket_ = fake_server_->Accept();  // accept() after client is connected to avoid blocking
     std::queue<std::pair<uint8_t, HciPacket>> empty;
@@ -155,9 +155,9 @@ class HciHalRootcanalTest : public ::testing::Test {
   }
 
   FakeRootcanalDesktopHciServer* fake_server_ = nullptr;
-  BluetoothHciHal* hal_ = nullptr;
+  HciHal* hal_ = nullptr;
   ModuleRegistry fake_registry_;
-  TestBluetoothHciHalCallbacks callbacks_;
+  TestHciHalCallbacks callbacks_;
   int fake_server_socket_ = -1;
 };
 
similarity index 94%
rename from gd/hal/bluetooth_snoop_logger.cc
rename to gd/hal/snoop_logger.cc
index 2fd719d..37eacf6 100644 (file)
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#include "hal/bluetooth_snoop_logger.h"
+#include "hal/snoop_logger.h"
 
 #include <arpa/inet.h>
 #include <netinet/in.h>
@@ -67,7 +67,7 @@ constexpr btsnoop_file_header_t BTSNOOP_FILE_HEADER = {
     .datalink_type = BTSNOOP_DATALINK_TYPE};
 }  // namespace
 
-BluetoothSnoopLogger::BluetoothSnoopLogger(const std::string& filename) {
+SnoopLogger::SnoopLogger(const std::string& filename) {
   {
     std::ifstream btsnoop_istream(filename);
     file_exists_ = btsnoop_istream.is_open();
@@ -81,7 +81,7 @@ BluetoothSnoopLogger::BluetoothSnoopLogger(const std::string& filename) {
   }
 }
 
-void BluetoothSnoopLogger::capture(const HciPacket& packet, Direction direction, PacketType type) {
+void SnoopLogger::capture(const HciPacket& packet, Direction direction, PacketType type) {
   uint64_t timestamp_us =
       std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch())
           .count();
similarity index 92%
rename from gd/hal/bluetooth_snoop_logger.h
rename to gd/hal/snoop_logger.h
index 6c41f3a..4447a8f 100644 (file)
@@ -26,9 +26,9 @@
 namespace bluetooth {
 namespace hal {
 
-class BluetoothSnoopLogger {
+class SnoopLogger {
  public:
-  explicit BluetoothSnoopLogger(const std::string& filename);
+  explicit SnoopLogger(const std::string& filename);
 
   enum class PacketType {
     CMD = 1,