Skip to content

Commit

Permalink
Fixing low level and medium issues in static code analysis
Browse files Browse the repository at this point in the history
Uninitialized and COPY_INSTED_OF_MOVE
issues are resolved in bluetooth interface

Tested:
BT on/off -> 20times
Connect phone, play music -> 10 times
HFP call -> 10 times
File transfer
CtsBluetoothTestCases

Tracked-On: OAM-123193
Signed-off-by: devath1x <[email protected]>
Signed-off-by: Gowtham Anandha Babu <[email protected]>
  • Loading branch information
devath1x committed Aug 27, 2024
1 parent 5cd6bfd commit c20aaed
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion bluetooth/bluetooth_hci.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static const uint8_t HCI_DATA_TYPE_SCO = 3;

class BluetoothDeathRecipient : public hidl_death_recipient {
public:
BluetoothDeathRecipient(const sp<IBluetoothHci> hci) : mHci(hci) {}
BluetoothDeathRecipient(const sp<IBluetoothHci> hci) : mHci(hci), has_died_(false) {}

virtual void serviceDied(
uint64_t /*cookie*/,
Expand Down
6 changes: 3 additions & 3 deletions bluetooth/h4_protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class H4Protocol : public HciProtocol {
H4Protocol(int fd, PacketReadCallback event_cb, PacketReadCallback acl_cb,
PacketReadCallback sco_cb)
: uart_fd_(fd),
event_cb_(event_cb),
acl_cb_(acl_cb),
sco_cb_(sco_cb),
event_cb_(std::move(event_cb)),
acl_cb_(std::move(acl_cb)),
sco_cb_(std::move(sco_cb)),
hci_packetizer_([this]() { OnPacketReady(); }) {}

size_t Send(uint8_t type, const uint8_t* data, size_t length);
Expand Down
2 changes: 1 addition & 1 deletion bluetooth/hci_packetizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ using HciPacketReadyCallback = std::function<void(void)>;
class HciPacketizer {
public:
HciPacketizer(HciPacketReadyCallback packet_cb)
: packet_ready_cb_(packet_cb){};
: packet_ready_cb_(std::move(packet_cb)){};
void OnDataReady(int fd, HciPacketType packet_type);
void CbHciPacket(uint8_t* data, size_t length);
const hidl_vec<uint8_t>& GetPacket() const;
Expand Down
4 changes: 2 additions & 2 deletions bluetooth/mct_protocol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ namespace hci {

MctProtocol::MctProtocol(int* fds, PacketReadCallback event_cb,
PacketReadCallback acl_cb)
: event_cb_(event_cb),
acl_cb_(acl_cb),
: event_cb_(std::move(event_cb)),
acl_cb_(std::move(acl_cb)),
event_packetizer_([this]() { OnEventPacketReady(); }),
acl_packetizer_([this]() { OnAclDataPacketReady(); }) {
for (int i = 0; i < CH_MAX; i++) {
Expand Down
12 changes: 6 additions & 6 deletions bluetooth/vendor_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ bool VendorInterface::Initialize(
return false;
}
g_vendor_interface = new VendorInterface();
return g_vendor_interface->Open(initialize_complete_cb, event_cb, acl_cb,
sco_cb);
return g_vendor_interface->Open(std::move(initialize_complete_cb), std::move(event_cb), std::move(acl_cb),
std::move(sco_cb));
}

void VendorInterface::Shutdown() {
Expand All @@ -192,7 +192,7 @@ bool VendorInterface::Open(InitializeCompleteCallback initialize_complete_cb,
PacketReadCallback event_cb,
PacketReadCallback acl_cb,
PacketReadCallback sco_cb) {
initialize_complete_cb_ = initialize_complete_cb;
initialize_complete_cb_ = std::move(initialize_complete_cb);

// Initialize vendor interface

Expand Down Expand Up @@ -247,20 +247,20 @@ bool VendorInterface::Open(InitializeCompleteCallback initialize_complete_cb,
}
}

event_cb_ = event_cb;
event_cb_ = std::move(event_cb);
PacketReadCallback intercept_events = [this](const hidl_vec<uint8_t>& event) {
HandleIncomingEvent(event);
};

if (fd_count == 1) {
hci::H4Protocol* h4_hci =
new hci::H4Protocol(fd_list[0], intercept_events, acl_cb, sco_cb);
new hci::H4Protocol(fd_list[0], intercept_events, acl_cb, std::move(sco_cb));
fd_watcher_.WatchFdForNonBlockingReads(
fd_list[0], [h4_hci](int fd) { h4_hci->OnDataReady(fd); });
hci_ = h4_hci;
} else {
hci::MctProtocol* mct_hci =
new hci::MctProtocol(fd_list, intercept_events, acl_cb);
new hci::MctProtocol(fd_list, std::move(intercept_events), acl_cb);
fd_watcher_.WatchFdForNonBlockingReads(
fd_list[CH_EVT], [mct_hci](int fd) { mct_hci->OnEventDataReady(fd); });
fd_watcher_.WatchFdForNonBlockingReads(
Expand Down

0 comments on commit c20aaed

Please sign in to comment.