Loading android/app/src/com/android/bluetooth/hap/HapClientService.java +4 −2 Original line number Diff line number Diff line Loading @@ -979,11 +979,12 @@ public class HapClientService extends ProfileService { case HapClientStackEvent.PRESET_INFO_REASON_PRESET_INFO_REQUEST_RESPONSE: { List current_presets = mPresetsMap.get(device); if (current_presets != null) { ListIterator<BluetoothHapPresetInfo> iter = current_presets.listIterator(); for (BluetoothHapPresetInfo new_preset : presets) { ListIterator<BluetoothHapPresetInfo> iter = current_presets.listIterator(); while (iter.hasNext()) { if (iter.next().getIndex() == new_preset.getIndex()) { iter.remove(); break; } } } Loading @@ -998,11 +999,12 @@ public class HapClientService extends ProfileService { case HapClientStackEvent.PRESET_INFO_REASON_PRESET_DELETED: { List current_presets = mPresetsMap.get(device); if (current_presets != null) { ListIterator<BluetoothHapPresetInfo> iter = current_presets.listIterator(); for (BluetoothHapPresetInfo new_preset : presets) { ListIterator<BluetoothHapPresetInfo> iter = current_presets.listIterator(); while (iter.hasNext()) { if (iter.next().getIndex() == new_preset.getIndex()) { iter.remove(); break; } } } Loading system/bta/has/has_client.cc +27 −22 Original line number Diff line number Diff line Loading @@ -1235,11 +1235,7 @@ class HasClientImpl : public HasClient { if (nt.change_id != PresetCtpChangeId::PRESET_GENERIC_UPDATE) break; if (nt.preset.has_value()) { /* Erase old value if exist */ device.has_presets.erase(nt.preset->GetIndex()); /* Erase in-between indices */ if (nt.prev_index != 0) { auto it = device.has_presets.begin(); while (it != device.has_presets.end()) { if ((it->GetIndex() > nt.prev_index) && Loading @@ -1253,12 +1249,19 @@ class HasClientImpl : public HasClient { ++it; } } } /* Update presets */ auto info = device.GetPreset(nt.preset->GetIndex()); if (info) { if (*info != *nt.preset) { device.has_presets.erase(nt.preset->GetIndex()); device.has_presets.insert(*nt.preset); auto info = device.GetPresetInfo(nt.preset->GetIndex()); if (info.has_value()) updated_infos.push_back(info.value()); updated_infos.push_back( *device.GetPresetInfo(nt.preset->GetIndex())); } } else { device.has_presets.insert(*nt.preset); updated_infos.push_back(*device.GetPresetInfo(nt.preset->GetIndex())); } } /* Journal update */ Loading Loading @@ -1319,15 +1322,17 @@ class HasClientImpl : public HasClient { } } if (!updated_infos.empty()) if (!updated_infos.empty()) { callbacks_->OnPresetInfo( device.addr, PresetInfoReason::PRESET_INFO_UPDATE, updated_infos); } if (!deleted_infos.empty()) if (!deleted_infos.empty()) { callbacks_->OnPresetInfo(device.addr, PresetInfoReason::PRESET_DELETED, deleted_infos); } } } void OnHasPresetAvailabilityChanged(HasDevice& device) { DLOG(INFO) << __func__; Loading system/bta/has/has_client_test.cc +9 −2 Original line number Diff line number Diff line Loading @@ -2165,10 +2165,16 @@ TEST_F(HasClientTest, test_presets_changed_generic_update_add_and_delete) { InjectPresetChanged( test_conn_id, test_address, false, new_test_preset2, 8 /* prev_index */, ::bluetooth::le_audio::has::PresetCtpChangeId::PRESET_GENERIC_UPDATE, false /* is_last */); /* Third event deletes preset 1 with the generic update */ InjectPresetChanged( test_conn_id, test_address, false, new_test_preset1, 0 /* prev_index */, ::bluetooth::le_audio::has::PresetCtpChangeId::PRESET_GENERIC_UPDATE, true /* is_last */); /* Verify received preset info - expect presets 1, 32 unchanged, 8, 9 * updated, and 2, 4, 5 deleted. * updated, and 1, 2, 4, 5 deleted. */ ASSERT_EQ(2u, updated_preset_details.size()); ASSERT_EQ(new_test_preset1.GetIndex(), Loading @@ -2184,10 +2190,11 @@ TEST_F(HasClientTest, test_presets_changed_generic_update_add_and_delete) { ASSERT_EQ(new_test_preset2.IsWritable(), updated_preset_details[1].writable); ASSERT_EQ(new_test_preset2.GetName(), updated_preset_details[1].preset_name); ASSERT_EQ(3u, deleted_preset_details.size()); ASSERT_EQ(4u, deleted_preset_details.size()); ASSERT_EQ(2, deleted_preset_details[0].preset_index); ASSERT_EQ(4, deleted_preset_details[1].preset_index); ASSERT_EQ(5, deleted_preset_details[2].preset_index); ASSERT_EQ(1, deleted_preset_details[3].preset_index); } TEST_F(HasClientTest, test_presets_changed_deleted) { Loading Loading
android/app/src/com/android/bluetooth/hap/HapClientService.java +4 −2 Original line number Diff line number Diff line Loading @@ -979,11 +979,12 @@ public class HapClientService extends ProfileService { case HapClientStackEvent.PRESET_INFO_REASON_PRESET_INFO_REQUEST_RESPONSE: { List current_presets = mPresetsMap.get(device); if (current_presets != null) { ListIterator<BluetoothHapPresetInfo> iter = current_presets.listIterator(); for (BluetoothHapPresetInfo new_preset : presets) { ListIterator<BluetoothHapPresetInfo> iter = current_presets.listIterator(); while (iter.hasNext()) { if (iter.next().getIndex() == new_preset.getIndex()) { iter.remove(); break; } } } Loading @@ -998,11 +999,12 @@ public class HapClientService extends ProfileService { case HapClientStackEvent.PRESET_INFO_REASON_PRESET_DELETED: { List current_presets = mPresetsMap.get(device); if (current_presets != null) { ListIterator<BluetoothHapPresetInfo> iter = current_presets.listIterator(); for (BluetoothHapPresetInfo new_preset : presets) { ListIterator<BluetoothHapPresetInfo> iter = current_presets.listIterator(); while (iter.hasNext()) { if (iter.next().getIndex() == new_preset.getIndex()) { iter.remove(); break; } } } Loading
system/bta/has/has_client.cc +27 −22 Original line number Diff line number Diff line Loading @@ -1235,11 +1235,7 @@ class HasClientImpl : public HasClient { if (nt.change_id != PresetCtpChangeId::PRESET_GENERIC_UPDATE) break; if (nt.preset.has_value()) { /* Erase old value if exist */ device.has_presets.erase(nt.preset->GetIndex()); /* Erase in-between indices */ if (nt.prev_index != 0) { auto it = device.has_presets.begin(); while (it != device.has_presets.end()) { if ((it->GetIndex() > nt.prev_index) && Loading @@ -1253,12 +1249,19 @@ class HasClientImpl : public HasClient { ++it; } } } /* Update presets */ auto info = device.GetPreset(nt.preset->GetIndex()); if (info) { if (*info != *nt.preset) { device.has_presets.erase(nt.preset->GetIndex()); device.has_presets.insert(*nt.preset); auto info = device.GetPresetInfo(nt.preset->GetIndex()); if (info.has_value()) updated_infos.push_back(info.value()); updated_infos.push_back( *device.GetPresetInfo(nt.preset->GetIndex())); } } else { device.has_presets.insert(*nt.preset); updated_infos.push_back(*device.GetPresetInfo(nt.preset->GetIndex())); } } /* Journal update */ Loading Loading @@ -1319,15 +1322,17 @@ class HasClientImpl : public HasClient { } } if (!updated_infos.empty()) if (!updated_infos.empty()) { callbacks_->OnPresetInfo( device.addr, PresetInfoReason::PRESET_INFO_UPDATE, updated_infos); } if (!deleted_infos.empty()) if (!deleted_infos.empty()) { callbacks_->OnPresetInfo(device.addr, PresetInfoReason::PRESET_DELETED, deleted_infos); } } } void OnHasPresetAvailabilityChanged(HasDevice& device) { DLOG(INFO) << __func__; Loading
system/bta/has/has_client_test.cc +9 −2 Original line number Diff line number Diff line Loading @@ -2165,10 +2165,16 @@ TEST_F(HasClientTest, test_presets_changed_generic_update_add_and_delete) { InjectPresetChanged( test_conn_id, test_address, false, new_test_preset2, 8 /* prev_index */, ::bluetooth::le_audio::has::PresetCtpChangeId::PRESET_GENERIC_UPDATE, false /* is_last */); /* Third event deletes preset 1 with the generic update */ InjectPresetChanged( test_conn_id, test_address, false, new_test_preset1, 0 /* prev_index */, ::bluetooth::le_audio::has::PresetCtpChangeId::PRESET_GENERIC_UPDATE, true /* is_last */); /* Verify received preset info - expect presets 1, 32 unchanged, 8, 9 * updated, and 2, 4, 5 deleted. * updated, and 1, 2, 4, 5 deleted. */ ASSERT_EQ(2u, updated_preset_details.size()); ASSERT_EQ(new_test_preset1.GetIndex(), Loading @@ -2184,10 +2190,11 @@ TEST_F(HasClientTest, test_presets_changed_generic_update_add_and_delete) { ASSERT_EQ(new_test_preset2.IsWritable(), updated_preset_details[1].writable); ASSERT_EQ(new_test_preset2.GetName(), updated_preset_details[1].preset_name); ASSERT_EQ(3u, deleted_preset_details.size()); ASSERT_EQ(4u, deleted_preset_details.size()); ASSERT_EQ(2, deleted_preset_details[0].preset_index); ASSERT_EQ(4, deleted_preset_details[1].preset_index); ASSERT_EQ(5, deleted_preset_details[2].preset_index); ASSERT_EQ(1, deleted_preset_details[3].preset_index); } TEST_F(HasClientTest, test_presets_changed_deleted) { Loading