Loading system/bta/vc/vc.cc +23 −0 Original line number Diff line number Diff line Loading @@ -707,6 +707,26 @@ class VolumeControlImpl : public VolumeControl { } } void RemoveDeviceFromOperationList(const RawAddress& addr) { if (ongoing_operations_.empty()) { return; } for (auto& op : ongoing_operations_) { auto it = find(op.devices_.begin(), op.devices_.end(), addr); if (it == op.devices_.end()) { continue; } op.devices_.erase(it); } // Remove operations with no devices ongoing_operations_.erase( std::remove_if(ongoing_operations_.begin(), ongoing_operations_.end(), [](auto& op) { return op.devices_.empty(); }), ongoing_operations_.end()); } void RemoveDeviceFromOperationList(const RawAddress& addr, int operation_id) { auto op = find_if(ongoing_operations_.begin(), ongoing_operations_.end(), [operation_id](auto& operation) { Loading Loading @@ -1143,6 +1163,9 @@ class VolumeControlImpl : public VolumeControl { void device_cleanup_helper(VolumeControlDevice* device, bool notify) { device->Disconnect(gatt_if_); RemoveDeviceFromOperationList(device->address); if (notify) callbacks_->OnConnectionState(ConnectionState::DISCONNECTED, device->address); Loading system/bta/vc/vc_test.cc +28 −0 Original line number Diff line number Diff line Loading @@ -1260,6 +1260,34 @@ TEST_F(VolumeControlValueSetTest, test_volume_operation_failed) { ASSERT_EQ(1, get_func_call_count("alarm_cancel")); } TEST_F(VolumeControlValueSetTest, test_volume_operation_failed_due_to_device_disconnection) { const std::vector<uint8_t> vol_x10({0x04, 0x00, 0x10}); EXPECT_CALL(gatt_queue, WriteCharacteristic(conn_id, 0x0024, vol_x10, GATT_WRITE, _, _)) .Times(1); ON_CALL(gatt_queue, WriteCharacteristic(_, _, _, _, _, _)) .WillByDefault(Invoke( [](uint16_t conn_id, uint16_t handle, std::vector<uint8_t> value, tGATT_WRITE_TYPE write_type, GATT_WRITE_OP_CB cb, void* cb_data) { /* Do nothing */ })); ASSERT_EQ(0, get_func_call_count("alarm_set_on_mloop")); ASSERT_EQ(0, get_func_call_count("alarm_cancel")); VolumeControl::Get()->SetVolume(test_address, 0x10); Mock::VerifyAndClearExpectations(&gatt_queue); EXPECT_CALL(*callbacks, OnConnectionState(ConnectionState::DISCONNECTED, test_address)); GetDisconnectedEvent(test_address, conn_id); Mock::VerifyAndClearExpectations(callbacks.get()); ASSERT_EQ(1, get_func_call_count("alarm_set_on_mloop")); ASSERT_EQ(1, get_func_call_count("alarm_cancel")); } TEST_F(VolumeControlValueSetTest, test_set_volume) { const std::vector<uint8_t> vol_x10({0x04, 0x00, 0x10}); EXPECT_CALL(gatt_queue, Loading Loading
system/bta/vc/vc.cc +23 −0 Original line number Diff line number Diff line Loading @@ -707,6 +707,26 @@ class VolumeControlImpl : public VolumeControl { } } void RemoveDeviceFromOperationList(const RawAddress& addr) { if (ongoing_operations_.empty()) { return; } for (auto& op : ongoing_operations_) { auto it = find(op.devices_.begin(), op.devices_.end(), addr); if (it == op.devices_.end()) { continue; } op.devices_.erase(it); } // Remove operations with no devices ongoing_operations_.erase( std::remove_if(ongoing_operations_.begin(), ongoing_operations_.end(), [](auto& op) { return op.devices_.empty(); }), ongoing_operations_.end()); } void RemoveDeviceFromOperationList(const RawAddress& addr, int operation_id) { auto op = find_if(ongoing_operations_.begin(), ongoing_operations_.end(), [operation_id](auto& operation) { Loading Loading @@ -1143,6 +1163,9 @@ class VolumeControlImpl : public VolumeControl { void device_cleanup_helper(VolumeControlDevice* device, bool notify) { device->Disconnect(gatt_if_); RemoveDeviceFromOperationList(device->address); if (notify) callbacks_->OnConnectionState(ConnectionState::DISCONNECTED, device->address); Loading
system/bta/vc/vc_test.cc +28 −0 Original line number Diff line number Diff line Loading @@ -1260,6 +1260,34 @@ TEST_F(VolumeControlValueSetTest, test_volume_operation_failed) { ASSERT_EQ(1, get_func_call_count("alarm_cancel")); } TEST_F(VolumeControlValueSetTest, test_volume_operation_failed_due_to_device_disconnection) { const std::vector<uint8_t> vol_x10({0x04, 0x00, 0x10}); EXPECT_CALL(gatt_queue, WriteCharacteristic(conn_id, 0x0024, vol_x10, GATT_WRITE, _, _)) .Times(1); ON_CALL(gatt_queue, WriteCharacteristic(_, _, _, _, _, _)) .WillByDefault(Invoke( [](uint16_t conn_id, uint16_t handle, std::vector<uint8_t> value, tGATT_WRITE_TYPE write_type, GATT_WRITE_OP_CB cb, void* cb_data) { /* Do nothing */ })); ASSERT_EQ(0, get_func_call_count("alarm_set_on_mloop")); ASSERT_EQ(0, get_func_call_count("alarm_cancel")); VolumeControl::Get()->SetVolume(test_address, 0x10); Mock::VerifyAndClearExpectations(&gatt_queue); EXPECT_CALL(*callbacks, OnConnectionState(ConnectionState::DISCONNECTED, test_address)); GetDisconnectedEvent(test_address, conn_id); Mock::VerifyAndClearExpectations(callbacks.get()); ASSERT_EQ(1, get_func_call_count("alarm_set_on_mloop")); ASSERT_EQ(1, get_func_call_count("alarm_cancel")); } TEST_F(VolumeControlValueSetTest, test_set_volume) { const std::vector<uint8_t> vol_x10({0x04, 0x00, 0x10}); EXPECT_CALL(gatt_queue, Loading