From f8c5d406a80c9023400b16c11cb904a2ca93cb89 Mon Sep 17 00:00:00 2001 From: BrainL Date: Fri, 30 May 2025 12:01:47 +0800 Subject: [PATCH 1/2] DP idl Signed-off-by: BrainL --- bundle.json | 5 +- common/BUILD.gn | 6 +- .../interfaces/access_control_profile.h | 14 +- .../interfaces/characteristic_profile.h | 13 +- common/include/interfaces/device_icon_info.h | 14 +- .../device_icon_info_filter_options.h | 13 +- common/include/interfaces/device_profile.h | 13 +- .../device_profile_filter_options.h | 14 +- common/include/interfaces/dp_subscribe_info.h | 10 +- .../interfaces/dp_subscribe_info_extension.h | 68 + common/include/interfaces/dp_sync_options.h | 13 +- .../interfaces/i_distributed_device_profile.h | 110 -- .../include/interfaces/local_service_info.h | 14 +- common/include/interfaces/product_info.h | 14 +- .../include/interfaces/service_info_profile.h | 14 +- .../interfaces/service_info_unique_key.h | 14 +- common/include/interfaces/service_profile.h | 15 +- .../include/interfaces/trust_device_profile.h | 14 +- .../include/interfaces/trusted_device_info.h | 14 +- common/include/utils/ipc_utils.h | 1 + .../src/interfaces/access_control_profile.cpp | 53 + .../src/interfaces/characteristic_profile.cpp | 37 + common/src/interfaces/device_icon_info.cpp | 41 + .../device_icon_info_filter_options.cpp | 33 + common/src/interfaces/device_profile.cpp | 93 + .../device_profile_filter_options.cpp | 29 + .../interfaces/dp_inited_callback_proxy.cpp | 2 +- common/src/interfaces/dp_subscribe_info.cpp | 1 - .../dp_subscribe_info_extension.cpp | 102 ++ common/src/interfaces/dp_sync_options.cpp | 44 + common/src/interfaces/local_service_info.cpp | 40 + .../pincode_invalid_callback_proxy.cpp | 2 +- common/src/interfaces/product_info.cpp | 36 + .../profile_change_listener_proxy.cpp | 2 +- .../src/interfaces/service_info_profile.cpp | 65 + .../interfaces/service_info_unique_key.cpp | 35 + common/src/interfaces/service_profile.cpp | 35 + .../src/interfaces/trust_device_profile.cpp | 39 + common/src/interfaces/trusted_device_info.cpp | 39 + common/src/utils/ipc_utils.cpp | 1 + interfaces/innerkits/core/BUILD.gn | 58 +- .../core/IDistributedDeviceProfile.idl | 92 + .../distributed_device_profile_client.h | 4 +- .../distributed_device_profile_proxy.h | 107 -- .../src/distributed_device_profile_client.cpp | 10 +- .../src/distributed_device_profile_proxy.cpp | 789 --------- old/common/include/device_profile_errors.h | 55 - old/common/include/device_profile_log.h | 52 - old/common/include/device_profile_utils.h | 36 - .../deviceprofile_ipc_interface_code.h | 67 - old/common/include/parcel_helper.h | 110 -- old/common/include/single_instance.h | 44 - old/common/src/device_profile_utils.cpp | 95 -- old/interfaces/innerkits/core/BUILD.gn | 83 - .../callback/device_profile_load_callback.h | 36 - .../distributed_device_profile_client.h | 91 - .../distributed_device_profile_proxy.h | 56 - .../include/idistributed_device_profile.h | 49 - .../core/include/iprofile_event_callback.h | 41 - .../core/include/iprofile_event_notifier.h | 33 - .../include/profile_change_notification.h | 73 - .../innerkits/core/include/profile_event.h | 33 - .../include/profile_event_notifier_stub.h | 55 - .../include/service_characteristic_profile.h | 50 - .../innerkits/core/include/subscribe_info.h | 38 - .../innerkits/core/include/sync_options.h | 52 - .../callback/device_profile_load_callback.cpp | 40 - .../src/distributed_device_profile_client.cpp | 386 ----- .../src/distributed_device_profile_proxy.cpp | 213 --- .../core/src/profile_event_notifier_stub.cpp | 102 -- old/permission/BUILD.gn | 22 - old/permission/authority.json | 59 - old/radar/BUILD.gn | 57 - old/radar/include/dp_radar_helper.h | 138 -- old/radar/src/dp_radar_helper.cpp | 460 ----- old/radar/test/unittest/BUILD.gn | 45 - .../test/unittest/dp_radar_helper_test.cpp | 219 --- .../test/unittest/dp_radar_helper_test.h | 33 - old/services/core/BUILD.gn | 155 -- .../include/authority/authority_manager.h | 74 - .../include/authority/trust_group_manager.h | 60 - .../contentsensor/app_info_collector.h | 35 - .../include/contentsensor/content_collector.h | 33 - .../contentsensor/content_sensor_manager.h | 39 - .../contentsensor/device_info_collector.h | 41 - .../contentsensor/pasteboard_info_collector.h | 35 - .../contentsensor/storage_info_collector.h | 33 - .../contentsensor/syscap_info_collector.h | 32 - .../contentsensor/system_info_collector.h | 36 - .../dbstorage/device_profile_storage.h | 86 - .../device_profile_storage_manager.h | 101 -- .../dbstorage/kvstore_death_recipient_dp.h | 29 - .../include/dbstorage/online_sync_table.h | 46 - .../core/include/dbstorage/sync_coordinator.h | 48 - .../core/include/devicemanager/device_info.h | 46 - .../include/devicemanager/dp_device_manager.h | 94 -- .../core/include/dfx/device_profile_dumper.h | 39 - .../distributed_device_profile_service.h | 77 - .../include/distributed_device_profile_stub.h | 123 -- .../subscribemanager/profile_change_handler.h | 58 - .../subscribemanager/profile_event_handler.h | 70 - .../profile_event_handler_factory.h | 45 - .../profile_event_notifier_proxy.h | 38 - .../subscribemanager/profile_sync_handler.h | 46 - .../subscribemanager/subscribe_info_checker.h | 46 - .../subscribemanager/subscribe_manager.h | 73 - .../subscriber_death_recipient.h | 32 - .../core/src/authority/authority_manager.cpp | 329 ---- .../src/authority/trust_group_manager.cpp | 187 -- .../src/contentsensor/app_info_collector.cpp | 54 - .../src/contentsensor/content_collector.cpp | 32 - .../contentsensor/content_sensor_manager.cpp | 68 - .../contentsensor/device_info_collector.cpp | 83 - .../pasteboard_info_collector.cpp | 61 - .../contentsensor/storage_info_collector.cpp | 62 - .../contentsensor/syscap_info_collector.cpp | 75 - .../contentsensor/system_info_collector.cpp | 72 - .../src/dbstorage/device_profile_storage.cpp | 405 ----- .../device_profile_storage_manager.cpp | 641 ------- .../dbstorage/kvstore_death_recipient_dp.cpp | 33 - .../core/src/dbstorage/online_sync_table.cpp | 164 -- .../core/src/dbstorage/sync_coordinator.cpp | 81 - .../core/src/devicemanager/device_info.cpp | 35 - .../src/devicemanager/dp_device_manager.cpp | 448 ----- .../core/src/dfx/device_profile_dumper.cpp | 82 - .../distributed_device_profile_service.cpp | 332 ---- .../src/distributed_device_profile_stub.cpp | 1252 -------------- .../core/src/profile_change_notification.cpp | 100 -- .../src/service_characteristic_profile.cpp | 89 - .../profile_change_handler.cpp | 283 ---- .../profile_event_handler.cpp | 117 -- .../profile_event_handler_factory.cpp | 62 - .../profile_event_notifier_proxy.cpp | 80 - .../subscribemanager/profile_sync_handler.cpp | 100 -- .../src/subscribemanager/subscribe_info.cpp | 66 - .../subscribe_info_checker.cpp | 85 - .../subscribemanager/subscribe_manager.cpp | 237 --- .../subscriber_death_recipient.cpp | 27 - old/services/core/src/sync_options.cpp | 81 - old/services/core/test/BUILD.gn | 295 ---- old/services/core/test/fuzztest/BUILD.gn | 26 - .../fuzztest/deviceprofile_fuzzer/BUILD.gn | 71 - .../fuzztest/deviceprofile_fuzzer/corpus/init | 16 - .../device_profile_fuzzer.cpp | 119 -- .../device_profile_fuzzer.h | 21 - .../fuzztest/deviceprofile_fuzzer/project.xml | 25 - .../fuzztest/dumplocalprofile_fuzzer/BUILD.gn | 73 - .../dumplocalprofile_fuzzer/corpus/init | 16 - .../dumplocalprofile_fuzzer.cpp | 46 - .../dumplocalprofile_fuzzer.h | 21 - .../dumplocalprofile_fuzzer/project.xml | 25 - .../fuzztest/getdeviceprofile_fuzzer/BUILD.gn | 73 - .../getdeviceprofile_fuzzer/corpus/init | 16 - .../getdeviceprofile_fuzzer.cpp | 64 - .../getdeviceprofile_fuzzer.h | 21 - .../getdeviceprofile_fuzzer/project.xml | 25 - .../fuzztest/putdeviceprofile_fuzzer/BUILD.gn | 73 - .../putdeviceprofile_fuzzer/corpus/init | 16 - .../putdeviceprofile_fuzzer/project.xml | 25 - .../putdeviceprofile_fuzzer.cpp | 69 - .../putdeviceprofile_fuzzer.h | 21 - .../putdeviceprofileinner_fuzzer/BUILD.gn | 72 - .../putdeviceprofileinner_fuzzer/corpus/init | 16 - .../putdeviceprofileinner_fuzzer/project.xml | 25 - .../putdeviceprofileinner_fuzzer.cpp | 100 -- .../putdeviceprofileinner_fuzzer.h | 21 - .../BUILD.gn | 74 - .../corpus/init | 16 - .../project.xml | 25 - .../subscribeprofileeventinner_fuzzer.cpp | 375 ---- .../subscribeprofileeventinner_fuzzer.h | 21 - .../syncdeviceprofileinner_fuzzer/BUILD.gn | 72 - .../syncdeviceprofileinner_fuzzer/corpus/init | 16 - .../syncdeviceprofileinner_fuzzer/project.xml | 25 - .../syncdeviceprofileinner_fuzzer.cpp | 99 -- .../syncdeviceprofileinner_fuzzer.h | 21 - .../test/unittest/content_sensor_test.cpp | 286 ---- .../test/unittest/device_profile_dfx_test.cpp | 185 -- .../unittest/device_profile_utils_test.cpp | 275 --- .../distributed_device_profile_stub_test.cpp | 446 ----- .../test/unittest/event_subscribe_test.cpp | 486 ------ .../test/unittest/profile_authority_test.cpp | 522 ------ .../unittest/profile_change_handler_test.cpp | 441 ----- .../profile_change_notification_test.cpp | 383 ----- .../core/test/unittest/profile_crud_test.cpp | 1067 ------------ .../core/test/unittest/profile_dm_test.cpp | 237 --- .../core/test/unittest/profile_entry_test.cpp | 100 -- .../profile_event_notifier_proxy_test.cpp | 113 -- .../core/test/unittest/profile_proxy_test.cpp | 132 -- .../test/unittest/profile_storage_test.cpp | 1503 ----------------- .../core/test/unittest/profile_sync_test.cpp | 255 --- .../test/unittest/service_profile_test.cpp | 112 -- .../unittest/subscribe_info_checker_test.cpp | 282 ---- .../test/unittest/subscribe_info_test.cpp | 119 -- .../test/unittest/subscribe_manager_test.cpp | 398 ----- old/services/core/test/unittest/test_util.cpp | 55 - old/services/core/test/unittest/test_util.h | 32 - old/services/core/test/unittest/utils.h | 25 - old/test/resource/BUILD.gn | 23 - .../resource/authority/invalid_authority.json | 62 - .../resource/authority/valid_authority.json | 17 - old/test/resource/ohos_test.xml | 22 - old/tools/dp/BUILD.gn | 55 - old/tools/dp/include/dp_command.h | 65 - old/tools/dp/include/shell_command.h | 64 - old/tools/dp/src/dp_command.cpp | 489 ------ old/tools/dp/src/main.cpp | 32 - old/tools/dp/src/shell_command.cpp | 128 -- radar/test/unittest/BUILD.gn | 1 + services/core/BUILD.gn | 4 +- .../distributed_device_profile_service_new.h | 24 +- .../distributed_device_profile_stub_new.h | 102 -- .../subscribe_profile_manager.h | 11 +- ...distributed_device_profile_service_new.cpp | 25 +- .../distributed_device_profile_stub_new.cpp | 1057 ------------ .../subscribe_profile_manager.cpp | 38 +- services/core/test/BUILD.gn | 15 - .../new_device_profile_fuzzer.cpp | 1 - ...stributed_device_profile_stub_new_test.cpp | 1132 ------------- 219 files changed, 1140 insertions(+), 24414 deletions(-) create mode 100644 common/include/interfaces/dp_subscribe_info_extension.h delete mode 100644 common/include/interfaces/i_distributed_device_profile.h create mode 100644 common/src/interfaces/dp_subscribe_info_extension.cpp create mode 100644 interfaces/innerkits/core/IDistributedDeviceProfile.idl delete mode 100644 interfaces/innerkits/core/include/distributed_device_profile_proxy.h delete mode 100644 interfaces/innerkits/core/src/distributed_device_profile_proxy.cpp delete mode 100644 old/common/include/device_profile_errors.h delete mode 100644 old/common/include/device_profile_log.h delete mode 100644 old/common/include/device_profile_utils.h delete mode 100644 old/common/include/deviceprofile_ipc_interface_code.h delete mode 100644 old/common/include/parcel_helper.h delete mode 100644 old/common/include/single_instance.h delete mode 100644 old/common/src/device_profile_utils.cpp delete mode 100644 old/interfaces/innerkits/core/BUILD.gn delete mode 100644 old/interfaces/innerkits/core/include/callback/device_profile_load_callback.h delete mode 100644 old/interfaces/innerkits/core/include/distributed_device_profile_client.h delete mode 100644 old/interfaces/innerkits/core/include/distributed_device_profile_proxy.h delete mode 100644 old/interfaces/innerkits/core/include/idistributed_device_profile.h delete mode 100644 old/interfaces/innerkits/core/include/iprofile_event_callback.h delete mode 100644 old/interfaces/innerkits/core/include/iprofile_event_notifier.h delete mode 100644 old/interfaces/innerkits/core/include/profile_change_notification.h delete mode 100644 old/interfaces/innerkits/core/include/profile_event.h delete mode 100644 old/interfaces/innerkits/core/include/profile_event_notifier_stub.h delete mode 100644 old/interfaces/innerkits/core/include/service_characteristic_profile.h delete mode 100644 old/interfaces/innerkits/core/include/subscribe_info.h delete mode 100644 old/interfaces/innerkits/core/include/sync_options.h delete mode 100644 old/interfaces/innerkits/core/src/callback/device_profile_load_callback.cpp delete mode 100644 old/interfaces/innerkits/core/src/distributed_device_profile_client.cpp delete mode 100644 old/interfaces/innerkits/core/src/distributed_device_profile_proxy.cpp delete mode 100644 old/interfaces/innerkits/core/src/profile_event_notifier_stub.cpp delete mode 100644 old/permission/BUILD.gn delete mode 100644 old/permission/authority.json delete mode 100644 old/radar/BUILD.gn delete mode 100644 old/radar/include/dp_radar_helper.h delete mode 100644 old/radar/src/dp_radar_helper.cpp delete mode 100644 old/radar/test/unittest/BUILD.gn delete mode 100644 old/radar/test/unittest/dp_radar_helper_test.cpp delete mode 100644 old/radar/test/unittest/dp_radar_helper_test.h delete mode 100644 old/services/core/BUILD.gn delete mode 100644 old/services/core/include/authority/authority_manager.h delete mode 100644 old/services/core/include/authority/trust_group_manager.h delete mode 100644 old/services/core/include/contentsensor/app_info_collector.h delete mode 100644 old/services/core/include/contentsensor/content_collector.h delete mode 100644 old/services/core/include/contentsensor/content_sensor_manager.h delete mode 100644 old/services/core/include/contentsensor/device_info_collector.h delete mode 100644 old/services/core/include/contentsensor/pasteboard_info_collector.h delete mode 100644 old/services/core/include/contentsensor/storage_info_collector.h delete mode 100644 old/services/core/include/contentsensor/syscap_info_collector.h delete mode 100644 old/services/core/include/contentsensor/system_info_collector.h delete mode 100644 old/services/core/include/dbstorage/device_profile_storage.h delete mode 100644 old/services/core/include/dbstorage/device_profile_storage_manager.h delete mode 100644 old/services/core/include/dbstorage/kvstore_death_recipient_dp.h delete mode 100644 old/services/core/include/dbstorage/online_sync_table.h delete mode 100644 old/services/core/include/dbstorage/sync_coordinator.h delete mode 100644 old/services/core/include/devicemanager/device_info.h delete mode 100644 old/services/core/include/devicemanager/dp_device_manager.h delete mode 100644 old/services/core/include/dfx/device_profile_dumper.h delete mode 100644 old/services/core/include/distributed_device_profile_service.h delete mode 100644 old/services/core/include/distributed_device_profile_stub.h delete mode 100644 old/services/core/include/subscribemanager/profile_change_handler.h delete mode 100644 old/services/core/include/subscribemanager/profile_event_handler.h delete mode 100644 old/services/core/include/subscribemanager/profile_event_handler_factory.h delete mode 100644 old/services/core/include/subscribemanager/profile_event_notifier_proxy.h delete mode 100644 old/services/core/include/subscribemanager/profile_sync_handler.h delete mode 100644 old/services/core/include/subscribemanager/subscribe_info_checker.h delete mode 100644 old/services/core/include/subscribemanager/subscribe_manager.h delete mode 100644 old/services/core/include/subscribemanager/subscriber_death_recipient.h delete mode 100644 old/services/core/src/authority/authority_manager.cpp delete mode 100644 old/services/core/src/authority/trust_group_manager.cpp delete mode 100644 old/services/core/src/contentsensor/app_info_collector.cpp delete mode 100644 old/services/core/src/contentsensor/content_collector.cpp delete mode 100644 old/services/core/src/contentsensor/content_sensor_manager.cpp delete mode 100644 old/services/core/src/contentsensor/device_info_collector.cpp delete mode 100644 old/services/core/src/contentsensor/pasteboard_info_collector.cpp delete mode 100644 old/services/core/src/contentsensor/storage_info_collector.cpp delete mode 100644 old/services/core/src/contentsensor/syscap_info_collector.cpp delete mode 100644 old/services/core/src/contentsensor/system_info_collector.cpp delete mode 100644 old/services/core/src/dbstorage/device_profile_storage.cpp delete mode 100644 old/services/core/src/dbstorage/device_profile_storage_manager.cpp delete mode 100644 old/services/core/src/dbstorage/kvstore_death_recipient_dp.cpp delete mode 100644 old/services/core/src/dbstorage/online_sync_table.cpp delete mode 100644 old/services/core/src/dbstorage/sync_coordinator.cpp delete mode 100644 old/services/core/src/devicemanager/device_info.cpp delete mode 100644 old/services/core/src/devicemanager/dp_device_manager.cpp delete mode 100644 old/services/core/src/dfx/device_profile_dumper.cpp delete mode 100644 old/services/core/src/distributed_device_profile_service.cpp delete mode 100644 old/services/core/src/distributed_device_profile_stub.cpp delete mode 100644 old/services/core/src/profile_change_notification.cpp delete mode 100644 old/services/core/src/service_characteristic_profile.cpp delete mode 100644 old/services/core/src/subscribemanager/profile_change_handler.cpp delete mode 100644 old/services/core/src/subscribemanager/profile_event_handler.cpp delete mode 100644 old/services/core/src/subscribemanager/profile_event_handler_factory.cpp delete mode 100644 old/services/core/src/subscribemanager/profile_event_notifier_proxy.cpp delete mode 100644 old/services/core/src/subscribemanager/profile_sync_handler.cpp delete mode 100644 old/services/core/src/subscribemanager/subscribe_info.cpp delete mode 100644 old/services/core/src/subscribemanager/subscribe_info_checker.cpp delete mode 100644 old/services/core/src/subscribemanager/subscribe_manager.cpp delete mode 100644 old/services/core/src/subscribemanager/subscriber_death_recipient.cpp delete mode 100644 old/services/core/src/sync_options.cpp delete mode 100644 old/services/core/test/BUILD.gn delete mode 100644 old/services/core/test/fuzztest/BUILD.gn delete mode 100644 old/services/core/test/fuzztest/deviceprofile_fuzzer/BUILD.gn delete mode 100644 old/services/core/test/fuzztest/deviceprofile_fuzzer/corpus/init delete mode 100644 old/services/core/test/fuzztest/deviceprofile_fuzzer/device_profile_fuzzer.cpp delete mode 100644 old/services/core/test/fuzztest/deviceprofile_fuzzer/device_profile_fuzzer.h delete mode 100644 old/services/core/test/fuzztest/deviceprofile_fuzzer/project.xml delete mode 100755 old/services/core/test/fuzztest/dumplocalprofile_fuzzer/BUILD.gn delete mode 100644 old/services/core/test/fuzztest/dumplocalprofile_fuzzer/corpus/init delete mode 100644 old/services/core/test/fuzztest/dumplocalprofile_fuzzer/dumplocalprofile_fuzzer.cpp delete mode 100644 old/services/core/test/fuzztest/dumplocalprofile_fuzzer/dumplocalprofile_fuzzer.h delete mode 100644 old/services/core/test/fuzztest/dumplocalprofile_fuzzer/project.xml delete mode 100755 old/services/core/test/fuzztest/getdeviceprofile_fuzzer/BUILD.gn delete mode 100644 old/services/core/test/fuzztest/getdeviceprofile_fuzzer/corpus/init delete mode 100644 old/services/core/test/fuzztest/getdeviceprofile_fuzzer/getdeviceprofile_fuzzer.cpp delete mode 100644 old/services/core/test/fuzztest/getdeviceprofile_fuzzer/getdeviceprofile_fuzzer.h delete mode 100644 old/services/core/test/fuzztest/getdeviceprofile_fuzzer/project.xml delete mode 100755 old/services/core/test/fuzztest/putdeviceprofile_fuzzer/BUILD.gn delete mode 100644 old/services/core/test/fuzztest/putdeviceprofile_fuzzer/corpus/init delete mode 100644 old/services/core/test/fuzztest/putdeviceprofile_fuzzer/project.xml delete mode 100644 old/services/core/test/fuzztest/putdeviceprofile_fuzzer/putdeviceprofile_fuzzer.cpp delete mode 100644 old/services/core/test/fuzztest/putdeviceprofile_fuzzer/putdeviceprofile_fuzzer.h delete mode 100755 old/services/core/test/fuzztest/putdeviceprofileinner_fuzzer/BUILD.gn delete mode 100644 old/services/core/test/fuzztest/putdeviceprofileinner_fuzzer/corpus/init delete mode 100644 old/services/core/test/fuzztest/putdeviceprofileinner_fuzzer/project.xml delete mode 100644 old/services/core/test/fuzztest/putdeviceprofileinner_fuzzer/putdeviceprofileinner_fuzzer.cpp delete mode 100644 old/services/core/test/fuzztest/putdeviceprofileinner_fuzzer/putdeviceprofileinner_fuzzer.h delete mode 100755 old/services/core/test/fuzztest/subscribeprofileeventinner_fuzzer/BUILD.gn delete mode 100644 old/services/core/test/fuzztest/subscribeprofileeventinner_fuzzer/corpus/init delete mode 100644 old/services/core/test/fuzztest/subscribeprofileeventinner_fuzzer/project.xml delete mode 100644 old/services/core/test/fuzztest/subscribeprofileeventinner_fuzzer/subscribeprofileeventinner_fuzzer.cpp delete mode 100644 old/services/core/test/fuzztest/subscribeprofileeventinner_fuzzer/subscribeprofileeventinner_fuzzer.h delete mode 100755 old/services/core/test/fuzztest/syncdeviceprofileinner_fuzzer/BUILD.gn delete mode 100644 old/services/core/test/fuzztest/syncdeviceprofileinner_fuzzer/corpus/init delete mode 100644 old/services/core/test/fuzztest/syncdeviceprofileinner_fuzzer/project.xml delete mode 100644 old/services/core/test/fuzztest/syncdeviceprofileinner_fuzzer/syncdeviceprofileinner_fuzzer.cpp delete mode 100644 old/services/core/test/fuzztest/syncdeviceprofileinner_fuzzer/syncdeviceprofileinner_fuzzer.h delete mode 100644 old/services/core/test/unittest/content_sensor_test.cpp delete mode 100644 old/services/core/test/unittest/device_profile_dfx_test.cpp delete mode 100644 old/services/core/test/unittest/device_profile_utils_test.cpp delete mode 100644 old/services/core/test/unittest/distributed_device_profile_stub_test.cpp delete mode 100644 old/services/core/test/unittest/event_subscribe_test.cpp delete mode 100644 old/services/core/test/unittest/profile_authority_test.cpp delete mode 100644 old/services/core/test/unittest/profile_change_handler_test.cpp delete mode 100644 old/services/core/test/unittest/profile_change_notification_test.cpp delete mode 100644 old/services/core/test/unittest/profile_crud_test.cpp delete mode 100644 old/services/core/test/unittest/profile_dm_test.cpp delete mode 100644 old/services/core/test/unittest/profile_entry_test.cpp delete mode 100644 old/services/core/test/unittest/profile_event_notifier_proxy_test.cpp delete mode 100644 old/services/core/test/unittest/profile_proxy_test.cpp delete mode 100644 old/services/core/test/unittest/profile_storage_test.cpp delete mode 100644 old/services/core/test/unittest/profile_sync_test.cpp delete mode 100644 old/services/core/test/unittest/service_profile_test.cpp delete mode 100644 old/services/core/test/unittest/subscribe_info_checker_test.cpp delete mode 100644 old/services/core/test/unittest/subscribe_info_test.cpp delete mode 100644 old/services/core/test/unittest/subscribe_manager_test.cpp delete mode 100644 old/services/core/test/unittest/test_util.cpp delete mode 100644 old/services/core/test/unittest/test_util.h delete mode 100644 old/services/core/test/unittest/utils.h delete mode 100644 old/test/resource/BUILD.gn delete mode 100644 old/test/resource/authority/invalid_authority.json delete mode 100644 old/test/resource/authority/valid_authority.json delete mode 100644 old/test/resource/ohos_test.xml delete mode 100644 old/tools/dp/BUILD.gn delete mode 100644 old/tools/dp/include/dp_command.h delete mode 100644 old/tools/dp/include/shell_command.h delete mode 100644 old/tools/dp/src/dp_command.cpp delete mode 100644 old/tools/dp/src/main.cpp delete mode 100644 old/tools/dp/src/shell_command.cpp delete mode 100644 services/core/include/distributed_device_profile_stub_new.h delete mode 100644 services/core/test/unittest/distributed_device_profile_stub_new_test.cpp diff --git a/bundle.json b/bundle.json index 4f5ee067..355f8ce7 100644 --- a/bundle.json +++ b/bundle.json @@ -72,8 +72,7 @@ "name": "//foundation/deviceprofile/device_info_manager/interfaces/innerkits/core:distributed_device_profile_sdk", "header": { "header_files": [ - "distributed_device_profile_client.h", - "distributed_device_profile_proxy.h" + "distributed_device_profile_client.h" ], "header_base": "//foundation/deviceprofile/device_info_manager/interfaces/innerkits/core/include/" } @@ -88,8 +87,8 @@ "characteristic_profile.h", "device_profile.h", "dp_subscribe_info.h", + "dp_subscribe_info_extension.h", "dp_sync_options.h", - "i_distributed_device_profile.h", "i_profile_change_listener.h", "i_sync_completed_callback.h", "profile_change_listener_proxy.h", diff --git a/common/BUILD.gn b/common/BUILD.gn index 52a0d330..d4f03880 100644 --- a/common/BUILD.gn +++ b/common/BUILD.gn @@ -61,6 +61,7 @@ ohos_shared_library("distributed_device_profile_common") { "src/interfaces/dp_inited_callback_proxy.cpp", "src/interfaces/dp_inited_callback_stub.cpp", "src/interfaces/dp_subscribe_info.cpp", + "src/interfaces/dp_subscribe_info_extension.cpp", "src/interfaces/dp_sync_options.cpp", "src/interfaces/i_profile_change_listener.cpp", "src/interfaces/local_service_info.cpp", @@ -85,7 +86,10 @@ ohos_shared_library("distributed_device_profile_common") { deps = [] - public_configs = [ ":distributed_device_profile_common_config" ] + public_configs = [ + ":distributed_device_profile_common_config", + "${device_profile_innerkits}:distributed_device_profile_interfaces_ipc_config", + ] external_deps = [ "access_token:libaccesstoken_sdk", diff --git a/common/include/interfaces/access_control_profile.h b/common/include/interfaces/access_control_profile.h index 4edb3da5..c7c87314 100644 --- a/common/include/interfaces/access_control_profile.h +++ b/common/include/interfaces/access_control_profile.h @@ -21,11 +21,11 @@ #include "accesser.h" #include "accessee.h" #include "distributed_device_profile_enums.h" -#include "dp_parcel.h" +#include "message_parcel.h" namespace OHOS { namespace DistributedDeviceProfile { -class AccessControlProfile : public DpParcel { +class AccessControlProfile : public Parcelable { public: AccessControlProfile(); ~AccessControlProfile() = default; @@ -63,9 +63,13 @@ public: void SetDeviceIdHash(const std::string& deviceIdHash); std::string GetExtraData() const; void SetExtraData(const std::string& extraData); - bool Marshalling(MessageParcel& parcel) const override; - bool UnMarshalling(MessageParcel& parcel) override; - std::string dump() const override; + bool Marshalling(MessageParcel& parcel) const ; + bool UnMarshalling(MessageParcel& parcel) ; + std::string dump() const ; + + bool ReadFromParcel(Parcel &parcel); + virtual bool Marshalling(Parcel &parcel) const override; + static AccessControlProfile *Unmarshalling(Parcel &parcel); private: int64_t accessControlId_; diff --git a/common/include/interfaces/characteristic_profile.h b/common/include/interfaces/characteristic_profile.h index 57523ba0..af4e6d99 100644 --- a/common/include/interfaces/characteristic_profile.h +++ b/common/include/interfaces/characteristic_profile.h @@ -19,11 +19,11 @@ #include #include #include "distributed_device_profile_constants.h" -#include "dp_parcel.h" +#include "message_parcel.h" namespace OHOS { namespace DistributedDeviceProfile { -class CharacteristicProfile : public DpParcel { +class CharacteristicProfile : public Parcelable { public: CharacteristicProfile(const std::string& deviceId, const std::string& serviceName, const std::string& characteristicKey, const std::string& characteristicValue) @@ -57,11 +57,14 @@ public: void SetIsMultiUser(bool isMultiUser); int32_t GetUserId() const; void SetUserId(int32_t userId); - bool Marshalling(MessageParcel& parcel) const override; - bool UnMarshalling(MessageParcel& parcel) override; + bool Marshalling(MessageParcel& parcel) const; + bool UnMarshalling(MessageParcel& parcel); bool operator!=(const CharacteristicProfile& charProfile) const; - std::string dump() const override; + std::string dump() const; + bool ReadFromParcel(Parcel &parcel); + virtual bool Marshalling(Parcel &parcel) const override; + static CharacteristicProfile *Unmarshalling(Parcel &parcel); private: std::string deviceId_ = ""; std::string serviceName_ = ""; diff --git a/common/include/interfaces/device_icon_info.h b/common/include/interfaces/device_icon_info.h index 302f67d6..8865c043 100644 --- a/common/include/interfaces/device_icon_info.h +++ b/common/include/interfaces/device_icon_info.h @@ -19,11 +19,11 @@ #include #include -#include "dp_parcel.h" +#include "message_parcel.h" namespace OHOS { namespace DistributedDeviceProfile { -class DeviceIconInfo : public DpParcel { +class DeviceIconInfo : public Parcelable { public: DeviceIconInfo() : id_(0), @@ -54,11 +54,13 @@ public: void SetUrl(const std::string& url); std::vector GetIcon() const; void SetIcon(const std::vector& icon); - bool Marshalling(MessageParcel& parcel) const override; - bool UnMarshalling(MessageParcel& parcel) override; + bool Marshalling(MessageParcel& parcel) const; + bool UnMarshalling(MessageParcel& parcel); bool operator!=(const DeviceIconInfo& other) const; - std::string dump() const override; - + std::string dump() const; + bool ReadFromParcel(Parcel &parcel); + virtual bool Marshalling(Parcel &parcel) const override; + static DeviceIconInfo *Unmarshalling(Parcel &parcel); private: int32_t id_; std::string productId_; diff --git a/common/include/interfaces/device_icon_info_filter_options.h b/common/include/interfaces/device_icon_info_filter_options.h index 7f5be396..1748eaa3 100644 --- a/common/include/interfaces/device_icon_info_filter_options.h +++ b/common/include/interfaces/device_icon_info_filter_options.h @@ -19,11 +19,11 @@ #include #include -#include "dp_parcel.h" +#include "message_parcel.h" namespace OHOS { namespace DistributedDeviceProfile { -class DeviceIconInfoFilterOptions : public DpParcel { +class DeviceIconInfoFilterOptions : public Parcelable { public: DeviceIconInfoFilterOptions() : internalModel_(""), subProductId_(""), imageType_(""), specName_("") {} @@ -40,9 +40,12 @@ public: std::string GetSpecName() const; void SetSpecName(const std::string& specName); - bool Marshalling(MessageParcel& parcel) const override; - bool UnMarshalling(MessageParcel& parcel) override; - std::string dump() const override; + bool Marshalling(MessageParcel& parcel) const ; + bool UnMarshalling(MessageParcel& parcel) ; + std::string dump() const ; + bool ReadFromParcel(Parcel &parcel); + virtual bool Marshalling(Parcel &parcel) const override; + static DeviceIconInfoFilterOptions *Unmarshalling(Parcel &parcel); private: std::vector productIds_; diff --git a/common/include/interfaces/device_profile.h b/common/include/interfaces/device_profile.h index 7072a39d..8f4a2df2 100644 --- a/common/include/interfaces/device_profile.h +++ b/common/include/interfaces/device_profile.h @@ -19,11 +19,11 @@ #include #include #include "distributed_device_profile_constants.h" -#include "dp_parcel.h" +#include "message_parcel.h" namespace OHOS { namespace DistributedDeviceProfile { -class DeviceProfile : public DpParcel { +class DeviceProfile : public Parcelable { public: DeviceProfile() : deviceId_(""), @@ -126,10 +126,10 @@ public: void SetAccountId(const std::string& accountId); std::string GetInternalModel() const; void SetInternalModel(const std::string& internalModel); - bool Marshalling(MessageParcel& parcel) const override; - bool UnMarshalling(MessageParcel& parcel) override; + bool Marshalling(MessageParcel& parcel) const; + bool UnMarshalling(MessageParcel& parcel); bool operator!=(const DeviceProfile& deviceProfile) const; - std::string dump() const override; + std::string dump() const; std::string AnnoymizeDump() const; const std::string GetBleMac() const; void SetBleMac(const std::string& bleMac); @@ -139,6 +139,9 @@ public: void SetSleMac(const std::string& sleMac); int32_t GetSetupType() const; void SetSetupType(int32_t setupType); + bool ReadFromParcel(Parcel &parcel); + virtual bool Marshalling(Parcel &parcel) const override; + static DeviceProfile *Unmarshalling(Parcel &parcel); private: std::string deviceId_; std::string deviceName_; diff --git a/common/include/interfaces/device_profile_filter_options.h b/common/include/interfaces/device_profile_filter_options.h index db28c64c..4ebae664 100644 --- a/common/include/interfaces/device_profile_filter_options.h +++ b/common/include/interfaces/device_profile_filter_options.h @@ -18,11 +18,11 @@ #include #include "distributed_device_profile_enums.h" -#include "dp_parcel.h" +#include "message_parcel.h" namespace OHOS { namespace DistributedDeviceProfile { -class DeviceProfileFilterOptions : public DpParcel { +class DeviceProfileFilterOptions : public Parcelable { public: DeviceProfileFilterOptions() : userId_(-1), @@ -43,9 +43,13 @@ public: std::vector GetDeviceProfileIds() const; void SetDeviceProfileIds(std::vector deviceProfileIds); void AddDeviceProfileIds(int32_t deviceProfileId); - bool Marshalling(MessageParcel& parcel) const override; - bool UnMarshalling(MessageParcel& parcel) override; - std::string dump() const override; + bool Marshalling(MessageParcel& parcel) const ; + bool UnMarshalling(MessageParcel& parcel) ; + std::string dump() const ; + + bool ReadFromParcel(Parcel &parcel); + virtual bool Marshalling(Parcel &parcel) const override; + static DeviceProfileFilterOptions *Unmarshalling(Parcel &parcel); private: int32_t userId_; diff --git a/common/include/interfaces/dp_subscribe_info.h b/common/include/interfaces/dp_subscribe_info.h index 2429d262..99a03a01 100644 --- a/common/include/interfaces/dp_subscribe_info.h +++ b/common/include/interfaces/dp_subscribe_info.h @@ -18,7 +18,7 @@ #include #include -#include "dp_parcel.h" +#include "message_parcel.h" #include "macro_utils.h" #include "iremote_broker.h" #include "i_profile_change_listener.h" @@ -26,7 +26,7 @@ namespace OHOS { namespace DistributedDeviceProfile { -class SubscribeInfo : public DpParcel { +class SubscribeInfo { public: SubscribeInfo(int32_t saId, const std::string& subscribeKey, std::unordered_set subscribeChangeTypes, sptr profileChangeListener, @@ -50,9 +50,9 @@ public: void SetListener(sptr listener); std::unordered_set GetProfileChangeTypes() const; void AddProfileChangeType(ProfileChangeType profileChangeType); - bool Marshalling(MessageParcel& parcel) const override; - bool UnMarshalling(MessageParcel& parcel) override; - std::string dump() const override; + bool Marshalling(MessageParcel& parcel) const ; + bool UnMarshalling(MessageParcel& parcel) ; + std::string dump() const ; private: int32_t saId_ = -1; diff --git a/common/include/interfaces/dp_subscribe_info_extension.h b/common/include/interfaces/dp_subscribe_info_extension.h new file mode 100644 index 00000000..d7ca7b91 --- /dev/null +++ b/common/include/interfaces/dp_subscribe_info_extension.h @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * 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. + */ + +#ifndef OHOS_DP_SUBSCRIBER_INFO_EXTENSION_H +#define OHOS_DP_SUBSCRIBER_INFO_EXTENSION_H + +#include +#include +#include "message_parcel.h" +#include "macro_utils.h" +#include "iremote_broker.h" +#include "i_profile_change_listener.h" +#include "distributed_device_profile_constants.h" +#include "dp_subscribe_info.h" + + +namespace OHOS { +namespace DistributedDeviceProfile { +class SubscribeInfoExtension : public Parcelable, public SubscribeInfo +{ +public: + SubscribeInfoExtension(int32_t saId, const std::string& subscribeKey, + std::unordered_set subscribeChangeTypes, + sptr profileChangeListener, + int32_t userId = DEFAULT_USER_ID) ; + SubscribeInfoExtension(const SubscribeInfo& subscribeInfo); + SubscribeInfoExtension() ; + ~SubscribeInfoExtension() ; + + bool ReadFromParcel(Parcel &parcel); + virtual bool Marshalling(Parcel &parcel) const override; + static SubscribeInfoExtension *Unmarshalling(Parcel &parcel); + +private: + int32_t saId_ = -1; + std::string subscribeKey_ = ""; + std::unordered_set subscribeChangeTypes_; + sptr listener_ = nullptr; + +}; + +class SubscribeExtensionCompare : public SubscribeCompare { +public: + SubscribeExtensionCompare() = default; + ~SubscribeExtensionCompare() = default; +}; + +class SubscribeExtensionHash : public SubscribeHash { +public: + SubscribeExtensionHash() = default; + ~SubscribeExtensionHash() = default; +}; +} // namespace DistributedDeviceProfile +} // namespace OHOS + +#endif // OHOS_DP_SUBSCRIBER_INFO_EXTENSION_H \ No newline at end of file diff --git a/common/include/interfaces/dp_sync_options.h b/common/include/interfaces/dp_sync_options.h index ceaf502c..bd1617e7 100644 --- a/common/include/interfaces/dp_sync_options.h +++ b/common/include/interfaces/dp_sync_options.h @@ -19,13 +19,13 @@ #include #include #include -#include "dp_parcel.h" +#include "message_parcel.h" #include "distributed_device_profile_constants.h" #include "distributed_device_profile_enums.h" namespace OHOS { namespace DistributedDeviceProfile { -class DpSyncOptions : public DpParcel { +class DpSyncOptions : public Parcelable { public: DpSyncOptions() = default; ~DpSyncOptions() = default; @@ -35,10 +35,13 @@ public: void AddDevice(const std::string& deviceId); void SetSyncMode(SyncMode mode); - bool Marshalling(MessageParcel& parcel) const override; - bool UnMarshalling(MessageParcel& parcel) override; - std::string dump() const override; + bool Marshalling(MessageParcel& parcel) const ; + bool UnMarshalling(MessageParcel& parcel) ; + std::string dump() const ; + bool ReadFromParcel(Parcel &parcel); + virtual bool Marshalling(Parcel &parcel) const override; + static DpSyncOptions *Unmarshalling(Parcel &parcel); private: SyncMode syncMode_{SyncMode::PUSH_PULL}; std::vector syncDeviceIds_; diff --git a/common/include/interfaces/i_distributed_device_profile.h b/common/include/interfaces/i_distributed_device_profile.h deleted file mode 100644 index b459ecc6..00000000 --- a/common/include/interfaces/i_distributed_device_profile.h +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2023-2025 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DP_I_DISTRIBUTED_DEVICE_PROFILE_H -#define OHOS_DP_I_DISTRIBUTED_DEVICE_PROFILE_H - -#include - -#include "iremote_broker.h" - -#include "access_control_profile.h" -#include "characteristic_profile.h" -#include "device_icon_info.h" -#include "device_icon_info_filter_options.h" -#include "device_profile.h" -#include "device_profile_filter_options.h" -#include "dp_subscribe_info.h" -#include "dp_sync_options.h" -#include "i_sync_completed_callback.h" -#include "product_info.h" -#include "service_info_profile.h" -#include "service_info_unique_key.h" -#include "service_profile.h" -#include "trust_device_profile.h" -#include "trusted_device_info.h" -#include "local_service_info.h" - -namespace OHOS { -namespace DistributedDeviceProfile { -class IDistributedDeviceProfile : public OHOS::IRemoteBroker { -public: - DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.DeviceProfile.IDistributedDeviceProfile"); - IDistributedDeviceProfile() = default; - virtual ~IDistributedDeviceProfile() = default; - virtual int32_t PutAccessControlProfile(const AccessControlProfile& aclProfile) = 0; - virtual int32_t UpdateAccessControlProfile(const AccessControlProfile& aclProfile) = 0; - virtual int32_t GetTrustDeviceProfile(const std::string& deviceId, TrustDeviceProfile& trustDeviceProfile) = 0; - virtual int32_t GetAllTrustDeviceProfile(std::vector& trustDeviceProfiles) = 0; - virtual int32_t GetAccessControlProfile(std::map queryParams, - std::vector& accessControlProfiles) = 0; - virtual int32_t GetAllAccessControlProfile(std::vector& accessControlProfiles) = 0; - virtual int32_t GetAllAclIncludeLnnAcl(std::vector& accessControlProfiles) = 0; - virtual int32_t DeleteAccessControlProfile(int32_t accessControlId) = 0; - virtual int32_t PutSessionKey(uint32_t userId, const std::vector& sessionKey, int32_t& sessionKeyId) = 0; - virtual int32_t GetSessionKey(uint32_t userId, int32_t sessionKeyId, std::vector& sessionKey) = 0; - virtual int32_t UpdateSessionKey(uint32_t userId, int32_t sessionKeyId, const std::vector& sessionKey) = 0; - virtual int32_t DeleteSessionKey(uint32_t userId, int32_t sessionKeyId) = 0; - virtual int32_t PutDeviceProfileBatch(std::vector& deviceProfiles) = 0; - virtual int32_t PutServiceProfile(const ServiceProfile& serviceProfile) = 0; - virtual int32_t PutServiceProfileBatch(const std::vector& serviceProfiles) = 0; - virtual int32_t PutCharacteristicProfile(const CharacteristicProfile& charProfile) = 0; - virtual int32_t PutCharacteristicProfileBatch(const std::vector& charProfiles) = 0; - virtual int32_t GetDeviceProfile(const std::string& deviceId, DeviceProfile& deviceProfile) = 0; - virtual int32_t GetDeviceProfiles(DeviceProfileFilterOptions& options, - std::vector& deviceProfiles) = 0; - virtual int32_t DeleteDeviceProfileBatch(std::vector& deviceProfiles) = 0; - virtual int32_t GetServiceProfile(const std::string& deviceId, const std::string& serviceName, - ServiceProfile& serviceProfile) = 0; - virtual int32_t GetCharacteristicProfile(const std::string& deviceId, const std::string& serviceName, - const std::string& characteristicId, CharacteristicProfile& charProfile) = 0; - virtual int32_t DeleteServiceProfile(const std::string& deviceId, const std::string& serviceName, - bool isMultiUser = false, int32_t userId = DEFAULT_USER_ID) = 0; - virtual int32_t DeleteCharacteristicProfile(const std::string& deviceId, const std::string& serviceName, - const std::string& characteristicId, bool isMultiUser = false, int32_t userId = DEFAULT_USER_ID) = 0; - virtual int32_t SubscribeDeviceProfile(const SubscribeInfo& subscribeInfo) = 0; - virtual int32_t UnSubscribeDeviceProfile(const SubscribeInfo& subscribeInfo) = 0; - virtual int32_t SubscribeDeviceProfileInited(int32_t saId, sptr dpInitedCallback) = 0; - virtual int32_t UnSubscribeDeviceProfileInited(int32_t saId) = 0; - virtual int32_t SubscribePinCodeInvalid(const std::string& bundleName, int32_t pinExchangeType, - sptr pinCodeCallback) = 0; - virtual int32_t UnSubscribePinCodeInvalid(const std::string& bundleName, int32_t pinExchangeType) = 0; - virtual int32_t SyncDeviceProfile(const DistributedDeviceProfile::DpSyncOptions& syncOptions, - sptr syncCompletedCallback) = 0; - virtual int32_t SendSubscribeInfos(std::map listenerMap) = 0; - virtual int32_t PutAllTrustedDevices(const std::vector deviceInfos) = 0; - virtual int32_t PutProductInfoBatch(const std::vector& productInfos) = 0; - virtual int32_t PutDeviceIconInfoBatch(const std::vector& deviceIconInfos) = 0; - virtual int32_t GetDeviceIconInfos(const DeviceIconInfoFilterOptions& filterOptions, - std::vector& deviceIconInfos) = 0; - virtual int32_t PutServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) = 0; - virtual int32_t DeleteServiceInfoProfile(const ServiceInfoUniqueKey& key) = 0; - virtual int32_t UpdateServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) = 0; - virtual int32_t GetServiceInfoProfileByUniqueKey(const ServiceInfoUniqueKey& key, - ServiceInfoProfile& serviceInfoProfile) = 0; - virtual int32_t GetServiceInfoProfileListByTokenId(const ServiceInfoUniqueKey& key, - std::vector& serviceInfoProfiles) = 0; - virtual int32_t GetAllServiceInfoProfileList(std::vector& serviceInfoProfiles) = 0; - virtual int32_t GetServiceInfoProfileListByBundleName(const ServiceInfoUniqueKey& key, - std::vector& serviceInfoProfiles) = 0; - virtual int32_t PutLocalServiceInfo(const LocalServiceInfo& localServiceInfo) = 0; - virtual int32_t UpdateLocalServiceInfo(const LocalServiceInfo& localServiceInfo) = 0; - virtual int32_t GetLocalServiceInfoByBundleAndPinType(const std::string& bundleName, - int32_t pinExchangeType, LocalServiceInfo& localServiceInfo) = 0; - virtual int32_t DeleteLocalServiceInfo(const std::string& bundleName, int32_t pinExchangeType) = 0; -}; -} // namespace DistributedDeviceProfile -} // namespace OHOS -#endif // OHOS_DP_I_DISTRIBUTED_DEVICE_PROFILE_H diff --git a/common/include/interfaces/local_service_info.h b/common/include/interfaces/local_service_info.h index 26b682c7..bd2386d1 100644 --- a/common/include/interfaces/local_service_info.h +++ b/common/include/interfaces/local_service_info.h @@ -20,11 +20,11 @@ #include #include "distributed_device_profile_constants.h" -#include "dp_parcel.h" +#include "message_parcel.h" namespace OHOS { namespace DistributedDeviceProfile { -class LocalServiceInfo : public DpParcel { +class LocalServiceInfo : public Parcelable { public: LocalServiceInfo(const std::string& bundleName, const int32_t authBoxType, const int32_t authType, const int32_t pinExchangeType, @@ -56,9 +56,13 @@ public: std::string GetExtraInfo() const; void SetExtraInfo(const std::string& extraInfo); - bool Marshalling(MessageParcel& parcel) const override; - bool UnMarshalling(MessageParcel& parcel) override; - std::string dump() const override; + bool Marshalling(MessageParcel& parcel) const ; + bool UnMarshalling(MessageParcel& parcel) ; + std::string dump() const; + + bool ReadFromParcel(Parcel &parcel); + virtual bool Marshalling(Parcel &parcel) const override; + static LocalServiceInfo *Unmarshalling(Parcel &parcel); private: std::string bundleName_ = ""; diff --git a/common/include/interfaces/product_info.h b/common/include/interfaces/product_info.h index 3f32690a..bf03da9b 100644 --- a/common/include/interfaces/product_info.h +++ b/common/include/interfaces/product_info.h @@ -19,11 +19,11 @@ #include #include -#include "dp_parcel.h" +#include "message_parcel.h" namespace OHOS { namespace DistributedDeviceProfile { -class ProductInfo : public DpParcel { +class ProductInfo : public Parcelable { public: ProductInfo() : productId_(""), model_(""), @@ -43,10 +43,14 @@ public: void SetProductShortName(const std::string& productShortName); std::string GetImageVersion() const; void SetImageVersion(const std::string& imageVersion); - bool Marshalling(MessageParcel& parcel) const override; - bool UnMarshalling(MessageParcel& parcel) override; + bool Marshalling(MessageParcel& parcel) const ; + bool UnMarshalling(MessageParcel& parcel); bool operator!=(const ProductInfo& other) const; - std::string dump() const override; + std::string dump() const; + + bool ReadFromParcel(Parcel &parcel); + virtual bool Marshalling(Parcel &parcel) const override; + static ProductInfo *Unmarshalling(Parcel &parcel); private: std::string GetAnonyProductName(const std::string& value) const; diff --git a/common/include/interfaces/service_info_profile.h b/common/include/interfaces/service_info_profile.h index f348a92c..894eb2df 100644 --- a/common/include/interfaces/service_info_profile.h +++ b/common/include/interfaces/service_info_profile.h @@ -20,11 +20,11 @@ #include #include "distributed_device_profile_constants.h" -#include "dp_parcel.h" +#include "message_parcel.h" namespace OHOS { namespace DistributedDeviceProfile { -class ServiceInfoProfile : public DpParcel { +class ServiceInfoProfile : public Parcelable { public: ServiceInfoProfile(const std::string& deviceId, const int32_t userId, const std::string& networkId, const std::string& tokenId, const int64_t serviceId, const std::string& serviceType, @@ -98,9 +98,13 @@ public: std::string GetExtraInfo() const; void SetExtraInfo(const std::string& extraInfo); - bool Marshalling(MessageParcel& parcel) const override; - bool UnMarshalling(MessageParcel& parcel) override; - std::string dump() const override; + bool Marshalling(MessageParcel& parcel) const; + bool UnMarshalling(MessageParcel& parcel); + std::string dump() const; + + bool ReadFromParcel(Parcel &parcel); + virtual bool Marshalling(Parcel &parcel) const override; + static ServiceInfoProfile *Unmarshalling(Parcel &parcel); private: std::string deviceId_ = ""; diff --git a/common/include/interfaces/service_info_unique_key.h b/common/include/interfaces/service_info_unique_key.h index 201fc880..a51aeca7 100644 --- a/common/include/interfaces/service_info_unique_key.h +++ b/common/include/interfaces/service_info_unique_key.h @@ -20,11 +20,11 @@ #include #include "distributed_device_profile_constants.h" -#include "dp_parcel.h" +#include "message_parcel.h" namespace OHOS { namespace DistributedDeviceProfile { -class ServiceInfoUniqueKey : public DpParcel { +class ServiceInfoUniqueKey : public Parcelable { public: ServiceInfoUniqueKey(const std::string& deviceId, const int32_t userId, const std::string& tokenId, const int64_t serviceId) @@ -53,9 +53,13 @@ public: void SetBundleName(const std::string& bundleName); bool operator<(const ServiceInfoUniqueKey& rhs) const; - bool Marshalling(MessageParcel& parcel) const override; - bool UnMarshalling(MessageParcel& parcel) override; - std::string dump() const override; + bool Marshalling(MessageParcel& parcel) const ; + bool UnMarshalling(MessageParcel& parcel) ; + std::string dump() const ; + + bool ReadFromParcel(Parcel &parcel); + virtual bool Marshalling(Parcel &parcel) const override; + static ServiceInfoUniqueKey*Unmarshalling(Parcel &parcel); private: std::string deviceId_ = ""; diff --git a/common/include/interfaces/service_profile.h b/common/include/interfaces/service_profile.h index b8ff73bd..0aa099b3 100644 --- a/common/include/interfaces/service_profile.h +++ b/common/include/interfaces/service_profile.h @@ -19,11 +19,12 @@ #include #include #include "distributed_device_profile_constants.h" -#include "dp_parcel.h" +#include "message_parcel.h" +#include "distributed_device_profile_errors.h" namespace OHOS { namespace DistributedDeviceProfile { -class ServiceProfile : public DpParcel { +class ServiceProfile : public Parcelable { public: ServiceProfile(const std::string& deviceId, const std::string& serviceName, const std::string& serviceType); ServiceProfile(const std::string& deviceId, const std::string& serviceName, const std::string& serviceType, @@ -41,10 +42,14 @@ public: void SetIsMultiUser(bool isMultiUser); int32_t GetUserId() const; void SetUserId(int32_t userId); - bool Marshalling(MessageParcel& parcel) const override; - bool UnMarshalling(MessageParcel& parcel) override; + bool Marshalling(MessageParcel& parcel) const; + bool UnMarshalling(MessageParcel& parcel); bool operator!=(const ServiceProfile& serviceProfile) const; - std::string dump() const override; + std::string dump() const; + + bool ReadFromParcel(Parcel &parcel); + virtual bool Marshalling(Parcel &parcel) const override; + static ServiceProfile *Unmarshalling(Parcel &parcel); private: std::string deviceId_ = ""; diff --git a/common/include/interfaces/trust_device_profile.h b/common/include/interfaces/trust_device_profile.h index 8ced271e..e8cd1f2b 100644 --- a/common/include/interfaces/trust_device_profile.h +++ b/common/include/interfaces/trust_device_profile.h @@ -18,11 +18,11 @@ #include #include "distributed_device_profile_enums.h" -#include "dp_parcel.h" +#include "message_parcel.h" namespace OHOS { namespace DistributedDeviceProfile { -class TrustDeviceProfile : public DpParcel { +class TrustDeviceProfile : public Parcelable { public: TrustDeviceProfile() : deviceId_(""), @@ -49,9 +49,13 @@ public: void SetPeerUserId(int32_t peerUserId); int32_t GetLocalUserId() const; void SetLocalUserId(int32_t localUserId); - bool Marshalling(MessageParcel& parcel) const override; - bool UnMarshalling(MessageParcel& parcel) override; - std::string dump() const override; + bool Marshalling(MessageParcel& parcel) const ; + bool UnMarshalling(MessageParcel& parcel) ; + std::string dump() const ; + + bool ReadFromParcel(Parcel &parcel); + virtual bool Marshalling(Parcel &parcel) const override; + static TrustDeviceProfile *Unmarshalling(Parcel &parcel); private: std::string deviceId_; diff --git a/common/include/interfaces/trusted_device_info.h b/common/include/interfaces/trusted_device_info.h index 82029040..d94aceaa 100644 --- a/common/include/interfaces/trusted_device_info.h +++ b/common/include/interfaces/trusted_device_info.h @@ -18,11 +18,11 @@ #include #include "distributed_device_profile_constants.h" -#include "dp_parcel.h" +#include "message_parcel.h" namespace OHOS { namespace DistributedDeviceProfile { -class TrustedDeviceInfo : public DpParcel { +class TrustedDeviceInfo : public Parcelable { public: TrustedDeviceInfo() : networkId_(""), authForm_(BINDTYPE_INIT), deviceTypeId_(0), osVersion_(""), osType_(0), udid_(""), uuid_("") @@ -46,9 +46,13 @@ public: bool operator!=(const TrustedDeviceInfo& trustedDeviceInfo) const; bool operator<(const TrustedDeviceInfo& trustedDeviceInfo) const; - bool Marshalling(MessageParcel& parcel) const override; - bool UnMarshalling(MessageParcel& parcel) override; - std::string dump() const override; + bool Marshalling(MessageParcel& parcel) const ; + bool UnMarshalling(MessageParcel& parcel) ; + std::string dump() const ; + + bool ReadFromParcel(Parcel &parcel); + virtual bool Marshalling(Parcel &parcel) const override; + static TrustedDeviceInfo *Unmarshalling(Parcel &parcel); private: std::string networkId_; diff --git a/common/include/utils/ipc_utils.h b/common/include/utils/ipc_utils.h index 4d3ba092..34300b12 100644 --- a/common/include/utils/ipc_utils.h +++ b/common/include/utils/ipc_utils.h @@ -33,6 +33,7 @@ #include "distributed_device_profile_errors.h" #include "distributed_device_profile_log.h" #include "dp_subscribe_info.h" +#include "dp_subscribe_info_extension.h" #include "product_info.h" #include "service_info_profile.h" #include "service_profile.h" diff --git a/common/src/interfaces/access_control_profile.cpp b/common/src/interfaces/access_control_profile.cpp index 07fc60a0..cf06f65b 100644 --- a/common/src/interfaces/access_control_profile.cpp +++ b/common/src/interfaces/access_control_profile.cpp @@ -282,5 +282,58 @@ std::string AccessControlProfile::dump() const cJSON_free(jsonChars); return jsonStr; } + +bool AccessControlProfile::ReadFromParcel(Parcel &parcel) +{ + READ_HELPER_RET(parcel, Int64, accessControlId_, false); + READ_HELPER_RET(parcel, Int64, accesserId_, false); + READ_HELPER_RET(parcel, Int64, accesseeId_, false); + READ_HELPER_RET(parcel, String, sessionKey_, false); + READ_HELPER_RET(parcel, Uint32, bindType_, false); + READ_HELPER_RET(parcel, Uint32, authenticationType_, false); + READ_HELPER_RET(parcel, Uint32, bindLevel_, false); + READ_HELPER_RET(parcel, Int32, status_, false); + READ_HELPER_RET(parcel, Int64, validPeriod_, false); + READ_HELPER_RET(parcel, Int64, lastAuthTime_, false); + READ_HELPER_RET(parcel, String, trustDeviceId_, false); + READ_HELPER_RET(parcel, Uint32, deviceIdType_, false); + READ_HELPER_RET(parcel, String, deviceIdHash_, false); + READ_HELPER_RET(parcel, String, extraData_, false); + return true; +} + +AccessControlProfile *AccessControlProfile::Unmarshalling(Parcel &parcel) +{ + AccessControlProfile *accessControlProfile = new (std::nothrow) AccessControlProfile(); + if (accessControlProfile == nullptr) { + return nullptr; + } + + if (!accessControlProfile->ReadFromParcel(parcel)) { + delete accessControlProfile; + accessControlProfile = nullptr; + } + + return accessControlProfile; +} + +bool AccessControlProfile::Marshalling(Parcel& parcel) const +{ + WRITE_HELPER_RET(parcel, Int64, accessControlId_, false); + WRITE_HELPER_RET(parcel, Int64, accesserId_, false); + WRITE_HELPER_RET(parcel, Int64, accesseeId_, false); + WRITE_HELPER_RET(parcel, String, sessionKey_, false); + WRITE_HELPER_RET(parcel, Uint32, bindType_, false); + WRITE_HELPER_RET(parcel, Uint32, authenticationType_, false); + WRITE_HELPER_RET(parcel, Uint32, bindLevel_, false); + WRITE_HELPER_RET(parcel, Int32, status_, false); + WRITE_HELPER_RET(parcel, Int32, validPeriod_, false); + WRITE_HELPER_RET(parcel, Int32, lastAuthTime_, false); + WRITE_HELPER_RET(parcel, String, trustDeviceId_, false); + WRITE_HELPER_RET(parcel, Uint32, deviceIdType_, false); + WRITE_HELPER_RET(parcel, String, deviceIdHash_, false); + WRITE_HELPER_RET(parcel, String, extraData_, false); + return true; +} } // namespace DistributedDeviceProfile } // namespace OHOS \ No newline at end of file diff --git a/common/src/interfaces/characteristic_profile.cpp b/common/src/interfaces/characteristic_profile.cpp index 13123602..abfedbc9 100644 --- a/common/src/interfaces/characteristic_profile.cpp +++ b/common/src/interfaces/characteristic_profile.cpp @@ -148,5 +148,42 @@ std::string CharacteristicProfile::dump() const cJSON_free(jsonChars); return jsonStr; } + +bool CharacteristicProfile::ReadFromParcel(Parcel &parcel) +{ + READ_HELPER_RET(parcel, String, deviceId_, false); + READ_HELPER_RET(parcel, String, serviceName_, false); + READ_HELPER_RET(parcel, String, characteristicKey_, false); + READ_HELPER_RET(parcel, String, characteristicValue_, false); + READ_HELPER_RET(parcel, Bool, isMultiUser_, false); + READ_HELPER_RET(parcel, Int32, userId_, false); + return true; +} + +CharacteristicProfile *CharacteristicProfile::Unmarshalling(Parcel &parcel) +{ + CharacteristicProfile *characteristicProfile = new (std::nothrow) CharacteristicProfile(); + if (characteristicProfile == nullptr) { + return nullptr; + } + + if (!characteristicProfile->ReadFromParcel(parcel)) { + delete characteristicProfile; + characteristicProfile = nullptr; + } + + return characteristicProfile; +} + +bool CharacteristicProfile::Marshalling(Parcel& parcel) const +{ + WRITE_HELPER_RET(parcel, String, deviceId_, false); + WRITE_HELPER_RET(parcel, String, serviceName_, false); + WRITE_HELPER_RET(parcel, String, characteristicKey_, false); + WRITE_HELPER_RET(parcel, String, characteristicValue_, false); + WRITE_HELPER_RET(parcel, Bool, isMultiUser_, false); + WRITE_HELPER_RET(parcel, Int32, userId_, false); + return true; +} } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/common/src/interfaces/device_icon_info.cpp b/common/src/interfaces/device_icon_info.cpp index 8587c3fc..71f930de 100644 --- a/common/src/interfaces/device_icon_info.cpp +++ b/common/src/interfaces/device_icon_info.cpp @@ -198,5 +198,46 @@ std::string DeviceIconInfo::dump() const cJSON_free(jsonChars); return jsonStr; } + +bool DeviceIconInfo::ReadFromParcel(Parcel &parcel) +{ + READ_HELPER_RET(parcel, String, productId_, false); + READ_HELPER_RET(parcel, String, internalModel_, false); + READ_HELPER_RET(parcel, String, subProductId_, false); + READ_HELPER_RET(parcel, String, imageType_, false); + READ_HELPER_RET(parcel, String, specName_, false); + READ_HELPER_RET(parcel, String, version_, false); + READ_HELPER_RET(parcel, String, wiseVersion_, false); + READ_HELPER_RET(parcel, String, url_, false); + return true; +} + +DeviceIconInfo *DeviceIconInfo::Unmarshalling(Parcel &parcel) +{ + DeviceIconInfo *deviceIconInfo = new (std::nothrow) DeviceIconInfo(); + if (deviceIconInfo == nullptr) { + return nullptr; + } + + if (!deviceIconInfo->ReadFromParcel(parcel)) { + delete deviceIconInfo; + deviceIconInfo = nullptr; + } + + return deviceIconInfo; +} + +bool DeviceIconInfo::Marshalling(Parcel& parcel) const +{ + WRITE_HELPER_RET(parcel, String, productId_, false); + WRITE_HELPER_RET(parcel, String, internalModel_, false); + WRITE_HELPER_RET(parcel, String, subProductId_, false); + WRITE_HELPER_RET(parcel, String, imageType_, false); + WRITE_HELPER_RET(parcel, String, specName_, false); + WRITE_HELPER_RET(parcel, String, version_, false); + WRITE_HELPER_RET(parcel, String, wiseVersion_, false); + WRITE_HELPER_RET(parcel, String, url_, false); + return true; +} } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/common/src/interfaces/device_icon_info_filter_options.cpp b/common/src/interfaces/device_icon_info_filter_options.cpp index 2426a342..a4143c81 100644 --- a/common/src/interfaces/device_icon_info_filter_options.cpp +++ b/common/src/interfaces/device_icon_info_filter_options.cpp @@ -142,5 +142,38 @@ std::string DeviceIconInfoFilterOptions::dump() const cJSON_free(jsonChars); return jsonStr; } + +bool DeviceIconInfoFilterOptions::ReadFromParcel(Parcel &parcel) +{ + READ_HELPER_RET(parcel, String, internalModel_, false); + READ_HELPER_RET(parcel, String, subProductId_, false); + READ_HELPER_RET(parcel, String, imageType_, false); + READ_HELPER_RET(parcel, String, specName_, false); + return true; +} + +DeviceIconInfoFilterOptions *DeviceIconInfoFilterOptions::Unmarshalling(Parcel &parcel) +{ + DeviceIconInfoFilterOptions *deviceIconInfoFilterOptions = new (std::nothrow) DeviceIconInfoFilterOptions(); + if (deviceIconInfoFilterOptions == nullptr) { + return nullptr; + } + + if (!deviceIconInfoFilterOptions->ReadFromParcel(parcel)) { + delete deviceIconInfoFilterOptions; + deviceIconInfoFilterOptions = nullptr; + } + + return deviceIconInfoFilterOptions; +} + +bool DeviceIconInfoFilterOptions::Marshalling(Parcel& parcel) const +{ + WRITE_HELPER_RET(parcel, String, internalModel_, false); + WRITE_HELPER_RET(parcel, String, subProductId_, false); + WRITE_HELPER_RET(parcel, String, imageType_, false); + WRITE_HELPER_RET(parcel, String, specName_, false); + return true; +} } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/common/src/interfaces/device_profile.cpp b/common/src/interfaces/device_profile.cpp index c2d49df6..566aa1c2 100644 --- a/common/src/interfaces/device_profile.cpp +++ b/common/src/interfaces/device_profile.cpp @@ -544,5 +544,98 @@ std::string DeviceProfile::AnnoymizeDump() const cJSON_free(jsonChars); return jsonStr; } + +bool DeviceProfile::ReadFromParcel(Parcel &parcel) +{ + READ_HELPER_RET(parcel, String, deviceId_, false); + READ_HELPER_RET(parcel, String, deviceName_, false); + READ_HELPER_RET(parcel, String, manufactureName_, false); + READ_HELPER_RET(parcel, String, deviceModel_, false); + READ_HELPER_RET(parcel, Int64, storageCapability_, false); + READ_HELPER_RET(parcel, String, osSysCap_, false); + READ_HELPER_RET(parcel, Int32, osApiLevel_, false); + READ_HELPER_RET(parcel, String, osVersion_, false); + READ_HELPER_RET(parcel, Int32, osType_, false); + READ_HELPER_RET(parcel, Bool, isMultiUser_, false); + READ_HELPER_RET(parcel, Int32, userId_, false); + READ_HELPER_RET(parcel, String, devType_, false); + READ_HELPER_RET(parcel, String, manu_, false); + READ_HELPER_RET(parcel, String, sn_, false); + READ_HELPER_RET(parcel, String, productId_, false); + READ_HELPER_RET(parcel, String, productName_, false); + READ_HELPER_RET(parcel, String, subProductId_, false); + READ_HELPER_RET(parcel, String, hiv_, false); + READ_HELPER_RET(parcel, String, mac_, false); + READ_HELPER_RET(parcel, String, fwv_, false); + READ_HELPER_RET(parcel, String, hwv_, false); + READ_HELPER_RET(parcel, String, swv_, false); + READ_HELPER_RET(parcel, Int32, protType_, false); + READ_HELPER_RET(parcel, String, wiseUserId_, false); + READ_HELPER_RET(parcel, String, wiseDeviceId_, false); + READ_HELPER_RET(parcel, String, registerTime_, false); + READ_HELPER_RET(parcel, String, modifyTime_, false); + READ_HELPER_RET(parcel, String, shareTime_, false); + READ_HELPER_RET(parcel, String, accountId_, false); + READ_HELPER_RET(parcel, String, internalModel_, false); + READ_HELPER_RET(parcel, String, bleMac_, false); + READ_HELPER_RET(parcel, String, brMac_, false); + READ_HELPER_RET(parcel, String, sleMac_, false); + READ_HELPER_RET(parcel, Int32, setupType_, false); + return true; +} + +DeviceProfile *DeviceProfile::Unmarshalling(Parcel &parcel) +{ + DeviceProfile *deviceProfile = new (std::nothrow) DeviceProfile(); + if (deviceProfile == nullptr) { + return nullptr; + } + + if (!deviceProfile->ReadFromParcel(parcel)) { + delete deviceProfile; + deviceProfile = nullptr; + } + + return deviceProfile; +} + +bool DeviceProfile::Marshalling(Parcel& parcel) const +{ + WRITE_HELPER_RET(parcel, String, deviceId_, false); + WRITE_HELPER_RET(parcel, String, deviceName_, false); + WRITE_HELPER_RET(parcel, String, manufactureName_, false); + WRITE_HELPER_RET(parcel, String, deviceModel_, false); + WRITE_HELPER_RET(parcel, Int64, storageCapability_, false); + WRITE_HELPER_RET(parcel, String, osSysCap_, false); + WRITE_HELPER_RET(parcel, Int32, osApiLevel_, false); + WRITE_HELPER_RET(parcel, String, osVersion_, false); + WRITE_HELPER_RET(parcel, Int32, osType_, false); + WRITE_HELPER_RET(parcel, Bool, isMultiUser_, false); + WRITE_HELPER_RET(parcel, Int32, userId_, false); + WRITE_HELPER_RET(parcel, String, devType_, false); + WRITE_HELPER_RET(parcel, String, manu_, false); + WRITE_HELPER_RET(parcel, String, sn_, false); + WRITE_HELPER_RET(parcel, String, productId_, false); + WRITE_HELPER_RET(parcel, String, productName_, false); + WRITE_HELPER_RET(parcel, String, subProductId_, false); + WRITE_HELPER_RET(parcel, String, hiv_, false); + WRITE_HELPER_RET(parcel, String, mac_, false); + WRITE_HELPER_RET(parcel, String, fwv_, false); + WRITE_HELPER_RET(parcel, String, hwv_, false); + WRITE_HELPER_RET(parcel, String, swv_, false); + WRITE_HELPER_RET(parcel, Int32, protType_, false); + WRITE_HELPER_RET(parcel, String, wiseUserId_, false); + WRITE_HELPER_RET(parcel, String, wiseDeviceId_, false); + WRITE_HELPER_RET(parcel, String, registerTime_, false); + WRITE_HELPER_RET(parcel, String, modifyTime_, false); + WRITE_HELPER_RET(parcel, String, shareTime_, false); + WRITE_HELPER_RET(parcel, String, accountId_, false); + WRITE_HELPER_RET(parcel, String, internalModel_, false); + WRITE_HELPER_RET(parcel, String, bleMac_, false); + WRITE_HELPER_RET(parcel, String, brMac_, false); + WRITE_HELPER_RET(parcel, String, sleMac_, false); + WRITE_HELPER_RET(parcel, Int32, setupType_, false); + return true; +} } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/common/src/interfaces/device_profile_filter_options.cpp b/common/src/interfaces/device_profile_filter_options.cpp index af1d1999..4d4d78ef 100644 --- a/common/src/interfaces/device_profile_filter_options.cpp +++ b/common/src/interfaces/device_profile_filter_options.cpp @@ -149,5 +149,34 @@ std::string DeviceProfileFilterOptions::dump() const cJSON_free(jsonChars); return jsonStr; } + +bool DeviceProfileFilterOptions::ReadFromParcel(Parcel &parcel) +{ + READ_HELPER_RET(parcel, Int32, userId_, false); + READ_HELPER_RET(parcel, String, accountId_, false); + return true; +} + +DeviceProfileFilterOptions *DeviceProfileFilterOptions::Unmarshalling(Parcel &parcel) +{ + DeviceProfileFilterOptions *deviceProfileFilterOptions = new (std::nothrow) DeviceProfileFilterOptions(); + if (deviceProfileFilterOptions == nullptr) { + return nullptr; + } + + if (!deviceProfileFilterOptions->ReadFromParcel(parcel)) { + delete deviceProfileFilterOptions; + deviceProfileFilterOptions = nullptr; + } + + return deviceProfileFilterOptions; +} + +bool DeviceProfileFilterOptions::Marshalling(Parcel& parcel) const +{ + WRITE_HELPER_RET(parcel, Int32, userId_, false); + WRITE_HELPER_RET(parcel, String, accountId_, false); + return true; +} } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/common/src/interfaces/dp_inited_callback_proxy.cpp b/common/src/interfaces/dp_inited_callback_proxy.cpp index c318dc84..284b944e 100644 --- a/common/src/interfaces/dp_inited_callback_proxy.cpp +++ b/common/src/interfaces/dp_inited_callback_proxy.cpp @@ -16,7 +16,7 @@ #include "dp_inited_callback_proxy.h" #include "macro_utils.h" #include "distributed_device_profile_errors.h" -#include "i_distributed_device_profile.h" +#include "idistributed_device_profile.h" #include "message_parcel.h" namespace OHOS { diff --git a/common/src/interfaces/dp_subscribe_info.cpp b/common/src/interfaces/dp_subscribe_info.cpp index 78ee3554..9757a694 100644 --- a/common/src/interfaces/dp_subscribe_info.cpp +++ b/common/src/interfaces/dp_subscribe_info.cpp @@ -204,4 +204,3 @@ std::string SubscribeInfo::dump() const } } // namespace DistributedDeviceProfile } // namespace OHOS - diff --git a/common/src/interfaces/dp_subscribe_info_extension.cpp b/common/src/interfaces/dp_subscribe_info_extension.cpp new file mode 100644 index 00000000..53773330 --- /dev/null +++ b/common/src/interfaces/dp_subscribe_info_extension.cpp @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. + * 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. + */ + + #include "dp_subscribe_info_extension.h" + #include "cJSON.h" + #include "distributed_device_profile_constants.h" + #include "ipc_utils.h" + #include "macro_utils.h" + #include "profile_change_listener_stub.h" + #include "profile_utils.h" + +namespace OHOS { +namespace DistributedDeviceProfile { +namespace { + const std::string TAG = "SubscribeInfoExtension"; +} +SubscribeInfoExtension::SubscribeInfoExtension(int32_t saId, const std::string& subscribeKey, + std::unordered_set subscribeChangeTypes, + sptr profileChangeListener, + int32_t userId) +{ + this->saId_ = saId; + this->subscribeKey_ = subscribeKey; + if (userId != DEFAULT_USER_ID) { + this->subscribeKey_ = this->subscribeKey_ + SEPARATOR + std::to_string(userId); + } + this->subscribeChangeTypes_ = subscribeChangeTypes; + if (profileChangeListener == nullptr) { + HILOGI("constructor!"); + return; + } + if (profileChangeListener->AsObject() == nullptr) { + HILOGI("constructor!"); + return; + } + this->listener_ = profileChangeListener->AsObject(); +} + +SubscribeInfoExtension::SubscribeInfoExtension(const SubscribeInfo& subscribeInfo) +{ + this->saId_ = subscribeInfo.GetSaId(); + this->subscribeKey_ = subscribeInfo.GetSubscribeKey(); + this->subscribeChangeTypes_ = subscribeInfo.GetProfileChangeTypes(); + if (subscribeInfo.GetListener() == nullptr) { + HILOGI("constructor!"); + return; + } + this->listener_ = subscribeInfo.GetListener(); +} + +SubscribeInfoExtension::SubscribeInfoExtension() +{ +} + +SubscribeInfoExtension::~SubscribeInfoExtension() +{ +} + +bool SubscribeInfoExtension::ReadFromParcel(Parcel &parcel) +{ + READ_HELPER_RET(parcel, Int32, saId_, false); + READ_HELPER_RET(parcel, String, subscribeKey_, false); + return true; + +} + +SubscribeInfoExtension *SubscribeInfoExtension::Unmarshalling(Parcel &parcel) +{ + SubscribeInfoExtension *subscribeInfoExtension = new (std::nothrow) SubscribeInfoExtension(); + if (subscribeInfoExtension == nullptr) { + return nullptr; + } + + if (!subscribeInfoExtension->ReadFromParcel(parcel)) { + delete subscribeInfoExtension; + subscribeInfoExtension = nullptr; + } + + return subscribeInfoExtension; +} + +bool SubscribeInfoExtension::Marshalling(Parcel& parcel) const +{ + WRITE_HELPER_RET(parcel, Int32, saId_, false); + WRITE_HELPER_RET(parcel, String, subscribeKey_, false); + WRITE_HELPER_RET(parcel, RemoteObject, listener_, false); + return true; +} +} +} \ No newline at end of file diff --git a/common/src/interfaces/dp_sync_options.cpp b/common/src/interfaces/dp_sync_options.cpp index 4d42d9fc..701fb32b 100644 --- a/common/src/interfaces/dp_sync_options.cpp +++ b/common/src/interfaces/dp_sync_options.cpp @@ -109,5 +109,49 @@ std::string DpSyncOptions::dump() const cJSON_free(jsonChars); return jsonStr; } + +bool DpSyncOptions::ReadFromParcel(Parcel &parcel) +{ + int32_t mode = 0; + READ_HELPER_RET(parcel, Int32, mode, false); + syncMode_ = static_cast(mode); + int32_t size = 0; + READ_HELPER_RET(parcel, Int32, size, false); + if (size > MAX_DEVICE_SIZE) { + return false; + } + for (int32_t i = 0; i < size; i++) { + std::string deviceId; + READ_HELPER_RET(parcel, String, deviceId, false); + syncDeviceIds_.emplace_back(deviceId); + } + return true; + +} + +DpSyncOptions *DpSyncOptions::Unmarshalling(Parcel &parcel) +{ + DpSyncOptions *dpSyncOptions = new (std::nothrow) DpSyncOptions(); + if (dpSyncOptions == nullptr) { + return nullptr; + } + + if (!dpSyncOptions->ReadFromParcel(parcel)) { + delete dpSyncOptions; + dpSyncOptions = nullptr; + } + + return dpSyncOptions; +} + +bool DpSyncOptions::Marshalling(Parcel& parcel) const +{ + WRITE_HELPER_RET(parcel, Int32, static_cast(syncMode_), false); + WRITE_HELPER_RET(parcel, Int32, static_cast(syncDeviceIds_.size()), false); + for (const auto& deviceId : syncDeviceIds_) { + WRITE_HELPER_RET(parcel, String, deviceId, false); + } + return true; +} } // namespace DistributedDeviceProfile } // namespace OHOS \ No newline at end of file diff --git a/common/src/interfaces/local_service_info.cpp b/common/src/interfaces/local_service_info.cpp index ea1579b9..25a50bd5 100644 --- a/common/src/interfaces/local_service_info.cpp +++ b/common/src/interfaces/local_service_info.cpp @@ -131,5 +131,45 @@ std::string LocalServiceInfo::dump() const { return ""; } + +bool LocalServiceInfo::ReadFromParcel(Parcel &parcel) +{ + READ_HELPER_RET(parcel, String, bundleName_, false); + READ_HELPER_RET(parcel, Int32, authBoxType_, false); + READ_HELPER_RET(parcel, Int32, authType_, false); + READ_HELPER_RET(parcel, Int32, pinExchangeType_, false); + READ_HELPER_RET(parcel, String, pinCode_, false); + READ_HELPER_RET(parcel, String, description_, false); + READ_HELPER_RET(parcel, String, extraInfo_, false); + return true; + +} + +LocalServiceInfo *LocalServiceInfo::Unmarshalling(Parcel &parcel) +{ + LocalServiceInfo *localServiceInfo = new (std::nothrow) LocalServiceInfo(); + if (localServiceInfo == nullptr) { + return nullptr; + } + + if (!localServiceInfo->ReadFromParcel(parcel)) { + delete localServiceInfo; + localServiceInfo = nullptr; + } + + return localServiceInfo; +} + +bool LocalServiceInfo::Marshalling(Parcel& parcel) const +{ + WRITE_HELPER_RET(parcel, String, bundleName_, false); + WRITE_HELPER_RET(parcel, Int32, authBoxType_, false); + WRITE_HELPER_RET(parcel, Int32, authType_, false); + WRITE_HELPER_RET(parcel, Int32, pinExchangeType_, false); + WRITE_HELPER_RET(parcel, String, pinCode_, false); + WRITE_HELPER_RET(parcel, String, description_, false); + WRITE_HELPER_RET(parcel, String, extraInfo_, false); + return true; +} } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/common/src/interfaces/pincode_invalid_callback_proxy.cpp b/common/src/interfaces/pincode_invalid_callback_proxy.cpp index 50c9255c..5925844b 100644 --- a/common/src/interfaces/pincode_invalid_callback_proxy.cpp +++ b/common/src/interfaces/pincode_invalid_callback_proxy.cpp @@ -16,7 +16,7 @@ #include "pincode_invalid_callback_proxy.h" #include "macro_utils.h" #include "distributed_device_profile_errors.h" -#include "i_distributed_device_profile.h" +#include "idistributed_device_profile.h" #include "message_parcel.h" namespace OHOS { diff --git a/common/src/interfaces/product_info.cpp b/common/src/interfaces/product_info.cpp index 324b94e8..35cff796 100644 --- a/common/src/interfaces/product_info.cpp +++ b/common/src/interfaces/product_info.cpp @@ -158,5 +158,41 @@ std::string ProductInfo::GetAnonyProductName(const std::string& productName) con cJSON_Delete(json); return jsonStr; } + +bool ProductInfo::ReadFromParcel(Parcel &parcel) +{ + READ_HELPER_RET(parcel, String, productId_, false); + READ_HELPER_RET(parcel, String, model_, false); + READ_HELPER_RET(parcel, String, productName_, false); + READ_HELPER_RET(parcel, String, productShortName_, false); + READ_HELPER_RET(parcel, String, imageVersion_, false); + return true; + +} + +ProductInfo *ProductInfo::Unmarshalling(Parcel &parcel) +{ + ProductInfo *productInfo = new (std::nothrow) ProductInfo(); + if (productInfo == nullptr) { + return nullptr; + } + + if (!productInfo->ReadFromParcel(parcel)) { + delete productInfo; + productInfo = nullptr; + } + + return productInfo; +} + +bool ProductInfo::Marshalling(Parcel& parcel) const +{ + WRITE_HELPER_RET(parcel, String, productId_, false); + WRITE_HELPER_RET(parcel, String, model_, false); + WRITE_HELPER_RET(parcel, String, productName_, false); + WRITE_HELPER_RET(parcel, String, productShortName_, false); + WRITE_HELPER_RET(parcel, String, imageVersion_, false); + return true; +} } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/common/src/interfaces/profile_change_listener_proxy.cpp b/common/src/interfaces/profile_change_listener_proxy.cpp index 740957ae..05d7f5d8 100644 --- a/common/src/interfaces/profile_change_listener_proxy.cpp +++ b/common/src/interfaces/profile_change_listener_proxy.cpp @@ -16,7 +16,7 @@ #include "profile_change_listener_proxy.h" #include "macro_utils.h" #include "distributed_device_profile_errors.h" -#include "i_distributed_device_profile.h" +#include "idistributed_device_profile.h" #include "message_parcel.h" namespace OHOS { diff --git a/common/src/interfaces/service_info_profile.cpp b/common/src/interfaces/service_info_profile.cpp index 9e126f86..522c029b 100644 --- a/common/src/interfaces/service_info_profile.cpp +++ b/common/src/interfaces/service_info_profile.cpp @@ -289,5 +289,70 @@ std::string ServiceInfoProfile::dump() const { return ""; } + +bool ServiceInfoProfile::ReadFromParcel(Parcel &parcel) +{ + READ_HELPER_RET(parcel, String, deviceId_, false); + READ_HELPER_RET(parcel, Int32, userId_, false); + READ_HELPER_RET(parcel, String, networkId_, false); + READ_HELPER_RET(parcel, String, tokenId_, false); + READ_HELPER_RET(parcel, Int64, serviceId_, false); + READ_HELPER_RET(parcel, String, serviceType_, false); + READ_HELPER_RET(parcel, String, serviceName_, false); + READ_HELPER_RET(parcel, String, serviceDisplayName_, false); + READ_HELPER_RET(parcel, String, customData_, false); + READ_HELPER_RET(parcel, Int32, customDataLen_, false); + READ_HELPER_RET(parcel, String, bundleName_, false); + READ_HELPER_RET(parcel, String, moduleName_, false); + READ_HELPER_RET(parcel, String, abilityName_, false); + READ_HELPER_RET(parcel, Int32, authBoxType_, false); + READ_HELPER_RET(parcel, Int32, authType_, false); + READ_HELPER_RET(parcel, Int32, pinExchangeType_, false); + READ_HELPER_RET(parcel, String, pinCode_, false); + READ_HELPER_RET(parcel, String, description_, false); + READ_HELPER_RET(parcel, String, serviceDicoveryScope_, false); + READ_HELPER_RET(parcel, String, extraInfo_, false); + return true; +} + +ServiceInfoProfile *ServiceInfoProfile::Unmarshalling(Parcel &parcel) +{ + ServiceInfoProfile *serviceInfoProfile = new (std::nothrow) ServiceInfoProfile(); + if (serviceInfoProfile == nullptr) { + return nullptr; + } + + if (!serviceInfoProfile->ReadFromParcel(parcel)) { + delete serviceInfoProfile; + serviceInfoProfile = nullptr; + } + + return serviceInfoProfile; +} + +bool ServiceInfoProfile::Marshalling(Parcel& parcel) const +{ + WRITE_HELPER_RET(parcel, String, deviceId_, false); + WRITE_HELPER_RET(parcel, Int32, userId_, false); + WRITE_HELPER_RET(parcel, String, networkId_, false); + WRITE_HELPER_RET(parcel, String, tokenId_, false); + WRITE_HELPER_RET(parcel, Int64, serviceId_, false); + WRITE_HELPER_RET(parcel, String, serviceType_, false); + WRITE_HELPER_RET(parcel, String, serviceName_, false); + WRITE_HELPER_RET(parcel, String, serviceDisplayName_, false); + WRITE_HELPER_RET(parcel, String, customData_, false); + WRITE_HELPER_RET(parcel, Int32, customDataLen_, false); + WRITE_HELPER_RET(parcel, String, bundleName_, false); + WRITE_HELPER_RET(parcel, String, moduleName_, false); + WRITE_HELPER_RET(parcel, String, abilityName_, false); + WRITE_HELPER_RET(parcel, Int32, authBoxType_, false); + WRITE_HELPER_RET(parcel, Int32, authType_, false); + WRITE_HELPER_RET(parcel, Int32, pinExchangeType_, false); + WRITE_HELPER_RET(parcel, String, pinCode_, false); + WRITE_HELPER_RET(parcel, String, description_, false); + WRITE_HELPER_RET(parcel, String, serviceDicoveryScope_, false); + WRITE_HELPER_RET(parcel, String, extraInfo_, false); + return true; +} } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/common/src/interfaces/service_info_unique_key.cpp b/common/src/interfaces/service_info_unique_key.cpp index 9e46fef4..218adab5 100644 --- a/common/src/interfaces/service_info_unique_key.cpp +++ b/common/src/interfaces/service_info_unique_key.cpp @@ -111,5 +111,40 @@ std::string ServiceInfoUniqueKey::dump() const { return ""; } + +bool ServiceInfoUniqueKey::ReadFromParcel(Parcel &parcel) +{ + READ_HELPER_RET(parcel, String, deviceId_, false); + READ_HELPER_RET(parcel, Int32, userId_, false); + READ_HELPER_RET(parcel, String, tokenId_, false); + READ_HELPER_RET(parcel, Int64, serviceId_, false); + READ_HELPER_RET(parcel, String, bundleName_, false); + return true; +} + +ServiceInfoUniqueKey *ServiceInfoUniqueKey::Unmarshalling(Parcel &parcel) +{ + ServiceInfoUniqueKey *serviceInfoUniqueKey = new (std::nothrow) ServiceInfoUniqueKey(); + if (serviceInfoUniqueKey == nullptr) { + return nullptr; + } + + if (!serviceInfoUniqueKey->ReadFromParcel(parcel)) { + delete serviceInfoUniqueKey; + serviceInfoUniqueKey = nullptr; + } + + return serviceInfoUniqueKey; +} + +bool ServiceInfoUniqueKey::Marshalling(Parcel& parcel) const +{ + WRITE_HELPER_RET(parcel, String, deviceId_, false); + WRITE_HELPER_RET(parcel, Int32, userId_, false); + WRITE_HELPER_RET(parcel, String, tokenId_, false); + WRITE_HELPER_RET(parcel, Int64, serviceId_, false); + WRITE_HELPER_RET(parcel, String, bundleName_, false); + return true; +} } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/common/src/interfaces/service_profile.cpp b/common/src/interfaces/service_profile.cpp index d4bc2272..f30be63e 100644 --- a/common/src/interfaces/service_profile.cpp +++ b/common/src/interfaces/service_profile.cpp @@ -148,5 +148,40 @@ std::string ServiceProfile::dump() const cJSON_free(jsonChars); return jsonStr; } + +bool ServiceProfile::ReadFromParcel(Parcel &parcel) +{ + READ_HELPER_RET(parcel, String, deviceId_, false); + READ_HELPER_RET(parcel, String, serviceName_, false); + READ_HELPER_RET(parcel, String, serviceType_, false); + READ_HELPER_RET(parcel, Bool, isMultiUser_, false); + READ_HELPER_RET(parcel, Int32, userId_, false); + return true; +} + +ServiceProfile *ServiceProfile::Unmarshalling(Parcel &parcel) +{ + ServiceProfile *serviceProfile = new (std::nothrow) ServiceProfile(); + if (serviceProfile == nullptr) { + return nullptr; + } + + if (!serviceProfile->ReadFromParcel(parcel)) { + delete serviceProfile; + serviceProfile = nullptr; + } + + return serviceProfile; +} + +bool ServiceProfile::Marshalling(Parcel& parcel) const +{ + WRITE_HELPER_RET(parcel, String, deviceId_, false); + WRITE_HELPER_RET(parcel, String, serviceName_, false); + WRITE_HELPER_RET(parcel, String, serviceType_, false); + WRITE_HELPER_RET(parcel, Bool, isMultiUser_, false); + WRITE_HELPER_RET(parcel, Int32, userId_, false); + return true; +} } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/common/src/interfaces/trust_device_profile.cpp b/common/src/interfaces/trust_device_profile.cpp index 75521705..a968bf15 100644 --- a/common/src/interfaces/trust_device_profile.cpp +++ b/common/src/interfaces/trust_device_profile.cpp @@ -145,5 +145,44 @@ std::string TrustDeviceProfile::dump() const cJSON_free(jsonChars); return jsonStr; } + +bool TrustDeviceProfile::ReadFromParcel(Parcel &parcel) +{ + READ_HELPER_RET(parcel, String, deviceId_, false); + READ_HELPER_RET(parcel, Uint32, deviceIdType_, false); + READ_HELPER_RET(parcel, String, deviceIdHash_, false); + READ_HELPER_RET(parcel, Int32, status_, false); + READ_HELPER_RET(parcel, Uint32, bindType_, false); + READ_HELPER_RET(parcel, Int32, peerUserId_, false); + READ_HELPER_RET(parcel, Int32, localUserId_, false); + return true; +} + +TrustDeviceProfile *TrustDeviceProfile::Unmarshalling(Parcel &parcel) +{ + TrustDeviceProfile *trustDeviceProfile = new (std::nothrow) TrustDeviceProfile(); + if (trustDeviceProfile == nullptr) { + return nullptr; + } + + if (!trustDeviceProfile->ReadFromParcel(parcel)) { + delete trustDeviceProfile; + trustDeviceProfile = nullptr; + } + + return trustDeviceProfile; +} + +bool TrustDeviceProfile::Marshalling(Parcel& parcel) const +{ + WRITE_HELPER_RET(parcel, String, deviceId_, false); + WRITE_HELPER_RET(parcel, Uint32, deviceIdType_, false); + WRITE_HELPER_RET(parcel, String, deviceIdHash_, false); + WRITE_HELPER_RET(parcel, Int32, status_, false); + WRITE_HELPER_RET(parcel, Uint32, bindType_, false); + WRITE_HELPER_RET(parcel, Int32, peerUserId_, false); + WRITE_HELPER_RET(parcel, Int32, localUserId_, false); + return true; +} } // namespace DistributedDeviceProfile } // namespace OHOS \ No newline at end of file diff --git a/common/src/interfaces/trusted_device_info.cpp b/common/src/interfaces/trusted_device_info.cpp index cb3059f2..3941f9b8 100644 --- a/common/src/interfaces/trusted_device_info.cpp +++ b/common/src/interfaces/trusted_device_info.cpp @@ -175,5 +175,44 @@ std::string TrustedDeviceInfo::dump() const cJSON_free(jsonChars); return jsonStr; } + +bool TrustedDeviceInfo::ReadFromParcel(Parcel &parcel) +{ + READ_HELPER_RET(parcel, String, networkId_, false); + READ_HELPER_RET(parcel, Int32, authForm_, false); + READ_HELPER_RET(parcel, Uint16, deviceTypeId_, false); + READ_HELPER_RET(parcel, String, osVersion_, false); + READ_HELPER_RET(parcel, Int32, osType_, false); + READ_HELPER_RET(parcel, String, udid_, false); + READ_HELPER_RET(parcel, String, uuid_, false); + return true; +} + +TrustedDeviceInfo *TrustedDeviceInfo::Unmarshalling(Parcel &parcel) +{ + TrustedDeviceInfo *trustedDeviceInfo = new (std::nothrow) TrustedDeviceInfo(); + if (trustedDeviceInfo == nullptr) { + return nullptr; + } + + if (!trustedDeviceInfo->ReadFromParcel(parcel)) { + delete trustedDeviceInfo; + trustedDeviceInfo = nullptr; + } + + return trustedDeviceInfo; +} + +bool TrustedDeviceInfo::Marshalling(Parcel& parcel) const +{ + WRITE_HELPER_RET(parcel, String, networkId_, false); + WRITE_HELPER_RET(parcel, Int32, authForm_, false); + WRITE_HELPER_RET(parcel, Uint16, deviceTypeId_, false); + WRITE_HELPER_RET(parcel, String, osVersion_, false); + WRITE_HELPER_RET(parcel, Int32, osType_, false); + WRITE_HELPER_RET(parcel, String, udid_, false); + WRITE_HELPER_RET(parcel, String, uuid_, false); + return true; +} } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/common/src/utils/ipc_utils.cpp b/common/src/utils/ipc_utils.cpp index 78a259bd..b0d1d1d4 100644 --- a/common/src/utils/ipc_utils.cpp +++ b/common/src/utils/ipc_utils.cpp @@ -15,6 +15,7 @@ #include "ipc_utils.h" #include "dp_subscribe_info.h" +#include "dp_subscribe_info_extension.h" #include "macro_utils.h" namespace OHOS { diff --git a/interfaces/innerkits/core/BUILD.gn b/interfaces/innerkits/core/BUILD.gn index 8af56923..5e791296 100644 --- a/interfaces/innerkits/core/BUILD.gn +++ b/interfaces/innerkits/core/BUILD.gn @@ -14,16 +14,64 @@ import("//build/ohos.gni") import("//build/ohos_var.gni") import("//foundation/deviceprofile/device_info_manager/deviceprofile.gni") +import("//build/config/components/idl_tool/idl.gni") + +idl_gen_interface("distributed_device_profile_interfaces_gn") { + sources=["IDistributedDeviceProfile.idl"] + hitrace = "HITRACE_TAG_DEVICE_PROFILE" + log_domainid = "0xD004400" + log_tag = "Distributed_Device_Profile" +} + +config("distributed_device_profile_interfaces_ipc_config"){ + include_dirs = [ + ".", + "${target_gen_dir}/", + ] +} + +ohos_source_set("distributed_device_profile_interfaces_ipc") { + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + + output_values = get_target_outputs(":distributed_device_profile_interfaces_gn") + sources = [] + sources += filter_include(output_values, [ "*.cpp" ]) + configs = [ + ":distributed_device_profile_interfaces_ipc_config" + ] + include_dirs = [ + "${device_profile_common}/include/constants", + "${device_profile_common}/include/interfaces", + "${device_profile_common}/include/utils", + ] + deps = [ ":distributed_device_profile_interfaces_gn",] + external_deps = [ + "cJSON:cjson", + "c_utils:utils", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + part_name = "device_info_manager" + subsystem_name = "deviceprofile" +} config("distributed_device_profile_sdk_config") { visibility = [ ":*" ] include_dirs = [ "include", "include/callback", + "${device_profile_path}/radar/include", "${device_profile_common}/include/constants", "${device_profile_common}/include/interfaces", "${device_profile_common}/include/utils", - "${device_profile_path}/radar/include", ] } @@ -54,14 +102,18 @@ ohos_shared_library("distributed_device_profile_sdk") { sources = [ "src/callback/device_profile_load_callback.cpp", "src/distributed_device_profile_client.cpp", - "src/distributed_device_profile_proxy.cpp", ] - public_configs = [ ":distributed_device_profile_sdk_config" ] + configs = [ ":distributed_device_profile_interfaces_ipc_config", ] + + public_configs = [ + ":distributed_device_profile_sdk_config", + ] deps = [ "${device_profile_common}:distributed_device_profile_common", "${device_profile_path}/radar:device_profile_radar", + ":distributed_device_profile_interfaces_ipc", ] external_deps = [ diff --git a/interfaces/innerkits/core/IDistributedDeviceProfile.idl b/interfaces/innerkits/core/IDistributedDeviceProfile.idl new file mode 100644 index 00000000..6aac8138 --- /dev/null +++ b/interfaces/innerkits/core/IDistributedDeviceProfile.idl @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * 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. + */ + +sequenceable OHOS.DistributedDeviceProfile.TrustDeviceProfile; +sequenceable OHOS.DistributedDeviceProfile.DeviceProfile; +sequenceable OHOS.DistributedDeviceProfile.ServiceProfile; +sequenceable OHOS.DistributedDeviceProfile.CharacteristicProfile; +sequenceable OHOS.DistributedDeviceProfile.AccessControlProfile; +sequenceable dp_subscribe_info_extension..OHOS.DistributedDeviceProfile.SubscribeInfoExtension; +sequenceable dp_sync_options..OHOS.DistributedDeviceProfile.DpSyncOptions; +sequenceable OHOS.DistributedDeviceProfile.TrustedDeviceInfo; +sequenceable OHOS.DistributedDeviceProfile.DeviceProfileFilterOptions; +sequenceable OHOS.DistributedDeviceProfile.ProductInfo; +sequenceable OHOS.DistributedDeviceProfile.DeviceIconInfo; +sequenceable OHOS.DistributedDeviceProfile.DeviceIconInfoFilterOptions; +sequenceable OHOS.IRemoteObject; +sequenceable OHOS.DistributedDeviceProfile.ServiceInfoProfile; +sequenceable OHOS.DistributedDeviceProfile.ServiceInfoUniqueKey; +sequenceable OHOS.DistributedDeviceProfile.LocalServiceInfo; + +interface OHOS.DistributedDeviceProfile.IDistributedDeviceProfile { + [ipccode 7] void PutAccessControlProfile([in] AccessControlProfile aclProfile); + [ipccode 8] void UpdateAccessControlProfile([in] AccessControlProfile aclProfile); + [ipccode 9] void GetTrustDeviceProfile([in] String deviceId, [out] TrustDeviceProfile trustDeviceProfile); + [ipccode 10] void GetAllTrustDeviceProfile([out] TrustDeviceProfile[] trustDeviceProfiles); + [ipccode 11] void GetAccessControlProfile([out] OrderedMap queryParams, + [out] AccessControlProfile[] accessControlProfiles); + [ipccode 12] void GetAllAccessControlProfile([out] AccessControlProfile[] accessControlProfiles); + [ipccode 13] void DeleteAccessControlProfile([in] int accessControlId); + [ipccode 46] void PutDeviceProfileBatch([out] DeviceProfile[] deviceProfiles); + [ipccode 14] void PutServiceProfile([in] ServiceProfile serviceProfile); + [ipccode 15] void PutServiceProfileBatch([in] ServiceProfile[] serviceProfiles); + [ipccode 16] void PutCharacteristicProfile([in] CharacteristicProfile charProfile); + [ipccode 17] void PutCharacteristicProfileBatch([in] CharacteristicProfile[] charProfiles); + [ipccode 18] void GetDeviceProfile([in] String deviceId, [out] DeviceProfile deviceProfile); + [ipccode 47] void GetDeviceProfiles([out] DeviceProfileFilterOptions options,[out] DeviceProfile[] deviceProfiles); + [ipccode 51] void DeleteDeviceProfileBatch([out] DeviceProfile[] deviceProfiles); + [ipccode 19] void GetServiceProfile([in] String deviceId, [in] String serviceName, + [out] ServiceProfile serviceProfile); + [ipccode 20] void GetCharacteristicProfile([in] String deviceId, [in] String serviceName, + [in] String characteristicId, [out] CharacteristicProfile charProfile); + [ipccode 21] void DeleteServiceProfile([in] String deviceId, [in] String serviceName, + [in] boolean isMultiUser, [in] int userId); + [ipccode 22] void DeleteCharacteristicProfile([in] String deviceId, [in] String serviceName, + [in] String characteristicId, [in] boolean isMultiUser, [in] int userId); + [ipccode 23] void SubscribeDeviceProfile([in] SubscribeInfoExtension subscribeInfoExtension); + [ipccode 24] void UnSubscribeDeviceProfile([in] SubscribeInfoExtension subscribeInfoExtension); + [ipccode 41] void SubscribeDeviceProfileInited([in] int saId, [in] IRemoteObject dpInitedCallback); + [ipccode 42] void UnSubscribeDeviceProfileInited([in] int saId); + [ipccode 25] void SyncDeviceProfile([in] DpSyncOptions syncOptions, + [in] IRemoteObject syncCompletedCallback); + [ipccode 26] void SendSubscribeInfos([out] OrderedMap listenerMap); + [ipccode 45] void PutAllTrustedDevices([in] TrustedDeviceInfo[] deviceInfos); + [ipccode 50] void PutProductInfoBatch([in] ProductInfo[] productInfos); + [ipccode 49] void PutDeviceIconInfoBatch([in] DeviceIconInfo[] deviceIconInfos); + [ipccode 48] void GetDeviceIconInfos([in] DeviceIconInfoFilterOptions filterOptions,[out] DeviceIconInfo[] deviceIconInfos); + [ipccode 59] void PutSessionKey([in] unsigned int userId, [in] unsigned char[] sessionKey, [out] int sessionKeyId); + [ipccode 60] void GetSessionKey([in] unsigned int userId, [in] int sessionKeyId, [out] unsigned char[] sessionKey); + [ipccode 61] void UpdateSessionKey([in] unsigned int userId, [in] int sessionKeyId, [in] unsigned char[] sessionKey); + [ipccode 62] void DeleteSessionKey([in] unsigned int userId, [in] int sessionKeyId); + [ipccode 64] void SubscribePinCodeInvalid([in] String bundleName, [in] int pinExchangeType, + [in] IRemoteObject pinCodeCallback); + [ipccode 65] void UnSubscribePinCodeInvalid([in] String bundleName, [in] int pinExchangeType); + [ipccode 52] void PutServiceInfoProfile([in] ServiceInfoProfile serviceInfoProfile); + [ipccode 53] void DeleteServiceInfoProfile([in] ServiceInfoUniqueKey key); + [ipccode 54] void UpdateServiceInfoProfile([in] ServiceInfoProfile serviceInfoProfile); + [ipccode 55] void GetServiceInfoProfileByUniqueKey([in] ServiceInfoUniqueKey key, + [inout] ServiceInfoProfile serviceInfoProfile); + [ipccode 56] void GetServiceInfoProfileListByTokenId([in]ServiceInfoUniqueKey key, + [out] ServiceInfoProfile[] serviceInfoProfiles); + [ipccode 57] void GetAllServiceInfoProfileList([out] ServiceInfoProfile[] serviceInfoProfiles); + [ipccode 58] void GetServiceInfoProfileListByBundleName([in] ServiceInfoUniqueKey key, + [out] ServiceInfoProfile[] serviceInfoProfiles); + [ipccode 66] void PutLocalServiceInfo([in] LocalServiceInfo localServiceInfo); + [ipccode 67] void UpdateLocalServiceInfo([in] LocalServiceInfo localServiceInfo); + [ipccode 68] void GetLocalServiceInfoByBundleAndPinType([in] String bundleName, + [in] int pinExchangeType, [out] LocalServiceInfo localServiceInfo); + [ipccode 69] void DeleteLocalServiceInfo([in] String bundleName,[in] int pinExchangeType); + [ipccode 70] void GetAllAclIncludeLnnAcl([out] AccessControlProfile[] accessControlProfiles); +} \ No newline at end of file diff --git a/interfaces/innerkits/core/include/distributed_device_profile_client.h b/interfaces/innerkits/core/include/distributed_device_profile_client.h index c9616d28..42251245 100644 --- a/interfaces/innerkits/core/include/distributed_device_profile_client.h +++ b/interfaces/innerkits/core/include/distributed_device_profile_client.h @@ -27,12 +27,13 @@ #include #include "i_pincode_invalid_callback.h" #include "i_profile_change_listener.h" -#include "i_distributed_device_profile.h" +#include "idistributed_device_profile.h" #include "i_dp_inited_callback.h" #include "iremote_object.h" #include "refbase.h" #include "single_instance.h" #include "dp_subscribe_info.h" +#include "dp_subscribe_info_extension.h" #include "distributed_device_profile_constants.h" #include "sync_completed_callback_stub.h" #include "system_ability_status_change_stub.h" @@ -149,6 +150,7 @@ private: std::mutex subscribeLock_; std::map subscribeInfos_; + std::map subscribeInfoExtensions_; std::mutex saListenerLock_; sptr saListenerCallback_ = nullptr; diff --git a/interfaces/innerkits/core/include/distributed_device_profile_proxy.h b/interfaces/innerkits/core/include/distributed_device_profile_proxy.h deleted file mode 100644 index 103d478d..00000000 --- a/interfaces/innerkits/core/include/distributed_device_profile_proxy.h +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) 2023-2025 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DP_DISTRIBUTED_DEVICE_PROFILE_PROXY_H -#define OHOS_DP_DISTRIBUTED_DEVICE_PROFILE_PROXY_H - -#include -#include -#include -#include - -#include "i_distributed_device_profile.h" -#include "i_dp_inited_callback.h" -#include "iremote_broker.h" -#include "iremote_proxy.h" -#include "refbase.h" -#include "distributed_device_profile_enums.h" -#include "distributed_device_profile_errors.h" -#include "ipc_utils.h" -#include "profile_change_listener_stub.h" - -namespace OHOS { -namespace DistributedDeviceProfile { -class DistributedDeviceProfileProxy : public IRemoteProxy { -public: - explicit DistributedDeviceProfileProxy(const sptr& impl) - : IRemoteProxy(impl) {} - ~DistributedDeviceProfileProxy() {} - - int32_t PutAccessControlProfile(const AccessControlProfile& aclProfile) override; - int32_t UpdateAccessControlProfile(const AccessControlProfile& aclProfile) override; - int32_t GetTrustDeviceProfile(const std::string& deviceId, TrustDeviceProfile& trustDeviceProfile) override; - int32_t GetAllTrustDeviceProfile(std::vector& trustDeviceProfiles) override; - int32_t GetAccessControlProfile(std::map queryParams, - std::vector& accessControlProfiles) override; - int32_t GetAllAccessControlProfile(std::vector& accessControlProfiles) override; - int32_t GetAllAclIncludeLnnAcl(std::vector& accessControlProfiles) override; - int32_t DeleteAccessControlProfile(int32_t accessControlId) override; - int32_t PutSessionKey(uint32_t userId, const std::vector& sessionKey, int32_t& sessionKeyId) override; - int32_t GetSessionKey(uint32_t userId, int32_t sessionKeyId, std::vector& sessionKey) override; - int32_t UpdateSessionKey(uint32_t userId, int32_t sessionKeyId, const std::vector& sessionKey) override; - int32_t DeleteSessionKey(uint32_t userId, int32_t sessionKeyId) override; - int32_t PutDeviceProfileBatch(std::vector& deviceProfiles) override; - int32_t PutServiceProfile(const ServiceProfile& serviceProfile) override; - int32_t PutServiceProfileBatch(const std::vector& serviceProfiles) override; - int32_t PutCharacteristicProfile(const CharacteristicProfile& charProfile) override; - int32_t PutCharacteristicProfileBatch(const std::vector& charProfiles) override; - int32_t GetDeviceProfile(const std::string& deviceId, DeviceProfile& deviceProfile) override; - int32_t GetDeviceProfiles(DeviceProfileFilterOptions& options, - std::vector& deviceProfiles) override; - int32_t DeleteDeviceProfileBatch(std::vector& deviceProfiles) override; - int32_t GetServiceProfile(const std::string& deviceId, const std::string& serviceName, - ServiceProfile& serviceProfile) override; - int32_t GetCharacteristicProfile(const std::string& deviceId, const std::string& serviceName, - const std::string& characteristicId, CharacteristicProfile& charProfile) override; - int32_t DeleteServiceProfile(const std::string& deviceId, const std::string& serviceName, bool isMultiUser = false, - int32_t userId = DEFAULT_USER_ID) override; - int32_t DeleteCharacteristicProfile(const std::string& deviceId, const std::string& serviceName, - const std::string& characteristicId, bool isMultiUser = false, int32_t userId = DEFAULT_USER_ID) override; - int32_t SubscribeDeviceProfile(const SubscribeInfo& subscribeInfo) override; - int32_t UnSubscribeDeviceProfile(const SubscribeInfo& subscribeInfo) override; - int32_t SubscribeDeviceProfileInited(int32_t saId, sptr dpInitedCallback) override; - int32_t UnSubscribeDeviceProfileInited(int32_t saId) override; - int32_t SubscribePinCodeInvalid(const std::string& bundleName, int32_t pinExchangeType, - sptr pinCodeCallback) override; - int32_t UnSubscribePinCodeInvalid(const std::string& bundleName, int32_t pinExchangeType) override; - int32_t SyncDeviceProfile(const DpSyncOptions& syncOptions, sptr syncCompletedCallback) override; - int32_t SendSubscribeInfos(std::map listenerMap) override; - int32_t PutAllTrustedDevices(const std::vector deviceInfos) override; - int32_t PutProductInfoBatch(const std::vector& productInfos) override; - int32_t PutDeviceIconInfoBatch(const std::vector& deviceIconInfos) override; - int32_t GetDeviceIconInfos(const DeviceIconInfoFilterOptions& filterOptions, - std::vector& deviceIconInfos) override; - int32_t PutServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) override; - int32_t DeleteServiceInfoProfile(const ServiceInfoUniqueKey& key) override; - int32_t UpdateServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) override; - int32_t GetServiceInfoProfileByUniqueKey(const ServiceInfoUniqueKey& key, - ServiceInfoProfile& serviceInfoProfile) override; - int32_t GetServiceInfoProfileListByTokenId(const ServiceInfoUniqueKey& key, - std::vector& serviceInfoProfiles) override; - int32_t GetAllServiceInfoProfileList(std::vector& serviceInfoProfiles) override; - int32_t GetServiceInfoProfileListByBundleName(const ServiceInfoUniqueKey& key, - std::vector& serviceInfoProfiles) override; - int32_t PutLocalServiceInfo(const LocalServiceInfo& localServiceInfo) override; - int32_t UpdateLocalServiceInfo(const LocalServiceInfo& localServiceInfo) override; - int32_t GetLocalServiceInfoByBundleAndPinType(const std::string& bundleName, - int32_t pinExchangeType, LocalServiceInfo& localServiceInfo) override; - int32_t DeleteLocalServiceInfo(const std::string& bundleName, int32_t pinExchangeType) override; - -private: - static inline BrokerDelegator delegator_; -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DP_DISTRIBUTED_DEVICE_PROFILE_PROXY_H diff --git a/interfaces/innerkits/core/src/distributed_device_profile_client.cpp b/interfaces/innerkits/core/src/distributed_device_profile_client.cpp index ed603963..a3de6fe0 100644 --- a/interfaces/innerkits/core/src/distributed_device_profile_client.cpp +++ b/interfaces/innerkits/core/src/distributed_device_profile_client.cpp @@ -33,7 +33,7 @@ #include "dp_radar_helper.h" #include "event_handler.h" #include "event_runner.h" -#include "i_distributed_device_profile.h" +#include "idistributed_device_profile.h" #include "if_system_ability_manager.h" #include "ipc_skeleton.h" #include "iremote_broker.h" @@ -123,7 +123,13 @@ void DistributedDeviceProfileClient::SendSubscribeInfosToService() HILOGE("SubscribeInfos size is invalid!size: %{public}zu!", subscribeInfos_.size()); return; } - dpService->SendSubscribeInfos(subscribeInfos_); + + subscribeInfoExtensions_.clear(); + for (const auto& subscribeInfo : subscribeInfos_) { + SubscribeInfoExtension subscribeInfoExtension(subscribeInfo.second); + subscribeInfoExtensions_.insert(std::make_pair(subscribeInfo.first, subscribeInfoExtension)); + } + dpService->SendSubscribeInfos(subscribeInfoExtensions_); } } diff --git a/interfaces/innerkits/core/src/distributed_device_profile_proxy.cpp b/interfaces/innerkits/core/src/distributed_device_profile_proxy.cpp deleted file mode 100644 index 96f09af2..00000000 --- a/interfaces/innerkits/core/src/distributed_device_profile_proxy.cpp +++ /dev/null @@ -1,789 +0,0 @@ -/* - * Copyright (c) 2021-2025 Huawei Device Co., Ltd. - * 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. - */ - -#include -#include "distributed_device_profile_proxy.h" - -namespace OHOS { -namespace DistributedDeviceProfile { -namespace { - const std::string TAG = "DistributedDeviceProfileProxy"; -} - -int32_t DistributedDeviceProfileProxy::PutAccessControlProfile(const AccessControlProfile& aclProfile) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!aclProfile.Marshalling(data)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::PUT_ACL_PROFILE), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::UpdateAccessControlProfile(const AccessControlProfile& aclProfile) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!aclProfile.Marshalling(data)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::UPDATE_ACL_PROFILE), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::PutProductInfoBatch(const std::vector& productInfos) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!IpcUtils::Marshalling(data, productInfos)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::PUT_PRODUCT_INFO_BATCH), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::PutDeviceIconInfoBatch(const std::vector& deviceIconInfos) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!IpcUtils::Marshalling(data, deviceIconInfos)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::PUT_DEVICE_ICON_INFO_BATCH), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::GetDeviceIconInfos(const DeviceIconInfoFilterOptions& filterOptions, - std::vector& deviceIconInfos) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!filterOptions.Marshalling(data)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::GET_DEVICE_ICON_INFOS), data, reply); - if (!IpcUtils::UnMarshalling(reply, deviceIconInfos)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::GetTrustDeviceProfile(const std::string& deviceId, - TrustDeviceProfile& trustDeviceProfile) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - WRITE_HELPER(data, String, deviceId); - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::GET_TRUST_DEVICE_PROFILE), data, reply); - if (!trustDeviceProfile.UnMarshalling(reply)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::GetAllTrustDeviceProfile(std::vector& trustDeviceProfiles) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::GET_ALL_TRUST_DEVICE_PROFILE), data, reply); - if (!IpcUtils::UnMarshalling(reply, trustDeviceProfiles)) { - HILOGE("dp ipc read parcel fail"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::GetAccessControlProfile(std::map queryParams, - std::vector& accessControlProfiles) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!IpcUtils::Marshalling(data, queryParams)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::GET_ACL_PROFILE), data, reply); - if (!IpcUtils::UnMarshalling(reply, accessControlProfiles)) { - HILOGE("dp ipc read parcel fail"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::GetAllAccessControlProfile( - std::vector& accessControlProfiles) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::GET_ALL_ACL_PROFILE), data, reply); - if (!IpcUtils::UnMarshalling(reply, accessControlProfiles)) { - HILOGE("dp ipc read parcel fail"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::GetAllAclIncludeLnnAcl(std::vector& accessControlProfiles) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::GET_ALL_ACL_INCLUDE_LNN_ACL), data, reply); - if (!IpcUtils::UnMarshalling(reply, accessControlProfiles)) { - HILOGE("dp ipc read parcel fail"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::DeleteAccessControlProfile(int32_t accessControlId) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - WRITE_HELPER(data, Int32, accessControlId); - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::DELETE_ACL_PROFILE), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::PutSessionKey( - uint32_t userId, const std::vector& sessionKey, int32_t& sessionKeyId) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - WRITE_HELPER(data, Uint32, userId); - if (!IpcUtils::Marshalling(data, sessionKey)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::PUT_SESSION_KEY), data, reply); - READ_HELPER(reply, Int32, sessionKeyId); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::GetSessionKey( - uint32_t userId, int32_t sessionKeyId, std::vector& sessionKey) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - WRITE_HELPER(data, Uint32, userId); - WRITE_HELPER(data, Int32, sessionKeyId); - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::GET_SESSION_KEY), data, reply); - if (!IpcUtils::UnMarshalling(reply, sessionKey)) { - HILOGE("dp ipc read parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::UpdateSessionKey( - uint32_t userId, int32_t sessionKeyId, const std::vector& sessionKey) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - WRITE_HELPER(data, Uint32, userId); - WRITE_HELPER(data, Int32, sessionKeyId); - if (!IpcUtils::Marshalling(data, sessionKey)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::UPDATE_SESSION_KEY), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::DeleteSessionKey(uint32_t userId, int32_t sessionKeyId) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - WRITE_HELPER(data, Uint32, userId); - WRITE_HELPER(data, Int32, sessionKeyId); - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::DELETE_SESSION_KEY), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::PutDeviceProfileBatch(std::vector& deviceProfiles) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!IpcUtils::Marshalling(data, deviceProfiles)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::PUT_DEVICE_PROFILE_BATCH), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::PutServiceProfile(const ServiceProfile& serviceProfile) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!serviceProfile.Marshalling(data)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::PUT_SERVICE_PROFILE), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::PutServiceProfileBatch(const std::vector& serviceProfiles) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!IpcUtils::Marshalling(data, serviceProfiles)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::PUT_SERVICE_PROFILE_BATCH), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::PutCharacteristicProfile(const CharacteristicProfile& charProfile) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!charProfile.Marshalling(data)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::PUT_CHAR_PROFILE), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::PutCharacteristicProfileBatch( - const std::vector& charProfiles) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!IpcUtils::Marshalling(data, charProfiles)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::PUT_CHAR_PROFILE_BATCH), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::GetDeviceProfile(const std::string& deviceId, DeviceProfile& deviceProfile) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - WRITE_HELPER(data, String, deviceId); - WRITE_HELPER(data, Bool, deviceProfile.IsMultiUser()); - WRITE_HELPER(data, Int32, deviceProfile.GetUserId()); - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::GET_DEVICE_PROFILE_NEW), data, reply); - if (!deviceProfile.UnMarshalling(reply)) { - HILOGE("dp ipc read parcel fail"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::GetDeviceProfiles(DeviceProfileFilterOptions& options, - std::vector& deviceProfiles) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!options.Marshalling(data)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::GET_DEVICE_PROFILES), data, reply); - if (!IpcUtils::UnMarshalling(reply, deviceProfiles)) { - HILOGE("dp ipc read parcel fail"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::DeleteDeviceProfileBatch(std::vector& deviceProfiles) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!IpcUtils::Marshalling(data, deviceProfiles)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::DELETE_DEVICE_PROFILE_BATCH), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::GetServiceProfile(const std::string& deviceId, const std::string& serviceName, - ServiceProfile& serviceProfile) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - WRITE_HELPER(data, String, deviceId); - WRITE_HELPER(data, String, serviceName); - WRITE_HELPER(data, Bool, serviceProfile.IsMultiUser()); - WRITE_HELPER(data, Int32, serviceProfile.GetUserId()); - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::GET_SERVICE_PROFILE), data, reply); - if (!serviceProfile.UnMarshalling(reply)) { - HILOGE("dp ipc read parcel fail"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::PutServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!serviceInfoProfile.Marshalling(data)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::PUT_SERVICE_INFO_PROFILE), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::DeleteServiceInfoProfile(const ServiceInfoUniqueKey& key) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!key.Marshalling(data)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::DELETE_SERVICE_INFO_PROFILE), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::UpdateServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!serviceInfoProfile.Marshalling(data)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::UPDATE_SERVICE_INFO_PROFILE), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::GetServiceInfoProfileByUniqueKey(const ServiceInfoUniqueKey& key, - ServiceInfoProfile& serviceInfoProfile) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!key.Marshalling(data)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::GET_SERVICE_INFO_PROFILE_BY_UNIQUE_KEY), data, reply); - if (!serviceInfoProfile.UnMarshalling(reply)) { - HILOGE("dp ipc read parcel fail"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::GetServiceInfoProfileListByTokenId(const ServiceInfoUniqueKey& key, - std::vector& serviceInfoProfiles) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!key.Marshalling(data)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::GET_SERVICE_INFO_PROFILE_LIST_BY_TOKEN_ID), - data, reply); - if (!IpcUtils::UnMarshalling(reply, serviceInfoProfiles)) { - HILOGE("dp ipc read parcel fail"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::GetAllServiceInfoProfileList( - std::vector& serviceInfoProfiles) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::GET_ALL_SERVICE_INFO_PROFILE_LIST), - data, reply); - if (!IpcUtils::UnMarshalling(reply, serviceInfoProfiles)) { - HILOGE("dp ipc read parcel fail"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::GetServiceInfoProfileListByBundleName(const ServiceInfoUniqueKey& key, - std::vector& serviceInfoProfiles) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!key.Marshalling(data)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::GET_SERVICE_INFO_PROFILE_LIST_BY_BUNDLE_NAME), - data, reply); - if (!IpcUtils::UnMarshalling(reply, serviceInfoProfiles)) { - HILOGE("dp ipc read parcel fail"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::GetCharacteristicProfile(const std::string& deviceId, - const std::string& serviceName, const std::string& characteristicId, CharacteristicProfile& charProfile) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - WRITE_HELPER(data, String, deviceId); - WRITE_HELPER(data, String, serviceName); - WRITE_HELPER(data, String, characteristicId); - WRITE_HELPER(data, Bool, charProfile.IsMultiUser()); - WRITE_HELPER(data, Int32, charProfile.GetUserId()); - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::GET_CHAR_PROFILE), data, reply); - if (!charProfile.UnMarshalling(reply)) { - HILOGE("dp ipc read parcel fail"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::DeleteServiceProfile(const std::string& deviceId, - const std::string& serviceName, bool isMultiUser, int32_t userId) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - WRITE_HELPER(data, String, deviceId); - WRITE_HELPER(data, String, serviceName); - WRITE_HELPER(data, Bool, isMultiUser); - WRITE_HELPER(data, Int32, userId); - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::DEL_SERVICE_PROFILE), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::DeleteCharacteristicProfile(const std::string& deviceId, - const std::string& serviceName, const std::string& characteristicId, bool isMultiUser, int32_t userId) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - WRITE_HELPER(data, String, deviceId); - WRITE_HELPER(data, String, serviceName); - WRITE_HELPER(data, String, characteristicId); - WRITE_HELPER(data, Bool, isMultiUser); - WRITE_HELPER(data, Int32, userId); - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::DEL_CHAR_PROFILE), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::SubscribeDeviceProfile(const SubscribeInfo& subscribeInfo) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!subscribeInfo.Marshalling(data)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::UnSubscribeDeviceProfile(const SubscribeInfo& subscribeInfo) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!subscribeInfo.Marshalling(data)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::SyncDeviceProfile(const DpSyncOptions& syncOptions, - const sptr syncCompletedCallback) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!syncOptions.Marshalling(data)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - WRITE_HELPER(data, RemoteObject, syncCompletedCallback); - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::SYNC_DEVICE_PROFILE_NEW), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::SendSubscribeInfos(std::map listenerMap) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!IpcUtils::Marshalling(data, listenerMap)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::SEND_SUBSCRIBE_INFOS), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::SubscribeDeviceProfileInited(int32_t saId, sptr dpInitedCallback) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - WRITE_HELPER(data, Int32, saId); - WRITE_HELPER(data, RemoteObject, dpInitedCallback); - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE_INITED), data, reply); - return DP_SUCCESS; -} - -int32_t OHOS::DistributedDeviceProfile::DistributedDeviceProfileProxy::UnSubscribeDeviceProfileInited(int32_t saId) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - WRITE_HELPER(data, Int32, saId); - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE_INITED), data, reply); - return DP_SUCCESS; -} - -int32_t OHOS::DistributedDeviceProfile::DistributedDeviceProfileProxy::SubscribePinCodeInvalid( - const std::string& bundleName, int32_t pinExchangeType, sptr pinCodeCallback) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - WRITE_HELPER(data, String, bundleName); - WRITE_HELPER(data, Int32, pinExchangeType); - WRITE_HELPER(data, RemoteObject, pinCodeCallback); - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::SUBSCRIBE_PINCODE_INVALID), data, reply); - return DP_SUCCESS; -} - -int32_t OHOS::DistributedDeviceProfile::DistributedDeviceProfileProxy::UnSubscribePinCodeInvalid( - const std::string& bundleName, int32_t pinExchangeType) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - WRITE_HELPER(data, String, bundleName); - WRITE_HELPER(data, Int32, pinExchangeType); - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::UNSUBSCRIBE_PINCODE_INVALID), data, reply); - return DP_SUCCESS; -} - -int32_t OHOS::DistributedDeviceProfile::DistributedDeviceProfileProxy::PutAllTrustedDevices( - const std::vector deviceInfos) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!IpcUtils::Marshalling(data, deviceInfos)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::PUT_ALL_TRUSTED_DEVICES), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::PutLocalServiceInfo(const LocalServiceInfo& localServiceInfo) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!localServiceInfo.Marshalling(data)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::PUT_LOCAL_SERVICE_INFO), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::UpdateLocalServiceInfo(const LocalServiceInfo& localServiceInfo) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - if (!localServiceInfo.Marshalling(data)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - MessageParcel reply; - SEND_REQUEST(remote, static_cast(DPInterfaceCode::UPDATE_LOCAL_SERVICE_INFO), data, reply); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::GetLocalServiceInfoByBundleAndPinType(const std::string& bundleName, - int32_t pinExchangeType, LocalServiceInfo& localServiceInfo) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - WRITE_HELPER(data, String, bundleName); - WRITE_HELPER(data, Int32, pinExchangeType); - MessageParcel reply; - SEND_REQUEST(remote, - static_cast(DPInterfaceCode::GET_LOCAL_SERVICE_INFO_BY_BINDLE_AND_PINTYPE), data, reply); - if (!localServiceInfo.UnMarshalling(reply)) { - HILOGE("dp ipc read parcel fail"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileProxy::DeleteLocalServiceInfo(const std::string& bundleName, int32_t pinExchangeType) -{ - sptr remote = nullptr; - GET_REMOTE_OBJECT(remote); - MessageParcel data; - WRITE_INTERFACE_TOKEN(data); - WRITE_HELPER(data, String, bundleName); - WRITE_HELPER(data, Int32, pinExchangeType); - MessageParcel reply; - SEND_REQUEST(remote, - static_cast(DPInterfaceCode::DELETE_LOCAL_SERVICE_INFO), data, reply); - return DP_SUCCESS; -} -} // namespace DeviceProfile -} // namespace OHOS diff --git a/old/common/include/device_profile_errors.h b/old/common/include/device_profile_errors.h deleted file mode 100644 index fabffb6e..00000000 --- a/old/common/include/device_profile_errors.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DEVICE_PROFILE_ERRORS_H -#define OHOS_DEVICE_PROFILE_ERRORS_H - -#include "errors.h" - -namespace OHOS { -namespace DeviceProfile { -enum { - DEVICE_PROFILE_MODULE_DDP = 0, -}; - -constexpr ErrCode DEVICE_PROFILE_ERR_OFFSET = ErrCodeOffset(SUBSYS_DEVICEPROFILE, DEVICE_PROFILE_MODULE_DDP); - -enum { - // DEVICE_PROFILE_ERR_OFFSET(98566143) - ERR_DP_INVALID_PARAMS = 98566144, - ERR_DP_INTERFACE_CHECK_FAILED = 98566145, - ERR_DP_GET_LOCAL_UDID_FAILED = 98566146, - ERR_DP_GET_SERVICE_FAILED = 98566147, - ERR_DP_INIT_DB_FAILED = 98566148, - ERR_DP_NOT_SUBSCRIBED = 98566149, - ERR_DP_UNSUBSCRIBE_FAILED = 98566150, - ERR_DP_SUBSCRIBE_FAILED = 98566151, - ERR_DP_SUBSCRIBE_LIMIT_EXCEEDED = 98566152, - ERR_DP_POST_TASK_FAILED = 98566153, - ERR_DP_DEVICE_SYNC_BUSY = 98566154, - ERR_DP_PERMISSION_DENIED = 98566155, - ERR_DP_UNTRUSTED_GROUP = 98566156, - ERR_DP_NOT_INIT_DB = 98566157, - ERR_DP_GET_NETWORKID_FAILED = 98566158, - ERR_DP_FILE_FAILED_ERR = 98566159, - ERR_DP_LOAD_SERVICE_ERR = 98566160, - ERR_DP_GET_DATA_FAILED = 98566161, - ERR_DP_DELETE_DATA_FAILED = 98566162, - ERR_DP_ADD_DATA_FAILED = 98566163, - ERR_DP_SYNC_DATA_FAILED = 98566164, -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DEVICE_PROFILE_ERRORS_H diff --git a/old/common/include/device_profile_log.h b/old/common/include/device_profile_log.h deleted file mode 100644 index a73b6ed9..00000000 --- a/old/common/include/device_profile_log.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DEVICE_PROFILE_LOG_H -#define OHOS_DEVICE_PROFILE_LOG_H - -#ifndef LOG_TAG -#define LOG_TAG "Device_Profile" -#undef LOG_DOMAIN -#define LOG_DOMAIN 0xD004400 -#endif -#include "hilog/log.h" - -namespace OHOS { -namespace DeviceProfile { - -#ifdef HILOGF -#undef HILOGF -#endif -#ifdef HILOGE -#undef HILOGE -#endif -#ifdef HILOGW -#undef HILOGW -#endif -#ifdef HILOGI -#undef HILOGI -#endif -#ifdef HILOGD -#undef HILOGD -#endif - -#define HILOGF(fmt, ...) HILOG_FATAL(LOG_CORE, "%{public}s::%{public}s " fmt, TAG.c_str(), __FUNCTION__, ##__VA_ARGS__) -#define HILOGE(fmt, ...) HILOG_ERROR(LOG_CORE, "%{public}s::%{public}s " fmt, TAG.c_str(), __FUNCTION__, ##__VA_ARGS__) -#define HILOGW(fmt, ...) HILOG_WARN(LOG_CORE, "%{public}s::%{public}s " fmt, TAG.c_str(), __FUNCTION__, ##__VA_ARGS__) -#define HILOGI(fmt, ...) HILOG_INFO(LOG_CORE, "%{public}s::%{public}s " fmt, TAG.c_str(), __FUNCTION__, ##__VA_ARGS__) -#define HILOGD(fmt, ...) HILOG_DEBUG(LOG_CORE, "%{public}s::%{public}s " fmt, TAG.c_str(), __FUNCTION__, ##__VA_ARGS__) -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DISTRIBUTED_DP_DATA_CHANGE_LISTENER_H diff --git a/old/common/include/device_profile_utils.h b/old/common/include/device_profile_utils.h deleted file mode 100644 index 30ceec13..00000000 --- a/old/common/include/device_profile_utils.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DEVICE_PROFILE_PROFILE_UTILS_H -#define OHOS_DEVICE_PROFILE_PROFILE_UTILS_H - -#include -#include - -#include "parcel.h" -#include "profile_event.h" - -namespace OHOS { -namespace DeviceProfile { -class DeviceProfileUtils { -public: - static bool WriteProfileEvents(const std::list& profileEvents, Parcel& parcel); - static bool ReadProfileEvents(Parcel& parcel, std::list& profileEvents); - static std::string AnonymizeDeviceId(const std::string& deviceId); - static std::string AnonymizeString(const std::string& value); -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DEVICE_PROFILE_PROFILE_UTILS_H diff --git a/old/common/include/deviceprofile_ipc_interface_code.h b/old/common/include/deviceprofile_ipc_interface_code.h deleted file mode 100644 index 6030128a..00000000 --- a/old/common/include/deviceprofile_ipc_interface_code.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DEVICE_PROFILE_IPC_INTERFACE_CODE_H -#define OHOS_DEVICE_PROFILE_IPC_INTERFACE_CODE_H - -#include - -/* SAID: 6001 */ -namespace OHOS { -namespace DeviceProfile { -enum class IDeviceProfileInterfaceCode : uint32_t { - PUT_DEVICE_PROFILE = 1, - GET_DEVICE_PROFILE = 2, - DELETE_DEVICE_PROFILE = 3, - SUBSCRIBE_PROFILE_EVENT = 4, - UNSUBSCRIBE_PROFILE_EVENT = 5, - SYNC_DEVICE_PROFILE = 6, - PUT_ACL_PROFILE = 7, // new ipc code - UPDATE_ACL_PROFILE = 8, - GET_TRUST_DEVICE_PROFILE = 9, - GET_ALL_TRUST_DEVICE_PROFILE = 10, - GET_ACL_PROFILE = 11, - GET_ALL_ACL_PROFILE = 12, - DELETE_ACL_PROFILE = 13, - PUT_SERVICE_PROFILE = 14, - PUT_SERVICE_PROFILE_BATCH = 15, - PUT_CHAR_PROFILE = 16, - PUT_CHAR_PROFILE_BATCH = 17, - GET_DEVICE_PROFILE_NEW = 18, - GET_SERVICE_PROFILE = 19, - GET_CHAR_PROFILE = 20, - DEL_SERVICE_PROFILE = 21, - DEL_CHAR_PROFILE = 22, - SUBSCRIBE_DEVICE_PROFILE = 23, - UNSUBSCRIBE_DEVICE_PROFILE = 24, - SYNC_DEVICE_PROFILE_NEW = 25, - SEND_SUBSCRIBE_INFOS = 26, - ON_SYNC_COMPLETED = 27, - ON_TRUST_DEVICE_PROFILE_ADD = 28, - ON_TRUST_DEVICE_PROFILE_UPDATE = 29, - ON_TRUST_DEVICE_PROFILE_DELETE = 30, - ON_DEVICE_PROFILE_ADD = 31, - ON_DEVICE_PROFILE_UPDATE = 32, - ON_DEVICE_PROFILE_DELETE = 33, - ON_SERVICE_PROFILE_ADD = 34, - ON_SERVICE_PROFILE_UPDATE = 35, - ON_SERVICE_PROFILE_DELETE = 36, - ON_CHAR_PROFILE_ADD = 37, - ON_CHAR_PROFILE_UPDATE = 38, - ON_CHAR_PROFILE_DELETE = 39, -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif diff --git a/old/common/include/parcel_helper.h b/old/common/include/parcel_helper.h deleted file mode 100644 index baa49673..00000000 --- a/old/common/include/parcel_helper.h +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DEVICE_PROFILE_PARCEL_HELPER_H -#define OHOS_DEVICE_PROFILE_PARCEL_HELPER_H - -#include "ipc_types.h" -#include "device_profile_log.h" - -namespace OHOS { -namespace DeviceProfile { -#define PARCEL_WRITE_HELPER(parcel, type, value) \ - do { \ - bool ret = parcel.Write##type((value)); \ - if (!ret) { \ - HILOGE("write value failed!"); \ - return ERR_FLATTEN_OBJECT; \ - } \ - } while (0) - -#define PARCEL_WRITE_HELPER_NORET(parcel, type, value) \ - do { \ - bool ret = parcel.Write##type((value)); \ - if (!ret) { \ - HILOGE("write value failed!"); \ - return; \ - } \ - } while (0) - -#define PARCEL_WRITE_HELPER_RET(parcel, type, value, failRet) \ - do { \ - bool ret = parcel.Write##type((value)); \ - if (!ret) { \ - HILOGE("write value failed!"); \ - return failRet; \ - } \ - } while (0) - -#define PARCEL_READ_HELPER(parcel, type, out) \ - do { \ - bool ret = parcel.Read##type((out)); \ - if (!ret) { \ - HILOGE("read value failed!"); \ - return ERR_FLATTEN_OBJECT; \ - } \ - } while (0) - -#define PARCEL_READ_HELPER_RET(parcel, type, out, failRet) \ - do { \ - bool ret = parcel.Read##type((out)); \ - if (!ret) { \ - HILOGE("read value failed!"); \ - return failRet; \ - } \ - } while (0) - -#define PARCEL_READ_HELPER_NORET(parcel, type, out) \ - do { \ - bool ret = parcel.Read##type((out)); \ - if (!ret) { \ - HILOGW("read value failed!"); \ - } \ - } while (0) - -#define PARCEL_WRITE_REPLY_NOERROR(reply, type, result) \ - do { \ - bool ret = reply.Write##type(result); \ - if (!ret) { \ - HILOGW("write reply failed!"); \ - } \ - return ERR_OK; \ - } while (0) - -#define PARCEL_TRANSACT_SYNC_RET_INT(remote, code, data, reply) \ - do { \ - MessageOption option; \ - int32_t errCode = remote->SendRequest(code, data, reply, option); \ - if (errCode != ERR_OK) { \ - HILOGE("transact failed, errCode = %{public}d", errCode); \ - return errCode; \ - } \ - HILOGI("transact succeeded"); \ - return ERR_OK; \ - } while (0) - -#define PARCEL_TRANSACT_SYNC_NORET(remote, code, data, reply) \ - do { \ - MessageOption option; \ - int32_t errCode = remote->SendRequest(code, data, reply, option); \ - if (errCode != ERR_OK) { \ - HILOGE("transact failed, errCode = %{public}d", errCode); \ - return; \ - } \ - HILOGI("transact succeeded"); \ - } while (0) -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DEVICE_PROFILE_PARCEL_HELPER_H \ No newline at end of file diff --git a/old/common/include/single_instance.h b/old/common/include/single_instance.h deleted file mode 100644 index 017b5c27..00000000 --- a/old/common/include/single_instance.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DEVICE_PROFILE_SINGLE_INSTANCE_H -#define OHOS_DEVICE_PROFILE_SINGLE_INSTANCE_H - -namespace OHOS { -namespace DeviceProfile { -#define DECLARE_SINGLE_INSTANCE_BASE(className) \ -public: \ - static className& GetInstance(); \ -private: \ - className(const className&) = delete; \ - className& operator= (const className&) = delete; \ - className(className&&) = delete; \ - className& operator= (className&&) = delete; \ - -#define DECLARE_SINGLE_INSTANCE(className) \ - DECLARE_SINGLE_INSTANCE_BASE(className) \ -private: \ - className() = default; \ - ~className() = default; \ - -#define IMPLEMENT_SINGLE_INSTANCE(className) \ -className& className::GetInstance() \ -{ \ - static auto instance = new className(); \ - return *instance; \ -} -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DEVICE_PROFILE_SINGLE_INSTANCE_H \ No newline at end of file diff --git a/old/common/src/device_profile_utils.cpp b/old/common/src/device_profile_utils.cpp deleted file mode 100644 index 4b968dc0..00000000 --- a/old/common/src/device_profile_utils.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. - * 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. - */ - -#include "device_profile_utils.h" - -#include -#include - -#include "parcel.h" -#include "parcel_helper.h" - -namespace OHOS { -namespace DeviceProfile { -namespace { -const std::string TAG = "DeviceProfileUtils"; - -constexpr int32_t NON_ANONYMIZED_LENGTH = 6; -constexpr uint32_t MAX_EVENT_LEN = 1000000; -const std::string EMPTY_DEVICE_ID = ""; -} - -bool DeviceProfileUtils::WriteProfileEvents(const std::list& profileEvents, Parcel& parcel) -{ - size_t size = profileEvents.size(); - PARCEL_WRITE_HELPER_RET(parcel, Uint32, static_cast(size), false); - for (auto profileEvent : profileEvents) { - PARCEL_WRITE_HELPER_RET(parcel, Uint32, static_cast(profileEvent), false); - } - return true; -} - -bool DeviceProfileUtils::ReadProfileEvents(Parcel& parcel, std::list& profileEvents) -{ - uint32_t numEvents = parcel.ReadUint32(); - if (numEvents > MAX_EVENT_LEN) { - return false; - } - - for (uint32_t i = 0; i < numEvents; i++) { - ProfileEvent profileEvent = static_cast(parcel.ReadUint32()); - if (profileEvent >= EVENT_PROFILE_END || profileEvent == EVENT_UNKNOWN) { - return false; - } - profileEvents.emplace_back(profileEvent); - } - return true; -} - -std::string DeviceProfileUtils::AnonymizeDeviceId(const std::string& deviceId) -{ - if (deviceId.length() < NON_ANONYMIZED_LENGTH) { - return EMPTY_DEVICE_ID; - } - std::string anonDeviceId = deviceId.substr(0, NON_ANONYMIZED_LENGTH); - anonDeviceId.append("******"); - return anonDeviceId; -} - -std::string DeviceProfileUtils::AnonymizeString(const std::string& value) -{ - constexpr size_t INT32_SHORT_ID_LENGTH = 20; - constexpr size_t INT32_PLAINTEXT_LENGTH = 4; - constexpr size_t INT32_MIN_ID_LENGTH = 3; - std::string res; - std::string tmpStr("******"); - size_t strLen = value.length(); - if (strLen < INT32_MIN_ID_LENGTH) { - return tmpStr; - } - - if (strLen <= INT32_SHORT_ID_LENGTH) { - res += value[0]; - res += tmpStr; - res += value[strLen - 1]; - } else { - res.append(value, 0, INT32_PLAINTEXT_LENGTH); - res += tmpStr; - res.append(value, strLen - INT32_PLAINTEXT_LENGTH, INT32_PLAINTEXT_LENGTH); - } - return res; -} -} // namespace DeviceProfile -} // namespace OHOS diff --git a/old/interfaces/innerkits/core/BUILD.gn b/old/interfaces/innerkits/core/BUILD.gn deleted file mode 100644 index 8985fa72..00000000 --- a/old/interfaces/innerkits/core/BUILD.gn +++ /dev/null @@ -1,83 +0,0 @@ -# Copyright (c) 2021-2024 Huawei Device Co., Ltd. -# 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. - -import("//build/ohos.gni") -import("//build/ohos_var.gni") -import("//foundation/deviceprofile/device_info_manager/deviceprofile.gni") - -config("distributed_device_profile_client_config") { - visibility = [ ":*" ] - include_dirs = [ - "include", - "${old_device_profile_path}/common/include", - "${old_device_profile_path}/radar/include", - ] -} - -ohos_shared_library("distributed_device_profile_client") { - branch_protector_ret = "pac_ret" - ldflags = [ - "-Wl,-z,relro", - "-Wl,-z,now", - ] - - cflags = [ - "-fPIC", - "-D_FORTIFY_SOURCE=2", - "-O2", - ] - - cflags_cc = cflags - - sanitize = { - boundary_sanitize = true - integer_overflow = true - ubsan = true - cfi = true - cfi_cross_dso = true - debug = false - } - - install_enable = true - - sources = [ - "${old_device_profile_path}/common/src/device_profile_utils.cpp", - "${old_device_profile_service}/core/src/profile_change_notification.cpp", - "${old_device_profile_service}/core/src/service_characteristic_profile.cpp", - "${old_device_profile_service}/core/src/subscribemanager/subscribe_info.cpp", - "${old_device_profile_service}/core/src/sync_options.cpp", - "src/callback/device_profile_load_callback.cpp", - "src/distributed_device_profile_client.cpp", - "src/distributed_device_profile_proxy.cpp", - "src/profile_event_notifier_stub.cpp", - ] - - public_configs = [ - ":distributed_device_profile_client_config", - "${old_device_profile_test}/resource:coverage_flags", - ] - - deps = [ "${old_device_profile_path}/radar:deviceprofileradar" ] - - external_deps = [ - "c_utils:utils", - "eventhandler:libeventhandler", - "hilog:libhilog", - "ipc:ipc_core", - "json:nlohmann_json_static", - "samgr:samgr_proxy", - ] - - part_name = "device_info_manager" - subsystem_name = "deviceprofile" -} diff --git a/old/interfaces/innerkits/core/include/callback/device_profile_load_callback.h b/old/interfaces/innerkits/core/include/callback/device_profile_load_callback.h deleted file mode 100644 index f9972fb3..00000000 --- a/old/interfaces/innerkits/core/include/callback/device_profile_load_callback.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DEVICE_PROFILE_LOAD_CALLBACK_H -#define OHOS_DEVICE_PROFILE_LOAD_CALLBACK_H - -#include -#include - -#include "refbase.h" -#include "system_ability_load_callback_stub.h" - -namespace OHOS { class IRemoteObject; } -namespace OHOS { -namespace DeviceProfile { -class DeviceProfileLoadCallback : public SystemAbilityLoadCallbackStub { -public: - void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, - const sptr &remoteObject) override; - void OnLoadSystemAbilityFail(int32_t systemAbilityId) override; -}; -} -} -#endif \ No newline at end of file diff --git a/old/interfaces/innerkits/core/include/distributed_device_profile_client.h b/old/interfaces/innerkits/core/include/distributed_device_profile_client.h deleted file mode 100644 index a31618c3..00000000 --- a/old/interfaces/innerkits/core/include/distributed_device_profile_client.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DISTRIBUTED_DEVICE_PROFILE_CLIENT_H -#define OHOS_DISTRIBUTED_DEVICE_PROFILE_CLIENT_H - -#include -#include -#include -#include -#include -#include -#include - -#include "event_handler.h" -#include "idistributed_device_profile.h" -#include "iprofile_event_callback.h" -#include "iremote_object.h" -#include "profile_event.h" -#include "profile_event_notifier_stub.h" -#include "refbase.h" -#include "single_instance.h" -#include "subscribe_info.h" - -namespace OHOS { -namespace DeviceProfile { -class DistributedDeviceProfileClient { - DECLARE_SINGLE_INSTANCE(DistributedDeviceProfileClient); - -public: - int32_t PutDeviceProfile(const ServiceCharacteristicProfile& profile); - int32_t GetDeviceProfile(const std::string& udid, const std::string& serviceId, - ServiceCharacteristicProfile& profile); - int32_t DeleteDeviceProfile(const std::string& serviceId); - int32_t SubscribeProfileEvent(const SubscribeInfo& subscribeInfo, - const std::shared_ptr& eventCb); - int32_t UnsubscribeProfileEvent(ProfileEvent profileEvent, - const std::shared_ptr& eventCb); - int32_t SubscribeProfileEvents(const std::list& subscribeInfos, - const std::shared_ptr& eventCb, - std::list& failedEvents); - int32_t UnsubscribeProfileEvents(const std::list& profileEvents, - const std::shared_ptr& eventCb, - std::list& failedEvents); - int32_t SyncDeviceProfile(const SyncOptions& syncOptions, - const std::shared_ptr& syncCb); - void LoadSystemAbilitySuccess(const sptr &remoteObject); - void LoadSystemAbilityFail(); - -private: - class DeviceProfileDeathRecipient : public IRemoteObject::DeathRecipient { - public: - void OnRemoteDied(const wptr& remote) override; - }; - - struct SubscribeRecord { - std::list subscribeInfos; - sptr notifier; - ProfileEvents profileEvents; - }; - - sptr GetDeviceProfileService(); - bool LoadDeviceProfileService(); - bool CheckProfileInvalidity(const ServiceCharacteristicProfile& profile); - void OnServiceDied(const sptr& remote); - void MergeSubscribeInfoLocked(std::list& subscribeInfos, - const std::list& newSubscribeInfos); - - std::condition_variable proxyConVar_; - std::mutex serviceLock_; - std::mutex subscribeLock_; - sptr dpProxy_; - sptr dpDeathRecipient_; - std::shared_ptr dpClientHandler_; - std::map, SubscribeRecord> subscribeRecords_; -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DISTRIBUTED_DEVICE_PROFILE_CLIENT_H \ No newline at end of file diff --git a/old/interfaces/innerkits/core/include/distributed_device_profile_proxy.h b/old/interfaces/innerkits/core/include/distributed_device_profile_proxy.h deleted file mode 100644 index e112399e..00000000 --- a/old/interfaces/innerkits/core/include/distributed_device_profile_proxy.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DISTRIBUTED_DEVICE_PROFILE_PROXY_H -#define OHOS_DISTRIBUTED_DEVICE_PROFILE_PROXY_H - -#include -#include -#include -#include - -#include "idistributed_device_profile.h" -#include "iremote_broker.h" -#include "iremote_proxy.h" -#include "profile_event.h" -#include "refbase.h" - -namespace OHOS { -namespace DeviceProfile { -class DistributedDeviceProfileProxy : public IRemoteProxy { -public: - explicit DistributedDeviceProfileProxy(const sptr& impl) - : IRemoteProxy(impl) {} - ~DistributedDeviceProfileProxy() = default; - - int32_t PutDeviceProfile(const ServiceCharacteristicProfile& profile) override; - int32_t GetDeviceProfile(const std::string& udid, const std::string& serviceId, - ServiceCharacteristicProfile& profile) override; - int32_t DeleteDeviceProfile(const std::string& serviceId) override; - int32_t SubscribeProfileEvents(const std::list& subscribeInfos, - const sptr& profileEventNotifier, - std::list& failedEvents) override; - int32_t UnsubscribeProfileEvents(const std::list& profileEvents, - const sptr& profileEventNotifier, - std::list& failedEvents) override; - int32_t SyncDeviceProfile(const SyncOptions& syncOptions, - const sptr& profileEventNotifier) override; - -private: - static inline BrokerDelegator delegator_; -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DISTRIBUTED_DEVICE_PROFILE_PROXY_H \ No newline at end of file diff --git a/old/interfaces/innerkits/core/include/idistributed_device_profile.h b/old/interfaces/innerkits/core/include/idistributed_device_profile.h deleted file mode 100644 index cdbc0427..00000000 --- a/old/interfaces/innerkits/core/include/idistributed_device_profile.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_I_DISTRIBUTED_DEVICE_PROFILE_H -#define OHOS_I_DISTRIBUTED_DEVICE_PROFILE_H - -#include - -#include "iremote_broker.h" -#include "service_characteristic_profile.h" -#include "iprofile_event_notifier.h" -#include "profile_event.h" -#include "subscribe_info.h" -#include "sync_options.h" - -namespace OHOS { -namespace DeviceProfile { -class IDistributedDeviceProfile : public IRemoteBroker { -public: - virtual int32_t PutDeviceProfile(const ServiceCharacteristicProfile& profile) = 0; - virtual int32_t GetDeviceProfile(const std::string& udid, const std::string& serviceId, - ServiceCharacteristicProfile& profile) = 0; - virtual int32_t DeleteDeviceProfile(const std::string& serviceId) = 0; - virtual int32_t SubscribeProfileEvents(const std::list& subscribeInfos, - const sptr& profileEventNotifier, - std::list& failedEvents) = 0; - virtual int32_t UnsubscribeProfileEvents(const std::list& profileEvents, - const sptr& profileEventNotifier, - std::list& failedEvents) = 0; - virtual int32_t SyncDeviceProfile(const SyncOptions& syncOptions, - const sptr& profileEventNotifier) = 0; - - DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.DeviceProfile.IDistributedDeviceProfile"); -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_I_DISTRIBUTED_DEVICE_PROFILE_H \ No newline at end of file diff --git a/old/interfaces/innerkits/core/include/iprofile_event_callback.h b/old/interfaces/innerkits/core/include/iprofile_event_callback.h deleted file mode 100644 index 457d3d94..00000000 --- a/old/interfaces/innerkits/core/include/iprofile_event_callback.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DEVICE_PROFILE_I_PROFILE_EVENT_CALLBACK_H -#define OHOS_DEVICE_PROFILE_I_PROFILE_EVENT_CALLBACK_H - -#include -#include "profile_change_notification.h" - -namespace OHOS { -namespace DeviceProfile { -enum SyncStatus { - SUCCEEDED = 0, - FAILED = 1 -}; - -using SyncResult = std::map; - -class IProfileEventCallback { -public: - IProfileEventCallback() = default; - virtual ~IProfileEventCallback() = default; - - virtual void OnSyncCompleted(const SyncResult& syncResults) {} - virtual void OnProfileChanged(const ProfileChangeNotification& changeNotification) {} -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DEVICE_PROFILE_I_PROFILE_EVENT_CALLBACK_H diff --git a/old/interfaces/innerkits/core/include/iprofile_event_notifier.h b/old/interfaces/innerkits/core/include/iprofile_event_notifier.h deleted file mode 100644 index 98217f1d..00000000 --- a/old/interfaces/innerkits/core/include/iprofile_event_notifier.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DEVICE_PROFILE_I_PROFILE_EVENT_NOTIFIER_H -#define OHOS_DEVICE_PROFILE_I_PROFILE_EVENT_NOTIFIER_H - -#include -#include "iremote_broker.h" -#include "iprofile_event_callback.h" - -namespace OHOS { -namespace DeviceProfile { -using SyncResult = std::map; - -class IProfileEventNotifier : public IRemoteBroker, public IProfileEventCallback { -public: - DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.DeviceProfile.IProfileEventNotifier"); -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DEVICE_PROFILE_I_PROFILE_EVENT_NOTIFIER_H diff --git a/old/interfaces/innerkits/core/include/profile_change_notification.h b/old/interfaces/innerkits/core/include/profile_change_notification.h deleted file mode 100644 index 85915a1f..00000000 --- a/old/interfaces/innerkits/core/include/profile_change_notification.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DEVICE_PROFILE_CHANGE_NOTIFICATION_H -#define OHOS_DEVICE_PROFILE_CHANGE_NOTIFICATION_H - -#include -#include - -#include "parcel.h" - -namespace OHOS { -namespace DeviceProfile { -enum class ProfileChangeType : uint8_t { - UNKNOWN_CHANGE_TYPE = 0, - INSERTED = 1, - UPDATED = 2, - DELETED = 3 -}; - -using Service2Index = std::map; - -struct ProfileEntry { - template - ProfileEntry(T&& k, T&& val, ProfileChangeType type) - : key(std::forward(k)), value(std::forward(val)), changeType(type) {} - ProfileEntry() {} - ~ProfileEntry() = default; - - bool Marshalling(Parcel& parcel) const; - bool Unmarshalling(Parcel& parcel); - - std::string key; - std::string value; - ProfileChangeType changeType {ProfileChangeType::UNKNOWN_CHANGE_TYPE}; -}; - -class ProfileChangeNotification : public Parcelable { -public: - ProfileChangeNotification(std::vector& profileEntries, - std::string& networkId, bool isLocal) - : profileEntries_(std::move(profileEntries)), - deviceId_(std::move(networkId)), isLocal_(isLocal) {} - ProfileChangeNotification() {} - ~ProfileChangeNotification() = default; - - const std::vector& GetProfileEntries() const; - const std::string& GetDeviceId() const; - bool IsLocal() const; - - bool Marshalling(Parcel& parcel) const override; - bool Unmarshalling(Parcel& parcel); - -private: - std::vector profileEntries_; - std::string deviceId_; - bool isLocal_ {false}; -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DEVICE_PROFILE_CHANGE_NOTIFICATION_H diff --git a/old/interfaces/innerkits/core/include/profile_event.h b/old/interfaces/innerkits/core/include/profile_event.h deleted file mode 100644 index 742a8b45..00000000 --- a/old/interfaces/innerkits/core/include/profile_event.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DEVICE_PROFILE_PROFILE_EVENT_H -#define OHOS_DEVICE_PROFILE_PROFILE_EVENT_H - -#include - -namespace OHOS { -namespace DeviceProfile { -enum ProfileEvent : uint32_t { - EVENT_UNKNOWN = 0, - EVENT_SYNC_COMPLETED = 1, - EVENT_PROFILE_CHANGED = 2, - EVENT_PROFILE_END, -}; - -using ProfileEvents = std::bitset; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DEVICE_PROFILE_PROFILE_EVENT_H \ No newline at end of file diff --git a/old/interfaces/innerkits/core/include/profile_event_notifier_stub.h b/old/interfaces/innerkits/core/include/profile_event_notifier_stub.h deleted file mode 100644 index 06cb678e..00000000 --- a/old/interfaces/innerkits/core/include/profile_event_notifier_stub.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DEVICE_PROFILE_I_PROFILE_SYNC_CALLBACK_STUB_H -#define OHOS_DEVICE_PROFILE_I_PROFILE_SYNC_CALLBACK_STUB_H - -#include -#include -#include -#include - -#include "iprofile_event_notifier.h" -#include "iremote_stub.h" -#include "message_parcel.h" -#include "refbase.h" - -namespace OHOS { -namespace DeviceProfile { -class ProfileEventNotifierStub : public IRemoteStub { -public: - explicit ProfileEventNotifierStub(const std::shared_ptr& profileEventCb) - : profileEventCb_(profileEventCb) {} - ~ProfileEventNotifierStub() = default; - - virtual int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, - MessageParcel& reply, MessageOption& option) override; - -private: - using Handler = int32_t(ProfileEventNotifierStub::*)(MessageParcel& data, MessageParcel& reply); - using HandlersMap = std::map; - - static HandlersMap InitHandlersMap(); - - int32_t OnSyncCompletedInner(MessageParcel& data, MessageParcel& reply); - int32_t OnProfileChangedInner(MessageParcel& data, MessageParcel& reply); - -private: - static const HandlersMap handlersMap_; - std::shared_ptr profileEventCb_; -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DEVICE_PROFILE_I_PROFILE_SYNC_CALLBACK_STUB_H diff --git a/old/interfaces/innerkits/core/include/service_characteristic_profile.h b/old/interfaces/innerkits/core/include/service_characteristic_profile.h deleted file mode 100644 index 009fc8db..00000000 --- a/old/interfaces/innerkits/core/include/service_characteristic_profile.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DEVICE_SERVICE_PROFILE_CHARACTERISTIC_PROFILE_H -#define OHOS_DEVICE_SERVICE_PROFILE_CHARACTERISTIC_PROFILE_H - -#include "parcel.h" - -namespace OHOS { -namespace DeviceProfile { -class ServiceCharacteristicProfile : public Parcelable { -public: - ServiceCharacteristicProfile() = default; - ~ServiceCharacteristicProfile() = default; - - void SetServiceId(const std::string& serviceId); - void SetServiceType(const std::string& serviceType); - void SetServiceProfileJson(const std::string& profileJson); - void SetCharacteristicProfileJson(const std::string& profileJson); - - const std::string& GetServiceId() const; - const std::string& GetServiceType() const; - const std::string& GetServiceProfileJson() const; - const std::string& GetCharacteristicProfileJson() const; - - bool Marshalling(Parcel& parcel) const override; - bool Unmarshalling(Parcel& parcel); - -private: - std::string serviceId_; - std::string serviceType_; - // reserved, not used currently - std::string serviceProfileJson_; - std::string characteristicProfileJson_; -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DEVICE_SERVICE_PROFILE_CHARACTERISTIC_PROFILE_H \ No newline at end of file diff --git a/old/interfaces/innerkits/core/include/subscribe_info.h b/old/interfaces/innerkits/core/include/subscribe_info.h deleted file mode 100644 index 62f4a888..00000000 --- a/old/interfaces/innerkits/core/include/subscribe_info.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DEVICE_PROFILE_SUBSCRIBE_INFO_H -#define OHOS_DEVICE_PROFILE_SUBSCRIBE_INFO_H - -#include "nlohmann/json.hpp" -#include "profile_event.h" -#include "parcel.h" - -namespace OHOS { -namespace DeviceProfile { -using ExtraInfo = nlohmann::json; - -struct SubscribeInfo : public Parcelable { - bool Marshalling(Parcel& parcel) const override; - bool Unmarshalling(Parcel& parcel); - - ProfileEvent profileEvent {ProfileEvent::EVENT_UNKNOWN}; - ExtraInfo extraInfo; - - bool operator!=(const SubscribeInfo& rhs) const; -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DEVICE_PROFILE_SUBSCRIBE_INFO_H \ No newline at end of file diff --git a/old/interfaces/innerkits/core/include/sync_options.h b/old/interfaces/innerkits/core/include/sync_options.h deleted file mode 100644 index c0c733ee..00000000 --- a/old/interfaces/innerkits/core/include/sync_options.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DEVICE_PROFILE_SYNC_OPTIONS_H -#define OHOS_DEVICE_PROFILE_SYNC_OPTIONS_H - -#include - -#include "parcel.h" - -namespace OHOS { -namespace DeviceProfile { -// must keep same with DistributedKv::SyncMode -enum class SyncMode : int64_t { - PULL, - PUSH, - PUSH_PULL, -}; - -class SyncOptions : public Parcelable { -public: - SyncOptions() = default; - ~SyncOptions() = default; - - const std::list& GetDeviceList() const; - SyncMode GetSyncMode() const; - - void AddDevice(const std::string& deviceId); - void SetSyncMode(SyncMode mode); - - bool Marshalling(Parcel& parcel) const override; - bool Unmarshalling(Parcel& parcel); - -private: - SyncMode syncMode_ {SyncMode::PUSH}; - std::list syncDevIds_; -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DEVICE_PROFILE_SYNC_OPTIONS_H \ No newline at end of file diff --git a/old/interfaces/innerkits/core/src/callback/device_profile_load_callback.cpp b/old/interfaces/innerkits/core/src/callback/device_profile_load_callback.cpp deleted file mode 100644 index 6d50dc0d..00000000 --- a/old/interfaces/innerkits/core/src/callback/device_profile_load_callback.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * 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. - */ - -#include "callback/device_profile_load_callback.h" - -#include "device_profile_log.h" -#include "distributed_device_profile_client.h" - -namespace OHOS { class IRemoteObject; } -namespace OHOS { -namespace DeviceProfile { - -const std::string TAG = "DeviceProfileLoadCallback"; - -void DeviceProfileLoadCallback::OnLoadSystemAbilitySuccess( - int32_t systemAbilityId, const sptr &remoteObject) -{ - DistributedDeviceProfileClient::GetInstance().LoadSystemAbilitySuccess(remoteObject); - HILOGI("on load system ability success!"); -} - -void DeviceProfileLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) -{ - DistributedDeviceProfileClient::GetInstance().LoadSystemAbilityFail(); - HILOGI("on load system ability failed!"); -} -} -} \ No newline at end of file diff --git a/old/interfaces/innerkits/core/src/distributed_device_profile_client.cpp b/old/interfaces/innerkits/core/src/distributed_device_profile_client.cpp deleted file mode 100644 index 7dbe3e01..00000000 --- a/old/interfaces/innerkits/core/src/distributed_device_profile_client.cpp +++ /dev/null @@ -1,386 +0,0 @@ -/* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. - * 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. - */ - -#include "distributed_device_profile_client.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "callback/device_profile_load_callback.h" -#include "device_profile_errors.h" -#include "device_profile_log.h" -#include "dp_radar_helper.h" -#include "event_handler.h" -#include "event_runner.h" -#include "idistributed_device_profile.h" -#include "if_system_ability_manager.h" -#include "ipc_skeleton.h" -#include "iremote_broker.h" -#include "iservice_registry.h" -#include "profile_event_notifier_stub.h" -#include "service_characteristic_profile.h" -#include "system_ability_definition.h" - -namespace OHOS { -namespace DeviceProfile { -using namespace std::chrono_literals; - -namespace { -const std::string TAG = "DistributedDeviceProfileClient"; -const std::string JSON_NULL = "null"; -constexpr int32_t DP_LOADSA_TIMEOUT_MS = 10000; -} - -IMPLEMENT_SINGLE_INSTANCE(DistributedDeviceProfileClient); - -bool DistributedDeviceProfileClient::LoadDeviceProfileService() -{ - std::unique_lock lock(serviceLock_); - sptr loadCallback = sptr(new DeviceProfileLoadCallback()); - if (loadCallback == nullptr) { - HILOGE("loadCallback is nullptr."); - return false; - } - - auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (samgrProxy == nullptr) { - HILOGE("get samgr failed"); - return false; - } - - int32_t ret = samgrProxy->LoadSystemAbility(DISTRIBUTED_DEVICE_PROFILE_SA_ID, loadCallback); - struct RadarInfo info = { - .funcName = "LoadDeviceProfileService", - .stageRes = (ret == ERR_OK) ? - static_cast(StageRes::STAGE_IDLE) : static_cast(StageRes::STAGE_FAIL), - .bizState = (ret == ERR_OK) ? - static_cast(BizState::BIZ_STATE_START) : static_cast(BizState::BIZ_STATE_END), - .toCallPkg = SAMAGRNAME, - .errCode = ERR_DP_LOAD_SERVICE_ERR, - }; - if (!DpRadarHelper::GetInstance().ReportLoadDpSa(info)) { - HILOGE("ReportLoadDpSa failed"); - } - if (ret != ERR_OK) { - HILOGE("Failed to Load systemAbility"); - return false; - } - - auto waitStatus = proxyConVar_.wait_for(lock, std::chrono::milliseconds(DP_LOADSA_TIMEOUT_MS), - [this]() { return dpProxy_ != nullptr; }); - if (!waitStatus) { - HILOGE("dp load sa timeout"); - return false; - } - return true; -} - -void DistributedDeviceProfileClient::LoadSystemAbilitySuccess(const sptr &remoteObject) -{ - HILOGI("DistributedDeviceProfileClient FinishStartSA"); - struct RadarInfo info = { - .funcName = "LoadSystemAbilitySuccess", - .stageRes = static_cast(StageRes::STAGE_SUCC), - .hostName = SAMAGRNAME, - }; - if (!DpRadarHelper::GetInstance().ReportLoadDpSaCb(info)) { - HILOGE("ReportLoadDpSaCb failed"); - } - std::lock_guard lock(serviceLock_); - if (dpDeathRecipient_ == nullptr) { - dpDeathRecipient_ = sptr( - new DeviceProfileDeathRecipient); - } - if (remoteObject != nullptr) { - remoteObject->AddDeathRecipient(dpDeathRecipient_); - dpProxy_ = iface_cast(remoteObject); - proxyConVar_.notify_one(); - } -} - -void DistributedDeviceProfileClient::LoadSystemAbilityFail() -{ - struct RadarInfo info = { - .funcName = "LoadSystemAbilityFail", - .stageRes = static_cast(StageRes::STAGE_FAIL), - .bizState = static_cast(BizState::BIZ_STATE_END), - .hostName = SAMAGRNAME, - .errCode = ERR_DP_LOAD_SERVICE_ERR, - }; - if (!DpRadarHelper::GetInstance().ReportLoadDpSaCb(info)) { - HILOGE("ReportLoadDpSaCb failed"); - } - std::lock_guard lock(serviceLock_); - dpProxy_ = nullptr; -} - -int32_t DistributedDeviceProfileClient::PutDeviceProfile(const ServiceCharacteristicProfile& profile) -{ - if (CheckProfileInvalidity(profile)) { - return ERR_DP_INVALID_PARAMS; - } - - auto dps = GetDeviceProfileService(); - if (dps == nullptr) { - HILOGE("get dp service failed"); - return ERR_DP_GET_SERVICE_FAILED; - } - return dps->PutDeviceProfile(profile); -} - -int32_t DistributedDeviceProfileClient::GetDeviceProfile(const std::string& udid, const std::string& serviceId, - ServiceCharacteristicProfile& profile) -{ - auto dps = GetDeviceProfileService(); - if (dps == nullptr) { - return ERR_DP_GET_SERVICE_FAILED; - } - return dps->GetDeviceProfile(udid, serviceId, profile); -} - -int32_t DistributedDeviceProfileClient::DeleteDeviceProfile(const std::string& serviceId) -{ - if (serviceId.empty()) { - return ERR_DP_INVALID_PARAMS; - } - - auto dps = GetDeviceProfileService(); - if (dps == nullptr) { - return ERR_DP_GET_SERVICE_FAILED; - } - return dps->DeleteDeviceProfile(serviceId); -} - -int32_t DistributedDeviceProfileClient::SubscribeProfileEvent(const SubscribeInfo& subscribeInfo, - const std::shared_ptr& eventCb) -{ - std::list subscribeInfos; - subscribeInfos.emplace_back(subscribeInfo); - std::list failedEvents; - return SubscribeProfileEvents(subscribeInfos, eventCb, failedEvents); -} - -int32_t DistributedDeviceProfileClient::SubscribeProfileEvents(const std::list& subscribeInfos, - const std::shared_ptr& eventCb, - std::list& failedEvents) -{ - if (subscribeInfos.empty() || eventCb == nullptr) { - return ERR_DP_INVALID_PARAMS; - } - - ProfileEvents subProfileEvents; - for (auto& subscribeInfo : subscribeInfos) { - subProfileEvents.set(static_cast(subscribeInfo.profileEvent)); - } - // duplicated profile event is disallowed - if (subProfileEvents.count() != subscribeInfos.size()) { - return ERR_DP_INVALID_PARAMS; - } - - std::unique_lock autoLock(subscribeLock_); - sptr notifier; - auto iter = subscribeRecords_.find(eventCb); - if (iter != subscribeRecords_.end()) { - notifier = iter->second.notifier; - } else { - notifier = sptr( - new ProfileEventNotifierStub(eventCb)); - } - autoLock.unlock(); - - auto dps = GetDeviceProfileService(); - if (dps == nullptr) { - return ERR_DP_GET_SERVICE_FAILED; - } - - failedEvents.clear(); - int32_t errCode = dps->SubscribeProfileEvents(subscribeInfos, notifier, failedEvents); - for (auto failedEvent : failedEvents) { - subProfileEvents.reset(static_cast(failedEvent)); - } - - autoLock.lock(); - iter = subscribeRecords_.find(eventCb); - if (iter != subscribeRecords_.end()) { - MergeSubscribeInfoLocked(iter->second.subscribeInfos, subscribeInfos); - iter->second.profileEvents |= subProfileEvents; - } else { - SubscribeRecord record {subscribeInfos, notifier, subProfileEvents}; - subscribeRecords_.emplace(eventCb, std::move(record)); - } - return errCode; -} - -int32_t DistributedDeviceProfileClient::UnsubscribeProfileEvent(ProfileEvent profileEvent, - const std::shared_ptr& eventCb) -{ - std::list profileEvents; - profileEvents.emplace_back(profileEvent); - std::list failedEvents; - return UnsubscribeProfileEvents(profileEvents, eventCb, failedEvents); -} - -int32_t DistributedDeviceProfileClient::UnsubscribeProfileEvents(const std::list& profileEvents, - const std::shared_ptr& eventCb, - std::list& failedEvents) -{ - if (profileEvents.empty() || eventCb == nullptr) { - return ERR_DP_INVALID_PARAMS; - } - - std::unique_lock autoLock(subscribeLock_); - ProfileEvents unsubProfileEvents; - for (auto profileEvent : profileEvents) { - unsubProfileEvents.set(static_cast(profileEvent)); - } - auto iter = subscribeRecords_.find(eventCb); - if (iter == subscribeRecords_.end()) { - return ERR_DP_NOT_SUBSCRIBED; - } - sptr notifier = iter->second.notifier; - autoLock.unlock(); - - auto dps = GetDeviceProfileService(); - if (dps == nullptr) { - return ERR_DP_GET_SERVICE_FAILED; - } - - failedEvents.clear(); - int32_t errCode = dps->UnsubscribeProfileEvents(profileEvents, notifier, failedEvents); - autoLock.lock(); - iter = subscribeRecords_.find(eventCb); - if (iter != subscribeRecords_.end()) { - for (auto failedEvent : failedEvents) { - unsubProfileEvents.reset(static_cast(failedEvent)); - } - auto& subProfileEvents = iter->second.profileEvents; - subProfileEvents &= ~unsubProfileEvents; - if (subProfileEvents.none()) { - subscribeRecords_.erase(iter); - } - } - return errCode; -} - -int32_t DistributedDeviceProfileClient::SyncDeviceProfile(const SyncOptions& syncOptions, - const std::shared_ptr& syncCb) -{ - auto dps = GetDeviceProfileService(); - if (dps == nullptr) { - return ERR_DP_GET_SERVICE_FAILED; - } - - sptr notifier = - sptr(new ProfileEventNotifierStub(syncCb)); - return dps->SyncDeviceProfile(syncOptions, notifier); -} - -sptr DistributedDeviceProfileClient::GetDeviceProfileService() -{ - { - std::lock_guard lock(serviceLock_); - if (dpProxy_ != nullptr) { - return dpProxy_; - } - auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (samgrProxy == nullptr) { - HILOGE("get samgr failed"); - return nullptr; - } - auto object = samgrProxy->CheckSystemAbility(DISTRIBUTED_DEVICE_PROFILE_SA_ID); - struct RadarInfo info = { - .funcName = "GetDeviceProfileService", - .stageRes = (object != nullptr) ? - static_cast(StageRes::STAGE_SUCC) : static_cast(StageRes::STAGE_FAIL), - .bizState = static_cast(BizState::BIZ_STATE_START), - .toCallPkg = SAMAGRNAME, - .errCode = ERR_DP_LOAD_SERVICE_ERR, - }; - if (!DpRadarHelper::GetInstance().ReportCheckDpSa(info)) { - HILOGE("ReportCheckDpSa failed"); - } - if (object != nullptr) { - HILOGI("get service succeeded"); - if (dpDeathRecipient_ == nullptr) { - dpDeathRecipient_ = sptr( - new DeviceProfileDeathRecipient); - } - object->AddDeathRecipient(dpDeathRecipient_); - dpProxy_ = iface_cast(object); - return dpProxy_; - } - } - - HILOGW("object is null"); - if (LoadDeviceProfileService()) { - std::lock_guard lock(serviceLock_); - if (dpProxy_ != nullptr) { - return dpProxy_; - } else { - HILOGE("load dp service failed"); - return nullptr; - } - } - HILOGE("load dp service failed"); - return nullptr; -} - -bool DistributedDeviceProfileClient::CheckProfileInvalidity(const ServiceCharacteristicProfile& profile) -{ - return profile.GetServiceId().empty() || - profile.GetServiceType().empty() || - profile.GetCharacteristicProfileJson().empty() || - profile.GetCharacteristicProfileJson() == JSON_NULL; -} - -void DistributedDeviceProfileClient::MergeSubscribeInfoLocked(std::list& subscribeInfos, - const std::list& newSubscribeInfos) -{ - for (const auto& newSubscribeInfo : newSubscribeInfos) { - auto iter = std::find_if(subscribeInfos.begin(), subscribeInfos.end(), - [&newSubscribeInfo](const auto& subscribeInfo) { - return subscribeInfo.profileEvent == newSubscribeInfo.profileEvent; - }); - if (iter == subscribeInfos.end()) { - subscribeInfos.emplace_back(newSubscribeInfo); - continue; - } - // override with the new subscribe info for same profile event - *iter = newSubscribeInfo; - } -} - -void DistributedDeviceProfileClient::OnServiceDied(const sptr& remote) -{ - HILOGI("called"); - std::lock_guard lock(serviceLock_); - dpProxy_ = nullptr; -} - -void DistributedDeviceProfileClient::DeviceProfileDeathRecipient::OnRemoteDied(const wptr& remote) -{ - DistributedDeviceProfileClient::GetInstance().OnServiceDied(remote.promote()); -} -} // namespace DeviceProfile -} // namespace OHOS diff --git a/old/interfaces/innerkits/core/src/distributed_device_profile_proxy.cpp b/old/interfaces/innerkits/core/src/distributed_device_profile_proxy.cpp deleted file mode 100644 index e590a049..00000000 --- a/old/interfaces/innerkits/core/src/distributed_device_profile_proxy.cpp +++ /dev/null @@ -1,213 +0,0 @@ -/* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. - * 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. - */ - -#include "distributed_device_profile_proxy.h" - -#include - -#include "deviceprofile_ipc_interface_code.h" -#include "device_profile_log.h" -#include "device_profile_utils.h" -#include "errors.h" -#include "ipc_types.h" -#include "iremote_object.h" -#include "message_option.h" -#include "message_parcel.h" -#include "parcel_helper.h" -#include "service_characteristic_profile.h" -#include "subscribe_info.h" -#include "sync_options.h" - -namespace OHOS { -namespace DeviceProfile { -namespace { -const std::string TAG = "DistributedDeviceProfileProxy"; -} - -int32_t DistributedDeviceProfileProxy::PutDeviceProfile(const ServiceCharacteristicProfile& profile) -{ - sptr remote = Remote(); - if (remote == nullptr) { - HILOGE("remote is nullptr"); - return ERR_FLATTEN_OBJECT; - } - MessageParcel data; - if (!data.WriteInterfaceToken(IDistributedDeviceProfile::GetDescriptor())) { - HILOGE("write interface token failed"); - return ERR_FLATTEN_OBJECT; - } - if (!profile.Marshalling(data)) { - HILOGE("marshall profile failed"); - return ERR_FLATTEN_OBJECT; - } - MessageParcel reply; - PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast(IDeviceProfileInterfaceCode::PUT_DEVICE_PROFILE), - data, reply); -} - -int32_t DistributedDeviceProfileProxy::GetDeviceProfile(const std::string& udid, const std::string& serviceId, - ServiceCharacteristicProfile& profile) -{ - sptr remote = Remote(); - if (remote == nullptr) { - HILOGE("remote is nullptr"); - return ERR_FLATTEN_OBJECT; - } - MessageParcel data; - if (!data.WriteInterfaceToken(IDistributedDeviceProfile::GetDescriptor())) { - HILOGE("write interface token failed"); - return ERR_FLATTEN_OBJECT; - } - PARCEL_WRITE_HELPER(data, String, udid); - PARCEL_WRITE_HELPER(data, String, serviceId); - MessageParcel reply; - MessageOption option; - int32_t errCode = remote->SendRequest(static_cast(IDeviceProfileInterfaceCode::GET_DEVICE_PROFILE), - data, reply, option); - if (errCode != ERR_NONE) { - HILOGE("transact failed, errCode = %{public}d", errCode); - return errCode; - } - int32_t ret = reply.ReadInt32(); - if (!profile.Unmarshalling(reply)) { - HILOGE("profile unmarshall failed"); - return ERR_FLATTEN_OBJECT; - } - HILOGI("ret = %{public}d", ret); - return ret; -} - -int32_t DistributedDeviceProfileProxy::DeleteDeviceProfile(const std::string& serviceId) -{ - sptr remote = Remote(); - if (remote == nullptr) { - HILOGE("remote is nullptr"); - return ERR_FLATTEN_OBJECT; - } - MessageParcel data; - if (!data.WriteInterfaceToken(IDistributedDeviceProfile::GetDescriptor())) { - HILOGE("write interface token failed"); - return ERR_FLATTEN_OBJECT; - } - PARCEL_WRITE_HELPER(data, String, serviceId); - MessageParcel reply; - PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast(IDeviceProfileInterfaceCode::DELETE_DEVICE_PROFILE), - data, reply); -} - -int32_t DistributedDeviceProfileProxy::SubscribeProfileEvents( - const std::list& subscribeInfos, - const sptr& profileEventNotifier, - std::list& failedEvents) -{ - sptr remote = Remote(); - if (remote == nullptr) { - HILOGE("remote is nullptr"); - return ERR_FLATTEN_OBJECT; - } - MessageParcel data; - if (!data.WriteInterfaceToken(IDistributedDeviceProfile::GetDescriptor())) { - HILOGE("write interface token failed"); - return ERR_FLATTEN_OBJECT; - } - size_t size = subscribeInfos.size(); - PARCEL_WRITE_HELPER(data, Uint32, static_cast(size)); - for (const auto& subscribeInfo : subscribeInfos) { - if (!subscribeInfo.Marshalling(data)) { - HILOGE("marshall subscribe info failed"); - return ERR_FLATTEN_OBJECT; - } - } - PARCEL_WRITE_HELPER(data, RemoteObject, profileEventNotifier); - MessageParcel reply; - MessageOption option; - int32_t errCode = remote->SendRequest(static_cast(IDeviceProfileInterfaceCode::SUBSCRIBE_PROFILE_EVENT), - data, reply, option); - if (errCode != ERR_NONE) { - HILOGE("transact failed, errCode = %{public}d", errCode); - return errCode; - } - int32_t ret = reply.ReadInt32(); - if ((ret != ERR_OK) && !DeviceProfileUtils::ReadProfileEvents(reply, failedEvents)) { - HILOGE("read profile events failed"); - return ERR_FLATTEN_OBJECT; - } - HILOGI("ret = %{public}d", ret); - return ret; -} - -int32_t DistributedDeviceProfileProxy::UnsubscribeProfileEvents( - const std::list& profileEvents, - const sptr& profileEventNotifier, - std::list& failedEvents) -{ - sptr remote = Remote(); - if (remote == nullptr) { - HILOGE("remote is nullptr"); - return ERR_FLATTEN_OBJECT; - } - MessageParcel data; - if (!data.WriteInterfaceToken(IDistributedDeviceProfile::GetDescriptor())) { - HILOGE("write interface token failed"); - return ERR_FLATTEN_OBJECT; - } - if (!DeviceProfileUtils::WriteProfileEvents(profileEvents, data)) { - return ERR_FLATTEN_OBJECT; - } - - PARCEL_WRITE_HELPER(data, RemoteObject, profileEventNotifier); - MessageParcel reply; - MessageOption option; - int32_t errCode = remote->SendRequest( - static_cast(IDeviceProfileInterfaceCode::UNSUBSCRIBE_PROFILE_EVENT), data, reply, option); - if (errCode != ERR_NONE) { - HILOGE("transact failed, errCode = %{public}d", errCode); - return errCode; - } - int32_t ret = reply.ReadInt32(); - if ((ret != ERR_OK) && !DeviceProfileUtils::ReadProfileEvents(reply, failedEvents)) { - HILOGW("read profile events failed"); - return ERR_FLATTEN_OBJECT; - } - HILOGI("ret = %{public}d", ret); - return ret; -} - -int32_t DistributedDeviceProfileProxy::SyncDeviceProfile(const SyncOptions& syncOptions, - const sptr& profileEventNotifier) -{ - sptr remote = Remote(); - if (remote == nullptr) { - HILOGE("remote is nullptr"); - return ERR_FLATTEN_OBJECT; - } - MessageParcel data; - if (!data.WriteInterfaceToken(IDistributedDeviceProfile::GetDescriptor())) { - HILOGE("write interface token failed"); - return ERR_FLATTEN_OBJECT; - } - - if (!syncOptions.Marshalling(data)) { - HILOGE("marshall option failed"); - return ERR_FLATTEN_OBJECT; - } - - PARCEL_WRITE_HELPER(data, RemoteObject, profileEventNotifier); - MessageParcel reply; - PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast(IDeviceProfileInterfaceCode::SYNC_DEVICE_PROFILE), - data, reply); -} -} // namespace DeviceProfile -} // namespace OHOS \ No newline at end of file diff --git a/old/interfaces/innerkits/core/src/profile_event_notifier_stub.cpp b/old/interfaces/innerkits/core/src/profile_event_notifier_stub.cpp deleted file mode 100644 index cb24d1a1..00000000 --- a/old/interfaces/innerkits/core/src/profile_event_notifier_stub.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. - * 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. - */ - -#include "profile_event_notifier_stub.h" - -#include -#include -#include - -#include "device_profile_errors.h" -#include "device_profile_log.h" -#include "errors.h" -#include "ipc_object_stub.h" -#include "iprofile_event_callback.h" -#include "message_parcel.h" -#include "profile_change_notification.h" -#include "profile_event.h" - -namespace OHOS { -namespace DeviceProfile { -namespace { -const std::string TAG = "ProfileEventNotifierStub"; -constexpr int32_t MAX_SYNC_RESULTS_SIZE = 50; -} - -const ProfileEventNotifierStub::HandlersMap ProfileEventNotifierStub::handlersMap_ = - ProfileEventNotifierStub::InitHandlersMap(); - -ProfileEventNotifierStub::HandlersMap ProfileEventNotifierStub::InitHandlersMap() -{ - ProfileEventNotifierStub::HandlersMap m; - m[EVENT_SYNC_COMPLETED] = &ProfileEventNotifierStub::OnSyncCompletedInner; - m[EVENT_PROFILE_CHANGED] = &ProfileEventNotifierStub::OnProfileChangedInner; - return m; -} - -int32_t ProfileEventNotifierStub::OnRemoteRequest(uint32_t code, MessageParcel& data, - MessageParcel& reply, MessageOption& option) -{ - HILOGI("code = %{public}u", code); - std::u16string descriptor = ProfileEventNotifierStub::GetDescriptor(); - std::u16string remoteDescriptor = data.ReadInterfaceToken(); - if (descriptor != remoteDescriptor) { - HILOGE("check descriptor failed"); - return ERR_DP_INTERFACE_CHECK_FAILED; - } - - switch (code) { - case ProfileEvent::EVENT_SYNC_COMPLETED: - return ProfileEventNotifierStub::OnSyncCompletedInner(data, reply); - case ProfileEvent::EVENT_PROFILE_CHANGED: - return ProfileEventNotifierStub::OnProfileChangedInner(data, reply); - default: - HILOGW("unknown request code, please check, code = %{public}u", code); - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } -} - -__attribute__((no_sanitize("cfi"))) int32_t ProfileEventNotifierStub::OnSyncCompletedInner(MessageParcel& data, - [[maybe_unused]] MessageParcel& reply) -{ - int32_t size = data.ReadInt32(); - if (size <= 0 || size > MAX_SYNC_RESULTS_SIZE) { - HILOGW("size %{public}d", size); - return ERR_DP_INVALID_PARAMS; - } - - SyncResult syncResults; - for (int32_t i = 0; i < size; i++) { - syncResults.emplace(data.ReadString(), static_cast(data.ReadInt32())); - } - if (profileEventCb_ != nullptr) { - profileEventCb_->OnSyncCompleted(syncResults); - } - return ERR_OK; -} - -__attribute__((no_sanitize("cfi"))) int32_t ProfileEventNotifierStub::OnProfileChangedInner(MessageParcel& data, - [[maybe_unused]] MessageParcel& reply) -{ - ProfileChangeNotification changeNotification; - if (!changeNotification.Unmarshalling(data)) { - HILOGW("marshalling failed"); - return ERR_DP_INVALID_PARAMS; - } - profileEventCb_->OnProfileChanged(changeNotification); - return ERR_OK; -} -} // namespace DeviceProfile -} // namespace OHOS diff --git a/old/permission/BUILD.gn b/old/permission/BUILD.gn deleted file mode 100644 index c272d1fa..00000000 --- a/old/permission/BUILD.gn +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. -# 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. - -import("//build/ohos.gni") - -ohos_prebuilt_etc("authority_json") { - install_enable = true - source = "authority.json" - relative_install_dir = "deviceprofile" - part_name = "device_info_manager" - subsystem_name = "deviceprofile" -} diff --git a/old/permission/authority.json b/old/permission/authority.json deleted file mode 100644 index 0b18fe66..00000000 --- a/old/permission/authority.json +++ /dev/null @@ -1,59 +0,0 @@ -{ - "distributedsched": { - "servicesAuthority": { - "specific": { - "appInfo": 1 - } - } - }, - "foundation": { - "servicesAuthority": { - "specific": { - "syscap": 1 - } - } - }, - "multimodalinput": { - "servicesAuthority": { - "specific": { - "InputDeviceCooperation": 3 - } - }, - "interfacesAuthority": { - "sync": {} - } - }, - "pasteboard_service": { - "servicesAuthority": { - "specific": { - "pasteboardService": 3 - } - }, - "interfacesAuthority": { - "sync": {} - } - }, - "msdp_sa": { - "servicesAuthority": { - "specific": { - "deviceStatus": 3 - } - }, - "interfacesAuthority": { - "sync": {} - } - }, - "CollaborationFwk": { - "servicesAuthority": { - "specific": { - "collaborationFwk": 3, - "infoCollection": 3, - "serviceNameCollection": 3, - "deviceStatus": 1 - } - }, - "interfacesAuthority": { - "sync": {} - } - } -} diff --git a/old/radar/BUILD.gn b/old/radar/BUILD.gn deleted file mode 100644 index 63e5bf28..00000000 --- a/old/radar/BUILD.gn +++ /dev/null @@ -1,57 +0,0 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. -# 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. - -import("//build/ohos.gni") -import("//build/ohos_var.gni") -import("//foundation/deviceprofile/device_info_manager/deviceprofile.gni") -ohos_shared_library("deviceprofileradar") { - branch_protector_ret = "pac_ret" - - ldflags = [ - "-Wl,-z,relro", - "-Wl,-z,now", - ] - - cflags = [ - "-fPIC", - "-D_FORTIFY_SOURCE=2", - "-O2", - ] - - cflags_cc = cflags - - sanitize = { - boundary_sanitize = true - integer_overflow = true - ubsan = true - cfi = true - cfi_cross_dso = true - debug = false - } - - include_dirs = [ - "include", - "${old_device_profile_path}/common/include", - ] - - sources = [ "src/dp_radar_helper.cpp" ] - - external_deps = [ - "c_utils:utils", - "hilog:libhilog", - "hisysevent:libhisysevent", - ] - - part_name = "device_info_manager" - subsystem_name = "deviceprofile" -} diff --git a/old/radar/include/dp_radar_helper.h b/old/radar/include/dp_radar_helper.h deleted file mode 100644 index 1e84ba8b..00000000 --- a/old/radar/include/dp_radar_helper.h +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DP_RADAR_HELPER_H -#define OHOS_DP_RADAR_HELPER_H - -#include -#include -#include -#include -#include - -#include "single_instance.h" - -namespace OHOS { -namespace DeviceProfile { -const std::string ORGPKGNAME = "deviceprofile"; -const std::string SAMAGRNAME = "SA"; -const std::string kvNAME = "distrubitedKv"; -const std::string DP_DATA_OPERATE_BEHAVIOR = "DP_DATA_OPERATE_BEHAVIOR"; -const int32_t SUBSYS_DISTRIBUTEDHARDWARE_DP = 205; -constexpr int32_t INVALID_UDID_LENGTH = 10; -constexpr int32_t SUBSTR_UDID_LENGTH = 5; -enum class BizScene : int32_t { - DP_GET_SA = 0x1, - DP_ADD_DATA = 0x2, - DP_DELET_DATA = 0x3, - DP_GET_DATA = 0x4, - DP_SUBSCRIBE_DATA = 0x5, - DP_UNSUBSCRIBE_DATA = 0x6, - DP_SYNC_DATA = 0x7, -}; - -enum class StageRes : int32_t { - STAGE_IDLE = 0x0, - STAGE_SUCC = 0x1, - STAGE_FAIL = 0x2, - STAGE_CANCEL = 0x3, - STAGE_UNKNOW = 0x4, -}; - -enum class BizState : int32_t { - BIZ_STATE_START = 0x1, - BIZ_STATE_END = 0x2, - BIZ_STATE_CANCEL = 0x3, -}; - -enum class GetSaStage : int32_t { - DP_CHECK_SA = 0x1, - DP_LOAD_SA = 0x2, - DP_SA_CHACK_AUTH = 0x3, -}; - -enum class GetDataStage : int32_t { - DP_GET_DATA = 0x1, -}; - -enum class AddDataStage : int32_t { - DP_ADD_DATA = 0x1, -}; - -enum class DelDataStage : int32_t { - DP_DELET_DATA = 0x1, -}; - -enum class SubscribeDataStage : int32_t { - DP_SUBSCRIBE_DATA = 0x1, - DP_RECIVE_DATA_CHANGE = 0x2, -}; - -enum class UnSubscribeDataStage : int32_t { - DP_UNSUBSCRIBE_DATA = 0x1, -}; - -enum class SyncDataStage : int32_t { - DP_SYNC_DATA = 0x1, - DP_RECIVE_SYNC_CALLBACK = 0x2, -}; - -enum class Module : int32_t { - DEVICE_PROFILE = 0x0, - SA_MGR = 0x1, - DISTRIBUTED_KV = 0x2, -}; - -struct RadarInfo { - std::string funcName; - int32_t stageRes; - int32_t bizState; - std::string toCallPkg; - std::string hostName; - std::string localUdid; - std::string peerUdid; - int32_t errCode; -}; - -class DpRadarHelper { - DECLARE_SINGLE_INSTANCE(DpRadarHelper); -public: - bool ReportCheckDpSa(struct RadarInfo info); - bool ReportLoadDpSa(struct RadarInfo info); - bool ReportLoadDpSaCb(struct RadarInfo info); - bool ReportSaCheckAuth(struct RadarInfo info); - bool ReportGetData(struct RadarInfo info); - bool ReportAddData(struct RadarInfo info); - bool ReportDeleteData(struct RadarInfo info); - bool ReportSubscribeData(struct RadarInfo info); - bool ReportNotifyDataChange(struct RadarInfo info); - bool ReportUnsbscribeData(struct RadarInfo info); - bool ReportSyncData(struct RadarInfo info); - bool ReportSyncDataCb(struct RadarInfo info); - std::string GetHostNameByServiceId(std::string serviceId); - std::string GetStringUdidList(std::list &udidList); -private: - int32_t GetErrorCode(int32_t errCode, int32_t module); - std::string GetAnonyUdid(std::string udid); - std::map hostNameMap_ = { - {"infoCollection", "CollaborationFwk"}, - {"pasteboardService", "pasteboardService"}, - {"appInfo", "dmsfwk"}, - {"deviceStatus", "msdp"}, - }; -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DP_RADAR_HELPER_H \ No newline at end of file diff --git a/old/radar/src/dp_radar_helper.cpp b/old/radar/src/dp_radar_helper.cpp deleted file mode 100644 index a7b83512..00000000 --- a/old/radar/src/dp_radar_helper.cpp +++ /dev/null @@ -1,460 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * 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. - */ - -#include "dp_radar_helper.h" -#include -#include "hisysevent.h" -#include "device_profile_log.h" - -namespace OHOS { -namespace DeviceProfile { -IMPLEMENT_SINGLE_INSTANCE(DpRadarHelper); -bool DpRadarHelper::ReportCheckDpSa(struct RadarInfo info) -{ - int32_t res = ERR_OK; - if (info.stageRes == static_cast(StageRes::STAGE_SUCC)) { - res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", info.funcName, - "BIZ_SCENE", static_cast(BizScene::DP_GET_SA), - "BIZ_STAGE", static_cast(GetSaStage::DP_CHECK_SA), - "STAGE_RES", info.stageRes, - "BIZ_STATE", info.bizState, - "TO_CALL_PKG", info.toCallPkg); - } else { - res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", info.funcName, - "BIZ_SCENE", static_cast(BizScene::DP_GET_SA), - "BIZ_STAGE", static_cast(GetSaStage::DP_CHECK_SA), - "STAGE_RES", info.stageRes, - "BIZ_STATE", info.bizState, - "TO_CALL_PKG", info.toCallPkg, - "ERROR_CODE", info.errCode); - } - if (res != ERR_OK) { - return false; - } - return true; -} - -bool DpRadarHelper::ReportLoadDpSa(struct RadarInfo info) -{ - int32_t res = ERR_OK; - if (info.stageRes == static_cast(StageRes::STAGE_IDLE)) { - res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", info.funcName, - "BIZ_SCENE", static_cast(BizScene::DP_GET_SA), - "BIZ_STAGE", static_cast(GetSaStage::DP_LOAD_SA), - "STAGE_RES", info.stageRes, - "TO_CALL_PKG", info.toCallPkg); - } else { - res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", info.funcName, - "BIZ_SCENE", static_cast(BizScene::DP_GET_SA), - "BIZ_STAGE", static_cast(GetSaStage::DP_LOAD_SA), - "STAGE_RES", info.stageRes, - "BIZ_STATE", info.bizState, - "TO_CALL_PKG", info.toCallPkg, - "ERROR_CODE", info.errCode); - } - if (res != ERR_OK) { - return false; - } - return true; -} - -bool DpRadarHelper::ReportLoadDpSaCb(struct RadarInfo info) -{ - int32_t res = ERR_OK; - if (info.stageRes == static_cast(StageRes::STAGE_IDLE)) { - res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", info.funcName, - "BIZ_SCENE", static_cast(BizScene::DP_GET_SA), - "BIZ_STAGE", static_cast(GetSaStage::DP_LOAD_SA), - "STAGE_RES", info.stageRes, - "HOST_NAME", info.hostName); - } else { - res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", info.funcName, - "BIZ_SCENE", static_cast(BizScene::DP_GET_SA), - "BIZ_STAGE", static_cast(GetSaStage::DP_LOAD_SA), - "STAGE_RES", info.stageRes, - "BIZ_STATE", info.bizState, - "HOST_NAME", info.hostName, - "ERROR_CODE", info.errCode); - } - if (res != ERR_OK) { - return false; - } - return true; -} - -bool DpRadarHelper::ReportSaCheckAuth(struct RadarInfo info) -{ - int res = ERR_OK; - if (info.stageRes == static_cast(StageRes::STAGE_SUCC)) { - res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", info.funcName, - "BIZ_SCENE", static_cast(BizScene::DP_GET_SA), - "BIZ_STAGE", static_cast(GetSaStage::DP_SA_CHACK_AUTH), - "STAGE_RES", info.stageRes, - "BIZ_STATE", info.bizState); - } else { - res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", info.funcName, - "BIZ_SCENE", static_cast(BizScene::DP_GET_SA), - "BIZ_STAGE", static_cast(GetSaStage::DP_SA_CHACK_AUTH), - "STAGE_RES", info.stageRes, - "BIZ_STATE", info.bizState, - "ERROR_CODE", info.errCode); - } - if (res != ERR_OK) { - return false; - } - return true; -} - -bool DpRadarHelper::ReportGetData(struct RadarInfo info) -{ - int res = ERR_OK; - if (info.stageRes == static_cast(StageRes::STAGE_SUCC)) { - res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", info.funcName, - "BIZ_SCENE", static_cast(BizScene::DP_GET_DATA), - "BIZ_STAGE", static_cast(GetDataStage::DP_GET_DATA), - "STAGE_RES", info.stageRes, - "BIZ_STATE", static_cast(BizState::BIZ_STATE_END), - "HOST_PKG", info.hostName, - "TO_CALL_PKG", info.toCallPkg, - "LOCAL_UDID", GetAnonyUdid(info.localUdid)); - } else { - res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", info.funcName, - "BIZ_SCENE", static_cast(BizScene::DP_GET_DATA), - "BIZ_STAGE", static_cast(GetDataStage::DP_GET_DATA), - "STAGE_RES", info.stageRes, - "BIZ_STATE", static_cast(BizState::BIZ_STATE_END), - "LOCAL_UDID", GetAnonyUdid(info.localUdid), - "HOST_PKG", info.hostName, - "TO_CALL_PKG", info.toCallPkg, - "ERROR_CODE", info.errCode); - } - if (res != ERR_OK) { - return false; - } - return true; -} - -bool DpRadarHelper::ReportAddData(struct RadarInfo info) -{ - int res = ERR_OK; - if (info.stageRes == static_cast(StageRes::STAGE_SUCC)) { - res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", info.funcName, - "BIZ_SCENE", static_cast(BizScene::DP_ADD_DATA), - "BIZ_STAGE", static_cast(AddDataStage::DP_ADD_DATA), - "STAGE_RES", info.stageRes, - "BIZ_STATE", static_cast(BizState::BIZ_STATE_END), - "LOCAL_UDID", GetAnonyUdid(info.localUdid), - "HOST_PKG", info.hostName, - "TO_CALL_PKG", info.toCallPkg); - } else { - res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", info.funcName, - "BIZ_SCENE", static_cast(BizScene::DP_ADD_DATA), - "BIZ_STAGE", static_cast(AddDataStage::DP_ADD_DATA), - "STAGE_RES", info.stageRes, - "BIZ_STATE", static_cast(BizState::BIZ_STATE_END), - "LOCAL_UDID", GetAnonyUdid(info.localUdid), - "HOST_PKG", info.hostName, - "TO_CALL_PKG", info.toCallPkg, - "ERROR_CODE", info.errCode); - } - if (res != ERR_OK) { - return false; - } - return true; -} - -bool DpRadarHelper::ReportDeleteData(struct RadarInfo info) -{ - int res = ERR_OK; - if (info.stageRes == static_cast(StageRes::STAGE_SUCC)) { - res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", info.funcName, - "BIZ_SCENE", static_cast(BizScene::DP_DELET_DATA), - "BIZ_STAGE", static_cast(static_cast(DelDataStage::DP_DELET_DATA)), - "STAGE_RES", info.stageRes, - "BIZ_STATE", static_cast(BizState::BIZ_STATE_END), - "HOST_PKG", info.hostName, - "TO_CALL_PKG", info.toCallPkg, - "LOCAL_UDID", GetAnonyUdid(info.localUdid)); - } else { - res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", info.funcName, - "BIZ_SCENE", static_cast(BizScene::DP_DELET_DATA), - "BIZ_STAGE", static_cast(static_cast(DelDataStage::DP_DELET_DATA)), - "STAGE_RES", info.stageRes, - "BIZ_STATE", static_cast(BizState::BIZ_STATE_END), - "LOCAL_UDID", GetAnonyUdid(info.localUdid), - "HOST_PKG", info.hostName, - "TO_CALL_PKG", info.toCallPkg, - "ERROR_CODE", info.errCode); - } - if (res != ERR_OK) { - return false; - } - return true; -} - -bool DpRadarHelper::ReportSubscribeData(struct RadarInfo info) -{ - int res = ERR_OK; - if (info.stageRes == static_cast(StageRes::STAGE_IDLE)) { - res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", "SubscribeProfileEvents", - "BIZ_SCENE", static_cast(BizScene::DP_SUBSCRIBE_DATA), - "BIZ_STAGE", static_cast(SubscribeDataStage::DP_SUBSCRIBE_DATA), - "STAGE_RES", info.stageRes, - "BIZ_STATE", static_cast(BizState::BIZ_STATE_START), - "TO_CALL_PKG", kvNAME); - } else { - res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", "SubscribeProfileEvents", - "BIZ_SCENE", static_cast(BizScene::DP_SUBSCRIBE_DATA), - "BIZ_STAGE", static_cast(SubscribeDataStage::DP_SUBSCRIBE_DATA), - "STAGE_RES", info.stageRes, - "BIZ_STATE", static_cast(BizState::BIZ_STATE_END), - "TO_CALL_PKG", kvNAME, - "ERROR_CODE", info.errCode); - } - if (res != ERR_OK) { - return false; - } - return true; -} - -bool DpRadarHelper::ReportNotifyDataChange(struct RadarInfo info) -{ - int32_t res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", info.funcName, - "BIZ_SCENE", static_cast(BizScene::DP_SUBSCRIBE_DATA), - "BIZ_STAGE", static_cast(SubscribeDataStage::DP_RECIVE_DATA_CHANGE), - "STAGE_RES", info.stageRes, - "BIZ_STATE", static_cast(BizState::BIZ_STATE_END)); - if (res != ERR_OK) { - return false; - } - return true; -} - -bool DpRadarHelper::ReportUnsbscribeData(struct RadarInfo info) -{ - int res = ERR_OK; - if (info.stageRes == static_cast(StageRes::STAGE_SUCC)) { - res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", info.funcName, - "BIZ_SCENE", static_cast(BizScene::DP_UNSUBSCRIBE_DATA), - "BIZ_STAGE", static_cast(UnSubscribeDataStage::DP_UNSUBSCRIBE_DATA), - "STAGE_RES", info.stageRes, - "BIZ_STATE", static_cast(BizState::BIZ_STATE_END), - "HOST_PKG", info.hostName, - "TO_CALL_PKG", info.toCallPkg); - } else { - res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", info.funcName, - "BIZ_SCENE", static_cast(BizScene::DP_UNSUBSCRIBE_DATA), - "BIZ_STAGE", static_cast(UnSubscribeDataStage::DP_UNSUBSCRIBE_DATA), - "STAGE_RES", info.stageRes, - "BIZ_STATE", static_cast(BizState::BIZ_STATE_END), - "HOST_PKG", info.hostName, - "TO_CALL_PKG", info.toCallPkg, - "ERROR_CODE", info.errCode); - } - if (res != ERR_OK) { - return false; - } - return true; -} - -bool DpRadarHelper::ReportSyncData(struct RadarInfo info) -{ - int res = ERR_OK; - if (info.stageRes == static_cast(StageRes::STAGE_IDLE)) { - res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", "SyncDeviceProfile", - "BIZ_SCENE", static_cast(BizScene::DP_SYNC_DATA), - "BIZ_STAGE", static_cast(SyncDataStage::DP_SYNC_DATA), - "STAGE_RES", info.stageRes, - "BIZ_STATE", static_cast(BizState::BIZ_STATE_START), - "HOST_PKG", info.hostName, - "PEER_UDID", GetAnonyUdid(info.peerUdid), - "TO_CALL_PKG", kvNAME); - } else { - res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", "SyncDeviceProfile", - "BIZ_SCENE", static_cast(BizScene::DP_SYNC_DATA), - "BIZ_STAGE", static_cast(SyncDataStage::DP_SYNC_DATA), - "STAGE_RES", info.stageRes, - "BIZ_STATE", static_cast(BizState::BIZ_STATE_END), - "HOST_PKG", info.hostName, - "PEER_UDID", GetAnonyUdid(info.peerUdid), - "TO_CALL_PKG", kvNAME, - "ERROR_CODE", info.errCode); - } - if (res != ERR_OK) { - return false; - } - return true; -} - -bool DpRadarHelper::ReportSyncDataCb(struct RadarInfo info) -{ - int32_t res = HiSysEventWrite( - OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE, - DP_DATA_OPERATE_BEHAVIOR, - HiviewDFX::HiSysEvent::EventType::BEHAVIOR, - "ORG_PKG", ORGPKGNAME, - "FUNC", info.funcName, - "BIZ_SCENE", static_cast(BizScene::DP_SYNC_DATA), - "BIZ_STAGE", static_cast(SyncDataStage::DP_RECIVE_SYNC_CALLBACK), - "STAGE_RES", info.stageRes, - "BIZ_STATE", info.bizState, - "LOCAL_UDID", GetAnonyUdid(info.localUdid)); - if (res != ERR_OK) { - return false; - } - return true; -} - -std::string DpRadarHelper::GetHostNameByServiceId(std::string serviceId) -{ - if (hostNameMap_.find(serviceId) != hostNameMap_.end()) { - return hostNameMap_[serviceId]; - } - return ""; -} - -std::string DpRadarHelper::GetStringUdidList(std::list &udidList) -{ - std::string ret = ""; - for (auto it = udidList.begin(); it != udidList.end(); it++) { - if ((*it).compare(udidList.back()) == 0) { - ret += GetAnonyUdid(*it); - } else { - ret += GetAnonyUdid(*it); - ret += ","; - } - } - return ret; -} - -int32_t DpRadarHelper::GetErrorCode(int32_t errCode, int32_t module) -{ - return ErrCodeOffset(SUBSYS_DISTRIBUTEDHARDWARE_DP, module) + errCode; -} - -std::string DpRadarHelper::GetAnonyUdid(std::string udid) -{ - if (udid.empty() || udid.length() < INVALID_UDID_LENGTH) { - return ""; - } - return udid.substr(0, SUBSTR_UDID_LENGTH) + "**" + udid.substr(udid.length() - SUBSTR_UDID_LENGTH); -} -} // namespace DeviceProfile -} // namespace OHOS \ No newline at end of file diff --git a/old/radar/test/unittest/BUILD.gn b/old/radar/test/unittest/BUILD.gn deleted file mode 100644 index eab35500..00000000 --- a/old/radar/test/unittest/BUILD.gn +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. -# 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. - -import("//build/ohos.gni") -import("//build/ohos_var.gni") -import("//build/test.gni") -import("//foundation/deviceprofile/device_info_manager/deviceprofile.gni") - -module_output_path = "device_info_manager/device_info_manager" - -device_profile_deps = [ - "${old_device_profile_innerkits}/core:distributed_device_profile_client", - "${old_device_profile_path}/radar:deviceprofileradar", - "${old_device_profile_service}/core:distributed_device_profile", -] - -device_profile_external_deps = [ - "hilog:libhilog", - "hisysevent:libhisysevent", - "ipc:ipc_core", -] - -ohos_unittest("dp_radar_helper_test_old") { - cflags = [ - "-Dprivate=public", - "-Dprotected=public", - ] - module_out_path = module_output_path - include_dirs = [ "${old_device_profile_path}/radar/include" ] - sources = [ "dp_radar_helper_test.cpp" ] - deps = device_profile_deps - external_deps = device_profile_external_deps - part_name = "device_info_manager" - subsystem_name = "deviceprofile" -} diff --git a/old/radar/test/unittest/dp_radar_helper_test.cpp b/old/radar/test/unittest/dp_radar_helper_test.cpp deleted file mode 100644 index 6ec00106..00000000 --- a/old/radar/test/unittest/dp_radar_helper_test.cpp +++ /dev/null @@ -1,219 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * 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. - */ - -#include "dp_radar_helper_test.h" -#include "dp_radar_helper.h" - -namespace OHOS { -namespace DeviceProfile { -void DpRadarHelperTest::SetUp() -{ -} - -void DpRadarHelperTest::TearDown() -{ -} - -void DpRadarHelperTest::SetUpTestCase() -{ -} - -void DpRadarHelperTest::TearDownTestCase() -{ -} - -HWTEST_F(DpRadarHelperTest, ReportCheckDpSa_001, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_SUCC); - bool res = DpRadarHelper::GetInstance().ReportCheckDpSa(info); - EXPECT_EQ(res, true); -} - -HWTEST_F(DpRadarHelperTest, ReportCheckDpSa_002, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_CANCEL); - bool res = DpRadarHelper::GetInstance().ReportCheckDpSa(info); - EXPECT_EQ(res, true); -} - -HWTEST_F(DpRadarHelperTest, ReportLoadDpSa_001, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_IDLE); - bool res = DpRadarHelper::GetInstance().ReportLoadDpSa(info); - EXPECT_EQ(res, true); -} - -HWTEST_F(DpRadarHelperTest, ReportLoadDpSa_002, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_SUCC); - bool res = DpRadarHelper::GetInstance().ReportLoadDpSa(info); - EXPECT_EQ(res, true); -} - -HWTEST_F(DpRadarHelperTest, ReportLoadDpSaCb_001, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_CANCEL); - bool res = DpRadarHelper::GetInstance().ReportLoadDpSaCb(info); - EXPECT_EQ(res, true); -} -HWTEST_F(DpRadarHelperTest, ReportLoadDpSaCb_002, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_IDLE); - bool res = DpRadarHelper::GetInstance().ReportLoadDpSaCb(info); - EXPECT_EQ(res, true); -} - -HWTEST_F(DpRadarHelperTest, ReportSaCheckAuth_001, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_SUCC); - bool res = DpRadarHelper::GetInstance().ReportSaCheckAuth(info); - EXPECT_EQ(res, true); -} - -HWTEST_F(DpRadarHelperTest, ReportSaCheckAuth_002, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_IDLE); - bool res = DpRadarHelper::GetInstance().ReportSaCheckAuth(info); - EXPECT_EQ(res, true); -} - -HWTEST_F(DpRadarHelperTest, ReportGetData_001, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_SUCC); - bool res = DpRadarHelper::GetInstance().ReportGetData(info); - EXPECT_EQ(res, true); -} -HWTEST_F(DpRadarHelperTest, ReportGetData_002, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_IDLE); - bool res = DpRadarHelper::GetInstance().ReportGetData(info); - EXPECT_EQ(res, true); -} - -HWTEST_F(DpRadarHelperTest, ReportAddData_001, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_IDLE); - bool res = DpRadarHelper::GetInstance().ReportAddData(info); - EXPECT_EQ(res, true); -} -HWTEST_F(DpRadarHelperTest, ReportAddData_002, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_SUCC); - bool res = DpRadarHelper::GetInstance().ReportAddData(info); - EXPECT_EQ(res, true); -} - -HWTEST_F(DpRadarHelperTest, ReportDeleteData_001, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_SUCC); - bool res = DpRadarHelper::GetInstance().ReportDeleteData(info); - EXPECT_EQ(res, true); -} - -HWTEST_F(DpRadarHelperTest, ReportDeleteData_002, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_IDLE); - bool res = DpRadarHelper::GetInstance().ReportDeleteData(info); - EXPECT_EQ(res, true); -} - -HWTEST_F(DpRadarHelperTest, ReportSubscribeData_001, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_SUCC); - bool res = DpRadarHelper::GetInstance().ReportSubscribeData(info); - EXPECT_EQ(res, true); -} -HWTEST_F(DpRadarHelperTest, ReportSubscribeData_002, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_IDLE); - bool res = DpRadarHelper::GetInstance().ReportSubscribeData(info); - EXPECT_EQ(res, true); -} - -HWTEST_F(DpRadarHelperTest, ReportNotifyDataChange_001, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_SUCC); - bool res = DpRadarHelper::GetInstance().ReportNotifyDataChange(info); - EXPECT_EQ(res, true); -} - -HWTEST_F(DpRadarHelperTest, ReportUnsbscribeData_001, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_IDLE); - bool res = DpRadarHelper::GetInstance().ReportUnsbscribeData(info); - EXPECT_EQ(res, true); -} -HWTEST_F(DpRadarHelperTest, ReportUnsbscribeData_002, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_SUCC); - bool res = DpRadarHelper::GetInstance().ReportUnsbscribeData(info); - EXPECT_EQ(res, true); -} - -HWTEST_F(DpRadarHelperTest, ReportSyncData_001, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_IDLE); - bool res = DpRadarHelper::GetInstance().ReportSyncData(info); - EXPECT_EQ(res, true); -} - -HWTEST_F(DpRadarHelperTest, ReportSyncData_002, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_SUCC); - bool res = DpRadarHelper::GetInstance().ReportSyncData(info); - EXPECT_EQ(res, true); -} - -HWTEST_F(DpRadarHelperTest, ReportSyncDataCb_001, testing::ext::TestSize.Level0) -{ - struct RadarInfo info = { 0 }; - info.stageRes = static_cast(StageRes::STAGE_SUCC); - bool res = DpRadarHelper::GetInstance().ReportSyncDataCb(info); - EXPECT_EQ(res, true); -} - -HWTEST_F(DpRadarHelperTest, GetAnonyUdid_001, testing::ext::TestSize.Level0) -{ - std::string udid = ""; - std::string res = DpRadarHelper::GetInstance().GetAnonyUdid(udid); - EXPECT_EQ(res, ""); - - udid = "1234567890abcdef"; - res = DpRadarHelper::GetInstance().GetAnonyUdid(udid); - EXPECT_EQ(res, "12345**bcdef"); -} -} // namespace DeviceProfile -} // namespace OHOS diff --git a/old/radar/test/unittest/dp_radar_helper_test.h b/old/radar/test/unittest/dp_radar_helper_test.h deleted file mode 100644 index e8670d7e..00000000 --- a/old/radar/test/unittest/dp_radar_helper_test.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DP_RADAR_HELPER_TEST_H -#define OHOS_DP_RADAR_HELPER_TEST_H - -#include -#include - -namespace OHOS { -namespace DeviceProfile { -class DpRadarHelperTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp(); - void TearDown(); -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DP_RADAR_HELPER_TEST_H diff --git a/old/services/core/BUILD.gn b/old/services/core/BUILD.gn deleted file mode 100644 index e9204331..00000000 --- a/old/services/core/BUILD.gn +++ /dev/null @@ -1,155 +0,0 @@ -# Copyright (c) 2021-2024 Huawei Device Co., Ltd. -# 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. - -import("//build/ohos.gni") -import("//build/ohos_var.gni") -import("//foundation/deviceprofile/device_info_manager/deviceprofile.gni") - -device_profile_common_sources = - [ "${old_device_profile_path}/common/src/device_profile_utils.cpp" ] - -config("device_info_manager_config") { - visibility = [ ":*" ] - visibility += [ "./test/*" ] - include_dirs = [ - "include", - "include/authority", - "include/devicemanager", - "include/contentsensor", - "include/dbstorage", - "include/dfx", - "include/subscribemanager", - "${old_device_profile_path}/common/include", - "${old_device_profile_innerkits}/core/include", - "${old_device_profile_service}/core/include", - "${old_device_profile_path}/radar/include", - "${device_profile_service}/include/", - "${device_profile_service}/include/contentsensormanager", - "${device_profile_service}/include/deviceprofilemanager", - "${device_profile_service}/include/deviceprofilemanager/listener", - "${device_profile_service}/include/permissionmanager", - "${device_profile_service}/include/persistenceadapter/kvadapter", - "${device_profile_service}/include/persistenceadapter/rdbadapter", - "${device_profile_service}/include/publishcommonevent", - "${device_profile_service}/include/subscribeprofilemanager", - "${device_profile_service}/include/trustprofilemanager", - "${device_profile_service}/include/utils", - "${device_profile_common}/include/constants", - "${device_profile_common}/include/interfaces", - "${device_profile_common}/include/utils", - ] -} - -ohos_shared_library("distributed_device_profile") { - branch_protector_ret = "pac_ret" - - ldflags = [ - "-Wl,-z,relro", - "-Wl,-z,now", - ] - - cflags = [ - "-fPIC", - "-D_FORTIFY_SOURCE=2", - "-O2", - ] - - cflags_cc = cflags - - sanitize = { - boundary_sanitize = true - integer_overflow = true - ubsan = true - cfi = true - cfi_cross_dso = true - debug = false - } - - install_enable = true - sources = [ - "src/authority/authority_manager.cpp", - "src/authority/trust_group_manager.cpp", - "src/contentsensor/app_info_collector.cpp", - "src/contentsensor/content_collector.cpp", - "src/contentsensor/content_sensor_manager.cpp", - "src/contentsensor/device_info_collector.cpp", - "src/contentsensor/pasteboard_info_collector.cpp", - "src/contentsensor/storage_info_collector.cpp", - "src/contentsensor/syscap_info_collector.cpp", - "src/contentsensor/system_info_collector.cpp", - "src/dbstorage/device_profile_storage.cpp", - "src/dbstorage/device_profile_storage_manager.cpp", - "src/dbstorage/kvstore_death_recipient_dp.cpp", - "src/dbstorage/online_sync_table.cpp", - "src/dbstorage/sync_coordinator.cpp", - "src/devicemanager/device_info.cpp", - "src/devicemanager/dp_device_manager.cpp", - "src/dfx/device_profile_dumper.cpp", - "src/distributed_device_profile_service.cpp", - "src/distributed_device_profile_stub.cpp", - "src/profile_change_notification.cpp", - "src/service_characteristic_profile.cpp", - "src/subscribemanager/profile_change_handler.cpp", - "src/subscribemanager/profile_event_handler.cpp", - "src/subscribemanager/profile_event_handler_factory.cpp", - "src/subscribemanager/profile_event_notifier_proxy.cpp", - "src/subscribemanager/profile_sync_handler.cpp", - "src/subscribemanager/subscribe_info.cpp", - "src/subscribemanager/subscribe_info_checker.cpp", - "src/subscribemanager/subscribe_manager.cpp", - "src/subscribemanager/subscriber_death_recipient.cpp", - "src/sync_options.cpp", - ] - sources += device_profile_common_sources - - configs = [ - ":device_info_manager_config", - "${old_device_profile_test}/resource:coverage_flags", - ] - - deps = [ - "${device_profile_common}:distributed_device_profile_common", - "${device_profile_service}:distributed_device_profile_svr", - "${old_device_profile_path}/radar:deviceprofileradar", - ] - - external_deps = [ - "access_token:libaccesstoken_sdk", - "c_utils:utils", - "common_event_service:cesfwk_innerkits", - "device_auth:deviceauth_sdk", - "device_manager:devicemanagersdk", - "dmsfwk:common_sdk", - "eventhandler:libeventhandler", - "hilog:libhilog", - "hisysevent:libhisysevent", - "hitrace:hitrace_meter", - "init:libbegetutil", - "ipc:ipc_core", - "json:nlohmann_json_static", - "kv_store:distributeddata_inner", - "relational_store:native_rdb", - "safwk:system_ability_fwk", - "samgr:samgr_common", - "samgr:samgr_proxy", - "syscap_codec:syscap_interface_shared", - ] - - part_name = "device_info_manager" - subsystem_name = "deviceprofile" -} - -group("unittest") { - testonly = true - deps = [ "test:unittest" ] -} diff --git a/old/services/core/include/authority/authority_manager.h b/old/services/core/include/authority/authority_manager.h deleted file mode 100644 index b27d57ed..00000000 --- a/old/services/core/include/authority/authority_manager.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DISTRIBUTED_DEVICE_PROFILE_AUTHORITY_MANAGER_H -#define OHOS_DISTRIBUTED_DEVICE_PROFILE_AUTHORITY_MANAGER_H - -#include -#include - -#include "single_instance.h" - -#include "nlohmann/json.hpp" - -namespace OHOS { -namespace DeviceProfile { -enum AuthValue : uint16_t { - // 0000 0000 0000 0001, the authority of read - AUTH_R = 0x0001, - // 0000 0000 0000 0010, the authority of write - AUTH_W = 0x0002, - // 0000 0000 0000 0011, the authority of both read and write - AUTH_RW = 0x0003 -}; - -class AuthorityManager { - DECLARE_SINGLE_INSTANCE(AuthorityManager); - -public: - bool Init(); - - bool CheckCallerTrust(); - bool CheckInterfaceAuthority(const std::string& ifaceName); - bool CheckServiceAuthority(AuthValue authVal, const std::string& serviceId); - bool CheckServicesAuthority(AuthValue authVal, const std::vector& serviceIds); - -private: - bool LoadAuthorityCfg(const std::string& filePath); - void InitSupportedInterfaces(); - - void ValidateAuthorityCfg(); - bool ValidateProcess(nlohmann::json& processJson); - bool ValidateInterfaces(nlohmann::json& interfacesJson); - bool ValidateServices(nlohmann::json& servicesJson); - bool ValidateServicesHelper(nlohmann::json& servicesJson); - bool ValidateService(const nlohmann::json& authValJson, bool readOnly); - - bool CheckServicesAuth(const nlohmann::json& servicesJson, AuthValue authVal, - const std::vector& serviceIds); - bool CheckPrefixServiceAuth(const nlohmann::json& prefixSvcsJson, - const std::string& serviceId, AuthValue authVal); - bool CheckSpecificServiceAuth(const nlohmann::json& specificSvcsJson, - const std::string& serviceId, AuthValue authVal); - - std::string GetCallingProcName(); - -private: - nlohmann::json authJson_; - std::unordered_set supportedInterfaces_; -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DISTRIBUTED_DEVICE_PROFILE_AUTHORITY_MANAGER_H \ No newline at end of file diff --git a/old/services/core/include/authority/trust_group_manager.h b/old/services/core/include/authority/trust_group_manager.h deleted file mode 100644 index f129583e..00000000 --- a/old/services/core/include/authority/trust_group_manager.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DISTRIBUTED_DEVICE_PROFILE_TRUST_GROUP_MANAGER_H -#define OHOS_DISTRIBUTED_DEVICE_PROFILE_TRUST_GROUP_MANAGER_H - -#include - -#include "device_auth.h" -#include "device_auth_defines.h" -#include "nlohmann/json.hpp" -#include "event_handler.h" -#include "single_instance.h" - -namespace OHOS { -namespace DeviceProfile { -struct GroupInfo { - std::string groupName; - std::string groupId; - std::string groupOwner; - int32_t groupType; - int32_t groupVisibility; - - GroupInfo() : groupName(""), groupId(""), groupOwner(""), groupType(0), groupVisibility(0) {} -}; - -void from_json(const nlohmann::json& jsonObject, GroupInfo& groupInfo); - -class TrustGroupManager { - DECLARE_SINGLE_INSTANCE(TrustGroupManager); - -public: - bool CheckTrustGroup(const std::string& deviceId); - bool InitHichainService(); -private: - static void OnDeviceUnBoundAdapter(const char* peerUdid, const char* groupInfo); - static bool CheckDeviceId(const std::string udid); - static std::string GetDeviceUdid(); - void InitDataChangeListener(); - bool CheckGroupsInfo(const char* returnGroups, uint32_t groupNum); - -private: - const DeviceGroupManager* hichainGmInstance_ = nullptr; - DataChangeListener dataChangeListener_; -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DISTRIBUTED_DEVICE_PROFILE_TRUST_GROUP_MANAGER_H diff --git a/old/services/core/include/contentsensor/app_info_collector.h b/old/services/core/include/contentsensor/app_info_collector.h deleted file mode 100644 index 807ac324..00000000 --- a/old/services/core/include/contentsensor/app_info_collector.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DEVICE_PROFILE_APP_INFO_COLLECTOR_H -#define OHOS_DEVICE_PROFILE_APP_INFO_COLLECTOR_H - -#include - -#include "content_collector.h" -#include "service_characteristic_profile.h" - -namespace OHOS { -namespace DeviceProfile { -class AppInfoCollector : public ContentCollector { -public: - bool ConvertToProfileData(ServiceCharacteristicProfile& profile) override; - -private: - bool GetDmsVersionInfo(std::string& dmsName, std::string& dmsVersionData); -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DEVICE_PROFILE_APP_INFO_COLLECTOR_H \ No newline at end of file diff --git a/old/services/core/include/contentsensor/content_collector.h b/old/services/core/include/contentsensor/content_collector.h deleted file mode 100644 index aa167f26..00000000 --- a/old/services/core/include/contentsensor/content_collector.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DEVICE_PROFILE_CONTENT_COLLECTOR_H -#define OHOS_DEVICE_PROFILE_CONTENT_COLLECTOR_H - -#include "service_characteristic_profile.h" - -namespace OHOS { -namespace DeviceProfile { -class ContentCollector { -public: - ContentCollector() = default; - virtual ~ContentCollector() = default; - virtual bool ConvertToProfileData(ServiceCharacteristicProfile& profile) = 0; - - void DoCollect(ServiceCharacteristicProfile& profileData); -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DEVICE_PROFILE_CONTENT_COLLECTOR_H \ No newline at end of file diff --git a/old/services/core/include/contentsensor/content_sensor_manager.h b/old/services/core/include/contentsensor/content_sensor_manager.h deleted file mode 100644 index 8dc8c454..00000000 --- a/old/services/core/include/contentsensor/content_sensor_manager.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DEVICE_PROFILE_CONTENT_SENSOR_MANAGER_H -#define OHOS_DEVICE_PROFILE_CONTENT_SENSOR_MANAGER_H - -#include - -#include "content_collector.h" -#include "event_handler.h" -#include "single_instance.h" - -namespace OHOS { -namespace DeviceProfile { -class ContentSensorManager { - DECLARE_SINGLE_INSTANCE(ContentSensorManager); - -public: - bool Init(); - -private: - bool Collect(); - std::shared_ptr csCollectorHandler_; -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DEVICE_PROFILE_CONTENT_SENSOR_MANAGER_H diff --git a/old/services/core/include/contentsensor/device_info_collector.h b/old/services/core/include/contentsensor/device_info_collector.h deleted file mode 100644 index 538e8c5b..00000000 --- a/old/services/core/include/contentsensor/device_info_collector.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DEVICE_PROFILE_DEVICE_INFO_TASK_H -#define OHOS_DEVICE_PROFILE_DEVICE_INFO_TASK_H - -#include - -#include "content_collector.h" -#include "service_characteristic_profile.h" - -namespace OHOS { -namespace DeviceProfile { -class DeviceInfoCollector : public ContentCollector { -public: - bool ConvertToProfileData(ServiceCharacteristicProfile& profile) override; - -private: - std::string GetDeviceModel(); - std::string GetDeviceManufacturer(); - std::string GetDeviceSerial(); - std::string GetDeviceName(); - std::string GetDeviceUdid(); - std::string GetDeviceProductId(); - std::string GetDevType(); -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DEVICE_PROFILE_DEVICE_INFO_TASK_H \ No newline at end of file diff --git a/old/services/core/include/contentsensor/pasteboard_info_collector.h b/old/services/core/include/contentsensor/pasteboard_info_collector.h deleted file mode 100644 index a06ae084..00000000 --- a/old/services/core/include/contentsensor/pasteboard_info_collector.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DEVICE_PROFILE_PASTEBOARD_INFO_COLLECTOR_H -#define OHOS_DEVICE_PROFILE_PASTEBOARD_INFO_COLLECTOR_H - -#include - -#include "content_collector.h" -#include "service_characteristic_profile.h" - -namespace OHOS { -namespace DeviceProfile { -class PasteboardInfoCollector : public ContentCollector { -public: - bool ConvertToProfileData(ServiceCharacteristicProfile& profile) override; - -private: - uint32_t GetSupportDistributedPasteboard(); -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DEVICE_PROFILE_PASTEBOARD_INFO_COLLECTOR_H \ No newline at end of file diff --git a/old/services/core/include/contentsensor/storage_info_collector.h b/old/services/core/include/contentsensor/storage_info_collector.h deleted file mode 100644 index ed7801c8..00000000 --- a/old/services/core/include/contentsensor/storage_info_collector.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DEVICE_PROFILE_STORAGE_INFO_COLLECTOR_H -#define OHOS_DEVICE_PROFILE_STORAGE_INFO_COLLECTOR_H - -#include "content_collector.h" -#include "service_characteristic_profile.h" - -namespace OHOS { -namespace DeviceProfile { -class StorageInfoCollector : public ContentCollector { -public: - bool ConvertToProfileData(ServiceCharacteristicProfile& profile) override; - -private: - int64_t GetTotalSize(); -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DEVICE_PROFILE_STORAGE_INFO_COLLECTOR_H diff --git a/old/services/core/include/contentsensor/syscap_info_collector.h b/old/services/core/include/contentsensor/syscap_info_collector.h deleted file mode 100644 index 59158c5d..00000000 --- a/old/services/core/include/contentsensor/syscap_info_collector.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DEVICE_PROFILE_SYSCAP_INFO_COLLECTOR_H -#define OHOS_DEVICE_PROFILE_SYSCAP_INFO_COLLECTOR_H - -#include - -#include "content_collector.h" -#include "service_characteristic_profile.h" - -namespace OHOS { -namespace DeviceProfile { -class SyscapInfoCollector : public ContentCollector { -public: - bool ConvertToProfileData(ServiceCharacteristicProfile& profile) override; -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DEVICE_PROFILE_SYSCAP_INFO_COLLECTOR_H \ No newline at end of file diff --git a/old/services/core/include/contentsensor/system_info_collector.h b/old/services/core/include/contentsensor/system_info_collector.h deleted file mode 100644 index b6b7eb73..00000000 --- a/old/services/core/include/contentsensor/system_info_collector.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DEVICE_PROFILE_SYSTEM_INFO_COLLECTOR_H -#define OHOS_DEVICE_PROFILE_SYSTEM_INFO_COLLECTOR_H - -#include - -#include "content_collector.h" -#include "service_characteristic_profile.h" - -namespace OHOS { -namespace DeviceProfile { -class SystemInfoCollector : public ContentCollector { -public: - bool ConvertToProfileData(ServiceCharacteristicProfile& profile) override; - -private: - int32_t GetOsType(); - std::string GetOsVersion(); -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DEVICE_PROFILE_SYSTEM_INFO_COLLECTOR_H \ No newline at end of file diff --git a/old/services/core/include/dbstorage/device_profile_storage.h b/old/services/core/include/dbstorage/device_profile_storage.h deleted file mode 100644 index 44b75654..00000000 --- a/old/services/core/include/dbstorage/device_profile_storage.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DISTRIBUTED_DEVICE_PROFILE_STORAGE_H -#define OHOS_DISTRIBUTED_DEVICE_PROFILE_STORAGE_H - -#include -#include - -#include "sync_options.h" - -#include "distributed_kv_data_manager.h" -#include "event_handler.h" -#include "kvstore_observer.h" -#include "kvstore_sync_callback.h" - -namespace OHOS { -namespace DeviceProfile { -enum class StorageInitStatus { - UNINITED = 1, - INIT_FAILED = 2, - INIT_SUCCEED = 3 -}; - -class DeviceProfileStorage { -public: - using KvStoreInitCallback = std::function; - - DeviceProfileStorage(const std::string& appId, const std::string& storeId); - virtual ~DeviceProfileStorage() = default; - - virtual void Init(); - virtual int32_t GetDeviceProfile(const std::string& key, std::string& value); - virtual int32_t GetDeviceProfile(const std::string& udid, const std::string& key, std::string& value); - virtual int32_t DeleteDeviceProfile(const std::string& key); - virtual int32_t PutDeviceProfile(const std::string& key, const std::string& value); - virtual int32_t PutDeviceProfileBatch(const std::vector& keys, - const std::vector& values); - virtual int32_t SyncDeviceProfile(const std::vector& deviceIdList, - SyncMode syncMode); - virtual int32_t RemoveDeviceData(const std::string networkId); - virtual int32_t RegisterSyncCallback(const std::shared_ptr& sycnCb); - virtual int32_t UnRegisterSyncCallback(); - - void SetOptions(const DistributedKv::Options& options); - StorageInitStatus GetInitStatus(); - bool RegisterKvStoreInitCallback(const KvStoreInitCallback& callback); - int32_t SubscribeKvStore(const std::shared_ptr& observer); - int32_t UnSubscribeKvStore(const std::shared_ptr& observer); - -private: - bool TryGetKvStore(); - bool InitKvStore(); - DistributedKv::Status GetKvStore(); - void DeleteKvStore(); - void SubscribeDeviceProfileKvStore(); - bool CheckTrustGroup(const std::vector& deviceIdList); - std::vector CheckTrustDeviceList(const std::vector &deviceIdList); - std::vector GetOnlineDevices(); - -private: - DistributedKv::Options options_; - DistributedKv::AppId appId_; - DistributedKv::StoreId storeId_; - DistributedKv::DistributedKvDataManager dataManager_; - - std::shared_ptr kvStorePtr_; - std::atomic initStatus_ {StorageInitStatus::UNINITED}; - KvStoreInitCallback kvStoreInitCallback_; - std::shared_mutex storageLock_; -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DISTRIBUTED_DEVICE_PROFILE_STORAGE_H diff --git a/old/services/core/include/dbstorage/device_profile_storage_manager.h b/old/services/core/include/dbstorage/device_profile_storage_manager.h deleted file mode 100644 index 36a88b3f..00000000 --- a/old/services/core/include/dbstorage/device_profile_storage_manager.h +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DISTRIBUTED_DEVICE_PROFILE_STORAGE_MANAGER_H -#define OHOS_DISTRIBUTED_DEVICE_PROFILE_STORAGE_MANAGER_H - -#include -#include - -#include "device_profile_storage.h" -#include "event_handler.h" -#include "kvstore_death_recipient_dp.h" -#include "online_sync_table.h" -#include "service_characteristic_profile.h" -#include "single_instance.h" - -#include "dp_device_manager.h" -#include "sync_options.h" - -#include "nlohmann/json.hpp" - -namespace OHOS { -namespace DeviceProfile { -enum class KeyType : int8_t { - UNKNOWN = -1, - SERVICE = 0, - SERVICE_LIST = 1, - DEVICE_INFO = 2 -}; - -class DeviceProfileStorageManager { - DECLARE_SINGLE_INSTANCE(DeviceProfileStorageManager); - friend class DeviceProfile::DpDeviceManager; - -public: - bool Init(); - void OnKvStoreInitDone(); - - int32_t PutDeviceProfile(const ServiceCharacteristicProfile& profile); - int32_t DeleteDeviceProfile(const std::string& serviceId); - int32_t GetDeviceProfile(const std::string& udid, const std::string& serviceId, - ServiceCharacteristicProfile& profile); - int32_t SyncDeviceProfile(const SyncOptions& syncOptions, - const sptr& profileEventNotifier); - - int32_t SubscribeKvStore(const std::shared_ptr& observer); - int32_t UnSubscribeKvStore(const std::shared_ptr& observer); - int32_t RegisterSyncCallback(const std::shared_ptr& sycnCb); - int32_t UnRegisterSyncCallback(); - void NotifySyncCompleted(); - void NotifySubscriberDied(const sptr& profileEventNotifier); - int32_t RemoveUnBoundDeviceProfile(const std::string& udid); - int32_t RemoveRemoteDeviceProfile(); - void DumpLocalProfile(std::string& result); - -private: - bool WaitKvDataService(); - void RestoreServiceItemLocked(const std::string& value); - void RegisterCallbacks(); - void FlushProfileItems(); - std::string GenerateKey(const std::string& udid, const std::string& key, KeyType keyType); - - bool CheckSyncOption(const SyncOptions& syncOptions); - int32_t NotifySyncStart(const sptr& profileEventNotifier); - void SetServiceType(const std::string& udid, const std::string& serviceId, ServiceCharacteristicProfile& profile); - void ReportBehaviorEvent(const std::string& event); - void ReportFaultEvent(const std::string& event, const std::string& key, const int32_t result); - -private: - std::mutex serviceLock_; - std::mutex callbackLock_; - std::mutex initLock_; - nlohmann::json servicesJson_; - std::shared_ptr onlineSyncTbl_; - std::shared_ptr storageHandler_; - sptr kvStoreDeathRecipientDp_; - std::string localUdid_; - std::map profileItems_; - std::atomic kvDataServiceFailed_ {false}; - std::atomic inited_ {false}; - std::shared_ptr kvStoreObserver_; - std::shared_ptr kvStoreSyncCallback_; - std::mutex profileSyncLock_; - sptr syncEventNotifier_; - std::atomic isSync_ {false}; -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DISTRIBUTED_DEVICE_PROFILE_STORAGE_MANAGER_H \ No newline at end of file diff --git a/old/services/core/include/dbstorage/kvstore_death_recipient_dp.h b/old/services/core/include/dbstorage/kvstore_death_recipient_dp.h deleted file mode 100644 index 29aa71ca..00000000 --- a/old/services/core/include/dbstorage/kvstore_death_recipient_dp.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_KVSTORE_DEATH_RECIPIENT_H -#define OHOS_KVSTORE_DEATH_RECIPIENT_H - -#include "iremote_object.h" - -namespace OHOS { -namespace DeviceProfile { -class KvStoreDeathRecipientDp : public IRemoteObject::DeathRecipient { -public: - void OnRemoteDied(const wptr& remote) override; -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_KVSTORE_DEATH_RECIPIENT_H \ No newline at end of file diff --git a/old/services/core/include/dbstorage/online_sync_table.h b/old/services/core/include/dbstorage/online_sync_table.h deleted file mode 100644 index a1457129..00000000 --- a/old/services/core/include/dbstorage/online_sync_table.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DISTRIBUTED_DEVICE_PROFILE_ONLINE_SYNC_TABLE_H -#define OHOS_DISTRIBUTED_DEVICE_PROFILE_ONLINE_SYNC_TABLE_H - -#include "device_profile_storage.h" - -namespace OHOS { -namespace DeviceProfile { -class OnlineSyncTable : public std::enable_shared_from_this, - public DeviceProfileStorage, - public DistributedKv::KvStoreSyncCallback { -public: - OnlineSyncTable(); - ~OnlineSyncTable() = default; - - void Init() override; - int32_t RegisterSyncCallback(const std::shared_ptr& sycnCb) override; - int32_t UnRegisterSyncCallback() override; - int32_t SyncDeviceProfile(const std::vector& deviceIds, SyncMode syncMode) override; - - void SyncCompleted(const std::map& results) override; - void NotifySyncCompleted(const std::map& results); - -private: - std::shared_ptr syncCallback_; - std::vector onlineDeviceIds_; - std::atomic retrySyncTimes_ {0}; - std::mutex tableLock_; -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DISTRIBUTED_DEVICE_PROFILE_ONLINE_SYNC_TABLE_H \ No newline at end of file diff --git a/old/services/core/include/dbstorage/sync_coordinator.h b/old/services/core/include/dbstorage/sync_coordinator.h deleted file mode 100644 index 695fd1ff..00000000 --- a/old/services/core/include/dbstorage/sync_coordinator.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DISTRIBUTED_PROFILE_SYNC_COORDINATOR_H -#define OHOS_DISTRIBUTED_PROFILE_SYNC_COORDINATOR_H - -#include -#include - -#include "single_instance.h" - -#include "event_handler.h" - -namespace OHOS { -namespace DeviceProfile { -class SyncCoordinator { - DECLARE_SINGLE_INSTANCE(SyncCoordinator); -public: - using SyncTask = std::function; - - bool Init(); - bool AcquireSync(); - void ReleaseSync(); - void SetSyncTrigger(bool isOnlineTrigger); - bool IsOnlineSync(); - bool IsOnSync(); - bool DispatchSyncTask(const SyncTask& syncTask, int64_t delayTime = 0); - -private: - std::atomic isOnlineTrigger_ {false}; - std::atomic isOnSync_ {false}; - std::shared_ptr syncHandler_; -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DISTRIBUTED_PROFILE_SYNC_COORDINATOR_H \ No newline at end of file diff --git a/old/services/core/include/devicemanager/device_info.h b/old/services/core/include/devicemanager/device_info.h deleted file mode 100644 index 5ca21374..00000000 --- a/old/services/core/include/devicemanager/device_info.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DEVICE_PROFILE_DEVICE_INFO_H -#define OHOS_DEVICE_PROFILE_DEVICE_INFO_H - -#include - -#include "parcel.h" - -namespace OHOS { -namespace DeviceProfile { -enum { - UNKNOWN_TYPE = 0x00, -}; - -class DeviceInfo { -public: - DeviceInfo(const std::string& deviceName, const std::string& networkId, int32_t deviceType) - : deviceName_(deviceName), networkId_(networkId), deviceType_(deviceType) {} - ~DeviceInfo() = default; - - const std::string& GetDeviceName() const; - const std::string& GetNetworkId() const; - int32_t GetDeviceType() const; - -private: - std::string deviceName_; - std::string networkId_; - int32_t deviceType_ = UNKNOWN_TYPE; -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DEVICE_PROFILE_DEVICE_INFO_H diff --git a/old/services/core/include/devicemanager/dp_device_manager.h b/old/services/core/include/devicemanager/dp_device_manager.h deleted file mode 100644 index 6251d31d..00000000 --- a/old/services/core/include/devicemanager/dp_device_manager.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DEVICE_PROFILE_DEVICE_MANAGER_H -#define OHOS_DEVICE_PROFILE_DEVICE_MANAGER_H - -#include -#include -#include - -#include "device_manager.h" -#include "device_manager_callback.h" -#include "dm_device_info.h" -#include "event_handler.h" - -#include "device_info.h" -#include "single_instance.h" - -namespace OHOS { -namespace DeviceProfile { -enum class DeviceIdType : uint8_t { - NETWORKID = 0, - UDID = 1, - UUID = 2 -}; - -class DpDeviceManager { - DECLARE_SINGLE_INSTANCE(DpDeviceManager); - -public: - bool Init(); - void GetLocalDeviceUdid(std::string& udid); - bool GetUdidByNetworkId(const std::string& networkId, std::string& udid); - bool GetUuidByNetworkId(const std::string& networkId, std::string& uuid); - bool DisconnectDeviceManager(); - bool ConnectDeviceManager(); - bool TransformDeviceId(const std::string& fromDeviceId, std::string& toDeviceId, - DeviceIdType toType); - void GetDeviceIdList(std::list& deviceIdList); - void GetDeviceList(std::list>& deviceList); - void RemoveDeviceIdsByUdid(const std::string& udid); - void GetTrustedDeviceList(); - -private: - std::shared_ptr GetInitCallback(); - std::shared_ptr GetStateCallback(); - void GetDevMgrHandler(); - bool WaitForDnetworkReady(); - void OnNodeOnline(const std::shared_ptr deviceInfo); - void OnNodeOffline(const std::string& networkId); - void AddLocalDeviceIds(); - void AddDeviceIds(const std::string& networkId); - void RemoveDeviceIds(const std::string& networkId); - void RemoveExpiredDeviceIds(const std::string& networkId); - void RecoverDevicesIfNeeded(); - -private: - std::mutex deviceLock_; - std::mutex initcallbackLock_; - std::mutex stateCallLock_; - std::mutex devMgrLock_; - std::mutex devTrustLock_; - std::shared_ptr devMgrHandler_; - std::shared_ptr stateCallback_; - std::shared_ptr initCallback_; - std::map> remoteDeviceInfoMap_; - std::list> deviceIdsList_; - -class DeviceInitCallBack : public DistributedHardware::DmInitCallback { - void OnRemoteDied() override; -}; - -class DpDeviceStateCallback : public DistributedHardware::DeviceStateCallback { - void OnDeviceOnline(const DistributedHardware::DmDeviceInfo &deviceInfo) override; - void OnDeviceOffline(const DistributedHardware::DmDeviceInfo &deviceInfo) override; - void OnDeviceChanged(const DistributedHardware::DmDeviceInfo &deviceInfo) override; - void OnDeviceReady(const DistributedHardware::DmDeviceInfo &deviceInfo) override; -}; -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DEVICE_PROFILE_DEVICE_MANAGER_H diff --git a/old/services/core/include/dfx/device_profile_dumper.h b/old/services/core/include/dfx/device_profile_dumper.h deleted file mode 100644 index 89eaefb1..00000000 --- a/old/services/core/include/dfx/device_profile_dumper.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DEVICE_PROFILE_DUMPER_H -#define OHOS_DEVICE_PROFILE_DUMPER_H - -#include -#include - -namespace OHOS { -namespace DeviceProfile { -class DeviceProfileDumper { -public: - static bool Dump(const std::vector& args, std::string& result); - -private: - DeviceProfileDumper() = default; - ~DeviceProfileDumper() = default; - - static void ShowHelp(std::string& result); - static void IllegalInput(std::string& result); - static bool CanDump(); - static bool DumpDefault(std::string& result); -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DEVICE_PROFILE_DUMPER_H \ No newline at end of file diff --git a/old/services/core/include/distributed_device_profile_service.h b/old/services/core/include/distributed_device_profile_service.h deleted file mode 100644 index 3661c813..00000000 --- a/old/services/core/include/distributed_device_profile_service.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DISTRIBUTED_DEVICE_PROFILE_SERVICE_H -#define OHOS_DISTRIBUTED_DEVICE_PROFILE_SERVICE_H - -#include - -#include "distributed_device_profile_stub.h" -#include "event_handler.h" -#include "event_runner.h" -#include "single_instance.h" -#include "system_ability.h" -#include "system_ability_definition.h" - -namespace OHOS { -namespace DeviceProfile { -class DistributedDeviceProfileService : public SystemAbility, public DistributedDeviceProfileStub { - DECLARE_SYSTEM_ABILITY(DistributedDeviceProfileService); - DECLARE_SINGLE_INSTANCE_BASE(DistributedDeviceProfileService); - -public: - DistributedDeviceProfileService(); - ~DistributedDeviceProfileService() = default; - - int32_t PutDeviceProfile(const ServiceCharacteristicProfile& profile) override; - int32_t DeleteDeviceProfile(const std::string& serviceId) override; - int32_t GetDeviceProfile(const std::string& udid, const std::string& serviceId, - ServiceCharacteristicProfile& profile) override; - int32_t SubscribeProfileEvents(const std::list& subscribeInfos, - const sptr& profileEventNotifier, - std::list& failedEvents) override; - int32_t UnsubscribeProfileEvents(const std::list& profileEvents, - const sptr& profileEventNotifier, - std::list& failedEvents) override; - int32_t SyncDeviceProfile(const SyncOptions& syncOptions, - const sptr& profileEventNotifier) override; - int32_t Dump(int32_t fd, const std::vector& args) override; - void DelayUnloadTask() override; - void DeviceOnline(); - -protected: - void OnStart(const SystemAbilityOnDemandReason& startReason) override; - void OnStop() override; - int32_t OnIdle(const SystemAbilityOnDemandReason& idleReason) override; - void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; - -private: - bool Init(); - bool DoBusinessInit(); -private: - std::shared_ptr unloadHandler_; - std::mutex unloadMutex_; - std::atomic isOnline_ {false}; - std::mutex depSaIdsMtx_; - std::unordered_set depSaIds_ { - SOFTBUS_SERVER_SA_ID, - DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID, - DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID, - SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN - }; -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DISTRIBUTED_DEVICE_PROFILE_SERVICE_H \ No newline at end of file diff --git a/old/services/core/include/distributed_device_profile_stub.h b/old/services/core/include/distributed_device_profile_stub.h deleted file mode 100644 index e74e5076..00000000 --- a/old/services/core/include/distributed_device_profile_stub.h +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (c) 2021-2025 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DISTRIBUTED_DEVICE_PROFILE_STUB_H -#define OHOS_DISTRIBUTED_DEVICE_PROFILE_STUB_H - -#include "idistributed_device_profile.h" - -#include - -#include "iremote_stub.h" - -namespace OHOS { -namespace DeviceProfile { -class DistributedDeviceProfileStub : public IRemoteStub { -public: - DistributedDeviceProfileStub(); - ~DistributedDeviceProfileStub() = default; - - int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, - MessageOption& option) override; - - int32_t PutDeviceProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t DeleteDeviceProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t GetDeviceProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t SubscribeProfileEventInner(MessageParcel& data, MessageParcel& reply); - int32_t UnsubscribeProfileEventInner(MessageParcel& data, MessageParcel& reply); - int32_t SyncDeviceProfileInner(MessageParcel& data, MessageParcel& reply); - // new stub interface - int32_t PutAccessControlProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t UpdateAccessControlProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t GetTrustDeviceProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t GetAllTrustDeviceProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t GetAccessControlProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t GetAllAccessControlProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t DeleteAccessControlProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t PutSessionKeyInner(MessageParcel& data, MessageParcel& reply); - int32_t GetSessionKeyInner(MessageParcel& data, MessageParcel& reply); - int32_t UpdateSessionKeyInner(MessageParcel& data, MessageParcel& reply); - int32_t DeleteSessionKeyInner(MessageParcel& data, MessageParcel& reply); - int32_t PutDeviceProfileBatchInner(MessageParcel& data, MessageParcel& reply); - int32_t PutServiceProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t PutServiceProfileBatchInner(MessageParcel& data, MessageParcel& reply); - int32_t PutCharacteristicProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t PutCharacteristicProfileBatchInner(MessageParcel& data, MessageParcel& reply); - int32_t GetDeviceProfileNewInner(MessageParcel& data, MessageParcel& reply); - int32_t GetDeviceProfilesInner(MessageParcel& data, MessageParcel& reply); - int32_t DeleteDeviceProfileBatchInner(MessageParcel& data, MessageParcel& reply); - int32_t GetServiceProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t GetCharacteristicProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t DeleteServiceProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t DeleteCharacteristicProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t SubscribeDeviceProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t UnSubscribeDeviceProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t SyncDeviceProfileNewInner(MessageParcel& data, MessageParcel& reply); - int32_t SendSubscribeInfosInner(MessageParcel& data, MessageParcel& reply); - int32_t SubscribeDeviceProfileInitedInner(MessageParcel& data, MessageParcel& reply); - int32_t UnSubscribeDeviceProfileInitedInner(MessageParcel& data, MessageParcel& reply); - int32_t SubscribePinCodeInvalidInner(MessageParcel& data, MessageParcel& reply); - int32_t UnSubscribePinCodeInvalidInner(MessageParcel& data, MessageParcel& reply); - int32_t PutAllTrustedDevicesInner(MessageParcel& data, MessageParcel& reply); - int32_t PutProductInfoBatchInner(MessageParcel& data, MessageParcel& reply); - int32_t PutDeviceIconInfoBatchInner(MessageParcel& data, MessageParcel& reply); - int32_t GetDeviceIconInfosInner(MessageParcel& data, MessageParcel& reply); - int32_t PutServiceInfoProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t DeleteServiceInfoProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t UpdateServiceInfoProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t GetServiceInfoProfileByUniqueKeyInner(MessageParcel& data, MessageParcel& reply); - int32_t GetServiceInfoProfileListByTokenIdInner(MessageParcel& data, MessageParcel& reply); - int32_t GetAllServiceInfoProfileListInner(MessageParcel& data, MessageParcel& reply); - int32_t GetServiceInfoProfileListByBundleNameInner(MessageParcel& data, MessageParcel& reply); - int32_t PutLocalServiceInfoInner(MessageParcel& data, MessageParcel& reply); - int32_t UpdateLocalServiceInfoInner(MessageParcel& data, MessageParcel& reply); - int32_t GetLocalServiceInfoByBundleAndPinTypeInner(MessageParcel& data, MessageParcel& reply); - int32_t DeleteLocalServiceInfoInner(MessageParcel& data, MessageParcel& reply); - - virtual void DelayUnloadTask() - { - return; - } - -private: - using Func = int32_t(DistributedDeviceProfileStub::*)(MessageParcel& data, MessageParcel& reply); - - bool EnforceInterfaceToken(MessageParcel& data); - - void InitNewRdbIpcInterface(); - - void InitNewKVIpcInterface(); - - void InitAclAndSubscribe(); - - int32_t NotifyAclEventInner(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option); - - int32_t NotifyProfileDataEventInner(uint32_t code, MessageParcel& data, MessageParcel& reply, - MessageOption& option); - - int32_t NotifyOldEventInner(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option); - - int32_t NotifyNewEventInner(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option); - - int32_t NotifyLocalServiceEventInner(uint32_t code, MessageParcel& data, MessageParcel& reply, - MessageOption& option); - -private: - std::map funcsMap_; - std::vector aclAndSubscribeFuncs_; -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DISTRIBUTED_DEVICE_PROFILE_STUB_H diff --git a/old/services/core/include/subscribemanager/profile_change_handler.h b/old/services/core/include/subscribemanager/profile_change_handler.h deleted file mode 100644 index 2e4f5ffd..00000000 --- a/old/services/core/include/subscribemanager/profile_change_handler.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DISTRIBUTED_DEVICE_PROFILE_PROFILE_CHANGE_HANDLER_H -#define OHOS_DISTRIBUTED_DEVICE_PROFILE_PROFILE_CHANGE_HANDLER_H - -#include - -#include "profile_change_notification.h" -#include "profile_event_handler.h" - -#include "kvstore_observer.h" - -namespace OHOS { -namespace DeviceProfile { -class ProfileChangeHandler : public std::enable_shared_from_this, - public ProfileEventHandler, - public DistributedKv::KvStoreObserver { -public: - explicit ProfileChangeHandler(const std::string& handlerName) - : ProfileEventHandler(handlerName) {} - ~ProfileChangeHandler() = default; - - void OnChange(const DistributedKv::ChangeNotification& changeNotification) override; - -private: - int32_t Register() override; - int32_t Unregister() override; - int32_t Subscribe(const SubscribeInfo& subscribeInfo, - const sptr& profileEventNotifier) override; - - void ConvertEntry(const std::vector& entries, ProfileChangeType changeType, - std::vector& profileEntries, Service2Index& service2Index); - - void NotifyProfileChanged(const ProfileChangeNotification& changeNotification, - const Service2Index& service2Index); - void FilterChangedProfileLocked(const SubscribeInfo& subscribeInfo, - const ProfileChangeNotification& changeNotification, - const Service2Index& service2Index, FilterInfo& filterInfo); - void NotifyProfileChangedLocked(const ProfileChangeNotification& changeNotification, - const FilterInfo& filterInfo, - const sptr& profileEventNotifier); -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DISTRIBUTED_DEVICE_PROFILE_PROFILE_CHANGE_HANDLER_H diff --git a/old/services/core/include/subscribemanager/profile_event_handler.h b/old/services/core/include/subscribemanager/profile_event_handler.h deleted file mode 100644 index d375721b..00000000 --- a/old/services/core/include/subscribemanager/profile_event_handler.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DEVICE_PROFILE_PROFILE_EVENT_HANDLER_H -#define OHOS_DEVICE_PROFILE_PROFILE_EVENT_HANDLER_H - -#include -#include -#include -#include - -#include "event_handler.h" -#include "iremote_object.h" - -#include "iprofile_event_notifier.h" -#include "profile_event.h" -#include "profile_change_notification.h" -#include "subscribe_info.h" -#include "single_instance.h" - -namespace OHOS { -namespace DeviceProfile { -struct FilterInfo { - bool filtered {false}; - std::unordered_set indexes; -}; - -class ProfileEventHandler { - friend class SubscriberDeathRecipient; -public: - explicit ProfileEventHandler(const std::string& handlerName) - : handlerName_(handlerName) {} - virtual ~ProfileEventHandler() = default; - - bool Init(); - bool IsRegistered() const; - - virtual int32_t Subscribe(const SubscribeInfo& subscribeInfo, - const sptr& profileEventNotifier); - int32_t Unsubscribe(const sptr& profileEventNotifier); - void OnSubscriberDied(const sptr& profileEventNotifier); - std::string AnonymizeSubscribeInfo(const SubscribeInfo& subscribeInfo); - -protected: - std::atomic isRegistered_ {false}; - std::mutex notifierLock_; - std::map, SubscribeInfo> profileEventSubscribeInfos_; - std::string handlerName_; - std::shared_ptr eventHandler_; - -private: - virtual int32_t Register() = 0; - virtual int32_t Unregister() = 0; -}; -} // namespace DeviceProfile -} // namespace OHOS - -#endif // OHOS_DEVICE_PROFILE_I_PROFILE_EVENT_H diff --git a/old/services/core/include/subscribemanager/profile_event_handler_factory.h b/old/services/core/include/subscribemanager/profile_event_handler_factory.h deleted file mode 100644 index d4ac67f9..00000000 --- a/old/services/core/include/subscribemanager/profile_event_handler_factory.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DEVICE_PROFILE_PROFILE_EVENT_HANDLER_FACTORY_H -#define OHOS_DEVICE_PROFILE_PROFILE_EVENT_HANDLER_FACTORY_H - -#include "profile_event.h" -#include "profile_event_handler.h" -#include "single_instance.h" - -namespace OHOS { -namespace DeviceProfile { -class ProfileEventHandlerFactory { - DECLARE_SINGLE_INSTANCE_BASE(ProfileEventHandlerFactory); - -public: - ProfileEventHandlerFactory(); - ~ProfileEventHandlerFactory() = default; - - std::shared_ptr GetHandler(ProfileEvent profileEvent); - -private: - using Handler = std::shared_ptr(ProfileEventHandlerFactory::*)(); - - std::shared_ptr GetProfileChangeHandlerInner(); - std::shared_ptr GetProfileSyncHandlerInner(); - -private: - std::map handlersMap_; -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DEVICE_PROFILE_PROFILE_EVENT_HANDLER_FACTORY_H diff --git a/old/services/core/include/subscribemanager/profile_event_notifier_proxy.h b/old/services/core/include/subscribemanager/profile_event_notifier_proxy.h deleted file mode 100644 index afcc3b69..00000000 --- a/old/services/core/include/subscribemanager/profile_event_notifier_proxy.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DEVICE_PROFILE_I_PROFILE_SYNC_CALLBACK_PROXY_H -#define OHOS_DEVICE_PROFILE_I_PROFILE_SYNC_CALLBACK_PROXY_H - -#include "iprofile_event_notifier.h" -#include "iremote_proxy.h" - -namespace OHOS { -namespace DeviceProfile { -class ProfileEventNotifierProxy : public IRemoteProxy { -public: - explicit ProfileEventNotifierProxy(const sptr& impl); - ~ProfileEventNotifierProxy() = default; - - void OnSyncCompleted(const SyncResult& syncResults) override; - void OnProfileChanged(const ProfileChangeNotification& changeNotification) override; - -private: - static inline BrokerDelegator delegator_; -}; -} // namespace DeviceProfile -} // namespace OHOS - -#endif // OHOS_DEVICE_PROFILE_I_PROFILE_SYNC_CALLBACK_PROXY_H diff --git a/old/services/core/include/subscribemanager/profile_sync_handler.h b/old/services/core/include/subscribemanager/profile_sync_handler.h deleted file mode 100644 index 3e17e77f..00000000 --- a/old/services/core/include/subscribemanager/profile_sync_handler.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DEVICE_PROFILE_PROFILE_SYNC_HANDLER_H -#define OHOS_DEVICE_PROFILE_PROFILE_SYNC_HANDLER_H - -#include - -#include "kvstore_sync_callback.h" -#include "profile_event_handler.h" - -namespace OHOS { -namespace DeviceProfile { -using namespace OHOS::DistributedKv; - -class ProfileSyncHandler : public std::enable_shared_from_this, - public ProfileEventHandler, - public DistributedKv::KvStoreSyncCallback { -public: - explicit ProfileSyncHandler(const std::string& handlerName) - : ProfileEventHandler(handlerName) {} - ~ProfileSyncHandler() = default; - - void SyncCompleted(const std::map& results) override; - -private: - int32_t Register() override; - int32_t Unregister() override; - - void NotifySyncCompleted(const SyncResult& syncResults); -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DEVICE_PROFILE_PROFILE_SYNC_HANDLER_H diff --git a/old/services/core/include/subscribemanager/subscribe_info_checker.h b/old/services/core/include/subscribemanager/subscribe_info_checker.h deleted file mode 100644 index e78029fa..00000000 --- a/old/services/core/include/subscribemanager/subscribe_info_checker.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DEVICE_PROFILE_SUBSCRIBE_INFO_CHECKER_H -#define OHOS_DEVICE_PROFILE_SUBSCRIBE_INFO_CHECKER_H - -#include - -#include "single_instance.h" -#include "subscribe_info.h" - -namespace OHOS { -namespace DeviceProfile { -class SubscribeInfoChecker { - DECLARE_SINGLE_INSTANCE_BASE(SubscribeInfoChecker); -public: - SubscribeInfoChecker(); - ~SubscribeInfoChecker() = default; - - bool Check(const std::list& subscribeInfos); - -private: - using Checker = bool(SubscribeInfoChecker::*)(const SubscribeInfo&); - - bool CheckSyncEventInner(const SubscribeInfo& subscribeInfo); - bool CheckProfileChangeInner(const SubscribeInfo& subscribeInfo); - -private: - std::map checkersMap_; -}; -} // namespace DeviceProfile -} // namespace OHOS - -#endif // OHOS_DEVICE_PROFILE_SUBSCRIBE_INFO_CHECKER_H diff --git a/old/services/core/include/subscribemanager/subscribe_manager.h b/old/services/core/include/subscribemanager/subscribe_manager.h deleted file mode 100644 index 4e7e2a24..00000000 --- a/old/services/core/include/subscribemanager/subscribe_manager.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DEVICE_PROFILE_SUBSCRIBE_MANAGER_H -#define OHOS_DEVICE_PROFILE_SUBSCRIBE_MANAGER_H - -#include -#include -#include -#include - -#include "iremote_object.h" -#include "single_instance.h" -#include "iprofile_event_notifier.h" -#include "profile_event.h" -#include "profile_change_notification.h" - -#include "profile_event_handler.h" -#include "subscribe_info.h" - -namespace OHOS { -namespace DeviceProfile { -class SubscribeManager { - DECLARE_SINGLE_INSTANCE(SubscribeManager); - -public: - bool Init(); - - int32_t SubscribeProfileEvents(const std::list& subscribeInfos, - const sptr& profileEventNotifier, - std::list& failedEvents); - int32_t UnsubscribeProfileEvents(const std::list& profileEvents, - const sptr& profileEventNotifier, - std::list& failedEvents); - - void OnSubscriberDied(const sptr& profileEventNotifier); - -private: - struct NotifierInfo { - int32_t callingUid; - ProfileEvents profileEvents; - }; - - void TryAddNotifierLocked(const sptr& profileEventNotifier, - const ProfileEvents& profileEvents); - void TryRemoveNotiferLocked(const sptr& profileEventNotifier, - const ProfileEvents& profileEvents); - void IncSubsOfUidLocked(int32_t uid); - void DecSubsOfUidLocked(int32_t uid); - bool CheckSubsOfUid(int32_t uid); - -private: - std::mutex handlerLock_; - std::map, NotifierInfo> notifiersMap_; - std::map> handlersMap_; - std::unordered_map uidSubsMap_; - sptr subscriberDeathRecipient_; -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DEVICE_PROFILE_SUBSCRIBE_MANAGER_H diff --git a/old/services/core/include/subscribemanager/subscriber_death_recipient.h b/old/services/core/include/subscribemanager/subscriber_death_recipient.h deleted file mode 100644 index 249072c8..00000000 --- a/old/services/core/include/subscribemanager/subscriber_death_recipient.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DEVICE_PROFILE_SUBSCRIBER_DEATH_RECIPIENT_H -#define OHOS_DEVICE_PROFILE_SUBSCRIBER_DEATH_RECIPIENT_H - -#include "iremote_object.h" - -namespace OHOS { -namespace DeviceProfile { -class SubscriberDeathRecipient : public IRemoteObject::DeathRecipient { -public: - SubscriberDeathRecipient() = default; - ~SubscriberDeathRecipient() = default; - - void OnRemoteDied(const wptr& remote) override; -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DEVICE_PROFILE_SUBSCRIBER_DEATH_RECIPIENT_H diff --git a/old/services/core/src/authority/authority_manager.cpp b/old/services/core/src/authority/authority_manager.cpp deleted file mode 100644 index b434bc59..00000000 --- a/old/services/core/src/authority/authority_manager.cpp +++ /dev/null @@ -1,329 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * 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. - */ - -#include "authority_manager.h" - -#include - -#include "accesstoken_kit.h" -#include "file_ex.h" -#include "ipc_skeleton.h" -#include "securec.h" - -#include "device_profile_log.h" - -namespace OHOS { -namespace DeviceProfile { -using namespace OHOS::Security::AccessToken; - -namespace { -const std::string TAG = "AuthorityManager"; - -constexpr uint32_t INVALID_TOKEN_ID = 0; -const std::string INTERFACES = "interfacesAuthority"; -const std::string SERVICES = "servicesAuthority"; -const std::string SERVICES_ALL = "all"; -const std::string SERVICES_SPECIFIC = "specific"; -const std::string SERVICES_PREFIX = "prefix"; -const std::string AUTHORITY_JSON_PATH = "/system/etc/deviceprofile/authority.json"; -} - -IMPLEMENT_SINGLE_INSTANCE(AuthorityManager); - -bool AuthorityManager::Init() -{ - if (!LoadAuthorityCfg(AUTHORITY_JSON_PATH)) { - return false; - } - InitSupportedInterfaces(); - ValidateAuthorityCfg(); - HILOGI("init succeeded"); - return true; -} - -void AuthorityManager::InitSupportedInterfaces() -{ - supportedInterfaces_ = { "sync" }; -} - -bool AuthorityManager::LoadAuthorityCfg(const std::string& filePath) -{ - std::ifstream ifs(filePath.c_str()); - if (!ifs.good()) { - HILOGE("load json file failed"); - return false; - } - authJson_ = nlohmann::json::parse(ifs, nullptr, false); - if (authJson_.is_discarded()) { - HILOGE("parse failed"); - return false; - } - return true; -} - -void AuthorityManager::ValidateAuthorityCfg() -{ - for (auto iter = authJson_.begin(); iter != authJson_.end();) { - if (!ValidateProcess(iter.value())) { - HILOGE("authority for proc %{public}s is invalid, deleted", iter.key().c_str()); - authJson_.erase(iter++); - } else { - iter++; - } - } -} - -bool AuthorityManager::ValidateProcess(nlohmann::json& processJson) -{ - for (auto& [key, value] : processJson.items()) { - if (key != INTERFACES && key != SERVICES) { - HILOGE("invalid key:%{public}s under proc", key.c_str()); - return false; - } - if (key == INTERFACES && !ValidateInterfaces(value)) { - return false; - } - if (key == SERVICES && !ValidateServices(value)) { - return false; - } - } - return true; -} - -bool AuthorityManager::ValidateInterfaces(nlohmann::json& interfacesJson) -{ - if (interfacesJson.empty()) { - return false; - } - - for (auto& [key, value] : interfacesJson.items()) { - if (supportedInterfaces_.find(key) == supportedInterfaces_.end()) { - return false; - } - // value should be type of object, e.g. "sync": {} - if (!value.is_object()) { - return false; - } - } - return true; -} - -bool AuthorityManager::ValidateServices(nlohmann::json& servicesJson) -{ - if (servicesJson.empty()) { - return false; - } - - if (servicesJson.contains(SERVICES_ALL)) { - // currently only read permission is allowed being with SERVICES_ALL - if (!ValidateService(servicesJson[SERVICES_ALL], true)) { - return false; - } - } - - if (servicesJson.contains(SERVICES_SPECIFIC) && - !ValidateServicesHelper(servicesJson[SERVICES_SPECIFIC])) { - return false; - } - if (servicesJson.contains(SERVICES_PREFIX) && - !ValidateServicesHelper(servicesJson[SERVICES_PREFIX])) { - return false; - } - return true; -} - -bool AuthorityManager::ValidateServicesHelper(nlohmann::json& servicesJson) -{ - for (auto& [key, value] : servicesJson.items()) { - if (!ValidateService(value, false)) { - HILOGW("service:%{public}s is invalid, deleted", key.c_str()); - return false; - } - } - return true; -} - -bool AuthorityManager::ValidateService(const nlohmann::json& authValJson, bool readOnly) -{ - if (!authValJson.is_number_unsigned()) { - HILOGE("not number type"); - return false; - } - auto authVal = authValJson.get(); - // single AUTH_W is meaningless and disallowed - if (authVal != AuthValue::AUTH_RW && - authVal != AuthValue::AUTH_R) { - HILOGE("invalid auth value"); - return false; - } - if (readOnly && authVal != AuthValue::AUTH_R) { - HILOGE("read only"); - return false; - } - return true; -} - -bool AuthorityManager::CheckInterfaceAuthority(const std::string& ifaceName) -{ - std::string procName = GetCallingProcName(); - if (!authJson_.contains(procName)) { - HILOGE("can't find entry for proc:%{public}s", procName.c_str()); - return false; - } - - auto& interfacesJson = authJson_[procName][INTERFACES]; - if (interfacesJson == nullptr) { - HILOGE("can't find interfaces entry"); - return false; - } - - if (!interfacesJson.contains(ifaceName)) { - HILOGE("%{public}s is disallowed for %{public}s", ifaceName.c_str(), - procName.c_str()); - return false; - } - return true; -} - -bool AuthorityManager::CheckServiceAuthority(AuthValue authVal, - const std::string& serviceId) -{ - return CheckServicesAuthority(authVal, { serviceId }); -} - -bool AuthorityManager::CheckServicesAuthority(AuthValue authVal, - const std::vector& serviceIds) -{ - bool hasEmpty = std::any_of(serviceIds.begin(), serviceIds.end(), - [](const auto& serviceId) { return serviceId.empty(); }); - if (hasEmpty) { - HILOGE("empty serviceId"); - return false; - } - - std::string procName = GetCallingProcName(); - if (!authJson_.contains(procName)) { - HILOGE("can't find entry for proc:%{public}s", procName.c_str()); - return false; - } - auto& servicesJson = authJson_[procName][SERVICES]; - if (servicesJson == nullptr) { - HILOGE("can't find services entry"); - return false; - } - - if (!CheckServicesAuth(servicesJson, authVal, serviceIds)) { - return false; - } - return true; -} - -bool AuthorityManager::CheckServicesAuth(const nlohmann::json& servicesJson, - AuthValue authVal, const std::vector& serviceIds) -{ - bool isReadWithAll = (authVal == AuthValue::AUTH_R) && servicesJson.contains(SERVICES_ALL); - if (serviceIds.empty()) { - // in case where no serviceIds provided, which means all services; but - // SERVICES_ALL is only allowed with AUTH_R - return isReadWithAll; - } - if (isReadWithAll) { - HILOGI("check pass, SERVICES_ALL with read"); - return true; - } - - const auto& specificSvcsJson = servicesJson.contains(SERVICES_SPECIFIC) ? - servicesJson[SERVICES_SPECIFIC] : nlohmann::json {}; - const auto& prefixSvcsJson = servicesJson.contains(SERVICES_PREFIX) ? - servicesJson[SERVICES_PREFIX] : nlohmann::json {}; - if (specificSvcsJson == nullptr && prefixSvcsJson == nullptr) { - HILOGE("check failed, no specific and prefix service"); - return false; - } - for (const auto& serviceId : serviceIds) { - if ((specificSvcsJson != nullptr) && - CheckSpecificServiceAuth(specificSvcsJson, serviceId, authVal)) { - continue; - } - if ((prefixSvcsJson != nullptr) && - CheckPrefixServiceAuth(prefixSvcsJson, serviceId, authVal)) { - continue; - } - HILOGE("denied to access service:%{public}s", serviceId.c_str()); - return false; - } - HILOGI("check pass, authorities statisfied"); - return true; -} - -bool AuthorityManager::CheckSpecificServiceAuth(const nlohmann::json& specificSvcsJson, - const std::string& serviceId, AuthValue authVal) -{ - if (!specificSvcsJson.contains(serviceId)) { - return false; - } - auto& authValJson = specificSvcsJson[serviceId]; - if (!authValJson.is_number_unsigned()) { - HILOGE("not number type"); - return false; - } - return ((authValJson.get() & authVal) != 0); -} - -bool AuthorityManager::CheckPrefixServiceAuth(const nlohmann::json& prefixSvcsJson, - const std::string& serviceId, AuthValue authVal) -{ - for (auto& [prefixSvcId, authValJson] : prefixSvcsJson.items()) { - if ((serviceId.compare(0, prefixSvcId.size(), prefixSvcId) == 0)) { - HILOGI("service:%{public}s, prefix:%{public}s", serviceId.c_str(), prefixSvcId.c_str()); - if (!authValJson.is_number_unsigned()) { - HILOGE("not number type"); - return false; - } - return ((authValJson.get() & authVal) != 0); - } - } - return false; -} - -bool AuthorityManager::CheckCallerTrust() -{ - auto tokenID = IPCSkeleton::GetCallingTokenID(); - if (tokenID == INVALID_TOKEN_ID) { - HILOGW("invalid token id"); - return false; - } - ATokenTypeEnum tokenType = AccessTokenKit::GetTokenTypeFlag(tokenID); - HILOGD("tokenID:%{public}u, tokenType:%{public}d", tokenID, tokenType); - // currently only support native trusted caller - return tokenType == ATokenTypeEnum::TOKEN_NATIVE; -} - -std::string AuthorityManager::GetCallingProcName() -{ - // called after CheckCallerTrust, and keep same policy with CheckCallerTrust - NativeTokenInfo nativeTokenInfo; - auto tokenID = IPCSkeleton::GetCallingTokenID(); - auto errCode = AccessTokenKit::GetNativeTokenInfo(tokenID, nativeTokenInfo); - HILOGI("get token info errCode = %{public}d", errCode); - std::string procName; - if (errCode == EOK) { - procName = std::move(nativeTokenInfo.processName); - HILOGI("procName:%{public}s", procName.c_str()); - } - return procName; -} -} // namespace DeviceProfile -} // namespace OHOS diff --git a/old/services/core/src/authority/trust_group_manager.cpp b/old/services/core/src/authority/trust_group_manager.cpp deleted file mode 100644 index 8da10e67..00000000 --- a/old/services/core/src/authority/trust_group_manager.cpp +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * 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. - */ - -#include "trust_group_manager.h" - -#include "device_profile_errors.h" -#include "device_profile_log.h" -#include "device_profile_storage_manager.h" -#include "device_profile_utils.h" -#include "dp_device_manager.h" -#include "sync_coordinator.h" - -namespace OHOS { -namespace DeviceProfile { -namespace { -const std::string TAG = "TrustGroupManager"; - -constexpr int32_t VISIBILITY_PUBLIC = -1; -const std::string AUTH_APPID = "device_profile_auth"; -} - -IMPLEMENT_SINGLE_INSTANCE(TrustGroupManager); - -void from_json(const nlohmann::json& jsonObject, GroupInfo& groupInfo) -{ - if (jsonObject.find(FIELD_GROUP_NAME) != jsonObject.end() && jsonObject[FIELD_GROUP_NAME].is_string()) { - jsonObject.at(FIELD_GROUP_NAME).get_to(groupInfo.groupName); - } - if (jsonObject.find(FIELD_GROUP_ID) != jsonObject.end() && jsonObject[FIELD_GROUP_ID].is_string()) { - jsonObject.at(FIELD_GROUP_ID).get_to(groupInfo.groupId); - } - if (jsonObject.find(FIELD_GROUP_OWNER) != jsonObject.end() && jsonObject[FIELD_GROUP_OWNER].is_string()) { - jsonObject.at(FIELD_GROUP_OWNER).get_to(groupInfo.groupOwner); - } - if (jsonObject.find(FIELD_GROUP_TYPE) != jsonObject.end() && jsonObject[FIELD_GROUP_TYPE].is_number_integer()) { - jsonObject.at(FIELD_GROUP_TYPE).get_to(groupInfo.groupType); - } - if (jsonObject.find(FIELD_GROUP_VISIBILITY) != jsonObject.end() && - jsonObject[FIELD_GROUP_VISIBILITY].is_number_integer()) { - jsonObject.at(FIELD_GROUP_VISIBILITY).get_to(groupInfo.groupVisibility); - } -} - -bool TrustGroupManager::InitHichainService() -{ - if (hichainGmInstance_ != nullptr) { - return true; - } - - if (InitDeviceAuthService() != ERR_OK) { - HILOGE("auth InitDeviceAuthService failed"); - return false; - } - - hichainGmInstance_ = GetGmInstance(); - if (hichainGmInstance_ == nullptr) { - HILOGE("auth GetGmInstance failed"); - return false; - } - - InitDataChangeListener(); - HILOGI("init succeeded"); - return true; -} - -void TrustGroupManager::InitDataChangeListener() -{ - dataChangeListener_.onDeviceUnBound = OnDeviceUnBoundAdapter; - if (hichainGmInstance_ == nullptr) { - HILOGE("hichainGmInstance_ is nullptr"); - return; - } - if (hichainGmInstance_->regDataChangeListener(AUTH_APPID.c_str(), &dataChangeListener_) != 0) { - HILOGE("auth RegDataChangeListener failed"); - } -} - -bool TrustGroupManager::CheckTrustGroup(const std::string& deviceId) -{ - if (!InitHichainService()) { - HILOGE("auth GetGmInstance failed"); - return false; - } - - uint32_t groupNum = 0; - char* returnGroups = nullptr; - int32_t ret = hichainGmInstance_->getRelatedGroups(ANY_OS_ACCOUNT, AUTH_APPID.c_str(), deviceId.c_str(), - &returnGroups, &groupNum); - if (ret != ERR_OK) { - HILOGE("failed, ret:%{public}d", ret); - return false; - } - return CheckGroupsInfo(returnGroups, groupNum); -} - -bool TrustGroupManager::CheckGroupsInfo(const char* returnGroups, uint32_t groupNum) -{ - if (returnGroups == nullptr || groupNum == 0) { - HILOGE("failed, returnGroups is nullptr"); - return false; - } - - nlohmann::json jsonObject = nlohmann::json::parse(returnGroups, nullptr, false); - if (jsonObject.is_discarded()) { - HILOGE("returnGroups parse error"); - return false; - } - if (!jsonObject.is_array()) { - HILOGE("not array type"); - return false; - } - std::vector groupInfos = jsonObject.get>(); - for (const auto& groupInfo : groupInfos) { - // check group visibility is whether public or not - if (groupInfo.groupVisibility != VISIBILITY_PUBLIC) { - continue; - } - - // check group type is whether (same count or point to point) or not - if (groupInfo.groupType == GroupType::IDENTICAL_ACCOUNT_GROUP || - groupInfo.groupType == GroupType::PEER_TO_PEER_GROUP) { - HILOGI("check success type = %{public}d", groupInfo.groupType); - return true; - } - } - HILOGE("check failed, not in trust group"); - return false; -} - -void TrustGroupManager::OnDeviceUnBoundAdapter(const char* peerUdid, const char* groupInfo) -{ - const std::string udid = peerUdid; - if (!CheckDeviceId(udid)) { - return; - } - - auto removeUnBoundDeviceTask = [udid = std::move(udid)]() { - HILOGI("remove unbound deivce profile start, udid = %{public}s", - DeviceProfileUtils::AnonymizeDeviceId(udid).c_str()); - if (GetInstance().CheckTrustGroup(udid)) { - HILOGI("unbound device in trust group"); - return; - } - - if (DeviceProfileStorageManager::GetInstance().RemoveUnBoundDeviceProfile(udid) != ERR_OK) { - HILOGE("remove unbound device profile failed, udid = %{public}s", - DeviceProfileUtils::AnonymizeDeviceId(udid).c_str()); - } else { - HILOGI("remove unbound deivce profile success, udid = %{public}s", - DeviceProfileUtils::AnonymizeDeviceId(udid).c_str()); - } - DpDeviceManager::GetInstance().RemoveDeviceIdsByUdid(udid); - }; - if (!SyncCoordinator::GetInstance().DispatchSyncTask(removeUnBoundDeviceTask)) { - HILOGE("post task failed"); - return; - } -} - -bool TrustGroupManager::CheckDeviceId(const std::string udid) -{ - std::string localDeviceId; - DpDeviceManager::GetInstance().GetLocalDeviceUdid(localDeviceId); - if (udid.empty() || localDeviceId.empty()) { - HILOGE("device id is empty"); - return false; - } - - if (udid == localDeviceId) { - return false; - } - return true; -} -} // namespace DeviceProfile -} // namespace OHOS \ No newline at end of file diff --git a/old/services/core/src/contentsensor/app_info_collector.cpp b/old/services/core/src/contentsensor/app_info_collector.cpp deleted file mode 100644 index 2f1fcab3..00000000 --- a/old/services/core/src/contentsensor/app_info_collector.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. - * 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. - */ - -#include "app_info_collector.h" - -#include "device_profile_log.h" -#include "dms_constant.h" -#include "nlohmann/json.hpp" - -namespace OHOS { -namespace DeviceProfile { -namespace { -const std::string TAG = "AppInfoCollector"; - -const std::string SERVICE_ID = "appInfo"; -const std::string SERVICE_TYPE = "appInfo"; -const std::string PACKAGE_NAMES = "packageNames"; -const std::string VERSIONS = "versions"; -} - -bool AppInfoCollector::ConvertToProfileData(ServiceCharacteristicProfile& profile) -{ - profile.SetServiceId(SERVICE_ID); - profile.SetServiceType(SERVICE_TYPE); - nlohmann::json jsonData; - std::string packageNames; - std::string versions; - GetDmsVersionInfo(packageNames, versions); - jsonData[PACKAGE_NAMES] = packageNames; - jsonData[VERSIONS] = versions; - profile.SetCharacteristicProfileJson(jsonData.dump()); - return true; -} - -bool AppInfoCollector::GetDmsVersionInfo(std::string& dmsName, std::string& dmsVersionData) -{ - dmsName = DistributedSchedule::Constants::DMS_NAME; - dmsVersionData = DistributedSchedule::Constants::DMS_VERSION; - return true; -} -} // namespace DeviceProfile -} // OHOS diff --git a/old/services/core/src/contentsensor/content_collector.cpp b/old/services/core/src/contentsensor/content_collector.cpp deleted file mode 100644 index cbac30a1..00000000 --- a/old/services/core/src/contentsensor/content_collector.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ - -#include "content_collector.h" - -#include "device_profile_log.h" -#include "device_profile_storage_manager.h" - -namespace OHOS { -namespace DeviceProfile { -namespace { -const std::string TAG = "ContentCollector"; -} - -void ContentCollector::DoCollect(ServiceCharacteristicProfile& profileData) -{ - DeviceProfileStorageManager::GetInstance().PutDeviceProfile(profileData); -} -} // namespace DeviceProfile -} // namespace OHOS \ No newline at end of file diff --git a/old/services/core/src/contentsensor/content_sensor_manager.cpp b/old/services/core/src/contentsensor/content_sensor_manager.cpp deleted file mode 100644 index 6792235b..00000000 --- a/old/services/core/src/contentsensor/content_sensor_manager.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. - * 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. - */ - -#include "content_sensor_manager.h" - -#include "app_info_collector.h" -#include "device_info_collector.h" -#include "device_profile_log.h" -#include "hitrace_meter.h" -#include "pasteboard_info_collector.h" -#include "storage_info_collector.h" -#include "syscap_info_collector.h" -#include "system_info_collector.h" - -namespace OHOS { -namespace DeviceProfile { -namespace { -const std::string TAG = "ContentSensorManager"; -const std::string DP_CONTENT_SENSOR_TRACE = "DP_CONTENT_SENSOR"; -} - -IMPLEMENT_SINGLE_INSTANCE(ContentSensorManager); - -bool ContentSensorManager::Init() -{ - return true; -} - -bool ContentSensorManager::Collect() -{ - auto csTask = []() { - HILOGI("ContentSensorManager Collect"); - std::list> taskList; - taskList.push_back(std::make_shared()); - taskList.push_back(std::make_shared()); - taskList.push_back(std::make_shared()); - taskList.push_back(std::make_shared()); - taskList.push_back(std::make_shared()); - taskList.push_back(std::make_shared()); - HITRACE_METER_NAME(HITRACE_TAG_DEVICE_PROFILE, DP_CONTENT_SENSOR_TRACE); - for (auto& task : taskList) { - ServiceCharacteristicProfile profileData; - if (task == nullptr || !task->ConvertToProfileData(profileData)) { - continue; - } - task->DoCollect(profileData); - } - }; - if (csCollectorHandler_ == nullptr || !csCollectorHandler_->PostTask(csTask)) { - HILOGE("post task failed"); - return false; - } - return true; -} -} // namespace DeviceProfile -} // namespace OHOS \ No newline at end of file diff --git a/old/services/core/src/contentsensor/device_info_collector.cpp b/old/services/core/src/contentsensor/device_info_collector.cpp deleted file mode 100644 index 605b86db..00000000 --- a/old/services/core/src/contentsensor/device_info_collector.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * 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. - */ - -#include "device_info_collector.h" - -#include "device_profile_log.h" -#include "nlohmann/json.hpp" -#include "parameter.h" -#include "content_sensor_manager_utils.h" - -namespace OHOS { -namespace DeviceProfile { -namespace { -const std::string TAG = "DeviceInfoCollector"; - -const std::string SERVICE_ID = "device"; -const std::string SERVICE_TYPE = "device"; -const std::string DEVICE_NAME = "deviceName"; -const std::string DEVICE_MODEL = "model"; -const std::string DEVICE_UDID = "udid"; -const std::string DEVICE_TYPE = "devType"; -const std::string DEVICE_MANU = "manu"; -const std::string DEVICE_SN = "sn"; -} - -bool DeviceInfoCollector::ConvertToProfileData(ServiceCharacteristicProfile& profile) -{ - profile.SetServiceId(SERVICE_ID); - profile.SetServiceType(SERVICE_TYPE); - nlohmann::json jsonData; - jsonData[DEVICE_NAME] = GetDeviceName(); - jsonData[DEVICE_MODEL] = GetDeviceModel(); - jsonData[DEVICE_UDID] = GetDeviceUdid(); - jsonData[DEVICE_TYPE] = GetDevType(); - jsonData[DEVICE_MANU] = GetDeviceManufacturer(); - jsonData[DEVICE_SN] = GetDeviceSerial(); - profile.SetCharacteristicProfileJson(jsonData.dump()); - return true; -} - -std::string DeviceInfoCollector::GetDeviceModel() -{ - return DistributedDeviceProfile::ContentSensorManagerUtils::GetInstance().ObtainProductModel(); -} - -std::string DeviceInfoCollector::GetDevType() -{ - return DistributedDeviceProfile::ContentSensorManagerUtils::GetInstance().ObtainDeviceType(); -} - -std::string DeviceInfoCollector::GetDeviceManufacturer() -{ - return DistributedDeviceProfile::ContentSensorManagerUtils::GetInstance().ObtainManufacture(); -} - -std::string DeviceInfoCollector::GetDeviceSerial() -{ - return DistributedDeviceProfile::ContentSensorManagerUtils::GetInstance().ObtainSerial(); -} - -std::string DeviceInfoCollector::GetDeviceName() -{ - return DistributedDeviceProfile::ContentSensorManagerUtils::GetInstance().ObtainMarketName(); -} - -std::string DeviceInfoCollector::GetDeviceUdid() -{ - return DistributedDeviceProfile::ContentSensorManagerUtils::GetInstance().ObtainLocalUdid(); -} -} // namespace DeviceProfile -} // namespace OHOS \ No newline at end of file diff --git a/old/services/core/src/contentsensor/pasteboard_info_collector.cpp b/old/services/core/src/contentsensor/pasteboard_info_collector.cpp deleted file mode 100644 index 45b52903..00000000 --- a/old/services/core/src/contentsensor/pasteboard_info_collector.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * 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. - */ - -#include "pasteboard_info_collector.h" - -#include "device_profile_log.h" -#include "nlohmann/json.hpp" -#include "parameter.h" - -namespace OHOS { -namespace DeviceProfile { -namespace { -const std::string TAG = "PasteboardInfoCollector"; -const std::string SERVICE_ID = "pasteboardService"; -const std::string SERVICE_TYPE = "pasteboardService"; -const std::string SUPPORT_DISTRIBUTED_PASTEBOARD = "supportDistributedPasteboard"; -const std::string PASTEBOARD_VERSION = "PasteboardVersionId"; -constexpr uint32_t FIRST_VERSION = 4; - -const char *DISTRIBUTED_PASTEBOARD_ENABLED_KEY = "persist.pasteboard.distributedPasteboardEnabled"; -const std::string ENABLED_STATUS = "true"; -const char* UNDEFINED_VALUE = "undefined"; -constexpr int CONFIG_LEN = 10; -constexpr uint32_t NOT_SUPPORT = 0; -constexpr uint32_t SUPPORT = 1; -} - -bool PasteboardInfoCollector::ConvertToProfileData(ServiceCharacteristicProfile& profile) -{ - HILOGI("call"); - profile.SetServiceId(SERVICE_ID); - profile.SetServiceType(SERVICE_TYPE); - nlohmann::json jsonData; - jsonData[SUPPORT_DISTRIBUTED_PASTEBOARD] = GetSupportDistributedPasteboard(); - jsonData[PASTEBOARD_VERSION] = FIRST_VERSION; - profile.SetCharacteristicProfileJson(jsonData.dump()); - return true; -} - -uint32_t PasteboardInfoCollector::GetSupportDistributedPasteboard() -{ - char value[CONFIG_LEN] = { 0 }; - GetParameter(DISTRIBUTED_PASTEBOARD_ENABLED_KEY, UNDEFINED_VALUE, value, CONFIG_LEN); - HILOGI("GetParameter, value = %{public}s.", value); - std::string enabledStatus(value); - return enabledStatus == ENABLED_STATUS ? SUPPORT : NOT_SUPPORT; -} -} // namespace DeviceProfile -} // OHOS \ No newline at end of file diff --git a/old/services/core/src/contentsensor/storage_info_collector.cpp b/old/services/core/src/contentsensor/storage_info_collector.cpp deleted file mode 100644 index 33e421d9..00000000 --- a/old/services/core/src/contentsensor/storage_info_collector.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * 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. - */ - -#include "storage_info_collector.h" - -#include - -#include "device_profile_log.h" -#include "nlohmann/json.hpp" - -namespace OHOS { -namespace DeviceProfile { -namespace { -const std::string TAG = "StorageInfoCollector"; - -const char* PATH_DATA = "/data"; -const std::string SERVICE_ID = "storage"; -const std::string SERVICE_TYPE = "storage"; -const std::string CAPACITY = "capacity"; -constexpr int64_t KILOBYTE = 1024; -} - -bool StorageInfoCollector::ConvertToProfileData(ServiceCharacteristicProfile& profile) -{ - profile.SetServiceId(SERVICE_ID); - profile.SetServiceType(SERVICE_TYPE); - nlohmann::json jsonData; - int64_t totalSize = GetTotalSize(); - if (totalSize == 0) { - return false; - } - jsonData[CAPACITY] = totalSize; - profile.SetCharacteristicProfileJson(jsonData.dump()); - return true; -} - -int64_t StorageInfoCollector::GetTotalSize() -{ - int64_t totalSize = 0; - struct statvfs diskInfo; - int ret = statvfs(PATH_DATA, &diskInfo); - if (ret != 0) { - HILOGE("GetTotalSize failed"); - return totalSize; - } - totalSize = (int64_t)diskInfo.f_bsize * (int64_t)diskInfo.f_blocks / KILOBYTE; - return totalSize; -} -} // namespace DeviceProfile -} // OHOS diff --git a/old/services/core/src/contentsensor/syscap_info_collector.cpp b/old/services/core/src/contentsensor/syscap_info_collector.cpp deleted file mode 100644 index 108bb27a..00000000 --- a/old/services/core/src/contentsensor/syscap_info_collector.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * 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. - */ - -#include "syscap_info_collector.h" - -#include "device_profile_errors.h" -#include "device_profile_log.h" -#include "nlohmann/json.hpp" -#include "parameters.h" -#include "syscap_interface.h" - -namespace OHOS { -namespace DeviceProfile { -namespace { - const std::string TAG = "SyscapInfoCollector"; - - const std::string SERVICE_ID = "syscap"; - const std::string SERVICE_TYPE = "syscap"; - const std::string CHARACTER_PRIVATE_SYSCAP = "privatesyscap"; - const std::string CHARACTER_OS_SYSCAP = "ossyscap"; - constexpr int32_t MAX_DATALEN = 1128; - constexpr int32_t INT_BYTES_LEN = 4; -} - -bool SyscapInfoCollector::ConvertToProfileData(ServiceCharacteristicProfile& profile) -{ - profile.SetServiceId(SERVICE_ID); - profile.SetServiceType(SERVICE_TYPE); - - char osBuffer[PCID_MAIN_BYTES]; - if (!EncodeOsSyscap(osBuffer, PCID_MAIN_BYTES)) { - HILOGE("EncodeOsSyscap failed"); - return false; - } - - std::vector osSyscapData; - for (int i = 0; i < PCID_MAIN_BYTES/INT_BYTES_LEN; i++) { - int32_t value = *((int32_t *)osBuffer + i); - osSyscapData.push_back(value); - } - - nlohmann::json jsonData; - nlohmann::json osSyscapJsonData(osSyscapData); - jsonData[CHARACTER_OS_SYSCAP] = osSyscapJsonData; - - char* privateBuffer = nullptr; - int32_t privateBufferLen; - if (!EncodePrivateSyscap(&privateBuffer, &privateBufferLen)) { - HILOGE("EncodePrivateSyscap failed"); - return false; - } - if (privateBufferLen + PCID_MAIN_BYTES > MAX_DATALEN) { - free(privateBuffer); - HILOGI("syscap data length too long"); - return false; - } - jsonData[CHARACTER_PRIVATE_SYSCAP] = privateBuffer; - free(privateBuffer); - profile.SetCharacteristicProfileJson(jsonData.dump()); - return true; -} -} // namespace DeviceProfile -} // namespace OHOS \ No newline at end of file diff --git a/old/services/core/src/contentsensor/system_info_collector.cpp b/old/services/core/src/contentsensor/system_info_collector.cpp deleted file mode 100644 index 3771121f..00000000 --- a/old/services/core/src/contentsensor/system_info_collector.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * 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. - */ - -#include "system_info_collector.h" - -#include "device_profile_log.h" -#include "nlohmann/json.hpp" -#include "parameter.h" -#include "securec.h" -#include "content_sensor_manager_utils.h" -#include "distributed_device_profile_constants.h" - -namespace OHOS { -namespace DeviceProfile { -namespace { -const std::string TAG = "SystemInfoCollector"; - -const std::string SERVICE_ID = "system"; -const std::string SERVICE_TYPE = "system"; -const std::string SYSTEM_OS_TYPE = "type"; -const std::string DEVICE_OHOS_VERSION = "harmonyVersion"; -const std::string DEVICE_API_LEVEL = "harmonyApiLevel"; -const std::string DEVICE_OHOS_NAME = "OpenHarmony"; -constexpr int32_t OHOS_TYPE_UNKNOWN = -1; -constexpr int32_t OHOS_TYPE = 10; -} - -bool SystemInfoCollector::ConvertToProfileData(ServiceCharacteristicProfile& profile) -{ - profile.SetServiceId(SERVICE_ID); - profile.SetServiceType(SERVICE_TYPE); - nlohmann::json jsonData; - jsonData[SYSTEM_OS_TYPE] = GetOsType(); - jsonData[DEVICE_OHOS_VERSION] = GetOsVersion(); - jsonData[DEVICE_API_LEVEL] = GetSdkApiVersion(); - profile.SetCharacteristicProfileJson(jsonData.dump()); - return true; -} - -int32_t SystemInfoCollector::GetOsType() -{ - std::string osFullName = DistributedDeviceProfile::ContentSensorManagerUtils::GetInstance().ObtainOsFullName(); - if (osFullName.empty() || osFullName.size() >= DistributedDeviceProfile::MAX_STRING_LEN) { - HILOGI("osFullName size is invalid!"); - return OHOS_TYPE_UNKNOWN; - } - size_t found = osFullName.find(DEVICE_OHOS_NAME); - if (found != std::string::npos) { - HILOGI("osFullName is invalid!"); - return OHOS_TYPE_UNKNOWN; - } - return OHOS_TYPE; -} - -std::string SystemInfoCollector::GetOsVersion() -{ - return DistributedDeviceProfile::ContentSensorManagerUtils::GetInstance().ObtainDisplayVersion(); -} -} // namespace DeviceProfile -} // namespace OHOS \ No newline at end of file diff --git a/old/services/core/src/dbstorage/device_profile_storage.cpp b/old/services/core/src/dbstorage/device_profile_storage.cpp deleted file mode 100644 index 1b5623ea..00000000 --- a/old/services/core/src/dbstorage/device_profile_storage.cpp +++ /dev/null @@ -1,405 +0,0 @@ -/* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. - * 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. - */ - -#include "device_profile_storage.h" - -#include -#include -#include - -#include "device_profile_errors.h" -#include "device_profile_log.h" -#include "device_profile_storage_manager.h" -#include "device_profile_utils.h" -#include "dp_device_manager.h" -#include "service_characteristic_profile.h" -#include "trust_group_manager.h" - -#include "datetime_ex.h" -#include "profile_change_handler.h" - -namespace OHOS { -namespace DeviceProfile { -using namespace OHOS::DistributedKv; -using namespace std::chrono_literals; - -namespace { -const std::string TAG = "DeviceProfileStorage"; -const std::string PKG_NAME = "ohos.deviceprofile"; -constexpr int32_t RETRY_TIMES_GET_KVSTORE = 1; -} - -DeviceProfileStorage::DeviceProfileStorage(const std::string& appId, const std::string& storeId) -{ - appId_.appId = appId, - storeId_.storeId = storeId; -} - -void DeviceProfileStorage::SetOptions(const Options& options) -{ - options_ = options; -} - -bool DeviceProfileStorage::RegisterKvStoreInitCallback(const KvStoreInitCallback& callback) -{ - if (kvStoreInitCallback_ != nullptr) { - HILOGE("callback is not null"); - return false; - } - kvStoreInitCallback_ = callback; - return true; -} - -void DeviceProfileStorage::Init() -{ - int64_t begin = GetTickCount(); - std::unique_lock writeLock(storageLock_); - bool result = TryGetKvStore(); - writeLock.unlock(); - int64_t end = GetTickCount(); - HILOGI("TryGetKvStore %{public}s, spend %{public}" PRId64 " ms", - result ? "succeeded" : "failed", end - begin); - // must call callback before set init status - if (result && kvStoreInitCallback_ != nullptr) { - kvStoreInitCallback_(); - } - if (result) { - initStatus_ = StorageInitStatus::INIT_SUCCEED; - } -} - -int32_t DeviceProfileStorage::SubscribeKvStore(const std::shared_ptr& observer) -{ - HILOGD("called"); - if (kvStorePtr_ == nullptr || observer == nullptr) { - return ERR_DP_INVALID_PARAMS; - } - Status status = kvStorePtr_->SubscribeKvStore(SubscribeType::SUBSCRIBE_TYPE_REMOTE, observer); - HILOGI("status %{public}d", status); - return static_cast(status); -} - -int32_t DeviceProfileStorage::UnSubscribeKvStore(const std::shared_ptr& observer) -{ - HILOGD("called"); - if (kvStorePtr_ == nullptr || observer == nullptr) { - return ERR_DP_INVALID_PARAMS; - } - Status status = kvStorePtr_->UnSubscribeKvStore(SubscribeType::SUBSCRIBE_TYPE_REMOTE, observer); - HILOGI("status %{public}d", status); - return static_cast(status); -} - -int32_t DeviceProfileStorage::RegisterSyncCallback(const std::shared_ptr& sycnCb) -{ - HILOGD("called"); - if (kvStorePtr_ == nullptr || sycnCb == nullptr) { - return ERR_DP_INVALID_PARAMS; - } - Status status = kvStorePtr_->RegisterSyncCallback(sycnCb); - HILOGI("status %{public}d", status); - return static_cast(status); -} - -int32_t DeviceProfileStorage::UnRegisterSyncCallback() -{ - HILOGD("called"); - if (kvStorePtr_ == nullptr) { - return ERR_DP_INVALID_PARAMS; - } - Status status = kvStorePtr_->UnRegisterSyncCallback(); - HILOGI("status %{public}d", status); - return static_cast(status); -} - -StorageInitStatus DeviceProfileStorage::GetInitStatus() -{ - HILOGI("GetInitStatus %{public}d", static_cast(initStatus_.load())); - return initStatus_; -} - -bool DeviceProfileStorage::TryGetKvStore() -{ - int32_t retryTimes = 0; - while (retryTimes < RETRY_TIMES_GET_KVSTORE) { - if (GetKvStore() == Status::SUCCESS && kvStorePtr_ != nullptr) { - return true; - } - HILOGD("retry get kvstore..."); - retryTimes++; - } - if (kvStorePtr_ == nullptr) { - initStatus_ = StorageInitStatus::INIT_FAILED; - return false; - } - return true; -} - -Status DeviceProfileStorage::GetKvStore() -{ - HILOGD("called"); - Status status = dataManager_.GetSingleKvStore(options_, appId_, storeId_, kvStorePtr_); - if (status != Status::SUCCESS) { - HILOGI("get failed, error = %{public}d", status); - } else { - HILOGI("get succeeded"); - } - return status; -} - -void DeviceProfileStorage::DeleteKvStore() -{ - Status status = dataManager_.DeleteKvStore(appId_, storeId_, options_.baseDir); - if (status != Status::SUCCESS) { - HILOGE("delete failed, error = %{public}d", status); - } -} - -int32_t DeviceProfileStorage::GetDeviceProfile(const std::string& key, std::string& value) -{ - std::shared_lock readLock(storageLock_); - if (kvStorePtr_ == nullptr) { - HILOGE("null kvstore"); - return ERR_DP_INVALID_PARAMS; - } - - Key k(key); - Value v; - Status status = kvStorePtr_->Get(k, v); - if (status != Status::SUCCESS) { - HILOGE("get failed, %{public}d", status); - return static_cast(status); - } - value = v.ToString(); - HILOGI("get succeeded"); - return static_cast(status); -} - -int32_t DeviceProfileStorage::PutDeviceProfile(const std::string& key, const std::string& value) -{ - std::unique_lock writeLock(storageLock_); - if (kvStorePtr_ == nullptr) { - HILOGE("null kvstore"); - return ERR_DP_INVALID_PARAMS; - } - - Key kvKey(key); - Value oldV; - if (kvStorePtr_->Get(kvKey, oldV) == Status::SUCCESS && oldV.ToString() == value) { - HILOGD("The key-value pair already exists. key=%{public}s,value=%{public}s", - DeviceProfileUtils::AnonymizeDeviceId(key).c_str(), DeviceProfileUtils::AnonymizeDeviceId(value).c_str()); - return ERR_OK; - } - - Value kvValue(value); - Status status = kvStorePtr_->Put(kvKey, kvValue); - if (status != Status::SUCCESS) { - HILOGE("put failed, error = %{public}d", status); - } - return static_cast(status); -} - -int32_t DeviceProfileStorage::PutDeviceProfileBatch(const std::vector& keys, - const std::vector& values) -{ - std::unique_lock writeLock(storageLock_); - if (kvStorePtr_ == nullptr) { - HILOGE("null kvstore"); - return ERR_DP_INVALID_PARAMS; - } - - const size_t keySize = keys.size(); - const size_t valSize = values.size(); - HILOGI("keySize = %{public}zu, valSize = %{public}zu", keySize, valSize); - if (keySize != valSize) { - HILOGE("diff key-value size"); - return ERR_DP_INVALID_PARAMS; - } - - std::vector entries; - Value oldV; - Key kvKey; - for (uint32_t i = 0; i < keySize; i++) { - kvKey = keys[i]; - if (kvStorePtr_->Get(kvKey, oldV) == Status::SUCCESS && oldV.ToString() == values[i]) { - HILOGD("The key-value pair already exists. key=%{public}s,value=%{public}s", - DeviceProfileUtils::AnonymizeDeviceId(keys[i]).c_str(), - DeviceProfileUtils::AnonymizeDeviceId(values[i]).c_str()); - continue; - } - - Entry entry; - entry.key = kvKey; - entry.value = values[i]; - entries.emplace_back(entry); - } - if (entries.empty()) { - HILOGD("All key-value pair already exists."); - return ERR_OK; - } - - Status status = kvStorePtr_->PutBatch(entries); - if (status != Status::SUCCESS) { - HILOGE("put batch failed, error = %{public}d", status); - } - return static_cast(status); -} - -int32_t DeviceProfileStorage::DeleteDeviceProfile(const std::string& key) -{ - std::unique_lock writeLock(storageLock_); - if (kvStorePtr_ == nullptr) { - return ERR_DP_INVALID_PARAMS; - } - Key k(key); - Status status = kvStorePtr_->Delete(k); - if (status != Status::SUCCESS) { - HILOGE("delete failed, error = %{public}d", status); - } - return static_cast(status); -} - -int32_t DeviceProfileStorage::SyncDeviceProfile(const std::vector& deviceIdList, - SyncMode syncMode) -{ - HILOGI("called"); - std::vector trustDeviceList = CheckTrustDeviceList(deviceIdList); - if (trustDeviceList.empty()) { - HILOGE("trust device list is empty"); - return ERR_DP_UNTRUSTED_GROUP; - } - - std::unique_lock writeLock(storageLock_); - if (kvStorePtr_ == nullptr) { - return ERR_DP_INVALID_PARAMS; - } - - Status status = kvStorePtr_->Sync(trustDeviceList, static_cast(syncMode)); - if (status != Status::SUCCESS) { - HILOGE("sync failed, error = %{public}d", status); - } - return static_cast(status); -} - -int32_t DeviceProfileStorage::RemoveDeviceData(const std::string networkId) -{ - HILOGI("called"); - - std::unique_lock writeLock(storageLock_); - if (kvStorePtr_ == nullptr) { - HILOGE("null kvstore"); - return ERR_DP_INVALID_PARAMS; - } - - Status status = kvStorePtr_->RemoveDeviceData(networkId); - if (status != Status::SUCCESS) { - HILOGE("remote device data failed, error = %{public}d", status); - } - return static_cast(status); -} - -bool DeviceProfileStorage::CheckTrustGroup(const std::vector& deviceIdList) -{ - if (deviceIdList.empty()) { - HILOGE("device list is empty"); - return false; - } - for (const auto& deviceId : deviceIdList) { - std::string udid; - if (!DpDeviceManager::GetInstance().TransformDeviceId(deviceId, udid, DeviceIdType::UDID)) { - HILOGE("%{public}s transform to udid failed", DeviceProfileUtils::AnonymizeDeviceId(deviceId).c_str()); - return false; - } - - if (!TrustGroupManager::GetInstance().CheckTrustGroup(udid)) { - HILOGE("%{public}s not in trust group", DeviceProfileUtils::AnonymizeDeviceId(deviceId).c_str()); - return false; - } - } - return true; -} - -std::vector DeviceProfileStorage::CheckTrustDeviceList(const std::vector &deviceIdList) -{ - std::vector trustDevices; - if (deviceIdList.empty()) { - HILOGE("device list is empty"); - return trustDevices; - } - std::vector onlineDevices = GetOnlineDevices(); - for (const auto& deviceId : deviceIdList) { - auto iter = find(onlineDevices.begin(), onlineDevices.end(), deviceId); - if (iter != onlineDevices.end()) { - HILOGI("%{public}s add to trust devices", DeviceProfileUtils::AnonymizeDeviceId(deviceId).c_str()); - trustDevices.push_back(deviceId); - } - } - return trustDevices; -} - -std::vector DeviceProfileStorage::GetOnlineDevices() -{ - std::vector targetDevices; - std::vector allOnlineDeviceInfos; - int32_t result = - DistributedHardware::DeviceManager::GetInstance().GetTrustedDeviceList(PKG_NAME, "", allOnlineDeviceInfos); - if (result != Status::SUCCESS || allOnlineDeviceInfos.empty()) { - HILOGE("GetTrustedDeviceList Failed!"); - return {}; - } - for (const auto& dmDeviceInfo : allOnlineDeviceInfos) { - targetDevices.push_back(dmDeviceInfo.networkId); - } - HILOGI("online device size is %{public}zu", targetDevices.size()); - return targetDevices; -} - -int32_t DeviceProfileStorage::GetDeviceProfile(const std::string& udid, const std::string& key, std::string& value) -{ - HILOGI("call"); - if (udid.empty() || key.empty()) { - HILOGE("udid or key invalid"); - return ERR_DP_INVALID_PARAMS; - } - Key k(key); - Value v; - Status status; - { - std::shared_lock readLock(storageLock_); - if (kvStorePtr_ == nullptr) { - HILOGE("null kvstore"); - return ERR_DP_INVALID_PARAMS; - } - status = kvStorePtr_->Get(k, v); - HILOGI("Get data status: %{public}d", status); - } - if (status == Status::NOT_FOUND) { - std::vector device; - device.push_back(udid); - SyncMode syncMode{ SyncMode::PUSH_PULL }; - int32_t res = SyncDeviceProfile(device, syncMode); - HILOGI("SyncDeviceProfile res: %{public}d!", res); - return static_cast(status); - } - if (status != Status::SUCCESS) { - HILOGE("get failed, %{public}d", status); - return static_cast(status); - } - value = v.ToString(); - HILOGI("get succeeded"); - return static_cast(status); -} -} // namespace DeviceProfile -} // namespace OHOS diff --git a/old/services/core/src/dbstorage/device_profile_storage_manager.cpp b/old/services/core/src/dbstorage/device_profile_storage_manager.cpp deleted file mode 100644 index 6138571c..00000000 --- a/old/services/core/src/dbstorage/device_profile_storage_manager.cpp +++ /dev/null @@ -1,641 +0,0 @@ -/* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. - * 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. - */ - -#include "device_profile_storage_manager.h" - -#include -#include - -#include "device_profile_errors.h" -#include "device_profile_log.h" -#include "device_profile_utils.h" -#include "dp_device_manager.h" -#include "dp_radar_helper.h" -#include "hisysevent.h" -#include "hitrace_meter.h" -#include "sync_coordinator.h" - -#include "ipc_object_proxy.h" -#include "ipc_skeleton.h" -#include "iservice_registry.h" -#include "subscribe_info.h" -#include "subscribe_manager.h" -#include "system_ability_definition.h" - -namespace OHOS { -namespace DeviceProfile { -using namespace OHOS::HiviewDFX; -using namespace std::chrono_literals; -using namespace OHOS::DistributedKv; - -namespace { -const std::string TAG = "DeviceProfileStorageManager"; - -const std::string SERVICE_TYPE = "type"; -const std::string SERVICES = "services"; -const std::string DP_SYNC_FAILED = "DP_SYNC_FAILED"; -const std::string DP_SYNC_EVENT = "DP_SYNC_EVENT"; -const std::string FAULT_CODE_KEY = "FAULT_CODE"; -const std::string DP_DEVICE_PUT_TRACE = "DP_DEVICE_PUT"; -const std::string DP_DEVICE_GET_TRACE = "DP_DEVICE_GET"; -const std::string DP_DEVICE_DELETE_TRACE = "DP_DEVICE_DELETE"; -const std::string DP_DEVICE_SYNC_TRACE = "DP_DEVICE_SYNC"; -constexpr int32_t RETRY_TIMES_WAIT_KV_DATA = 600; -constexpr int32_t FIX_TASK_ID = 0; -constexpr int32_t DELAY_TIME_MS = 100; -constexpr int32_t INDENT = -1; -const char INDENT_CHAR = ' '; -} - -IMPLEMENT_SINGLE_INSTANCE(DeviceProfileStorageManager); - -bool DeviceProfileStorageManager::Init() -{ - std::lock_guard lock(initLock_); - if (!inited_) { - if (!SyncCoordinator::GetInstance().Init()) { - HILOGE("SyncCoordinator init failed"); - return false; - } - DpDeviceManager::GetInstance().GetLocalDeviceUdid(localUdid_); - if (localUdid_.empty()) { - HILOGE("get local udid failed"); - return false; - } - onlineSyncTbl_ = std::make_shared(); - kvStoreDeathRecipientDp_ = sptr(new KvStoreDeathRecipientDp()); - auto runner = AppExecFwk::EventRunner::Create("dpstorage"); - storageHandler_ = std::make_shared(runner); - if (storageHandler_ == nullptr) { - return false; - } - inited_ = true; - } - - bool isKvServiceLoad = WaitKvDataService(); - if (!isKvServiceLoad) { - HILOGE("WaitKvDataService fail!"); - std::lock_guard autoLock(serviceLock_); - profileItems_.clear(); - kvDataServiceFailed_ = true; - return false; - } - HILOGI("WaitKvDataService success!"); - auto callback = std::bind(&DeviceProfileStorageManager::OnKvStoreInitDone, this); - onlineSyncTbl_->RegisterKvStoreInitCallback(callback); - onlineSyncTbl_->Init(); - - HILOGI("init succeeded"); - return true; -} - -bool DeviceProfileStorageManager::WaitKvDataService() -{ - auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (samgrProxy == nullptr) { - HILOGE("get samgrProxy failed"); - return false; - } - int32_t retryTimes = RETRY_TIMES_WAIT_KV_DATA; - do { - auto kvDataSvr = samgrProxy->CheckSystemAbility(DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID); - if (kvDataSvr != nullptr) { - IPCObjectProxy* proxy = reinterpret_cast(kvDataSvr.GetRefPtr()); - if (proxy != nullptr && !proxy->IsObjectDead()) { - HILOGI("get service succeed"); - proxy->AddDeathRecipient(kvStoreDeathRecipientDp_); - return true; - } - } - HILOGD("waiting for service..."); - std::this_thread::sleep_for(std::chrono::milliseconds(DELAY_TIME_MS)); - if (--retryTimes <= 0) { - HILOGE("waiting service timeout(60)s"); - return false; - } - } while (true); - return false; -} - -std::string DeviceProfileStorageManager::GenerateKey(const std::string& udid, - const std::string& key, KeyType keyType) -{ - std::string tmp; - tmp.append(udid).append("/").append(std::to_string(static_cast(keyType))).append("/").append(key); - return tmp; -} - -int32_t DeviceProfileStorageManager::PutDeviceProfile(const ServiceCharacteristicProfile& profile) -{ - HITRACE_METER_NAME(HITRACE_TAG_DEVICE_PROFILE, DP_DEVICE_PUT_TRACE); - if (onlineSyncTbl_ == nullptr) { - HILOGE("onlineSyncTbl is nullptr!"); - return ERR_DP_INIT_DB_FAILED; - } - if (kvDataServiceFailed_ || onlineSyncTbl_->GetInitStatus() == StorageInitStatus::INIT_FAILED) { - HILOGE("kvstore init failed"); - return ERR_DP_INIT_DB_FAILED; - } - - std::vector keys; - std::vector values; - std::string serviceId = profile.GetServiceId(); - keys.emplace_back(GenerateKey(localUdid_, serviceId, KeyType::SERVICE)); - values.emplace_back(profile.GetCharacteristicProfileJson()); - std::unique_lock autoLock(serviceLock_); - if (servicesJson_[serviceId] == nullptr) { - nlohmann::json j; - j[SERVICE_TYPE] = profile.GetServiceType(); - servicesJson_[serviceId] = j; - keys.emplace_back(GenerateKey(localUdid_, SERVICES, KeyType::SERVICE_LIST)); - values.emplace_back(servicesJson_.dump(INDENT, INDENT_CHAR, false, nlohmann::json::error_handler_t::ignore)); - } - - int32_t errCode = ERR_OK; - if (onlineSyncTbl_ != nullptr && onlineSyncTbl_->GetInitStatus() == StorageInitStatus::INIT_SUCCEED) { - autoLock.unlock(); - if (keys.size() > 1) { - errCode = onlineSyncTbl_->PutDeviceProfileBatch(keys, values); - } else { - errCode = onlineSyncTbl_->PutDeviceProfile(keys[0], values[0]); - } - } else { - for (size_t i = 0; i < keys.size(); i++) { - profileItems_[keys[i]] = values[i]; - } - } - struct RadarInfo info = { - .funcName = "PutDeviceProfile", - .stageRes = (errCode == ERR_OK) ? - static_cast(StageRes::STAGE_SUCC) : static_cast(StageRes::STAGE_FAIL), - .toCallPkg = kvNAME, - .hostName = DpRadarHelper::GetInstance().GetHostNameByServiceId(serviceId), - .localUdid = localUdid_, - .errCode = ERR_DP_ADD_DATA_FAILED, - }; - if (!DpRadarHelper::GetInstance().ReportAddData(info)) { - HILOGE("ReportAddData failed"); - } - return errCode; -} - -int32_t DeviceProfileStorageManager::GetDeviceProfile(const std::string& udid, - const std::string& serviceId, ServiceCharacteristicProfile& profile) -{ - HITRACE_METER_NAME(HITRACE_TAG_DEVICE_PROFILE, DP_DEVICE_GET_TRACE); - if (onlineSyncTbl_ == nullptr) { - HILOGE("onlineSyncTbl is nullptr!"); - return ERR_DP_INIT_DB_FAILED; - } - if (onlineSyncTbl_->GetInitStatus() == StorageInitStatus::INIT_FAILED) { - HILOGE("kvstore init failed"); - return ERR_DP_INIT_DB_FAILED; - } - - std::string key; - std::string value; - int32_t result = ERR_OK; - if (udid.empty()) { - key = GenerateKey(localUdid_, serviceId, KeyType::SERVICE); - SetServiceType(udid, serviceId, profile); - } else { - std::string queryUdid; - if (!DpDeviceManager::GetInstance().TransformDeviceId(udid, queryUdid, - DeviceIdType::UDID)) { - HILOGE("transform to networkid failed"); - return ERR_DP_INVALID_PARAMS; - } - key = GenerateKey(queryUdid, serviceId, KeyType::SERVICE); - SetServiceType(queryUdid, serviceId, profile); - } - std::unique_lock autoLock(serviceLock_); - auto itItem = profileItems_.find(key); - if (itItem != profileItems_.end()) { - value = profileItems_[key]; - } else { - autoLock.unlock(); - result = onlineSyncTbl_->GetDeviceProfile(udid, key, value); - } - struct RadarInfo info = { - .funcName = "GetDeviceProfile", - .stageRes = (result == ERR_OK) ? - static_cast(StageRes::STAGE_SUCC) : static_cast(StageRes::STAGE_FAIL), - .toCallPkg = kvNAME, - .hostName = DpRadarHelper::GetInstance().GetHostNameByServiceId(serviceId), - .localUdid = localUdid_, - .errCode = ERR_DP_GET_DATA_FAILED, - }; - if (!DpRadarHelper::GetInstance().ReportGetData(info)) { - HILOGE("ReportGetData failed"); - } - profile.SetServiceId(serviceId); - profile.SetCharacteristicProfileJson(value); - return result; -} - -void DeviceProfileStorageManager::SetServiceType(const std::string& udid, - const std::string& serviceId, ServiceCharacteristicProfile& profile) -{ - std::unique_lock autoLock(serviceLock_); - if (udid.empty()) { - auto jsonData = servicesJson_[serviceId]; - if (jsonData != nullptr) { - profile.SetServiceType(jsonData[SERVICE_TYPE]); - } - return; - } - if (onlineSyncTbl_ == nullptr) { - HILOGE("onlineSyncTbl is nullptr"); - return; - } - std::string value; - std::string key = GenerateKey(udid, SERVICES, KeyType::SERVICE_LIST); - int32_t result = onlineSyncTbl_->GetDeviceProfile(key, value); - if (result != ERR_OK) { - HILOGE("get service type failed"); - return; - } - auto jsonData = nlohmann::json::parse(value, nullptr, false); - if (jsonData.is_discarded()) { - HILOGE("parse error"); - return; - } - auto typeData = jsonData[serviceId]; - if (typeData != nullptr && typeData[SERVICE_TYPE] != nullptr) { - profile.SetServiceType(typeData[SERVICE_TYPE]); - } -} - -int32_t DeviceProfileStorageManager::DeleteDeviceProfile(const std::string& serviceId) -{ - HITRACE_METER_NAME(HITRACE_TAG_DEVICE_PROFILE, DP_DEVICE_DELETE_TRACE); - if (onlineSyncTbl_ == nullptr) { - HILOGE("onlineSyncTbl_ is null"); - return ERR_DP_INVALID_PARAMS; - } - if (onlineSyncTbl_->GetInitStatus() == StorageInitStatus::INIT_FAILED) { - HILOGE("kvstore init failed"); - return ERR_DP_INIT_DB_FAILED; - } - std::unique_lock autoLock(serviceLock_); - if (servicesJson_[serviceId] == nullptr) { - HILOGW("can't find service %{public}s", serviceId.c_str()); - return ERR_DP_INVALID_PARAMS; - } - nlohmann::json original = servicesJson_[serviceId]; - servicesJson_.erase(serviceId); - std::string servicesKey = GenerateKey(localUdid_, SERVICES, KeyType::SERVICE_LIST); - std::string servicesValue = servicesJson_.dump(); - int32_t errCode = ERR_OK; - std::string serviceKey = GenerateKey(localUdid_, serviceId, KeyType::SERVICE); - struct RadarInfo info = { - .funcName = "DeleteDeviceProfile", - .toCallPkg = kvNAME, - .hostName = DpRadarHelper::GetInstance().GetHostNameByServiceId(serviceId), - .localUdid = localUdid_, - }; - if (onlineSyncTbl_ != nullptr && onlineSyncTbl_->GetInitStatus() == StorageInitStatus::INIT_SUCCEED) { - errCode = onlineSyncTbl_->DeleteDeviceProfile(serviceKey); - if (errCode != ERR_OK) { - servicesJson_[serviceId] = std::move(original); - return errCode; - } - errCode = onlineSyncTbl_->PutDeviceProfile(servicesKey, servicesValue); - info.stageRes = (errCode == ERR_OK) ? - static_cast(StageRes::STAGE_SUCC) : static_cast(StageRes::STAGE_FAIL); - info.errCode = ERR_DP_DELETE_DATA_FAILED; - if (errCode != ERR_OK) { - HILOGW("update services failed, errorCode = %{public}d", errCode); - } - } else { - info.stageRes = static_cast(StageRes::STAGE_SUCC); - profileItems_.erase(serviceKey); - profileItems_[servicesKey] = std::move(servicesValue); - } - if (!DpRadarHelper::GetInstance().ReportDeleteData(info)) { - HILOGE("ReportDeleteData failed"); - } - return errCode; -} - -int32_t DeviceProfileStorageManager::RemoveUnBoundDeviceProfile(const std::string& udid) -{ - if (onlineSyncTbl_ == nullptr || onlineSyncTbl_->GetInitStatus() == StorageInitStatus::INIT_FAILED) { - HILOGE("kvstore init failed"); - return ERR_DP_INIT_DB_FAILED; - } - - std::unique_lock autoLock(serviceLock_); - if (onlineSyncTbl_->GetInitStatus() != StorageInitStatus::INIT_SUCCEED) { - HILOGE("kvstore not init"); - return ERR_DP_NOT_INIT_DB; - } - - int32_t errCode = ERR_OK; - std::string networkId; - if (!DpDeviceManager::GetInstance().TransformDeviceId(udid, networkId, DeviceIdType::NETWORKID)) { - HILOGE("udid transform to networkid failed, udid = %{public}s", - DeviceProfileUtils::AnonymizeDeviceId(udid).c_str()); - return ERR_DP_GET_NETWORKID_FAILED; - } - - errCode = onlineSyncTbl_->RemoveDeviceData(networkId); - return errCode; -} - -int32_t DeviceProfileStorageManager::RemoveRemoteDeviceProfile() -{ - if (onlineSyncTbl_ == nullptr || onlineSyncTbl_->GetInitStatus() == StorageInitStatus::INIT_FAILED) { - HILOGE("kvstore init failed"); - return ERR_DP_INIT_DB_FAILED; - } - - if (onlineSyncTbl_->GetInitStatus() != StorageInitStatus::INIT_SUCCEED) { - HILOGE("kvstore not init"); - return ERR_DP_NOT_INIT_DB; - } - int errCode = onlineSyncTbl_->RemoveDeviceData(""); - return errCode; -} - -int32_t DeviceProfileStorageManager::SyncDeviceProfile(const SyncOptions& syncOptions, - const sptr& profileEventNotifier) -{ - if (onlineSyncTbl_ == nullptr || onlineSyncTbl_->GetInitStatus() == StorageInitStatus::INIT_FAILED) { - HILOGE("kvstore init failed"); - return ERR_DP_INIT_DB_FAILED; - } - if (!CheckSyncOption(syncOptions)) { - HILOGW("device list has offline device"); - return ERR_DP_INVALID_PARAMS; - } - int32_t result = NotifySyncStart(profileEventNotifier); - if (result != ERR_OK) { - return result; - } - StartAsyncTrace(HITRACE_TAG_DEVICE_PROFILE, DP_DEVICE_SYNC_TRACE, FIX_TASK_ID); - auto syncTask = [syncOptions, this]() { - HILOGI("start sync"); - ReportBehaviorEvent(DP_SYNC_EVENT); - auto devicesList = syncOptions.GetDeviceList(); - if (devicesList.empty()) { - DpDeviceManager::GetInstance().GetDeviceIdList(devicesList); - } - SyncCoordinator::GetInstance().SetSyncTrigger(false); - std::vector devicesVector(std::vector { devicesList.begin(), devicesList.end() }); - int32_t result = onlineSyncTbl_->SyncDeviceProfile(devicesVector, syncOptions.GetSyncMode()); - struct RadarInfo info = { - .stageRes = (result == ERR_OK) ? - static_cast(StageRes::STAGE_IDLE) : static_cast(StageRes::STAGE_FAIL), - .bizState = (result == ERR_OK) ? - static_cast(BizState::BIZ_STATE_START) : static_cast(BizState::BIZ_STATE_END), - .peerUdid = DpRadarHelper::GetInstance().GetStringUdidList(devicesList), - .errCode = ERR_DP_SYNC_DATA_FAILED, - }; - if (!DpRadarHelper::GetInstance().ReportSyncData(info)) { - HILOGE("ReportSyncData failed"); - } - if (result != ERR_OK) { - ReportFaultEvent(DP_SYNC_FAILED, FAULT_CODE_KEY, result); - HILOGE("sync failed result : %{public}d", result); - NotifySyncCompleted(); - return; - } - }; - if (!SyncCoordinator::GetInstance().DispatchSyncTask(syncTask)) { - HILOGE("post sync task failed"); - NotifySyncCompleted(); - return ERR_DP_POST_TASK_FAILED; - } - return ERR_OK; -} - -int32_t DeviceProfileStorageManager::NotifySyncStart(const sptr& profileEventNotifier) -{ - { - std::lock_guard autoLock(profileSyncLock_); - syncEventNotifier_ = profileEventNotifier; - } - - SubscribeInfo subscribeInfo; - subscribeInfo.profileEvent = ProfileEvent::EVENT_SYNC_COMPLETED; - std::list subscribeInfos; - subscribeInfos.emplace_back(subscribeInfo); - std::list failedEvents; - if (SubscribeManager::GetInstance().SubscribeProfileEvents( - subscribeInfos, profileEventNotifier, failedEvents) != ERR_OK) { - HILOGE("subscribe sync event failed"); - SyncCoordinator::GetInstance().ReleaseSync(); - std::lock_guard autoLock(profileSyncLock_); - syncEventNotifier_ = nullptr; - return ERR_DP_SUBSCRIBE_FAILED; - } - return ERR_OK; -} - -void DeviceProfileStorageManager::NotifySyncCompleted() -{ - HILOGI("called"); - SyncCoordinator::GetInstance().ReleaseSync(); - FinishAsyncTrace(HITRACE_TAG_DEVICE_PROFILE, DP_DEVICE_SYNC_TRACE, FIX_TASK_ID); - std::lock_guard autoLock(profileSyncLock_); - std::list profileEvents; - profileEvents.emplace_back(ProfileEvent::EVENT_SYNC_COMPLETED); - std::list failedEvents; - int32_t ret = SubscribeManager::GetInstance().UnsubscribeProfileEvents( - profileEvents, syncEventNotifier_, failedEvents); - if (ret != ERR_OK) { - HILOGW("unsubscribe sync event failed"); - } - syncEventNotifier_ = nullptr; -} - -void DeviceProfileStorageManager::NotifySubscriberDied(const sptr& profileEventNotifier) -{ - HILOGI("called"); - std::lock_guard autoLock(profileSyncLock_); - if (profileEventNotifier != syncEventNotifier_) { - return; - } - - SyncCoordinator::GetInstance().ReleaseSync(); - syncEventNotifier_ = nullptr; -} - -bool DeviceProfileStorageManager::CheckSyncOption(const SyncOptions& syncOptions) -{ - std::list> onlineDevices; - DpDeviceManager::GetInstance().GetDeviceList(onlineDevices); - std::list onlineDeviceIds; - for (const auto& onlineDevice : onlineDevices) { - if (onlineDevice != nullptr) { - onlineDeviceIds.emplace_back(onlineDevice->GetNetworkId()); - } - } - - // check whether deviceId is online - auto syncDeviceIds = syncOptions.GetDeviceList(); - for (const auto& syncDeviceId : syncDeviceIds) { - auto iter = find(onlineDeviceIds.begin(), onlineDeviceIds.end(), syncDeviceId); - if (iter == onlineDeviceIds.end()) { - HILOGE("deviceId: %{public}s is not online", DeviceProfileUtils::AnonymizeDeviceId(syncDeviceId).c_str()); - return false; - } - } - return true; -} - -void DeviceProfileStorageManager::RestoreServiceItemLocked(const std::string& value) -{ - auto restoreItems = nlohmann::json::parse(value, nullptr, false); - if (restoreItems.is_discarded()) { - HILOGE("parse error"); - return; - } - for (const auto& [key, value] : servicesJson_.items()) { - restoreItems[key] = value; - } - servicesJson_ = std::move(restoreItems); -} - -void DeviceProfileStorageManager::FlushProfileItems() -{ - std::string services; - std::string servicesKey = GenerateKey(localUdid_, SERVICES, KeyType::SERVICE_LIST); - if (onlineSyncTbl_ == nullptr) { - HILOGE("onlineSyncTbl is nullptr"); - return; - } - int32_t errCode = onlineSyncTbl_->GetDeviceProfile(servicesKey, services); - std::unique_lock autoLock(serviceLock_); - if (errCode == ERR_OK) { - RestoreServiceItemLocked(services); - } - - std::vector keys; - std::vector values; - size_t itemSize = profileItems_.size(); - HILOGI("profile item size = %{public}zu", itemSize); - if (itemSize == 0) { - return; - } - keys.reserve(itemSize); - values.reserve(itemSize); - // update service list to avoid overwriting the value in db storage - profileItems_[servicesKey] = servicesJson_.dump(); - for (const auto& [key, value] : profileItems_) { - keys.emplace_back(key); - values.emplace_back(value); - } - profileItems_.clear(); - autoLock.unlock(); - - errCode = onlineSyncTbl_->PutDeviceProfileBatch(keys, values); - if (errCode != ERR_OK) { - HILOGE("put failed, errCode = %{public}d", errCode); - } -} - -void DeviceProfileStorageManager::RegisterCallbacks() -{ - HILOGI("called"); - int32_t errCode = ERR_OK; - if (onlineSyncTbl_ != nullptr && kvStoreObserver_ != nullptr) { - errCode = onlineSyncTbl_->SubscribeKvStore(kvStoreObserver_); - HILOGI("SubscribeKvStore errCode = %{public}d", errCode); - } - if (onlineSyncTbl_ != nullptr && kvStoreSyncCallback_ != nullptr) { - errCode = onlineSyncTbl_->RegisterSyncCallback(kvStoreSyncCallback_); - HILOGI("RegisterSyncCallback errCode = %{public}d", errCode); - } -} - -void DeviceProfileStorageManager::OnKvStoreInitDone() -{ - RegisterCallbacks(); - FlushProfileItems(); -} - -int32_t DeviceProfileStorageManager::SubscribeKvStore(const std::shared_ptr& observer) -{ - std::lock_guard autoLock(callbackLock_); - kvStoreObserver_ = observer; - if (onlineSyncTbl_ != nullptr && onlineSyncTbl_->GetInitStatus() == StorageInitStatus::INIT_SUCCEED) { - return onlineSyncTbl_->SubscribeKvStore(observer); - } - return ERR_OK; -} - -int32_t DeviceProfileStorageManager::UnSubscribeKvStore(const std::shared_ptr& observer) -{ - std::lock_guard autoLock(callbackLock_); - kvStoreObserver_ = nullptr; - if (onlineSyncTbl_ == nullptr) { - HILOGE("onlineSyncTbl is nullptr"); - return ERR_DP_INVALID_PARAMS; - } - return onlineSyncTbl_->UnSubscribeKvStore(observer); -} - -int32_t DeviceProfileStorageManager::RegisterSyncCallback(const std::shared_ptr& sycnCb) -{ - std::lock_guard autoLock(callbackLock_); - kvStoreSyncCallback_ = sycnCb; - if (onlineSyncTbl_ != nullptr && onlineSyncTbl_->GetInitStatus() == StorageInitStatus::INIT_SUCCEED) { - return onlineSyncTbl_->RegisterSyncCallback(sycnCb); - } - return ERR_OK; -} - -int32_t DeviceProfileStorageManager::UnRegisterSyncCallback() -{ - std::lock_guard autoLock(callbackLock_); - kvStoreSyncCallback_ = nullptr; - if (onlineSyncTbl_ == nullptr) { - HILOGE("onlineSyncTbl is nullptr"); - return ERR_DP_INVALID_PARAMS; - } - return onlineSyncTbl_->UnRegisterSyncCallback(); -} - -void DeviceProfileStorageManager::ReportBehaviorEvent(const std::string& event) -{ - int ret = HiSysEventWrite(HiSysEvent::Domain::DEVICE_PROFILE, event, HiSysEvent::EventType::BEHAVIOR); - if (ret != 0) { - HILOGE("hisysevent write failed! ret %{public}d.", ret); - } -} - -void DeviceProfileStorageManager::ReportFaultEvent(const std::string& event, - const std::string& key, const int32_t result) -{ - int ret = HiSysEventWrite(HiSysEvent::Domain::DEVICE_PROFILE, event, HiSysEvent::EventType::FAULT, key, result); - if (ret != 0) { - HILOGE("hisysevent write failed! ret %{public}d.", ret); - } -} - -void DeviceProfileStorageManager::DumpLocalProfile(std::string& result) -{ - for (const auto& [key, value] : servicesJson_.items()) { - result.append("key:"); - result.append(key); - result.append(" value:"); - result.append(value.dump()); - result.append("\n"); - } -} -} // namespace DeviceProfile -} // namespace OHOS diff --git a/old/services/core/src/dbstorage/kvstore_death_recipient_dp.cpp b/old/services/core/src/dbstorage/kvstore_death_recipient_dp.cpp deleted file mode 100644 index c544d204..00000000 --- a/old/services/core/src/dbstorage/kvstore_death_recipient_dp.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. - * 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. - */ - -#include "kvstore_death_recipient_dp.h" - -#include "device_profile_log.h" -#include "device_profile_storage_manager.h" - -namespace OHOS { -namespace DeviceProfile { -namespace { -const std::string TAG = "KvStoreDeathRecipientDp"; -} - -void KvStoreDeathRecipientDp::OnRemoteDied(const wptr& remote) -{ - HILOGI("called"); - DeviceProfileStorageManager::GetInstance().Init(); -} -} // namespace DeviceProfile -} // namespace OHOS \ No newline at end of file diff --git a/old/services/core/src/dbstorage/online_sync_table.cpp b/old/services/core/src/dbstorage/online_sync_table.cpp deleted file mode 100644 index 4d2a9bc2..00000000 --- a/old/services/core/src/dbstorage/online_sync_table.cpp +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. - * 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. - */ - -#include "online_sync_table.h" - -#include "device_profile_errors.h" -#include "device_profile_log.h" -#include "device_profile_utils.h" -#include "dp_device_manager.h" -#include "sync_coordinator.h" - -namespace OHOS { -namespace DeviceProfile { -using namespace OHOS::DistributedKv; - -namespace { -const std::string TAG = "OnlineSyncTable"; - -const std::string APP_ID = "distributed_device_profile_service"; -const std::string STORE_ID = "online_sync_storage"; -constexpr int32_t MAX_RETRY_SYNC_TIMES = 30; -constexpr int32_t INTERVAL_RETRY_SYNC_MS = 100; -} - -OnlineSyncTable::OnlineSyncTable() : DeviceProfileStorage(APP_ID, STORE_ID) -{ -} - -void OnlineSyncTable::Init() -{ - HILOGD("called"); - Options options = { - .createIfMissing = true, - .encrypt = true, - .autoSync = true, - .securityLevel = DistributedKv::SecurityLevel::S1, - .area = 1, - .kvStoreType = KvStoreType::SINGLE_VERSION, - .baseDir = "/data/service/el1/public/database/distributed_device_profile_service" - }; - // clean the IMMEDIATE_SYNC_ON_CHANGE - SyncPolicy syncPolicyOnline { - .type = PolicyType::IMMEDIATE_SYNC_ON_ONLINE - }; - options.policies.emplace_back(syncPolicyOnline); - SetOptions(options); - DeviceProfileStorage::Init(); - int32_t errCode = DeviceProfileStorage::RegisterSyncCallback(shared_from_this()); - if (errCode != ERR_OK) { - HILOGE("register sync callback failed, errCode = %{public}d", errCode); - } -} - -int32_t OnlineSyncTable::RegisterSyncCallback(const std::shared_ptr& syncCb) -{ - HILOGI("called"); - if (syncCb == nullptr) { - HILOGE("syncCb is nullptr!"); - return ERR_DP_INVALID_PARAMS; - } - std::lock_guard autoLock(tableLock_); - syncCallback_ = syncCb; - HILOGI("RegisterSyncCallback success!"); - return ERR_OK; -} - -int32_t OnlineSyncTable::UnRegisterSyncCallback() -{ - HILOGI("called"); - std::lock_guard autoLock(tableLock_); - syncCallback_ = nullptr; - return ERR_OK; -} - -int32_t OnlineSyncTable::SyncDeviceProfile(const std::vector& deviceIds, - SyncMode syncMode) -{ - HILOGI("called"); - auto syncTask = [this, deviceIds = std::move(deviceIds), syncMode]() { - HILOGI("start sync task"); - retrySyncTimes_ = 0; - int32_t errCode = DeviceProfileStorage::SyncDeviceProfile(deviceIds, syncMode); - if (errCode != ERR_OK) { - SyncCoordinator::GetInstance().ReleaseSync(); - HILOGE("sync errCode = %{public}d", errCode); - } - }; - if (!SyncCoordinator::GetInstance().DispatchSyncTask(syncTask)) { - HILOGE("post online sync task failed"); - return ERR_DP_POST_TASK_FAILED; - } - return ERR_OK; -} - -void OnlineSyncTable::SyncCompleted(const std::map& results) -{ - if (!SyncCoordinator::GetInstance().IsOnlineSync()) { - HILOGI("manual sync callback"); - NotifySyncCompleted(results); - return; - } - - HILOGI("online sync callback"); - std::vector failedDeviceIds; - for (const auto& [deviceId, result] : results) { - HILOGI("deviceId = %{public}s, result = %{public}d", - DeviceProfileUtils::AnonymizeDeviceId(deviceId).c_str(), result); - if (result != Status::SUCCESS) { - std::string networkId; - if (!DpDeviceManager::GetInstance().TransformDeviceId(deviceId, networkId, - DeviceIdType::NETWORKID)) { - HILOGE("transform to networkid failed"); - continue; - } - failedDeviceIds.emplace_back(std::move(networkId)); - } - } - - HILOGI("retry times = %{public}d", retrySyncTimes_.load()); - if ((retrySyncTimes_++ < MAX_RETRY_SYNC_TIMES) && !failedDeviceIds.empty()) { - auto retrySyncTask = [this, deviceIds = std::move(failedDeviceIds)]() { - HILOGI("retrying sync..."); - DeviceProfileStorage::SyncDeviceProfile(deviceIds, SyncMode::PUSH); - }; - if (SyncCoordinator::GetInstance().DispatchSyncTask(retrySyncTask, - INTERVAL_RETRY_SYNC_MS)) { - return; - } else { - HILOGE("post online sync retry task failed"); - } - } - // notify and release when there is no retry - NotifySyncCompleted(results); - SyncCoordinator::GetInstance().ReleaseSync(); -} - -void OnlineSyncTable::NotifySyncCompleted(const std::map& results) -{ - HILOGI("called, syncResult size %{public}zu!", results.size()); - for (const auto& item : results) { - HILOGI("SyncResult networkId %{public}s result %{public}d", - DeviceProfileUtils::AnonymizeDeviceId(item.first).c_str(), static_cast(item.second)); - } - std::lock_guard autoLock(tableLock_); - if (syncCallback_ != nullptr) { - HILOGI("notify sync callback"); - syncCallback_->SyncCompleted(results); - } - HILOGI("NotifySyncCompleted end!"); -} -} // namespace DeviceProfile -} // namespace OHOS diff --git a/old/services/core/src/dbstorage/sync_coordinator.cpp b/old/services/core/src/dbstorage/sync_coordinator.cpp deleted file mode 100644 index 5fe340d2..00000000 --- a/old/services/core/src/dbstorage/sync_coordinator.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. - * 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. - */ - -#include "sync_coordinator.h" - -#include - -#include "device_profile_log.h" - -namespace OHOS { -namespace DeviceProfile { -namespace { -const std::string TAG = "SyncCoordinator"; -} - -IMPLEMENT_SINGLE_INSTANCE(SyncCoordinator); - -bool SyncCoordinator::Init() -{ - auto runner = AppExecFwk::EventRunner::Create("syncHandler"); - syncHandler_ = std::make_shared(runner); - if (syncHandler_ == nullptr) { - return false; - } - return true; -} - -bool SyncCoordinator::AcquireSync() -{ - if (isOnSync_) { - HILOGI("acquire from %{public}s", isOnlineTrigger_ ? "online" : "manual"); - return false; - } - isOnSync_ = true; - return true; -} - -void SyncCoordinator::ReleaseSync() -{ - isOnSync_ = false; -} - -bool SyncCoordinator::IsOnSync() -{ - HILOGI("isOnSync_ %{public}s", std::to_string(isOnSync_).c_str()); - return isOnSync_; -} - -void SyncCoordinator::SetSyncTrigger(bool isOnlineTrigger) -{ - isOnlineTrigger_ = isOnlineTrigger; -} - -bool SyncCoordinator::IsOnlineSync() -{ - return isOnlineTrigger_; -} - -bool SyncCoordinator::DispatchSyncTask(const SyncTask& syncTask, int64_t delayTime) -{ - if (syncHandler_ == nullptr || !syncHandler_->PostTask(syncTask, delayTime)) { - HILOGE("post task failed"); - isOnSync_ = false; - return false; - } - return true; -} -} // namespace DeviceProfile -} // namespace OHOS diff --git a/old/services/core/src/devicemanager/device_info.cpp b/old/services/core/src/devicemanager/device_info.cpp deleted file mode 100644 index a1feea88..00000000 --- a/old/services/core/src/devicemanager/device_info.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ - -#include "device_info.h" - -namespace OHOS { -namespace DeviceProfile { -const std::string& DeviceInfo::GetDeviceName() const -{ - return deviceName_; -} - -const std::string& DeviceInfo::GetNetworkId() const -{ - return networkId_; -} - -int32_t DeviceInfo::GetDeviceType() const -{ - return deviceType_; -} -} // namespace DeviceProfile -} // namespace OHOS \ No newline at end of file diff --git a/old/services/core/src/devicemanager/dp_device_manager.cpp b/old/services/core/src/devicemanager/dp_device_manager.cpp deleted file mode 100644 index 440b4005..00000000 --- a/old/services/core/src/devicemanager/dp_device_manager.cpp +++ /dev/null @@ -1,448 +0,0 @@ -/* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. - * 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. - */ - -#include "dp_device_manager.h" - -#include -#include - -#include - -#include "parameter.h" - -#include "device_profile_log.h" -#include "device_profile_manager.h" -#include "device_profile_utils.h" -#include "distributed_device_profile_service.h" -#include "dm_constants.h" -#include "event_handler_factory.h" -#include "ipc_object_proxy.h" -#include "ipc_skeleton.h" -#include "iservice_registry.h" -#include "system_ability_definition.h" - -namespace OHOS { -namespace DeviceProfile { -using namespace std::chrono_literals; -using namespace DistributedHardware; - -namespace { -const std::string TAG = "DpDeviceManager"; - -constexpr int32_t RETRY_TIMES = 30; -constexpr uint8_t MAX_DEVICE_TYPE = 3; -constexpr int32_t DEVICE_ID_SIZE = 65; -constexpr int32_t MAX_TIMES_CONNECT_DEVICEMANAGER = 10; -const std::string PKG_NAME = "ohos.deviceprofile"; -} - -IMPLEMENT_SINGLE_INSTANCE(DpDeviceManager); - -std::shared_ptr DpDeviceManager::GetInitCallback() -{ - std::lock_guard autoLock(initcallbackLock_); - if (initCallback_ == nullptr) { - initCallback_ = std::make_shared(); - } - return initCallback_; -} - -std::shared_ptr DpDeviceManager::GetStateCallback() -{ - std::lock_guard autoLock(stateCallLock_); - if (stateCallback_ == nullptr) { - stateCallback_ = std::make_shared(); - } - return stateCallback_; -} - -void DpDeviceManager::GetDevMgrHandler() -{ - std::lock_guard autoLock(devMgrLock_); - if (devMgrHandler_ == nullptr) { - devMgrHandler_ = DistributedDeviceProfile::EventHandlerFactory::GetInstance().GetEventHandler(); - } -} - -bool DpDeviceManager::Init() -{ - GetInitCallback(); - GetStateCallback(); - GetDevMgrHandler(); - { - std::lock_guard autoLock(devMgrLock_); - if (devMgrHandler_ == nullptr) { - return false; - } - } - if (!ConnectDeviceManager()) { - return false; - } - return true; -} - -void DpDeviceManager::DeviceInitCallBack::OnRemoteDied() -{ - HILOGI("DeviceInitCallBack OnRemoteDied"); - DpDeviceManager::GetInstance().Init(); -} - -void DpDeviceManager::GetTrustedDeviceList() -{ - std::vector deviceList; - int32_t ret = DeviceManager::GetInstance().GetTrustedDeviceList(PKG_NAME, "", deviceList); - if (ret != ERR_OK) { - HILOGE("GetTrustedDeviceList Failed!"); - return; - } - if (deviceList.empty()) { - HILOGI("deviceList is empty!"); - return; - } - for (const DmDeviceInfo& dmDeviceInfo : deviceList) { - auto dpDeviceInfo = std::make_shared( - dmDeviceInfo.deviceName, dmDeviceInfo.networkId, dmDeviceInfo.deviceTypeId); - DpDeviceManager::GetInstance().OnNodeOnline(dpDeviceInfo); - } - DistributedDeviceProfileService::GetInstance().DeviceOnline(); -} - -void DpDeviceManager::DpDeviceStateCallback::OnDeviceOnline(const DmDeviceInfo &deviceInfo) -{ - HILOGI("online called"); - auto dpDeviceInfo = std::make_shared( - deviceInfo.deviceName, deviceInfo.networkId, deviceInfo.deviceTypeId); - DpDeviceManager::GetInstance().OnNodeOnline(dpDeviceInfo); - DistributedDeviceProfileService::GetInstance().DeviceOnline(); -} - -void DpDeviceManager::DpDeviceStateCallback::OnDeviceOffline(const DmDeviceInfo &deviceInfo) -{ - HILOGI("offline called"); - std::string networkId = deviceInfo.networkId; - DpDeviceManager::GetInstance().OnNodeOffline(networkId); -} - -void DpDeviceManager::DpDeviceStateCallback::OnDeviceChanged(const DmDeviceInfo &deviceInfo) -{ - HILOGD("called"); -} - -void DpDeviceManager::DpDeviceStateCallback::OnDeviceReady(const DmDeviceInfo &deviceInfo) -{ - HILOGD("called"); -} - -void DpDeviceManager::OnNodeOnline(const std::shared_ptr deviceInfo) -{ - if (deviceInfo == nullptr) { - HILOGE("deviceInfo is nullptr"); - return; - } - auto onlineNotifyTask = [this, deviceInfo = deviceInfo]() { - HILOGI("online networkId = %{public}s", - DeviceProfileUtils::AnonymizeDeviceId(deviceInfo->GetNetworkId()).c_str()); - RemoveExpiredDeviceIds(deviceInfo->GetNetworkId()); - AddDeviceIds(deviceInfo->GetNetworkId()); - { - std::string networkId = deviceInfo->GetNetworkId(); - std::lock_guard autoLock(deviceLock_); - remoteDeviceInfoMap_[networkId] = deviceInfo; - } - }; - std::lock_guard autoLock(devMgrLock_); - if (devMgrHandler_ == nullptr) { - HILOGE("devMgrHandler is nullptr"); - return; - } - if (!devMgrHandler_->PostTask(onlineNotifyTask)) { - HILOGE("post task failed"); - return; - } -} - -void DpDeviceManager::OnNodeOffline(const std::string& networkId) -{ - auto offlineNotifyTask = [this, networkId = std::move(networkId)]() { - HILOGI("offline networkId = %{public}s", DeviceProfileUtils::AnonymizeDeviceId(networkId).c_str()); - std::lock_guard autoLock(deviceLock_); - remoteDeviceInfoMap_.erase(networkId); - }; - std::lock_guard autoLock(devMgrLock_); - if (devMgrHandler_ == nullptr) { - HILOGE("devMgrHandler is nullptr"); - return; - } - if (!devMgrHandler_->PostTask(offlineNotifyTask)) { - HILOGE("post task failed"); - return; - } -} - -bool DpDeviceManager::WaitForDnetworkReady() -{ - auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (samgr == nullptr) { - HILOGE("WaitForDnetworkReady failed to get samgr!"); - return false; - } - int32_t retryTimeout = RETRY_TIMES; - do { - auto dnetworkDm = samgr->CheckSystemAbility(DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID); - auto dnetworkSoftBus = samgr->CheckSystemAbility(SOFTBUS_SERVER_SA_ID); - if (dnetworkDm != nullptr && dnetworkSoftBus != nullptr) { - IPCObjectProxy* dmProxy = reinterpret_cast(dnetworkDm.GetRefPtr()); - IPCObjectProxy* sbProxy = reinterpret_cast(dnetworkSoftBus.GetRefPtr()); - // make sure the proxy is not dead - if (dmProxy != nullptr && !dmProxy->IsObjectDead() && sbProxy != nullptr && !sbProxy->IsObjectDead()) { - return true; - } - } - HILOGI("Waiting for dnentwork service..."); - std::this_thread::sleep_for(1s); - if (--retryTimeout <= 0) { - HILOGI("Waiting for dnentwork service timeout(30)s"); - return false; - } - } while (true); - return false; -} - -bool DpDeviceManager::ConnectDeviceManager() -{ - HILOGI("ConnectDeviceManager"); - bool isReady = WaitForDnetworkReady(); - if (!isReady) { - HILOGE("ConnectDeviceManager wait Dnetwork failed!"); - return false; - } - - auto registerTask = [this]() { - HILOGD("register task..."); - int32_t retryTimes = 0; - int32_t errCode = ERR_OK; - while (retryTimes++ < MAX_TIMES_CONNECT_DEVICEMANAGER) { - int32_t ret = DeviceManager::GetInstance().InitDeviceManager(PKG_NAME, GetInitCallback()); - if (ret != 0) { - HILOGE("init device manager failed, ret:%{public}d", ret); - std::this_thread::sleep_for(1s); - continue; - } - errCode = DeviceManager::GetInstance().RegisterDevStateCallback( - PKG_NAME, "", GetStateCallback()); - if (errCode == ERR_OK) { - DpDeviceManager::GetInstance().GetTrustedDeviceList(); - break; - } - HILOGE("register errCode = %{public}d, retrying...", errCode); - - errCode = DeviceManager::GetInstance().UnRegisterDevStateCallback(PKG_NAME); - HILOGI("unregister errCode = %{public}d", errCode); - std::this_thread::sleep_for(1s); - } - - if (errCode == ERR_OK) { - AddLocalDeviceIds(); - RecoverDevicesIfNeeded(); - } - HILOGI("register %{public}s", (errCode == ERR_OK) ? "success" : "timeout"); - }; - std::lock_guard autoLock(devMgrLock_); - if (devMgrHandler_ == nullptr) { - HILOGE("devMgrHandler is nullptr"); - return false; - } - if (!devMgrHandler_->PostTask(registerTask)) { - HILOGE("post task failed"); - return false; - } - return true; -} - -void DpDeviceManager::RecoverDevicesIfNeeded() -{ - HILOGI("called"); - std::vector deviceList; - if (DeviceManager::GetInstance().GetTrustedDeviceList(PKG_NAME, "", deviceList) != ERR_OK) { - HILOGE("get all node info failed"); - return; - } - for (DmDeviceInfo dmDeviceInfo : deviceList) { - std::string networkId = dmDeviceInfo.networkId; - HILOGI("deviceId %{public}s found", DeviceProfileUtils::AnonymizeDeviceId(networkId).c_str()); - AddDeviceIds(networkId); - { - auto deviceInfo = std::make_shared( - dmDeviceInfo.deviceName, dmDeviceInfo.networkId, dmDeviceInfo.deviceTypeId); - std::lock_guard autoLock(deviceLock_); - remoteDeviceInfoMap_.emplace(std::move(networkId), deviceInfo); - } - } -} - -void DpDeviceManager::AddLocalDeviceIds() -{ - HILOGI("called"); - DmDeviceInfo dmInfo; - int32_t errCode = DeviceManager::GetInstance().GetLocalDeviceInfo(PKG_NAME, dmInfo); - if (errCode != ERR_OK) { - HILOGW("errCode = %{public}d", errCode); - std::string udid; - GetLocalDeviceUdid(udid); - std::vector deviceIds = {"", std::move(udid), ""}; - std::lock_guard autoLock(deviceLock_); - deviceIdsList_.emplace_back(std::move(deviceIds)); - } else { - AddDeviceIds(dmInfo.networkId); - } -} - -void DpDeviceManager::AddDeviceIds(const std::string& networkId) -{ - HILOGI("called"); - std::string udid; - if (GetUdidByNetworkId(networkId, udid)) { - HILOGI("udid %{public}s", DeviceProfileUtils::AnonymizeDeviceId(udid).c_str()); - } - std::string uuid; - if (GetUuidByNetworkId(networkId, uuid)) { - HILOGI("uuid %{public}s", DeviceProfileUtils::AnonymizeDeviceId(uuid).c_str()); - } - std::vector deviceIds = {networkId, std::move(udid), std::move(uuid)}; - std::lock_guard autoLock(deviceLock_); - deviceIdsList_.emplace_back(std::move(deviceIds)); -} - -void DpDeviceManager::RemoveExpiredDeviceIds(const std::string& networkId) -{ - HILOGI("called"); - std::string udid; - if (!GetUdidByNetworkId(networkId, udid)) { - return; - } - if (udid.empty()) { - return; - } - RemoveDeviceIdsByUdid(udid); -} - -void DpDeviceManager::RemoveDeviceIds(const std::string& networkId) -{ - HILOGI("called"); - std::lock_guard autoLock(deviceLock_); - auto iter = std::find_if(deviceIdsList_.begin(), deviceIdsList_.end(), [&networkId](const auto& deviceIds) { - return deviceIds[static_cast(DeviceIdType::NETWORKID)] == networkId; - }); - if (iter != deviceIdsList_.end()) { - deviceIdsList_.erase(iter); - } - return; -} - -void DpDeviceManager::RemoveDeviceIdsByUdid(const std::string& udid) -{ - HILOGI("called"); - std::lock_guard autoLock(deviceLock_); - auto iter = std::find_if(deviceIdsList_.begin(), deviceIdsList_.end(), [&udid](const auto& deviceIds) { - return deviceIds[static_cast(DeviceIdType::UDID)] == udid; - }); - if (iter != deviceIdsList_.end()) { - deviceIdsList_.erase(iter); - HILOGI("remove device udid %{public}s", DeviceProfileUtils::AnonymizeDeviceId(udid).c_str()); - } - return; -} - -bool DpDeviceManager::DisconnectDeviceManager() -{ - int32_t errCode = DeviceManager::GetInstance().UnRegisterDevStateCallback(PKG_NAME); - if (errCode != ERR_OK) { - HILOGE("remove failed, errCode = %{public}d", errCode); - return false; - } - return true; -} - -void DpDeviceManager::GetLocalDeviceUdid(std::string& udid) -{ - char localDeviceId[DEVICE_ID_SIZE] = {0}; - GetDevUdid(localDeviceId, DEVICE_ID_SIZE); - udid = localDeviceId; -} - -bool DpDeviceManager::GetUdidByNetworkId(const std::string& networkId, std::string& udid) -{ - return ((DeviceManager::GetInstance().GetUdidByNetworkId( - PKG_NAME, networkId, udid) == 0) ? true : false); -} - -bool DpDeviceManager::GetUuidByNetworkId(const std::string& networkId, std::string& uuid) -{ - return ((DeviceManager::GetInstance().GetUuidByNetworkId( - PKG_NAME, networkId, uuid) == 0) ? true : false); -} - -bool DpDeviceManager::TransformDeviceId(const std::string& fromDeviceId, - std::string& toDeviceId, DeviceIdType toType) -{ - if (fromDeviceId.empty()) { - HILOGW("empty device id"); - return false; - } - - uint8_t idx = static_cast(toType); - if (idx > MAX_DEVICE_TYPE - 1) { - return false; - } - - toDeviceId = ""; - std::lock_guard autoLock(deviceLock_); - for (const auto& deviceIds : deviceIdsList_) { - auto iter = std::find(deviceIds.begin(), deviceIds.end(), fromDeviceId); - if (iter != deviceIds.end()) { - toDeviceId = deviceIds[idx]; - return !toDeviceId.empty(); - } - } - return false; -} - -void DpDeviceManager::GetDeviceIdList(std::list& deviceIdList) -{ - deviceIdList.clear(); - std::lock_guard autoLock(deviceLock_); - for (const auto& [_, deviceInfo] : remoteDeviceInfoMap_) { - if (deviceInfo == nullptr) { - HILOGW("deviceInfo is nullptr"); - continue; - } - deviceIdList.emplace_back(deviceInfo->GetNetworkId()); - } -} - -void DpDeviceManager::GetDeviceList(std::list>& deviceList) -{ - deviceList.clear(); - std::lock_guard autoLock(deviceLock_); - for (const auto& [_, deviceInfo] : remoteDeviceInfoMap_) { - if (deviceInfo == nullptr) { - HILOGW("deviceInfo is nullptr"); - continue; - } - deviceList.emplace_back(deviceInfo); - } -} -} // namespace DeviceProfile -} // namespace OHOS diff --git a/old/services/core/src/dfx/device_profile_dumper.cpp b/old/services/core/src/dfx/device_profile_dumper.cpp deleted file mode 100644 index a9895c00..00000000 --- a/old/services/core/src/dfx/device_profile_dumper.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * 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. - */ - -#include "device_profile_dumper.h" - -#include "device_profile_log.h" -#include "device_profile_storage_manager.h" -#include "ipc_skeleton.h" - -namespace OHOS { -namespace DeviceProfile { -namespace { -constexpr size_t MIN_ARGS_SIZE = 1; -const std::string ARGS_HELP = "-h"; -const std::string TAG = "DeviceProfileDumper"; -constexpr int32_t UID_HIDUMPER = 1212; -} - -bool DeviceProfileDumper::DumpDefault(std::string& result) -{ - result.append("DeviceProfile Dump:\n"); - DeviceProfileStorageManager::GetInstance().DumpLocalProfile(result); - return true; -} - -bool DeviceProfileDumper::Dump(const std::vector& args, std::string& result) -{ - result.clear(); - if (!CanDump()) { - result.append("Dump failed, not allowed"); - return false; - } - - if (args.size() < MIN_ARGS_SIZE) { - return DumpDefault(result); - } - - if (args.size() == MIN_ARGS_SIZE) { - // -h - if (args[0] == ARGS_HELP) { - ShowHelp(result); - return true; - } - } - IllegalInput(result); - return false; -} - -void DeviceProfileDumper::ShowHelp(std::string& result) -{ - result.append("DeviceProfile Dump options:\n") - .append(" [-h] [cmd]...\n"); -} - -void DeviceProfileDumper::IllegalInput(std::string& result) -{ - result.append("The arguments are illegal and you can enter '-h' for help.\n"); -} - -bool DeviceProfileDumper::CanDump() -{ - auto callingUid = IPCSkeleton::GetCallingUid(); - HILOGI("calling uid = %{public}u", callingUid); - if (callingUid != UID_HIDUMPER) { - return false; - } - return true; -} -} // namespace DeviceProfile -} // namespace OHOS diff --git a/old/services/core/src/distributed_device_profile_service.cpp b/old/services/core/src/distributed_device_profile_service.cpp deleted file mode 100644 index 73e3ccaa..00000000 --- a/old/services/core/src/distributed_device_profile_service.cpp +++ /dev/null @@ -1,332 +0,0 @@ -/* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. - * 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. - */ - -#include "distributed_device_profile_service.h" - -#include "file_ex.h" -#include "string_ex.h" - -#include "authority_manager.h" -#include "content_sensor_manager.h" -#include "device_profile_dumper.h" -#include "device_profile_errors.h" -#include "device_profile_log.h" -#include "device_profile_storage_manager.h" -#include "distributed_device_profile_service_new.h" -#include "dp_device_manager.h" -#include "dp_radar_helper.h" -#include "event_handler_factory.h" -#include "hitrace_meter.h" -#include "if_system_ability_manager.h" -#include "ipc_object_proxy.h" -#include "ipc_skeleton.h" -#include "iprofile_event_notifier.h" -#include "iservice_registry.h" -#include "profile_cache.h" -#include "sa_profiles.h" -#include "service_characteristic_profile.h" -#include "sync_coordinator.h" -#include "subscribe_manager.h" -#include "trust_group_manager.h" - -namespace OHOS { -namespace DeviceProfile { -namespace { -const std::string TAG = "DistributedDeviceProfileService"; -const std::string DP_DEVICE_SUB_TRACE = "DP_DEVICE_SUB"; -const std::string TASK_ID = "unload"; -const std::string BOOT_COMPLETED_EVENT = "usual.event.BOOT_COMPLETED"; -const std::string STRING_DEVICE_ONLINE = "deviceonline"; -const std::string EVENT_ID = "eventId"; -const std::string NAME = "name"; -const std::string INIT_TASK_ID = "CheckAndInitDP"; -constexpr int32_t DELAY_TIME = 180000; -constexpr int32_t UNLOAD_IMMEDIATELY = 0; -constexpr int32_t DP_IPC_THREAD_NUM = 32; -} - -IMPLEMENT_SINGLE_INSTANCE(DistributedDeviceProfileService); -const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(&DistributedDeviceProfileService::GetInstance()); - -DistributedDeviceProfileService::DistributedDeviceProfileService() - : SystemAbility(DISTRIBUTED_DEVICE_PROFILE_SA_ID, true) -{ -} - -bool DistributedDeviceProfileService::Init() -{ - HILOGI("init DistributedDeviceProfileServiceNew"); - DistributedDeviceProfile::DistributedDeviceProfileServiceNew::GetInstance().Init(); - { - std::lock_guard lock(unloadMutex_); - if (unloadHandler_ == nullptr) { - unloadHandler_ = DistributedDeviceProfile::EventHandlerFactory::GetInstance().GetEventHandler(); - } - if (unloadHandler_ == nullptr) { - return false; - } - } - HILOGI("init succeeded"); - return true; -} - -int32_t DistributedDeviceProfileService::PutDeviceProfile(const ServiceCharacteristicProfile& profile) -{ - bool ret = AuthorityManager::GetInstance().CheckServiceAuthority(AuthValue::AUTH_W, - profile.GetServiceId()); - struct RadarInfo info = { - .funcName = "PutDeviceProfile", - .stageRes = ret ? - static_cast(StageRes::STAGE_SUCC) : static_cast(StageRes::STAGE_FAIL), - .bizState = static_cast(BizState::BIZ_STATE_END), - .errCode = ERR_DP_PERMISSION_DENIED, - }; - if (!DpRadarHelper::GetInstance().ReportSaCheckAuth(info)) { - HILOGE("ReportSaCheckAuth failed"); - } - if (!ret) { - return ERR_DP_PERMISSION_DENIED; - } - return DeviceProfileStorageManager::GetInstance().PutDeviceProfile(profile); -} - -void DistributedDeviceProfileService::DeviceOnline() -{ - HILOGI("device online begin"); - isOnline_ = true; - { - std::lock_guard lock(unloadMutex_); - if (unloadHandler_ == nullptr) { - return; - } - unloadHandler_->RemoveTask(TASK_ID); - } -} - -int32_t DistributedDeviceProfileService::GetDeviceProfile(const std::string& udid, const std::string& serviceId, - ServiceCharacteristicProfile& profile) -{ - bool ret = AuthorityManager::GetInstance().CheckServiceAuthority(AuthValue::AUTH_R, - serviceId); - struct RadarInfo info = { - .funcName = "GetDeviceProfile", - .stageRes = ret ? - static_cast(StageRes::STAGE_SUCC) : static_cast(StageRes::STAGE_FAIL), - .bizState = static_cast(BizState::BIZ_STATE_END), - .errCode = ERR_DP_PERMISSION_DENIED, - }; - if (!DpRadarHelper::GetInstance().ReportSaCheckAuth(info)) { - HILOGE("ReportSaCheckAuth failed"); - } - if (!ret) { - return ERR_DP_PERMISSION_DENIED; - } - return DeviceProfileStorageManager::GetInstance().GetDeviceProfile(udid, serviceId, profile); -} - -int32_t DistributedDeviceProfileService::DeleteDeviceProfile(const std::string& serviceId) -{ - bool ret = AuthorityManager::GetInstance().CheckServiceAuthority(AuthValue::AUTH_W, - serviceId); - struct RadarInfo info = { - .funcName = "DeleteDeviceProfile", - .stageRes = ret ? - static_cast(StageRes::STAGE_SUCC) : static_cast(StageRes::STAGE_FAIL), - .bizState = static_cast(BizState::BIZ_STATE_END), - .errCode = ERR_DP_PERMISSION_DENIED, - }; - if (!DpRadarHelper::GetInstance().ReportSaCheckAuth(info)) { - HILOGE("ReportSaCheckAuth failed"); - } - if (!ret) { - return ERR_DP_PERMISSION_DENIED; - } - return DeviceProfileStorageManager::GetInstance().DeleteDeviceProfile(serviceId); -} - -int32_t DistributedDeviceProfileService::SubscribeProfileEvents(const std::list& subscribeInfos, - const sptr& profileEventNotifier, - std::list& failedEvents) -{ - HITRACE_METER_NAME(HITRACE_TAG_DEVICE_PROFILE, DP_DEVICE_SUB_TRACE); - struct RadarInfo info = { - .funcName = "SubscribeProfileEvents", - .stageRes = static_cast(StageRes::STAGE_SUCC), - .bizState = static_cast(BizState::BIZ_STATE_END), - }; - if (!DpRadarHelper::GetInstance().ReportSaCheckAuth(info)) { - HILOGE("ReportSaCheckAuth failed"); - } - return SubscribeManager::GetInstance().SubscribeProfileEvents(subscribeInfos, - profileEventNotifier, failedEvents); -} - -int32_t DistributedDeviceProfileService::UnsubscribeProfileEvents(const std::list& profileEvents, - const sptr& profileEventNotifier, - std::list& failedEvents) -{ - struct RadarInfo info = { - .funcName = "UnsubscribeProfileEvents", - .stageRes = static_cast(StageRes::STAGE_SUCC), - .bizState = static_cast(BizState::BIZ_STATE_END), - }; - if (!DpRadarHelper::GetInstance().ReportSaCheckAuth(info)) { - HILOGE("ReportSaCheckAuth failed"); - } - return SubscribeManager::GetInstance().UnsubscribeProfileEvents(profileEvents, - profileEventNotifier, failedEvents); -} - -int32_t DistributedDeviceProfileService::SyncDeviceProfile(const SyncOptions& syncOptions, - const sptr& profileEventNotifier) -{ - bool ret = AuthorityManager::GetInstance().CheckInterfaceAuthority("sync"); - struct RadarInfo info = { - .funcName = "SyncDeviceProfile", - .stageRes = ret ? - static_cast(StageRes::STAGE_SUCC) : static_cast(StageRes::STAGE_FAIL), - .bizState = static_cast(BizState::BIZ_STATE_END), - .errCode = ERR_DP_PERMISSION_DENIED, - }; - if (!DpRadarHelper::GetInstance().ReportSaCheckAuth(info)) { - HILOGE("ReportSaCheckAuth failed"); - } - if (!ret) { - return ERR_DP_PERMISSION_DENIED; - } - return DeviceProfileStorageManager::GetInstance().SyncDeviceProfile(syncOptions, profileEventNotifier); -} - -int32_t DistributedDeviceProfileService::Dump(int32_t fd, const std::vector& args) -{ - std::vector argsInStr8; - for (const auto& arg : args) { - argsInStr8.emplace_back(Str16ToStr8(arg)); - } - - std::string result; - DeviceProfileDumper::Dump(argsInStr8, result); - - if (!SaveStringToFd(fd, result)) { - HILOGE("save to fd failed"); - return ERR_DP_FILE_FAILED_ERR; - } - return ERR_OK; -} - -void DistributedDeviceProfileService::DelayUnloadTask() -{ - auto task = [this]() { - HILOGD("do unload task"); - if (DistributedDeviceProfile::ProfileCache::GetInstance().IsDeviceOnline()) { - return; - } - auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (samgrProxy == nullptr) { - HILOGE("get samgr failed"); - return; - } - int32_t ret = samgrProxy->UnloadSystemAbility(DISTRIBUTED_DEVICE_PROFILE_SA_ID); - if (ret != ERR_OK) { - HILOGE("remove system ability failed"); - return; - } - }; - - { - std::lock_guard lock(unloadMutex_); - if (unloadHandler_ == nullptr) { - return; - } - unloadHandler_->RemoveTask(TASK_ID); - if (!DistributedDeviceProfile::ProfileCache::GetInstance().IsDeviceOnline()) { - HILOGI("delay unload task post task"); - unloadHandler_->PostTask(task, TASK_ID, DELAY_TIME); - } - } -} - -void DistributedDeviceProfileService::OnStart(const SystemAbilityOnDemandReason& startReason) -{ - HILOGI("called"); - if (!Init()) { - HILOGE("init failed"); - } - AddSystemAbilityListener(SOFTBUS_SERVER_SA_ID); - AddSystemAbilityListener(DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID); - AddSystemAbilityListener(DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID); - AddSystemAbilityListener(SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN); - if (!Publish(this)) { - HILOGE("publish SA failed"); - return; - } - IPCSkeleton::SetMaxWorkThreadNum(DP_IPC_THREAD_NUM); - HILOGI("start reason %{public}s", startReason.GetName().c_str()); - DelayUnloadTask(); -} - -int32_t DistributedDeviceProfileService::OnIdle(const SystemAbilityOnDemandReason& idleReason) -{ - HILOGI("idle reason %{public}d", idleReason.GetId()); - return UNLOAD_IMMEDIATELY; -} - -void DistributedDeviceProfileService::OnStop() -{ - HILOGI("called"); - if (!DistributedDeviceProfile::DistributedDeviceProfileServiceNew::GetInstance().UnInit()) { - HILOGE("UnInit failed"); - return; - } -} - -void DistributedDeviceProfileService::OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) -{ - HILOGI("called systemAbilityId:%{public}d", systemAbilityId); - if (systemAbilityId == SUBSYS_ACCOUNT_SYS_ABILITY_ID_BEGIN) { - DistributedDeviceProfile::DistributedDeviceProfileServiceNew::GetInstance().SubscribeAccountCommonEvent(); - } - if (DistributedDeviceProfile::DistributedDeviceProfileServiceNew::GetInstance().IsInited()) { - return; - } - { - std::lock_guard lock(depSaIdsMtx_); - if (depSaIds_.empty()) { - return; - } - depSaIds_.erase(systemAbilityId); - if (!depSaIds_.empty()) { - return; - } - } - DoBusinessInit(); -} - -bool DistributedDeviceProfileService::DoBusinessInit() -{ - HILOGD("called"); - if (!AuthorityManager::GetInstance().Init()) { - HILOGE("AuthorityManager init failed"); - return false; - } - if (DistributedDeviceProfile::DistributedDeviceProfileServiceNew::GetInstance().PostInit() != ERR_OK) { - HILOGE("PostInit failed"); - return false; - } - HILOGI("DoBusinessInit succeeded"); - return true; -} -} // namespace DeviceProfile -} // namespace OHOS diff --git a/old/services/core/src/distributed_device_profile_stub.cpp b/old/services/core/src/distributed_device_profile_stub.cpp deleted file mode 100644 index bc257720..00000000 --- a/old/services/core/src/distributed_device_profile_stub.cpp +++ /dev/null @@ -1,1252 +0,0 @@ -/* - * Copyright (c) 2021-2025 Huawei Device Co., Ltd. - * 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. - */ - -#include "distributed_device_profile_stub.h" - -#include - -#include "authority_manager.h" -#include "deviceprofile_ipc_interface_code.h" -#include "device_profile_errors.h" -#include "device_profile_log.h" -#include "device_profile_storage.h" -#include "device_profile_utils.h" -#include "ipc_skeleton.h" -#include "iprofile_event_notifier.h" -#include "parcel_helper.h" -#include "distributed_device_profile_service_new.h" -#include "distributed_device_profile_errors.h" - -namespace OHOS { -namespace DeviceProfile { -using namespace OHOS::DistributedDeviceProfile; -namespace { -const std::string TAG = "DistributedDeviceProfileStub"; -constexpr uint32_t MAX_EVENT_LEN = 1000000; -} - -DistributedDeviceProfileStub::DistributedDeviceProfileStub() -{ - funcsMap_[static_cast(IDeviceProfileInterfaceCode::PUT_DEVICE_PROFILE)] = - &DistributedDeviceProfileStub::PutDeviceProfileInner; - funcsMap_[static_cast(IDeviceProfileInterfaceCode::DELETE_DEVICE_PROFILE)] = - &DistributedDeviceProfileStub::DeleteDeviceProfileInner; - funcsMap_[static_cast(IDeviceProfileInterfaceCode::GET_DEVICE_PROFILE)] = - &DistributedDeviceProfileStub::GetDeviceProfileInner; - funcsMap_[static_cast(IDeviceProfileInterfaceCode::SUBSCRIBE_PROFILE_EVENT)] = - &DistributedDeviceProfileStub::SubscribeProfileEventInner; - funcsMap_[static_cast(IDeviceProfileInterfaceCode::UNSUBSCRIBE_PROFILE_EVENT)] = - &DistributedDeviceProfileStub::UnsubscribeProfileEventInner; - funcsMap_[static_cast(IDeviceProfileInterfaceCode::SYNC_DEVICE_PROFILE)] = - &DistributedDeviceProfileStub::SyncDeviceProfileInner; - InitNewRdbIpcInterface(); - InitNewKVIpcInterface(); - InitAclAndSubscribe(); -} - -void DistributedDeviceProfileStub::InitAclAndSubscribe() -{ - aclAndSubscribeFuncs_.emplace_back(static_cast(DPInterfaceCode::PUT_ACL_PROFILE)); - aclAndSubscribeFuncs_.emplace_back(static_cast(DPInterfaceCode::UPDATE_ACL_PROFILE)); - aclAndSubscribeFuncs_.emplace_back(static_cast(DPInterfaceCode::GET_TRUST_DEVICE_PROFILE)); - aclAndSubscribeFuncs_.emplace_back(static_cast(DPInterfaceCode::GET_ALL_TRUST_DEVICE_PROFILE)); - aclAndSubscribeFuncs_.emplace_back(static_cast(DPInterfaceCode::GET_ACL_PROFILE)); - aclAndSubscribeFuncs_.emplace_back(static_cast(DPInterfaceCode::GET_ALL_ACL_PROFILE)); - aclAndSubscribeFuncs_.emplace_back(static_cast(DPInterfaceCode::DELETE_ACL_PROFILE)); - aclAndSubscribeFuncs_.emplace_back(static_cast(DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE)); - aclAndSubscribeFuncs_.emplace_back(static_cast(DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE)); - aclAndSubscribeFuncs_.emplace_back(static_cast(DPInterfaceCode::SEND_SUBSCRIBE_INFOS)); - aclAndSubscribeFuncs_.emplace_back(static_cast(DPInterfaceCode::PUT_SERVICE_PROFILE)); - aclAndSubscribeFuncs_.emplace_back(static_cast(DPInterfaceCode::PUT_SERVICE_PROFILE_BATCH)); - aclAndSubscribeFuncs_.emplace_back(static_cast(DPInterfaceCode::PUT_CHAR_PROFILE)); - aclAndSubscribeFuncs_.emplace_back(static_cast(DPInterfaceCode::PUT_CHAR_PROFILE_BATCH)); - aclAndSubscribeFuncs_.emplace_back(static_cast(DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE_INITED)); - aclAndSubscribeFuncs_.emplace_back(static_cast(DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE_INITED)); - aclAndSubscribeFuncs_.emplace_back(static_cast(DPInterfaceCode::PUT_ALL_TRUSTED_DEVICES)); - aclAndSubscribeFuncs_.emplace_back(static_cast(DPInterfaceCode::PUT_DEVICE_PROFILE_BATCH)); - aclAndSubscribeFuncs_.emplace_back(static_cast(DPInterfaceCode::GET_DEVICE_PROFILES)); - aclAndSubscribeFuncs_.emplace_back(static_cast(DPInterfaceCode::DELETE_DEVICE_PROFILE_BATCH)); - aclAndSubscribeFuncs_.emplace_back(static_cast(DPInterfaceCode::GET_DEVICE_ICON_INFOS)); - aclAndSubscribeFuncs_.emplace_back(static_cast(DPInterfaceCode::PUT_DEVICE_ICON_INFO_BATCH)); - aclAndSubscribeFuncs_.emplace_back(static_cast(DPInterfaceCode::PUT_PRODUCT_INFO_BATCH)); - aclAndSubscribeFuncs_.emplace_back(static_cast(DPInterfaceCode::PUT_SESSION_KEY)); - aclAndSubscribeFuncs_.emplace_back(static_cast(DPInterfaceCode::GET_SESSION_KEY)); - aclAndSubscribeFuncs_.emplace_back(static_cast(DPInterfaceCode::UPDATE_SESSION_KEY)); - aclAndSubscribeFuncs_.emplace_back(static_cast(DPInterfaceCode::DELETE_SESSION_KEY)); -} - -int32_t DistributedDeviceProfileStub::NotifyAclEventInner(uint32_t code, MessageParcel& data, - MessageParcel& reply, MessageOption& option) -{ - switch (code) { - case static_cast(DPInterfaceCode::PUT_ACL_PROFILE): - return PutAccessControlProfileInner(data, reply); - case static_cast(DPInterfaceCode::UPDATE_ACL_PROFILE): - return UpdateAccessControlProfileInner(data, reply); - case static_cast(DPInterfaceCode::GET_TRUST_DEVICE_PROFILE): - return GetTrustDeviceProfileInner(data, reply); - case static_cast(DPInterfaceCode::GET_ALL_TRUST_DEVICE_PROFILE): - return GetAllTrustDeviceProfileInner(data, reply); - case static_cast(DPInterfaceCode::GET_ACL_PROFILE): - return GetAccessControlProfileInner(data, reply); - case static_cast(DPInterfaceCode::GET_ALL_ACL_PROFILE): - return GetAllAccessControlProfileInner(data, reply); - case static_cast(DPInterfaceCode::DELETE_ACL_PROFILE): - return DeleteAccessControlProfileInner(data, reply); - case static_cast(DPInterfaceCode::PUT_SESSION_KEY): - return PutSessionKeyInner(data, reply); - case static_cast(DPInterfaceCode::GET_SESSION_KEY): - return GetSessionKeyInner(data, reply); - case static_cast(DPInterfaceCode::UPDATE_SESSION_KEY): - return UpdateSessionKeyInner(data, reply); - case static_cast(DPInterfaceCode::DELETE_SESSION_KEY): - return DeleteSessionKeyInner(data, reply); - default: - return NotifyProfileDataEventInner(code, data, reply, option); - } -} - -int32_t DistributedDeviceProfileStub::NotifyProfileDataEventInner(uint32_t code, MessageParcel& data, - MessageParcel& reply, MessageOption& option) -{ - switch (code) { - case static_cast(DPInterfaceCode::PUT_DEVICE_PROFILE_BATCH): - return PutDeviceProfileBatchInner(data, reply); - case static_cast(DPInterfaceCode::GET_DEVICE_PROFILES): - return GetDeviceProfilesInner(data, reply); - case static_cast(DPInterfaceCode::GET_DEVICE_ICON_INFOS): - return GetDeviceIconInfosInner(data, reply); - case static_cast(DPInterfaceCode::PUT_DEVICE_ICON_INFO_BATCH): - return PutDeviceIconInfoBatchInner(data, reply); - case static_cast(DPInterfaceCode::PUT_PRODUCT_INFO_BATCH): - return PutProductInfoBatchInner(data, reply); - case static_cast(DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE): - return SubscribeDeviceProfileInner(data, reply); - case static_cast(DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE): - return UnSubscribeDeviceProfileInner(data, reply); - case static_cast(DPInterfaceCode::SEND_SUBSCRIBE_INFOS): - return SendSubscribeInfosInner(data, reply); - case static_cast(DPInterfaceCode::PUT_SERVICE_PROFILE): - return PutServiceProfileInner(data, reply); - case static_cast(DPInterfaceCode::PUT_SERVICE_PROFILE_BATCH): - return PutServiceProfileBatchInner(data, reply); - case static_cast(DPInterfaceCode::PUT_CHAR_PROFILE): - return PutCharacteristicProfileInner(data, reply); - case static_cast(DPInterfaceCode::PUT_CHAR_PROFILE_BATCH): - return PutCharacteristicProfileBatchInner(data, reply); - case static_cast(DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE_INITED): - return SubscribeDeviceProfileInitedInner(data, reply); - case static_cast(DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE_INITED): - return UnSubscribeDeviceProfileInitedInner(data, reply); - case static_cast(DPInterfaceCode::PUT_ALL_TRUSTED_DEVICES): - return PutAllTrustedDevicesInner(data, reply); - case static_cast(DPInterfaceCode::DELETE_DEVICE_PROFILE_BATCH): - return DeleteDeviceProfileBatchInner(data, reply); - default: - HILOGW("unknown request code, please check, code = %{public}u", code); - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } -} - -int32_t DistributedDeviceProfileStub::NotifyOldEventInner(uint32_t code, MessageParcel& data, - MessageParcel& reply, MessageOption& option) -{ - switch (code) { - case static_cast(IDeviceProfileInterfaceCode::PUT_DEVICE_PROFILE): - return PutDeviceProfileInner(data, reply); - case static_cast(IDeviceProfileInterfaceCode::DELETE_DEVICE_PROFILE): - return DeleteDeviceProfileInner(data, reply); - case static_cast(IDeviceProfileInterfaceCode::GET_DEVICE_PROFILE): - return GetDeviceProfileInner(data, reply); - case static_cast(IDeviceProfileInterfaceCode::SUBSCRIBE_PROFILE_EVENT): - return SubscribeProfileEventInner(data, reply); - case static_cast(IDeviceProfileInterfaceCode::UNSUBSCRIBE_PROFILE_EVENT): - return UnsubscribeProfileEventInner(data, reply); - case static_cast(IDeviceProfileInterfaceCode::SYNC_DEVICE_PROFILE): - return SyncDeviceProfileInner(data, reply); - default: - return NotifyNewEventInner(code, data, reply, option); - } -} - -int32_t DistributedDeviceProfileStub::NotifyNewEventInner(uint32_t code, MessageParcel& data, - MessageParcel& reply, MessageOption& option) -{ - switch (code) { - case static_cast(DPInterfaceCode::GET_DEVICE_PROFILE_NEW): - return GetDeviceProfileNewInner(data, reply); - case static_cast(DPInterfaceCode::GET_SERVICE_PROFILE): - return GetServiceProfileInner(data, reply); - case static_cast(DPInterfaceCode::GET_CHAR_PROFILE): - return GetCharacteristicProfileInner(data, reply); - case static_cast(DPInterfaceCode::DEL_SERVICE_PROFILE): - return DeleteServiceProfileInner(data, reply); - case static_cast(DPInterfaceCode::DEL_CHAR_PROFILE): - return DeleteCharacteristicProfileInner(data, reply); - case static_cast(DPInterfaceCode::SYNC_DEVICE_PROFILE_NEW): - return SyncDeviceProfileNewInner(data, reply); - case static_cast(DPInterfaceCode::PUT_SERVICE_INFO_PROFILE): - return PutServiceInfoProfileInner(data, reply); - case static_cast(DPInterfaceCode::DELETE_SERVICE_INFO_PROFILE): - return DeleteServiceInfoProfileInner(data, reply); - case static_cast(DPInterfaceCode::UPDATE_SERVICE_INFO_PROFILE): - return UpdateServiceInfoProfileInner(data, reply); - case static_cast(DPInterfaceCode::GET_SERVICE_INFO_PROFILE_BY_UNIQUE_KEY): - return GetServiceInfoProfileByUniqueKeyInner(data, reply); - case static_cast(DPInterfaceCode::GET_SERVICE_INFO_PROFILE_LIST_BY_TOKEN_ID): - return GetServiceInfoProfileListByTokenIdInner(data, reply); - case static_cast(DPInterfaceCode::GET_ALL_SERVICE_INFO_PROFILE_LIST): - return GetAllServiceInfoProfileListInner(data, reply); - case static_cast(DPInterfaceCode::GET_SERVICE_INFO_PROFILE_LIST_BY_BUNDLE_NAME): - return GetServiceInfoProfileListByBundleNameInner(data, reply); - case static_cast(DPInterfaceCode::SUBSCRIBE_PINCODE_INVALID): - return SubscribePinCodeInvalidInner(data, reply); - case static_cast(DPInterfaceCode::UNSUBSCRIBE_PINCODE_INVALID): - return UnSubscribePinCodeInvalidInner(data, reply); - default: - return NotifyLocalServiceEventInner(code, data, reply, option); - } -} - -int32_t DistributedDeviceProfileStub::NotifyLocalServiceEventInner(uint32_t code, MessageParcel& data, - MessageParcel& reply, MessageOption& option) -{ - switch (code) { - case static_cast(DPInterfaceCode::PUT_LOCAL_SERVICE_INFO): - return PutLocalServiceInfoInner(data, reply); - case static_cast(DPInterfaceCode::UPDATE_LOCAL_SERVICE_INFO): - return UpdateLocalServiceInfoInner(data, reply); - case static_cast(DPInterfaceCode::GET_LOCAL_SERVICE_INFO_BY_BINDLE_AND_PINTYPE): - return GetLocalServiceInfoByBundleAndPinTypeInner(data, reply); - case static_cast(DPInterfaceCode::DELETE_LOCAL_SERVICE_INFO): - return DeleteLocalServiceInfoInner(data, reply); - default: - HILOGW("unknown request code, please check, code = %{public}u", code); - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } -} - -bool DistributedDeviceProfileStub::EnforceInterfaceToken(MessageParcel& data) -{ - return data.ReadInterfaceToken() == IDistributedDeviceProfile::GetDescriptor(); -} - -void DistributedDeviceProfileStub::InitNewRdbIpcInterface() -{ - funcsMap_[static_cast(DPInterfaceCode::PUT_ACL_PROFILE)] = - &DistributedDeviceProfileStub::PutAccessControlProfileInner; - funcsMap_[static_cast(DPInterfaceCode::UPDATE_ACL_PROFILE)] = - &DistributedDeviceProfileStub::UpdateAccessControlProfileInner; - funcsMap_[static_cast(DPInterfaceCode::GET_TRUST_DEVICE_PROFILE)] = - &DistributedDeviceProfileStub::GetTrustDeviceProfileInner; - funcsMap_[static_cast(DPInterfaceCode::GET_ALL_TRUST_DEVICE_PROFILE)] = - &DistributedDeviceProfileStub::GetAllTrustDeviceProfileInner; - funcsMap_[static_cast(DPInterfaceCode::GET_ACL_PROFILE)] = - &DistributedDeviceProfileStub::GetAccessControlProfileInner; - funcsMap_[static_cast(DPInterfaceCode::GET_ALL_ACL_PROFILE)] = - &DistributedDeviceProfileStub::GetAllAccessControlProfileInner; - funcsMap_[static_cast(DPInterfaceCode::DELETE_ACL_PROFILE)] = - &DistributedDeviceProfileStub::DeleteAccessControlProfileInner; - funcsMap_[static_cast(DPInterfaceCode::PUT_SESSION_KEY)] = - &DistributedDeviceProfileStub::PutSessionKeyInner; - funcsMap_[static_cast(DPInterfaceCode::GET_SESSION_KEY)] = - &DistributedDeviceProfileStub::GetSessionKeyInner; - funcsMap_[static_cast(DPInterfaceCode::UPDATE_SESSION_KEY)] = - &DistributedDeviceProfileStub::UpdateSessionKeyInner; - funcsMap_[static_cast(DPInterfaceCode::DELETE_SESSION_KEY)] = - &DistributedDeviceProfileStub::DeleteSessionKeyInner; -} - -void DistributedDeviceProfileStub::InitNewKVIpcInterface() -{ - funcsMap_[static_cast(DPInterfaceCode::PUT_SERVICE_PROFILE)] = - &DistributedDeviceProfileStub::PutServiceProfileInner; - funcsMap_[static_cast(DPInterfaceCode::PUT_SERVICE_PROFILE_BATCH)] = - &DistributedDeviceProfileStub::PutServiceProfileBatchInner; - funcsMap_[static_cast(DPInterfaceCode::PUT_CHAR_PROFILE)] = - &DistributedDeviceProfileStub::PutCharacteristicProfileInner; - funcsMap_[static_cast(DPInterfaceCode::PUT_CHAR_PROFILE_BATCH)] = - &DistributedDeviceProfileStub::PutCharacteristicProfileBatchInner; - funcsMap_[static_cast(DPInterfaceCode::GET_DEVICE_PROFILE_NEW)] = - &DistributedDeviceProfileStub::GetDeviceProfileNewInner; - funcsMap_[static_cast(DPInterfaceCode::GET_SERVICE_PROFILE)] = - &DistributedDeviceProfileStub::GetServiceProfileInner; - funcsMap_[static_cast(DPInterfaceCode::GET_CHAR_PROFILE)] = - &DistributedDeviceProfileStub::GetCharacteristicProfileInner; - funcsMap_[static_cast(DPInterfaceCode::DEL_SERVICE_PROFILE)] = - &DistributedDeviceProfileStub::DeleteServiceProfileInner; - funcsMap_[static_cast(DPInterfaceCode::DEL_CHAR_PROFILE)] = - &DistributedDeviceProfileStub::DeleteCharacteristicProfileInner; - funcsMap_[static_cast(DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE)] = - &DistributedDeviceProfileStub::SubscribeDeviceProfileInner; - funcsMap_[static_cast(DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE)] = - &DistributedDeviceProfileStub::UnSubscribeDeviceProfileInner; - funcsMap_[static_cast(DPInterfaceCode::SEND_SUBSCRIBE_INFOS)] = - &DistributedDeviceProfileStub::SendSubscribeInfosInner; - funcsMap_[static_cast(DPInterfaceCode::SYNC_DEVICE_PROFILE_NEW)] = - &DistributedDeviceProfileStub::SyncDeviceProfileNewInner; -} - -int32_t DistributedDeviceProfileStub::OnRemoteRequest(uint32_t code, MessageParcel& data, - MessageParcel& reply, MessageOption& option) -{ - HILOGI("code = %{public}u, CallingPid = %{public}u", code, IPCSkeleton::GetCallingPid()); - DelayUnloadTask(); - if (!EnforceInterfaceToken(data)) { - HILOGE("check interface token failed"); - return ERR_DP_INTERFACE_CHECK_FAILED; - } - if (!AuthorityManager::GetInstance().CheckCallerTrust()) { - HILOGE("caller is not trusted"); - return ERR_DP_PERMISSION_DENIED; - } - if (std::find(aclAndSubscribeFuncs_.begin(), aclAndSubscribeFuncs_.end(), code) != - aclAndSubscribeFuncs_.end()) { - int32_t ret = NotifyAclEventInner(code, data, reply, option); - return ret; - } - if (!DistributedDeviceProfileServiceNew::GetInstance().IsInited()) { - HILOGE("DP not finish init"); - return ERR_DP_LOAD_SERVICE_ERR; - } - int32_t ret = NotifyOldEventInner(code, data, reply, option); - return ret; -} - -int32_t DistributedDeviceProfileStub::PutDeviceProfileInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - ServiceCharacteristicProfile profile; - if (!profile.Unmarshalling(data)) { - return ERR_NULL_OBJECT; - } - return PutDeviceProfile(profile); -} - -int32_t DistributedDeviceProfileStub::GetDeviceProfileInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - std::string udid; - std::string serviceId; - ServiceCharacteristicProfile profile; - PARCEL_READ_HELPER(data, String, udid); - PARCEL_READ_HELPER(data, String, serviceId); - int32_t ret = GetDeviceProfile(udid, serviceId, profile); - if (!reply.WriteInt32(ret)) { - HILOGE("WriteInt32 failed"); - return ERR_FLATTEN_OBJECT; - } - if (!profile.Marshalling(reply)) { - HILOGE("marshall profile failed"); - return ERR_FLATTEN_OBJECT; - } - return ERR_NONE; -} - -int32_t DistributedDeviceProfileStub::DeleteDeviceProfileInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - return DeleteDeviceProfile(data.ReadString()); -} - -int32_t DistributedDeviceProfileStub::SubscribeProfileEventInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - uint32_t numSubscribeInfos = data.ReadUint32(); - if (numSubscribeInfos == 0 || numSubscribeInfos > MAX_EVENT_LEN) { - return ERR_DP_INVALID_PARAMS; - } - - std::list subscribeInfos; - for (uint32_t i = 0; i < numSubscribeInfos; i++) { - SubscribeInfo subscribeInfo; - if (!subscribeInfo.Unmarshalling(data)) { - return ERR_NULL_OBJECT; - } - HILOGD("profile event = %{public}u", static_cast(subscribeInfo.profileEvent)); - subscribeInfos.emplace_back(std::move(subscribeInfo)); - } - sptr eventNotifier = data.ReadRemoteObject(); - std::list failedEvents; - - int32_t errCode = SubscribeProfileEvents(subscribeInfos, eventNotifier, failedEvents); - HILOGI("errCode = %{public}d", errCode); - if (!reply.WriteInt32(errCode)) { - return ERR_FLATTEN_OBJECT; - } - if ((errCode != ERR_OK) && !DeviceProfileUtils::WriteProfileEvents(failedEvents, reply)) { - HILOGE("write profile events failed"); - return ERR_FLATTEN_OBJECT; - } - return ERR_NONE; -} - -int32_t DistributedDeviceProfileStub::UnsubscribeProfileEventInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - uint32_t numEvents = data.ReadUint32(); - if (numEvents == 0 || numEvents > MAX_EVENT_LEN) { - return ERR_DP_INVALID_PARAMS; - } - - std::list profileEvents; - for (uint32_t i = 0; i < numEvents; i++) { - ProfileEvent profileEvent = static_cast(data.ReadUint32()); - if (profileEvent >= EVENT_PROFILE_END || profileEvent == EVENT_UNKNOWN) { - return ERR_DP_INVALID_PARAMS; - } - profileEvents.emplace_back(profileEvent); - } - sptr eventNotifier = data.ReadRemoteObject(); - std::list failedEvents; - - int32_t errCode = UnsubscribeProfileEvents(profileEvents, eventNotifier, failedEvents); - HILOGI("errCode = %{public}d", errCode); - if (!reply.WriteInt32(errCode)) { - return ERR_FLATTEN_OBJECT; - } - if ((errCode != ERR_OK) && !DeviceProfileUtils::WriteProfileEvents(failedEvents, reply)) { - HILOGE("write profile events failed"); - return ERR_FLATTEN_OBJECT; - } - return ERR_NONE; -} - -int32_t DistributedDeviceProfileStub::SyncDeviceProfileInner(MessageParcel& data, MessageParcel& reply) -{ - SyncOptions syncOption; - if (!syncOption.Unmarshalling(data)) { - HILOGD("unmarshalling failed"); - return ERR_NULL_OBJECT; - } - - sptr eventNotifier = data.ReadRemoteObject(); - return SyncDeviceProfile(syncOption, eventNotifier); -} - -int32_t DistributedDeviceProfileStub::PutAccessControlProfileInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - AccessControlProfile accessControlProfile; - if (!accessControlProfile.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().PutAccessControlProfile(accessControlProfile); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::UpdateAccessControlProfileInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - AccessControlProfile accessControlProfile; - if (!accessControlProfile.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().UpdateAccessControlProfile(accessControlProfile); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::GetTrustDeviceProfileInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - std::string deviceId; - READ_HELPER(data, String, deviceId); - TrustDeviceProfile trustDeviceProfile; - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().GetTrustDeviceProfile(deviceId, trustDeviceProfile); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - if (!trustDeviceProfile.Marshalling(reply)) { - HILOGE("write parcel fail!"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::PutProductInfoBatchInner(MessageParcel& data, MessageParcel& reply) -{ - std::vector productInfos; - if (!IpcUtils::UnMarshalling(data, productInfos)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().PutProductInfoBatch(productInfos); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::PutDeviceIconInfoBatchInner(MessageParcel& data, MessageParcel& reply) -{ - std::vector deviceIconInfos; - if (!IpcUtils::UnMarshalling(data, deviceIconInfos)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().PutDeviceIconInfoBatch(deviceIconInfos); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::GetDeviceIconInfosInner(MessageParcel& data, MessageParcel& reply) -{ - DeviceIconInfoFilterOptions filterOptions; - std::vector deviceIconInfos; - if (!filterOptions.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().GetDeviceIconInfos(filterOptions, - deviceIconInfos); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - if (!IpcUtils::Marshalling(reply, deviceIconInfos)) { - HILOGE("Write parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::PutServiceInfoProfileInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - ServiceInfoProfile serviceInfoProfile; - if (!serviceInfoProfile.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().PutServiceInfoProfile(serviceInfoProfile); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::DeleteServiceInfoProfileInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - ServiceInfoUniqueKey key; - if (!key.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().DeleteServiceInfoProfile(key); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::UpdateServiceInfoProfileInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - ServiceInfoProfile serviceInfoProfile; - if (!serviceInfoProfile.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().UpdateServiceInfoProfile(serviceInfoProfile); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::GetServiceInfoProfileByUniqueKeyInner(MessageParcel& data, MessageParcel& reply) -{ - ServiceInfoUniqueKey key; - ServiceInfoProfile serviceInfoProfile; - if (!key.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().GetServiceInfoProfileByUniqueKey(key, - serviceInfoProfile); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - if (!serviceInfoProfile.Marshalling(reply)) { - HILOGE("write parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::GetServiceInfoProfileListByTokenIdInner(MessageParcel& data, - MessageParcel& reply) -{ - ServiceInfoUniqueKey key; - std::vector serviceInfoProfiles; - if (!key.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().GetServiceInfoProfileListByTokenId(key, - serviceInfoProfiles); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - - if (!IpcUtils::Marshalling(reply, serviceInfoProfiles)) { - HILOGE("Write parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::GetAllServiceInfoProfileListInner(MessageParcel& data, - MessageParcel& reply) -{ - std::vector serviceInfoProfiles; - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().GetAllServiceInfoProfileList(serviceInfoProfiles); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - - if (!IpcUtils::Marshalling(reply, serviceInfoProfiles)) { - HILOGE("Write parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::GetServiceInfoProfileListByBundleNameInner(MessageParcel& data, - MessageParcel& reply) -{ - ServiceInfoUniqueKey key; - std::vector serviceInfoProfiles; - if (!key.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().GetServiceInfoProfileListByBundleName(key, - serviceInfoProfiles); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - - if (!IpcUtils::Marshalling(reply, serviceInfoProfiles)) { - HILOGE("Write parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::DeleteDeviceProfileBatchInner(MessageParcel& data, MessageParcel& reply) -{ - std::vector deviceProfiles; - if (!IpcUtils::UnMarshalling(data, deviceProfiles)) { - HILOGE("Write parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().DeleteDeviceProfileBatch(deviceProfiles); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::GetAllTrustDeviceProfileInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - std::vector trustDeviceProfiles; - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().GetAllTrustDeviceProfile(trustDeviceProfiles); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - if (!IpcUtils::Marshalling(reply, trustDeviceProfiles)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::GetAccessControlProfileInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - std::map queryParams; - if (!IpcUtils::UnMarshalling(data, queryParams)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - std::vector accessControlProfiles; - int32_t ret = - DistributedDeviceProfileServiceNew::GetInstance().GetAccessControlProfile(queryParams, accessControlProfiles); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - if (!IpcUtils::Marshalling(reply, accessControlProfiles)) { - HILOGE("write parcel fail!"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::GetAllAccessControlProfileInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - std::vector accessControlProfiles; - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().GetAllAccessControlProfile(accessControlProfiles); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - if (!IpcUtils::Marshalling(reply, accessControlProfiles)) { - HILOGE("write parcel fail!"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::DeleteAccessControlProfileInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - int32_t accessControlId; - READ_HELPER(data, Int32, accessControlId); - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().DeleteAccessControlProfile(accessControlId); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::PutSessionKeyInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - uint32_t userId = 0; - std::vector sessionKey; - int32_t sessionKeyId = 0; - READ_HELPER(data, Uint32, userId); - if (!IpcUtils::UnMarshalling(data, sessionKey)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().PutSessionKey(userId, sessionKey, sessionKeyId); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return DP_WRITE_PARCEL_FAIL; - } - WRITE_HELPER(reply, Int32, sessionKeyId); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::GetSessionKeyInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - uint32_t userId = 0; - int32_t sessionKeyId = 0; - std::vector sessionKey; - READ_HELPER(data, Uint32, userId); - READ_HELPER(data, Int32, sessionKeyId); - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().GetSessionKey(userId, sessionKeyId, sessionKey); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return DP_WRITE_PARCEL_FAIL; - } - if (!IpcUtils::Marshalling(reply, sessionKey)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::UpdateSessionKeyInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - uint32_t userId = 0; - std::vector sessionKey; - int32_t sessionKeyId = 0; - READ_HELPER(data, Uint32, userId); - READ_HELPER(data, Int32, sessionKeyId); - if (!IpcUtils::UnMarshalling(data, sessionKey)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().UpdateSessionKey(userId, sessionKeyId, sessionKey); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::DeleteSessionKeyInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - uint32_t userId = 0; - int32_t sessionKeyId = 0; - READ_HELPER(data, Uint32, userId); - READ_HELPER(data, Int32, sessionKeyId); - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().DeleteSessionKey(userId, sessionKeyId); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::PutDeviceProfileBatchInner(MessageParcel& data, MessageParcel& reply) -{ - std::vector deviceProfiles; - if (!IpcUtils::UnMarshalling(data, deviceProfiles)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().PutDeviceProfileBatch(deviceProfiles); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::PutServiceProfileInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - ServiceProfile serviceProfile; - if (!serviceProfile.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().PutServiceProfile(serviceProfile); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::PutServiceProfileBatchInner(MessageParcel& data, MessageParcel& reply) -{ - std::vector serviceProfiles; - if (!IpcUtils::UnMarshalling(data, serviceProfiles)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().PutServiceProfileBatch(serviceProfiles); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::PutCharacteristicProfileInner(MessageParcel& data, MessageParcel& reply) -{ - CharacteristicProfile charProfile; - if (!charProfile.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().PutCharacteristicProfile(charProfile); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::PutCharacteristicProfileBatchInner(MessageParcel& data, MessageParcel& reply) -{ - std::vector charProfiles; - if (!IpcUtils::UnMarshalling(data, charProfiles)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().PutCharacteristicProfileBatch(charProfiles); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::GetDeviceProfileNewInner(MessageParcel& data, MessageParcel& reply) -{ - std::string deviceId; - bool isMultiUser = false; - int32_t userId = DistributedDeviceProfile::DEFAULT_USER_ID; - OHOS::DistributedDeviceProfile::DeviceProfile deviceProfile; - READ_HELPER(data, String, deviceId); - READ_HELPER(data, Bool, isMultiUser); - READ_HELPER(data, Int32, userId); - deviceProfile.SetIsMultiUser(isMultiUser); - deviceProfile.SetUserId(userId); - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().GetDeviceProfile(deviceId, deviceProfile); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - if (!deviceProfile.Marshalling(reply)) { - HILOGE("write parcel fail!"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::GetDeviceProfilesInner(MessageParcel& data, MessageParcel& reply) -{ - DeviceProfileFilterOptions options; - std::vector deviceProfiles; - if (!options.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().GetDeviceProfiles(options, deviceProfiles); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - if (!IpcUtils::Marshalling(reply, deviceProfiles)) { - HILOGE("write parcel fail!"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::GetServiceProfileInner(MessageParcel& data, MessageParcel& reply) -{ - std::string deviceId; - std::string serviceName; - ServiceProfile serviceProfile; - bool isMultiUser = false; - int32_t userId = DistributedDeviceProfile::DEFAULT_USER_ID; - READ_HELPER(data, String, deviceId); - READ_HELPER(data, String, serviceName); - READ_HELPER(data, Bool, isMultiUser); - READ_HELPER(data, Int32, userId); - serviceProfile.SetIsMultiUser(isMultiUser); - serviceProfile.SetUserId(userId); - int32_t ret = - DistributedDeviceProfileServiceNew::GetInstance().GetServiceProfile(deviceId, serviceName, serviceProfile); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - if (!serviceProfile.Marshalling(reply)) { - HILOGE("write parcel fail!"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::GetCharacteristicProfileInner(MessageParcel& data, MessageParcel& reply) -{ - std::string deviceId; - std::string serviceName; - std::string characteristicKey; - bool isMultiUser = false; - int32_t userId = DistributedDeviceProfile::DEFAULT_USER_ID; - READ_HELPER(data, String, deviceId); - READ_HELPER(data, String, serviceName); - READ_HELPER(data, String, characteristicKey); - READ_HELPER(data, Bool, isMultiUser); - READ_HELPER(data, Int32, userId); - CharacteristicProfile charProfile; - charProfile.SetIsMultiUser(isMultiUser); - charProfile.SetUserId(userId); - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().GetCharacteristicProfile(deviceId, serviceName, - characteristicKey, charProfile); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - if (!charProfile.Marshalling(reply)) { - HILOGE("write parcel fail!"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::DeleteServiceProfileInner(MessageParcel& data, MessageParcel& reply) -{ - std::string deviceId; - std::string serviceName; - bool isMultiUser = false; - int32_t userId = DistributedDeviceProfile::DEFAULT_USER_ID; - READ_HELPER(data, String, deviceId); - READ_HELPER(data, String, serviceName); - READ_HELPER(data, Bool, isMultiUser); - READ_HELPER(data, Int32, userId); - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().DeleteServiceProfile(deviceId, serviceName, - isMultiUser, userId); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::DeleteCharacteristicProfileInner(MessageParcel& data, MessageParcel& reply) -{ - std::string deviceId; - std::string serviceName; - std::string characteristicKey; - bool isMultiUser = false; - int32_t userId = OHOS::DistributedDeviceProfile::DEFAULT_USER_ID; - READ_HELPER(data, String, deviceId); - READ_HELPER(data, String, serviceName); - READ_HELPER(data, String, characteristicKey); - READ_HELPER(data, Bool, isMultiUser); - READ_HELPER(data, Int32, userId); - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().DeleteCharacteristicProfile(deviceId, serviceName, - characteristicKey, isMultiUser, userId); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::SubscribeDeviceProfileInner(MessageParcel& data, MessageParcel& reply) -{ - OHOS::DistributedDeviceProfile::SubscribeInfo subscribeInfo; - if (!subscribeInfo.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().SubscribeDeviceProfile(subscribeInfo); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::UnSubscribeDeviceProfileInner(MessageParcel& data, MessageParcel& reply) -{ - OHOS::DistributedDeviceProfile::SubscribeInfo subscribeInfo; - if (!subscribeInfo.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().UnSubscribeDeviceProfile(subscribeInfo); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::SyncDeviceProfileNewInner(MessageParcel& data, MessageParcel& reply) -{ - OHOS::DistributedDeviceProfile::DpSyncOptions syncOptions; - if (!syncOptions.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - sptr syncCompletedCallback = data.ReadRemoteObject(); - int32_t ret = - DistributedDeviceProfileServiceNew::GetInstance().SyncDeviceProfile(syncOptions, syncCompletedCallback); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::SendSubscribeInfosInner(MessageParcel& data, MessageParcel& reply) -{ - std::map listenerMap; - if (!IpcUtils::UnMarshalling(data, listenerMap)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().SendSubscribeInfos(listenerMap); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::SubscribeDeviceProfileInitedInner(MessageParcel& data, MessageParcel& reply) -{ - int32_t saId = -1; - READ_HELPER(data, Int32, saId); - sptr dpInitedCallback = data.ReadRemoteObject(); - if (dpInitedCallback == nullptr) { - HILOGE("read remoteObject failed!"); - return ERR_FLATTEN_OBJECT; - } - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().SubscribeDeviceProfileInited(saId, - dpInitedCallback); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::UnSubscribeDeviceProfileInitedInner(MessageParcel& data, MessageParcel& reply) -{ - int32_t saId = -1; - READ_HELPER(data, Int32, saId); - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().UnSubscribeDeviceProfileInited(saId); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::SubscribePinCodeInvalidInner(MessageParcel& data, MessageParcel& reply) -{ - std::string bundleName = ""; - int32_t pinExchangeType = DEFAULT_PIN_EXCHANGE_TYPE; - READ_HELPER(data, String, bundleName); - READ_HELPER(data, Int32, pinExchangeType); - sptr pincodeInvalidCallback = data.ReadRemoteObject(); - if (pincodeInvalidCallback == nullptr) { - HILOGE("read remoteObject failed!"); - return ERR_FLATTEN_OBJECT; - } - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().SubscribePinCodeInvalid(bundleName, - pinExchangeType, pincodeInvalidCallback); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::UnSubscribePinCodeInvalidInner(MessageParcel& data, MessageParcel& reply) -{ - std::string bundleName = ""; - int32_t pinExchangeType = DEFAULT_PIN_EXCHANGE_TYPE; - READ_HELPER(data, String, bundleName); - READ_HELPER(data, Int32, pinExchangeType); - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().UnSubscribePinCodeInvalid(bundleName, - pinExchangeType); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::PutAllTrustedDevicesInner(MessageParcel& data, MessageParcel& reply) -{ - std::vector deviceInfos; - if (!IpcUtils::UnMarshalling(data, deviceInfos)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().PutAllTrustedDevices(deviceInfos); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::PutLocalServiceInfoInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - LocalServiceInfo localServiceInfo; - if (!localServiceInfo.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().PutLocalServiceInfo(localServiceInfo); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::UpdateLocalServiceInfoInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - LocalServiceInfo localServiceInfo; - if (!localServiceInfo.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().UpdateLocalServiceInfo(localServiceInfo); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::GetLocalServiceInfoByBundleAndPinTypeInner(MessageParcel& data, - MessageParcel& reply) -{ - LocalServiceInfo localServiceInfo; - int32_t pinExchangeType = 0; - std::string bundleName = ""; - READ_HELPER(data, String, bundleName); - READ_HELPER(data, Int32, pinExchangeType); - int32_t ret = DistributedDeviceProfileServiceNew::GetInstance().GetLocalServiceInfoByBundleAndPinType( - bundleName, pinExchangeType, localServiceInfo); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - if (!localServiceInfo.Marshalling(reply)) { - HILOGE("write parcel fail!"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStub::DeleteLocalServiceInfoInner(MessageParcel& data, MessageParcel& reply) -{ - int32_t pinExchangeType = 0; - std::string bundleName = ""; - READ_HELPER(data, String, bundleName); - READ_HELPER(data, Int32, pinExchangeType); - int32_t ret = - DistributedDeviceProfileServiceNew::GetInstance().DeleteLocalServiceInfo(bundleName, pinExchangeType); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} -} // namespace DeviceProfile -} // namespace OHOS diff --git a/old/services/core/src/profile_change_notification.cpp b/old/services/core/src/profile_change_notification.cpp deleted file mode 100644 index 22456a11..00000000 --- a/old/services/core/src/profile_change_notification.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ - -#include "profile_change_notification.h" - -#include -#include -#include -#include - -#include "device_profile_log.h" -#include "parcel.h" -#include "parcel_helper.h" - -namespace OHOS { -namespace DeviceProfile { -namespace { -const std::string TAG = "ProfileChangeNotification"; -constexpr int32_t MAX_ENTRY_LEN = 1000000; -} - -const std::vector& ProfileChangeNotification::GetProfileEntries() const -{ - return profileEntries_; -} - -const std::string& ProfileChangeNotification::GetDeviceId() const -{ - return deviceId_; -} - -bool ProfileChangeNotification::IsLocal() const -{ - return isLocal_; -} - -bool ProfileChangeNotification::Marshalling(Parcel& parcel) const -{ - int32_t entrySize = static_cast(profileEntries_.size()); - PARCEL_WRITE_HELPER_RET(parcel, Int32, entrySize, false); - for (const auto& profileEntry : profileEntries_) { - if (!profileEntry.Marshalling(parcel)) { - return false; - } - } - PARCEL_WRITE_HELPER_RET(parcel, String, deviceId_, false); - - return true; -} - -bool ProfileChangeNotification::Unmarshalling(Parcel& parcel) -{ - int32_t entrySize = parcel.ReadInt32(); - if (entrySize < 0 || entrySize > MAX_ENTRY_LEN) { - HILOGE("invalid entrySize = %{public}d", entrySize); - return false; - } - profileEntries_.reserve(entrySize); - for (int32_t i = 0; i < entrySize; i++) { - ProfileEntry profileEntry; - if (!profileEntry.Unmarshalling(parcel)) { - return false; - } - profileEntries_.emplace_back(std::move(profileEntry)); - } - PARCEL_READ_HELPER_RET(parcel, String, deviceId_, false); - return true; -} - -bool ProfileEntry::Marshalling(Parcel& parcel) const -{ - PARCEL_WRITE_HELPER_RET(parcel, String, key, false); - PARCEL_WRITE_HELPER_RET(parcel, String, value, false); - PARCEL_WRITE_HELPER_RET(parcel, Uint8, static_cast(changeType), false); - return true; -} - -bool ProfileEntry::Unmarshalling(Parcel& parcel) -{ - PARCEL_READ_HELPER_RET(parcel, String, key, false); - PARCEL_READ_HELPER_RET(parcel, String, value, false); - uint8_t type = 0; - PARCEL_READ_HELPER_RET(parcel, Uint8, type, false); - changeType = static_cast(type); - return true; -} -} // namespace DeviceProfile -} // namespace OHOS diff --git a/old/services/core/src/service_characteristic_profile.cpp b/old/services/core/src/service_characteristic_profile.cpp deleted file mode 100644 index f3fb371c..00000000 --- a/old/services/core/src/service_characteristic_profile.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ - -#include "service_characteristic_profile.h" - -#include -#include - -#include "device_profile_log.h" -#include "parcel.h" -#include "parcel_helper.h" - -namespace OHOS { -namespace DeviceProfile { -namespace { -const std::string TAG = "ServiceCharacteristicProfile"; -} - -void ServiceCharacteristicProfile::SetServiceId(const std::string& serviceId) -{ - serviceId_ = serviceId; -} - -void ServiceCharacteristicProfile::SetServiceType(const std::string& serviceType) -{ - serviceType_ = serviceType; -} - -void ServiceCharacteristicProfile::SetServiceProfileJson(const std::string& profileJson) -{ - serviceProfileJson_ = profileJson; -} - -void ServiceCharacteristicProfile::SetCharacteristicProfileJson(const std::string& profileJson) -{ - characteristicProfileJson_ = profileJson; -} - -const std::string& ServiceCharacteristicProfile::GetServiceId() const -{ - return serviceId_; -} - -const std::string& ServiceCharacteristicProfile::GetServiceType() const -{ - return serviceType_; -} - -const std::string& ServiceCharacteristicProfile::GetServiceProfileJson() const -{ - return serviceProfileJson_; -} - -const std::string& ServiceCharacteristicProfile::GetCharacteristicProfileJson() const -{ - return characteristicProfileJson_; -} - -bool ServiceCharacteristicProfile::Marshalling(Parcel& parcel) const -{ - PARCEL_WRITE_HELPER_RET(parcel, String, serviceId_, false); - PARCEL_WRITE_HELPER_RET(parcel, String, serviceType_, false); - PARCEL_WRITE_HELPER_RET(parcel, String, characteristicProfileJson_, false); - PARCEL_WRITE_HELPER_RET(parcel, String, serviceProfileJson_, false); - return true; -} - -bool ServiceCharacteristicProfile::Unmarshalling(Parcel& parcel) -{ - PARCEL_READ_HELPER_RET(parcel, String, serviceId_, false); - PARCEL_READ_HELPER_RET(parcel, String, serviceType_, false); - PARCEL_READ_HELPER_RET(parcel, String, characteristicProfileJson_, false); - PARCEL_READ_HELPER_RET(parcel, String, serviceProfileJson_, false); - return true; -} -} // namespace DeviceProfile -} // namespace OHOS diff --git a/old/services/core/src/subscribemanager/profile_change_handler.cpp b/old/services/core/src/subscribemanager/profile_change_handler.cpp deleted file mode 100644 index aa5a7696..00000000 --- a/old/services/core/src/subscribemanager/profile_change_handler.cpp +++ /dev/null @@ -1,283 +0,0 @@ -/* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. - * 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. - */ - -#include "profile_change_handler.h" - -#include - -#include "datetime_ex.h" -#include "string_ex.h" - -#include "authority_manager.h" -#include "device_profile_errors.h" -#include "device_profile_log.h" -#include "device_profile_storage_manager.h" -#include "device_profile_utils.h" -#include "dp_radar_helper.h" -#include "profile_change_notification.h" - -namespace OHOS { -namespace DeviceProfile { -using namespace OHOS::DistributedKv; - -namespace { -const std::string TAG = "ProfileChangeHandler"; - -constexpr int32_t NUM_KEY_FILEDS = 3; -constexpr int32_t DEVICE_ID_SIZE = 64; -} - -struct ProfileKey { - std::string udid; - std::string serviceId; - KeyType type {KeyType::UNKNOWN}; - - static std::unique_ptr Parse(const std::string& entryKey); -}; - -std::unique_ptr ProfileKey::Parse(const std::string& entryKey) -{ - std::vector vec; - SplitStr(entryKey, "/", vec); - if (vec.size() != NUM_KEY_FILEDS) { - HILOGE("parse key failed"); - return nullptr; - } - - int32_t index = 0; - auto profileKey = std::make_unique(); - profileKey->udid = std::move(vec[index++]); - if (profileKey->udid.size() != DEVICE_ID_SIZE) { - HILOGE("parse udid failed"); - return nullptr; - } - int32_t type = 0; - if (!StrToInt(vec[index++], type)) { - HILOGE("parse type failed"); - return nullptr; - } - profileKey->type = static_cast(type); - profileKey->serviceId = std::move(vec[index]); - return profileKey; -} - -void ProfileChangeHandler::OnChange(const ChangeNotification& changeNotification) -{ - std::vector profileEntries; - const auto& insertedEntries = changeNotification.GetInsertEntries(); - const auto& updatedEntries = changeNotification.GetUpdateEntries(); - const auto& deletedEntries = changeNotification.GetDeleteEntries(); - int32_t numEntries = insertedEntries.size() + updatedEntries.size() + deletedEntries.size(); - profileEntries.reserve(numEntries); - HILOGI("numEntries = %{public}d", numEntries); - - int64_t begin = GetTickCount(); - Service2Index service2Index; - Entry entry; - if (!insertedEntries.empty()) { - entry = insertedEntries.front(); - ConvertEntry(insertedEntries, ProfileChangeType::INSERTED, profileEntries, service2Index); - } - if (!updatedEntries.empty()) { - entry = updatedEntries.front(); - ConvertEntry(updatedEntries, ProfileChangeType::UPDATED, profileEntries, service2Index); - } - if (!deletedEntries.empty()) { - entry = deletedEntries.front(); - ConvertEntry(deletedEntries, ProfileChangeType::DELETED, profileEntries, service2Index); - } - HILOGI("convert entry elapsedTime is %{public}" PRId64 " ms", GetTickCount() - begin); - - std::string udid; - auto profileKey = ProfileKey::Parse(entry.key.ToString()); - if (profileKey == nullptr) { - HILOGE("bad profile entry"); - return; - } - udid = std::move(profileKey->udid); - HILOGI("udid = %{public}s", DeviceProfileUtils::AnonymizeDeviceId(udid).c_str()); - std::string localUdid; - // won't fail - DpDeviceManager::GetInstance().GetLocalDeviceUdid(localUdid); - - std::string networkId; - if (!DpDeviceManager::GetInstance().TransformDeviceId(udid, networkId, - DeviceIdType::NETWORKID)) { - HILOGE("transform to networkid failed"); - } - - ProfileChangeNotification notification(profileEntries, networkId, localUdid == udid); - auto notifyTask = [this, notification = std::move(notification), - service2Index = std::move(service2Index)]() { - NotifyProfileChanged(notification, service2Index); - }; - std::lock_guard autoLock(notifierLock_); - if (eventHandler_ != nullptr && !eventHandler_->PostTask(notifyTask)) { - HILOGI("post task failed"); - } -} - -void ProfileChangeHandler::ConvertEntry(const std::vector& entries, - ProfileChangeType changeType, std::vector& profileEntries, - Service2Index& service2Index) -{ - for (const auto& entry : entries) { - auto profileKey = ProfileKey::Parse(entry.key.ToString()); - if (profileKey == nullptr || profileKey->type != KeyType::SERVICE) { - HILOGW("profileKey is invalid"); - continue; - } - - std::string trimmedKey = std::move(profileKey->serviceId); - HILOGI("key = %{public}s, state = %{public}u", trimmedKey.c_str(), - static_cast(changeType)); - service2Index.emplace(trimmedKey, profileEntries.size()); - profileEntries.emplace_back(std::move(trimmedKey), entry.value.ToString(), changeType); - HILOGD("value = %{public}s, state = %{public}u", - DeviceProfileUtils::AnonymizeString(entry.value.ToString()).c_str(), static_cast(changeType)); - } -} - -void ProfileChangeHandler::NotifyProfileChanged(const ProfileChangeNotification& changeNotification, - const Service2Index& service2Index) -{ - HILOGD("called"); - std::lock_guard autoLock(notifierLock_); - HILOGI("subscribers size = %{public}zu", profileEventSubscribeInfos_.size()); - struct RadarInfo info = { - .funcName = "NotifyProfileChanged", - .stageRes = static_cast(StageRes::STAGE_SUCC), - .hostName = kvNAME, - }; - if (!DpRadarHelper::GetInstance().ReportNotifyDataChange(info)) { - HILOGE("ReportNotifyDataChange failed"); - } - for (const auto& [notifier, subscribeInfo] : profileEventSubscribeInfos_) { - sptr profileEventNotifier = iface_cast(notifier); - if (profileEventNotifier == nullptr) { - HILOGE("cast to IProfileEventNotifier failed"); - continue; - } - - FilterInfo filterInfo; - FilterChangedProfileLocked(subscribeInfo, changeNotification, service2Index, filterInfo); - int64_t begin = GetTickCount(); - NotifyProfileChangedLocked(changeNotification, filterInfo, profileEventNotifier); - HILOGI("notify elapsedTime is %{public}" PRId64 " ms", GetTickCount() - begin); - } -} - -void ProfileChangeHandler::NotifyProfileChangedLocked(const ProfileChangeNotification& changeNotification, - const FilterInfo& filterInfo, const sptr& profileEventNotifier) -{ - if (profileEventNotifier == nullptr) { - HILOGE("profileEventNotifier is nullptr!"); - return; - } - if (!filterInfo.filtered) { - HILOGD("not filtered"); - profileEventNotifier->OnProfileChanged(changeNotification); - return; - } - - const auto& indexes = filterInfo.indexes; - // filtered but not found satisfied service - size_t size = indexes.size(); - if (size == 0) { - return; - } - - std::vector filteredEntries; - filteredEntries.reserve(size); - const auto& profileEntries = changeNotification.GetProfileEntries(); - for (auto index : indexes) { - filteredEntries.emplace_back(profileEntries[index]); - } - HILOGI("filtered with %{public}zu entries", size); - bool isLocal = changeNotification.IsLocal(); - std::string deviceId = changeNotification.GetDeviceId(); - ProfileChangeNotification filteredNotification(filteredEntries, deviceId, isLocal); - profileEventNotifier->OnProfileChanged(filteredNotification); -} - -void ProfileChangeHandler::FilterChangedProfileLocked(const SubscribeInfo& subscribeInfo, - const ProfileChangeNotification& changeNotification, - const Service2Index& service2Index, FilterInfo& filterInfo) -{ - const auto& extraInfo = subscribeInfo.extraInfo; - - // currently only support specific deviceId - std::string deviceId = extraInfo["deviceId"]; - if (!deviceId.empty()) { - filterInfo.filtered = true; - std::string networkId; - if (!DpDeviceManager::GetInstance().TransformDeviceId(deviceId, networkId, - DeviceIdType::NETWORKID)) { - HILOGE("transform to networkid failed"); - return; - } - if (networkId != changeNotification.GetDeviceId()) { - return; - } - } - - const auto& serviceIdsJson = extraInfo["serviceIds"]; - auto& indexes = filterInfo.indexes; - if (serviceIdsJson.empty()) { - return; - } - filterInfo.filtered = true; - for (const auto& serviceIdJson : serviceIdsJson) { - std::string serviceId = serviceIdJson; - HILOGI("serviceId = %{public}s", serviceId.c_str()); - auto iter = service2Index.find(serviceId); - if (iter != service2Index.end()) { - indexes.insert(iter->second); - } - } -} - -int32_t ProfileChangeHandler::Register() -{ - HILOGI("called"); - return DeviceProfileStorageManager::GetInstance().SubscribeKvStore(shared_from_this()); -} - -int32_t ProfileChangeHandler::Unregister() -{ - HILOGI("called"); - return DeviceProfileStorageManager::GetInstance().UnSubscribeKvStore(shared_from_this()); -} - -int32_t ProfileChangeHandler::Subscribe(const SubscribeInfo& subscribeInfo, - const sptr& profileEventNotifier) -{ - const auto& extraInfo = subscribeInfo.extraInfo; - const auto& serviceIdsJson = extraInfo["serviceIds"]; - std::vector serviceIds; - for (const auto& serviceIdJson : serviceIdsJson) { - std::string serviceId = serviceIdJson; - HILOGI("serviceId = %{public}s", serviceId.c_str()); - serviceIds.emplace_back(std::move(serviceId)); - } - - if (!AuthorityManager::GetInstance().CheckServicesAuthority(AuthValue::AUTH_R, - serviceIds)) { - return ERR_DP_PERMISSION_DENIED; - } - return ProfileEventHandler::Subscribe(subscribeInfo, profileEventNotifier); -} -} // namespace DeviceProfile -} // namespace OHOS diff --git a/old/services/core/src/subscribemanager/profile_event_handler.cpp b/old/services/core/src/subscribemanager/profile_event_handler.cpp deleted file mode 100644 index d7488973..00000000 --- a/old/services/core/src/subscribemanager/profile_event_handler.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. - * 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. - */ - -#include "profile_event_handler.h" - -#include "device_profile_errors.h" -#include "device_profile_log.h" -#include "device_profile_utils.h" - -namespace OHOS { -namespace DeviceProfile { -namespace { -const std::string TAG = "ProfileEventHandler"; -} - -bool ProfileEventHandler::Init() -{ - auto runner = AppExecFwk::EventRunner::Create(handlerName_); - eventHandler_ = std::make_shared(runner); - if (eventHandler_ == nullptr) { - return false; - } - return true; -} - -int32_t ProfileEventHandler::Subscribe(const SubscribeInfo& subscribeInfo, - const sptr& profileEventNotifier) -{ - std::lock_guard autoLock(notifierLock_); - auto iter = profileEventSubscribeInfos_.find(profileEventNotifier); - if (iter == profileEventSubscribeInfos_.end()) { - HILOGI("add subscribeInfo, deviceId = %{public}s", AnonymizeSubscribeInfo(subscribeInfo).c_str()); - profileEventSubscribeInfos_.emplace(profileEventNotifier, std::move(subscribeInfo)); - HILOGI("profileEventSubscribeInfos_ size = %{public}zu", profileEventSubscribeInfos_.size()); - for (const auto& entry : profileEventSubscribeInfos_) { - const SubscribeInfo& subscribeInfo = entry.second; - HILOGI("subscribeInfo: deviceId = %{public}s", AnonymizeSubscribeInfo(subscribeInfo).c_str()); - } - } else { - // just overwrite when the follow-ups subscribe with the same notifier - HILOGW("overwrite last subscribed info"); - HILOGI("update subscribeInfo, deviceId = %{public}s", AnonymizeSubscribeInfo(subscribeInfo).c_str()); - iter->second = std::move(subscribeInfo); - HILOGI("profileEventSubscribeInfos_ size = %{public}zu", profileEventSubscribeInfos_.size()); - for (const auto& entry : profileEventSubscribeInfos_) { - HILOGI("subscribeInfo: deviceId = %{public}s", AnonymizeSubscribeInfo(entry.second).c_str()); - } - } - - if (!isRegistered_) { - int32_t errCode = Register(); - if (errCode != ERR_OK) { - HILOGE("errCode = %{public}d", errCode); - return ERR_DP_SUBSCRIBE_FAILED; - } - isRegistered_ = true; - } - return ERR_OK; -} - -int32_t ProfileEventHandler::Unsubscribe(const sptr& profileEventNotifier) -{ - std::lock_guard autoLock(notifierLock_); - auto iter = profileEventSubscribeInfos_.find(profileEventNotifier); - if (iter == profileEventSubscribeInfos_.end()) { - HILOGW("not subscribe yet"); - return ERR_DP_NOT_SUBSCRIBED; - } - HILOGI("remove subscribeInfo, deviceId = %{public}s", AnonymizeSubscribeInfo(iter->second).c_str()); - profileEventSubscribeInfos_.erase(iter); - HILOGI("profileEventSubscribeInfos_ size = %{public}zu", profileEventSubscribeInfos_.size()); - for (const auto& entry : profileEventSubscribeInfos_) { - HILOGI("subscribeInfo: deviceId = %{public}s", AnonymizeSubscribeInfo(entry.second).c_str()); - } - if (profileEventSubscribeInfos_.empty()) { - int32_t errCode = Unregister(); - if (errCode != ERR_OK) { - HILOGE("errCode = %{public}d", errCode); - return ERR_DP_UNSUBSCRIBE_FAILED; - } - isRegistered_ = false; - } - return ERR_OK; -} - -void ProfileEventHandler::OnSubscriberDied(const sptr& profileEventNotifier) -{ - HILOGD("called"); - Unsubscribe(profileEventNotifier); -} - -bool ProfileEventHandler::IsRegistered() const -{ - return isRegistered_; -} - -std::string ProfileEventHandler::AnonymizeSubscribeInfo(const SubscribeInfo& subscribeInfo) -{ - if (!subscribeInfo.extraInfo.contains("deviceId") || !subscribeInfo.extraInfo["deviceId"].is_string()) { - return ""; - } - return DeviceProfileUtils::AnonymizeDeviceId(subscribeInfo.extraInfo["deviceId"].get()); -} -} // namespace DeviceProfile -} // namespace OHOS diff --git a/old/services/core/src/subscribemanager/profile_event_handler_factory.cpp b/old/services/core/src/subscribemanager/profile_event_handler_factory.cpp deleted file mode 100644 index b384bdd1..00000000 --- a/old/services/core/src/subscribemanager/profile_event_handler_factory.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. - * 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. - */ - -#include "profile_event_handler_factory.h" - -#include "device_profile_log.h" -#include "profile_change_handler.h" -#include "profile_sync_handler.h" - -namespace OHOS { -namespace DeviceProfile { -namespace { -const std::string TAG = "ProfileEventHandlerFactory"; -} - -IMPLEMENT_SINGLE_INSTANCE(ProfileEventHandlerFactory); - -ProfileEventHandlerFactory::ProfileEventHandlerFactory() -{ - handlersMap_[ProfileEvent::EVENT_SYNC_COMPLETED] = - &ProfileEventHandlerFactory::GetProfileSyncHandlerInner; - handlersMap_[ProfileEvent::EVENT_PROFILE_CHANGED] = - &ProfileEventHandlerFactory::GetProfileChangeHandlerInner; -} - -std::shared_ptr ProfileEventHandlerFactory::GetHandler(ProfileEvent profileEvent) -{ - HILOGI("get handler for event = %{public}u", static_cast(profileEvent)); - switch (static_cast(profileEvent)) { - case ProfileEvent::EVENT_SYNC_COMPLETED: - return ProfileEventHandlerFactory::GetProfileSyncHandlerInner(); - case ProfileEvent::EVENT_PROFILE_CHANGED: - return ProfileEventHandlerFactory::GetProfileChangeHandlerInner(); - default: - HILOGW("unknown request code, please check, code = %{public}u", static_cast(profileEvent)); - return nullptr; - } -} - -std::shared_ptr ProfileEventHandlerFactory::GetProfileChangeHandlerInner() -{ - return std::make_shared("profileChange"); -} - -std::shared_ptr ProfileEventHandlerFactory::GetProfileSyncHandlerInner() -{ - return std::make_shared("profileSync"); -} -} // namespace DeviceProfile -} // namespace OHOS diff --git a/old/services/core/src/subscribemanager/profile_event_notifier_proxy.cpp b/old/services/core/src/subscribemanager/profile_event_notifier_proxy.cpp deleted file mode 100644 index 7095bf1e..00000000 --- a/old/services/core/src/subscribemanager/profile_event_notifier_proxy.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ - -#include "profile_event_notifier_proxy.h" - -#include "device_profile_log.h" -#include "profile_event.h" - -namespace OHOS { -namespace DeviceProfile { -namespace { -const std::string TAG = "ProfileEventNotifierProxy"; -} - -ProfileEventNotifierProxy::ProfileEventNotifierProxy(const sptr& impl) - : IRemoteProxy(impl) -{} - -void ProfileEventNotifierProxy::OnSyncCompleted(const SyncResult& syncResults) -{ - HILOGI("called"); - MessageParcel data; - MessageParcel reply; - if (!data.WriteInterfaceToken(ProfileEventNotifierProxy::GetDescriptor())) { - HILOGE("write descriptor failed"); - return; - } - if (!data.WriteInt32(static_cast(syncResults.size()))) { - HILOGE("write syncResults size failed"); - return; - } - - for (const auto& [deviceId, syncResult] : syncResults) { - if (!data.WriteString(deviceId) || - !data.WriteInt32(static_cast(syncResult))) { - HILOGE("write syncResults failed"); - return; - } - } - MessageOption option { MessageOption::TF_ASYNC }; - int32_t errCode = Remote()->SendRequest(EVENT_SYNC_COMPLETED, data, reply, option); - if (errCode != ERR_OK) { - HILOGE("send request failed, errCode = %{public}d", errCode); - } -} - -void ProfileEventNotifierProxy::OnProfileChanged(const ProfileChangeNotification& changeNotification) -{ - HILOGI("called"); - MessageParcel data; - MessageParcel reply; - if (!data.WriteInterfaceToken(ProfileEventNotifierProxy::GetDescriptor())) { - HILOGE("write descriptor failed"); - return; - } - if (!changeNotification.Marshalling(data)) { - HILOGE("write profile change notification failed"); - return; - } - - MessageOption option { MessageOption::TF_ASYNC }; - int32_t errCode = Remote()->SendRequest(EVENT_PROFILE_CHANGED, data, reply, option); - if (errCode != ERR_OK) { - HILOGE("send request failed, errCode = %{public}d", errCode); - } -} -} // namespace DeviceProfile -} // namespace OHOS diff --git a/old/services/core/src/subscribemanager/profile_sync_handler.cpp b/old/services/core/src/subscribemanager/profile_sync_handler.cpp deleted file mode 100644 index bf6d4304..00000000 --- a/old/services/core/src/subscribemanager/profile_sync_handler.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. - * 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. - */ - -#include "profile_sync_handler.h" - -#include "device_profile_log.h" -#include "device_profile_storage_manager.h" -#include "device_profile_utils.h" -#include "dp_radar_helper.h" -#include "subscribe_manager.h" - -namespace OHOS { -namespace DeviceProfile { -using namespace OHOS::DistributedKv; - -namespace { -const std::string TAG = "ProfileSyncHandler"; -} - -void ProfileSyncHandler::SyncCompleted(const std::map& results) -{ - HILOGI("called"); - SyncResult syncResults; - for (const auto& [deviceId, status] : results) { - HILOGD("deviceId = %{public}s, status = %{public}d", - DeviceProfileUtils::AnonymizeDeviceId(deviceId).c_str(), status); - SyncStatus syncStauts = (status == Status::SUCCESS) ? SUCCEEDED : FAILED; - syncResults.emplace(deviceId, syncStauts); - } - - auto notifyTask = [this, syncResults = std::move(syncResults)]() { - NotifySyncCompleted(syncResults); - }; - std::lock_guard autoLock(notifierLock_); - if (eventHandler_ != nullptr && !eventHandler_->PostTask(notifyTask)) { - HILOGI("post task failed"); - } -} - -void ProfileSyncHandler::NotifySyncCompleted(const SyncResult& syncResults) -{ - struct RadarInfo info = { - .funcName = "NotifySyncCompleted", - .stageRes = static_cast(StageRes::STAGE_SUCC), - .bizState = static_cast(BizState::BIZ_STATE_END), - .hostName = kvNAME, - }; - if (!DpRadarHelper::GetInstance().ReportSyncDataCb(info)) { - HILOGE("ReportSyncDataCb failed"); - } - { - std::lock_guard autoLock(notifierLock_); - HILOGI("profileEventSubscribeInfos size %{public}zu", profileEventSubscribeInfos_.size()); - auto iter = profileEventSubscribeInfos_.begin(); - while (iter != profileEventSubscribeInfos_.end()) { - sptr profileEventNotifier = iface_cast(iter->first); - if (profileEventNotifier == nullptr) { - HILOGE("cast to IProfileEventNotifier failed"); - iter++; - } else { - profileEventNotifier->OnSyncCompleted(syncResults); - HILOGI("sync remove, deviceId = %{public}s", - ProfileEventHandler::AnonymizeSubscribeInfo(iter->second).c_str()); - profileEventSubscribeInfos_.erase(iter++); - HILOGI("profileEventSubscribeInfos_ size = %{public}zu", profileEventSubscribeInfos_.size()); - for (const auto& entry : profileEventSubscribeInfos_) { - HILOGI("subscribeInfo: deviceId = %{public}s", - ProfileEventHandler::AnonymizeSubscribeInfo(entry.second).c_str()); - } - } - } - } - DeviceProfileStorageManager::GetInstance().NotifySyncCompleted(); -} - -int32_t ProfileSyncHandler::Register() -{ - HILOGI("called"); - return DeviceProfileStorageManager::GetInstance().RegisterSyncCallback(shared_from_this()); -} - -int32_t ProfileSyncHandler::Unregister() -{ - HILOGI("called"); - return DeviceProfileStorageManager::GetInstance().UnRegisterSyncCallback(); -} -} // namespace DeviceProfile -} // namespace OHOS diff --git a/old/services/core/src/subscribemanager/subscribe_info.cpp b/old/services/core/src/subscribemanager/subscribe_info.cpp deleted file mode 100644 index e240da2e..00000000 --- a/old/services/core/src/subscribemanager/subscribe_info.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. - * 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. - */ - -#include "subscribe_info.h" - -#include -#include -#include -#include -#include -#include -#include - -#include "device_profile_log.h" -#include "device_profile_utils.h" -#include "parcel.h" -#include "parcel_helper.h" -#include "profile_event.h" - -namespace OHOS { -namespace DeviceProfile { -namespace { -const std::string TAG = "SubscribeInfo"; -} - -bool SubscribeInfo::Marshalling(Parcel& parcel) const -{ - PARCEL_WRITE_HELPER_RET(parcel, Uint32, profileEvent, false); - PARCEL_WRITE_HELPER_RET(parcel, String, extraInfo.dump(), false); - return true; -} - -bool SubscribeInfo::Unmarshalling(Parcel& parcel) -{ - profileEvent = static_cast(parcel.ReadUint32()); - if (profileEvent >= EVENT_PROFILE_END || profileEvent == EVENT_UNKNOWN) { - HILOGE("invalid profile event, %{public}u", static_cast(profileEvent)); - return false; - } - std::string value = parcel.ReadString(); - extraInfo = ExtraInfo::parse(value, nullptr, false); - if (extraInfo.is_discarded()) { - HILOGE("parse extra info failed, %{public}s", DeviceProfileUtils::AnonymizeString(value).c_str()); - return false; - } - return true; -} - -bool SubscribeInfo::operator!=(const SubscribeInfo& rhs) const -{ - return ((profileEvent != rhs.profileEvent) || (extraInfo != rhs.extraInfo)); -} -} // namespace DeviceProfile -} // namespace OHOS diff --git a/old/services/core/src/subscribemanager/subscribe_info_checker.cpp b/old/services/core/src/subscribemanager/subscribe_info_checker.cpp deleted file mode 100644 index d1b93cd3..00000000 --- a/old/services/core/src/subscribemanager/subscribe_info_checker.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. - * 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. - */ - -#include "subscribe_info_checker.h" - -#include "device_profile_log.h" -#include "profile_event.h" - -namespace OHOS { -namespace DeviceProfile { -namespace { -const std::string TAG = "SubscribeInfoChecker"; -} - -IMPLEMENT_SINGLE_INSTANCE(SubscribeInfoChecker); - -SubscribeInfoChecker::SubscribeInfoChecker() -{ - checkersMap_[EVENT_SYNC_COMPLETED] = &SubscribeInfoChecker::CheckSyncEventInner; - checkersMap_[EVENT_PROFILE_CHANGED] = &SubscribeInfoChecker::CheckProfileChangeInner; -} - -bool SubscribeInfoChecker::Check(const std::list& subscribeInfos) -{ - auto checker = [this](const auto& subscribeInfo) { - auto profileEvent = subscribeInfo.profileEvent; - switch (static_cast(profileEvent)) { - case ProfileEvent::EVENT_SYNC_COMPLETED: - return SubscribeInfoChecker::CheckSyncEventInner(subscribeInfo); - case ProfileEvent::EVENT_PROFILE_CHANGED: - return SubscribeInfoChecker::CheckProfileChangeInner(subscribeInfo); - default: - HILOGE("unknown profile event = %{public}u", static_cast(profileEvent)); - return false; - } - }; - return std::all_of(subscribeInfos.begin(), subscribeInfos.end(), checker); -} - -bool SubscribeInfoChecker::CheckSyncEventInner([[maybe_unused]] const SubscribeInfo& subscribeInfo) -{ - // currently no need to check for sync event - return true; -} - -bool SubscribeInfoChecker::CheckProfileChangeInner(const SubscribeInfo& subscribeInfo) -{ - const ExtraInfo& extraInfo = subscribeInfo.extraInfo; - const auto& deviceIdJson = extraInfo["deviceId"]; - if (deviceIdJson == nullptr) { - return false; - } - HILOGD("check deviceId"); - if (deviceIdJson.type() != ExtraInfo::value_t::string) { - return false; - } - - const auto& serviceIdsJson = extraInfo["serviceIds"]; - if (serviceIdsJson == nullptr) { - return false; - } - HILOGD("check serviceIds"); - auto type = serviceIdsJson.type(); - if (type != ExtraInfo::value_t::array) { - return false; - } else { - return std::all_of(serviceIdsJson.begin(), serviceIdsJson.end(), - [](const auto& serviceIdJson) { return serviceIdJson.type() == ExtraInfo::value_t::string; }); - } - return true; -} -} // namespace DeviceProfile -} // namespace OHOS \ No newline at end of file diff --git a/old/services/core/src/subscribemanager/subscribe_manager.cpp b/old/services/core/src/subscribemanager/subscribe_manager.cpp deleted file mode 100644 index a3bca60b..00000000 --- a/old/services/core/src/subscribemanager/subscribe_manager.cpp +++ /dev/null @@ -1,237 +0,0 @@ -/* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. - * 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. - */ - -#include "subscribe_manager.h" - -#include "ipc_object_proxy.h" -#include "ipc_skeleton.h" - -#include "device_profile_errors.h" -#include "device_profile_log.h" -#include "device_profile_storage_manager.h" -#include "dp_radar_helper.h" -#include "profile_change_handler.h" -#include "profile_event_handler_factory.h" -#include "subscribe_info_checker.h" -#include "subscriber_death_recipient.h" - -namespace OHOS { -namespace DeviceProfile { -namespace { -const std::string TAG = "SubscribeManager"; - -constexpr int32_t MAX_SUBSCRIBS_PER_UID = 100; -} - -IMPLEMENT_SINGLE_INSTANCE(SubscribeManager); - -bool SubscribeManager::Init() -{ - subscriberDeathRecipient_ = sptr( - new (std::nothrow) SubscriberDeathRecipient); - if (subscriberDeathRecipient_ == nullptr) { - HILOGE("null death recipient"); - return false; - } - HILOGI("init succeeded"); - return true; -} - -int32_t SubscribeManager::SubscribeProfileEvents(const std::list& subscribeInfos, - const sptr& profileEventNotifier, - std::list& failedEvents) -{ - HILOGI("called"); - if (!SubscribeInfoChecker::GetInstance().Check(subscribeInfos)) { - HILOGE("SubscribeInfo check failed"); - return ERR_DP_INVALID_PARAMS; - } - - int32_t callingUid = IPCSkeleton::GetCallingUid(); - HILOGI("uid %{public}d subscribe", callingUid); - std::lock_guard autoLock(handlerLock_); - ProfileEvents subProfileEvents; - std::shared_ptr handler; - for (const auto& subscribeInfo : subscribeInfos) { - auto profileEvent = subscribeInfo.profileEvent; - auto iter = handlersMap_.find(profileEvent); - if (iter == handlersMap_.end()) { - handler = ProfileEventHandlerFactory::GetInstance().GetHandler(profileEvent); - if (handler == nullptr || !handler->Init()) { - failedEvents.emplace_back(profileEvent); - HILOGW("get or init handler for event:%{public}d failed", profileEvent); - continue; - } - handlersMap_.emplace(profileEvent, handler); - } else { - handler = iter->second; - if (handler == nullptr || !handler->Init()) { - failedEvents.emplace_back(profileEvent); - HILOGW("get or init handler for event:%{public}d failed", profileEvent); - continue; - } - } - if (handler->Subscribe(subscribeInfo, profileEventNotifier) != ERR_OK) { - HILOGE("subscribe event:%{public}d failed", profileEvent); - failedEvents.emplace_back(profileEvent); - } else { - subProfileEvents.set(static_cast(profileEvent)); - } - } - if (!subProfileEvents.none()) { - TryAddNotifierLocked(profileEventNotifier, subProfileEvents); - } - struct RadarInfo info = { - .stageRes = failedEvents.empty() ? - static_cast(StageRes::STAGE_IDLE) : static_cast(StageRes::STAGE_FAIL), - .errCode = ERR_DP_SUBSCRIBE_FAILED, - }; - if (!DpRadarHelper::GetInstance().ReportSubscribeData(info)) { - HILOGE("ReportSubscribeData failed"); - } - return failedEvents.empty() ? ERR_OK : ERR_DP_SUBSCRIBE_FAILED; -} - -int32_t SubscribeManager::UnsubscribeProfileEvents(const std::list& profileEvents, - const sptr& profileEventNotifier, - std::list& failedEvents) -{ - HILOGI("called"); - std::lock_guard autoLock(handlerLock_); - ProfileEvents unsubProfileEvents; - for (auto profileEvent : profileEvents) { - auto iter = handlersMap_.find(profileEvent); - if (iter == handlersMap_.end()) { - HILOGW("not find event:%{public}u", static_cast(profileEvent)); - continue; - } - auto handler = iter->second; - if (handler == nullptr || handler->Unsubscribe(profileEventNotifier) != ERR_OK) { - HILOGE("unsubscribe event:%{public}d failed", profileEvent); - failedEvents.emplace_back(profileEvent); - } else { - unsubProfileEvents.set(static_cast(profileEvent)); - } - } - if (!unsubProfileEvents.none()) { - TryRemoveNotiferLocked(profileEventNotifier, unsubProfileEvents); - } - struct RadarInfo info = { - .funcName = "UnsubscribeProfileEvents", - .stageRes = failedEvents.empty() ? - static_cast(StageRes::STAGE_SUCC) : static_cast(StageRes::STAGE_FAIL), - .toCallPkg = kvNAME, - .errCode = ERR_DP_UNSUBSCRIBE_FAILED, - }; - if (!DpRadarHelper::GetInstance().ReportUnsbscribeData(info)) { - HILOGE("ReportUnsbscribeData failed"); - } - return failedEvents.empty() ? ERR_OK : ERR_DP_UNSUBSCRIBE_FAILED; -} - -void SubscribeManager::TryAddNotifierLocked(const sptr& profileEventNotifier, - const ProfileEvents& subProfileEvents) -{ - if (profileEventNotifier == nullptr) { - HILOGE("profileEventNotifier is nullptr!"); - return; - } - auto iter = notifiersMap_.find(profileEventNotifier); - if (iter == notifiersMap_.end()) { - int32_t callingUid = IPCSkeleton::GetCallingUid(); - NotifierInfo notifierInfo = { callingUid, subProfileEvents}; - notifiersMap_.emplace(profileEventNotifier, std::move(notifierInfo)); - profileEventNotifier->AddDeathRecipient(subscriberDeathRecipient_); - HILOGI("notifiers size = %{public}zu", notifiersMap_.size()); - IncSubsOfUidLocked(callingUid); - } else { - iter->second.profileEvents |= subProfileEvents; - } -} - -void SubscribeManager::TryRemoveNotiferLocked(const sptr& profileEventNotifier, - const ProfileEvents& unsubProfileEvents) -{ - if (profileEventNotifier == nullptr) { - HILOGE("profileEventNotifier is nullptr!"); - return; - } - auto iter = notifiersMap_.find(profileEventNotifier); - if (iter == notifiersMap_.end()) { - return; - } - auto& subProfileEvents = iter->second.profileEvents; - subProfileEvents &= ~unsubProfileEvents; - if (subProfileEvents.none()) { - int32_t callingUid = iter->second.callingUid; - profileEventNotifier->RemoveDeathRecipient(subscriberDeathRecipient_); - notifiersMap_.erase(iter); - HILOGI("notifiers size = %{public}zu", notifiersMap_.size()); - DecSubsOfUidLocked(callingUid); - return; - } -} - -void SubscribeManager::IncSubsOfUidLocked(int32_t uid) -{ - if (uidSubsMap_.find(uid) != uidSubsMap_.end()) { - ++uidSubsMap_[uid]; - } else { - uidSubsMap_[uid] = 1; - } - HILOGI("uid %{public}d has %{public}u subscription(s)", uid, uidSubsMap_[uid]); -} - -void SubscribeManager::DecSubsOfUidLocked(int32_t uid) -{ - auto iter = uidSubsMap_.find(uid); - if (iter != uidSubsMap_.end()) { - auto& numSubs = iter->second; - if (--numSubs == 0) { - uidSubsMap_.erase(iter); - } - HILOGI("uid %{public}d subscription(s) is %{public}u", uid, numSubs); - } -} - -bool SubscribeManager::CheckSubsOfUid(int32_t uid) -{ - std::lock_guard autoLock(handlerLock_); - auto iter = uidSubsMap_.find(uid); - if (iter == uidSubsMap_.end()) { - return true; - } - if (iter->second >= MAX_SUBSCRIBS_PER_UID) { - return false; - } - return true; -} - -void SubscribeManager::OnSubscriberDied(const sptr& profileEventNotifier) -{ - HILOGI("called"); - DeviceProfileStorageManager::GetInstance().NotifySubscriberDied(profileEventNotifier); - std::lock_guard autoLock(handlerLock_); - auto iter = notifiersMap_.find(profileEventNotifier); - if (iter != notifiersMap_.end()) { - DecSubsOfUidLocked(iter->second.callingUid); - notifiersMap_.erase(iter); - } - for (const auto& [_, handler] : handlersMap_) { - handler->OnSubscriberDied(profileEventNotifier); - } -} -} // namespace DeviceProfile -} // namespace OHOS diff --git a/old/services/core/src/subscribemanager/subscriber_death_recipient.cpp b/old/services/core/src/subscribemanager/subscriber_death_recipient.cpp deleted file mode 100644 index 73253e0d..00000000 --- a/old/services/core/src/subscribemanager/subscriber_death_recipient.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ - -#include "subscriber_death_recipient.h" - -#include "subscribe_manager.h" - -namespace OHOS { -namespace DeviceProfile { -void SubscriberDeathRecipient::OnRemoteDied(const wptr& remote) -{ - SubscribeManager::GetInstance().OnSubscriberDied(remote.promote()); -} -} // namespace DeviceProfile -} // namespace OHOS \ No newline at end of file diff --git a/old/services/core/src/sync_options.cpp b/old/services/core/src/sync_options.cpp deleted file mode 100644 index d048fe26..00000000 --- a/old/services/core/src/sync_options.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * 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. - */ - -#include "sync_options.h" - -#include -#include -#include - -#include "device_profile_log.h" -#include "parcel.h" -#include "parcel_helper.h" - -namespace OHOS { -namespace DeviceProfile { -namespace { -const std::string TAG = "SyncOptions"; -constexpr int32_t MAX_DEVICE_LEN = 1000000; -} - -const std::list& SyncOptions::GetDeviceList() const -{ - return syncDevIds_; -} - -void SyncOptions::AddDevice(const std::string& deviceId) -{ - syncDevIds_.emplace_back(deviceId); -} - -SyncMode SyncOptions::GetSyncMode() const -{ - return syncMode_; -} - -void SyncOptions::SetSyncMode(SyncMode mode) -{ - syncMode_ = mode; -} - -bool SyncOptions::Marshalling(Parcel& parcel) const -{ - PARCEL_WRITE_HELPER_RET(parcel, Int32, static_cast(syncMode_), false); - PARCEL_WRITE_HELPER_RET(parcel, Int32, static_cast(syncDevIds_.size()), false); - for (const auto& deviceId : syncDevIds_) { - PARCEL_WRITE_HELPER_RET(parcel, String, deviceId, false); - } - return true; -} - -bool SyncOptions::Unmarshalling(Parcel& parcel) -{ - int32_t mode = 0; - PARCEL_READ_HELPER_RET(parcel, Int32, mode, false); - syncMode_ = static_cast(mode); - int32_t size = 0; - PARCEL_READ_HELPER_RET(parcel, Int32, size, false); - if (size > MAX_DEVICE_LEN) { - return false; - } - for (int32_t i = 0; i < size; i++) { - std::string deviceId; - PARCEL_READ_HELPER_RET(parcel, String, deviceId, false); - syncDevIds_.emplace_back(deviceId); - } - return true; -} -} // namespace DeviceProfile -} // namespace OHOS \ No newline at end of file diff --git a/old/services/core/test/BUILD.gn b/old/services/core/test/BUILD.gn deleted file mode 100644 index bb5dafbb..00000000 --- a/old/services/core/test/BUILD.gn +++ /dev/null @@ -1,295 +0,0 @@ -# Copyright (c) 2021-2024 Huawei Device Co., Ltd. -# 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. - -import("//build/ohos.gni") -import("//build/ohos_var.gni") -import("//build/test.gni") -import("//foundation/deviceprofile/device_info_manager/deviceprofile.gni") - -module_output_path = "device_info_manager/device_info_manager" - -device_profile_configs = [ - "${old_device_profile_service}/core:device_info_manager_config", - "${old_device_profile_test}/resource:coverage_flags", -] - -device_profile_deps = [ - "${old_device_profile_innerkits}/core:distributed_device_profile_client", - "${old_device_profile_service}/core:distributed_device_profile", -] - -device_profile_external_deps = [ - "ability_base:want", - "access_token:libaccesstoken_sdk", - "access_token:libnativetoken", - "access_token:libtoken_setproc", - "c_utils:utils", - "device_auth:deviceauth_sdk", - "device_manager:devicemanagersdk", - "dsoftbus:softbus_client", - "eventhandler:libeventhandler", - "googletest:gtest_main", - "hilog:libhilog", - "hisysevent:libhisysevent", - "ipc:ipc_core", - "kv_store:distributeddata_inner", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - "syscap_codec:syscap_interface_shared", -] - -ohos_unittest("profile_crud_test") { - module_out_path = module_output_path - - sources = [ - "unittest/profile_crud_test.cpp", - "unittest/test_util.cpp", - ] - configs = device_profile_configs - deps = device_profile_deps - external_deps = device_profile_external_deps - part_name = "device_info_manager" - subsystem_name = "deviceprofile" -} - -ohos_unittest("profile_dm_test") { - module_out_path = module_output_path - - sources = [ "unittest/profile_dm_test.cpp" ] - configs = device_profile_configs - deps = device_profile_deps - deps += [ "${device_profile_service}:distributed_device_profile_svr" ] - external_deps = device_profile_external_deps - part_name = "device_info_manager" - subsystem_name = "deviceprofile" -} - -ohos_unittest("profile_storage_test") { - module_out_path = module_output_path - - sources = [ "unittest/profile_storage_test.cpp" ] - configs = device_profile_configs - deps = device_profile_deps - external_deps = device_profile_external_deps - part_name = "device_info_manager" - subsystem_name = "deviceprofile" -} - -ohos_unittest("profile_sync_test") { - module_out_path = module_output_path - - sources = [ "unittest/profile_sync_test.cpp" ] - configs = device_profile_configs - deps = device_profile_deps - external_deps = device_profile_external_deps - part_name = "device_info_manager" - subsystem_name = "deviceprofile" -} - -ohos_unittest("event_subscribe_test") { - module_out_path = module_output_path - - sources = [ "unittest/event_subscribe_test.cpp" ] - configs = device_profile_configs - deps = device_profile_deps - external_deps = device_profile_external_deps - part_name = "device_info_manager" - subsystem_name = "deviceprofile" -} - -ohos_unittest("profile_authority_test") { - module_out_path = module_output_path - - sources = [ - "unittest/profile_authority_test.cpp", - "unittest/test_util.cpp", - ] - configs = device_profile_configs - deps = device_profile_deps - external_deps = device_profile_external_deps - part_name = "device_info_manager" - subsystem_name = "deviceprofile" -} - -ohos_unittest("content_sensor_test") { - module_out_path = module_output_path - - sources = [ "unittest/content_sensor_test.cpp" ] - configs = device_profile_configs - deps = device_profile_deps - external_deps = device_profile_external_deps - part_name = "device_info_manager" - subsystem_name = "deviceprofile" -} - -ohos_unittest("profile_change_notification_test") { - module_out_path = module_output_path - - sources = [ "unittest/profile_change_notification_test.cpp" ] - configs = device_profile_configs - deps = device_profile_deps - external_deps = device_profile_external_deps - part_name = "device_info_manager" - subsystem_name = "deviceprofile" -} - -ohos_unittest("profile_entry_test") { - module_out_path = module_output_path - - sources = [ "unittest/profile_entry_test.cpp" ] - configs = device_profile_configs - deps = device_profile_deps - external_deps = device_profile_external_deps - part_name = "device_info_manager" - subsystem_name = "deviceprofile" -} - -ohos_unittest("profile_proxy_test") { - module_out_path = module_output_path - - sources = [ "unittest/profile_proxy_test.cpp" ] - configs = device_profile_configs - deps = device_profile_deps - external_deps = device_profile_external_deps - part_name = "device_info_manager" - subsystem_name = "deviceprofile" -} - -ohos_unittest("service_profile_test") { - module_out_path = module_output_path - - sources = [ "unittest/service_profile_test.cpp" ] - configs = device_profile_configs - deps = device_profile_deps - external_deps = device_profile_external_deps - part_name = "device_info_manager" - subsystem_name = "deviceprofile" -} - -ohos_unittest("subscribe_info_test") { - module_out_path = module_output_path - - sources = [ "unittest/subscribe_info_test.cpp" ] - configs = device_profile_configs - deps = device_profile_deps - external_deps = device_profile_external_deps - part_name = "device_info_manager" - subsystem_name = "deviceprofile" -} - -ohos_unittest("subscribe_manager_test") { - module_out_path = module_output_path - - sources = [ "unittest/subscribe_manager_test.cpp" ] - configs = device_profile_configs - deps = device_profile_deps - external_deps = device_profile_external_deps - part_name = "device_info_manager" - subsystem_name = "deviceprofile" -} - -ohos_unittest("profile_change_handler_test") { - module_out_path = module_output_path - - sources = [ "unittest/profile_change_handler_test.cpp" ] - configs = device_profile_configs - deps = device_profile_deps - external_deps = device_profile_external_deps - part_name = "device_info_manager" - subsystem_name = "deviceprofile" -} - -ohos_unittest("subscribe_info_checker_test") { - module_out_path = module_output_path - - sources = [ "unittest/subscribe_info_checker_test.cpp" ] - configs = device_profile_configs - deps = device_profile_deps - external_deps = device_profile_external_deps - part_name = "device_info_manager" - subsystem_name = "deviceprofile" -} - -ohos_unittest("device_profile_dfx_test") { - module_out_path = module_output_path - - sources = [ "unittest/device_profile_dfx_test.cpp" ] - configs = device_profile_configs - deps = device_profile_deps - external_deps = device_profile_external_deps - part_name = "device_info_manager" - subsystem_name = "deviceprofile" -} - -ohos_unittest("device_profile_utils_test") { - module_out_path = module_output_path - - sources = [ "unittest/device_profile_utils_test.cpp" ] - configs = device_profile_configs - deps = device_profile_deps - external_deps = device_profile_external_deps - part_name = "device_info_manager" - subsystem_name = "deviceprofile" -} - -ohos_unittest("profile_event_notifier_proxy_test") { - module_out_path = module_output_path - - sources = [ "unittest/profile_event_notifier_proxy_test.cpp" ] - configs = device_profile_configs - deps = device_profile_deps - external_deps = device_profile_external_deps - part_name = "device_info_manager" - subsystem_name = "deviceprofile" -} - -ohos_unittest("distributed_device_profile_stub_test") { - module_out_path = module_output_path - cflags = [ - "-Dprivate=public", - "-Dprotected=public", - ] - sources = [ "unittest/distributed_device_profile_stub_test.cpp" ] - configs = device_profile_configs - deps = device_profile_deps - external_deps = device_profile_external_deps - part_name = "device_info_manager" - subsystem_name = "deviceprofile" -} - -group("unittest") { - testonly = true - deps = [ - ":content_sensor_test", - ":device_profile_dfx_test", - ":device_profile_utils_test", - ":distributed_device_profile_stub_test", - ":event_subscribe_test", - ":profile_authority_test", - ":profile_change_handler_test", - ":profile_change_notification_test", - ":profile_dm_test", - ":profile_entry_test", - ":profile_event_notifier_proxy_test", - ":profile_proxy_test", - ":profile_storage_test", - ":profile_sync_test", - ":service_profile_test", - ":subscribe_info_checker_test", - ":subscribe_info_test", - ":subscribe_manager_test", - ] - if (!device_info_manager_switch_static_disable) { - deps += [ ":profile_crud_test" ] - } -} diff --git a/old/services/core/test/fuzztest/BUILD.gn b/old/services/core/test/fuzztest/BUILD.gn deleted file mode 100644 index 69ccab6a..00000000 --- a/old/services/core/test/fuzztest/BUILD.gn +++ /dev/null @@ -1,26 +0,0 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. -# 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. - -group("fuzztest") { - testonly = true - - deps = [ - "deviceprofile_fuzzer:fuzztest", - "dumplocalprofile_fuzzer:fuzztest", - "getdeviceprofile_fuzzer:fuzztest", - "putdeviceprofile_fuzzer:fuzztest", - "putdeviceprofileinner_fuzzer:fuzztest", - "subscribeprofileeventinner_fuzzer:fuzztest", - "syncdeviceprofileinner_fuzzer:fuzztest", - ] -} diff --git a/old/services/core/test/fuzztest/deviceprofile_fuzzer/BUILD.gn b/old/services/core/test/fuzztest/deviceprofile_fuzzer/BUILD.gn deleted file mode 100644 index 2a763154..00000000 --- a/old/services/core/test/fuzztest/deviceprofile_fuzzer/BUILD.gn +++ /dev/null @@ -1,71 +0,0 @@ -# Copyright (c) 2022-2023 Huawei Device Co., Ltd. -# 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. - -#####################hydra-fuzz################### -import("//build/config/features.gni") -import("//build/ohos.gni") -import("//build/test.gni") -import("//foundation/deviceprofile/device_info_manager/deviceprofile.gni") -module_output_path = old_fuzz_test_output_path - -device_profile_configs = [ - "${old_device_profile_service}/core:device_info_manager_config", - "${old_device_profile_test}/resource:coverage_flags", -] - -device_profile_deps = [ - "${old_device_profile_innerkits}/core:distributed_device_profile_client", - "${old_device_profile_service}/core:distributed_device_profile", -] - -##############################fuzztest########################################## -ohos_fuzztest("DeviceProfileFuzzTest") { - module_out_path = module_output_path - - fuzz_config_file = - "${old_device_profile_service}/core/test/fuzztest/deviceprofile_fuzzer" - - cflags = [ - "-g", - "-O0", - "-Dprivate=public", - "-Dprotected=public", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - - configs = device_profile_configs - - sources = [ "device_profile_fuzzer.cpp" ] - - deps = device_profile_deps - - external_deps = [ - "access_token:libaccesstoken_sdk", - "access_token:libnativetoken", - "access_token:libtoken_setproc", - "c_utils:utils", - "eventhandler:libeventhandler", - "hilog:libhilog", - "ipc:ipc_core", - "json:nlohmann_json_static", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - ] -} - -group("fuzztest") { - testonly = true - - deps = [ ":DeviceProfileFuzzTest" ] -} diff --git a/old/services/core/test/fuzztest/deviceprofile_fuzzer/corpus/init b/old/services/core/test/fuzztest/deviceprofile_fuzzer/corpus/init deleted file mode 100644 index 8eb5a7d6..00000000 --- a/old/services/core/test/fuzztest/deviceprofile_fuzzer/corpus/init +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * 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. - */ - -FUZZ \ No newline at end of file diff --git a/old/services/core/test/fuzztest/deviceprofile_fuzzer/device_profile_fuzzer.cpp b/old/services/core/test/fuzztest/deviceprofile_fuzzer/device_profile_fuzzer.cpp deleted file mode 100644 index c6bdeafd..00000000 --- a/old/services/core/test/fuzztest/deviceprofile_fuzzer/device_profile_fuzzer.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * 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. - */ - -#include "device_profile_fuzzer.h" - -#include "iremote_stub.h" -#include "distributed_device_profile_service.h" - -#include -#include -#include -#include -#include -#include -#include -#include "sys/stat.h" -#include "accesstoken_kit.h" -#include "nativetoken_kit.h" -#include "token_setproc.h" -#include "distributed_device_profile_enums.h" - -namespace OHOS { -namespace DeviceProfile { -namespace { - constexpr size_t THRESHOLD = 10; - constexpr int32_t OFFSET = 4; - constexpr int32_t ZERO_BIT = 0; - constexpr int32_t FIRST_BIT = 1; - constexpr int32_t SECOND_BIT = 2; - constexpr int32_t THIRD_BIT = 3; - constexpr int32_t ZERO_MOVE_LEN = 24; - constexpr int32_t FIRST_MOVE_LEN = 16; - constexpr int32_t SECOND_MOVE_LEN = 8; - bool g_flag = false; - const std::u16string DP_INTERFACE_TOKEN = u"OHOS.DeviceProfile.IDistributedDeviceProfile"; -} - -uint32_t Convert2Uint32(const uint8_t* ptr) -{ - if (ptr == nullptr) { - return 0; - } - return (ptr[ZERO_BIT] << ZERO_MOVE_LEN) | (ptr[FIRST_BIT] << FIRST_MOVE_LEN) | - (ptr[SECOND_BIT] << SECOND_MOVE_LEN) | (ptr[THIRD_BIT]); -} - -void MockPermission(const char* processName) -{ - static const char *perms[] = { - "ohos.permission.DISTRIBUTED_DATASYNC" - }; - - uint64_t tokenId; - NativeTokenInfoParams infoInstance = { - .dcapsNum = 0, - .permsNum = 1, - .aclsNum = 0, - .dcaps = nullptr, - .perms = perms, - .acls = nullptr, - .processName = processName, - .aplStr = "system_core", - }; - tokenId = GetAccessTokenId(&infoInstance); - SetSelfTokenID(tokenId); - OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo(); -} - -void FuzzDeviceProfile(const uint8_t* rawData, size_t size) -{ - MockPermission("distributedsched"); - uint32_t code = Convert2Uint32(rawData); - rawData = rawData + OFFSET; - size = size - OFFSET; - MessageParcel data; - data.WriteInterfaceToken(DP_INTERFACE_TOKEN); - data.WriteBuffer(rawData, size); - data.RewindRead(0); - MessageParcel reply; - MessageOption option; - std::string baseDir = "/data/service/el1/public/database/distributed_device_profile_service"; - mkdir(baseDir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); - if (!g_flag) { - DistributedDeviceProfileService::GetInstance().Init(); - g_flag = true; - } - DistributedDeviceProfileService::GetInstance().OnRemoteRequest(code % - static_cast(DistributedDeviceProfile::DPInterfaceCode::MAX), data, reply, option); - DistributedDeviceProfileService::GetInstance().NotifyAclEventInner(code % - static_cast(DistributedDeviceProfile::DPInterfaceCode::MAX), data, reply, option); - DistributedDeviceProfileService::GetInstance().NotifyOldEventInner(code % - static_cast(DistributedDeviceProfile::DPInterfaceCode::MAX), data, reply, option); - DistributedDeviceProfileService::GetInstance().NotifyNewEventInner(code % - static_cast(DistributedDeviceProfile::DPInterfaceCode::MAX), data, reply, option); -} -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - if (size < OHOS::DeviceProfile::THRESHOLD) { - return 0; - } - OHOS::DeviceProfile::FuzzDeviceProfile(data, size); - return 0; -} \ No newline at end of file diff --git a/old/services/core/test/fuzztest/deviceprofile_fuzzer/device_profile_fuzzer.h b/old/services/core/test/fuzztest/deviceprofile_fuzzer/device_profile_fuzzer.h deleted file mode 100644 index 6015946d..00000000 --- a/old/services/core/test/fuzztest/deviceprofile_fuzzer/device_profile_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef DEVICE_PROFILE_FUZZER_H -#define DEVICE_PROFILE_FUZZER_H - -#define FUZZ_PROJECT_NAME "device_profile_fuzzer" - -#endif \ No newline at end of file diff --git a/old/services/core/test/fuzztest/deviceprofile_fuzzer/project.xml b/old/services/core/test/fuzztest/deviceprofile_fuzzer/project.xml deleted file mode 100644 index 6e8ad2cf..00000000 --- a/old/services/core/test/fuzztest/deviceprofile_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/old/services/core/test/fuzztest/dumplocalprofile_fuzzer/BUILD.gn b/old/services/core/test/fuzztest/dumplocalprofile_fuzzer/BUILD.gn deleted file mode 100755 index c4ce0793..00000000 --- a/old/services/core/test/fuzztest/dumplocalprofile_fuzzer/BUILD.gn +++ /dev/null @@ -1,73 +0,0 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. -# 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. - -#####################hydra-fuzz################### -import("//build/config/features.gni") -import("//build/ohos.gni") -import("//build/test.gni") -import("//foundation/deviceprofile/device_info_manager/deviceprofile.gni") -module_output_path = old_fuzz_test_output_path - -device_profile_configs = [ - "${old_device_profile_service}/core:device_info_manager_config", - "${old_device_profile_test}/resource:coverage_flags", -] - -device_profile_external_deps = [ - "access_token:libaccesstoken_sdk", - "c_utils:utils", - "device_auth:deviceauth_sdk", - "device_manager:devicemanagersdk", - "dsoftbus:softbus_client", - "eventhandler:libeventhandler", - "hilog:libhilog", - "hisysevent:libhisysevent", - "ipc:ipc_core", - "json:nlohmann_json_static", - "kv_store:distributeddata_inner", - "syscap_codec:syscap_interface_shared", -] - -device_profile_deps = [ - "${old_device_profile_innerkits}/core:distributed_device_profile_client", - "${old_device_profile_service}/core:distributed_device_profile", -] - -##############################fuzztest########################################## -ohos_fuzztest("DumpLocalProfileFuzzTest") { - module_out_path = module_output_path - - fuzz_config_file = - "${old_device_profile_service}/core/test/fuzztest/dumplocalprofile_fuzzer" - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - - configs = device_profile_configs - - sources = [ "dumplocalprofile_fuzzer.cpp" ] - - deps = device_profile_deps - - external_deps = device_profile_external_deps -} - -group("fuzztest") { - testonly = true - - deps = [ ":DumpLocalProfileFuzzTest" ] -} diff --git a/old/services/core/test/fuzztest/dumplocalprofile_fuzzer/corpus/init b/old/services/core/test/fuzztest/dumplocalprofile_fuzzer/corpus/init deleted file mode 100644 index 2b595da0..00000000 --- a/old/services/core/test/fuzztest/dumplocalprofile_fuzzer/corpus/init +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * 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. - */ - -FUZZ \ No newline at end of file diff --git a/old/services/core/test/fuzztest/dumplocalprofile_fuzzer/dumplocalprofile_fuzzer.cpp b/old/services/core/test/fuzztest/dumplocalprofile_fuzzer/dumplocalprofile_fuzzer.cpp deleted file mode 100644 index 7c881623..00000000 --- a/old/services/core/test/fuzztest/dumplocalprofile_fuzzer/dumplocalprofile_fuzzer.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * 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. - */ - -#include "dumplocalprofile_fuzzer.h" - -#include "device_profile_storage_manager.h" - -#include -#include -#include -#include -#include -#include - -namespace OHOS { -namespace DeviceProfile { -void FuzzDumpLocalProfile(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size == 0)) { - return; - } - std::string result(reinterpret_cast(data), size); - DeviceProfileStorageManager::GetInstance().DumpLocalProfile(result); -} -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - OHOS::DeviceProfile::FuzzDumpLocalProfile(data, size); - return 0; -} - diff --git a/old/services/core/test/fuzztest/dumplocalprofile_fuzzer/dumplocalprofile_fuzzer.h b/old/services/core/test/fuzztest/dumplocalprofile_fuzzer/dumplocalprofile_fuzzer.h deleted file mode 100644 index 5d06b635..00000000 --- a/old/services/core/test/fuzztest/dumplocalprofile_fuzzer/dumplocalprofile_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef DUMP_LOCAL_PROFILE_FUZZER_H -#define DUMP_LOCAL_PROFILE_FUZZER_H - -#define FUZZ_PROJECT_NAME "dumplocalprofile_fuzzer" - -#endif \ No newline at end of file diff --git a/old/services/core/test/fuzztest/dumplocalprofile_fuzzer/project.xml b/old/services/core/test/fuzztest/dumplocalprofile_fuzzer/project.xml deleted file mode 100644 index 4fdbc407..00000000 --- a/old/services/core/test/fuzztest/dumplocalprofile_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/old/services/core/test/fuzztest/getdeviceprofile_fuzzer/BUILD.gn b/old/services/core/test/fuzztest/getdeviceprofile_fuzzer/BUILD.gn deleted file mode 100755 index 62978969..00000000 --- a/old/services/core/test/fuzztest/getdeviceprofile_fuzzer/BUILD.gn +++ /dev/null @@ -1,73 +0,0 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. -# 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. - -#####################hydra-fuzz################### -import("//build/config/features.gni") -import("//build/ohos.gni") -import("//build/test.gni") -import("//foundation/deviceprofile/device_info_manager/deviceprofile.gni") -module_output_path = old_fuzz_test_output_path - -device_profile_configs = [ - "${old_device_profile_service}/core:device_info_manager_config", - "${old_device_profile_test}/resource:coverage_flags", -] - -device_profile_external_deps = [ - "access_token:libaccesstoken_sdk", - "c_utils:utils", - "device_auth:deviceauth_sdk", - "device_manager:devicemanagersdk", - "dsoftbus:softbus_client", - "eventhandler:libeventhandler", - "hilog:libhilog", - "hisysevent:libhisysevent", - "ipc:ipc_core", - "json:nlohmann_json_static", - "kv_store:distributeddata_inner", - "syscap_codec:syscap_interface_shared", -] - -device_profile_deps = [ - "${old_device_profile_innerkits}/core:distributed_device_profile_client", - "${old_device_profile_service}/core:distributed_device_profile", -] - -##############################fuzztest########################################## -ohos_fuzztest("GetDeviceProfileFuzzTest") { - module_out_path = module_output_path - - fuzz_config_file = - "${old_device_profile_service}/core/test/fuzztest/getdeviceprofile_fuzzer" - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - - configs = device_profile_configs - - sources = [ "getdeviceprofile_fuzzer.cpp" ] - - deps = device_profile_deps - - external_deps = device_profile_external_deps -} - -group("fuzztest") { - testonly = true - - deps = [ ":GetDeviceProfileFuzzTest" ] -} diff --git a/old/services/core/test/fuzztest/getdeviceprofile_fuzzer/corpus/init b/old/services/core/test/fuzztest/getdeviceprofile_fuzzer/corpus/init deleted file mode 100644 index 2b595da0..00000000 --- a/old/services/core/test/fuzztest/getdeviceprofile_fuzzer/corpus/init +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * 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. - */ - -FUZZ \ No newline at end of file diff --git a/old/services/core/test/fuzztest/getdeviceprofile_fuzzer/getdeviceprofile_fuzzer.cpp b/old/services/core/test/fuzztest/getdeviceprofile_fuzzer/getdeviceprofile_fuzzer.cpp deleted file mode 100644 index 82a9207e..00000000 --- a/old/services/core/test/fuzztest/getdeviceprofile_fuzzer/getdeviceprofile_fuzzer.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * 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. - */ - -#include "getdeviceprofile_fuzzer.h" - -#include "device_profile_storage_manager.h" - -#include -#include -#include -#include -#include -#include - -namespace OHOS { -namespace DeviceProfile { -namespace { - constexpr int32_t TEST_LEVEL = 8; - constexpr int32_t TIME = 3; -} - -void FuzzGetDeviceProfile(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size == 0)) { - return; - } - DeviceProfileStorageManager::GetInstance().Init(); - sleep(TIME); - - ServiceCharacteristicProfile profile; - std::string serviceId(reinterpret_cast(data), size); - std::string serviceType(reinterpret_cast(data), size); - profile.SetServiceId(serviceId); - profile.SetServiceType(serviceType); - nlohmann::json j; - j["testVersion"] = "3.0.0"; - j["testApiLevel"] = TEST_LEVEL; - profile.SetCharacteristicProfileJson(j.dump()); - DeviceProfileStorageManager::GetInstance().GetDeviceProfile("", serviceId, profile); - - DeviceProfileStorageManager::GetInstance().DeleteDeviceProfile(serviceId); -} -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - OHOS::DeviceProfile::FuzzGetDeviceProfile(data, size); - return 0; -} - diff --git a/old/services/core/test/fuzztest/getdeviceprofile_fuzzer/getdeviceprofile_fuzzer.h b/old/services/core/test/fuzztest/getdeviceprofile_fuzzer/getdeviceprofile_fuzzer.h deleted file mode 100644 index 1c606858..00000000 --- a/old/services/core/test/fuzztest/getdeviceprofile_fuzzer/getdeviceprofile_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef GET_DEVICE_PROFILE_FUZZER_H -#define GET_DEVICE_PROFILE_FUZZER_H - -#define FUZZ_PROJECT_NAME "getdeviceprofile_fuzzer" - -#endif \ No newline at end of file diff --git a/old/services/core/test/fuzztest/getdeviceprofile_fuzzer/project.xml b/old/services/core/test/fuzztest/getdeviceprofile_fuzzer/project.xml deleted file mode 100644 index 4fdbc407..00000000 --- a/old/services/core/test/fuzztest/getdeviceprofile_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/old/services/core/test/fuzztest/putdeviceprofile_fuzzer/BUILD.gn b/old/services/core/test/fuzztest/putdeviceprofile_fuzzer/BUILD.gn deleted file mode 100755 index 2cb3e9ee..00000000 --- a/old/services/core/test/fuzztest/putdeviceprofile_fuzzer/BUILD.gn +++ /dev/null @@ -1,73 +0,0 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. -# 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. - -#####################hydra-fuzz################### -import("//build/config/features.gni") -import("//build/ohos.gni") -import("//build/test.gni") -import("//foundation/deviceprofile/device_info_manager/deviceprofile.gni") -module_output_path = old_fuzz_test_output_path - -device_profile_configs = [ - "${old_device_profile_service}/core:device_info_manager_config", - "${old_device_profile_test}/resource:coverage_flags", -] - -device_profile_external_deps = [ - "access_token:libaccesstoken_sdk", - "c_utils:utils", - "device_auth:deviceauth_sdk", - "device_manager:devicemanagersdk", - "dsoftbus:softbus_client", - "eventhandler:libeventhandler", - "hilog:libhilog", - "hisysevent:libhisysevent", - "ipc:ipc_core", - "json:nlohmann_json_static", - "kv_store:distributeddata_inner", - "syscap_codec:syscap_interface_shared", -] - -device_profile_deps = [ - "${old_device_profile_innerkits}/core:distributed_device_profile_client", - "${old_device_profile_service}/core:distributed_device_profile", -] - -##############################fuzztest########################################## -ohos_fuzztest("PutDeviceProfileFuzzTest") { - module_out_path = module_output_path - - fuzz_config_file = - "${old_device_profile_service}/core/test/fuzztest/putdeviceprofile_fuzzer" - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - - configs = device_profile_configs - - sources = [ "putdeviceprofile_fuzzer.cpp" ] - - deps = device_profile_deps - - external_deps = device_profile_external_deps -} - -group("fuzztest") { - testonly = true - - deps = [ ":PutDeviceProfileFuzzTest" ] -} diff --git a/old/services/core/test/fuzztest/putdeviceprofile_fuzzer/corpus/init b/old/services/core/test/fuzztest/putdeviceprofile_fuzzer/corpus/init deleted file mode 100644 index 2b595da0..00000000 --- a/old/services/core/test/fuzztest/putdeviceprofile_fuzzer/corpus/init +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * 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. - */ - -FUZZ \ No newline at end of file diff --git a/old/services/core/test/fuzztest/putdeviceprofile_fuzzer/project.xml b/old/services/core/test/fuzztest/putdeviceprofile_fuzzer/project.xml deleted file mode 100644 index 4fdbc407..00000000 --- a/old/services/core/test/fuzztest/putdeviceprofile_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/old/services/core/test/fuzztest/putdeviceprofile_fuzzer/putdeviceprofile_fuzzer.cpp b/old/services/core/test/fuzztest/putdeviceprofile_fuzzer/putdeviceprofile_fuzzer.cpp deleted file mode 100644 index c3da8e41..00000000 --- a/old/services/core/test/fuzztest/putdeviceprofile_fuzzer/putdeviceprofile_fuzzer.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * 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. - */ - -#include "putdeviceprofile_fuzzer.h" - -#include "device_profile_storage_manager.h" - -#include -#include -#include -#include -#include -#include -#include -#include "sys/stat.h" - -namespace OHOS { -namespace DeviceProfile { -namespace { - constexpr int32_t TEST_LEVEL = 8; - constexpr int32_t TIME = 3; -} - -void FuzzPutDeviceProfile(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size == 0)) { - return; - } - std::string baseDir = "/data/service/el1/public/database/distributed_device_profile_service"; - mkdir(baseDir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); - DeviceProfileStorageManager::GetInstance().Init(); - sleep(TIME); - ServiceCharacteristicProfile profile; - std::string serviceId(reinterpret_cast(data), size); - std::string serviceType(reinterpret_cast(data), size); - - profile.SetServiceId(serviceId); - profile.SetServiceType(serviceType); - nlohmann::json j; - j["testVersion"] = "3.0.0"; - j["testApiLevel"] = TEST_LEVEL; - profile.SetCharacteristicProfileJson(j.dump()); - DeviceProfileStorageManager::GetInstance().PutDeviceProfile(profile); - - std::string udid(reinterpret_cast(data), size); - DeviceProfileStorageManager::GetInstance().RemoveUnBoundDeviceProfile(udid); -} -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - OHOS::DeviceProfile::FuzzPutDeviceProfile(data, size); - return 0; -} - diff --git a/old/services/core/test/fuzztest/putdeviceprofile_fuzzer/putdeviceprofile_fuzzer.h b/old/services/core/test/fuzztest/putdeviceprofile_fuzzer/putdeviceprofile_fuzzer.h deleted file mode 100644 index 3871e551..00000000 --- a/old/services/core/test/fuzztest/putdeviceprofile_fuzzer/putdeviceprofile_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef PUT_DEVICE_PROFILE_FUZZER_H -#define PUT_DEVICE_PROFILE_FUZZER_H - -#define FUZZ_PROJECT_NAME "putdeviceprofile_fuzzer" - -#endif \ No newline at end of file diff --git a/old/services/core/test/fuzztest/putdeviceprofileinner_fuzzer/BUILD.gn b/old/services/core/test/fuzztest/putdeviceprofileinner_fuzzer/BUILD.gn deleted file mode 100755 index 25d0c45b..00000000 --- a/old/services/core/test/fuzztest/putdeviceprofileinner_fuzzer/BUILD.gn +++ /dev/null @@ -1,72 +0,0 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. -# 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. - -#####################hydra-fuzz################### -import("//build/config/features.gni") -import("//build/ohos.gni") -import("//build/test.gni") -import("//foundation/deviceprofile/device_info_manager/deviceprofile.gni") -module_output_path = old_fuzz_test_output_path - -device_profile_configs = [ - "${old_device_profile_service}/core:device_info_manager_config", - "${old_device_profile_test}/resource:coverage_flags", -] - -device_profile_external_deps = [ - "access_token:libaccesstoken_sdk", - "c_utils:utils", - "device_auth:deviceauth_sdk", - "device_manager:devicemanagersdk", - "dsoftbus:softbus_client", - "eventhandler:libeventhandler", - "hilog:libhilog", - "hisysevent:libhisysevent", - "ipc:ipc_core", - "json:nlohmann_json_static", - "kv_store:distributeddata_inner", - "syscap_codec:syscap_interface_shared", -] - -device_profile_deps = [ - "${old_device_profile_innerkits}/core:distributed_device_profile_client", - "${old_device_profile_service}/core:distributed_device_profile", -] - -##############################fuzztest########################################## -ohos_fuzztest("PutDeviceProfileInnerFuzzTest") { - module_out_path = module_output_path - - fuzz_config_file = "${old_device_profile_service}/core/test/fuzztest/putdeviceprofileinner_fuzzer" - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - - configs = device_profile_configs - - sources = [ "putdeviceprofileinner_fuzzer.cpp" ] - - deps = device_profile_deps - - external_deps = device_profile_external_deps -} - -group("fuzztest") { - testonly = true - - deps = [ ":PutDeviceProfileInnerFuzzTest" ] -} diff --git a/old/services/core/test/fuzztest/putdeviceprofileinner_fuzzer/corpus/init b/old/services/core/test/fuzztest/putdeviceprofileinner_fuzzer/corpus/init deleted file mode 100644 index 2b595da0..00000000 --- a/old/services/core/test/fuzztest/putdeviceprofileinner_fuzzer/corpus/init +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * 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. - */ - -FUZZ \ No newline at end of file diff --git a/old/services/core/test/fuzztest/putdeviceprofileinner_fuzzer/project.xml b/old/services/core/test/fuzztest/putdeviceprofileinner_fuzzer/project.xml deleted file mode 100644 index 4fdbc407..00000000 --- a/old/services/core/test/fuzztest/putdeviceprofileinner_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/old/services/core/test/fuzztest/putdeviceprofileinner_fuzzer/putdeviceprofileinner_fuzzer.cpp b/old/services/core/test/fuzztest/putdeviceprofileinner_fuzzer/putdeviceprofileinner_fuzzer.cpp deleted file mode 100644 index 2980cbab..00000000 --- a/old/services/core/test/fuzztest/putdeviceprofileinner_fuzzer/putdeviceprofileinner_fuzzer.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * 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. - */ - -#include "putdeviceprofileinner_fuzzer.h" - -#include "distributed_device_profile_stub.h" - -#include -#include -#include -#include -#include -#include - -namespace OHOS { -namespace DeviceProfile { -class DistributedDeviceProfileStubTest : public DistributedDeviceProfileStub { -public: -public: - DistributedDeviceProfileStubTest() = default; - ~DistributedDeviceProfileStubTest() = default; - int32_t PutDeviceProfile(const ServiceCharacteristicProfile& profile) - { - (void)profile; - return 0; - } - int32_t GetDeviceProfile(const std::string& udid, const std::string& serviceId, - ServiceCharacteristicProfile& profile) - { - (void)udid; - (void)serviceId; - (void)profile; - return 0; - } - int32_t DeleteDeviceProfile(const std::string& serviceId) - { - (void)serviceId; - return 0; - } - int32_t SubscribeProfileEvents(const std::list& subscribeInfos, - const sptr& profileEventNotifier, std::list& failedEvents) - { - (void)subscribeInfos; - (void)profileEventNotifier; - (void)failedEvents; - return 0; - } - int32_t UnsubscribeProfileEvents(const std::list& profileEvents, - const sptr& profileEventNotifier, std::list& failedEvents) - { - (void)profileEvents; - (void)profileEventNotifier; - (void)failedEvents; - return 0; - } - int32_t SyncDeviceProfile(const SyncOptions& syncOptions, const sptr& profileEventNotifier) - { - (void)syncOptions; - (void)profileEventNotifier; - return 0; - } -}; -void FuzzDumpLocalProfile(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size == 0)) { - return; - } - std::string udid(reinterpret_cast(data), size); - std::string serviceId(reinterpret_cast(data), size); - MessageParcel messageData; - messageData.WriteString(udid); - messageData.WriteString(serviceId); - MessageParcel reply; - std::shared_ptr deviceProfileStub = - std::make_shared(); - deviceProfileStub->PutDeviceProfileInner(messageData, reply); - deviceProfileStub->GetDeviceProfileInner(messageData, reply); -} -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - OHOS::DeviceProfile::FuzzDumpLocalProfile(data, size); - return 0; -} - diff --git a/old/services/core/test/fuzztest/putdeviceprofileinner_fuzzer/putdeviceprofileinner_fuzzer.h b/old/services/core/test/fuzztest/putdeviceprofileinner_fuzzer/putdeviceprofileinner_fuzzer.h deleted file mode 100644 index 94104d5b..00000000 --- a/old/services/core/test/fuzztest/putdeviceprofileinner_fuzzer/putdeviceprofileinner_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef PUT_DEVICE_PROFILE_INNER_FUZZER_H -#define PUT_DEVICE_PROFILE_INNER_FUZZER_H - -#define FUZZ_PROJECT_NAME "putdeviceprofileinner_fuzzer" - -#endif \ No newline at end of file diff --git a/old/services/core/test/fuzztest/subscribeprofileeventinner_fuzzer/BUILD.gn b/old/services/core/test/fuzztest/subscribeprofileeventinner_fuzzer/BUILD.gn deleted file mode 100755 index 43479e75..00000000 --- a/old/services/core/test/fuzztest/subscribeprofileeventinner_fuzzer/BUILD.gn +++ /dev/null @@ -1,74 +0,0 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. -# 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. - -#####################hydra-fuzz################### -import("//build/config/features.gni") -import("//build/ohos.gni") -import("//build/test.gni") -import("//foundation/deviceprofile/device_info_manager/deviceprofile.gni") -module_output_path = old_fuzz_test_output_path - -device_profile_configs = [ - "${old_device_profile_service}/core:device_info_manager_config", - "${old_device_profile_test}/resource:coverage_flags", -] - -device_profile_external_deps = [ - "access_token:libaccesstoken_sdk", - "access_token:libnativetoken", - "access_token:libtoken_setproc", - "c_utils:utils", - "device_auth:deviceauth_sdk", - "device_manager:devicemanagersdk", - "dsoftbus:softbus_client", - "eventhandler:libeventhandler", - "hilog:libhilog", - "hisysevent:libhisysevent", - "ipc:ipc_core", - "json:nlohmann_json_static", - "kv_store:distributeddata_inner", - "syscap_codec:syscap_interface_shared", -] - -device_profile_deps = [ - "${old_device_profile_innerkits}/core:distributed_device_profile_client", - "${old_device_profile_service}/core:distributed_device_profile", -] - -##############################fuzztest########################################## -ohos_fuzztest("SubscribeProfileEventInnerFuzzTest") { - module_out_path = module_output_path - - fuzz_config_file = "${old_device_profile_service}/core/test/fuzztest/subscribeprofileeventinner_fuzzer" - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - - configs = device_profile_configs - - sources = [ "subscribeprofileeventinner_fuzzer.cpp" ] - - deps = device_profile_deps - - external_deps = device_profile_external_deps -} - -group("fuzztest") { - testonly = true - - deps = [ ":SubscribeProfileEventInnerFuzzTest" ] -} diff --git a/old/services/core/test/fuzztest/subscribeprofileeventinner_fuzzer/corpus/init b/old/services/core/test/fuzztest/subscribeprofileeventinner_fuzzer/corpus/init deleted file mode 100644 index 2b595da0..00000000 --- a/old/services/core/test/fuzztest/subscribeprofileeventinner_fuzzer/corpus/init +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * 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. - */ - -FUZZ \ No newline at end of file diff --git a/old/services/core/test/fuzztest/subscribeprofileeventinner_fuzzer/project.xml b/old/services/core/test/fuzztest/subscribeprofileeventinner_fuzzer/project.xml deleted file mode 100644 index 4fdbc407..00000000 --- a/old/services/core/test/fuzztest/subscribeprofileeventinner_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/old/services/core/test/fuzztest/subscribeprofileeventinner_fuzzer/subscribeprofileeventinner_fuzzer.cpp b/old/services/core/test/fuzztest/subscribeprofileeventinner_fuzzer/subscribeprofileeventinner_fuzzer.cpp deleted file mode 100644 index cdee9452..00000000 --- a/old/services/core/test/fuzztest/subscribeprofileeventinner_fuzzer/subscribeprofileeventinner_fuzzer.cpp +++ /dev/null @@ -1,375 +0,0 @@ -/* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. - * 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. - */ - -#include "subscribeprofileeventinner_fuzzer.h" - -#include "distributed_device_profile_stub.h" - -#include -#include -#include -#include -#include -#include -#include -#include "accesstoken_kit.h" -#include "nativetoken_kit.h" -#include "token_setproc.h" - -namespace OHOS { -namespace DeviceProfile { -namespace { -const int32_t PERMS_NUM = 2; -} - -class DistributedDeviceProfileStubTest : public DistributedDeviceProfileStub { -public: -public: - DistributedDeviceProfileStubTest() = default; - ~DistributedDeviceProfileStubTest() = default; - int32_t PutDeviceProfile(const ServiceCharacteristicProfile& profile) - { - (void)profile; - return 0; - } - int32_t GetDeviceProfile(const std::string& udid, const std::string& serviceId, - ServiceCharacteristicProfile& profile) - { - (void)udid; - (void)serviceId; - (void)profile; - return 0; - } - int32_t DeleteDeviceProfile(const std::string& serviceId) - { - (void)serviceId; - return 0; - } - int32_t SubscribeProfileEvents(const std::list& subscribeInfos, - const sptr& profileEventNotifier, std::list& failedEvents) - { - (void)subscribeInfos; - (void)profileEventNotifier; - (void)failedEvents; - return 0; - } - int32_t UnsubscribeProfileEvents(const std::list& profileEvents, - const sptr& profileEventNotifier, std::list& failedEvents) - { - (void)profileEvents; - (void)profileEventNotifier; - (void)failedEvents; - return 0; - } - int32_t SyncDeviceProfile(const SyncOptions& syncOptions, const sptr& profileEventNotifier) - { - (void)syncOptions; - (void)profileEventNotifier; - return 0; - } -}; - -void MockPermission(const char* processName) -{ - const char *perms[PERMS_NUM] = { - "ohos.permission.DISTRIBUTED_DATASYNC", - "ohos.permission.DISTRIBUTED_SOFTBUS_CENTER" - }; - uint64_t tokenId; - NativeTokenInfoParams infoInstance = { - .dcapsNum = 0, - .permsNum = PERMS_NUM, - .aclsNum = 0, - .dcaps = nullptr, - .perms = perms, - .acls = nullptr, - .processName = processName, - .aplStr = "system_core", - }; - tokenId = GetAccessTokenId(&infoInstance); - SetSelfTokenID(tokenId); - OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo(); -} - -void FuzzDumpLocalProfile(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size < sizeof(uint32_t))) { - return; - } - uint32_t numSubscribeInfos = *(reinterpret_cast(data)); - MessageParcel messageData; - MessageParcel reply; - messageData.WriteUint32(numSubscribeInfos); - std::shared_ptr deviceProfileStub = - std::make_shared(); - deviceProfileStub->SubscribeProfileEventInner(messageData, reply); - deviceProfileStub->UnsubscribeProfileEventInner(messageData, reply); -} - -void PutAccessControlProfileInnerTest(const uint8_t *data, size_t size) -{ - if ((data == nullptr) || (size == 0)) { - return; - } - MockPermission("deviceprofile"); - std::string udid(reinterpret_cast(data), size); - std::string serviceId(reinterpret_cast(data), size); - MessageParcel messageData; - messageData.WriteString(udid); - messageData.WriteString(serviceId); - MessageParcel reply; - std::shared_ptr deviceProfilePutStub = - std::make_shared(); - deviceProfilePutStub->PutAccessControlProfileInner(messageData, reply); - deviceProfilePutStub->GetAccessControlProfileInner(messageData, reply); -} - -void GetTrustDeviceProfileInnerTest(const uint8_t *data, size_t size) -{ - if ((data == nullptr) || (size == 0)) { - return; - } - MockPermission("deviceprofile"); - std::string deviceId(reinterpret_cast(data), size); - MessageParcel messageData; - messageData.WriteString(deviceId); - MessageParcel reply; - std::shared_ptr deviceProfileGetStub = - std::make_shared(); - deviceProfileGetStub->PutAccessControlProfileInner(messageData, reply); - deviceProfileGetStub->GetTrustDeviceProfileInner(messageData, reply); - deviceProfileGetStub->GetAllTrustDeviceProfileInner(messageData, reply); -} - -void UpdateAccessControlProfileInnerTest(const uint8_t *data, size_t size) -{ - if ((data == nullptr) || (size == 0)) { - return; - } - MockPermission("deviceprofile"); - std::string udid(reinterpret_cast(data), size); - std::string serviceId(reinterpret_cast(data), size); - MessageParcel messageData; - messageData.WriteString(udid); - messageData.WriteString(serviceId); - MessageParcel reply; - std::shared_ptr deviceProfileUpdateStub = - std::make_shared(); - deviceProfileUpdateStub->PutAccessControlProfileInner(messageData, reply); - deviceProfileUpdateStub->UpdateAccessControlProfileInner(messageData, reply); -} - -void GetAllAccessControlProfileInnerTest(const uint8_t *data, size_t size) -{ - if ((data == nullptr) || (size == 0)) { - return; - } - MockPermission("deviceprofile"); - std::string udid(reinterpret_cast(data), size); - std::string serviceId(reinterpret_cast(data), size); - MessageParcel messageData; - messageData.WriteString(udid); - messageData.WriteString(serviceId); - MessageParcel reply; - std::shared_ptr deviceProfileGetAllStub = - std::make_shared(); - deviceProfileGetAllStub->PutAccessControlProfileInner(messageData, reply); - deviceProfileGetAllStub->GetAllAccessControlProfileInner(messageData, reply); -} - -void DeleteAccessControlProfileInnerTest(const uint8_t *data, size_t size) -{ - if ((data == nullptr) || (size == 0)) { - return; - } - MockPermission("deviceprofile"); - std::string udid(reinterpret_cast(data), size); - std::string serviceId(reinterpret_cast(data), size); - MessageParcel messageData; - messageData.WriteString(udid); - messageData.WriteString(serviceId); - MessageParcel reply; - std::shared_ptr deviceProfileDeleteStub = - std::make_shared(); - deviceProfileDeleteStub->PutAccessControlProfileInner(messageData, reply); - deviceProfileDeleteStub->GetAllAccessControlProfileInner(messageData, reply); - deviceProfileDeleteStub->DeleteAccessControlProfileInner(messageData, reply); -} - -void PutServiceProfileInnerTest(const uint8_t *data, size_t size) -{ - if ((data == nullptr) || (size == 0)) { - return; - } - MockPermission("deviceprofile"); - std::string udid(reinterpret_cast(data), size); - std::string serviceId(reinterpret_cast(data), size); - MessageParcel messageData; - messageData.WriteString(udid); - messageData.WriteString(serviceId); - MessageParcel reply; - std::shared_ptr deviceProfilePutSerStub = - std::make_shared(); - deviceProfilePutSerStub->PutServiceProfileInner(messageData, reply); - deviceProfilePutSerStub->GetServiceProfileInner(messageData, reply); -} - -void PutServiceProfileBatchInnerTest(const uint8_t *data, size_t size) -{ - if ((data == nullptr) || (size == 0)) { - return; - } - MockPermission("deviceprofile"); - std::string udid(reinterpret_cast(data), size); - std::string serviceId(reinterpret_cast(data), size); - MessageParcel messageData; - messageData.WriteString(udid); - messageData.WriteString(serviceId); - MessageParcel reply; - std::shared_ptr deviceProfilePutSerStub = - std::make_shared(); - deviceProfilePutSerStub->PutServiceProfileBatchInner(messageData, reply); - deviceProfilePutSerStub->GetServiceProfileInner(messageData, reply); -} - -void PutCharacteristicProfileInnerTest(const uint8_t *data, size_t size) -{ - if ((data == nullptr) || (size == 0)) { - return; - } - MockPermission("deviceprofile"); - std::string udid(reinterpret_cast(data), size); - std::string serviceId(reinterpret_cast(data), size); - MessageParcel messageData; - messageData.WriteString(udid); - messageData.WriteString(serviceId); - MessageParcel reply; - std::shared_ptr deviceProfilePutStub = - std::make_shared(); - deviceProfilePutStub->PutCharacteristicProfileInner(messageData, reply); - deviceProfilePutStub->GetCharacteristicProfileInner(messageData, reply); -} - -void PutCharacteristicProfileBatchInnerTest(const uint8_t *data, size_t size) -{ - if ((data == nullptr) || (size == 0)) { - return; - } - MockPermission("deviceprofile"); - std::string udid(reinterpret_cast(data), size); - std::string serviceId(reinterpret_cast(data), size); - MessageParcel messageData; - messageData.WriteString(udid); - messageData.WriteString(serviceId); - MessageParcel reply; - std::shared_ptr deviceProfileStub = - std::make_shared(); - deviceProfileStub->PutCharacteristicProfileBatchInner(messageData, reply); - deviceProfileStub->GetCharacteristicProfileInner(messageData, reply); -} - -void DeleteCharacteristicProfileInnerTest(const uint8_t *data, size_t size) -{ - if ((data == nullptr) || (size == 0)) { - return; - } - MockPermission("deviceprofile"); - std::string udid(reinterpret_cast(data), size); - std::string serviceId(reinterpret_cast(data), size); - MessageParcel messageData; - messageData.WriteString(udid); - messageData.WriteString(serviceId); - MessageParcel reply; - std::shared_ptr deviceProfileStub = - std::make_shared(); - deviceProfileStub->PutCharacteristicProfileBatchInner(messageData, reply); - deviceProfileStub->DeleteCharacteristicProfileInner(messageData, reply); -} - -void DeleteServiceProfileInnerTest(const uint8_t *data, size_t size) -{ - if ((data == nullptr) || (size == 0)) { - return; - } - MockPermission("deviceprofile"); - std::string udid(reinterpret_cast(data), size); - std::string serviceId(reinterpret_cast(data), size); - MessageParcel messageData; - messageData.WriteString(udid); - messageData.WriteString(serviceId); - MessageParcel reply; - std::shared_ptr deviceProfileDeleteSerStub = - std::make_shared(); - deviceProfileDeleteSerStub->PutServiceProfileBatchInner(messageData, reply); - deviceProfileDeleteSerStub->DeleteServiceProfileInner(messageData, reply); -} - -void SubscribeDeviceProfileInnerTest(const uint8_t *data, size_t size) -{ - if ((data == nullptr) || (size == 0)) { - return; - } - MockPermission("deviceprofile"); - std::string udid(reinterpret_cast(data), size); - std::string serviceId(reinterpret_cast(data), size); - MessageParcel messageData; - messageData.WriteString(udid); - messageData.WriteString(serviceId); - MessageParcel reply; - std::shared_ptr deviceProfileSubStub = - std::make_shared(); - deviceProfileSubStub->SubscribeDeviceProfileInner(messageData, reply); - deviceProfileSubStub->UnSubscribeDeviceProfileInner(messageData, reply); -} - -void SyncDeviceProfileNewInnerTest(const uint8_t *data, size_t size) -{ - if ((data == nullptr) || (size == 0)) { - return; - } - MockPermission("deviceprofile"); - std::string udid(reinterpret_cast(data), size); - std::string serviceId(reinterpret_cast(data), size); - MessageParcel messageData; - messageData.WriteString(udid); - messageData.WriteString(serviceId); - MessageParcel reply; - std::shared_ptr deviceProfileSyncStub = - std::make_shared(); - deviceProfileSyncStub->SyncDeviceProfileNewInner(messageData, reply); - deviceProfileSyncStub->SendSubscribeInfosInner(messageData, reply); -} -} // namespace DeviceProfile -} // namespace OHOS - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - OHOS::DeviceProfile::FuzzDumpLocalProfile(data, size); - OHOS::DeviceProfile::PutAccessControlProfileInnerTest(data, size); - OHOS::DeviceProfile::GetTrustDeviceProfileInnerTest(data, size); - OHOS::DeviceProfile::UpdateAccessControlProfileInnerTest(data, size); - OHOS::DeviceProfile::GetAllAccessControlProfileInnerTest(data, size); - OHOS::DeviceProfile::DeleteAccessControlProfileInnerTest(data, size); - OHOS::DeviceProfile::PutServiceProfileBatchInnerTest(data, size); - OHOS::DeviceProfile::PutServiceProfileInnerTest(data, size); - OHOS::DeviceProfile::PutCharacteristicProfileInnerTest(data, size); - OHOS::DeviceProfile::PutCharacteristicProfileBatchInnerTest(data, size); - OHOS::DeviceProfile::DeleteCharacteristicProfileInnerTest(data, size); - OHOS::DeviceProfile::DeleteServiceProfileInnerTest(data, size); - OHOS::DeviceProfile::SyncDeviceProfileNewInnerTest(data, size); - OHOS::DeviceProfile::SubscribeDeviceProfileInnerTest(data, size); - return 0; -} diff --git a/old/services/core/test/fuzztest/subscribeprofileeventinner_fuzzer/subscribeprofileeventinner_fuzzer.h b/old/services/core/test/fuzztest/subscribeprofileeventinner_fuzzer/subscribeprofileeventinner_fuzzer.h deleted file mode 100644 index 2b291438..00000000 --- a/old/services/core/test/fuzztest/subscribeprofileeventinner_fuzzer/subscribeprofileeventinner_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef SUBSRCIBE_PROFILE_EVENT_INNER_FUZZER_H -#define SUBSRCIBE_PROFILE_EVENT_INNER_FUZZER_H - -#define FUZZ_PROJECT_NAME "subscribeprofileeventInner_fuzzer" - -#endif \ No newline at end of file diff --git a/old/services/core/test/fuzztest/syncdeviceprofileinner_fuzzer/BUILD.gn b/old/services/core/test/fuzztest/syncdeviceprofileinner_fuzzer/BUILD.gn deleted file mode 100755 index cec010bc..00000000 --- a/old/services/core/test/fuzztest/syncdeviceprofileinner_fuzzer/BUILD.gn +++ /dev/null @@ -1,72 +0,0 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. -# 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. - -#####################hydra-fuzz################### -import("//build/config/features.gni") -import("//build/ohos.gni") -import("//build/test.gni") -import("//foundation/deviceprofile/device_info_manager/deviceprofile.gni") -module_output_path = old_fuzz_test_output_path - -device_profile_configs = [ - "${old_device_profile_service}/core:device_info_manager_config", - "${old_device_profile_test}/resource:coverage_flags", -] - -device_profile_external_deps = [ - "access_token:libaccesstoken_sdk", - "c_utils:utils", - "device_auth:deviceauth_sdk", - "device_manager:devicemanagersdk", - "dsoftbus:softbus_client", - "eventhandler:libeventhandler", - "hilog:libhilog", - "hisysevent:libhisysevent", - "ipc:ipc_core", - "json:nlohmann_json_static", - "kv_store:distributeddata_inner", - "syscap_codec:syscap_interface_shared", -] - -device_profile_deps = [ - "${old_device_profile_innerkits}/core:distributed_device_profile_client", - "${old_device_profile_service}/core:distributed_device_profile", -] - -##############################fuzztest########################################## -ohos_fuzztest("SyncDeviceProfileInnerFuzzTest") { - module_out_path = module_output_path - - fuzz_config_file = "${old_device_profile_service}/core/test/fuzztest/syncdeviceprofileinner_fuzzer" - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - - configs = device_profile_configs - - sources = [ "syncdeviceprofileinner_fuzzer.cpp" ] - - deps = device_profile_deps - - external_deps = device_profile_external_deps -} - -group("fuzztest") { - testonly = true - - deps = [ ":SyncDeviceProfileInnerFuzzTest" ] -} diff --git a/old/services/core/test/fuzztest/syncdeviceprofileinner_fuzzer/corpus/init b/old/services/core/test/fuzztest/syncdeviceprofileinner_fuzzer/corpus/init deleted file mode 100644 index 2b595da0..00000000 --- a/old/services/core/test/fuzztest/syncdeviceprofileinner_fuzzer/corpus/init +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * 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. - */ - -FUZZ \ No newline at end of file diff --git a/old/services/core/test/fuzztest/syncdeviceprofileinner_fuzzer/project.xml b/old/services/core/test/fuzztest/syncdeviceprofileinner_fuzzer/project.xml deleted file mode 100644 index 4fdbc407..00000000 --- a/old/services/core/test/fuzztest/syncdeviceprofileinner_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/old/services/core/test/fuzztest/syncdeviceprofileinner_fuzzer/syncdeviceprofileinner_fuzzer.cpp b/old/services/core/test/fuzztest/syncdeviceprofileinner_fuzzer/syncdeviceprofileinner_fuzzer.cpp deleted file mode 100644 index a18eb33c..00000000 --- a/old/services/core/test/fuzztest/syncdeviceprofileinner_fuzzer/syncdeviceprofileinner_fuzzer.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * 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. - */ - -#include "syncdeviceprofileinner_fuzzer.h" - -#include "distributed_device_profile_stub.h" - -#include -#include -#include -#include -#include -#include - -namespace OHOS { -namespace DeviceProfile { -class DistributedDeviceProfileStubTest : public DistributedDeviceProfileStub { -public: - DistributedDeviceProfileStubTest() = default; - ~DistributedDeviceProfileStubTest() = default; - int32_t PutDeviceProfile(const ServiceCharacteristicProfile& profile) - { - (void)profile; - return 0; - } - int32_t GetDeviceProfile(const std::string& udid, const std::string& serviceId, - ServiceCharacteristicProfile& profile) - { - (void)udid; - (void)serviceId; - (void)profile; - return 0; - } - int32_t DeleteDeviceProfile(const std::string& serviceId) - { - (void)serviceId; - return 0; - } - int32_t SubscribeProfileEvents(const std::list& subscribeInfos, - const sptr& profileEventNotifier, std::list& failedEvents) - { - (void)subscribeInfos; - (void)profileEventNotifier; - (void)failedEvents; - return 0; - } - int32_t UnsubscribeProfileEvents(const std::list& profileEvents, - const sptr& profileEventNotifier, std::list& failedEvents) - { - (void)profileEvents; - (void)profileEventNotifier; - (void)failedEvents; - return 0; - } - int32_t SyncDeviceProfile(const SyncOptions& syncOptions, const sptr& profileEventNotifier) - { - (void)syncOptions; - (void)profileEventNotifier; - return 0; - } -}; -void FuzzDumpLocalProfile(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size == 0)) { - return; - } - std::string udid(reinterpret_cast(data), size); - std::string serviceId(reinterpret_cast(data), size); - MessageParcel messageData; - messageData.WriteString(udid); - messageData.WriteString(serviceId); - MessageParcel reply; - std::shared_ptr deviceProfileStub = - std::make_shared(); - deviceProfileStub->SyncDeviceProfileInner(messageData, reply); - deviceProfileStub->DeleteDeviceProfileInner(messageData, reply); -} -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - OHOS::DeviceProfile::FuzzDumpLocalProfile(data, size); - return 0; -} - diff --git a/old/services/core/test/fuzztest/syncdeviceprofileinner_fuzzer/syncdeviceprofileinner_fuzzer.h b/old/services/core/test/fuzztest/syncdeviceprofileinner_fuzzer/syncdeviceprofileinner_fuzzer.h deleted file mode 100644 index 2dc389e7..00000000 --- a/old/services/core/test/fuzztest/syncdeviceprofileinner_fuzzer/syncdeviceprofileinner_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef SYNC_DEVICE_PROFILE_INNER_FUZZER_H -#define SYNC_DEVICE_PROFILE_INNER_FUZZER_H - -#define FUZZ_PROJECT_NAME "syncdeviceprofileInner_fuzzer" - -#endif \ No newline at end of file diff --git a/old/services/core/test/unittest/content_sensor_test.cpp b/old/services/core/test/unittest/content_sensor_test.cpp deleted file mode 100644 index 0c3a103e..00000000 --- a/old/services/core/test/unittest/content_sensor_test.cpp +++ /dev/null @@ -1,286 +0,0 @@ -/* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. - * 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. - */ - -#include "gtest/gtest.h" - -#include - -#include "app_info_collector.h" -#include "utils.h" - -#define private public -#define protected public -#include "distributed_device_profile_client.h" -#include "content_sensor_manager.h" -#include "device_info_collector.h" -#include "pasteboard_info_collector.h" -#include "storage_info_collector.h" -#include "syscap_info_collector.h" -#include "system_info_collector.h" -#undef private -#undef protected - -namespace OHOS { -namespace DeviceProfile { -using namespace testing; -using namespace testing::ext; - -class ContentSensorTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp(); - void TearDown(); -}; - -void ContentSensorTest::SetUpTestCase() -{ - DistributedDeviceProfileClient::GetInstance().DeleteDeviceProfile("111111"); -} - -void ContentSensorTest::TearDownTestCase() -{ -} - -void ContentSensorTest::SetUp() -{ -} - -void ContentSensorTest::TearDown() -{ -} - -/** - * @tc.name: GetDeviceName_001 - * @tc.desc: get device name - * @tc.type: FUNC - */ -HWTEST_F(ContentSensorTest, GetDeviceName_001, TestSize.Level2) -{ - DeviceInfoCollector devInfo; - auto result = devInfo.GetDeviceName(); - EXPECT_NE(result, ""); -} - -/** - * @tc.name: GetDeviceModel_002 - * @tc.desc: get device model - * @tc.type: FUNC - */ -HWTEST_F(ContentSensorTest, GetDeviceModel_002, TestSize.Level2) -{ - DeviceInfoCollector devInfo; - auto result = devInfo.GetDeviceModel(); - EXPECT_NE(result, ""); -} - -/** - * @tc.name: GetDeviceUdid_003 - * @tc.desc: get device udid - * @tc.type: FUNC - */ -HWTEST_F(ContentSensorTest, GetDeviceUdid_003, TestSize.Level2) -{ - DeviceInfoCollector devInfo; - auto result = devInfo.GetDeviceUdid(); - EXPECT_NE(result, ""); -} - -/** - * @tc.name: GetDevType_004 - * @tc.desc: get device type - * @tc.type: FUNC - */ -HWTEST_F(ContentSensorTest, GetDevType_004, TestSize.Level2) -{ - DeviceInfoCollector devInfo; - auto result = devInfo.GetDevType(); - EXPECT_NE(result, ""); -} - -/** - * @tc.name: GetDeviceManufacturer_001 - * @tc.desc: get device manufacturer - * @tc.type: FUNC - */ -HWTEST_F(ContentSensorTest, GetDeviceManufacturer_001, TestSize.Level2) -{ - DeviceInfoCollector devInfo; - auto result = devInfo.GetDeviceManufacturer(); - EXPECT_NE(result, ""); -} - -/** - * @tc.name: GetDeviceSerial_001 - * @tc.desc: get device serial - * @tc.type: FUNC - */ -HWTEST_F(ContentSensorTest, GetDeviceSerial_001, TestSize.Level2) -{ - DeviceInfoCollector devInfo; - auto result = devInfo.GetDeviceSerial(); - EXPECT_NE(result, ""); -} - -/** - * @tc.name: GetTotalSize_001 - * @tc.desc: get total size - * @tc.type: FUNC - * @tc.require: I5J7PW - */ -HWTEST_F(ContentSensorTest, GetTotalSize_001, TestSize.Level2) -{ - const char* PATH_DATA = "/data"; - struct statvfs diskInfo; - int ret = statvfs(PATH_DATA, &diskInfo); - EXPECT_EQ(ret, 0); -} - -/** - * @tc.name: GetDmsVersion_001 - * @tc.desc: get dms version - * @tc.type: FUNC - * @tc.require: I5RWKZ - */ -HWTEST_F(ContentSensorTest, GetDmsVersion_001, TestSize.Level2) -{ - AppInfoCollector appInfoCollector; - ServiceCharacteristicProfile profile; - bool result = appInfoCollector.ConvertToProfileData(profile); - EXPECT_EQ(result, true); -} - -/** - * @tc.name: GetPasteboardInfo_001 - * @tc.desc: get pasteboard info - * @tc.type: FUNC - * @tc.require: I5RWKZ - */ -HWTEST_F(ContentSensorTest, GetPasteboardInfo_001, TestSize.Level2) -{ - PasteboardInfoCollector pasteboardInfoCollector; - ServiceCharacteristicProfile profile; - bool result = pasteboardInfoCollector.ConvertToProfileData(profile); - EXPECT_EQ(result, true); -} - -/** - * @tc.name: GetOsVersion_001 - * @tc.desc: GetOsVersion - * @tc.type: FUNC - * @tc.require: I52U5M - */ -HWTEST_F(ContentSensorTest, GetOsVersion_001, TestSize.Level3) -{ - SystemInfoCollector systemInfo; - std::string result = systemInfo.GetOsVersion(); - DTEST_LOG << "result:" << result << std::endl; - EXPECT_NE(result, ""); -} - -/** - * @tc.name: SyscapInfoCollector_001 - * @tc.desc: syscap info collector - * @tc.type: FUNC - * @tc.require: I59PZ3 - */ -HWTEST_F(ContentSensorTest, SyscapInfoCollector_001, TestSize.Level3) -{ - ServiceCharacteristicProfile profile; - profile.SetServiceId("test"); - profile.SetServiceType("test"); - SyscapInfoCollector syscapInfo; - bool result = syscapInfo.ConvertToProfileData(profile); - EXPECT_EQ(result, true); -} - -/** - * @tc.name: SyscapInfoCollector_001 - * @tc.desc: syscap info collector - * @tc.type: FUNC - * @tc.require: I59PZ3 - */ -HWTEST_F(ContentSensorTest, SyscapInfoCollector_002, TestSize.Level3) -{ - ServiceCharacteristicProfile profile; - profile.SetServiceId(""); - profile.SetServiceType(""); - SyscapInfoCollector syscapInfo; - bool result = syscapInfo.ConvertToProfileData(profile); - EXPECT_EQ(result, true); -} - -/** - * @tc.name: SyscapInfoCollector_001 - * @tc.desc: syscap info collector - * @tc.type: FUNC - * @tc.require: I59PZ3 - */ -HWTEST_F(ContentSensorTest, SyscapInfoCollector_003, TestSize.Level3) -{ - ServiceCharacteristicProfile profile; - profile.SetServiceId(""); - profile.SetServiceType("test"); - SyscapInfoCollector syscapInfo; - bool result = syscapInfo.ConvertToProfileData(profile); - EXPECT_EQ(result, true); -} - -/** - * @tc.name: SyscapInfoCollector_001 - * @tc.desc: syscap info collector - * @tc.type: FUNC - * @tc.require: I59PZ3 - */ -HWTEST_F(ContentSensorTest, SyscapInfoCollector_004, TestSize.Level3) -{ - ServiceCharacteristicProfile profile; - profile.SetServiceId("test"); - profile.SetServiceType(""); - SyscapInfoCollector syscapInfo; - bool result = syscapInfo.ConvertToProfileData(profile); - EXPECT_EQ(result, true); -} - -/** - * @tc.name: StorageInfoCollector_001 - * @tc.desc: syscap info collector - * @tc.type: FUNC - * @tc.require: I59PZ3 - */ -HWTEST_F(ContentSensorTest, StorageInfoCollector_001, TestSize.Level3) -{ - ServiceCharacteristicProfile profile; - profile.SetServiceId("test"); - profile.SetServiceType(""); - StorageInfoCollector storageInfo; - bool result = storageInfo.ConvertToProfileData(profile); - EXPECT_EQ(result, true); -} - -/** - * @tc.name: GetTotalSize_002 - * @tc.desc: get total size - * @tc.type: FUNC - * @tc.require: I59PZ3 - */ -HWTEST_F(ContentSensorTest, GetTotalSize_002, TestSize.Level3) -{ - StorageInfoCollector storageInfo; - int64_t result = storageInfo.GetTotalSize(); - EXPECT_NE(result, 0); -} -} -} diff --git a/old/services/core/test/unittest/device_profile_dfx_test.cpp b/old/services/core/test/unittest/device_profile_dfx_test.cpp deleted file mode 100644 index d81fc638..00000000 --- a/old/services/core/test/unittest/device_profile_dfx_test.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * 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. - */ - -#include -#include - -#define private public -#define protected public -#include "device_profile_dumper.h" -#include "distributed_device_profile_client.h" -#undef private -#undef protected -#include "ipc_skeleton.h" -#include "utils.h" - -namespace OHOS { -namespace DeviceProfile { -using namespace testing; -using namespace testing::ext; - -class DeviceProfileDFXTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp(); - void TearDown(); -}; - - -void DeviceProfileDFXTest::SetUpTestCase() -{ - DTEST_LOG << "SetUpTestCase" << std::endl; - DistributedDeviceProfileClient::GetInstance().DeleteDeviceProfile("111111"); -} - -void DeviceProfileDFXTest::TearDownTestCase() -{ - DTEST_LOG << "TearDownTestCase" << std::endl; -} - -void DeviceProfileDFXTest::SetUp() -{ - DTEST_LOG << "SetUp" << std::endl; -} - -void DeviceProfileDFXTest::TearDown() -{ - DTEST_LOG << "TearDown" << std::endl; -} - -/** - * @tc.name: DumpDefault_001 - * @tc.desc: dfx dump default - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(DeviceProfileDFXTest, DumpDefault_001, TestSize.Level3) -{ - auto dumper = std::make_shared(); - std::string msg; - dumper->ShowHelp(msg); - dumper->IllegalInput(msg); - auto result = dumper->DumpDefault(msg); - EXPECT_EQ(true, result); -} - -/** - * @tc.name: CanDump_002 - * @tc.desc: CanDump - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(DeviceProfileDFXTest, CanDump_001, TestSize.Level3) -{ - auto dumper = std::make_shared(); - auto result = dumper->CanDump(); - EXPECT_EQ(false, result); -} - -/** - * @tc.name: Dump_002 - * @tc.desc: Dump - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(DeviceProfileDFXTest, Dump_001, TestSize.Level3) -{ - auto dumper = std::make_shared(); - std::string msg; - const std::vector args; - auto result = dumper->Dump(args, msg); - EXPECT_EQ(false, result); -} - -/** - * @tc.name: CanDump_002 - * @tc.desc: CanDump - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(DeviceProfileDFXTest, CanDump_002, TestSize.Level3) -{ - setuid(1212); - auto dumper = std::make_shared(); - auto result = dumper->CanDump(); - EXPECT_EQ(true, result); -} - -/** - * @tc.name: Dump_002 - * @tc.desc: Dump - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(DeviceProfileDFXTest, Dump_002, TestSize.Level3) -{ - auto dumper = std::make_shared(); - std::string msg; - const std::vector args; - auto result = dumper->Dump(args, msg); - EXPECT_EQ(true, result); -} - -/** - * @tc.name: Dump_003 - * @tc.desc: Dump - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(DeviceProfileDFXTest, Dump_003, TestSize.Level3) -{ - auto dumper = std::make_shared(); - std::string msg; - std::vector args; - args.emplace_back("-h"); - auto result = dumper->Dump(args, msg); - EXPECT_EQ(true, result); -} - -/** - * @tc.name: Dump_004 - * @tc.desc: Dump - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(DeviceProfileDFXTest, Dump_004, TestSize.Level3) -{ - auto dumper = std::make_shared(); - std::string msg; - std::vector args; - args.emplace_back("-g"); - auto result = dumper->Dump(args, msg); - EXPECT_EQ(false, result); -} - -/** - * @tc.name: Dump_005 - * @tc.desc: Dump - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(DeviceProfileDFXTest, Dump_005, TestSize.Level3) -{ - auto dumper = std::make_shared(); - std::string msg; - std::vector args; - args.emplace_back("-h"); - args.emplace_back("-g"); - auto result = dumper->Dump(args, msg); - EXPECT_EQ(false, result); -} -} -} \ No newline at end of file diff --git a/old/services/core/test/unittest/device_profile_utils_test.cpp b/old/services/core/test/unittest/device_profile_utils_test.cpp deleted file mode 100644 index c86a2336..00000000 --- a/old/services/core/test/unittest/device_profile_utils_test.cpp +++ /dev/null @@ -1,275 +0,0 @@ -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * 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. - */ - -#include - -#include "device_profile_dumper.h" -#include "device_profile_utils.h" -#include "distributed_device_profile_client.h" -#include "sync_options.h" -#include "subscribe_info.h" -#include "utils.h" - -namespace OHOS { -namespace DeviceProfile { -using namespace testing; -using namespace testing::ext; - -namespace { -constexpr uint32_t MAX_EVENT_LEN = 1000001; -constexpr int32_t MAX_DEVICE_LEN = 1000001; -} - -class DeviceProfileUtilsTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp(); - void TearDown(); -}; - -void DeviceProfileUtilsTest::SetUpTestCase() -{ - DTEST_LOG << "SetUpTestCase" << std::endl; - DistributedDeviceProfileClient::GetInstance().DeleteDeviceProfile("111111"); -} - -void DeviceProfileUtilsTest::TearDownTestCase() -{ - DTEST_LOG << "TearDownTestCase" << std::endl; -} - -void DeviceProfileUtilsTest::SetUp() -{ - DTEST_LOG << "SetUp" << std::endl; -} - -void DeviceProfileUtilsTest::TearDown() -{ - DTEST_LOG << "TearDown" << std::endl; -} - -/** - * @tc.name: WriteProfileEvents_001 - * @tc.desc: WriteProfileEvents - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(DeviceProfileUtilsTest, WriteProfileEvents_001, TestSize.Level3) -{ - std::list failedEvents; - Parcel parcel; - bool ret = DeviceProfileUtils::WriteProfileEvents(failedEvents, parcel); - EXPECT_TRUE(ret); -} - -/** - * @tc.name: Unmarshalling_002 - * @tc.desc: unmarshalling - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(DeviceProfileUtilsTest, Unmarshalling_001, TestSize.Level3) -{ - std::list failedEvents; - failedEvents.emplace_back(ProfileEvent::EVENT_PROFILE_CHANGED); - failedEvents.emplace_back(ProfileEvent::EVENT_SYNC_COMPLETED); - Parcel parcel; - bool ret = DeviceProfileUtils::WriteProfileEvents(failedEvents, parcel); - EXPECT_TRUE(ret); -} - -/** - * @tc.name: ReadProfileEvents_001 - * @tc.desc: ReadProfileEvents - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(DeviceProfileUtilsTest, ReadProfileEvents_001, TestSize.Level3) -{ - Parcel parcel; - parcel.WriteUint32(MAX_EVENT_LEN); - std::list failedEvents; - bool ret = DeviceProfileUtils::ReadProfileEvents(parcel, failedEvents); - EXPECT_FALSE(ret); -} - -/** - * @tc.name: ReadProfileEvents_002 - * @tc.desc: ReadProfileEvents - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(DeviceProfileUtilsTest, ReadProfileEvents_002, TestSize.Level3) -{ - Parcel parcel; - parcel.WriteUint32(1); - parcel.WriteUint32(1); - std::list failedEvents; - bool ret = DeviceProfileUtils::ReadProfileEvents(parcel, failedEvents); - EXPECT_TRUE(ret); -} - -/** - * @tc.name: ReadProfileEvents_003 - * @tc.desc: ReadProfileEvents - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(DeviceProfileUtilsTest, ReadProfileEvents_003, TestSize.Level3) -{ - Parcel parcel; - parcel.WriteUint32(1); - parcel.WriteUint32(0); - std::list failedEvents; - bool ret = DeviceProfileUtils::ReadProfileEvents(parcel, failedEvents); - EXPECT_FALSE(ret); -} - -/** - * @tc.name: ReadProfileEvents_003 - * @tc.desc: ReadProfileEvents - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(DeviceProfileUtilsTest, ReadProfileEvents_004, TestSize.Level3) -{ - Parcel parcel; - parcel.WriteUint32(1); - parcel.WriteUint32(4); - std::list failedEvents; - bool ret = DeviceProfileUtils::ReadProfileEvents(parcel, failedEvents); - EXPECT_FALSE(ret); -} - -/** - * @tc.name: AnonymizeString_003 - * @tc.desc: AnonymizeString - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(DeviceProfileUtilsTest, AnonymizeString_001, TestSize.Level3) -{ - std::string value = ""; - std::string ret = DeviceProfileUtils::AnonymizeString(value); - EXPECT_EQ("******", ret); -} - -/** - * @tc.name: AnonymizeString_003 - * @tc.desc: AnonymizeString - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(DeviceProfileUtilsTest, AnonymizeString_002, TestSize.Level3) -{ - std::string value = "123456789012345678901"; - std::string ret = DeviceProfileUtils::AnonymizeString(value); - EXPECT_EQ("1234******8901", ret); -} - -/** - * @tc.name: Dump_001 - * @tc.desc: dump - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(DeviceProfileUtilsTest, Dump_001, TestSize.Level3) -{ - std::string result; - std::vector args; - bool ret = DeviceProfileDumper::Dump(args, result); - EXPECT_FALSE(ret); -} - -/** - * @tc.name: Marshalling_001 - * @tc.desc: dump - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(DeviceProfileUtilsTest, SyncOptionsMarshalling_001, TestSize.Level3) -{ - SyncOptions syncOption; - Parcel parcel; - bool ret = syncOption.Marshalling(parcel); - EXPECT_TRUE(ret); -} - -/** - * @tc.name: Marshalling_002 - * @tc.desc: dump - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(DeviceProfileUtilsTest, SyncOptionsMarshalling_002, TestSize.Level3) -{ - SyncOptions syncOption; - syncOption.AddDevice("1234"); - Parcel parcel; - bool ret = syncOption.Marshalling(parcel); - EXPECT_TRUE(ret); -} - -/** - * @tc.name: Unmarshalling_001 - * @tc.desc: Unmarshalling - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(DeviceProfileUtilsTest, SyncOptionsUnmarshalling_001, TestSize.Level3) -{ - Parcel parcel; - parcel.WriteInt32(1); - parcel.WriteInt32(0); - SyncOptions syncOption; - bool ret = syncOption.Unmarshalling(parcel); - EXPECT_TRUE(ret); -} - -/** - * @tc.name: Unmarshalling_002 - * @tc.desc: Unmarshalling - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(DeviceProfileUtilsTest, SyncOptionsUnmarshalling_002, TestSize.Level3) -{ - Parcel parcel; - parcel.WriteInt32(1); - parcel.WriteInt32(MAX_DEVICE_LEN); - SyncOptions syncOption; - bool ret = syncOption.Unmarshalling(parcel); - EXPECT_FALSE(ret); -} - -/** - * @tc.name: Unmarshalling_003 - * @tc.desc: Unmarshalling - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(DeviceProfileUtilsTest, SyncOptionsUnmarshalling_003, TestSize.Level3) -{ - Parcel parcel; - parcel.WriteInt32(1); - parcel.WriteInt32(1); - parcel.WriteString("12345"); - SyncOptions syncOption; - bool ret = syncOption.Unmarshalling(parcel); - EXPECT_TRUE(ret); -} -} -} \ No newline at end of file diff --git a/old/services/core/test/unittest/distributed_device_profile_stub_test.cpp b/old/services/core/test/unittest/distributed_device_profile_stub_test.cpp deleted file mode 100644 index 8b9675d2..00000000 --- a/old/services/core/test/unittest/distributed_device_profile_stub_test.cpp +++ /dev/null @@ -1,446 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * 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. - */ - -#include -#include - -#include "distributed_device_profile_stub.h" -#include "idistributed_device_profile.h" -#include "iremote_stub.h" -#include "device_profile_errors.h" -#include "distributed_device_profile_client.h" -#include "distributed_device_profile_enums.h" -#include "deviceprofile_ipc_interface_code.h" -#include "distributed_device_profile_errors.h" -#include "utils.h" - -namespace OHOS { -namespace DeviceProfile { - -using namespace OHOS::DistributedDeviceProfile; -using namespace testing; -using namespace testing::ext; - -class DeviceProfileStubTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp(); - void TearDown(); -}; - -void DeviceProfileStubTest::SetUpTestCase() -{ - DTEST_LOG << "SetUpTestCase" << std::endl; -} - -void DeviceProfileStubTest::TearDownTestCase() -{ - DTEST_LOG << "TearDownTestCase" << std::endl; -} - -void DeviceProfileStubTest::SetUp() -{ - DTEST_LOG << "SetUp" << std::endl; -} - -void DeviceProfileStubTest::TearDown() -{ - DTEST_LOG << "TearDown" << std::endl; -} - -class DistributedDeviceProfileStubTest : public DistributedDeviceProfileStub { -public: - DistributedDeviceProfileStubTest() = default; - ~DistributedDeviceProfileStubTest() = default; - int32_t PutDeviceProfile(const ServiceCharacteristicProfile& profile) - { - (void)profile; - return 0; - } - int32_t GetDeviceProfile(const std::string& udid, const std::string& serviceId, - ServiceCharacteristicProfile& profile) - { - (void)udid; - (void)serviceId; - (void)profile; - return 0; - } - int32_t DeleteDeviceProfile(const std::string& serviceId) - { - (void)serviceId; - return 0; - } - int32_t SubscribeProfileEvents(const std::list& subscribeInfos, - const sptr& profileEventNotifier, std::list& failedEvents) - { - (void)subscribeInfos; - (void)profileEventNotifier; - (void)failedEvents; - return 0; - } - int32_t UnsubscribeProfileEvents(const std::list& profileEvents, - const sptr& profileEventNotifier, std::list& failedEvents) - { - (void)profileEvents; - (void)profileEventNotifier; - (void)failedEvents; - return 0; - } - int32_t SyncDeviceProfile(const SyncOptions& syncOptions, const sptr& profileEventNotifier) - { - (void)syncOptions; - (void)profileEventNotifier; - return 0; - } -}; - -HWTEST_F(DeviceProfileStubTest, NotifyAclEventInner_001, TestSize.Level3) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(DistributedDeviceProfile::DPInterfaceCode::PUT_ACL_PROFILE); - std::shared_ptr distributedDeviceProfileStub = - std::make_shared(); - int32_t result = distributedDeviceProfileStub->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(DP_READ_PARCEL_FAIL, result); -} - -HWTEST_F(DeviceProfileStubTest, NotifyAclEventInner_002, TestSize.Level3) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(DPInterfaceCode::UPDATE_ACL_PROFILE); - std::shared_ptr distributedDeviceProfileStub = - std::make_shared(); - int32_t result = distributedDeviceProfileStub->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(DP_READ_PARCEL_FAIL, result); -} - -HWTEST_F(DeviceProfileStubTest, NotifyAclEventInner_003, TestSize.Level3) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(DistributedDeviceProfile::DPInterfaceCode::GET_TRUST_DEVICE_PROFILE); - std::shared_ptr distributedDeviceProfileStub = - std::make_shared(); - int32_t result = distributedDeviceProfileStub->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(ERR_FLATTEN_OBJECT, result); -} - -HWTEST_F(DeviceProfileStubTest, NotifyAclEventInner_004, TestSize.Level3) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(DistributedDeviceProfile::DPInterfaceCode::GET_ALL_TRUST_DEVICE_PROFILE); - std::shared_ptr distributedDeviceProfileStub = - std::make_shared(); - int32_t result = distributedDeviceProfileStub->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(DP_READ_PARCEL_FAIL, result); -} - -HWTEST_F(DeviceProfileStubTest, NotifyAclEventInner_005, TestSize.Level3) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(DistributedDeviceProfile::DPInterfaceCode::GET_ACL_PROFILE); - std::shared_ptr distributedDeviceProfileStub = - std::make_shared(); - int32_t result = distributedDeviceProfileStub->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(DP_READ_PARCEL_FAIL, result); -} - -HWTEST_F(DeviceProfileStubTest, NotifyAclEventInner_006, TestSize.Level3) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(DistributedDeviceProfile::DPInterfaceCode::GET_ALL_ACL_PROFILE); - std::shared_ptr distributedDeviceProfileStub = - std::make_shared(); - int32_t result = distributedDeviceProfileStub->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(DP_WRITE_PARCEL_FAIL, result); -} - -HWTEST_F(DeviceProfileStubTest, NotifyAclEventInner_007, TestSize.Level3) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(DistributedDeviceProfile::DPInterfaceCode::DELETE_ACL_PROFILE); - std::shared_ptr distributedDeviceProfileStub = - std::make_shared(); - int32_t result = distributedDeviceProfileStub->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(ERR_FLATTEN_OBJECT, result); -} - -HWTEST_F(DeviceProfileStubTest, NotifyAclEventInner_008, TestSize.Level3) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(DistributedDeviceProfile::DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE); - std::shared_ptr distributedDeviceProfileStub = - std::make_shared(); - int32_t result = distributedDeviceProfileStub->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(DP_READ_PARCEL_FAIL, result); -} - -HWTEST_F(DeviceProfileStubTest, NotifyAclEventInner_009, TestSize.Level3) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(DistributedDeviceProfile::DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE); - std::shared_ptr distributedDeviceProfileStub = - std::make_shared(); - int32_t result = distributedDeviceProfileStub->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(DP_READ_PARCEL_FAIL, result); -} - -HWTEST_F(DeviceProfileStubTest, NotifyAclEventInner_010, TestSize.Level3) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(DistributedDeviceProfile::DPInterfaceCode::SEND_SUBSCRIBE_INFOS); - std::shared_ptr distributedDeviceProfileStub = - std::make_shared(); - int32_t result = distributedDeviceProfileStub->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(DP_READ_PARCEL_FAIL, result); -} - -HWTEST_F(DeviceProfileStubTest, NotifyAclEventInner_011, TestSize.Level3) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(DistributedDeviceProfile::DPInterfaceCode::PUT_SERVICE_PROFILE); - std::shared_ptr distributedDeviceProfileStub = - std::make_shared(); - int32_t result = distributedDeviceProfileStub->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(DP_READ_PARCEL_FAIL, result); -} - -HWTEST_F(DeviceProfileStubTest, NotifyAclEventInner_012, TestSize.Level3) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(DistributedDeviceProfile::DPInterfaceCode::PUT_SERVICE_PROFILE_BATCH); - std::shared_ptr distributedDeviceProfileStub = - std::make_shared(); - int32_t result = distributedDeviceProfileStub->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(DP_READ_PARCEL_FAIL, result); -} - -HWTEST_F(DeviceProfileStubTest, NotifyAclEventInner_013, TestSize.Level3) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(DistributedDeviceProfile::DPInterfaceCode::PUT_CHAR_PROFILE); - std::shared_ptr distributedDeviceProfileStub = - std::make_shared(); - int32_t result = distributedDeviceProfileStub->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(DP_READ_PARCEL_FAIL, result); -} - -HWTEST_F(DeviceProfileStubTest, NotifyAclEventInner_014, TestSize.Level3) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(DistributedDeviceProfile::DPInterfaceCode::PUT_CHAR_PROFILE_BATCH); - std::shared_ptr distributedDeviceProfileStub = - std::make_shared(); - int32_t result = distributedDeviceProfileStub->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(DP_READ_PARCEL_FAIL, result); -} - -HWTEST_F(DeviceProfileStubTest, NotifyAclEventInner_015, TestSize.Level3) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - uint32_t code = 1000; - std::shared_ptr distributedDeviceProfileStub = - std::make_shared(); - int32_t result = distributedDeviceProfileStub->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(305, result); -} - -HWTEST_F(DeviceProfileStubTest, NotifyOldEventInner_001, TestSize.Level3) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(IDeviceProfileInterfaceCode::PUT_DEVICE_PROFILE); - std::shared_ptr distributedDeviceProfileStub = - std::make_shared(); - int32_t result = distributedDeviceProfileStub->NotifyOldEventInner(code, data, reply, option); - EXPECT_EQ(ERR_NULL_OBJECT, result); -} - -HWTEST_F(DeviceProfileStubTest, NotifyOldEventInner_002, TestSize.Level3) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(IDeviceProfileInterfaceCode::DELETE_DEVICE_PROFILE); - std::shared_ptr distributedDeviceProfileStub = - std::make_shared(); - int32_t result = distributedDeviceProfileStub->NotifyOldEventInner(code, data, reply, option); - EXPECT_EQ(0, result); -} - -HWTEST_F(DeviceProfileStubTest, NotifyOldEventInner_003, TestSize.Level3) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(IDeviceProfileInterfaceCode::GET_DEVICE_PROFILE); - std::shared_ptr distributedDeviceProfileStub = - std::make_shared(); - int32_t result = distributedDeviceProfileStub->NotifyOldEventInner(code, data, reply, option); - EXPECT_EQ(ERR_FLATTEN_OBJECT, result); -} - -HWTEST_F(DeviceProfileStubTest, NotifyOldEventInner_004, TestSize.Level3) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(IDeviceProfileInterfaceCode::SUBSCRIBE_PROFILE_EVENT); - std::shared_ptr distributedDeviceProfileStub = - std::make_shared(); - int32_t result = distributedDeviceProfileStub->NotifyOldEventInner(code, data, reply, option); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, result); -} - -HWTEST_F(DeviceProfileStubTest, NotifyOldEventInner_005, TestSize.Level3) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(IDeviceProfileInterfaceCode::UNSUBSCRIBE_PROFILE_EVENT); - std::shared_ptr distributedDeviceProfileStub = - std::make_shared(); - int32_t result = distributedDeviceProfileStub->NotifyOldEventInner(code, data, reply, option); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, result); -} - -HWTEST_F(DeviceProfileStubTest, NotifyOldEventInner_006, TestSize.Level3) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(IDeviceProfileInterfaceCode::SYNC_DEVICE_PROFILE); - std::shared_ptr distributedDeviceProfileStub = - std::make_shared(); - int32_t result = distributedDeviceProfileStub->NotifyOldEventInner(code, data, reply, option); - EXPECT_EQ(ERR_NULL_OBJECT, result); -} - -HWTEST_F(DeviceProfileStubTest, NotifyNewEventInner_001, TestSize.Level3) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(DPInterfaceCode::GET_DEVICE_PROFILE_NEW); - std::shared_ptr distributedDeviceProfileStub = - std::make_shared(); - int32_t result = distributedDeviceProfileStub->NotifyNewEventInner(code, data, reply, option); - EXPECT_EQ(ERR_FLATTEN_OBJECT, result); -} - -HWTEST_F(DeviceProfileStubTest, NotifyNewEventInner_002, TestSize.Level3) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(DPInterfaceCode::GET_SERVICE_PROFILE); - std::shared_ptr distributedDeviceProfileStub = - std::make_shared(); - int32_t result = distributedDeviceProfileStub->NotifyNewEventInner(code, data, reply, option); - EXPECT_EQ(ERR_FLATTEN_OBJECT, result); -} - -HWTEST_F(DeviceProfileStubTest, NotifyNewEventInner_003, TestSize.Level3) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(DPInterfaceCode::GET_CHAR_PROFILE); - std::shared_ptr distributedDeviceProfileStub = - std::make_shared(); - int32_t result = distributedDeviceProfileStub->NotifyNewEventInner(code, data, reply, option); - EXPECT_EQ(ERR_FLATTEN_OBJECT, result); -} - -HWTEST_F(DeviceProfileStubTest, NotifyNewEventInner_004, TestSize.Level3) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(DPInterfaceCode::DEL_SERVICE_PROFILE); - std::shared_ptr distributedDeviceProfileStub = - std::make_shared(); - int32_t result = distributedDeviceProfileStub->NotifyNewEventInner(code, data, reply, option); - EXPECT_EQ(ERR_FLATTEN_OBJECT, result); -} - -HWTEST_F(DeviceProfileStubTest, NotifyNewEventInner_005, TestSize.Level3) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(DPInterfaceCode::DEL_CHAR_PROFILE); - std::shared_ptr distributedDeviceProfileStub = - std::make_shared(); - int32_t result = distributedDeviceProfileStub->NotifyNewEventInner(code, data, reply, option); - EXPECT_EQ(ERR_FLATTEN_OBJECT, result); -} - -HWTEST_F(DeviceProfileStubTest, NotifyNewEventInner_006, TestSize.Level3) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - uint32_t code = static_cast(DPInterfaceCode::SYNC_DEVICE_PROFILE_NEW); - std::shared_ptr distributedDeviceProfileStub = - std::make_shared(); - int32_t result = distributedDeviceProfileStub->NotifyNewEventInner(code, data, reply, option); - EXPECT_EQ(DP_READ_PARCEL_FAIL, result); -} - -HWTEST_F(DeviceProfileStubTest, NotifyNewEventInner_007, TestSize.Level3) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - uint32_t code = 1000; - std::shared_ptr distributedDeviceProfileStub = - std::make_shared(); - int32_t result = distributedDeviceProfileStub->NotifyNewEventInner(code, data, reply, option); - EXPECT_EQ(305, result); -} -} // namespace DeviceProfile -} // namespace OHOS \ No newline at end of file diff --git a/old/services/core/test/unittest/event_subscribe_test.cpp b/old/services/core/test/unittest/event_subscribe_test.cpp deleted file mode 100644 index 2cfaab34..00000000 --- a/old/services/core/test/unittest/event_subscribe_test.cpp +++ /dev/null @@ -1,486 +0,0 @@ -/* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. - * 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. - */ - -#include "gtest/gtest.h" - -#include - -#include "utils.h" - -#include "device_profile_errors.h" -#include "distributed_device_profile_client.h" -#include "nlohmann/json.hpp" - -namespace OHOS { -namespace DeviceProfile { -using namespace std::chrono_literals; -using namespace testing; -using namespace testing::ext; - -namespace { -const int32_t UT_ERROR = -1; -} -class EventSubscribeTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp(); - void TearDown(); -}; - -void EventSubscribeTest::SetUpTestCase() -{ - DistributedDeviceProfileClient::GetInstance().DeleteDeviceProfile("111111"); -} - -void EventSubscribeTest::TearDownTestCase() -{ -} - -void EventSubscribeTest::SetUp() -{ -} - -void EventSubscribeTest::TearDown() -{ -} - -class ProfileEventCallback : public IProfileEventCallback { -public: - ProfileEventCallback() = default; - ~ProfileEventCallback() = default; - - void OnSyncCompleted(const SyncResult& syncResults) override - { - } - - void OnProfileChanged(const ProfileChangeNotification& changeNotification) override - { - if (!subServiceIds_.empty()) { - const auto& profileEntries = changeNotification.GetProfileEntries(); - for (const auto& ProfileEntry : profileEntries) { - auto key = ProfileEntry.key; - DTEST_LOG << "key: " << key << std::endl; - auto iter = std::find(subServiceIds_.begin(), subServiceIds_.end(), key); - EXPECT_TRUE(iter != subServiceIds_.end()); - numNotifications_++; - } - } - } - - void SetSubServiceIds(const std::list& subServiceIds) - { - subServiceIds_ = subServiceIds; - } - - int32_t GetNotificationNum() const - { - return numNotifications_; - } - -private: - std::list subServiceIds_; - int32_t numNotifications_ {0}; -}; - -int32_t PutFakeStorage() -{ - ServiceCharacteristicProfile profile; - profile.SetServiceId("fakeStorage"); - profile.SetServiceType("fakeStorage"); - nlohmann::json j; - j["capacity"] = 0; - profile.SetCharacteristicProfileJson(j.dump()); - return DistributedDeviceProfileClient::GetInstance().PutDeviceProfile(profile); -} - -int32_t PutFakeSystem() -{ - ServiceCharacteristicProfile profile; - profile.SetServiceId("fakeSystem"); - profile.SetServiceType("fakeSystem"); - nlohmann::json j; - j["harmonyVersion"] = "2.2.0"; - profile.SetCharacteristicProfileJson(j.dump()); - return DistributedDeviceProfileClient::GetInstance().PutDeviceProfile(profile); -} - -int32_t MockSubscribeEvents(const std::shared_ptr& eventCb, - const std::list& serviceIds, const std::string& deviceId) -{ - if (eventCb == nullptr) { - return UT_ERROR; - } - eventCb->SetSubServiceIds(serviceIds); - ExtraInfo extraInfo; - extraInfo["deviceId"] = deviceId; - extraInfo["serviceIds"] = serviceIds; - - std::list subscribeInfos; - SubscribeInfo eventChange; - eventChange.profileEvent = ProfileEvent::EVENT_PROFILE_CHANGED; - eventChange.extraInfo = std::move(extraInfo); - subscribeInfos.emplace_back(eventChange); - - SubscribeInfo eventSync; - eventSync.profileEvent = ProfileEvent::EVENT_SYNC_COMPLETED; - subscribeInfos.emplace_back(eventSync); - - std::list failedEvents; - return DistributedDeviceProfileClient::GetInstance().SubscribeProfileEvents( - subscribeInfos, eventCb, failedEvents); -} - -int32_t MockUnsubscribeEvents(const std::shared_ptr& eventCb) -{ - if (eventCb == nullptr) { - return UT_ERROR; - } - std::list profileEvents; - profileEvents.emplace_back(ProfileEvent::EVENT_PROFILE_CHANGED); - profileEvents.emplace_back(ProfileEvent::EVENT_SYNC_COMPLETED); - std::list failedEvents; - return DistributedDeviceProfileClient::GetInstance().UnsubscribeProfileEvents( - profileEvents, eventCb, failedEvents); -} - -int32_t MockSubscribeEvent(const std::shared_ptr& eventCb, - const std::list& serviceIds, const std::string& deviceId) -{ - if (eventCb == nullptr) { - return UT_ERROR; - } - eventCb->SetSubServiceIds(serviceIds); - ExtraInfo extraInfo; - extraInfo["deviceId"] = deviceId; - extraInfo["serviceIds"] = serviceIds; - - SubscribeInfo subscribeInfo; - subscribeInfo.profileEvent = ProfileEvent::EVENT_PROFILE_CHANGED; - subscribeInfo.extraInfo = std::move(extraInfo); - return DistributedDeviceProfileClient::GetInstance().SubscribeProfileEvent(subscribeInfo, eventCb); -} - -/** - * @tc.name: Subscribe001 - * @tc.desc: subscribe a service and put a service profile - * @tc.type: FUNC - */ -HWTEST_F(EventSubscribeTest, Subscribe001, TestSize.Level2) -{ - auto callback = std::make_shared(); - if (MockSubscribeEvent(callback, {"fakeStorage"}, "")) { - EXPECT_TRUE(MockSubscribeEvent(callback, {"fakeStorage"}, "")); - DTEST_LOG << "subscribe failed" << std::endl; - return; - } - - int32_t errCode = PutFakeStorage(); - EXPECT_EQ(errCode, ERR_OK); - if (errCode == ERR_OK) { - DTEST_LOG << "put succeeded" << std::endl; - std::this_thread::sleep_for(1s); - EXPECT_TRUE(callback->GetNotificationNum() == 1); - } -} - -/** - * @tc.name: Subscribe002 - * @tc.desc: subscribe a service and put a unsubscribed service - * @tc.type: FUNC - */ -HWTEST_F(EventSubscribeTest, Subscribe002, TestSize.Level2) -{ - auto callback = std::make_shared(); - if (MockSubscribeEvent(callback, {"fakeSystem"}, "")) { - EXPECT_TRUE(MockSubscribeEvent(callback, {"fakeSystem"}, "")); - DTEST_LOG << "subscribe failed" << std::endl; - return; - } - int32_t errCode = PutFakeStorage(); - EXPECT_EQ(errCode, ERR_OK); - if (errCode == ERR_OK) { - DTEST_LOG << "put succeeded" << std::endl; - std::this_thread::sleep_for(1s); - EXPECT_TRUE(callback->GetNotificationNum() == 0); - } -} - -/** - * @tc.name: Subscribe003 - * @tc.desc: subscribe services and put service - * @tc.type: FUNC - */ -HWTEST_F(EventSubscribeTest, Subscribe003, TestSize.Level2) -{ - auto callback = std::make_shared(); - std::list serviceIds = {"fakeStorage", "fakeSystem"}; - if (MockSubscribeEvents(callback, serviceIds, "") != ERR_OK) { - EXPECT_NE(MockSubscribeEvents(callback, serviceIds, ""), ERR_OK); - DTEST_LOG << "subscribe failed" << std::endl; - return; - } - int32_t errCode = PutFakeSystem(); - EXPECT_EQ(errCode, ERR_OK); - if (errCode == ERR_OK) { - DTEST_LOG << "put succeeded" << std::endl; - std::this_thread::sleep_for(1s); - EXPECT_TRUE(callback->GetNotificationNum() == 1); - } -} - -/** - * @tc.name: Subscribe004 - * @tc.desc: subscribe with invalid deviceId - * @tc.type: FUNC - */ -HWTEST_F(EventSubscribeTest, Subscribe004, TestSize.Level2) -{ - auto callback = std::make_shared(); - std::list serviceIds = {"fakeStorage", "fakeSystem"}; - if (MockSubscribeEvent(callback, serviceIds, "fake_device_id") != ERR_OK) { - EXPECT_NE(MockSubscribeEvent(callback, serviceIds, "fake_device_id"), ERR_OK); - DTEST_LOG << "subscribe failed" << std::endl; - return; - } - int32_t errCode = PutFakeStorage(); - EXPECT_EQ(errCode, ERR_OK); - if (errCode == ERR_OK) { - DTEST_LOG << "put succeeded" << std::endl; - std::this_thread::sleep_for(1s); - EXPECT_TRUE(callback->GetNotificationNum() == 0); - } -} - -/** - * @tc.name: Subscribe005 - * @tc.desc: subscribe services and put services - * @tc.type: FUNC - */ -HWTEST_F(EventSubscribeTest, Subscribe005, TestSize.Level2) -{ - auto callback = std::make_shared(); - /** - * @tc.steps: step1. subscribe change event with two services - */ - std::list serviceIds = {"fakeStorage", "fakeSystem"}; - if (MockSubscribeEvent(callback, serviceIds, "") != ERR_OK) { - EXPECT_NE(MockSubscribeEvent(callback, serviceIds, ""), ERR_OK); - DTEST_LOG << "subscribe failed" << std::endl; - return; - } - - /** - * @tc.steps: step2. put service profile which is subscribed - * @tc.expected: step2. got one notification. - */ - int32_t errCode = PutFakeStorage(); - EXPECT_EQ(errCode, ERR_OK); - if (errCode == ERR_OK) { - DTEST_LOG << "put succeeded" << std::endl; - std::this_thread::sleep_for(1s); - EXPECT_TRUE(callback->GetNotificationNum() == 1); - } - /** - * @tc.steps: step3. put the other subscribed service profile - * @tc.expected: step3. got notification again. - */ - errCode = PutFakeSystem(); - EXPECT_EQ(errCode, ERR_OK); - if (errCode == ERR_OK) { - DTEST_LOG << "put succeeded" << std::endl; - std::this_thread::sleep_for(1s); - EXPECT_TRUE(callback->GetNotificationNum() == 2); - } -} - -/** - * @tc.name: Subscribe006 - * @tc.desc: subscribe with duplicated events - * @tc.type: FUNC - */ -HWTEST_F(EventSubscribeTest, Subscribe006, TestSize.Level0) -{ - auto callback = std::make_shared(); - std::list subscribeInfos; - ExtraInfo extraInfo; - extraInfo["deviceId"] = ""; - extraInfo["serviceIds"] = {"fakeSystem"}; - - SubscribeInfo eventChange; - eventChange.profileEvent = ProfileEvent::EVENT_PROFILE_CHANGED; - eventChange.extraInfo = std::move(extraInfo); - subscribeInfos.emplace_back(eventChange); - subscribeInfos.emplace_back(eventChange); - - std::list failedEvents; - int32_t errCode = DistributedDeviceProfileClient::GetInstance().SubscribeProfileEvents( - subscribeInfos, callback, failedEvents); - EXPECT_TRUE(errCode == ERR_DP_INVALID_PARAMS); -} - -/** - * @tc.name: Unsubscribe001 - * @tc.desc: unsubscribe event which is not subscribed yet - * @tc.type: FUNC - */ -HWTEST_F(EventSubscribeTest, Unsubscribe001, TestSize.Level0) -{ - auto callback = std::make_shared(); - int32_t errCode = DistributedDeviceProfileClient::GetInstance().UnsubscribeProfileEvent( - ProfileEvent::EVENT_PROFILE_CHANGED, callback); - EXPECT_TRUE(errCode == ERR_DP_NOT_SUBSCRIBED); -} - -/** - * @tc.name: Unsubscribe002 - * @tc.desc: unsubscribe events which are not subscribed yet - * @tc.type: FUNC - */ -HWTEST_F(EventSubscribeTest, Unsubscribe002, TestSize.Level0) -{ - auto callback = std::make_shared(); - int32_t errCode = MockUnsubscribeEvents(callback); - EXPECT_TRUE(errCode == ERR_DP_NOT_SUBSCRIBED); -} - -/** - * @tc.name: SubscribeWithUnsusbscribe001 - * @tc.desc: subscribe events and then unsubscribe one - * @tc.type: FUNC - */ -HWTEST_F(EventSubscribeTest, SubscribeWithUnsusbscribe001, TestSize.Level2) -{ - auto callback = std::make_shared(); - - /** - * @tc.steps: step1. subscribe sync and change event - */ - std::list serviceIds = {"fakeStorage", "fakeSystem"}; - if (MockSubscribeEvents(callback, serviceIds, "") != ERR_OK) { - EXPECT_NE(MockSubscribeEvents(callback, serviceIds, ""), ERR_OK); - DTEST_LOG << "subscribe failed" << std::endl; - return; - } - - /** - * @tc.steps: step2. put service profile which is subscribed - * @tc.expected: step2. got one notification. - */ - int32_t errCode = PutFakeSystem(); - EXPECT_EQ(errCode, ERR_OK); - if (errCode == ERR_OK) { - DTEST_LOG << "put succeeded" << std::endl; - std::this_thread::sleep_for(1s); - EXPECT_TRUE(callback->GetNotificationNum() == 1); - } - - /** - * @tc.steps: step3. unsubscribe sync event - */ - errCode = DistributedDeviceProfileClient::GetInstance().UnsubscribeProfileEvent( - ProfileEvent::EVENT_SYNC_COMPLETED, callback); - if (errCode != ERR_OK) { - EXPECT_NE(errCode, ERR_OK); - DTEST_LOG << "unsubscribe failed" << std::endl; - return; - } - EXPECT_EQ(errCode, ERR_OK); - - /** - * @tc.steps: step4. put the other subscribed service profile - * @tc.expected: step4. got notification again. - */ - errCode = PutFakeStorage(); - EXPECT_EQ(errCode, ERR_OK); - if (errCode == ERR_OK) { - DTEST_LOG << "put succeeded" << std::endl; - std::this_thread::sleep_for(1s); - EXPECT_TRUE(callback->GetNotificationNum() == 2); - } -} - -/** - * @tc.name: SubscribeWithUnsusbscribe002 - * @tc.desc: subscribe events and then unsubscribe all - * @tc.type: FUNC - */ -HWTEST_F(EventSubscribeTest, SubscribeWithUnsusbscribe002, TestSize.Level2) -{ - auto callback = std::make_shared(); - - /** - * @tc.steps: step1. subscribe sync and change event - */ - std::list serviceIds = {"fakeStorage", "fakeSystem"}; - if (MockSubscribeEvents(callback, serviceIds, "") != ERR_OK) { - EXPECT_NE(MockSubscribeEvents(callback, serviceIds, ""), ERR_OK); - DTEST_LOG << "subscribe failed" << std::endl; - return; - } - - /** - * @tc.steps: step2. put service profile which is subscribed - * @tc.expected: step2. got one notification. - */ - int32_t errCode = PutFakeSystem(); - EXPECT_EQ(errCode, ERR_OK); - if (errCode == ERR_OK) { - DTEST_LOG << "put succeeded" << std::endl; - std::this_thread::sleep_for(1s); - EXPECT_TRUE(callback->GetNotificationNum() == 1); - } - - /** - * @tc.steps: step3. unsubscribe all events - */ - if (MockUnsubscribeEvents(callback) != ERR_OK) { - EXPECT_NE(MockUnsubscribeEvents(callback), ERR_OK); - DTEST_LOG << "unsubscribe failed" << std::endl; - return; - } - - /** - * @tc.steps: step4. put a subscribed service profile - * @tc.expected: step4. can't receive notification. - */ - errCode = PutFakeStorage(); - EXPECT_EQ(errCode, ERR_OK); - if (errCode == ERR_OK) { - DTEST_LOG << "put succeeded" << std::endl; - std::this_thread::sleep_for(1s); - EXPECT_TRUE(callback->GetNotificationNum() == 1); - } -} - -/** - * @tc.name: SubDeviceProfile_001 - * @tc.desc: sub device profile - * @tc.type: FUNC - * @tc.require: I51HKG - */ -HWTEST_F(EventSubscribeTest, UnsubDeviceProfile_001, TestSize.Level3) -{ - auto callback = std::make_shared(); - std::list profileEvents; - profileEvents.emplace_back(ProfileEvent::EVENT_PROFILE_CHANGED); - std::list failedEvents; - auto result = DistributedDeviceProfileClient::GetInstance().UnsubscribeProfileEvents( - profileEvents, callback, failedEvents); - DTEST_LOG << "result: " << result << std::endl; - EXPECT_NE(result, ERR_INVALID_DATA); -} -} -} \ No newline at end of file diff --git a/old/services/core/test/unittest/profile_authority_test.cpp b/old/services/core/test/unittest/profile_authority_test.cpp deleted file mode 100644 index 2f38a9de..00000000 --- a/old/services/core/test/unittest/profile_authority_test.cpp +++ /dev/null @@ -1,522 +0,0 @@ -/* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. - * 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. - */ - -#include "gtest/gtest.h" - -#include "test_util.h" -#include "utils.h" - -#define protected public -#define private public -#include "authority_manager.h" -#include "device_manager.h" -#include "distributed_device_profile_client.h" -#include "dp_device_manager.h" -#include "sync_coordinator.h" -#include "trust_group_manager.h" -#undef private -#undef protected -#include "device_profile_errors.h" - -namespace OHOS { -namespace DeviceProfile { -using namespace testing; -using namespace testing::ext; -using namespace DistributedHardware; - -namespace { -const std::string AUTHORITY_JSON_PATH = "/system/etc/deviceprofile/authority.json"; -const std::string TEST_DEVICEID = "1111111111111111111111111"; -const std::string TEST_TRUST_GROUP = - "{\"groupId\":\"id\",\"groupType\":0,\"groupName\":\"name\",\"groupOwner\":\"test\",\"groupVisibility\":1}"; -const std::string TEST_TRUST_GROUPS = - "[{\"groupId\":\"id\",\"groupType\":0,\"groupName\":\"name\",\"groupOwner\":\"test\",\"groupVisibility\":1}]"; -const std::string TEST_TRUST_GROUPS_VISIABLE = - "[{\"groupId\":\"id\",\"groupType\":0,\"groupName\":\"name\",\"groupOwner\":\"test\",\"groupVisibility\":-1}]"; -const std::string TEST_TRUST_GROUPS_SAMEACCOUNT = - "[{\"groupId\":\"id\",\"groupType\":256,\"groupName\":\"name\",\"groupOwner\":\"test\",\"groupVisibility\":-1}]"; -const std::string TEST_TRUST_GROUP_EMPTY = "{}"; -const std::string TEST_TRUST_GROUPS_EMPTY = "[{}]"; -const std::string INVALID_AUTHORITY_STR = - "{\"fakeProcess1\":{\"servicesAuthority\":{\"all\":3}},\"fakeProcess2\":{\"servicesAuthority\":{\"all\":true}}}"; -const std::string VALID_AUTHORITY_STR = "{\"hdcd\":{\"servicesAuthority\":{\"all\":1,\"specific\":" \ - "{\"storage\":3,\"system\":3},\"prefix\":{\"cameraRear\":3}},\"interfacesAuthority\":{\"sync\":{}}}}"; -const std::string PKG_NAME = "ohos.deviceprofile"; -const std::string INVALID_INTERFACE_SERVICE = "{\"invalidinterface\":\"invalid\""; -const std::string INVALID_INTERFACE_VALUE = "{\"interfacesAuthority\":\"invalid\""; -const std::string INVALID_SERVIES_SPE = "{\"specific\":{\"storage\":\"3\"}}"; -const std::string INVALID_SERVIES_PRE = "{\"prefix\":{\"storage\":\"3\"}}"; -const std::string EMPTY_INTERFACE_VALUE = "{\"interfacesAuthority\":\"\""; -const std::string EMPTY_AUTHORITY_STR = "{\"distributedsched\":\"\""; -} - -class ProfileAuthorityTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - static bool LoadAuthorityCfg(const std::string& filePath); - static bool LoadAuthorityByStr(const std::string& jsonStr); - void SetUp(); - void TearDown(); - class DeviceInitCallBack : public DistributedHardware::DmInitCallback { - void OnRemoteDied() override; -}; -}; - -void ProfileAuthorityTest::DeviceInitCallBack::OnRemoteDied() -{ -} - -void ProfileAuthorityTest::SetUpTestCase() -{ - DistributedDeviceProfileClient::GetInstance().DeleteDeviceProfile("111111"); -} - -void ProfileAuthorityTest::TearDownTestCase() -{ -} - -void ProfileAuthorityTest::SetUp() -{ -} - -void ProfileAuthorityTest::TearDown() -{ -} - -bool ProfileAuthorityTest::LoadAuthorityCfg(const std::string& filePath) -{ - if (!AuthorityManager::GetInstance().LoadAuthorityCfg(filePath)) { - DTEST_LOG << "not found " << filePath << std::endl; - return false; - } - AuthorityManager::GetInstance().InitSupportedInterfaces(); - AuthorityManager::GetInstance().ValidateAuthorityCfg(); - return true; -} - -bool ProfileAuthorityTest::LoadAuthorityByStr(const std::string& jsonStr) -{ - AuthorityManager::GetInstance().authJson_ = - nlohmann::json::parse(jsonStr.c_str(), nullptr, false); - if (AuthorityManager::GetInstance().authJson_.is_discarded()) { - return false; - } - - AuthorityManager::GetInstance().InitSupportedInterfaces(); - AuthorityManager::GetInstance().ValidateAuthorityCfg(); - return true; -} - -/** - * @tc.name: PrecheckAuthority_001 - * @tc.desc: precheck an authority json with invalid config - * @tc.type: FUNC - * @tc.require: I4OH94 - */ -HWTEST_F(ProfileAuthorityTest, PrecheckAuthority_001, TestSize.Level2) -{ - if (!LoadAuthorityByStr(INVALID_AUTHORITY_STR)) { - return; - } - - EXPECT_EQ(AuthorityManager::GetInstance().authJson_.dump(), R"({})"); -} - -/** - * @tc.name: CheckAuthority_002 - * @tc.desc: check authority of a fake serviceId - * @tc.type: FUNC - * @tc.require: I4OH94 - */ -HWTEST_F(ProfileAuthorityTest, CheckAuthority_002, TestSize.Level2) -{ - if (!LoadAuthorityByStr(VALID_AUTHORITY_STR)) { - return; - } - - EXPECT_EQ(false, AuthorityManager::GetInstance().CheckServiceAuthority(AuthValue::AUTH_W, - "fakeServiceId")); -} - -/** - * @tc.name: CheckAuthority_003 - * @tc.desc: check authority of specific serviceId with diff auth value - * @tc.type: FUNC - * @tc.require: I4OH94 - */ -HWTEST_F(ProfileAuthorityTest, CheckAuthority_003, TestSize.Level2) -{ - if (!LoadAuthorityByStr(VALID_AUTHORITY_STR)) { - return; - } - - EXPECT_EQ(true, AuthorityManager::GetInstance().CheckServiceAuthority(AuthValue::AUTH_R, "storage")); - EXPECT_EQ(true, AuthorityManager::GetInstance().CheckServiceAuthority(AuthValue::AUTH_W, "storage")); -} - -/** - * @tc.name: CheckAuthority_004 - * @tc.desc: check authority of an empty serviceId - * @tc.type: FUNC - * @tc.require: I4OH94 - */ -HWTEST_F(ProfileAuthorityTest, CheckAuthority_004, TestSize.Level2) -{ - if (!LoadAuthorityByStr(VALID_AUTHORITY_STR)) { - return; - } - - EXPECT_EQ(false, AuthorityManager::GetInstance().CheckServiceAuthority(AuthValue::AUTH_R, - "")); - EXPECT_EQ(false, AuthorityManager::GetInstance().CheckServicesAuthority(AuthValue::AUTH_R, - {"system", ""})); -} - -/** - * @tc.name: CheckAuthority_005 - * @tc.desc: check authority of all with diff auth value - * @tc.type: FUNC - * @tc.require: I4OH94 - */ -HWTEST_F(ProfileAuthorityTest, CheckAuthority_005, TestSize.Level2) -{ - if (!LoadAuthorityByStr(VALID_AUTHORITY_STR)) { - return; - } - - EXPECT_EQ(true, AuthorityManager::GetInstance().CheckServicesAuthority(AuthValue::AUTH_R, {})); - EXPECT_EQ(false, AuthorityManager::GetInstance().CheckServicesAuthority(AuthValue::AUTH_W, {})); -} - -/** - * @tc.name: CheckAuthority_006 - * @tc.desc: check authority of serviceIds with same prefix - * @tc.type: FUNC - * @tc.require: I4OH94 - */ -HWTEST_F(ProfileAuthorityTest, CheckAuthority_006, TestSize.Level2) -{ - if (!LoadAuthorityByStr(VALID_AUTHORITY_STR)) { - return; - } - - EXPECT_EQ(true, AuthorityManager::GetInstance().CheckServiceAuthority(AuthValue::AUTH_R, - "cameraRear1")); - EXPECT_EQ(true, AuthorityManager::GetInstance().CheckServiceAuthority(AuthValue::AUTH_W, - "cameraRear1")); - - EXPECT_EQ(true, AuthorityManager::GetInstance().CheckServiceAuthority(AuthValue::AUTH_R, - "cameraRear2")); - EXPECT_EQ(true, AuthorityManager::GetInstance().CheckServiceAuthority(AuthValue::AUTH_W, - "cameraRear2")); -} - -/** - * @tc.name: CheckAuthority_007 - * @tc.desc: check authority of multiple serviceIds - * @tc.type: FUNC - * @tc.require: I4OH94 - */ -HWTEST_F(ProfileAuthorityTest, CheckAuthority_007, TestSize.Level2) -{ - if (!LoadAuthorityByStr(VALID_AUTHORITY_STR)) { - return; - } - - EXPECT_EQ(true, AuthorityManager::GetInstance().CheckServicesAuthority(AuthValue::AUTH_W, - {"cameraRear1", "cameraRear2", "cameraRear3"})); - EXPECT_EQ(true, AuthorityManager::GetInstance().CheckServicesAuthority(AuthValue::AUTH_W, - {"storage", "system"})); - EXPECT_EQ(true, AuthorityManager::GetInstance().CheckServicesAuthority(AuthValue::AUTH_W, - {"cameraRear1", "cameraRear2", "cameraRear3", "storage", "system"})); - - if (!LoadAuthorityByStr(INVALID_AUTHORITY_STR)) { - return; - } - EXPECT_EQ(false, AuthorityManager::GetInstance().CheckServicesAuthority(AuthValue::AUTH_W, - {"storage", "system"})); -} - -/** - * @tc.name: CheckAuthority_008 - * @tc.desc: check authority of interfaces - * @tc.type: FUNC - * @tc.require: I4OH94 - */ -HWTEST_F(ProfileAuthorityTest, CheckAuthority_008, TestSize.Level2) -{ - if (!LoadAuthorityByStr(VALID_AUTHORITY_STR)) { - return; - } - - EXPECT_EQ(true, AuthorityManager::GetInstance().CheckInterfaceAuthority("sync")); - EXPECT_EQ(false, AuthorityManager::GetInstance().CheckInterfaceAuthority("fakeInterface")); - EXPECT_EQ(false, AuthorityManager::GetInstance().CheckInterfaceAuthority("")); - - if (!LoadAuthorityByStr(INVALID_AUTHORITY_STR)) { - return; - } - EXPECT_EQ(false, AuthorityManager::GetInstance().CheckInterfaceAuthority("sync")); -} - -/** - * @tc.name: CheckAuthority_009 - * @tc.desc: check authority of interfaces - * @tc.type: FUNC - * @tc.require: I4OH94 - */ -HWTEST_F(ProfileAuthorityTest, CheckAuthority_009, TestSize.Level2) -{ - if (!LoadAuthorityCfg(AUTHORITY_JSON_PATH)) { - return; - } - - EXPECT_EQ(false, AuthorityManager::GetInstance().CheckServiceAuthority(AuthValue::AUTH_R, "syscap")); -} - -/** - * @tc.name: CheckAuthority_0010 - * @tc.desc: check authority of interfaces - * @tc.type: FUNC - * @tc.require: I4OH94 - */ -HWTEST_F(ProfileAuthorityTest, CheckAuthority_0010, TestSize.Level2) -{ - nlohmann::json jsonObject = nlohmann::json::parse(INVALID_INTERFACE_SERVICE, nullptr, false); - if (jsonObject.is_discarded()) { - return; - } - - EXPECT_EQ(false, AuthorityManager::GetInstance().ValidateProcess(jsonObject)); -} - -/** - * @tc.name: CheckAuthority_0011 - * @tc.desc: check authority of interfaces - * @tc.type: FUNC - * @tc.require: I4OH94 - */ -HWTEST_F(ProfileAuthorityTest, CheckAuthority_0011, TestSize.Level2) -{ - nlohmann::json jsonObject = nlohmann::json::parse(INVALID_INTERFACE_VALUE, nullptr, false); - if (jsonObject.is_discarded()) { - return; - } - - EXPECT_EQ(false, AuthorityManager::GetInstance().ValidateProcess(jsonObject)); - EXPECT_EQ(false, AuthorityManager::GetInstance().ValidateInterfaces(jsonObject)); - - jsonObject = nlohmann::json::parse(EMPTY_INTERFACE_VALUE, nullptr, false); - if (jsonObject.is_discarded()) { - return; - } - EXPECT_EQ(false, AuthorityManager::GetInstance().ValidateInterfaces(jsonObject)); -} - -/** - * @tc.name: CheckAuthority_0012 - * @tc.desc: check authority of interfaces - * @tc.type: FUNC - * @tc.require: I4OH94 - */ -HWTEST_F(ProfileAuthorityTest, CheckAuthority_0012, TestSize.Level2) -{ - nlohmann::json jsonObject = nlohmann::json::parse(TEST_TRUST_GROUP_EMPTY, nullptr, false); - if (jsonObject.is_discarded()) { - return; - } - EXPECT_EQ(false, AuthorityManager::GetInstance().ValidateServices(jsonObject)); - EXPECT_EQ(false, AuthorityManager::GetInstance().ValidateInterfaces(jsonObject)); - - jsonObject = nlohmann::json::parse(INVALID_SERVIES_SPE, nullptr, false); - if (jsonObject.is_discarded()) { - return; - } - EXPECT_EQ(false, AuthorityManager::GetInstance().ValidateServices(jsonObject)); - - jsonObject = nlohmann::json::parse(INVALID_SERVIES_PRE, nullptr, false); - if (jsonObject.is_discarded()) { - return; - } - EXPECT_EQ(false, AuthorityManager::GetInstance().ValidateServices(jsonObject)); -} - -/** - * @tc.name: Init_001 - * @tc.desc: precheck an authority json with invalid config - * @tc.type: FUNC - * @tc.require: I4OH94 - */ -HWTEST_F(ProfileAuthorityTest, Init_001, TestSize.Level2) -{ - EXPECT_EQ(true, AuthorityManager::GetInstance().Init()); -} - -/** - * @tc.name: CheckDeviceId_001 - * @tc.desc: check device id of interfaces - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileAuthorityTest, CheckDeviceId_001, TestSize.Level2) -{ - EXPECT_EQ(false, TrustGroupManager::GetInstance().CheckDeviceId("")); - EXPECT_EQ(true, TrustGroupManager::GetInstance().CheckDeviceId(TEST_DEVICEID)); -} - -/** - * @tc.name: InitHichainService_001 - * @tc.desc: init hichain service of interfaces - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileAuthorityTest, InitHichainService_001, TestSize.Level2) -{ - TrustGroupManager::GetInstance().OnDeviceUnBoundAdapter("", ""); - - std::string localDeviceId; - DpDeviceManager::GetInstance().GetLocalDeviceUdid(localDeviceId); - TrustGroupManager::GetInstance().OnDeviceUnBoundAdapter(localDeviceId.c_str(), ""); - EXPECT_EQ(true, TrustGroupManager::GetInstance().InitHichainService()); -} - -/** - * @tc.name: CheckTrustGroup_001 - * @tc.desc: check trust group of interfaces - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileAuthorityTest, CheckTrustGroup_001, TestSize.Level2) -{ - GroupInfo groupInfo; - nlohmann::json jsonObject = nlohmann::json::parse(TEST_TRUST_GROUP, nullptr, false); - if (jsonObject.is_discarded()) { - return; - } - from_json(jsonObject, groupInfo); - EXPECT_EQ(false, TrustGroupManager::GetInstance().CheckTrustGroup("")); -} - -/** - * @tc.name: CheckTrustGroup_002 - * @tc.desc: check trust group of interfaces - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileAuthorityTest, CheckTrustGroup_002, TestSize.Level2) -{ - GroupInfo groupInfo; - nlohmann::json jsonObject = nlohmann::json::parse(TEST_TRUST_GROUP_EMPTY, nullptr, false); - if (jsonObject.is_discarded()) { - return; - } - from_json(jsonObject, groupInfo); - EXPECT_EQ(false, TrustGroupManager::GetInstance().CheckTrustGroup("")); -} - -/** - * @tc.name: InitHichainService_002 - * @tc.desc: init hichain service of interfaces - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileAuthorityTest, InitHichainService_002, TestSize.Level2) -{ - std::string localDeviceId; - std::shared_ptr initCallback_ = - std::make_shared(); - DeviceManager::GetInstance().InitDeviceManager(PKG_NAME, initCallback_); - DpDeviceManager::GetInstance().GetLocalDeviceUdid(localDeviceId); - TrustGroupManager::GetInstance().OnDeviceUnBoundAdapter(localDeviceId.c_str(), ""); - EXPECT_EQ(true, TrustGroupManager::GetInstance().InitHichainService()); -} - -/** - * @tc.name: CheckCallerTrust_001 - * @tc.desc: init hichain service of interfaces - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileAuthorityTest, CheckCallerTrust_001, TestSize.Level2) -{ - TestUtil::MockInvalidTokenID(); - bool res = AuthorityManager::GetInstance().CheckCallerTrust(); - EXPECT_EQ(false, res); -} - -/** - * @tc.name: CheckCallerTrust_002 - * @tc.desc: init hichain service of interfaces - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileAuthorityTest, CheckCallerTrust_002, TestSize.Level2) -{ - TestUtil::MockPermission("distributedsched"); - bool res = AuthorityManager::GetInstance().CheckCallerTrust(); - EXPECT_EQ(true, res); -} - -/** - * @tc.name: CheckInterfaceAuthority_001 - * @tc.desc: init hichain service of interfaces - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileAuthorityTest, CheckInterfaceAuthority_001, TestSize.Level2) -{ - AuthorityManager::GetInstance().authJson_.clear(); - bool res = AuthorityManager::GetInstance().CheckInterfaceAuthority(""); - EXPECT_EQ(false, res); -} - -/** - * @tc.name: CheckTrustGroup_003 - * @tc.desc: check trust group of interfaces - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileAuthorityTest, CheckTrustGroup_003, TestSize.Level3) -{ - EXPECT_EQ(false, TrustGroupManager::GetInstance().CheckGroupsInfo(TEST_TRUST_GROUPS.c_str(), 0)); - EXPECT_EQ(false, TrustGroupManager::GetInstance().CheckGroupsInfo(TEST_TRUST_GROUPS.c_str(), 1)); -} - -/** - * @tc.name: CheckTrustGroup_004 - * @tc.desc: check trust group of interfaces - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileAuthorityTest, CheckTrustGroup_004, TestSize.Level3) -{ - EXPECT_EQ(false, TrustGroupManager::GetInstance().CheckGroupsInfo(TEST_TRUST_GROUPS_EMPTY.c_str(), 1)); -} - -/** - * @tc.name: CheckTrustGroup_005 - * @tc.desc: check trust group of interfaces - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileAuthorityTest, CheckTrustGroup_005, TestSize.Level3) -{ - EXPECT_EQ(false, TrustGroupManager::GetInstance().CheckGroupsInfo(TEST_TRUST_GROUPS_VISIABLE.c_str(), 1)); - EXPECT_EQ(true, TrustGroupManager::GetInstance().CheckGroupsInfo(TEST_TRUST_GROUPS_SAMEACCOUNT.c_str(), 1)); - EXPECT_EQ(false, TrustGroupManager::GetInstance().CheckGroupsInfo(AUTHORITY_JSON_PATH.c_str(), 1)); -} -} -} diff --git a/old/services/core/test/unittest/profile_change_handler_test.cpp b/old/services/core/test/unittest/profile_change_handler_test.cpp deleted file mode 100644 index 93cf6467..00000000 --- a/old/services/core/test/unittest/profile_change_handler_test.cpp +++ /dev/null @@ -1,441 +0,0 @@ -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * 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. - */ - -#include - -#include "device_profile_errors.h" -#include "distributed_device_profile_client.h" -#include "profile_change_notification.h" -#include "subscribe_info.h" -#include "utils.h" - -#define private public -#define protected public -#include "dp_device_manager.h" -#include "profile_change_handler.h" -#include "profile_event_handler.h" -#include "profile_sync_handler.h" -#include "sync_coordinator.h" - -namespace OHOS { -namespace DeviceProfile { -using namespace testing; -using namespace testing::ext; - -class ProfileChangeHandlerTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp(); - void TearDown(); - std::shared_ptr profileChangeHandler_; -}; - -class StorageProfileEventCallback : public IProfileEventCallback { -}; - -void ProfileChangeHandlerTest::SetUpTestCase() -{ - DTEST_LOG << "SetUpTestCase" << std::endl; - DistributedDeviceProfileClient::GetInstance().DeleteDeviceProfile("111111"); -} - -void ProfileChangeHandlerTest::TearDownTestCase() -{ - DTEST_LOG << "TearDownTestCase" << std::endl; -} - -void ProfileChangeHandlerTest::SetUp() -{ - DTEST_LOG << "SetUp" << std::endl; - if (profileChangeHandler_ == nullptr) { - profileChangeHandler_ = std::make_shared("profileChangeTest"); - } -} - -void ProfileChangeHandlerTest::TearDown() -{ - DTEST_LOG << "TearDown" << std::endl; -} - - -/** - * @tc.name: ConvertEntry_001 - * @tc.desc: ConvertEntry - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(ProfileChangeHandlerTest, ConvertEntry_001, TestSize.Level3) -{ - DistributedKv::Entry entry1; - entry1.key = "key"; - entry1.value = "value"; - std::vector inserts; - inserts.emplace_back(entry1); - ProfileChangeType changeType {ProfileChangeType::UNKNOWN_CHANGE_TYPE}; - std::vector filteredEntries; - Service2Index service2Index; - profileChangeHandler_->ConvertEntry(inserts, changeType, filteredEntries, service2Index); - EXPECT_TRUE(filteredEntries.empty()); -} - -/** - * @tc.name: ConvertEntry_002 - * @tc.desc: ConvertEntry - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(ProfileChangeHandlerTest, ConvertEntry_002, TestSize.Level3) -{ - DistributedKv::Entry entry1; - entry1.key = "key/key/key"; - entry1.value = "value"; - std::vector inserts; - inserts.emplace_back(entry1); - ProfileChangeType changeType {ProfileChangeType::UNKNOWN_CHANGE_TYPE}; - std::vector filteredEntries; - Service2Index service2Index; - profileChangeHandler_->ConvertEntry(inserts, changeType, filteredEntries, service2Index); - EXPECT_TRUE(filteredEntries.empty()); -} - -/** - * @tc.name: ConvertEntry_003 - * @tc.desc: ConvertEntry - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(ProfileChangeHandlerTest, ConvertEntry_003, TestSize.Level3) -{ - DistributedKv::Entry entry1; - entry1.key = "1234567812345678123456781234567812345678123456781234567812345678/key/key"; - entry1.value = "value"; - std::vector inserts; - inserts.emplace_back(entry1); - ProfileChangeType changeType {ProfileChangeType::UNKNOWN_CHANGE_TYPE}; - std::vector filteredEntries; - Service2Index service2Index; - profileChangeHandler_->ConvertEntry(inserts, changeType, filteredEntries, service2Index); - EXPECT_TRUE(filteredEntries.empty()); -} - -/** - * @tc.name: ConvertEntry_004 - * @tc.desc: ConvertEntry - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(ProfileChangeHandlerTest, ConvertEntry_004, TestSize.Level3) -{ - DistributedKv::Entry entry1; - entry1.key = "1234567812345678123456781234567812345678123456781234567812345678/1/key"; - entry1.value = "value"; - std::vector inserts; - inserts.emplace_back(entry1); - ProfileChangeType changeType {ProfileChangeType::UNKNOWN_CHANGE_TYPE}; - std::vector filteredEntries; - Service2Index service2Index; - profileChangeHandler_->ConvertEntry(inserts, changeType, filteredEntries, service2Index); - EXPECT_TRUE(filteredEntries.empty()); -} - -/** - * @tc.name: ConvertEntry_005 - * @tc.desc: ConvertEntry - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(ProfileChangeHandlerTest, ConvertEntry_005, TestSize.Level3) -{ - DistributedKv::Entry entry1; - entry1.key = "1234567812345678123456781234567812345678123456781234567812345678/0/1"; - entry1.value = "value"; - std::vector inserts; - inserts.emplace_back(entry1); - ProfileChangeType changeType {ProfileChangeType::UNKNOWN_CHANGE_TYPE}; - std::vector filteredEntries; - Service2Index service2Index; - profileChangeHandler_->ConvertEntry(inserts, changeType, filteredEntries, service2Index); - EXPECT_FALSE(filteredEntries.empty()); - EXPECT_FALSE(service2Index.empty()); -} - -/** - * @tc.name: Subscribe_001 - * @tc.desc: Subscribe - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(ProfileChangeHandlerTest, Subscribe_001, TestSize.Level3) -{ - SubscribeInfo subInfo; - subInfo.extraInfo = {{"serviceIds", "1111"}}; - auto syncCb = std::make_shared(); - sptr notifier = - sptr(new ProfileEventNotifierStub(syncCb)); - int32_t ret = profileChangeHandler_->Subscribe(subInfo, notifier); - ASSERT_EQ(ret, ERR_DP_PERMISSION_DENIED); -} - -/** - * @tc.name: FilterChangedProfileLocked_001 - * @tc.desc: FilterChangedProfileLocked - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(ProfileChangeHandlerTest, FilterChangedProfileLocked_001, TestSize.Level3) -{ - SubscribeInfo subInfo; - subInfo.extraInfo = { - {"deviceId", ""}, - {"serviceIds", {}} - }; - ProfileChangeNotification profileNotification; - FilterInfo filterInfo; - Service2Index service2Index; - profileChangeHandler_->FilterChangedProfileLocked(subInfo, profileNotification, - service2Index, filterInfo); - ASSERT_FALSE(filterInfo.filtered); -} - -/** - * @tc.name: FilterChangedProfileLocked_002 - * @tc.desc: FilterChangedProfileLocked - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(ProfileChangeHandlerTest, FilterChangedProfileLocked_002, TestSize.Level3) -{ - SubscribeInfo subInfo; - subInfo.extraInfo = { - {"deviceId", "111"} - }; - ProfileChangeNotification profileNotification; - FilterInfo filterInfo; - Service2Index service2Index; - profileChangeHandler_->FilterChangedProfileLocked(subInfo, profileNotification, - service2Index, filterInfo); - ASSERT_TRUE(filterInfo.filtered); -} - -/** - * @tc.name: FilterChangedProfileLocked_003 - * @tc.desc: FilterChangedProfileLocked - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(ProfileChangeHandlerTest, FilterChangedProfileLocked_003, TestSize.Level3) -{ - SubscribeInfo subInfo; - subInfo.extraInfo = { - {"deviceId", ""}, - {"serviceIds", ""} - }; - ProfileChangeNotification profileNotification; - FilterInfo filterInfo; - Service2Index service2Index; - profileChangeHandler_->FilterChangedProfileLocked(subInfo, profileNotification, - service2Index, filterInfo); - ASSERT_TRUE(filterInfo.filtered); -} - -/** - * @tc.name: FilterChangedProfileLocked_004 - * @tc.desc: FilterChangedProfileLocked - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(ProfileChangeHandlerTest, FilterChangedProfileLocked_004, TestSize.Level3) -{ - SubscribeInfo subInfo; - subInfo.extraInfo = { - {"deviceId", ""}, - {"serviceIds", "1111"} - }; - ProfileChangeNotification profileNotification; - FilterInfo filterInfo; - Service2Index service2Index; - profileChangeHandler_->FilterChangedProfileLocked(subInfo, profileNotification, - service2Index, filterInfo); - ASSERT_TRUE(filterInfo.filtered); -} - -/** - * @tc.name: FilterChangedProfileLocked_005 - * @tc.desc: FilterChangedProfileLocked - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(ProfileChangeHandlerTest, FilterChangedProfileLocked_005, TestSize.Level3) -{ - SubscribeInfo subInfo; - subInfo.extraInfo = { - {"deviceId", ""}, - {"serviceIds", "1111"} - }; - ProfileChangeNotification profileNotification; - FilterInfo filterInfo; - Service2Index service2Index = {{"1111", 1}}; - profileChangeHandler_->FilterChangedProfileLocked(subInfo, profileNotification, - service2Index, filterInfo); - ASSERT_TRUE(filterInfo.filtered); - ASSERT_FALSE(filterInfo.indexes.empty()); -} - -/** - * @tc.name: NotifyProfileChangedLocked_001 - * @tc.desc: NotifyProfileChangedLocked - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(ProfileChangeHandlerTest, NotifyProfileChangedLocked_001, TestSize.Level3) -{ - ProfileChangeNotification profileNotification; - FilterInfo filterInfo; - auto syncCb = std::make_shared(); - sptr notifier = - sptr(new ProfileEventNotifierStub(syncCb)); - profileChangeHandler_->NotifyProfileChangedLocked(profileNotification, filterInfo, notifier); - ASSERT_FALSE(filterInfo.filtered); -} - -/** - * @tc.name: NotifyProfileChangedLocked_002 - * @tc.desc: NotifyProfileChangedLocked - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(ProfileChangeHandlerTest, NotifyProfileChangedLocked_002, TestSize.Level3) -{ - ProfileChangeNotification profileNotification; - FilterInfo filterInfo; - filterInfo.filtered = true; - auto syncCb = std::make_shared(); - sptr notifier = - sptr(new ProfileEventNotifierStub(syncCb)); - profileChangeHandler_->NotifyProfileChangedLocked(profileNotification, filterInfo, notifier); - ASSERT_TRUE(filterInfo.indexes.empty()); -} - -/** - * @tc.name: NotifyProfileChangedLocked_003 - * @tc.desc: NotifyProfileChangedLocked - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(ProfileChangeHandlerTest, NotifyProfileChangedLocked_003, TestSize.Level3) -{ - ProfileEntry entry; - std::vector entries(1, entry); - std::string networkId = "1"; - ProfileChangeNotification profileNotification(entries, networkId, true); - FilterInfo filterInfo; - filterInfo.filtered = true; - filterInfo.indexes.emplace(0); - auto syncCb = std::make_shared(); - sptr notifier = - sptr(new ProfileEventNotifierStub(syncCb)); - profileChangeHandler_->NotifyProfileChangedLocked(profileNotification, filterInfo, notifier); - ASSERT_FALSE(filterInfo.indexes.empty()); -} - -/** - * @tc.name: NotifyProfileChanged_001 - * @tc.desc: NotifyProfileChanged - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(ProfileChangeHandlerTest, NotifyProfileChanged_001, TestSize.Level3) -{ - auto syncCb = std::make_shared(); - sptr notifier = - sptr(new ProfileEventNotifierStub(syncCb)); - - SubscribeInfo subInfo; - subInfo.extraInfo = { - {"deviceId", ""}, - {"serviceIds", "1111"} - }; - - profileChangeHandler_->profileEventSubscribeInfos_[notifier] = subInfo; - Service2Index service2Index; - ProfileChangeNotification profileNotification; - profileChangeHandler_->NotifyProfileChanged(profileNotification, service2Index); - ASSERT_TRUE(service2Index.empty()); -} - -/** - * @tc.name: OnChange_001 - * @tc.desc: OnChange - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(ProfileChangeHandlerTest, OnChange_001, TestSize.Level3) -{ - std::shared_ptr profileSyncHandler_ = - std::make_shared("profileSyncTest"); - std::vector deviceIds = {"", std::move("testudid123"), ""}; - std::map results; - SyncCoordinator::GetInstance().Init(); - SyncCoordinator::GetInstance().isOnlineTrigger_ = false; - profileSyncHandler_->SyncCompleted(results); - SyncCoordinator::GetInstance().isOnlineTrigger_ = true; - profileSyncHandler_->SyncCompleted(results); - results["success123"] = Status::SUCCESS; - results["test1"] = Status::ERROR; - profileSyncHandler_->SyncCompleted(results); - results.clear(); - results["success123"] = Status::SUCCESS; - results["test1"] = Status::ERROR; - results["test2"] = Status::ERROR; - results["test3"] = Status::ERROR; - results["test4"] = Status::ERROR; - std::vector deviceIds1; - deviceIds1.emplace_back("test1"); - deviceIds1.emplace_back("test2"); - deviceIds1.emplace_back("test3"); - deviceIds1.emplace_back("test4"); - DpDeviceManager::GetInstance().deviceIdsList_.emplace_back(deviceIds1); - profileSyncHandler_->SyncCompleted(results); - DistributedKv::ChangeNotification profileNotification({}, {}, {}, "", true); - profileChangeHandler_->OnChange(profileNotification); - ASSERT_TRUE(profileChangeHandler_->profileEventSubscribeInfos_.empty()); -} - -/** - * @tc.name: OnChange_002 - * @tc.desc: OnChange - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(ProfileChangeHandlerTest, OnChange_002, TestSize.Level3) -{ - std::vector insertEntries; - std::vector updateEntries; - std::vector deleteEntries; - DistributedKv::Entry entry; - entry.key = "key"; - entry.value = "value"; - insertEntries.emplace_back(entry); - updateEntries.emplace_back(entry); - deleteEntries.emplace_back(entry); - std::string deviceId = "device"; - DistributedKv::ChangeNotification profileNotification(std::move(insertEntries), std::move(updateEntries), - std::move(deleteEntries), deviceId, false); - profileChangeHandler_->OnChange(profileNotification); - ASSERT_TRUE(profileChangeHandler_->profileEventSubscribeInfos_.empty()); -} -} -} \ No newline at end of file diff --git a/old/services/core/test/unittest/profile_change_notification_test.cpp b/old/services/core/test/unittest/profile_change_notification_test.cpp deleted file mode 100644 index 17034f22..00000000 --- a/old/services/core/test/unittest/profile_change_notification_test.cpp +++ /dev/null @@ -1,383 +0,0 @@ -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * 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. - */ - -#include -#include - -#include "device_profile_errors.h" -#include "distributed_device_profile_client.h" -#include "iprofile_event_callback.h" -#include "iprofile_event_notifier.h" -#include "profile_change_notification.h" -#include "profile_event.h" -#include "profile_event_notifier_proxy.h" -#include "profile_event_notifier_stub.h" - -#include "utils.h" - -namespace OHOS { -namespace DeviceProfile { -using namespace testing; -using namespace testing::ext; - -namespace { -constexpr int32_t MAX_ENTRY_LEN = 1000001; -} - -class ProfileChangeNotificationTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp(); - void TearDown(); -}; - -class StorageProfileEventCallback : public IProfileEventCallback { -}; - -void ProfileChangeNotificationTest::SetUpTestCase() -{ - DTEST_LOG << "SetUpTestCase" << std::endl; - DistributedDeviceProfileClient::GetInstance().DeleteDeviceProfile("111111"); -} - -void ProfileChangeNotificationTest::TearDownTestCase() -{ - DTEST_LOG << "TearDownTestCase" << std::endl; -} - -void ProfileChangeNotificationTest::SetUp() -{ - DTEST_LOG << "SetUp" << std::endl; -} - -void ProfileChangeNotificationTest::TearDown() -{ - DTEST_LOG << "TearDown" << std::endl; -} - -/** - * @tc.name: GetProfileEntries_001 - * @tc.desc: get profile entries - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(ProfileChangeNotificationTest, GetProfileEntries_001, TestSize.Level3) -{ - ProfileChangeNotification notification; - auto result = notification.GetProfileEntries(); - EXPECT_EQ(true, result.empty()); -} - -/** - * @tc.name: GetProfileEntries_002 - * @tc.desc: get profile entries - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(ProfileChangeNotificationTest, GetProfileEntries_002, TestSize.Level3) -{ - std::vector profileEntries; - std::string networkId; - bool isLocal = true; - ProfileChangeNotification notification(profileEntries, networkId, isLocal); - auto result = notification.GetProfileEntries(); - EXPECT_EQ(true, result.empty()); -} - -/** - * @tc.name: GetDeviceId_001 - * @tc.desc: get device id - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(ProfileChangeNotificationTest, GetDeviceId_001, TestSize.Level3) -{ - std::vector profileEntries; - std::string networkId; - bool isLocal = true; - std::shared_ptr temp = - std::make_shared(profileEntries, networkId, isLocal); - std::string result = temp->GetDeviceId(); - EXPECT_EQ("", result); -} - -/** - * @tc.name: IsLocal_001 - * @tc.desc: judge is local - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(ProfileChangeNotificationTest, IsLocal_001, TestSize.Level3) -{ - std::shared_ptr temp = std::make_shared(); - bool result = temp->IsLocal(); - EXPECT_EQ(false, result); -} - -/** - * @tc.name: Marshalling_001 - * @tc.desc: marshalling of profile change notification - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(ProfileChangeNotificationTest, Marshalling_001, TestSize.Level3) -{ - Parcel parcel; - std::shared_ptr temp = std::make_shared(); - bool result = temp->Marshalling(parcel); - EXPECT_EQ(true, result); -} - -/** - * @tc.name: Marshalling_001 - * @tc.desc: marshalling of profile change notification - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(ProfileChangeNotificationTest, Marshalling_002, TestSize.Level3) -{ - ProfileEntry entry; - std::vector profileEntries(1, entry); - std::string networkId = "112223"; - bool isLocal = true; - ProfileChangeNotification notification(profileEntries, networkId, isLocal); - Parcel parcel; - bool ret = notification.Marshalling(parcel); - EXPECT_TRUE(ret); -} - -/** - * @tc.name: Unmarshalling_001 - * @tc.desc: unmarshalling of profile change notification - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(ProfileChangeNotificationTest, Unmarshalling_001, TestSize.Level3) -{ - Parcel parcel; - std::shared_ptr temp = std::make_shared(); - bool result = temp->Unmarshalling(parcel); - EXPECT_EQ(false, result); -} - -/** - * @tc.name: Unmarshalling_002 - * @tc.desc: unmarshalling of profile change notification - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(ProfileChangeNotificationTest, Unmarshalling_002, TestSize.Level3) -{ - Parcel parcel; - parcel.WriteInt32(-1); - std::shared_ptr temp = std::make_shared(); - bool result = temp->Unmarshalling(parcel); - EXPECT_FALSE(result); -} - -/** - * @tc.name: Unmarshalling_002 - * @tc.desc: unmarshalling of profile change notification - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(ProfileChangeNotificationTest, Unmarshalling_003, TestSize.Level3) -{ - Parcel parcel; - parcel.WriteInt32(MAX_ENTRY_LEN); - std::shared_ptr temp = std::make_shared(); - bool result = temp->Unmarshalling(parcel); - EXPECT_FALSE(result); -} - -/** - * @tc.name: Unmarshalling_002 - * @tc.desc: unmarshalling of profile change notification - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(ProfileChangeNotificationTest, Unmarshalling_004, TestSize.Level3) -{ - Parcel parcel; - parcel.WriteInt32(1); - parcel.WriteString("111"); - parcel.WriteString("222"); - uint8_t type = 1; - parcel.WriteUint8(type); - parcel.WriteString("222"); - std::shared_ptr temp = std::make_shared(); - bool result = temp->Unmarshalling(parcel); - EXPECT_TRUE(result); -} - -/** - * @tc.name: Unmarshalling_002 - * @tc.desc: unmarshalling of profile change notification - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(ProfileChangeNotificationTest, Unmarshalling_005, TestSize.Level3) -{ - Parcel parcel; - parcel.WriteInt32(1); - std::shared_ptr temp = std::make_shared(); - bool result = temp->Unmarshalling(parcel); - EXPECT_FALSE(result); -} - -/** - * @tc.name: OnRemoteRequest_001 - * @tc.desc: OnRemoteRequest of profile event notification - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(ProfileChangeNotificationTest, OnRemoteRequest_001, TestSize.Level3) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option { MessageOption::TF_ASYNC }; - SyncResult syncResults; - syncResults.emplace("testdeviceid", SUCCEEDED); - if (!data.WriteInterfaceToken(ProfileEventNotifierProxy::GetDescriptor())) { - return; - } - if (!data.WriteInt32(static_cast(syncResults.size()))) { - return; - } - - for (const auto& [deviceId, syncResult] : syncResults) { - if (!data.WriteString(deviceId) || - !data.WriteInt32(static_cast(syncResult))) { - return; - } - } - - auto syncCb = std::make_shared(); - std::shared_ptr temp = std::make_shared(syncCb); - int32_t result = temp->OnRemoteRequest(EVENT_SYNC_COMPLETED, data, reply, option); - DTEST_LOG << "result: " << result << std::endl; - EXPECT_EQ(0, result); -} -/** - * @tc.name: OnRemoteRequest_002 - * @tc.desc: OnRemoteRequest of profile event notification - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(ProfileChangeNotificationTest, OnRemoteRequest_002, TestSize.Level3) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option { MessageOption::TF_ASYNC }; - if (!data.WriteInterfaceToken(ProfileEventNotifierProxy::GetDescriptor())) { - return; - } - - auto syncCb = std::make_shared(); - std::shared_ptr temp = std::make_shared(syncCb); - int32_t result = temp->OnRemoteRequest(EVENT_PROFILE_CHANGED, data, reply, option); - DTEST_LOG << "result: " << result << std::endl; - EXPECT_EQ(ERR_DP_INVALID_PARAMS, result); -} - -/** - * @tc.name: OnRemoteRequest_003 - * @tc.desc: OnRemoteRequest of profile event notification - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(ProfileChangeNotificationTest, OnRemoteRequest_003, TestSize.Level3) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option { MessageOption::TF_ASYNC }; - SyncResult syncResults; - if (!data.WriteInterfaceToken(ProfileEventNotifierProxy::GetDescriptor())) { - return; - } - if (!data.WriteInt32(static_cast(syncResults.size()))) { - return; - } - - auto syncCb = std::make_shared(); - std::shared_ptr temp = std::make_shared(syncCb); - int32_t result = temp->OnRemoteRequest(EVENT_SYNC_COMPLETED, data, reply, option); - DTEST_LOG << "result: " << result << std::endl; - EXPECT_EQ(ERR_DP_INVALID_PARAMS, result); -} - - -HWTEST_F(ProfileChangeNotificationTest, OnRemoteRequest_004, TestSize.Level3) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option { MessageOption::TF_ASYNC }; - SyncResult syncResults; - if (!data.WriteInterfaceToken(ProfileEventNotifierProxy::GetDescriptor())) { - return; - } - if (!data.WriteInt32(static_cast(syncResults.size()))) { - return; - } - - uint32_t code = ProfileEvent::EVENT_SYNC_COMPLETED; - auto syncCb = std::make_shared(); - std::shared_ptr temp = std::make_shared(syncCb); - int32_t result = temp->OnRemoteRequest(code, data, reply, option); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, result); -} - -HWTEST_F(ProfileChangeNotificationTest, OnRemoteRequest_005, TestSize.Level3) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option { MessageOption::TF_ASYNC }; - SyncResult syncResults; - if (!data.WriteInterfaceToken(ProfileEventNotifierProxy::GetDescriptor())) { - return; - } - if (!data.WriteInt32(static_cast(syncResults.size()))) { - return; - } - - uint32_t code = ProfileEvent::EVENT_PROFILE_CHANGED; - auto syncCb = std::make_shared(); - std::shared_ptr temp = std::make_shared(syncCb); - int32_t result = temp->OnRemoteRequest(code, data, reply, option); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, result); -} - -HWTEST_F(ProfileChangeNotificationTest, OnRemoteRequest_006, TestSize.Level3) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option { MessageOption::TF_ASYNC }; - SyncResult syncResults; - if (!data.WriteInterfaceToken(ProfileEventNotifierProxy::GetDescriptor())) { - return; - } - if (!data.WriteInt32(static_cast(syncResults.size()))) { - return; - } - - uint32_t code = 1000; - auto syncCb = std::make_shared(); - std::shared_ptr temp = std::make_shared(syncCb); - int32_t result = temp->OnRemoteRequest(code, data, reply, option); - EXPECT_EQ(305, result); -} -} -} \ No newline at end of file diff --git a/old/services/core/test/unittest/profile_crud_test.cpp b/old/services/core/test/unittest/profile_crud_test.cpp deleted file mode 100644 index 1a5f9649..00000000 --- a/old/services/core/test/unittest/profile_crud_test.cpp +++ /dev/null @@ -1,1067 +0,0 @@ -/* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. - * 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. - */ - -#include "gtest/gtest.h" - -#include "utils.h" -#include "test_util.h" - -#define private public -#define protected public -#include "device_profile_errors.h" -#include "device_profile_log.h" -#include "distributed_device_profile_client.h" -#include "hisysevent.h" -#include "nlohmann/json.hpp" -#include "syscap_info_collector.h" -#include "syscap_interface.h" -#undef private -#undef protected - -namespace OHOS { -namespace DeviceProfile { -using namespace OHOS::HiviewDFX; -namespace { - const std::string TAG = "SyscapInfoCollector"; - const std::string SERVICE_ID = "syscap"; - const std::string SERVICE_TYPE = "syscap"; - const std::string CHARACTER_PRIVATE_SYSCAP = "privatesyscap"; - const std::string CHARACTER_OS_SYSCAP = "ossyscap"; - const std::string DP_SYNC_FAILED = "DP_SYNC_FAILED"; - const std::string FAULT_CODE_KEY = "FAULT_CODE"; - const std::string DOMAIN_NAME = std::string(HiSysEvent::Domain::DEVICE_PROFILE); -} -using namespace testing; -using namespace testing::ext; - -class ProfileCrudTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp(); - void TearDown(); -}; - -void ProfileCrudTest::SetUpTestCase() -{ - DTEST_LOG << "SetUpTestCase" << std::endl; -} - -void ProfileCrudTest::TearDownTestCase() -{ - DTEST_LOG << "TearDownTestCase" << std::endl; -} - -void ProfileCrudTest::SetUp() -{ - DTEST_LOG << "SetUp" << std::endl; -} - -void ProfileCrudTest::TearDown() -{ - DTEST_LOG << "TearDown" << std::endl; -} - -class ProfileEventCallback : public IProfileEventCallback { -public: - ProfileEventCallback() = default; - ~ProfileEventCallback() = default; - - void OnSyncCompleted(const SyncResult& syncResults) override - { - } - - void OnProfileChanged(const ProfileChangeNotification& changeNotification) override - { - if (!subServiceIds_.empty()) { - const auto& profileEntries = changeNotification.GetProfileEntries(); - for (const auto& ProfileEntry : profileEntries) { - auto key = ProfileEntry.key; - DTEST_LOG << "key: " << key << std::endl; - numNotifications_++; - } - } - } - - void SetSubServiceIds(const std::list& subServiceIds) - { - subServiceIds_ = subServiceIds; - } - - int32_t GetNotificationNum() const - { - return numNotifications_; - } - -private: - std::list subServiceIds_; - int32_t numNotifications_ {0}; -}; - -/** - * @tc.name: PutDeviceProfile_001 - * @tc.desc: put device profile with empty service id - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileCrudTest, PutDeviceProfile_001, TestSize.Level3) -{ - auto dps = DistributedDeviceProfileClient::GetInstance().GetDeviceProfileService(); - if (dps == nullptr) { - DTEST_LOG << "device profile service is nullptr" << std::endl; - return; - } - - ServiceCharacteristicProfile profile; - profile.SetServiceId(""); - profile.SetServiceType("test"); - nlohmann::json j; - j["testVersion"] = "3.0.0"; - j["testApiLevel"] = 7; - profile.SetCharacteristicProfileJson(j.dump()); - int32_t result = DistributedDeviceProfileClient::GetInstance().PutDeviceProfile(profile); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, result); -} - -/** - * @tc.name: PutDeviceProfile_002 - * @tc.desc: put device profile with empty service type - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileCrudTest, PutDeviceProfile_002, TestSize.Level3) -{ - auto dps = DistributedDeviceProfileClient::GetInstance().GetDeviceProfileService(); - if (dps == nullptr) { - DTEST_LOG << "device profile service is nullptr" << std::endl; - return; - } - - ServiceCharacteristicProfile profile; - profile.SetServiceId("test"); - profile.SetServiceType(""); - nlohmann::json j; - j["testVersion"] = "3.0.0"; - j["testApiLevel"] = 7; - profile.SetCharacteristicProfileJson(j.dump()); - int32_t result = DistributedDeviceProfileClient::GetInstance().PutDeviceProfile(profile); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, result); -} - -/** - * @tc.name: PutDeviceProfile_003 - * @tc.desc: put device profile with empty characteristics - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileCrudTest, PutDeviceProfile_003, TestSize.Level3) -{ - auto dps = DistributedDeviceProfileClient::GetInstance().GetDeviceProfileService(); - if (dps == nullptr) { - DTEST_LOG << "device profile service is nullptr" << std::endl; - return; - } - - ServiceCharacteristicProfile profile; - profile.SetServiceId("test"); - profile.SetServiceType("test"); - nlohmann::json j; - // the result string is "null" - profile.SetCharacteristicProfileJson(j.dump()); - int32_t result = DistributedDeviceProfileClient::GetInstance().PutDeviceProfile(profile); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, result); -} - -/** - * @tc.name: PutDeviceProfile_004 - * @tc.desc: put device profile without set characteristics - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileCrudTest, PutDeviceProfile_004, TestSize.Level3) -{ - auto dps = DistributedDeviceProfileClient::GetInstance().GetDeviceProfileService(); - if (dps == nullptr) { - DTEST_LOG << "device profile service is nullptr" << std::endl; - return; - } - - ServiceCharacteristicProfile profile; - profile.SetServiceId("test"); - profile.SetServiceType("test"); - int32_t result = DistributedDeviceProfileClient::GetInstance().PutDeviceProfile(profile); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, result); -} - -/** - * @tc.name: PutDeviceProfile_005 - * @tc.desc: put device profile without set characteristics - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileCrudTest, PutDeviceProfile_005, TestSize.Level3) -{ - auto dps = DistributedDeviceProfileClient::GetInstance().GetDeviceProfileService(); - if (dps == nullptr) { - DTEST_LOG << "device profile service is nullptr" << std::endl; - return; - } - TestUtil::MockPermission("multimodalinput"); - ServiceCharacteristicProfile profile; - profile.SetServiceId("InputDeviceCooperation"); - profile.SetServiceType("InputDeviceCooperation"); - nlohmann::json j; - j["testVersion"] = "3.0.0"; - j["testApiLevel"] = 7; - profile.SetCharacteristicProfileJson(j.dump()); - DistributedDeviceProfileClient::GetInstance().PutDeviceProfile(profile); - ServiceCharacteristicProfile profileNew; - profileNew.SetServiceId("test"); - profileNew.SetServiceType("test"); - nlohmann::json jNew; - jNew["testVersion"] = "3.0.0"; - jNew["testApiLevel"] = 7; - profileNew.SetCharacteristicProfileJson(jNew.dump()); - int32_t result = DistributedDeviceProfileClient::GetInstance().PutDeviceProfile(profileNew); - EXPECT_EQ(ERR_DP_PERMISSION_DENIED, result); -} - -/** - * @tc.name: DeleteDeviceProfile_001 - * @tc.desc: delete an empty profile - * @tc.type: FUNC - * @tc.require: I4NY21 - */ -HWTEST_F(ProfileCrudTest, DeleteDeviceProfile_001, TestSize.Level3) -{ - auto dps = DistributedDeviceProfileClient::GetInstance().GetDeviceProfileService(); - if (dps == nullptr) { - DTEST_LOG << "device profile service is nullptr" << std::endl; - return; - } - - int32_t result = DistributedDeviceProfileClient::GetInstance().DeleteDeviceProfile(""); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, result); -} - -/** - * @tc.name: DeleteDeviceProfile_002 - * @tc.desc: delete an empty profile - * @tc.type: FUNC - * @tc.require: I4NY21 - */ -HWTEST_F(ProfileCrudTest, DeleteDeviceProfile_002, TestSize.Level3) -{ - auto dps = DistributedDeviceProfileClient::GetInstance().GetDeviceProfileService(); - if (dps == nullptr) { - DTEST_LOG << "device profile service is nullptr" << std::endl; - return; - } - TestUtil::MockPermission("multimodalinput"); - DistributedDeviceProfileClient::GetInstance().DeleteDeviceProfile("InputDeviceCooperation"); - int32_t result = DistributedDeviceProfileClient::GetInstance().DeleteDeviceProfile("test"); - EXPECT_EQ(ERR_DP_PERMISSION_DENIED, result); -} - -/** - * @tc.name: SubscribeProfileEvent_001 - * @tc.desc: subscribe device profile - * @tc.type: FUNC - * @tc.require: I4NY1U - */ -HWTEST_F(ProfileCrudTest, SubscribeProfileEvent_001, TestSize.Level3) -{ - auto eventCb = std::make_shared(); - if (eventCb == nullptr) { - DTEST_LOG << "device profile service is nullptr" << std::endl; - return; - } - - SubscribeInfo subscribeInfo; - int result = DistributedDeviceProfileClient::GetInstance().SubscribeProfileEvent(subscribeInfo, eventCb); - EXPECT_NE(ERR_DP_INVALID_PARAMS, result); -} - -/** - * @tc.name: SyncDeviceProfile_001 - * @tc.desc: sync device profile - * @tc.type: FUNC - * @tc.require: I4NY1U - */ -HWTEST_F(ProfileCrudTest, SyncDeviceProfile_001, TestSize.Level3) -{ - auto dps = DistributedDeviceProfileClient::GetInstance().GetDeviceProfileService(); - if (dps == nullptr) { - DTEST_LOG << "device profile service is nullptr" << std::endl; - return; - } - TestUtil::MockPermission("faketest"); - wptr remote; - DistributedDeviceProfileClient::DeviceProfileDeathRecipient obj; - obj.OnRemoteDied(remote); - auto syncCb = std::make_shared(); - SyncOptions syncOptions; - int result = DistributedDeviceProfileClient::GetInstance().SyncDeviceProfile(syncOptions, syncCb); - EXPECT_EQ(ERR_DP_PERMISSION_DENIED, result); -} - -/** - * @tc.name: UnsubscribeProfileEvent_001 - * @tc.desc: unsubscribe device profile - * @tc.type: FUNC - * @tc.require: I4NY1U - */ -HWTEST_F(ProfileCrudTest, UnsubscribeProfileEvent_001, TestSize.Level3) -{ - auto eventCb = std::make_shared(); - if (eventCb == nullptr) { - DTEST_LOG << "device profile service is nullptr" << std::endl; - return; - } - - Parcel parcel; - ProfileEvent profileEvent = static_cast(parcel.ReadUint32()); - int result = DistributedDeviceProfileClient::GetInstance().UnsubscribeProfileEvent(profileEvent, eventCb); - EXPECT_NE(ERR_DP_INVALID_PARAMS, result); -} - -/** - * @tc.name: SubscribeProfileEvents_001 - * @tc.desc: Subscribe device profile - * @tc.type: FUNC - * @tc.require: I4NY1U - */ -HWTEST_F(ProfileCrudTest, SubscribeProfileEvents_001, TestSize.Level3) -{ - auto dps = DistributedDeviceProfileClient::GetInstance().GetDeviceProfileService(); - if (dps == nullptr) { - DTEST_LOG << "device profile service is nullptr" << std::endl; - return; - } - - std::list subscribeInfos; - auto eventCb = std::make_shared(); - std::list failedEvents; - if (subscribeInfos.empty() || eventCb == nullptr) { - return; - } - int result = DistributedDeviceProfileClient::GetInstance().SubscribeProfileEvents(subscribeInfos, - eventCb, failedEvents); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, result); -} - -/** - * @tc.name: SubscribeProfileEvents_002 - * @tc.desc: Subscribe device profile - * @tc.type: FUNC - * @tc.require: I4NY1U - */ -HWTEST_F(ProfileCrudTest, SubscribeProfileEvents_002, TestSize.Level3) -{ - auto dps = DistributedDeviceProfileClient::GetInstance().GetDeviceProfileService(); - if (dps == nullptr) { - DTEST_LOG << "device profile service is nullptr" << std::endl; - return; - } - - std::list subscribeInfos; - auto eventCb = std::make_shared(); - std::list failedEvents; - int result = DistributedDeviceProfileClient::GetInstance().SubscribeProfileEvents(subscribeInfos, - eventCb, failedEvents); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, result); -} - -/** - * @tc.name: SubscribeProfileEvents_003 - * @tc.desc: Subscribe device profile - * @tc.type: FUNC - * @tc.require: I4NY1U - */ -HWTEST_F(ProfileCrudTest, SubscribeProfileEvents_003, TestSize.Level3) -{ - auto dps = DistributedDeviceProfileClient::GetInstance().GetDeviceProfileService(); - if (dps == nullptr) { - DTEST_LOG << "device profile service is nullptr" << std::endl; - return; - } - TestUtil::MockPermission("distributedsched"); - auto callback = std::make_shared(); - std::list subscribeInfos; - std::list serviceIds; - serviceIds.emplace_back("appInfo"); - std::string deviceId = ""; - ExtraInfo extraInfo; - extraInfo["deviceId"] = deviceId; - extraInfo["serviceIds"] = serviceIds; - - SubscribeInfo info1; - info1.profileEvent = ProfileEvent::EVENT_PROFILE_CHANGED; - info1.extraInfo = std::move(extraInfo); - subscribeInfos.emplace_back(info1); - - SubscribeInfo info2; - info2.profileEvent = ProfileEvent::EVENT_SYNC_COMPLETED; - info2.extraInfo = std::move(extraInfo); - subscribeInfos.emplace_back(info2); - - std::list failedEvents; - DistributedDeviceProfileClient::SubscribeRecord subscribeRecord; - subscribeRecord.subscribeInfos = subscribeInfos; - subscribeRecord.notifier = sptr( - new ProfileEventNotifierStub(callback)); - subscribeRecord.profileEvents.set(static_cast(ProfileEvent::EVENT_PROFILE_CHANGED)); - DistributedDeviceProfileClient::GetInstance().subscribeRecords_[callback] = subscribeRecord; - DistributedDeviceProfileClient::GetInstance().SubscribeProfileEvents(subscribeInfos, callback, failedEvents); - - std::list subscribeInfosNew; - std::list failedEventsNew; - int result = DistributedDeviceProfileClient::GetInstance().SubscribeProfileEvents(subscribeInfosNew, - nullptr, failedEventsNew); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, result); -} - -/** - * @tc.name: SubscribeProfileEvents_004 - * @tc.desc: Subscribe device profile - * @tc.type: FUNC - * @tc.require: I4NY1U - */ -HWTEST_F(ProfileCrudTest, SubscribeProfileEvents_004, TestSize.Level3) -{ - TestUtil::MockPermission("distributedsched"); - auto dps = DistributedDeviceProfileClient::GetInstance().GetDeviceProfileService(); - if (dps == nullptr) { - DTEST_LOG << "device profile service is nullptr" << std::endl; - return; - } - - std::list subscribeInfos; - SubscribeInfo subscribeInfo; - subscribeInfos.emplace_back(subscribeInfo); - std::list failedEvents; - auto eventCb = std::make_shared(); - int result = DistributedDeviceProfileClient::GetInstance().SubscribeProfileEvents(subscribeInfos, - eventCb, failedEvents); - EXPECT_EQ(7, result); -} - -/** - * @tc.name: SubscribeProfileEvents_005 - * @tc.desc: Subscribe device profile - * @tc.type: FUNC - * @tc.require: I4NY1U - */ -HWTEST_F(ProfileCrudTest, SubscribeProfileEvents_005, TestSize.Level3) -{ - auto dps = DistributedDeviceProfileClient::GetInstance().GetDeviceProfileService(); - if (dps == nullptr) { - DTEST_LOG << "device profile service is nullptr" << std::endl; - return; - } - TestUtil::MockPermission("distributedsched"); - auto callback = std::make_shared(); - std::list subscribeInfos; - std::list serviceIds; - serviceIds.emplace_back("appInfo"); - std::string deviceId = ""; - ExtraInfo extraInfo; - extraInfo["deviceId"] = deviceId; - extraInfo["serviceIds"] = serviceIds; - - SubscribeInfo info1; - info1.profileEvent = ProfileEvent::EVENT_PROFILE_CHANGED; - info1.extraInfo = std::move(extraInfo); - subscribeInfos.emplace_back(info1); - - SubscribeInfo info2; - info2.profileEvent = ProfileEvent::EVENT_SYNC_COMPLETED; - subscribeInfos.emplace_back(info2); - - std::list failedEvents; - DistributedDeviceProfileClient::GetInstance().SubscribeProfileEvents(subscribeInfos, callback, failedEvents); - - std::list subscribeInfosNew; - SubscribeInfo subscribeInfoNew; - subscribeInfosNew.emplace_back(subscribeInfoNew); - std::list failedEventsNew; - int result = DistributedDeviceProfileClient::GetInstance().SubscribeProfileEvents(subscribeInfosNew, - nullptr, failedEventsNew); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, result); -} - -/** - * @tc.name: SubscribeProfileEvents_006 - * @tc.desc: Subscribe device profile - * @tc.type: FUNC - * @tc.require: I4NY1U - */ -HWTEST_F(ProfileCrudTest, SubscribeProfileEvents_006, TestSize.Level3) -{ - TestUtil::MockPermission("distributedsched"); - auto callback = std::make_shared(); - std::list subscribeInfos; - std::list serviceIds; - serviceIds.emplace_back("test"); - std::string deviceId = "test"; - ExtraInfo extraInfo; - extraInfo["deviceId"] = deviceId; - extraInfo["serviceIds"] = serviceIds; - - SubscribeInfo info1; - info1.profileEvent = ProfileEvent::EVENT_PROFILE_CHANGED; - info1.extraInfo = std::move(extraInfo); - subscribeInfos.emplace_back(info1); - - SubscribeInfo info2; - info2.profileEvent = ProfileEvent::EVENT_SYNC_COMPLETED; - subscribeInfos.emplace_back(info2); - - std::list failedEvents; - int result = - DistributedDeviceProfileClient::GetInstance().SubscribeProfileEvents(subscribeInfos, callback, failedEvents); - EXPECT_EQ(ERR_DP_SUBSCRIBE_FAILED, result); -} - -/** - * @tc.name: UnsubscribeProfileEvents_001 - * @tc.desc: Unsubscribe device profile - * @tc.type: FUNC - * @tc.require: I4NY1U - */ -HWTEST_F(ProfileCrudTest, UnsubscribeProfileEvents_001, TestSize.Level3) -{ - auto dps = DistributedDeviceProfileClient::GetInstance().GetDeviceProfileService(); - if (dps == nullptr) { - DTEST_LOG << "device profile service is nullptr" << std::endl; - return; - } - - std::list profileEvents; - auto eventCb = std::make_shared(); - std::list failedEvents; - if (profileEvents.empty() || eventCb == nullptr) { - return; - } - int result = DistributedDeviceProfileClient::GetInstance().UnsubscribeProfileEvents(profileEvents, - eventCb, failedEvents); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, result); -} - -/** - * @tc.name: UnsubscribeProfileEvents_002 - * @tc.desc: Subscribe device profile - * @tc.type: FUNC - * @tc.require: I4NY1U - */ -HWTEST_F(ProfileCrudTest, UnsubscribeProfileEvents_002, TestSize.Level3) -{ - auto dps = DistributedDeviceProfileClient::GetInstance().GetDeviceProfileService(); - if (dps == nullptr) { - DTEST_LOG << "device profile service is nullptr" << std::endl; - return; - } - - std::list subscribeInfos; - auto eventCb = std::make_shared(); - std::list failedEvents; - int result = DistributedDeviceProfileClient::GetInstance().UnsubscribeProfileEvents(subscribeInfos, - eventCb, failedEvents); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, result); -} - -/** - * @tc.name: UnsubscribeProfileEvents_003 - * @tc.desc: Subscribe device profile - * @tc.type: FUNC - * @tc.require: I4NY1U - */ -HWTEST_F(ProfileCrudTest, UnsubscribeProfileEvents_003, TestSize.Level3) -{ - auto dps = DistributedDeviceProfileClient::GetInstance().GetDeviceProfileService(); - if (dps == nullptr) { - DTEST_LOG << "device profile service is nullptr" << std::endl; - return; - } - std::list subscribeInfos1; - std::list newSubscribeInfos1; - SubscribeInfo subscribeInfo1; - SubscribeInfo subscribeInfo2; - subscribeInfos1.emplace_back(subscribeInfo1); - newSubscribeInfos1.emplace_back(subscribeInfo2); - DistributedDeviceProfileClient::GetInstance().MergeSubscribeInfoLocked(subscribeInfos1, newSubscribeInfos1); - std::list subscribeInfos; - std::list failedEvents; - int result = DistributedDeviceProfileClient::GetInstance().UnsubscribeProfileEvents(subscribeInfos, - nullptr, failedEvents); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, result); -} - -/** - * @tc.name: SubscribeProfileEvents_004 - * @tc.desc: Subscribe device profile - * @tc.type: FUNC - * @tc.require: I4NY1U - */ -HWTEST_F(ProfileCrudTest, UnsubscribeProfileEvents_004, TestSize.Level3) -{ - auto dps = DistributedDeviceProfileClient::GetInstance().GetDeviceProfileService(); - if (dps == nullptr) { - DTEST_LOG << "device profile service is nullptr" << std::endl; - return; - } - std::list subscribeInfos1; - std::list newSubscribeInfos1; - SubscribeInfo subscribeInfo; - SubscribeInfo subscribeInfo11; - subscribeInfos1.emplace_back(subscribeInfo); - newSubscribeInfos1.emplace_back(subscribeInfo); - DistributedDeviceProfileClient::GetInstance().MergeSubscribeInfoLocked(subscribeInfos1, newSubscribeInfos1); - newSubscribeInfos1.clear(); - newSubscribeInfos1.emplace_back(subscribeInfo11); - DistributedDeviceProfileClient::GetInstance().MergeSubscribeInfoLocked(subscribeInfos1, newSubscribeInfos1); - std::list subscribeInfos; - ProfileEvent subscribeInfo1; - subscribeInfos.emplace_back(subscribeInfo1); - std::list failedEvents; - auto eventCb = std::make_shared(); - int result = DistributedDeviceProfileClient::GetInstance().UnsubscribeProfileEvents(subscribeInfos, - eventCb, failedEvents); - EXPECT_EQ(ERR_DP_NOT_SUBSCRIBED, result); -} - -/** - * @tc.name: UnsubscribeProfileEvents_005 - * @tc.desc: Subscribe device profile - * @tc.type: FUNC - * @tc.require: I4NY1U - */ -HWTEST_F(ProfileCrudTest, UnSubscribeProfileEvents_005, TestSize.Level3) -{ - auto dps = DistributedDeviceProfileClient::GetInstance().GetDeviceProfileService(); - if (dps == nullptr) { - DTEST_LOG << "device profile service is nullptr" << std::endl; - return; - } - std::list subscribeInfos; - std::list newSubscribeInfos; - DistributedDeviceProfileClient::GetInstance().MergeSubscribeInfoLocked(subscribeInfos, newSubscribeInfos); - std::list profileEvents; - ProfileEvent profileEvent; - profileEvents.emplace_back(profileEvent); - std::list failedEvents; - int result = DistributedDeviceProfileClient::GetInstance().UnsubscribeProfileEvents(profileEvents, - nullptr, failedEvents); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, result); -} - -/** - * @tc.name: UnsubscribeProfileEvents_006 - * @tc.desc: Subscribe device profile - * @tc.type: FUNC - * @tc.require: I4NY1U - */ -HWTEST_F(ProfileCrudTest, UnSubscribeProfileEvents_006, TestSize.Level3) -{ - auto dps = DistributedDeviceProfileClient::GetInstance().GetDeviceProfileService(); - if (dps == nullptr) { - DTEST_LOG << "device profile service is nullptr" << std::endl; - return; - } - - std::list subscribeInfos; - ProfileEvent subscribeInfo; - subscribeInfos.emplace_back(subscribeInfo); - std::list failedEvents; - auto eventCb = std::make_shared(); - DistributedDeviceProfileClient::SubscribeRecord subscribeRecord; - DistributedDeviceProfileClient::GetInstance().subscribeRecords_[eventCb] = subscribeRecord; - int result = DistributedDeviceProfileClient::GetInstance().UnsubscribeProfileEvents(subscribeInfos, - eventCb, failedEvents); - EXPECT_EQ(3, result); -} - -/** - * @tc.name: UnsubscribeProfileEvents_007 - * @tc.desc: Subscribe device profile - * @tc.type: FUNC - * @tc.require: I4NY1U - */ -HWTEST_F(ProfileCrudTest, UnSubscribeProfileEvents_007, TestSize.Level3) -{ - auto callback = std::make_shared(); - std::list profileEvents; - SubscribeInfo info1; - profileEvents.emplace_back(ProfileEvent::EVENT_PROFILE_CHANGED); - profileEvents.emplace_back(ProfileEvent::EVENT_SYNC_COMPLETED); - std::list failedEvents; - int result = - DistributedDeviceProfileClient::GetInstance().UnsubscribeProfileEvents(profileEvents, callback, failedEvents); - EXPECT_EQ(ERR_DP_NOT_SUBSCRIBED, result); -} - -/** - * @tc.name: GetDeviceProfile_001 - * @tc.desc: get device profile with syscap - * @tc.type: FUNC - * @tc.require: I59PZ3 - */ -HWTEST_F(ProfileCrudTest, GetDeviceProfile_001, TestSize.Level3) -{ - auto dps = DistributedDeviceProfileClient::GetInstance().GetDeviceProfileService(); - if (dps == nullptr) { - DTEST_LOG << "device profile service is nullptr" << std::endl; - return; - } - ServiceCharacteristicProfile profile; - profile.SetServiceId(SERVICE_ID); - profile.SetServiceType(SERVICE_TYPE); - int32_t result = DistributedDeviceProfileClient::GetInstance().GetDeviceProfile("", SERVICE_ID, profile); - EXPECT_EQ(ERR_DP_PERMISSION_DENIED, result); - std::string jsonData = profile.GetCharacteristicProfileJson(); - DTEST_LOG << "jsonData:" << jsonData << std::endl; - nlohmann::json jsonObject = nlohmann::json::parse(jsonData, nullptr, false); - if (jsonObject.is_discarded()) { - DTEST_LOG << "json parse faild" << std::endl; - return; - } - if (!jsonObject.contains(CHARACTER_OS_SYSCAP) || !jsonObject[CHARACTER_OS_SYSCAP].is_array()) { - DTEST_LOG << "can't find entry for CHARACTER_OS_SYSCAP or not array type" << std::endl; - return; - } - std::vector values = jsonObject[CHARACTER_OS_SYSCAP].get>(); - int intValues[PCID_MAIN_INTS]; - int i = 0; - for (int value : values) { - intValues[i++] = value; - } - char (*osOutput)[SINGLE_SYSCAP_LEN] = nullptr; - int32_t length; - if (!DecodeOsSyscap((char *)intValues, &osOutput, &length)) { - DTEST_LOG << "DecodeOsSyscap failed" << std::endl; - return; - } - for (int i = 0; i < length; i++) { - DTEST_LOG << "OsSyscap: " << *(osOutput + i) << std::endl; - } - std::string capabilities = jsonObject[CHARACTER_PRIVATE_SYSCAP]; - char (*priOutput)[SINGLE_SYSCAP_LEN] = nullptr; - if (!DecodePrivateSyscap((char *)capabilities.c_str(), &priOutput, &length)) { - DTEST_LOG << "DecodePrivateSyscap failed" << std::endl; - return; - } - for (int i = 0; i < length; i++) { - DTEST_LOG << "PrivateSyscap: " << *(priOutput + i) << std::endl; - } -} - -/** - * @tc.name: GetDeviceProfile_002 - * @tc.desc: get device profile - * @tc.type: FUNC - * @tc.require: I4NY22 - */ -HWTEST_F(ProfileCrudTest, GetDeviceProfile_002, TestSize.Level3) -{ - auto dps = DistributedDeviceProfileClient::GetInstance().GetDeviceProfileService(); - if (dps == nullptr) { - DTEST_LOG << "device profile service is nullptr" << std::endl; - return; - } - TestUtil::MockPermission("multimodalinput"); - ServiceCharacteristicProfile profile; - profile.SetServiceId("InputDeviceCooperation"); - profile.SetServiceType("InputDeviceCooperation"); - nlohmann::json j; - profile.SetCharacteristicProfileJson(j.dump()); - DistributedDeviceProfileClient::GetInstance().GetDeviceProfile("", "InputDeviceCooperation", profile); - ServiceCharacteristicProfile profileNew; - profileNew.SetServiceId("test"); - profileNew.SetServiceType("test"); - nlohmann::json jNew; - profileNew.SetCharacteristicProfileJson(jNew.dump()); - int32_t result = DistributedDeviceProfileClient::GetInstance().GetDeviceProfile("", SERVICE_ID, profileNew); - EXPECT_NE(ERR_DP_INVALID_PARAMS, result); -} - -/** - * @tc.name: DfxErrorPrint_001 - * @tc.desc: print hisysevent error event - * @tc.type: FUNC - * @tc.require: I5EE0Y - */ -HWTEST_F(ProfileCrudTest, DfxErrorPrint_001, TestSize.Level3) -{ - int ret = HiSysEventWrite(HiSysEvent::Domain::DEVICE_PROFILE, DP_SYNC_FAILED, - HiSysEvent::EventType::FAULT, FAULT_CODE_KEY, -1); - EXPECT_EQ(0, ret); -} - -/** - * @tc.name: UnsubscribeProfileEvents_008 - * @tc.desc: Subscribe device profile - * @tc.type: FUNC - * @tc.require: I4NY1U - */ -HWTEST_F(ProfileCrudTest, UnSubscribeProfileEvents_008, TestSize.Level3) -{ - TestUtil::MockPermission("distributedsched"); - auto callback = std::make_shared(); - std::list profileEvents; - SubscribeInfo info1; - profileEvents.emplace_back(ProfileEvent::EVENT_PROFILE_CHANGED); - profileEvents.emplace_back(ProfileEvent::EVENT_SYNC_COMPLETED); - std::list failedEvents; - int result = - DistributedDeviceProfileClient::GetInstance().UnsubscribeProfileEvents(profileEvents, callback, failedEvents); - EXPECT_EQ(ERR_DP_NOT_SUBSCRIBED, result); -} - -/** - * @tc.name: UnsubscribeProfileEvents_009 - * @tc.desc: Subscribe device profile - * @tc.type: FUNC - * @tc.require: I4NY1U - */ -HWTEST_F(ProfileCrudTest, UnSubscribeProfileEvents_009, TestSize.Level3) -{ - TestUtil::MockPermission("distributedsched"); - auto callback = std::make_shared(); - std::list subscribeInfos; - std::list serviceIds; - serviceIds.emplace_back("appInfo"); - std::string deviceId = ""; - ExtraInfo extraInfo; - extraInfo["deviceId"] = deviceId; - extraInfo["serviceIds"] = serviceIds; - - SubscribeInfo info1; - info1.profileEvent = ProfileEvent::EVENT_PROFILE_CHANGED; - info1.extraInfo = std::move(extraInfo); - subscribeInfos.emplace_back(info1); - - SubscribeInfo info2; - info2.profileEvent = ProfileEvent::EVENT_SYNC_COMPLETED; - subscribeInfos.emplace_back(info2); - - std::list failedEvents; - int result = - DistributedDeviceProfileClient::GetInstance().SubscribeProfileEvents(subscribeInfos, callback, failedEvents); - std::list profileEvents; - profileEvents.emplace_back(ProfileEvent::EVENT_PROFILE_CHANGED); - profileEvents.emplace_back(ProfileEvent::EVENT_SYNC_COMPLETED); - result = - DistributedDeviceProfileClient::GetInstance().UnsubscribeProfileEvents(profileEvents, callback, failedEvents); - EXPECT_EQ(0, result); -} - -/** - * @tc.name: SyncDeviceProfile_002 - * @tc.desc: sync device profile - * @tc.type: FUNC - * @tc.require: I4NY1U - */ -HWTEST_F(ProfileCrudTest, SyncDeviceProfile_002, TestSize.Level3) -{ - TestUtil::MockPermission("multimodalinput"); - int64_t mode = 2; - SyncOptions syncOption; - syncOption.SetSyncMode((OHOS::DeviceProfile::SyncMode)mode); - syncOption.AddDevice("test"); - int result = DistributedDeviceProfileClient::GetInstance().SyncDeviceProfile(syncOption, - std::make_shared()); - EXPECT_EQ(ERR_DP_INIT_DB_FAILED, result); -} - -/** - * @tc.name: PutDeviceProfile_006 - * @tc.desc: delete an empty profile - * @tc.type: FUNC - * @tc.require: I4NY21 - */ -HWTEST_F(ProfileCrudTest, PutDeviceProfile_006, TestSize.Level3) -{ - ServiceCharacteristicProfile profile; - profile.SetServiceId("test"); - profile.SetServiceType("test"); - nlohmann::json j; - // the result string is "null" - profile.SetCharacteristicProfileJson(j.dump()); - int32_t result = DistributedDeviceProfileClient::GetInstance().PutDeviceProfile(profile); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, result); -} - -/** - * @tc.name: GetDeviceProfile_003 - * @tc.desc: get device profile - * @tc.type: FUNC - * @tc.require: I4NY22 - */ -HWTEST_F(ProfileCrudTest, GetDeviceProfile_003, TestSize.Level3) -{ - ServiceCharacteristicProfile profile; - profile.SetServiceId("test"); - profile.SetServiceType("test"); - nlohmann::json j; - profile.SetCharacteristicProfileJson(j.dump()); - int32_t result = DistributedDeviceProfileClient::GetInstance().GetDeviceProfile("", SERVICE_ID, profile); - EXPECT_NE(ERR_DP_INVALID_PARAMS, result); -} - -/** - * @tc.name: DeleteDeviceProfile_003 - * @tc.desc: delete an empty profile - * @tc.type: FUNC - * @tc.require: I4NY21 - */ -HWTEST_F(ProfileCrudTest, DeleteDeviceProfile_003, TestSize.Level3) -{ - TestUtil::MockPermission("faketest"); - int32_t result = DistributedDeviceProfileClient::GetInstance().DeleteDeviceProfile("test"); - EXPECT_EQ(ERR_DP_PERMISSION_DENIED, result); -} - -/** - * @tc.name: PutDeviceProfile_007 - * @tc.desc: put device profile with empty service type - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileCrudTest, PutDeviceProfile_007, TestSize.Level3) -{ - ServiceCharacteristicProfile profile; - profile.SetServiceId("test"); - profile.SetServiceType("test"); - nlohmann::json j; - j["testVersion"] = "3.0.0"; - j["testApiLevel"] = 7; - profile.SetCharacteristicProfileJson(j.dump()); - profile.SetServiceProfileJson(j.dump()); - int32_t result = DistributedDeviceProfileClient::GetInstance().PutDeviceProfile(profile); - EXPECT_NE(ERR_DP_INVALID_PARAMS, result); -} - -/** - * @tc.name: PutDeviceProfile_008 - * @tc.desc: put device profile with empty service type - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileCrudTest, PutDeviceProfile_008, TestSize.Level3) -{ - ServiceCharacteristicProfile profile; - profile.SetServiceId("test"); - profile.SetServiceType("test"); - nlohmann::json j; - j["testVersion"] = "3.0.0"; - j["testApiLevel"] = 7; - profile.SetCharacteristicProfileJson(j.dump()); - profile.SetServiceProfileJson(j.dump()); - int32_t result = DistributedDeviceProfileClient::GetInstance().PutDeviceProfile(profile); - EXPECT_NE(ERR_DP_INVALID_PARAMS, result); -} -/** - * @tc.name: SubscribeProfileEvents_007 - * @tc.desc: Subscribe device profile - * @tc.type: FUNC - * @tc.require: I4NY1U - */ -HWTEST_F(ProfileCrudTest, SubscribeProfileEvents_007, TestSize.Level3) -{ - std::list subscribeInfos; - std::list failedEvents; - int result = DistributedDeviceProfileClient::GetInstance().SubscribeProfileEvents(subscribeInfos, - nullptr, failedEvents); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, result); -} -/** - * @tc.name: SubscribeProfileEvents_008 - * @tc.desc: Subscribe device profile - * @tc.type: FUNC - * @tc.require: I4NY1U - */ -HWTEST_F(ProfileCrudTest, SubscribeProfileEvents_008, TestSize.Level3) -{ - TestUtil::MockPermission("multimodalinput"); - auto callback = std::make_shared(); - std::list subscribeInfos; - std::list serviceIds; - serviceIds.emplace_back("test"); - std::string deviceId = "test"; - ExtraInfo extraInfo; - extraInfo["deviceId"] = deviceId; - extraInfo["serviceIds"] = serviceIds; - - SubscribeInfo info1; - info1.profileEvent = ProfileEvent::EVENT_PROFILE_CHANGED; - info1.extraInfo = std::move(extraInfo); - subscribeInfos.emplace_back(info1); - - SubscribeInfo info2; - info2.profileEvent = ProfileEvent::EVENT_SYNC_COMPLETED; - subscribeInfos.emplace_back(info2); - - std::list failedEvents; - int result = - DistributedDeviceProfileClient::GetInstance().SubscribeProfileEvents(subscribeInfos, callback, failedEvents); - EXPECT_EQ(ERR_DP_SUBSCRIBE_FAILED, result); -} - -/** - * @tc.name: SubscribeProfileEvents_009 - * @tc.desc: Subscribe device profile - * @tc.type: FUNC - * @tc.require: I4NY1U - */ -HWTEST_F(ProfileCrudTest, SubscribeProfileEvents_009, TestSize.Level3) -{ - DistributedDeviceProfileClient::GetInstance().LoadSystemAbilityFail(); - TestUtil::MockPermission("distributedsched"); - auto callback = std::make_shared(); - std::list subscribeInfos; - std::list serviceIds; - serviceIds.emplace_back("appInfo"); - std::string deviceId = ""; - ExtraInfo extraInfo; - extraInfo["deviceId"] = deviceId; - extraInfo["serviceIds"] = serviceIds; - - SubscribeInfo info1; - info1.profileEvent = ProfileEvent::EVENT_PROFILE_CHANGED; - info1.extraInfo = std::move(extraInfo); - subscribeInfos.emplace_back(info1); - - SubscribeInfo info2; - info2.profileEvent = ProfileEvent::EVENT_SYNC_COMPLETED; - info2.extraInfo = std::move(extraInfo); - subscribeInfos.emplace_back(info2); - - std::list failedEvents; - DistributedDeviceProfileClient::SubscribeRecord subscribeRecord; - subscribeRecord.subscribeInfos = subscribeInfos; - subscribeRecord.notifier = sptr( - new ProfileEventNotifierStub(callback)); - subscribeRecord.profileEvents.set(static_cast(ProfileEvent::EVENT_SYNC_COMPLETED)); - DistributedDeviceProfileClient::GetInstance().subscribeRecords_[callback] = subscribeRecord; - DistributedDeviceProfileClient::GetInstance().SubscribeProfileEvents(subscribeInfos, callback, failedEvents); - std::list profileEvents; - profileEvents.emplace_back(ProfileEvent::EVENT_PROFILE_CHANGED); - profileEvents.emplace_back(ProfileEvent::EVENT_SYNC_COMPLETED); - int result = DistributedDeviceProfileClient::GetInstance().UnsubscribeProfileEvents(profileEvents, - nullptr, failedEvents); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, result); -} -} -} diff --git a/old/services/core/test/unittest/profile_dm_test.cpp b/old/services/core/test/unittest/profile_dm_test.cpp deleted file mode 100644 index 73ba7beb..00000000 --- a/old/services/core/test/unittest/profile_dm_test.cpp +++ /dev/null @@ -1,237 +0,0 @@ -/* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. - * 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. - */ - -#include - -#include "utils.h" - -#define private public -#define protected public -#include "dp_device_manager.h" -#include "event_handler_factory.h" -#undef private -#undef protected - -namespace OHOS { -namespace DeviceProfile { -using namespace testing; -using namespace testing::ext; - -class ProfileDmTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp(); - void TearDown(); -}; - -void ProfileDmTest::SetUpTestCase() -{ - DTEST_LOG << "SetUpTestCase" << std::endl; -} - -void ProfileDmTest::TearDownTestCase() -{ - DTEST_LOG << "TearDownTestCase" << std::endl; -} - -void ProfileDmTest::SetUp() -{ - DTEST_LOG << "SetUp" << std::endl; -} - -void ProfileDmTest::TearDown() -{ - DTEST_LOG << "TearDown" << std::endl; -} - -/** - * @tc.name: WaitForDnetworkReady_001 - * @tc.desc: marshalling - * @tc.type: FUNC - * @tc.require: I4OH94 - */ -HWTEST_F(ProfileDmTest, WaitForDnetworkReady_001, TestSize.Level3) -{ - bool res = DpDeviceManager::GetInstance().WaitForDnetworkReady(); - EXPECT_EQ(true, res); -} - -/** - * @tc.name: GetUdidByNetworkId_001 - * @tc.desc: marshalling - * @tc.type: FUNC - * @tc.require: I4OH94 - */ -HWTEST_F(ProfileDmTest, GetUdidByNetworkId_001, TestSize.Level3) -{ - std::string udid; - bool res = DpDeviceManager::GetInstance().GetUdidByNetworkId("", udid); - EXPECT_EQ(false, res); -} - -/** - * @tc.name: GetUuidByNetworkId_001 - * @tc.desc: marshalling - * @tc.type: FUNC - * @tc.require: I4OH94 - */ -HWTEST_F(ProfileDmTest, GetUuidByNetworkId_001, TestSize.Level3) -{ - std::string uuid; - DpDeviceManager::GetInstance().AddLocalDeviceIds(); - DpDeviceManager::GetInstance().RecoverDevicesIfNeeded(); - bool res = DpDeviceManager::GetInstance().GetUuidByNetworkId("", uuid); - EXPECT_EQ(false, res); -} - -/** - * @tc.name: TransformDeviceId - * @tc.desc: marshalling - * @tc.type: FUNC - * @tc.require: I4OH94 - */ -HWTEST_F(ProfileDmTest, TransformDeviceId_001, TestSize.Level3) -{ - std::string queryUdid; - std::string udid; - DpDeviceManager::GetInstance().RemoveDeviceIds(""); - DpDeviceManager::GetInstance().GetLocalDeviceUdid(udid); - DpDeviceManager::GetInstance().RemoveDeviceIdsByUdid(""); - DpDeviceManager::GetInstance().RemoveExpiredDeviceIds(""); - DpDeviceManager::GetInstance().GetTrustedDeviceList(); - bool res = DpDeviceManager::GetInstance().TransformDeviceId("", queryUdid, DeviceIdType::UUID); - EXPECT_EQ(false, res); -} - -/** - * @tc.name: Init_001 - * @tc.desc: set service profile json - * @tc.type: FUNC - * @tc.require: I4OH94 - */ -HWTEST_F(ProfileDmTest, Init_001, TestSize.Level3) -{ - DistributedDeviceProfile::EventHandlerFactory::GetInstance().Init(); - bool res = DpDeviceManager::GetInstance().Init(); - DpDeviceManager::GetInstance().GetTrustedDeviceList(); - DpDeviceManager::GetInstance().AddLocalDeviceIds(); - EXPECT_EQ(true, res); -} - -/** - * @tc.name: WaitForDnetworkReady_002 - * @tc.desc: marshalling - * @tc.type: FUNC - * @tc.require: I4OH94 - */ -HWTEST_F(ProfileDmTest, WaitForDnetworkReady_002, TestSize.Level3) -{ - bool res = DpDeviceManager::GetInstance().WaitForDnetworkReady(); - EXPECT_EQ(true, res); -} - -/** - * @tc.name: ConnectDeviceManager_001 - * @tc.desc: marshalling - * @tc.type: FUNC - * @tc.require: I4OH94 - */ -HWTEST_F(ProfileDmTest, ConnectDeviceManager_001, TestSize.Level3) -{ - bool res = DpDeviceManager::GetInstance().ConnectDeviceManager(); - EXPECT_EQ(true, res); -} - -/** - * @tc.name: GetUdidByNetworkId_002 - * @tc.desc: marshalling - * @tc.type: FUNC - * @tc.require: I4OH94 - */ -HWTEST_F(ProfileDmTest, GetUdidByNetworkId_002, TestSize.Level3) -{ - auto dpDeviceInfo = std::make_shared( - "12345678", "12345678", 0x00); - DpDeviceManager::GetInstance().OnNodeOnline(dpDeviceInfo); - std::string udid; - bool res = DpDeviceManager::GetInstance().GetUdidByNetworkId("", udid); - EXPECT_EQ(false, res); -} - -/** - * @tc.name: GetUuidByNetworkId_002 - * @tc.desc: marshalling - * @tc.type: FUNC - * @tc.require: I4OH94 - */ -HWTEST_F(ProfileDmTest, GetUuidByNetworkId_002, TestSize.Level3) -{ - std::string uuid; - DpDeviceManager::GetInstance().OnNodeOffline(""); - DpDeviceManager::GetInstance().AddLocalDeviceIds(); - DpDeviceManager::GetInstance().RecoverDevicesIfNeeded(); - bool res = DpDeviceManager::GetInstance().GetUuidByNetworkId("", uuid); - EXPECT_EQ(false, res); -} - -/** - * @tc.name: TransformDeviceId_002 - * @tc.desc: marshalling - * @tc.type: FUNC - * @tc.require: I4OH94 - */ -HWTEST_F(ProfileDmTest, TransformDeviceId_002, TestSize.Level3) -{ - std::string queryUdid; - std::string udid; - DpDeviceManager::GetInstance().RemoveDeviceIds(""); - DpDeviceManager::GetInstance().GetLocalDeviceUdid(udid); - DpDeviceManager::GetInstance().RemoveDeviceIdsByUdid(""); - DpDeviceManager::GetInstance().RemoveExpiredDeviceIds(""); - std::list deviceIdList; - deviceIdList.emplace_back("testttt"); - DpDeviceManager::GetInstance().GetDeviceIdList(deviceIdList); - std::shared_ptr device; - std::list> deviceList; - DpDeviceManager::GetInstance().GetDeviceList(deviceList); - bool res = DpDeviceManager::GetInstance().TransformDeviceId("", queryUdid, DeviceIdType::UUID); - EXPECT_EQ(false, res); -} - -/** - * @tc.name: DisconnectDeviceManager_001 - * @tc.desc: marshalling - * @tc.type: FUNC - * @tc.require: I4OH94 - */ -HWTEST_F(ProfileDmTest, DisconnectDeviceManager_001, TestSize.Level3) -{ - std::string queryUdid; - std::string udid; - std::list deviceIdList; - std::map> remoteDeviceInfoMap_; - std::shared_ptr deviceInfo = std::make_shared("test", "test", 1); - DpDeviceManager::GetInstance().remoteDeviceInfoMap_["testttt"] = deviceInfo; - deviceIdList.emplace_back("testttt"); - DpDeviceManager::GetInstance().GetDeviceIdList(deviceIdList); - std::shared_ptr device; - std::list> deviceList; - DpDeviceManager::GetInstance().GetDeviceList(deviceList); - bool res = DpDeviceManager::GetInstance().DisconnectDeviceManager(); - EXPECT_EQ(true, res); -} -} -} diff --git a/old/services/core/test/unittest/profile_entry_test.cpp b/old/services/core/test/unittest/profile_entry_test.cpp deleted file mode 100644 index 6f0a35e2..00000000 --- a/old/services/core/test/unittest/profile_entry_test.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * 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. - */ - -#include - -#include "distributed_device_profile_client.h" -#include "profile_change_notification.h" -#include "utils.h" - -namespace OHOS { -namespace DeviceProfile { -using namespace testing; -using namespace testing::ext; - -class ProfileEntryTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp(); - void TearDown(); -}; - -void ProfileEntryTest::SetUpTestCase() -{ - DTEST_LOG << "SetUpTestCase" << std::endl; - DistributedDeviceProfileClient::GetInstance().DeleteDeviceProfile("111111"); -} - -void ProfileEntryTest::TearDownTestCase() -{ - DTEST_LOG << "TearDownTestCase" << std::endl; -} - -void ProfileEntryTest::SetUp() -{ - DTEST_LOG << "SetUp" << std::endl; -} - -void ProfileEntryTest::TearDown() -{ - DTEST_LOG << "TearDown" << std::endl; -} - -/** - * @tc.name: Marshalling_001 - * @tc.desc: Marshalling of profile entry - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(ProfileEntryTest, Marshalling_001, TestSize.Level3) -{ - Parcel parcel; - std::shared_ptr temp = std::make_shared(); - bool result = temp->Marshalling(parcel); - EXPECT_EQ(true, result); -} - -/** - * @tc.name: Unmarshalling_001 - * @tc.desc: Unmarshalling of profile entry - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(ProfileEntryTest, Unmarshalling_001, TestSize.Level3) -{ - Parcel parcel; - std::shared_ptr temp = std::make_shared(); - bool result = temp->Unmarshalling(parcel); - EXPECT_EQ(false, result); -} - -/** - * @tc.name: Unmarshalling_002 - * @tc.desc: Unmarshalling of profile entry - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(ProfileEntryTest, Unmarshalling_002, TestSize.Level3) -{ - Parcel parcel; - std::shared_ptr temp = std::make_shared(); - bool result = temp->Marshalling(parcel); - EXPECT_EQ(true, result); - result = temp->Unmarshalling(parcel); - EXPECT_EQ(true, result); -} -} -} \ No newline at end of file diff --git a/old/services/core/test/unittest/profile_event_notifier_proxy_test.cpp b/old/services/core/test/unittest/profile_event_notifier_proxy_test.cpp deleted file mode 100644 index 8ab53223..00000000 --- a/old/services/core/test/unittest/profile_event_notifier_proxy_test.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * 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. - */ - -#include - -#include "distributed_device_profile_client.h" -#include "profile_event_notifier_proxy.h" -#include "utils.h" - -namespace OHOS { -namespace DeviceProfile { -using namespace testing; -using namespace testing::ext; - -class ProfileEventNotifierProxyTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp(); - void TearDown(); -}; - -class StorageProfileEventCallback : public IProfileEventCallback { -public: - int result = 0; -}; - -void ProfileEventNotifierProxyTest::SetUpTestCase() -{ - DTEST_LOG << "SetUpTestCase" << std::endl; - DistributedDeviceProfileClient::GetInstance().DeleteDeviceProfile("111111"); -} - -void ProfileEventNotifierProxyTest::TearDownTestCase() -{ - DTEST_LOG << "TearDownTestCase" << std::endl; -} - -void ProfileEventNotifierProxyTest::SetUp() -{ - DTEST_LOG << "SetUp" << std::endl; -} - -void ProfileEventNotifierProxyTest::TearDown() -{ - DTEST_LOG << "TearDown" << std::endl; -} - -/** - * @tc.name: OnSyncCompleted_001 - * @tc.desc: OnSyncCompleted - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(ProfileEventNotifierProxyTest, OnSyncCompleted_001, TestSize.Level3) -{ - auto syncCb = std::make_shared(); - sptr stub(new ProfileEventNotifierStub(syncCb)); - sptr proxy(new ProfileEventNotifierProxy(stub)); - ASSERT_NE(proxy, nullptr); - SyncResult syncResults; - proxy->OnSyncCompleted(syncResults); - EXPECT_EQ(syncCb->result, 0); -} - -/** - * @tc.name: OnSyncCompleted_001 - * @tc.desc: OnSyncCompleted - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(ProfileEventNotifierProxyTest, OnSyncCompleted_002, TestSize.Level3) -{ - auto syncCb = std::make_shared(); - sptr stub(new ProfileEventNotifierStub(syncCb)); - sptr proxy(new ProfileEventNotifierProxy(stub)); - ASSERT_NE(proxy, nullptr); - SyncResult syncResults; - syncResults.emplace("testdeviceid", SUCCEEDED); - proxy->OnSyncCompleted(syncResults); - EXPECT_EQ(syncCb->result, 0); -} - -/** - * @tc.name: OnProfileChanged_001 - * @tc.desc: OnProfileChanged - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(ProfileEventNotifierProxyTest, OnProfileChanged_001, TestSize.Level3) -{ - auto syncCb = std::make_shared(); - sptr stub(new ProfileEventNotifierStub(syncCb)); - sptr proxy(new ProfileEventNotifierProxy(stub)); - ASSERT_NE(proxy, nullptr); - ProfileChangeNotification notification; - proxy->OnProfileChanged(notification); - EXPECT_EQ(syncCb->result, 0); -} -} -} \ No newline at end of file diff --git a/old/services/core/test/unittest/profile_proxy_test.cpp b/old/services/core/test/unittest/profile_proxy_test.cpp deleted file mode 100644 index 635c65b0..00000000 --- a/old/services/core/test/unittest/profile_proxy_test.cpp +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * 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. - */ - -#include - -#include "utils.h" - -#define private public -#include "distributed_device_profile_client.h" -#include "distributed_device_profile_proxy.h" -#include "iprofile_event_callback.h" -#undef private - -namespace OHOS { -namespace DeviceProfile { -using namespace testing; -using namespace testing::ext; - -class ProfileProxyTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp(); - void TearDown(); -}; - -void ProfileProxyTest::SetUpTestCase() -{ - DTEST_LOG << "SetUpTestCase" << std::endl; - DistributedDeviceProfileClient::GetInstance().DeleteDeviceProfile("111111"); -} - -void ProfileProxyTest::TearDownTestCase() -{ - DTEST_LOG << "TearDownTestCase" << std::endl; -} - -void ProfileProxyTest::SetUp() -{ - DTEST_LOG << "SetUp" << std::endl; -} - -void ProfileProxyTest::TearDown() -{ - DTEST_LOG << "TearDown" << std::endl; -} - -/** - * @tc.name: PutDeviceProfile_001 - * @tc.desc: put device profile with test service - * @tc.type: FUNC - * @tc.require: I51HKG - */ -HWTEST_F(ProfileProxyTest, PutDeviceProfile_001, TestSize.Level3) -{ - auto dps = DistributedDeviceProfileClient::GetInstance().GetDeviceProfileService(); - if (dps == nullptr) { - return; - } - - SyncResult syncResults; - IProfileEventCallback eventCb; - eventCb.OnSyncCompleted(syncResults); - DTEST_LOG << "sync results completed" << std::endl; - - ServiceCharacteristicProfile profile; - profile.SetServiceId("test"); - profile.SetServiceType("test"); - nlohmann::json jsonData; - profile.SetCharacteristicProfileJson(jsonData.dump()); - int32_t result = dps->PutDeviceProfile(profile); - DTEST_LOG << "result: " << result << std::endl; - EXPECT_NE(result, ERR_INVALID_DATA); -} - -/** - * @tc.name: DeleteDeviceProfile_001 - * @tc.desc: delete an empty profile - * @tc.type: FUNC - * @tc.require: I51HKG - */ -HWTEST_F(ProfileProxyTest, DeleteDeviceProfile_001, TestSize.Level3) -{ - auto dps = DistributedDeviceProfileClient::GetInstance().GetDeviceProfileService(); - if (dps == nullptr) { - return; - } - - std::string serviceId = ""; - int32_t result = dps->DeleteDeviceProfile(serviceId); - DTEST_LOG << "result: " << result << std::endl; - EXPECT_NE(result, ERR_INVALID_DATA); -} - -/** - * @tc.name: SyncDeviceProfile_001 - * @tc.desc: sync device profile - * @tc.type: FUNC - * @tc.require: I51HKG - */ -HWTEST_F(ProfileProxyTest, SyncDeviceProfile_001, TestSize.Level3) -{ - auto dps = DistributedDeviceProfileClient::GetInstance().GetDeviceProfileService(); - if (dps == nullptr) { - return; - } - - ProfileChangeNotification changeNotification; - IProfileEventCallback eventCb; - eventCb.OnProfileChanged(changeNotification); - DTEST_LOG << "profile changed" << std::endl; - - SyncOptions syncOptions; - sptr profileEventNotifier; - int32_t result = dps->SyncDeviceProfile(syncOptions, profileEventNotifier); - DTEST_LOG << "result: " << result << std::endl; - EXPECT_NE(result, ERR_INVALID_DATA); -} -} -} \ No newline at end of file diff --git a/old/services/core/test/unittest/profile_storage_test.cpp b/old/services/core/test/unittest/profile_storage_test.cpp deleted file mode 100644 index f6122afc..00000000 --- a/old/services/core/test/unittest/profile_storage_test.cpp +++ /dev/null @@ -1,1503 +0,0 @@ -/* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. - * 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. - */ - -#include "gtest/gtest.h" - -#include "utils.h" - -#include -#include -#include - -#define private public -#define protected public -#include "device_profile_errors.h" -#include "device_profile_log.h" -#include "device_profile_storage.h" -#include "device_profile_storage_manager.h" -#include "distributed_device_profile_client.h" -#include "hisysevent.h" -#include "nlohmann/json.hpp" -#include "online_sync_table.h" -#include "sync_coordinator.h" -#include "syscap_info_collector.h" -#include "syscap_interface.h" -#undef private -#undef protected - -namespace OHOS { -namespace DeviceProfile { -using namespace OHOS::HiviewDFX; -using namespace OHOS::DistributedKv; -namespace { - const std::string TAG = "SyscapInfoCollector"; - const std::string SERVICE_ID = "test"; - const std::string SERVICE_TYPE = "test"; - const std::string CHARACTER_PRIVATE_SYSCAP = "privatesyscap"; - const std::string CHARACTER_OS_SYSCAP = "ossyscap"; - const std::string FAULT_CODE_KEY = "FAULT_CODE"; - const std::string DOMAIN_NAME = std::string(HiSysEvent::Domain::DEVICE_PROFILE); - const std::string APP_ID = "distributed_device_profile_service"; - const std::string STORE_ID = "online_sync_storage_test"; - static std::shared_ptr deviceProfileStorage = nullptr; - static std::shared_ptr kvStorePtr_ = nullptr; -} -using namespace testing; -using namespace testing::ext; - -class ProfileStorageTest : public testing::Test { -public: - ProfileStorageTest(); - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp(); - void TearDown(); -}; - -ProfileStorageTest::ProfileStorageTest() -{ - DTEST_LOG << "constructor" << std::endl; -} - -void ProfileStorageTest::SetUpTestCase() -{ - DTEST_LOG << "SetUpTestCase" << std::endl; - std::string baseDir = "/data/service/el1/public/database/test"; - mkdir(baseDir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); - Options options = { - .createIfMissing = true, - .encrypt = false, - .autoSync = false, - .securityLevel = DistributedKv::SecurityLevel::S1, - .kvStoreType = KvStoreType::SINGLE_VERSION, - .area = 1, - .baseDir = baseDir - }; - // clean the IMMEDIATE_SYNC_ON_CHANGE - SyncPolicy syncPolicy { - .type = PolicyType::IMMEDIATE_SYNC_ON_ONLINE - }; - options.policies.emplace_back(syncPolicy); - deviceProfileStorage = std::make_shared(APP_ID, STORE_ID); - if (deviceProfileStorage != nullptr) { - deviceProfileStorage->SetOptions(options); - } -} - -void ProfileStorageTest::TearDownTestCase() -{ - DTEST_LOG << "TearDownTestCase" << std::endl; -} - -void ProfileStorageTest::SetUp() -{ - DTEST_LOG << "SetUp" << std::endl; -} - -void ProfileStorageTest::TearDown() -{ - DTEST_LOG << "TearDown" << std::endl; -} - -class StorageProfileEventCallback : public IProfileEventCallback { -}; - -class ProfileSyncHandler : public DistributedKv::KvStoreSyncCallback { -public: - void SyncCompleted(const std::map& results) override - { - } -}; - -/** - * @tc.name: TryGetKvStore_001 - * @tc.desc: put device profile with empty service id - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileStorageTest, TryGetKvStore_001, TestSize.Level3) -{ - ServiceCharacteristicProfile profile; - DeviceProfileStorageManager::GetInstance().onlineSyncTbl_ = std::make_shared(); - /** - * @tc.steps: step1. add RestoreServiceItemLocked - */ - DeviceProfileStorageManager::GetInstance().RestoreServiceItemLocked(""); - - bool result = DeviceProfileStorageManager::GetInstance().onlineSyncTbl_->TryGetKvStore(); - EXPECT_EQ(false, result); -} - -/** - * @tc.name: PutDeviceProfile_001 - * @tc.desc: put device profile with empty service id - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileStorageTest, PutDeviceProfile_001, TestSize.Level3) -{ - ServiceCharacteristicProfile profile; - /** - * @tc.steps: step1. add SetServiceType_001 - */ - DeviceProfileStorageManager::GetInstance().SetServiceType("", "", profile); - - int32_t result = DeviceProfileStorageManager::GetInstance().PutDeviceProfile(profile); - EXPECT_EQ(ERR_DP_INIT_DB_FAILED, result); -} - -/** - * @tc.name: GetDeviceProfile_001 - * @tc.desc: get device profile with empty service id - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileStorageTest, GetDeviceProfile_001, TestSize.Level3) -{ - ServiceCharacteristicProfile profile; - /** - * @tc.steps: step1. add SetServiceType_002 - */ - std::string udid = "1111test1111"; - DeviceProfileStorageManager::GetInstance().SetServiceType(udid, "", profile); - - int32_t result = DeviceProfileStorageManager::GetInstance().GetDeviceProfile("", "", profile); - EXPECT_EQ(ERR_DP_INIT_DB_FAILED, result); -} - -/** - * @tc.name: DeleteDeviceProfile_001 - * @tc.desc: delete device profile with empty service id - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileStorageTest, DeleteDeviceProfile_001, TestSize.Level3) -{ - /** - * @tc.steps: step1. add SetServiceType_003 - */ - ServiceCharacteristicProfile profile; - std::string serviceId = "2222test2222"; - DeviceProfileStorageManager::GetInstance().SetServiceType("", serviceId, profile); - - int32_t result = DeviceProfileStorageManager::GetInstance().DeleteDeviceProfile(""); - EXPECT_EQ(ERR_DP_INIT_DB_FAILED, result); -} - -/** - * @tc.name: RemoveUnBoundDeviceProfile_001 - * @tc.desc: delete device profile with empty service id - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileStorageTest, RemoveUnBoundDeviceProfile_001, TestSize.Level3) -{ - /** - * @tc.steps: step1. add SetServiceType_004 - */ - ServiceCharacteristicProfile profile; - std::string udid = "1111test1111"; - std::string serviceId = "2222test2222"; - DeviceProfileStorageManager::GetInstance().SetServiceType(udid, serviceId, profile); - - int32_t result = DeviceProfileStorageManager::GetInstance().RemoveUnBoundDeviceProfile(""); - EXPECT_EQ(ERR_DP_INIT_DB_FAILED, result); -} - -/** - * @tc.name: SyncDeviceProfile_001 - * @tc.desc: sync device profile - * @tc.type: FUNC - * @tc.require: I4NY1U - */ -HWTEST_F(ProfileStorageTest, SyncDeviceProfile_001, TestSize.Level3) -{ - wptr remote; - DistributedDeviceProfileClient::DeviceProfileDeathRecipient obj; - obj.OnRemoteDied(remote); - auto syncCb = std::make_shared(); - SyncOptions syncOptions; - sptr notifier = - sptr(new ProfileEventNotifierStub(syncCb)); - int result = DeviceProfileStorageManager::GetInstance().SyncDeviceProfile(syncOptions, notifier); - EXPECT_EQ(ERR_DP_INIT_DB_FAILED, result); -} - -/** - * @tc.name: PutDeviceProfile_001 - * @tc.desc: put device profile with empty service id - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileStorageTest, WaitKvDataService_001, TestSize.Level3) -{ - ServiceCharacteristicProfile profile; - bool result = DeviceProfileStorageManager::GetInstance().WaitKvDataService(); - EXPECT_EQ(true, result); -} - -/** - * @tc.name: RemoveUnBoundDeviceProfile_002 - * @tc.desc: delete device profile with empty service id - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileStorageTest, RemoveUnBoundDeviceProfile_002, TestSize.Level3) -{ - DeviceProfileStorageManager::GetInstance().onlineSyncTbl_->initStatus_ = StorageInitStatus::UNINITED; - int32_t result = DeviceProfileStorageManager::GetInstance().RemoveUnBoundDeviceProfile(""); - EXPECT_EQ(ERR_DP_NOT_INIT_DB, result); -} - -/** - * @tc.name: PutDeviceProfile_002 - * @tc.desc: put device profile with empty service id - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileStorageTest, PutDeviceProfile_002, TestSize.Level3) -{ - ServiceCharacteristicProfile profile; - profile.SetServiceId("test"); - profile.SetServiceType("test"); - nlohmann::json j; - j["testVersion"] = "3.0.0"; - j["testApiLevel"] = 8; - profile.SetCharacteristicProfileJson(j.dump()); - int32_t result = DeviceProfileStorageManager::GetInstance().PutDeviceProfile(profile); - EXPECT_EQ(0, result); -} - -/** - * @tc.name: PutDeviceProfile_003 - * @tc.desc: put device profile with empty service id - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileStorageTest, PutDeviceProfile_003, TestSize.Level3) -{ - ServiceCharacteristicProfile profile; - profile.SetServiceId(""); - profile.SetServiceType("test"); - nlohmann::json j; - j["testVersion"] = "3.0.0"; - j["testApiLevel"] = 8; - profile.SetCharacteristicProfileJson(j.dump()); - int32_t result = DeviceProfileStorageManager::GetInstance().PutDeviceProfile(profile); - EXPECT_EQ(0, result); -} - -/** - * @tc.name: PutDeviceProfile_004 - * @tc.desc: put device profile with empty service id - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileStorageTest, PutDeviceProfile_004, TestSize.Level3) -{ - ServiceCharacteristicProfile profile; - profile.SetServiceId("test"); - profile.SetServiceType(""); - nlohmann::json j; - j["testVersion"] = "3.0.0"; - j["testApiLevel"] = 8; - profile.SetCharacteristicProfileJson(j.dump()); - int32_t result = DeviceProfileStorageManager::GetInstance().PutDeviceProfile(profile); - EXPECT_EQ(0, result); -} - -/** - * @tc.name: PutDeviceProfile_005 - * @tc.desc: get device profile - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileStorageTest, PutDeviceProfile_005, TestSize.Level2) -{ - std::shared_ptr onlineSyncTbl_ = std::make_shared(); - int32_t res = onlineSyncTbl_->PutDeviceProfile("test", "test"); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, res); -} - -/** - * @tc.name: GetDeviceProfile_002 - * @tc.desc: get device profile with syscap - * @tc.type: FUNC - * @tc.require: I59PZ3 - */ -HWTEST_F(ProfileStorageTest, GetDeviceProfile_002, TestSize.Level3) -{ - ServiceCharacteristicProfile profile; - profile.SetServiceId(SERVICE_ID); - profile.SetServiceType(SERVICE_TYPE); - int32_t result = DeviceProfileStorageManager::GetInstance().GetDeviceProfile("", SERVICE_ID, profile); - EXPECT_EQ(0, result); - std::string jsonData = profile.GetCharacteristicProfileJson(); - DTEST_LOG << "jsonData:" << jsonData << std::endl; -} - -/** - * @tc.name: GetDeviceProfile_003 - * @tc.desc: get device profile with syscap - * @tc.type: FUNC - * @tc.require: I59PZ3 - */ -HWTEST_F(ProfileStorageTest, GetDeviceProfile_003, TestSize.Level3) -{ - ServiceCharacteristicProfile profile; - profile.SetServiceId(SERVICE_ID); - profile.SetServiceType(SERVICE_TYPE); - int32_t result = DeviceProfileStorageManager::GetInstance().GetDeviceProfile("test", "", profile); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, result); -} - -/** - * @tc.name: GetDeviceProfile_004 - * @tc.desc: get device profile with syscap - * @tc.type: FUNC - * @tc.require: I59PZ3 - */ -HWTEST_F(ProfileStorageTest, GetDeviceProfile_004, TestSize.Level3) -{ - ServiceCharacteristicProfile profile; - profile.SetServiceId(SERVICE_ID); - profile.SetServiceType(SERVICE_TYPE); - int32_t result = DeviceProfileStorageManager::GetInstance().GetDeviceProfile("test", SERVICE_ID, profile); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, result); -} - -/** - * @tc.name: DeleteDeviceProfile_002 - * @tc.desc: delete an empty profile - * @tc.type: FUNC - * @tc.require: I4NY21 - */ -HWTEST_F(ProfileStorageTest, DeleteDeviceProfile_002, TestSize.Level3) -{ - int32_t result = DeviceProfileStorageManager::GetInstance().DeleteDeviceProfile("test"); - EXPECT_EQ(0, result); -} - -/** - * @tc.name: DeleteDeviceProfile_003 - * @tc.desc: delete device profile with empty service id after init - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileStorageTest, DeleteDeviceProfile_003, TestSize.Level3) -{ - int32_t result = DeviceProfileStorageManager::GetInstance().DeleteDeviceProfile(""); - EXPECT_EQ(0, result); -} - -/** - * @tc.name: DeleteDeviceProfile_004 - * @tc.desc: put device profile batch - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileStorageTest, DeleteDeviceProfile_004, TestSize.Level2) -{ - std::shared_ptr onlineSyncTbl_ = std::make_shared(); - int32_t res = onlineSyncTbl_->DeleteDeviceProfile("test"); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, res); -} - -/** - * @tc.name: RemoveDeviceData_001 - * @tc.desc: put device profile batch - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileStorageTest, RemoveDeviceData_001, TestSize.Level2) -{ - std::shared_ptr onlineSyncTbl_ = std::make_shared(); - int32_t res = onlineSyncTbl_->RemoveDeviceData("networkid11111"); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, res); -} - -/** - * @tc.name: SubscribeKvStore_002 - * @tc.desc: SubscribeKvStore - * @tc.type: FUNC - * @tc.require: I4NY21 - */ -HWTEST_F(ProfileStorageTest, SubscribeKvStore_002, TestSize.Level3) -{ - int32_t result = DeviceProfileStorageManager::GetInstance().SubscribeKvStore(nullptr); - EXPECT_EQ(0, result); -} - -/** - * @tc.name: UnSubscribeKvStore_001 - * @tc.desc: UnSubscribeKvStore - * @tc.type: FUNC - * @tc.require: I4NY21 - */ -HWTEST_F(ProfileStorageTest, UnSubscribeKvStore_001, TestSize.Level3) -{ - int32_t result = DeviceProfileStorageManager::GetInstance().UnSubscribeKvStore(nullptr); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, result); -} - -/** - * @tc.name: RegisterSyncCallback_002 - * @tc.desc: RegisterSyncCallback - * @tc.type: FUNC - * @tc.require: I4NY21 - */ -HWTEST_F(ProfileStorageTest, RegisterSyncCallback_002, TestSize.Level3) -{ - int32_t result = DeviceProfileStorageManager::GetInstance().RegisterSyncCallback(nullptr); - EXPECT_EQ(0, result); -} - -/** - * @tc.name: UnRegisterSyncCallback_001 - * @tc.desc: UnRegisterSyncCallback - * @tc.type: FUNC - * @tc.require: I4NY21 - */ -HWTEST_F(ProfileStorageTest, UnRegisterSyncCallback_001, TestSize.Level3) -{ - int32_t result = DeviceProfileStorageManager::GetInstance().UnRegisterSyncCallback(); - EXPECT_EQ(0, result); -} - -/** - * @tc.name: SyncDeviceProfile_002 - * @tc.desc: sync device profile - * @tc.type: FUNC - * @tc.require: I5QPGN - */ -HWTEST_F(ProfileStorageTest, SyncDeviceProfile_002, TestSize.Level3) -{ - wptr remote; - DistributedDeviceProfileClient::DeviceProfileDeathRecipient obj; - obj.OnRemoteDied(remote); - auto syncCb = std::make_shared(); - SyncOptions syncOptions; - sptr notifier = - sptr(new ProfileEventNotifierStub(syncCb)); - int result = DeviceProfileStorageManager::GetInstance().SyncDeviceProfile(syncOptions, notifier); - EXPECT_EQ(ERR_DP_SUBSCRIBE_FAILED, result); -} - -/** - * @tc.name: SyncDeviceProfile_003 - * @tc.desc: sync device profile - * @tc.type: FUNC - * @tc.require: I5QPGN - */ -HWTEST_F(ProfileStorageTest, SyncDeviceProfile_003, TestSize.Level3) -{ - wptr remote; - DistributedDeviceProfileClient::DeviceProfileDeathRecipient obj; - obj.OnRemoteDied(remote); - auto syncCb = std::make_shared(); - syncCb = nullptr; - SyncOptions syncOptions; - sptr notifier = - sptr(new ProfileEventNotifierStub(syncCb)); - notifier = nullptr; - int result = DeviceProfileStorageManager::GetInstance().SyncDeviceProfile(syncOptions, notifier); - EXPECT_EQ(ERR_DP_SUBSCRIBE_FAILED, result); -} - -/** - * @tc.name: RemoveUnBoundDeviceProfile_003 - * @tc.desc: remove unBound device profile - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileStorageTest, RemoveUnBoundDeviceProfile_003, TestSize.Level3) -{ - DeviceProfileStorageManager::GetInstance().onlineSyncTbl_->initStatus_ = StorageInitStatus::INIT_SUCCEED; - int32_t result = DeviceProfileStorageManager::GetInstance().RemoveUnBoundDeviceProfile(""); - EXPECT_EQ(ERR_DP_GET_NETWORKID_FAILED, result); -} - -/** - * @tc.name: RemoveUnBoundDeviceProfile_004 - * @tc.desc: remove unBound device profile - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileStorageTest, RemoveUnBoundDeviceProfile_004, TestSize.Level3) -{ - std::string event = "EVENT_TEST"; - std::string key = "EVENT_KEY"; - int32_t result = 0; - std::string strResult = "returnresult"; - DeviceProfileStorageManager::GetInstance().DumpLocalProfile(strResult); - DeviceProfileStorageManager::GetInstance().ReportFaultEvent(event, key, result); - DeviceProfileStorageManager::GetInstance().ReportBehaviorEvent(event); - result = DeviceProfileStorageManager::GetInstance().RemoveUnBoundDeviceProfile("test"); - EXPECT_EQ(ERR_DP_GET_NETWORKID_FAILED, result); -} - -/** - * @tc.name: CheckSyncOption_001 - * @tc.desc: report fault event - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileStorageTest, CheckSyncOption_001, TestSize.Level3) -{ - SyncOptions syncOptions; - std::string deviceId = "1111test2222"; - syncOptions.AddDevice(deviceId); - DeviceProfileStorageManager::GetInstance().NotifySyncCompleted(); - auto syncCb = std::make_shared(); - sptr notifier = - sptr(new ProfileEventNotifierStub(syncCb)); - DeviceProfileStorageManager::GetInstance().NotifySubscriberDied(notifier); - notifier = nullptr; - DeviceProfileStorageManager::GetInstance().NotifySubscriberDied(notifier); - bool res = DeviceProfileStorageManager::GetInstance().CheckSyncOption(syncOptions); - EXPECT_EQ(false, res); -} - -/** - * @tc.name: SubscribeKvStore_003 - * @tc.desc: subscribe kvstore - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileStorageTest, SubscribeKvStore_003, TestSize.Level2) -{ - std::shared_ptr onlineSyncTbl_ = std::make_shared(); - std::shared_ptr kvStoreObserver_ = nullptr; - int32_t res = onlineSyncTbl_->SubscribeKvStore(kvStoreObserver_); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, res); -} - -/** - * @tc.name: GetDeviceProfile_005 - * @tc.desc: get device profile - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileStorageTest, GetDeviceProfile_005, TestSize.Level2) -{ - std::shared_ptr onlineSyncTbl_ = std::make_shared(); - std::string key = ""; - std::string value = ""; - int32_t res = onlineSyncTbl_->GetDeviceProfile(key, value); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, res); -} - -/** - * @tc.name: GetDeviceProfile_006 - * @tc.desc: get device profile - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileStorageTest, GetDeviceProfile_006, TestSize.Level2) -{ - std::shared_ptr onlineSyncTbl_ = std::make_shared(); - std::string key = ""; - std::string udid = ""; - std::string value = ""; - int32_t res = onlineSyncTbl_->GetDeviceProfile(udid, key, value); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, res); -} - -/** - * @tc.name: GetDeviceProfile_006 - * @tc.desc: get device profile - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileStorageTest, GetDeviceProfile_007, TestSize.Level2) -{ - std::shared_ptr onlineSyncTbl_ = std::make_shared(); - std::string key = "11111"; - std::string udid = ""; - std::string value = ""; - int32_t res = onlineSyncTbl_->GetDeviceProfile(udid, key, value); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, res); -} - -/** - * @tc.name: GetDeviceProfile_006 - * @tc.desc: get device profile - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileStorageTest, GetDeviceProfile_008, TestSize.Level2) -{ - std::shared_ptr onlineSyncTbl_ = std::make_shared(); - std::string key = ""; - std::string udid = "111111"; - std::string value = ""; - int32_t res = onlineSyncTbl_->GetDeviceProfile(udid, key, value); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, res); -} - -/** - * @tc.name: GetDeviceProfile_006 - * @tc.desc: get device profile - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileStorageTest, GetDeviceProfile_009, TestSize.Level2) -{ - std::shared_ptr onlineSyncTbl_ = std::make_shared(); - std::string key = "11111"; - std::string udid = "11111"; - std::string value = ""; - int32_t res = onlineSyncTbl_->GetDeviceProfile(udid, key, value); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, res); -} - -/** - * @tc.name: SubscribeKvStore_004 - * @tc.desc: subscribe kvstore - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileStorageTest, SubscribeKvStore_004, TestSize.Level2) -{ - std::shared_ptr onlineSyncTbl_ = std::make_shared(); - std::shared_ptr kvStoreObserver_ = - std::make_shared(); - int32_t res = onlineSyncTbl_->SubscribeKvStore(kvStoreObserver_); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, res); -} - -/** - * @tc.name: UnSubscribeKvStore_002 - * @tc.desc: subscribe kvstore - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileStorageTest, UnSubscribeKvStore_002, TestSize.Level2) -{ - std::shared_ptr onlineSyncTbl_ = std::make_shared(); - std::shared_ptr kvStoreObserver_ = nullptr; - int32_t res = onlineSyncTbl_->UnSubscribeKvStore(kvStoreObserver_); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, res); -} - -/** - * @tc.name: UnSubscribeKvStore_003 - * @tc.desc: subscribe kvstore - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileStorageTest, UnSubscribeKvStore_003, TestSize.Level2) -{ - std::shared_ptr onlineSyncTbl_ = std::make_shared(); - std::shared_ptr kvStoreObserver_ = - std::make_shared(); - int32_t res = onlineSyncTbl_->UnSubscribeKvStore(kvStoreObserver_); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, res); -} - -/** - * @tc.name: RegisterSyncCallback_003 - * @tc.desc: subscribe kvstore - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileStorageTest, RegisterSyncCallback_003, TestSize.Level2) -{ - std::shared_ptr onlineSyncTbl_ = std::make_shared(); - std::shared_ptr syncCallback = nullptr; - int32_t res = onlineSyncTbl_->RegisterSyncCallback(syncCallback); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, res); -} - -/** - * @tc.name: RegisterSyncCallback_004 - * @tc.desc: subscribe kvstore - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileStorageTest, RegisterSyncCallback_004, TestSize.Level2) -{ - std::shared_ptr onlineSyncTbl_ = std::make_shared(); - std::shared_ptr syncCallback = - std::make_shared(); - int32_t res = onlineSyncTbl_->RegisterSyncCallback(syncCallback); - EXPECT_EQ(0, res); -} - -/** - * @tc.name: UnRegisterSyncCallback_002 - * @tc.desc: subscribe kvstore - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileStorageTest, UnRegisterSyncCallback_002, TestSize.Level2) -{ - std::shared_ptr onlineSyncTbl_ = std::make_shared(); - int32_t res = onlineSyncTbl_->UnRegisterSyncCallback(); - EXPECT_EQ(0, res); -} - -/** - * @tc.name: GetKvStore_001 - * @tc.desc: get kvstore - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileStorageTest, GetKvStore_001, TestSize.Level2) -{ - std::shared_ptr onlineSyncTbl_ = std::make_shared(); - onlineSyncTbl_->DeleteKvStore(); - int32_t res = onlineSyncTbl_->GetKvStore(); - EXPECT_EQ(27459585, res); -} - -/** - * @tc.name: PutDeviceProfile_006 - * @tc.desc: get device profile - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileStorageTest, PutDeviceProfile_006, TestSize.Level2) -{ - std::shared_ptr onlineSyncTbl_ = std::make_shared(); - onlineSyncTbl_->kvStorePtr_ = nullptr; - int32_t res = onlineSyncTbl_->PutDeviceProfile("test", "test"); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, res); -} - -/** - * @tc.name: SubscribeKvStore_005 - * @tc.desc: subscribe kvstore - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileStorageTest, SubscribeKvStore_005, TestSize.Level2) -{ - std::shared_ptr onlineSyncTbl_ = std::make_shared(); - onlineSyncTbl_->kvStorePtr_ = nullptr; - std::shared_ptr kvStoreObserver_ = - std::make_shared(); - int32_t res = onlineSyncTbl_->SubscribeKvStore(kvStoreObserver_); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, res); -} - -/** - * @tc.name: SubscribeKvStore_006 - * @tc.desc: subscribe kvstore - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileStorageTest, SubscribeKvStore_006, TestSize.Level2) -{ - std::shared_ptr onlineSyncTbl_ = std::make_shared(); - onlineSyncTbl_->kvStorePtr_ = nullptr; - std::shared_ptr kvStoreObserver_ = nullptr; - int32_t res = onlineSyncTbl_->SubscribeKvStore(kvStoreObserver_); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, res); -} - -/** - * @tc.name: UnSubscribeKvStore_004 - * @tc.desc: subscribe kvstore - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileStorageTest, UnSubscribeKvStore_004, TestSize.Level2) -{ - std::shared_ptr onlineSyncTbl_ = std::make_shared(); - onlineSyncTbl_->kvStorePtr_ = nullptr; - std::shared_ptr kvStoreObserver_ = - std::make_shared(); - int32_t res = onlineSyncTbl_->UnSubscribeKvStore(kvStoreObserver_); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, res); -} - -/** - * @tc.name: UnSubscribeKvStore_005 - * @tc.desc: subscribe kvstore - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileStorageTest, UnSubscribeKvStore_005, TestSize.Level2) -{ - std::shared_ptr onlineSyncTbl_ = std::make_shared(); - onlineSyncTbl_->kvStorePtr_ = nullptr; - std::shared_ptr kvStoreObserver_ = nullptr; - int32_t res = onlineSyncTbl_->UnSubscribeKvStore(kvStoreObserver_); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, res); -} - -/** - * @tc.name: RegisterSyncCallback_005 - * @tc.desc: subscribe kvstore - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileStorageTest, RegisterSyncCallback_005, TestSize.Level2) -{ - std::shared_ptr onlineSyncTbl_ = std::make_shared(); - onlineSyncTbl_->kvStorePtr_ = nullptr; - std::shared_ptr syncCallback = - std::make_shared(); - int32_t res = onlineSyncTbl_->RegisterSyncCallback(syncCallback); - EXPECT_EQ(0, res); -} - -/** - * @tc.name: RegisterSyncCallback_006 - * @tc.desc: subscribe kvstore - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileStorageTest, RegisterSyncCallback_006, TestSize.Level2) -{ - std::shared_ptr onlineSyncTbl_ = std::make_shared(); - onlineSyncTbl_->kvStorePtr_ = nullptr; - std::shared_ptr syncCallback = nullptr; - int32_t res = onlineSyncTbl_->RegisterSyncCallback(syncCallback); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, res); -} - -/** - * @tc.name: UnRegisterSyncCallback_003 - * @tc.desc: subscribe kvstore - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileStorageTest, UnRegisterSyncCallback_003, TestSize.Level2) -{ - std::shared_ptr onlineSyncTbl_ = std::make_shared(); - onlineSyncTbl_->kvStorePtr_ = nullptr; - int32_t res = onlineSyncTbl_->UnRegisterSyncCallback(); - EXPECT_EQ(0, res); -} - -/** - * @tc.name: PutDeviceProfileBatch_001 - * @tc.desc: put device profile batch - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileStorageTest, PutDeviceProfileBatch_001, TestSize.Level2) -{ - std::shared_ptr onlineSyncTbl_ = std::make_shared(); - onlineSyncTbl_->kvStorePtr_ = nullptr; - vector keys = {"test"}; - vector values = {"test"}; - int32_t res = onlineSyncTbl_->PutDeviceProfileBatch(keys, values); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, res); -} - -/** - * @tc.name: DeleteDeviceProfile_005 - * @tc.desc: put device profile batch - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileStorageTest, DeleteDeviceProfile_005, TestSize.Level2) -{ - std::shared_ptr onlineSyncTbl_ = std::make_shared(); - onlineSyncTbl_->kvStorePtr_ = nullptr; - int32_t res = onlineSyncTbl_->DeleteDeviceProfile("test"); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, res); -} - -/** - * @tc.name: RemoveDeviceData_002 - * @tc.desc: remove device data - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileStorageTest, RemoveDeviceData_002, TestSize.Level2) -{ - std::shared_ptr onlineSyncTbl_ = std::make_shared(); - onlineSyncTbl_->kvStorePtr_ = nullptr; - int32_t res = onlineSyncTbl_->RemoveDeviceData("network1111111"); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, res); -} - -/** - * @tc.name: CheckTrustGroup_001 - * @tc.desc: check trust group - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileStorageTest, CheckTrustGroup_001, TestSize.Level2) -{ - std::shared_ptr onlineSyncTbl_ = std::make_shared(); - std::vector deviceIdList = {}; - bool res = onlineSyncTbl_->CheckTrustGroup(deviceIdList); - EXPECT_EQ(false, res); -} - -/** - * @tc.name: CheckTrustGroup_002 - * @tc.desc: check trust group - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileStorageTest, CheckTrustGroup_002, TestSize.Level2) -{ - std::shared_ptr onlineSyncTbl_ = std::make_shared(); - std::vector deviceIdList = {"did1111111"}; - bool res = onlineSyncTbl_->CheckTrustGroup(deviceIdList); - EXPECT_EQ(false, res); -} - -/** - * @tc.name: SubscribeKvStore_007 - * @tc.desc: subscribe kvstore - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileStorageTest, SubscribeKvStore_007, TestSize.Level2) -{ - DeviceProfileStorageManager::GetInstance().onlineSyncTbl_->initStatus_ = StorageInitStatus::INIT_SUCCEED; - std::shared_ptr kvStoreObserver_ = nullptr; - int32_t res = DeviceProfileStorageManager::GetInstance().SubscribeKvStore(kvStoreObserver_); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, res); -} - -/** - * @tc.name: UnSubscribeKvStore_006 - * @tc.desc: subscribe kvstore - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileStorageTest, UnSubscribeKvStore_006, TestSize.Level2) -{ - DeviceProfileStorageManager::GetInstance().onlineSyncTbl_->initStatus_ = StorageInitStatus::INIT_SUCCEED; - std::shared_ptr kvStoreObserver_ = nullptr; - DeviceProfileStorageManager::GetInstance().profileItems_.clear(); - DeviceProfileStorageManager::GetInstance().FlushProfileItems(); - int32_t res = DeviceProfileStorageManager::GetInstance().UnSubscribeKvStore(kvStoreObserver_); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, res); -} - -/** - * @tc.name: DeleteDeviceProfile_006 - * @tc.desc: delete device profile with empty service id after init - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileStorageTest, DeleteDeviceProfile_006, TestSize.Level3) -{ - DeviceProfileStorageManager::GetInstance().onlineSyncTbl_->initStatus_ = StorageInitStatus::INIT_SUCCEED; - DeviceProfileStorageManager::GetInstance().servicesJson_.clear(); - int32_t result = DeviceProfileStorageManager::GetInstance().DeleteDeviceProfile("test"); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, result); -} - -/** - * @tc.name: DeleteDeviceProfile_007 - * @tc.desc: delete device profile with empty service id after init - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileStorageTest, DeleteDeviceProfile_007, TestSize.Level3) -{ - DeviceProfileStorageManager::GetInstance().onlineSyncTbl_->initStatus_ = StorageInitStatus::INIT_SUCCEED; - nlohmann::json j; - j[SERVICE_TYPE] = "567"; - DeviceProfileStorageManager::GetInstance().servicesJson_["test"] = j; - int32_t result = DeviceProfileStorageManager::GetInstance().DeleteDeviceProfile("test"); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, result); -} - -/** - * @tc.name: PutDeviceProfile_007 - * @tc.desc: put device profile with empty service id - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileStorageTest, PutDeviceProfile_007, TestSize.Level3) -{ - DeviceProfileStorageManager::GetInstance().onlineSyncTbl_->initStatus_ = StorageInitStatus::INIT_SUCCEED; - ServiceCharacteristicProfile profile; - profile.SetServiceId(""); - profile.SetServiceType("test"); - nlohmann::json j; - j["testVersion"] = "3.0.0"; - j["testApiLevel"] = 8; - profile.SetCharacteristicProfileJson(j.dump()); - int32_t result = DeviceProfileStorageManager::GetInstance().PutDeviceProfile(profile); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, result); -} - -/** - * @tc.name: RegisterSyncCallback_007 - * @tc.desc: put device profile with empty service id - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileStorageTest, RegisterSyncCallback_007, TestSize.Level3) -{ - ServiceCharacteristicProfile profile; - std::shared_ptr syncCallback = - std::make_shared(); - std::shared_ptr onlineSyncTblTest_ = std::make_shared(); - std::map results; - onlineSyncTblTest_->syncCallback_ = nullptr; - onlineSyncTblTest_->NotifySyncCompleted(results); - onlineSyncTblTest_->syncCallback_ = syncCallback; - onlineSyncTblTest_->NotifySyncCompleted(results); - SyncCoordinator::GetInstance().isOnlineTrigger_ = true; - onlineSyncTblTest_->SyncCompleted(results); - SyncCoordinator::GetInstance().isOnlineTrigger_ = false; - onlineSyncTblTest_->SyncCompleted(results); - bool result = onlineSyncTblTest_->RegisterSyncCallback(syncCallback); - EXPECT_EQ(false, result); -} - -/** - * @tc.name: AcquireSync_001 - * @tc.desc: put device profile with empty service id - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileStorageTest, AcquireSync_001, TestSize.Level3) -{ - SyncCoordinator::GetInstance().isOnSync_ = true; - bool result = SyncCoordinator::GetInstance().AcquireSync(); - EXPECT_EQ(false, result); -} - -/** - * @tc.name: UnRegisterSyncCallback_004 - * @tc.desc: put device profile with empty service id - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileStorageTest, UnRegisterSyncCallback_004, TestSize.Level3) -{ - std::shared_ptr onlineSyncTbl_ = std::make_shared(APP_ID, STORE_ID); - int32_t result = onlineSyncTbl_->UnRegisterSyncCallback(); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, result); -} - -/** - * @tc.name: UnRegisterSyncCallback_005 - * @tc.desc: put device profile with empty service id - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileStorageTest, UnRegisterSyncCallback_005, TestSize.Level3) -{ - deviceProfileStorage->Init(); - if (deviceProfileStorage != nullptr) { - int32_t result = deviceProfileStorage->UnRegisterSyncCallback(); - EXPECT_EQ(0, result); - } -} - -/** - * @tc.name: PutDeviceProfile_008 - * @tc.desc: put device profile with empty service id - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileStorageTest, PutDeviceProfile_008, TestSize.Level3) -{ - deviceProfileStorage->Init(); - ServiceCharacteristicProfile profile; - nlohmann::json j; - j["testVersion"] = "3.0.0"; - j["testApiLevel"] = 8; - profile.SetCharacteristicProfileJson(j.dump()); - std::vector keys; - std::vector values; - keys.emplace_back(DeviceProfileStorageManager::GetInstance().GenerateKey("test123udid", "test", KeyType::SERVICE)); - values.emplace_back(profile.GetCharacteristicProfileJson()); - if (deviceProfileStorage->kvStorePtr_ == nullptr) { - deviceProfileStorage->kvStorePtr_ = kvStorePtr_; - } - if (deviceProfileStorage != nullptr) { - int32_t result = deviceProfileStorage->PutDeviceProfile(keys[0], values[0]); - EXPECT_EQ(0, result); - } -} - -/** - * @tc.name: PutDeviceProfileBatch_002 - * @tc.desc: put device profile with empty service id - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileStorageTest, PutDeviceProfileBatch_002, TestSize.Level3) -{ - deviceProfileStorage->Init(); - std::vector keys; - std::vector values; - keys.emplace_back("key"); - values.emplace_back("value1"); - values.emplace_back("value2"); - if (deviceProfileStorage != nullptr) { - int32_t result = deviceProfileStorage->PutDeviceProfileBatch(keys, values); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, result); - } -} - -/** - * @tc.name: DeleteDeviceProfile_008 - * @tc.desc: put device profile with empty service id - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileStorageTest, DeleteDeviceProfile_008, TestSize.Level3) -{ - deviceProfileStorage->Init(); - std::string key = - DeviceProfileStorageManager::GetInstance().GenerateKey("test123udid", "test", KeyType::SERVICE); - if (deviceProfileStorage != nullptr) { - int32_t result = deviceProfileStorage->DeleteDeviceProfile(key); - EXPECT_EQ(0, result); - } -} - -/** - * @tc.name: SubscribeKvStore_008 - * @tc.desc: put device profile with empty service id - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileStorageTest, SubscribeKvStore_008, TestSize.Level3) -{ - std::shared_ptr onlineSyncTbl_ = std::make_shared(APP_ID, STORE_ID); - int32_t res = onlineSyncTbl_->SubscribeKvStore(nullptr); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, res); -} - -/** - * @tc.name: SubscribeKvStore_009 - * @tc.desc: put device profile with empty service id - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileStorageTest, SubscribeKvStore_009, TestSize.Level3) -{ - std::shared_ptr onlineSyncTbl_ = std::make_shared(APP_ID, STORE_ID); - std::shared_ptr kvStoreObserver_ = - std::make_shared(); - int32_t res = onlineSyncTbl_->SubscribeKvStore(kvStoreObserver_); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, res); -} - -/** - * @tc.name: SubscribeKvStore_0010 - * @tc.desc: put device profile with empty service id - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileStorageTest, SubscribeKvStore_0010, TestSize.Level3) -{ - deviceProfileStorage->Init(); - std::shared_ptr kvStoreObserver_ = - std::make_shared(); - int32_t res = deviceProfileStorage->SubscribeKvStore(nullptr); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, res); -} - -/** - * @tc.name: SubscribeKvStore_0011 - * @tc.desc: put device profile with empty service id - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileStorageTest, SubscribeKvStore_0011, TestSize.Level3) -{ - deviceProfileStorage->Init(); - std::shared_ptr kvStoreObserver_ = - std::make_shared(); - int32_t res = deviceProfileStorage->SubscribeKvStore(kvStoreObserver_); - EXPECT_EQ(0, res); -} - -/** - * @tc.name: UnSubscribeKvStore_007 - * @tc.desc: put device profile with empty service id - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileStorageTest, UnSubscribeKvStore_007, TestSize.Level3) -{ - std::shared_ptr onlineSyncTbl_ = std::make_shared(APP_ID, STORE_ID); - int32_t res = onlineSyncTbl_->UnSubscribeKvStore(nullptr); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, res); -} - -/** - * @tc.name: UnSubscribeKvStore_008 - * @tc.desc: put device profile with empty service id - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileStorageTest, UnSubscribeKvStore_008, TestSize.Level3) -{ - std::shared_ptr onlineSyncTbl_ = std::make_shared(APP_ID, STORE_ID); - std::shared_ptr kvStoreObserver_ = - std::make_shared(); - int32_t res = onlineSyncTbl_->UnSubscribeKvStore(nullptr); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, res); -} - -/** - * @tc.name: UnSubscribeKvStore_009 - * @tc.desc: put device profile with empty service id - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileStorageTest, UnSubscribeKvStore_009, TestSize.Level3) -{ - deviceProfileStorage->Init(); - std::shared_ptr kvStoreObserver_ = - std::make_shared(); - int32_t res = deviceProfileStorage->UnSubscribeKvStore(nullptr); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, res); -} - -/** - * @tc.name: UnSubscribeKvStore_0010 - * @tc.desc: put device profile with empty service id - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileStorageTest, UnSubscribeKvStore_0010, TestSize.Level3) -{ - deviceProfileStorage->Init(); - std::shared_ptr kvStoreObserver_ = - std::make_shared(); - int32_t res = deviceProfileStorage->UnSubscribeKvStore(kvStoreObserver_); - EXPECT_EQ(27459590, res); -} - -/** - * @tc.name: RegisterSyncCallback_008 - * @tc.desc: subscribe kvstore - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileStorageTest, RegisterSyncCallback_008, TestSize.Level2) -{ - std::shared_ptr onlineSyncTbl_ = std::make_shared(APP_ID, STORE_ID); - int32_t res = onlineSyncTbl_->RegisterSyncCallback(nullptr); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, res); -} - -/** - * @tc.name: RegisterSyncCallback_009 - * @tc.desc: subscribe kvstore - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileStorageTest, RegisterSyncCallback_009, TestSize.Level2) -{ - std::shared_ptr onlineSyncTbl_ = std::make_shared(APP_ID, STORE_ID); - std::shared_ptr syncCallback = - std::make_shared(); - int32_t res = onlineSyncTbl_->RegisterSyncCallback(syncCallback); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, res); -} - -/** - * @tc.name: RegisterSyncCallback_010 - * @tc.desc: subscribe kvstore - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileStorageTest, RegisterSyncCallback_010, TestSize.Level2) -{ - deviceProfileStorage->Init(); - int32_t res = deviceProfileStorage->RegisterSyncCallback(nullptr); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, res); -} - -/** - * @tc.name: RegisterSyncCallback_011 - * @tc.desc: subscribe kvstore - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileStorageTest, RegisterSyncCallback_011, TestSize.Level2) -{ - deviceProfileStorage->Init(); - std::shared_ptr syncCallback = - std::make_shared(); - int32_t res = deviceProfileStorage->RegisterSyncCallback(syncCallback); - EXPECT_EQ(0, res); -} - -/** - * @tc.name: RemoveDeviceData_003 - * @tc.desc: remove device data - * @tc.type: FUNC - * @tc.require: I4OH93 - */ -HWTEST_F(ProfileStorageTest, RemoveDeviceData_003, TestSize.Level2) -{ - deviceProfileStorage->Init(); - int32_t res = deviceProfileStorage->RemoveDeviceData("network1111111"); - EXPECT_EQ(27459584, res); -} - -/** - * @tc.name: SyncDeviceProfile_004 - * @tc.desc: sync device profile - * @tc.type: FUNC - * @tc.require: I5QPGN - */ -HWTEST_F(ProfileStorageTest, SyncDeviceProfile_004, TestSize.Level3) -{ - deviceProfileStorage->Init(); - DeviceProfileStorageManager::GetInstance().RegisterCallbacks(); - DeviceProfileStorageManager::GetInstance().kvStoreObserver_ = std::make_shared(); - std::vector deviceIds = {"", std::move("testudid123"), ""}; - int result = deviceProfileStorage->SyncDeviceProfile(deviceIds, SyncMode::PUSH); - EXPECT_EQ(ERR_DP_UNTRUSTED_GROUP, result); -} - -/** - * @tc.name: PutDeviceProfile_009 - * @tc.desc: put device profile with empty service id - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileStorageTest, PutDeviceProfile_009, TestSize.Level3) -{ - DeviceProfileStorageManager::GetInstance().onlineSyncTbl_->initStatus_ = StorageInitStatus::INIT_SUCCEED; - ServiceCharacteristicProfile profile; - profile.SetServiceId("testttt"); - profile.SetServiceType("testttt"); - nlohmann::json j; - j["testVersion"] = "3.0.0"; - j["testApiLevel"] = 8; - profile.SetCharacteristicProfileJson(j.dump()); - nlohmann::json j1; - j1["type"] = "testttt"; - DeviceProfileStorageManager::GetInstance().servicesJson_["testttt"] = j1; - int32_t result = DeviceProfileStorageManager::GetInstance().PutDeviceProfile(profile); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, result); -} - -/** - * @tc.name: SetServiceType_005 - * @tc.desc: set service type - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileStorageTest, SetServiceType_005, TestSize.Level3) -{ - deviceProfileStorage->Init(); - ServiceCharacteristicProfile profile; - nlohmann::json j; - j["testVersion"] = "3.0.0"; - j["testApiLevel"] = 8; - profile.SetCharacteristicProfileJson(j.dump()); - std::vector keys; - std::vector values; - keys.emplace_back(DeviceProfileStorageManager::GetInstance().GenerateKey( - "test123udid", "services", KeyType::SERVICE_LIST)); - values.emplace_back(profile.GetCharacteristicProfileJson()); - int result = -1; - if (deviceProfileStorage->kvStorePtr_ == nullptr) { - deviceProfileStorage->kvStorePtr_ = kvStorePtr_; - } - if (deviceProfileStorage != nullptr) { - result = deviceProfileStorage->PutDeviceProfile(keys[0], values[0]); - } - DeviceProfileStorageManager::GetInstance().onlineSyncTbl_ = deviceProfileStorage; - - std::string udid = "test123udid"; - std::string serviceId = "test"; - DeviceProfileStorageManager::GetInstance().SetServiceType(udid, serviceId, profile); - std::shared_ptr syncCallback = - std::make_shared(); - DeviceProfileStorageManager::GetInstance().kvStoreObserver_ = std::make_shared(); - DeviceProfileStorageManager::GetInstance().kvStoreSyncCallback_ = syncCallback; - DeviceProfileStorageManager::GetInstance().RegisterCallbacks(); - EXPECT_EQ(0, result); -} - -/** - * @tc.name: PutDeviceProfile_010 - * @tc.desc: put device profile nullptr - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileStorageTest, PutDeviceProfile_010, TestSize.Level3) -{ - ServiceCharacteristicProfile profile; - DeviceProfileStorageManager::GetInstance().onlineSyncTbl_->initStatus_ = StorageInitStatus::INIT_SUCCEED; - int32_t ret = DeviceProfileStorageManager::GetInstance().PutDeviceProfile(profile); - EXPECT_EQ(ret, ERR_OK); - DeviceProfileStorageManager::GetInstance().kvDataServiceFailed_ = true; - ret = DeviceProfileStorageManager::GetInstance().PutDeviceProfile(profile); - EXPECT_NE(ret, ERR_OK); - DeviceProfileStorageManager::GetInstance().onlineSyncTbl_->initStatus_ = StorageInitStatus::INIT_FAILED; - ret = DeviceProfileStorageManager::GetInstance().PutDeviceProfile(profile); - EXPECT_NE(ret, ERR_OK); - ret = DeviceProfileStorageManager::GetInstance().RemoveUnBoundDeviceProfile("111"); - EXPECT_NE(ret, ERR_OK); - ret = DeviceProfileStorageManager::GetInstance().RemoveRemoteDeviceProfile(); - EXPECT_NE(ret, ERR_OK); - std::shared_ptr kvStoreObserver_ = - std::make_shared(); - ret = DeviceProfileStorageManager::GetInstance().SubscribeKvStore(kvStoreObserver_); - EXPECT_EQ(ret, ERR_OK); - DeviceProfileStorageManager::GetInstance().RegisterCallbacks(); - DeviceProfileStorageManager::GetInstance().onlineSyncTbl_->initStatus_ = StorageInitStatus::INIT_SUCCEED; - ret = DeviceProfileStorageManager::GetInstance().RemoveUnBoundDeviceProfile("111"); - EXPECT_NE(ret, ERR_OK); - ret = DeviceProfileStorageManager::GetInstance().RemoveRemoteDeviceProfile(); - EXPECT_EQ(ret, 27459584); -} - -/** - * @tc.name: DeviceProfileStorage_001 - * @tc.desc: onlineSyncTbl_ nullptr - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileStorageTest, DeviceProfileStorage_001, TestSize.Level3) -{ - std::shared_ptr onlineSyncTbl_ = std::make_shared(APP_ID, STORE_ID); - onlineSyncTbl_->kvStoreInitCallback_ = nullptr; - onlineSyncTbl_->Init(); - onlineSyncTbl_->kvStorePtr_ = nullptr; - bool ret = onlineSyncTbl_->TryGetKvStore(); - EXPECT_EQ(ret, false); -} - -void MyKvStoreInitCallback() -{ - return; -} - -/** - * @tc.name: RegisterKvStoreInitCallback_001 - * @tc.desc: onlineSyncTbl_ nullptr - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileStorageTest, RegisterKvStoreInitCallback_001, TestSize.Level3) -{ - std::shared_ptr onlineSyncTbl_ = std::make_shared(APP_ID, STORE_ID); - onlineSyncTbl_->kvStoreInitCallback_ = nullptr; - DeviceProfileStorage::KvStoreInitCallback callback; - onlineSyncTbl_->RegisterKvStoreInitCallback(MyKvStoreInitCallback); - bool ret = onlineSyncTbl_->RegisterKvStoreInitCallback(MyKvStoreInitCallback); - EXPECT_EQ(ret, false); -} -} -} \ No newline at end of file diff --git a/old/services/core/test/unittest/profile_sync_test.cpp b/old/services/core/test/unittest/profile_sync_test.cpp deleted file mode 100644 index 33dbb4c9..00000000 --- a/old/services/core/test/unittest/profile_sync_test.cpp +++ /dev/null @@ -1,255 +0,0 @@ -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * 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. - */ - -#include "gtest/gtest.h" - -#include "utils.h" - -#include -#include -#include - -#define private public -#define protected public -#include "device_profile_errors.h" -#include "device_profile_log.h" -#include "device_profile_storage.h" -#include "device_profile_storage_manager.h" -#include "distributed_device_profile_client.h" -#include "distributed_device_profile_service.h" -#include "hisysevent.h" -#include "nlohmann/json.hpp" -#include "online_sync_table.h" -#include "sync_coordinator.h" -#include "syscap_info_collector.h" -#include "syscap_interface.h" -#undef private -#undef protected - -namespace OHOS { -namespace DeviceProfile { -using namespace OHOS::HiviewDFX; -using namespace OHOS::DistributedKv; -namespace { - const std::string TAG = "SyscapInfoCollector"; - const std::string SERVICE_ID = "test"; - const std::string SERVICE_TYPE = "test"; - const std::string CHARACTER_PRIVATE_SYSCAP = "privatesyscap"; - const std::string CHARACTER_OS_SYSCAP = "ossyscap"; - const std::string FAULT_CODE_KEY = "FAULT_CODE"; - const std::string DOMAIN_NAME = std::string(HiSysEvent::Domain::DEVICE_PROFILE); - const std::string APP_ID = "distributed_device_profile_service"; - const std::string STORE_ID = "online_sync_storage_test"; -} -using namespace testing; -using namespace testing::ext; - -class ProfileSyncTest : public testing::Test { -public: - ProfileSyncTest(); - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp(); - void TearDown(); - -public: - std::shared_ptr deviceProfileStorage; - std::shared_ptr kvStorePtr_; -}; - -ProfileSyncTest::ProfileSyncTest() -{ -} - -void ProfileSyncTest::SetUpTestCase() -{ - DTEST_LOG << "SetUpTestCase" << std::endl; -} - -void ProfileSyncTest::TearDownTestCase() -{ - DTEST_LOG << "TearDownTestCase" << std::endl; -} - -void ProfileSyncTest::SetUp() -{ - DTEST_LOG << "SetUp" << std::endl; -} - -void ProfileSyncTest::TearDown() -{ - DTEST_LOG << "TearDown" << std::endl; -} - -class StorageProfileEventCallback : public IProfileEventCallback { -}; - -class ProfileSyncHandler : public DistributedKv::KvStoreSyncCallback { -public: - void SyncCompleted(const std::map& results) override - { - } -}; - -/** - * @tc.name: Init_001 - * @tc.desc: put device profile with empty service id - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileSyncTest, Init_001, TestSize.Level3) -{ - auto runner = AppExecFwk::EventRunner::Create("dpstoragetest"); - DeviceProfileStorageManager::GetInstance().storageHandler_ = - std::make_shared(runner); - DeviceProfileStorageManager::GetInstance().onlineSyncTbl_ = - std::make_shared(); - DeviceProfileStorageManager::GetInstance().inited_ = true; - bool result = DeviceProfileStorageManager::GetInstance().Init(); - EXPECT_EQ(true, result); -} -/** - * @tc.name: RegisterSyncCallback_001 - * @tc.desc: put device profile with empty service id - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileSyncTest, RegisterSyncCallback_001, TestSize.Level3) -{ - DeviceProfileStorageManager::GetInstance().onlineSyncTbl_->initStatus_ = - StorageInitStatus::INIT_SUCCEED; - int32_t res = DeviceProfileStorageManager::GetInstance().RegisterSyncCallback(nullptr); - EXPECT_EQ(ERR_DP_INVALID_PARAMS, res); -} -/** - * @tc.name: SyncDeviceProfile_001 - * @tc.desc: sync device profile - * @tc.type: FUNC - * @tc.require: I5QPGN - */ -HWTEST_F(ProfileSyncTest, SyncDeviceProfile_001, TestSize.Level3) -{ - SyncCoordinator::GetInstance().Init(); - std::vector deviceIds = {"", std::move("testudid123"), ""}; - std::map results; - results["123456"] = Status::SUCCESS; - results["78910"] = Status::ERROR; - results["996"] = Status::ERROR; - std::list> deviceIdsList_; - std::vector vectorDeviceId = {"996", "996", "996"}; - deviceIdsList_.push_back(vectorDeviceId); - DpDeviceManager::GetInstance().deviceIdsList_ = deviceIdsList_; - SyncCoordinator::GetInstance().isOnlineTrigger_ = true; - std::shared_ptr onlineSyncTblTest_ = std::make_shared(); - onlineSyncTblTest_->SyncCompleted(results); - int result = DeviceProfileStorageManager::GetInstance().onlineSyncTbl_-> - SyncDeviceProfile(deviceIds, SyncMode::PUSH); - EXPECT_EQ(0, result); -} - -/** - * @tc.name: DeleteDeviceProfile_001 - * @tc.desc: sync device profile - * @tc.type: FUNC - * @tc.require: I5QPGN - */ -HWTEST_F(ProfileSyncTest, DeleteDeviceProfile_001, TestSize.Level3) -{ - int32_t res = DistributedDeviceProfileService::GetInstance().DeleteDeviceProfile("test"); - EXPECT_EQ(ERR_DP_PERMISSION_DENIED, res); -} - -/** - * @tc.name: SyncDeviceProfile_002 - * @tc.desc: sync device profile - * @tc.type: FUNC - * @tc.require: I5QPGN - */ -HWTEST_F(ProfileSyncTest, SyncDeviceProfile_002, TestSize.Level3) -{ - auto syncCb = std::make_shared(); - SyncOptions syncOptions; - sptr notifier = - sptr(new ProfileEventNotifierStub(syncCb)); - int result = DistributedDeviceProfileService::GetInstance().SyncDeviceProfile(syncOptions, notifier); - EXPECT_EQ(ERR_DP_PERMISSION_DENIED, result); -} - -/** - * @tc.name: OnIdle_001 - * @tc.desc: sync device profile - * @tc.type: FUNC - * @tc.require: I5QPGN - */ -HWTEST_F(ProfileSyncTest, OnIdle_001, TestSize.Level3) -{ - DistributedDeviceProfileService::GetInstance().isOnline_ = true; - auto runner = AppExecFwk::EventRunner::Create("unload"); - DistributedDeviceProfileService::GetInstance().unloadHandler_ = - std::make_shared(runner); - DistributedDeviceProfileService::GetInstance().DelayUnloadTask(); - SystemAbilityOnDemandReason reason; - reason.SetId(OnDemandReasonId::SETTING_SWITCH); - int result = DistributedDeviceProfileService::GetInstance().OnIdle(reason); - EXPECT_EQ(0, result); -} - -/** - * @tc.name: OnIdle_002 - * @tc.desc: sync device profile - * @tc.type: FUNC - * @tc.require: I5QPGN - */ -HWTEST_F(ProfileSyncTest, OnIdle_002, TestSize.Level3) -{ - SystemAbilityOnDemandReason reason; - reason.SetId(OnDemandReasonId::DEVICE_ONLINE); - SyncCoordinator::GetInstance().isOnSync_ = false; - int result = DistributedDeviceProfileService::GetInstance().OnIdle(reason); - EXPECT_EQ(0, result); -} - -/** - * @tc.name: DeviceOnline_001 - * @tc.desc: put device profile with empty service id - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileSyncTest, DeviceOnline_001, TestSize.Level3) -{ - DistributedDeviceProfileService::GetInstance().OnStop(); - - DistributedDeviceProfileService::GetInstance().DeviceOnline(); - bool ret = DistributedDeviceProfileService::GetInstance().isOnline_; - EXPECT_EQ(true, ret); -} - -/** - * @tc.name: Dump_001 - * @tc.desc: put device profile with empty service id - * @tc.type: FUNC - * @tc.require: I4NY23 - */ -HWTEST_F(ProfileSyncTest, Dump_001, TestSize.Level3) -{ - int32_t fd = 0; - std::vector args; - std::u16string arg = u"123456"; - args.push_back(arg); - int result = DistributedDeviceProfileService::GetInstance().Dump(fd, args); - EXPECT_EQ(ERR_DP_FILE_FAILED_ERR, result); -} -} -} \ No newline at end of file diff --git a/old/services/core/test/unittest/service_profile_test.cpp b/old/services/core/test/unittest/service_profile_test.cpp deleted file mode 100644 index db924d71..00000000 --- a/old/services/core/test/unittest/service_profile_test.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * 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. - */ - -#include - -#include "distributed_device_profile_client.h" -#include "service_characteristic_profile.h" -#include "utils.h" - -namespace OHOS { -namespace DeviceProfile { -using namespace testing; -using namespace testing::ext; - -class ServiceProfileTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp(); - void TearDown(); -}; - -void ServiceProfileTest::SetUpTestCase() -{ - DTEST_LOG << "SetUpTestCase" << std::endl; - DistributedDeviceProfileClient::GetInstance().DeleteDeviceProfile("111111"); -} - -void ServiceProfileTest::TearDownTestCase() -{ - DTEST_LOG << "TearDownTestCase" << std::endl; -} - -void ServiceProfileTest::SetUp() -{ - DTEST_LOG << "SetUp" << std::endl; -} - -void ServiceProfileTest::TearDown() -{ - DTEST_LOG << "TearDown" << std::endl; -} - -/** - * @tc.name: SetServiceProfileJson_001 - * @tc.desc: set service profile json - * @tc.type: FUNC - * @tc.require: I4OH94 - */ -HWTEST_F(ServiceProfileTest, SetServiceProfileJson_001, TestSize.Level3) -{ - std::string profileJson; - ServiceCharacteristicProfile profile; - profile.SetServiceProfileJson(profileJson); - EXPECT_EQ("", profileJson); -} - -/** - * @tc.name: GetServiceProfileJson_001 - * @tc.desc: get service profile json - * @tc.type: FUNC - * @tc.require: I4OH94 - */ -HWTEST_F(ServiceProfileTest, GetServiceProfileJson_001, TestSize.Level3) -{ - std::string profileJson = ""; - ServiceCharacteristicProfile profile; - std::string result = profile.GetServiceProfileJson(); - EXPECT_EQ(profileJson, result); -} - -/** - * @tc.name: Marshalling_001 - * @tc.desc: marshalling - * @tc.type: FUNC - * @tc.require: I4OH94 - */ -HWTEST_F(ServiceProfileTest, Marshalling_001, TestSize.Level3) -{ - Parcel parcel; - ServiceCharacteristicProfile profile; - bool result = profile.Marshalling(parcel); - EXPECT_EQ(true, result); -} - -/** - * @tc.name: Unmarshalling_001 - * @tc.desc: unmarshalling - * @tc.type: FUNC - * @tc.require: I4OH94 - */ -HWTEST_F(ServiceProfileTest, Unmarshalling_001, TestSize.Level3) -{ - Parcel parcel; - ServiceCharacteristicProfile profile; - bool result = profile.Unmarshalling(parcel); - EXPECT_NE(true, result); -} -} -} \ No newline at end of file diff --git a/old/services/core/test/unittest/subscribe_info_checker_test.cpp b/old/services/core/test/unittest/subscribe_info_checker_test.cpp deleted file mode 100644 index 8b191729..00000000 --- a/old/services/core/test/unittest/subscribe_info_checker_test.cpp +++ /dev/null @@ -1,282 +0,0 @@ -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * 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. - */ - -#include - -#include "distributed_device_profile_client.h" -#include "profile_event_handler_factory.h" -#include "subscribe_info.h" -#include "subscribe_info_checker.h" -#include "utils.h" - -namespace OHOS { -namespace DeviceProfile { -using namespace testing; -using namespace testing::ext; - -class SubscribeInfoCheckerTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp(); - void TearDown(); -}; - -void SubscribeInfoCheckerTest::SetUpTestCase() -{ - DTEST_LOG << "SetUpTestCase" << std::endl; - DistributedDeviceProfileClient::GetInstance().DeleteDeviceProfile("111111"); -} - -void SubscribeInfoCheckerTest::TearDownTestCase() -{ - DTEST_LOG << "TearDownTestCase" << std::endl; -} - -void SubscribeInfoCheckerTest::SetUp() -{ - DTEST_LOG << "SetUp" << std::endl; -} - -void SubscribeInfoCheckerTest::TearDown() -{ - DTEST_LOG << "TearDown" << std::endl; -} - -/** - * @tc.name: Check_001 - * @tc.desc: Check - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(SubscribeInfoCheckerTest, Check_001, TestSize.Level3) -{ - SubscribeInfo subInfo; - subInfo.extraInfo = { - {"deviceId", ""}, - {"serviceIds", "1111"} - }; - subInfo.profileEvent = ProfileEvent::EVENT_UNKNOWN; - std::list infos(1, subInfo); - bool ret = SubscribeInfoChecker::GetInstance().Check(infos); - ASSERT_FALSE(ret); -} - -/** - * @tc.name: Check_002 - * @tc.desc: Check - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(SubscribeInfoCheckerTest, Check_002, TestSize.Level3) -{ - SubscribeInfo subInfo; - subInfo.extraInfo = { - {"deviceId", ""}, - {"serviceIds", "1111"} - }; - subInfo.profileEvent = ProfileEvent::EVENT_SYNC_COMPLETED; - std::list infos(1, subInfo); - bool ret = SubscribeInfoChecker::GetInstance().Check(infos); - ASSERT_TRUE(ret); -} - -/** - * @tc.name: Check_004 - * @tc.desc: Check - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(SubscribeInfoCheckerTest, Check_004, TestSize.Level3) -{ - SubscribeInfo subInfo; - subInfo.extraInfo = { - {"deviceId", "1"}, - {"serviceIds", "1111"} - }; - subInfo.profileEvent = ProfileEvent::EVENT_PROFILE_CHANGED; - std::list infos(1, subInfo); - bool ret = SubscribeInfoChecker::GetInstance().Check(infos); - ASSERT_FALSE(ret); -} - -/** - * @tc.name: Check_005 - * @tc.desc: Check - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(SubscribeInfoCheckerTest, Check_005, TestSize.Level3) -{ - SubscribeInfo subInfo; - subInfo.extraInfo = { - {"deviceId", 1}, - {"serviceIds", "1111"} - }; - subInfo.profileEvent = ProfileEvent::EVENT_PROFILE_CHANGED; - std::list infos(1, subInfo); - bool ret = SubscribeInfoChecker::GetInstance().Check(infos); - ASSERT_FALSE(ret); -} - -/** - * @tc.name: Check_006 - * @tc.desc: Check - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(SubscribeInfoCheckerTest, Check_006, TestSize.Level3) -{ - SubscribeInfo subInfo; - subInfo.extraInfo = { - {"deviceId", "deviceId"} - }; - subInfo.profileEvent = ProfileEvent::EVENT_PROFILE_CHANGED; - std::list infos(1, subInfo); - bool ret = SubscribeInfoChecker::GetInstance().Check(infos); - ASSERT_FALSE(ret); -} - -/** - * @tc.name: Check_007 - * @tc.desc: Check - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(SubscribeInfoCheckerTest, Check_007, TestSize.Level3) -{ - SubscribeInfo subInfo; - subInfo.extraInfo = { - {"deviceId", "deviceId"} - }; - std::list serviceIds = {"fakeStorage", "fakeSystem"}; - subInfo.extraInfo["serviceIds"] = serviceIds; - subInfo.profileEvent = ProfileEvent::EVENT_PROFILE_CHANGED; - std::list infos(1, subInfo); - bool ret = SubscribeInfoChecker::GetInstance().Check(infos); - ASSERT_TRUE(ret); -} - -/** - * @tc.name: Check_007 - * @tc.desc: Check - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(SubscribeInfoCheckerTest, Check_008, TestSize.Level3) -{ - SubscribeInfo subInfo; - subInfo.extraInfo["serviceIds"] = nullptr; - subInfo.profileEvent = ProfileEvent::EVENT_PROFILE_CHANGED; - std::list infos(1, subInfo); - bool ret = SubscribeInfoChecker::GetInstance().Check(infos); - ASSERT_FALSE(ret); -} - -/** - * @tc.name: Check_007 - * @tc.desc: Check - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(SubscribeInfoCheckerTest, Check_009, TestSize.Level3) -{ - SubscribeInfo subInfo; - subInfo.extraInfo["deviceId"] = nullptr; - subInfo.profileEvent = ProfileEvent::EVENT_PROFILE_CHANGED; - std::list infos(1, subInfo); - bool ret = SubscribeInfoChecker::GetInstance().Check(infos); - ASSERT_FALSE(ret); -} - -/** - * @tc.name: GetHandler_001 - * @tc.desc: GetHandler - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(SubscribeInfoCheckerTest, GetHandler_001, TestSize.Level3) -{ - auto result = ProfileEventHandlerFactory::GetInstance().GetHandler(ProfileEvent::EVENT_PROFILE_END); - DTEST_LOG << "result: " << result << std::endl; - EXPECT_EQ(nullptr, result); -} - - -/** - * @tc.name: GetHandler_010 - * @tc.desc: GetHandler - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(SubscribeInfoCheckerTest, Check_010, TestSize.Level3) -{ - SubscribeInfo subInfo; - subInfo.extraInfo = { - {"deviceId", "deviceId"} - }; - std::list serviceIds = {"fakeStorage", "fakeSystem"}; - subInfo.profileEvent = ProfileEvent::EVENT_SYNC_COMPLETED; - std::list infos(1, subInfo); - bool ret = SubscribeInfoChecker::GetInstance().Check(infos); - ASSERT_TRUE(ret); -} - -/** - * @tc.name: GetHandler_011 - * @tc.desc: GetHandler - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(SubscribeInfoCheckerTest, Check_011, TestSize.Level3) -{ - SubscribeInfo subInfo; - subInfo.extraInfo = { - {"deviceId", "deviceId"} - }; - std::list serviceIds = {"fakeStorage", "fakeSystem"}; - subInfo.profileEvent = ProfileEvent::EVENT_UNKNOWN; - std::list infos(1, subInfo); - bool ret = SubscribeInfoChecker::GetInstance().Check(infos); - ASSERT_FALSE(ret); -} - -/** - * @tc.name: GetHandler_002 - * @tc.desc: GetHandler - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(SubscribeInfoCheckerTest, GetHandler_002, TestSize.Level3) -{ - auto result = ProfileEventHandlerFactory::GetInstance().GetHandler(ProfileEvent::EVENT_PROFILE_CHANGED); - DTEST_LOG << "result: " << result << std::endl; - EXPECT_NE(nullptr, result); -} - -/** - * @tc.name: GetHandler_003 - * @tc.desc: GetHandler - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(SubscribeInfoCheckerTest, GetHandler_003, TestSize.Level3) -{ - auto result = ProfileEventHandlerFactory::GetInstance().GetHandler(ProfileEvent::EVENT_UNKNOWN); - DTEST_LOG << "result: " << result << std::endl; - EXPECT_EQ(nullptr, result); -} -} -} \ No newline at end of file diff --git a/old/services/core/test/unittest/subscribe_info_test.cpp b/old/services/core/test/unittest/subscribe_info_test.cpp deleted file mode 100644 index 34b1633d..00000000 --- a/old/services/core/test/unittest/subscribe_info_test.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * 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. - */ - -#include - -#include "distributed_device_profile_client.h" -#include "subscribe_info.h" -#include "utils.h" - -namespace OHOS { -namespace DeviceProfile { -using namespace testing; -using namespace testing::ext; - -class SubscribeInfoTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp(); - void TearDown(); -}; - -void SubscribeInfoTest::SetUpTestCase() -{ - DTEST_LOG << "SetUpTestCase" << std::endl; - DistributedDeviceProfileClient::GetInstance().DeleteDeviceProfile("111111"); -} - -void SubscribeInfoTest::TearDownTestCase() -{ - DTEST_LOG << "TearDownTestCase" << std::endl; -} - -void SubscribeInfoTest::SetUp() -{ - DTEST_LOG << "SetUp" << std::endl; -} - -void SubscribeInfoTest::TearDown() -{ - DTEST_LOG << "TearDown" << std::endl; -} - -/** - * @tc.name: Unmarshalling_001 - * @tc.desc: unmarshalling - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(SubscribeInfoTest, Unmarshalling_001, TestSize.Level3) -{ - Parcel parcel; - SubscribeInfo subInfo; - bool result = subInfo.Unmarshalling(parcel); - EXPECT_NE(true, result); -} - -/** - * @tc.name: Unmarshalling_001 - * @tc.desc: unmarshalling - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(SubscribeInfoTest, Unmarshalling_002, TestSize.Level3) -{ - Parcel parcel; - parcel.WriteUint32(1); - parcel.WriteString("test"); - SubscribeInfo subInfo; - bool result = subInfo.Unmarshalling(parcel); - EXPECT_FALSE(result); -} - -/** - * @tc.name: Unmarshalling_001 - * @tc.desc: unmarshalling - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(SubscribeInfoTest, Unmarshalling_003, TestSize.Level3) -{ - Parcel parcel; - parcel.WriteUint32(1); - std::string test = R"( - {"key": "value"} - )"; - parcel.WriteString(test); - SubscribeInfo subInfo; - bool result = subInfo.Unmarshalling(parcel); - EXPECT_TRUE(result); -} - -/** - * @tc.name: operator_001 - * @tc.desc: operator - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(SubscribeInfoTest, operator_001, TestSize.Level3) -{ - SubscribeInfo rhs; - SubscribeInfo subInfo; - bool result = subInfo.operator != (rhs); - EXPECT_NE(true, result); -} -} -} \ No newline at end of file diff --git a/old/services/core/test/unittest/subscribe_manager_test.cpp b/old/services/core/test/unittest/subscribe_manager_test.cpp deleted file mode 100644 index 1bf48b7f..00000000 --- a/old/services/core/test/unittest/subscribe_manager_test.cpp +++ /dev/null @@ -1,398 +0,0 @@ -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * 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. - */ - -#include - -#include "device_profile_errors.h" -#include "device_profile_storage_manager.h" -#include "distributed_device_profile_client.h" -#include "ipc_skeleton.h" -#include "profile_event.h" -#include "subscribe_info.h" -#include "subscriber_death_recipient.h" -#include "utils.h" - -#define private public -#include "profile_event_handler_factory.h" -#include "profile_sync_handler.h" -#include "subscribe_manager.h" - -namespace OHOS { -namespace DeviceProfile { -using namespace testing; -using namespace testing::ext; - -namespace { - constexpr int32_t MAX_SUBSCRIBS_PER_UID = 100; -} - -class SubscribeManagerTest : public testing::Test { -public: - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp(); - void TearDown(); -}; - -void SubscribeManagerTest::SetUpTestCase() -{ - DTEST_LOG << "SetUpTestCase" << std::endl; - DistributedDeviceProfileClient::GetInstance().DeleteDeviceProfile("111111"); - DeviceProfileStorageManager::GetInstance().Init(); -} - -void SubscribeManagerTest::TearDownTestCase() -{ - DTEST_LOG << "TearDownTestCase" << std::endl; -} - -void SubscribeManagerTest::SetUp() -{ - DTEST_LOG << "SetUp" << std::endl; -} - -void SubscribeManagerTest::TearDown() -{ - DTEST_LOG << "TearDown" << std::endl; -} - -class StorageProfileEventCallback : public IProfileEventCallback { -}; - -/** - * @tc.name: IncSubsOfUidLocked_001 - * @tc.desc: IncSubsOfUidLocked - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(SubscribeManagerTest, IncSubsOfUidLocked_001, TestSize.Level3) -{ - int32_t mockUid = -1; - SubscribeManager::GetInstance().IncSubsOfUidLocked(mockUid); - int32_t expectedCount = SubscribeManager::GetInstance().uidSubsMap_[mockUid]; - EXPECT_EQ(expectedCount, 1); - SubscribeManager::GetInstance().IncSubsOfUidLocked(mockUid); - expectedCount = SubscribeManager::GetInstance().uidSubsMap_[mockUid]; - EXPECT_EQ(expectedCount, 2); - SubscribeManager::GetInstance().uidSubsMap_.clear(); -} - -/** - * @tc.name: CheckSubsOfUid_001 - * @tc.desc: IncSubsOfUidLocked - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(SubscribeManagerTest, CheckSubsOfUid_001, TestSize.Level3) -{ - int32_t mockUid = -1; - bool ret = SubscribeManager::GetInstance().CheckSubsOfUid(mockUid); - EXPECT_TRUE(ret); - SubscribeManager::GetInstance().uidSubsMap_.clear(); -} - -/** - * @tc.name: CheckSubsOfUid_002 - * @tc.desc: CheckSubsOfUid - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(SubscribeManagerTest, CheckSubsOfUid_002, TestSize.Level3) -{ - int32_t mockUid = -1; - SubscribeManager::GetInstance().IncSubsOfUidLocked(mockUid); - bool ret = SubscribeManager::GetInstance().CheckSubsOfUid(mockUid); - EXPECT_TRUE(ret); - SubscribeManager::GetInstance().uidSubsMap_.clear(); -} - -/** - * @tc.name: CheckSubsOfUid_003 - * @tc.desc: CheckSubsOfUid - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(SubscribeManagerTest, CheckSubsOfUid_003, TestSize.Level3) -{ - int32_t mockUid = -1; - SubscribeManager::GetInstance().uidSubsMap_[mockUid] = MAX_SUBSCRIBS_PER_UID; - bool ret = SubscribeManager::GetInstance().CheckSubsOfUid(mockUid); - EXPECT_FALSE(ret); - SubscribeManager::GetInstance().uidSubsMap_.clear(); -} - -/** - * @tc.name: DecSubsOfUidLocked_001 - * @tc.desc: DecSubsOfUidLocked - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(SubscribeManagerTest, DecSubsOfUidLocked_001, TestSize.Level3) -{ - int32_t mockUid = -1; - SubscribeManager::GetInstance().DecSubsOfUidLocked(mockUid); - bool ret = SubscribeManager::GetInstance().uidSubsMap_.empty(); - EXPECT_TRUE(ret); -} - -/** - * @tc.name: DecSubsOfUidLocked_002 - * @tc.desc: DecSubsOfUidLocked - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(SubscribeManagerTest, DecSubsOfUidLocked_002, TestSize.Level3) -{ - int32_t mockUid = -1; - SubscribeManager::GetInstance().IncSubsOfUidLocked(mockUid); - bool ret = SubscribeManager::GetInstance().uidSubsMap_.empty(); - EXPECT_FALSE(ret); - SubscribeManager::GetInstance().DecSubsOfUidLocked(mockUid); - ret = SubscribeManager::GetInstance().uidSubsMap_.empty(); - EXPECT_TRUE(ret); -} - -/** - * @tc.name: DecSubsOfUidLocked_002 - * @tc.desc: DecSubsOfUidLocked - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(SubscribeManagerTest, DecSubsOfUidLocked_003, TestSize.Level3) -{ - int32_t mockUid = -1; - SubscribeManager::GetInstance().uidSubsMap_[mockUid] = MAX_SUBSCRIBS_PER_UID; - bool ret = SubscribeManager::GetInstance().uidSubsMap_.empty(); - EXPECT_FALSE(ret); - SubscribeManager::GetInstance().DecSubsOfUidLocked(mockUid); - ret = SubscribeManager::GetInstance().uidSubsMap_.empty(); - EXPECT_FALSE(ret); - SubscribeManager::GetInstance().uidSubsMap_.clear(); -} - -/** - * @tc.name: OnSubscriberDied_001 - * @tc.desc: OnSubscriberDied - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(SubscribeManagerTest, OnSubscriberDied_001, TestSize.Level3) -{ - sptr object; - SubscribeManager::GetInstance().OnSubscriberDied(object); - bool ret = SubscribeManager::GetInstance().notifiersMap_.empty(); - EXPECT_TRUE(ret); -} - -/** - * @tc.name: Init_001 - * @tc.desc: Init - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(SubscribeManagerTest, Init_001, TestSize.Level3) -{ - bool ret = SubscribeManager::GetInstance().Init(); - EXPECT_TRUE(ret); -} - -/** - * @tc.name: SubscribeProfileEvents_001 - * @tc.desc: SubscribeProfileEvents - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(SubscribeManagerTest, SubscribeProfileEvents_001, TestSize.Level3) -{ - auto syncCb = std::make_shared(); - sptr notifier = - sptr(new ProfileEventNotifierStub(syncCb)); - std::list subscribeInfos; - std::list failedEvents; - int32_t ret = SubscribeManager::GetInstance().SubscribeProfileEvents(subscribeInfos, notifier, failedEvents); - EXPECT_EQ(ret, ERR_OK); -} - -/** - * @tc.name: SubscribeProfileEvents_001 - * @tc.desc: SubscribeProfileEvents - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(SubscribeManagerTest, SubscribeProfileEvents_002, TestSize.Level3) -{ - auto syncCb = std::make_shared(); - sptr notifier = - sptr(new ProfileEventNotifierStub(syncCb)); - std::list subscribeInfos; - SubscribeInfo eventChange; - subscribeInfos.emplace_back(eventChange); - std::list failedEvents; - int32_t ret = SubscribeManager::GetInstance().SubscribeProfileEvents(subscribeInfos, notifier, failedEvents); - EXPECT_EQ(ret, ERR_DP_INVALID_PARAMS); -} - -/** - * @tc.name: UnsubscribeProfileEvents_001 - * @tc.desc: UnsubscribeProfileEvents - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(SubscribeManagerTest, UnsubscribeProfileEvents_001, TestSize.Level3) -{ - auto syncCb = std::make_shared(); - sptr notifier = - sptr(new ProfileEventNotifierStub(syncCb)); - - std::list profileEvents = { ProfileEvent::EVENT_SYNC_COMPLETED }; - std::list failedEvents; - - int32_t ret = SubscribeManager::GetInstance().UnsubscribeProfileEvents(profileEvents, notifier, failedEvents); - EXPECT_EQ(ret, ERR_OK); -} - -/** - * @tc.name: TryAddNotifierLocked_001 - * @tc.desc: TryAddNotifierLocked - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(SubscribeManagerTest, TryAddNotifierLocked_001, TestSize.Level3) -{ - auto syncCb = std::make_shared(); - sptr notifier = - sptr(new ProfileEventNotifierStub(syncCb)); - - ProfileEvents subProfileEvents; - subProfileEvents.set(1); - ASSERT_TRUE(SubscribeManager::GetInstance().subscriberDeathRecipient_ != nullptr); - SubscribeManager::GetInstance().TryAddNotifierLocked(notifier, subProfileEvents); - bool ret = SubscribeManager::GetInstance().notifiersMap_.empty(); - EXPECT_FALSE(ret); - SubscribeManager::GetInstance().TryAddNotifierLocked(notifier, subProfileEvents); - SubscribeManager::GetInstance().notifiersMap_.clear(); - ret = SubscribeManager::GetInstance().notifiersMap_.empty(); - EXPECT_TRUE(ret); -} - -/** - * @tc.name: TryRemoveNotiferLocked_001 - * @tc.desc: TryRemoveNotiferLocked - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(SubscribeManagerTest, TryRemoveNotiferLocked001, TestSize.Level3) -{ - auto syncCb = std::make_shared(); - sptr notifier = - sptr(new ProfileEventNotifierStub (syncCb)); - - ProfileEvents subProfileEvents; - subProfileEvents.set(1); - ASSERT_TRUE(SubscribeManager::GetInstance().subscriberDeathRecipient_ != nullptr); - SubscribeManager::GetInstance().TryRemoveNotiferLocked(notifier, subProfileEvents); - bool ret = SubscribeManager::GetInstance().notifiersMap_.empty(); - EXPECT_TRUE(ret); -} - -/** - * @tc.name: TryRemoveNotiferLocked_002 - * @tc.desc: TryRemoveNotiferLocked - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(SubscribeManagerTest, TryRemoveNotiferLocked002, TestSize.Level3) -{ - auto syncCb = std::make_shared(); - sptr notifier = - sptr(new ProfileEventNotifierStub(syncCb)); - - ProfileEvents subProfileEvents; - subProfileEvents.set(1); - ASSERT_TRUE(SubscribeManager::GetInstance().subscriberDeathRecipient_ != nullptr); - SubscribeManager::GetInstance().TryAddNotifierLocked(notifier, subProfileEvents); - bool ret = SubscribeManager::GetInstance().notifiersMap_.empty(); - EXPECT_FALSE(ret); - SubscribeManager::GetInstance().TryRemoveNotiferLocked(notifier, subProfileEvents); - ret = SubscribeManager::GetInstance().notifiersMap_.empty(); - EXPECT_TRUE(ret); -} - -/** - * @tc.name: TryRemoveNotiferLocked_003 - * @tc.desc: TryRemoveNotiferLocked - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(SubscribeManagerTest, TryRemoveNotiferLocked003, TestSize.Level3) -{ - auto syncCb = std::make_shared(); - sptr notifier = - sptr(new ProfileEventNotifierStub(syncCb)); - - ProfileEvents subProfileEvents; - subProfileEvents.set(1); - SubscribeManager::GetInstance().TryAddNotifierLocked(notifier, subProfileEvents); - bool ret = SubscribeManager::GetInstance().notifiersMap_.empty(); - EXPECT_FALSE(ret); - ProfileEvents unSubProfileEvents; - unSubProfileEvents.set(0); - SubscribeManager::GetInstance().TryRemoveNotiferLocked(notifier, unSubProfileEvents); - ret = SubscribeManager::GetInstance().notifiersMap_.empty(); - EXPECT_FALSE(ret); -} - -/** - * @tc.name: Unregister_001 - * @tc.desc: Unregister - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(SubscribeManagerTest, Unregister_001, TestSize.Level3) -{ - auto handler = std::make_shared("syncHandler"); - auto result = handler->Unregister(); - - std::map syncResult; - syncResult["testdeviceid"] = Status::SUCCESS; - handler->SyncCompleted(syncResult); - - SyncResult syncResults; - syncResults.emplace("testdeviceid", SUCCEEDED); - handler->NotifySyncCompleted(syncResults); - - auto syncCb = std::make_shared(); - wptr notifier = - sptr(new ProfileEventNotifierStub(syncCb)); - auto death = std::make_shared(); - death->OnRemoteDied(notifier); - DTEST_LOG << "result: " << result << std::endl; - EXPECT_EQ(0, result); -} - -/** - * @tc.name: GetProfileChangeHandlerInner_001 - * @tc.desc: GetProfileChangeHandlerInner - * @tc.type: FUNC - * @tc.require: I4NY1T - */ -HWTEST_F(SubscribeManagerTest, GetProfileChangeHandlerInner_001, TestSize.Level3) -{ - auto result = ProfileEventHandlerFactory::GetInstance().GetProfileChangeHandlerInner(); - DTEST_LOG << "result: " << result << std::endl; - EXPECT_NE(nullptr, result); -} -} -} diff --git a/old/services/core/test/unittest/test_util.cpp b/old/services/core/test/unittest/test_util.cpp deleted file mode 100644 index 3a4084c7..00000000 --- a/old/services/core/test/unittest/test_util.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * 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. - */ - -#include "test_util.h" - -#include "accesstoken_kit.h" -#include "nativetoken_kit.h" -#include "token_setproc.h" - -namespace OHOS { -namespace DeviceProfile { -void DeviceProfile::TestUtil::MockPermission(const std::string& procName) -{ - static const char *PERMS[] = { - "ohos.permission.DISTRIBUTED_DATASYNC" - }; - MockProcessAndPermission(procName.c_str(), PERMS, 1); -} - -void DeviceProfile::TestUtil::MockProcessAndPermission(const char* processName, const char *perms[], int32_t permsNum) -{ - uint64_t tokenId; - NativeTokenInfoParams infoInstance = { - .dcapsNum = 0, - .permsNum = permsNum, - .aclsNum = 0, - .dcaps = nullptr, - .perms = perms, - .acls = nullptr, - .processName = processName, - .aplStr = "system_core", - }; - tokenId = GetAccessTokenId(&infoInstance); - SetSelfTokenID(tokenId); - OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo(); -} - -void DeviceProfile::TestUtil::MockInvalidTokenID() -{ - SetSelfTokenID(Security::AccessToken::INVALID_TOKENID); -} -} -} \ No newline at end of file diff --git a/old/services/core/test/unittest/test_util.h b/old/services/core/test/unittest/test_util.h deleted file mode 100644 index 4a82fb54..00000000 --- a/old/services/core/test/unittest/test_util.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef MOCK_PERMISSION_H -#define MOCK_PERMISSION_H - -#include "iservice_registry.h" - -namespace OHOS { -namespace DeviceProfile { -class TestUtil { -public: - static void MockPermission(const std::string& procName); - static void MockProcessAndPermission(const char* processName, - const char *perms[], int32_t permsNum); - static void MockInvalidTokenID(); -}; -} -} // namespace OHOS -#endif // SAMGR_SERVICES_SAMGR_MOCK_PERMISSION_H \ No newline at end of file diff --git a/old/services/core/test/unittest/utils.h b/old/services/core/test/unittest/utils.h deleted file mode 100644 index b452d68e..00000000 --- a/old/services/core/test/unittest/utils.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DEVICE_PROFILE_UNITTEST_UTILS_H -#define OHOS_DEVICE_PROFILE_UNITTEST_UTILS_H - -namespace OHOS { -namespace DeviceProfile { -#define DTEST_LOG std::cout << __FILE__ << ":" << __LINE__ << ":" -} // namespace DeviceProfile -} // namespace OHOS - -#endif // OHOS_DEVICE_PROFILE_UNITTEST_UTILS_H \ No newline at end of file diff --git a/old/test/resource/BUILD.gn b/old/test/resource/BUILD.gn deleted file mode 100644 index 1aa2dc49..00000000 --- a/old/test/resource/BUILD.gn +++ /dev/null @@ -1,23 +0,0 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. -# 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. - -declare_args() { - device_info_manager_feature_coverage = false -} - -config("coverage_flags") { - if (device_info_manager_feature_coverage) { - cflags = [ "--coverage" ] - ldflags = [ "--coverage" ] - } -} diff --git a/old/test/resource/authority/invalid_authority.json b/old/test/resource/authority/invalid_authority.json deleted file mode 100644 index 939763d6..00000000 --- a/old/test/resource/authority/invalid_authority.json +++ /dev/null @@ -1,62 +0,0 @@ -{ - "fakeProcess1": { - "servicesAuthority": { - "all": 3 - } - }, - "fakeProcess2": { - "servicesAuthority": { - "all": true - } - }, - "fakeProcess3": { - "servicesAuthority": { - "all": "read" - } - }, - "fakeProcess4": { - "servicesAuthority": { - "specific": { - "storage": -1 - } - } - }, - "fakeProcess5": { - "servicesAuthority": { - "specific": { - "system": 4 - } - } - }, - "fakeProcess6": { - "servicesAuthority": { - "prefix": { - "camerRear": 2 - } - } - }, - "fakeProcess7": { - "interfacesAuthority": { - "fakeInterface": {} - } - }, - "fakeProcess8": { - "interfacesAuthority": { - "sync": 1 - } - }, - "fakeProcess9": { - "interfacesAuthority": { - } - }, - "fakeProcess10": { - "servicesAuthority": { - } - }, - "fakeProcess11": { - "fakeKey1": { - }, - "fakeKey2": { - } - } -} \ No newline at end of file diff --git a/old/test/resource/authority/valid_authority.json b/old/test/resource/authority/valid_authority.json deleted file mode 100644 index f7a70336..00000000 --- a/old/test/resource/authority/valid_authority.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "profile_authority_test": { - "servicesAuthority": { - "all": 1, - "specific": { - "storage": 3, - "system": 3 - }, - "prefix": { - "cameraRear": 3 - } - }, - "interfacesAuthority": { - "sync": {} - } - } -} \ No newline at end of file diff --git a/old/test/resource/ohos_test.xml b/old/test/resource/ohos_test.xml deleted file mode 100644 index 67978a3c..00000000 --- a/old/test/resource/ohos_test.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - diff --git a/old/tools/dp/BUILD.gn b/old/tools/dp/BUILD.gn deleted file mode 100644 index cae14f4d..00000000 --- a/old/tools/dp/BUILD.gn +++ /dev/null @@ -1,55 +0,0 @@ -# Copyright (c) 2021-2023 Huawei Device Co., Ltd. -# 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. - -import("//build/ohos.gni") -import("//build/ohos_var.gni") -import("//foundation/deviceprofile/device_info_manager/deviceprofile.gni") - -config("dp_tools_config") { - visibility = [ ":*" ] - include_dirs = [ "include" ] -} - -ohos_executable("dp") { - sanitize = { - cfi = true - cfi_cross_dso = true - debug = false - } - install_enable = true - - configs = [ - ":dp_tools_config", - "${old_device_profile_test}/resource:coverage_flags", - ] - - sources = [ - "src/dp_command.cpp", - "src/main.cpp", - "src/shell_command.cpp", - ] - - deps = [ - "${old_device_profile_innerkits}/core:distributed_device_profile_client", - ] - external_deps = [ - "c_utils:utils", - "dsoftbus:softbus_client", - "eventhandler:libeventhandler", - "hilog:libhilog", - "ipc:ipc_core", - ] - - part_name = "device_info_manager" - subsystem_name = "deviceprofile" -} diff --git a/old/tools/dp/include/dp_command.h b/old/tools/dp/include/dp_command.h deleted file mode 100644 index 0756dce8..00000000 --- a/old/tools/dp/include/dp_command.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef DEVICE_PROFILE_DP_COMMAND_H -#define DEVICE_PROFILE_DP_COMMAND_H - -#include -#include -#include - -#include "device_profile_log.h" -#include "errors.h" -#include "iprofile_event_callback.h" -#include "shell_command.h" - -namespace OHOS { -namespace DeviceProfile { -class DpShellCommand : public OHOS::DeviceProfile::ShellCommand { -public: - DpShellCommand(int argc, char *argv[]); - ~DpShellCommand() override {} - -private: - ErrCode CreateCommandMap() override; - ErrCode CreateMessageMap() override; - ErrCode init() override; - - ErrCode HelpCommand(); - ErrCode GetDeviceCommand(); - ErrCode QueryCommand(); - ErrCode PutCommand(); - ErrCode DeleteCommand(); - ErrCode SyncCommand(); - ErrCode SubscribeCommand(); - - int32_t HandleUnknownOption(char optopt); - int32_t HandleNormalOption(int option, std::string& deviceId, - std::string& serviceId, std::string& serviceType); - int32_t HandleSyncOption(int option, std::string& mode, - std::list& deviceIds); - int32_t HandleSubscribeOption(int option, std::string& deviceId, - std::list& serviceIds); -}; - -class ProfileEventCallback : public IProfileEventCallback { -public: - void OnSyncCompleted(const SyncResult& syncResults) override; - void OnProfileChanged(const ProfileChangeNotification& changeNotification) override; -}; -} // namespace DeviceProfile -} // namespace OHOS - -#endif // DEVICE_PROFILE_DP_COMMAND_H \ No newline at end of file diff --git a/old/tools/dp/include/shell_command.h b/old/tools/dp/include/shell_command.h deleted file mode 100644 index 3eb7b39e..00000000 --- a/old/tools/dp/include/shell_command.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef DEVICE_PROFILE_SHELL_COMMAND_H -#define DEVICE_PROFILE_SHELL_COMMAND_H - -#include -#include -#include -#include -#include -#include -#include - -#include "errors.h" - -namespace OHOS { -namespace DeviceProfile { -class ShellCommand { -public: - ShellCommand(int argc, char *argv[], std::string name); - virtual ~ShellCommand() = default; - - ErrCode OnCommand(); - std::string ExecCommand(); - std::string GetCommandErrorMsg() const; - std::string GetUnknownOptionMsg(std::string &unknownOption) const; - std::string GetMessageFromCode(int32_t code) const; - - virtual ErrCode CreateCommandMap() = 0; - virtual ErrCode CreateMessageMap() = 0; - virtual ErrCode init() = 0; - -protected: - static constexpr int MIN_ARGUMENT_NUMBER = 2; - - int argc_; - char **argv_; - - std::string cmd_; - std::vector argList_; - - std::string name_; - std::map> commandMap_; - std::map messageMap_; - - std::string resultReceiver_ = ""; -}; -} // namespace DeviceProfile -} // namespace OHOS - -#endif // DEVICE_PROFILE_SHELL_COMMAND_H \ No newline at end of file diff --git a/old/tools/dp/src/dp_command.cpp b/old/tools/dp/src/dp_command.cpp deleted file mode 100644 index 82024660..00000000 --- a/old/tools/dp/src/dp_command.cpp +++ /dev/null @@ -1,489 +0,0 @@ -/* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. - * 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. - */ - -#include "dp_command.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "device_profile_log.h" -#include "distributed_device_profile_client.h" -#include "iprofile_event_notifier.h" -#include "nlohmann/json.hpp" -#include "nlohmann/json_fwd.hpp" -#include "profile_event.h" -#include "service_characteristic_profile.h" -#include "softbus_bus_center.h" -#include "subscribe_info.h" -#include "sync_options.h" - -namespace OHOS { -namespace DeviceProfile { -namespace { -const std::string TAG = "DpShellCommand"; -const std::string DP_TOOL_NAME = "dp"; -const std::string DP_HELP_MSG = "usage: dp \n" - "These are common dp commands list:\n" - " help list available commands\n" - " getDevice list all devices\n" - " query query device info with options\n" - " put put device info with options\n" - " sync sync device info with options\n" - " delete delete device info with options\n" - " subscribe subscribe device info with options\n"; -const std::string HELP_MSG_QUERY = - "usage: dp query \n" - "options list:\n" - " -h, --help list available commands\n" - " -d query device info by a device id\n" - " -s query device info by a service id\n"; -const std::string HELP_MSG_SYNC = - "usage: dp sync \n" - "options list:\n" - " -h, --help list available commands\n" - " -d sync device info by a device ids\n" - " -m sync device info by mode\n"; -const std::string HELP_MSG_PUT = - "usage: dp put \n" - "options list:\n" - " -h, --help list available commands\n" - " -s put device info by service id\n" - " -t put device info by service type\n"; -const std::string HELP_MSG_SUBSCRIBE = - "usage: dp subscribe \n" - "options list:\n" - " -h, --help list available commands\n" - " -s subscribe device info by service ids\n" - " -d subscribe device info by device id\n"; -const std::string HELP_MSG_DELETE = - "usage: dp delete \n" - "options list:\n" - " -h, --help list available commands\n" - " -s service id to delete\n"; -constexpr int32_t API_LEVEL = 7; -constexpr int32_t SYNC_SLEEP_TIME = 10; -constexpr int32_t BASE = 10; -constexpr int32_t SUBSCRIBE_SLEEP_TIME = 120; -const std::string SHORT_OPTIONS = "hd:s:m:t:"; -const struct option LONG_OPTIONS[] = { - {"help", no_argument, nullptr, 'h'}, - {"device-id", required_argument, nullptr, 'd'}, - {"service-id", required_argument, nullptr, 's'}, - {"mode", required_argument, nullptr, 'm'}, - {"service-type", required_argument, nullptr, 't'}, - {nullptr, nullptr, nullptr, nullptr}, -}; -} - -DpShellCommand::DpShellCommand(int argc, char *argv[]) : ShellCommand(argc, argv, DP_TOOL_NAME) -{ -} - -ErrCode DpShellCommand::init() -{ - return ERR_OK; -} - -ErrCode DpShellCommand::CreateCommandMap() -{ - commandMap_ = { - {"help", std::bind(&DpShellCommand::HelpCommand, this)}, - {"getDevice", std::bind(&DpShellCommand::GetDeviceCommand, this)}, - {"query", std::bind(&DpShellCommand::QueryCommand, this)}, - {"put", std::bind(&DpShellCommand::PutCommand, this)}, - {"delete", std::bind(&DpShellCommand::DeleteCommand, this)}, - {"sync", std::bind(&DpShellCommand::SyncCommand, this)}, - {"subscribe", std::bind(&DpShellCommand::SubscribeCommand, this)}, - }; - return ERR_OK; -} - -ErrCode DpShellCommand::CreateMessageMap() -{ - messageMap_ = {}; - return ERR_OK; -} - -ErrCode DpShellCommand::HelpCommand() -{ - resultReceiver_.append(DP_HELP_MSG); - return ERR_OK; -} - -ErrCode DpShellCommand::GetDeviceCommand() -{ - resultReceiver_.append("[remote device list]\n"); - NodeBasicInfo *info = nullptr; - int32_t infoNum = 0; - int32_t ret = GetAllNodeDeviceInfo("dp", &info, &infoNum); - if (ret != ERR_OK) { - resultReceiver_.append("get remote device list error\n"); - return ret; - } - for (int32_t i = 0; i < infoNum; i++) { - if (info == nullptr) { - continue; - } - resultReceiver_.append("networkId: " + std::string(info->networkId) - + " deviceName:" + std::string(info->deviceName) + "\n"); - info++; - } - - resultReceiver_.append("[local device list]\n"); - NodeBasicInfo localInfo; - ret = GetLocalNodeDeviceInfo("dp", &localInfo); - if (ret != ERR_OK) { - resultReceiver_.append("get local device error\n"); - FreeNodeInfo(info); - return ret; - } - resultReceiver_.append("networkId: " + std::string(localInfo.networkId) - + " deviceName:" + std::string(localInfo.deviceName) + "\n"); - FreeNodeInfo(info); - return ERR_OK; -} - -ErrCode DpShellCommand::QueryCommand() -{ - int32_t result = ERR_OK; - std::string serviceType; - std::string deviceId; - std::string serviceId; - while (true) { - int option = getopt_long(argc_, argv_, SHORT_OPTIONS.c_str(), LONG_OPTIONS, nullptr); - HILOGI("option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind); - if (optind < 0 || optind > argc_) { - return OHOS::ERR_INVALID_VALUE; - } - - if (option == -1) { - break; - } - result = HandleNormalOption(option, deviceId, serviceId, serviceType); - } - - if (result == ERR_OK) { - ServiceCharacteristicProfile profile; - DistributedDeviceProfileClient::GetInstance().GetDeviceProfile(deviceId, serviceId, profile); - std::string jsonData = profile.GetCharacteristicProfileJson(); - resultReceiver_.append("ServiceId:" + profile.GetServiceId() + "\n"); - resultReceiver_.append("ServiceType:" + profile.GetServiceType() + "\n"); - resultReceiver_.append("jsonData:" + jsonData + "\n"); - } else { - resultReceiver_.append(HELP_MSG_QUERY); - } - return result; -} - -ErrCode DpShellCommand::PutCommand() -{ - int32_t result = ERR_OK; - std::string serviceType; - std::string serviceId; - std::string deviceId; - while (true) { - int option = getopt_long(argc_, argv_, SHORT_OPTIONS.c_str(), LONG_OPTIONS, nullptr); - HILOGI("option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind); - if (optind < 0 || optind > argc_) { - return OHOS::ERR_INVALID_VALUE; - } - if (option == -1) { - break; - } - result = HandleNormalOption(option, deviceId, serviceId, serviceType); - } - - if (result == ERR_OK) { - ServiceCharacteristicProfile profile; - profile.SetServiceId(serviceId); - profile.SetServiceType(serviceType); - nlohmann::json j; - j["testVersion"] = "3.0.0"; - j["testApiLevel"] = API_LEVEL; - profile.SetCharacteristicProfileJson(j.dump()); - DistributedDeviceProfileClient::GetInstance().PutDeviceProfile(profile); - } else { - resultReceiver_.append(HELP_MSG_PUT); - } - return result; -} - -ErrCode DpShellCommand::DeleteCommand() -{ - int32_t result = ERR_OK; - std::string serviceType; - std::string deviceId; - std::string serviceId; - - while (true) { - int option = getopt_long(argc_, argv_, SHORT_OPTIONS.c_str(), LONG_OPTIONS, nullptr); - HILOGI("option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind); - if (optind < 0 || optind > argc_) { - return OHOS::ERR_INVALID_VALUE; - } - - if (option == -1) { - break; - } - result = HandleNormalOption(option, deviceId, serviceId, serviceType); - } - - if (result == ERR_OK) { - DistributedDeviceProfileClient::GetInstance().DeleteDeviceProfile(serviceId); - } else { - resultReceiver_.append(HELP_MSG_DELETE); - } - return result; -} - -ErrCode DpShellCommand::SyncCommand() -{ - int32_t result = ERR_OK; - std::list deviceIds; - std::string modeStr; - while (true) { - int option = getopt_long(argc_, argv_, SHORT_OPTIONS.c_str(), LONG_OPTIONS, nullptr); - HILOGI("option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind); - if (optind < 0 || optind > argc_) { - return OHOS::ERR_INVALID_VALUE; - } - - if (option == -1) { - break; - } - result = HandleSyncOption(option, modeStr, deviceIds); - } - - if (result == ERR_OK) { - SyncOptions syncOption; - int64_t mode = strtol(modeStr.c_str(), nullptr, BASE); - syncOption.SetSyncMode((OHOS::DeviceProfile::SyncMode)mode); - for (const auto& deviceId : deviceIds) { - syncOption.AddDevice(deviceId); - } - DistributedDeviceProfileClient::GetInstance().SyncDeviceProfile(syncOption, - std::make_shared()); - sleep(SYNC_SLEEP_TIME); - HILOGI("sync end"); - } else { - resultReceiver_.append(HELP_MSG_SYNC); - } - return result; -} - -ErrCode DpShellCommand::SubscribeCommand() -{ - int32_t result = ERR_OK; - std::list serviceIds; - std::string deviceId; - while (true) { - int option = getopt_long(argc_, argv_, SHORT_OPTIONS.c_str(), LONG_OPTIONS, nullptr); - HILOGI("option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind); - if (optind < 0 || optind > argc_) { - return OHOS::ERR_INVALID_VALUE; - } - - if (option == -1) { - break; - } - result = HandleSubscribeOption(option, deviceId, serviceIds); - } - - if (result == ERR_OK) { - auto callback = std::make_shared(); - std::list subscribeInfos; - ExtraInfo extraInfo; - extraInfo["deviceId"] = deviceId; - extraInfo["serviceIds"] = serviceIds; - - SubscribeInfo info1; - info1.profileEvent = ProfileEvent::EVENT_PROFILE_CHANGED; - info1.extraInfo = std::move(extraInfo); - subscribeInfos.emplace_back(info1); - - SubscribeInfo info2; - info2.profileEvent = ProfileEvent::EVENT_SYNC_COMPLETED; - subscribeInfos.emplace_back(info2); - - std::list failedEvents; - DistributedDeviceProfileClient::GetInstance().SubscribeProfileEvents(subscribeInfos, callback, failedEvents); - sleep(SUBSCRIBE_SLEEP_TIME); - std::list profileEvents; - profileEvents.emplace_back(ProfileEvent::EVENT_PROFILE_CHANGED); - failedEvents.clear(); - DistributedDeviceProfileClient::GetInstance().UnsubscribeProfileEvents(profileEvents, callback, failedEvents); - sleep(SYNC_SLEEP_TIME); - } else { - resultReceiver_.append(HELP_MSG_SUBSCRIBE); - } - return result; -} - -int32_t DpShellCommand::HandleNormalOption(int option, std::string& deviceId, - std::string& serviceId, std::string& serviceType) -{ - HILOGI("%{public}s start, option: %{public}d", __func__, option); - int32_t result = ERR_OK; - switch (option) { - case 'h': { - if (optind - 1 < argc_) { - HILOGI("'dp query' %{public}s", argv_[optind - 1]); - } - result = OHOS::ERR_INVALID_VALUE; - break; - } - case 'd': { - if (optarg == nullptr) { - resultReceiver_.append("error: option, requires a value\n"); - result = OHOS::ERR_INVALID_VALUE; - break; - } - deviceId = optarg; - break; - } - case 's': { - if (optarg == nullptr) { - resultReceiver_.append("error: option, requires a value\n"); - result = OHOS::ERR_INVALID_VALUE; - break; - } - serviceId = optarg; - break; - } - case 't': { - if (optarg == nullptr) { - resultReceiver_.append("error: option, requires a value\n"); - result = OHOS::ERR_INVALID_VALUE; - break; - } - serviceType = optarg; - break; - } - default: { - result = OHOS::ERR_INVALID_VALUE; - HILOGE("'dp query' invalid option."); - break; - } - } - return result; -} - -int32_t DpShellCommand::HandleSyncOption(int option, std::string& mode, std::list& deviceIds) -{ - HILOGI("%{public}s start, option: %{public}d", __func__, option); - int32_t result = ERR_OK; - switch (option) { - case 'h': { - if (optind - 1 < argc_) { - HILOGI("'dp sync' %{public}s", argv_[optind - 1]); - } - result = OHOS::ERR_INVALID_VALUE; - break; - } - case 'd': { - if (optarg == nullptr) { - resultReceiver_.append("error: option, requires a value\n"); - result = OHOS::ERR_INVALID_VALUE; - break; - } - std::stringstream input(optarg); - std::string temp; - while (std::getline(input, temp, ' ')) { - deviceIds.push_back(temp); - } - break; - } - case 'm': { - if (optarg == nullptr) { - resultReceiver_.append("error: option, requires a value\n"); - result = OHOS::ERR_INVALID_VALUE; - break; - } - mode = optarg; - break; - } - default: { - result = OHOS::ERR_INVALID_VALUE; - HILOGE("'dp sync' invalid option."); - break; - } - } - return result; -} - -int32_t DpShellCommand::HandleSubscribeOption(int option, std::string& deviceId, - std::list& serviceIds) -{ - HILOGI("%{public}s start, option: %{public}d", __func__, option); - int32_t result = ERR_OK; - switch (option) { - case 'h': { - if (optind - 1 < argc_) { - HILOGI("'dp subscribe' %{public}s", argv_[optind - 1]); - } - result = OHOS::ERR_INVALID_VALUE; - break; - } - case 's': { - if (optarg == nullptr) { - resultReceiver_.append("error: option, requires a value\n"); - result = OHOS::ERR_INVALID_VALUE; - break; - } - std::stringstream input(optarg); - std::string temp; - while (std::getline(input, temp, ' ')) { - serviceIds.push_back(temp); - } - break; - } - case 'd': { - if (optarg == nullptr) { - resultReceiver_.append("error: option, requires a value\n"); - result = OHOS::ERR_INVALID_VALUE; - break; - } - deviceId = optarg; - break; - } - default: { - result = OHOS::ERR_INVALID_VALUE; - HILOGE("'dp subscribe' invalid option."); - break; - } - } - return result; -} - -void ProfileEventCallback::OnSyncCompleted(const SyncResult& syncResults) -{ - HILOGI("OnSyncCompleted"); -} - -void ProfileEventCallback::OnProfileChanged(const ProfileChangeNotification& changeNotification) -{ - HILOGI("OnProfileChanged"); -} -} // namespace DeviceProfile -} // namespace OHOS \ No newline at end of file diff --git a/old/tools/dp/src/main.cpp b/old/tools/dp/src/main.cpp deleted file mode 100644 index dc5351f1..00000000 --- a/old/tools/dp/src/main.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ - -#include "dp_command.h" - -#include -#include -#include - -#include "shell_command.h" - -using namespace std; -using namespace OHOS::DeviceProfile; - -int main(int argc, char *argv[]) -{ - DpShellCommand cmd(argc, argv); - std::cout << cmd.ExecCommand(); - return 0; -} \ No newline at end of file diff --git a/old/tools/dp/src/shell_command.cpp b/old/tools/dp/src/shell_command.cpp deleted file mode 100644 index b99589a4..00000000 --- a/old/tools/dp/src/shell_command.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * 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. - */ - -#include "shell_command.h" - -#include -#include -#include -#include -#include -#include - -#include "device_profile_log.h" - -namespace OHOS { -namespace DeviceProfile { -namespace { -const std::string TAG = "ShellCommand"; - -const std::string HELP_MSG_NO_OPTION = "error: you must specify an option at least."; -} - -ShellCommand::ShellCommand(int argc, char *argv[], std::string name) -{ - opterr = 0; - argc_ = argc; - argv_ = argv; - name_ = name; - - if (argc < MIN_ARGUMENT_NUMBER) { - cmd_ = "help"; - return; - } - cmd_ = argv[1]; - for (int i = 2; i < argc; i++) { - argList_.push_back(argv[i]); - } -} - -ErrCode ShellCommand::OnCommand() -{ - int result = ERR_OK; - - auto respond = commandMap_[cmd_]; - if (respond == nullptr) { - resultReceiver_.append(GetCommandErrorMsg()); - respond = commandMap_["help"]; - } - - if (init() == ERR_OK) { - respond(); - } else { - result = OHOS::ERR_INVALID_VALUE; - } - - return result; -} - -std::string ShellCommand::ExecCommand() -{ - int result = CreateCommandMap(); - if (result != ERR_OK) { - HILOGE("failed to create command map.\n"); - } - - result = CreateMessageMap(); - if (result != ERR_OK) { - HILOGE("failed to create message map.\n"); - } - - result = OnCommand(); - if (result != ERR_OK) { - HILOGE("failed to execute your command.\n"); - resultReceiver_ = "error: failed to execute your command.\n"; - } - - return resultReceiver_; -} - -std::string ShellCommand::GetCommandErrorMsg() const -{ - std::string commandErrorMsg = - name_ + ": '" + cmd_ + "' is not a valid " + name_ + " command. See '" + name_ + " help'.\n"; - return commandErrorMsg; -} - -std::string ShellCommand::GetUnknownOptionMsg(std::string &unknownOption) const -{ - std::string result = ""; - - if (optind < 0 || optind > argc_) { - return result; - } - - result.append("error: unknown option"); - result.append(".\n"); - return result; -} - -std::string ShellCommand::GetMessageFromCode(int32_t code) const -{ - HILOGI("[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__); - HILOGI("code = %{public}d", code); - - std::string result = ""; - if (messageMap_.find(code) != messageMap_.end()) { - std::string message = messageMap_.at(code); - if (message.size() != 0) { - result.append(message + "\n"); - } - } - HILOGI("result = %{public}s", result.c_str()); - return result; -} -} // namespace DeviceProfile -} // namespace OHOS \ No newline at end of file diff --git a/radar/test/unittest/BUILD.gn b/radar/test/unittest/BUILD.gn index 6bae4277..ed8c373c 100644 --- a/radar/test/unittest/BUILD.gn +++ b/radar/test/unittest/BUILD.gn @@ -29,6 +29,7 @@ device_profile_external_deps = [ "hilog:libhilog", "hisysevent:libhisysevent", "ipc:ipc_core", + "c_utils:utils", ] ohos_unittest("dp_radar_helper_test_new") { diff --git a/services/core/BUILD.gn b/services/core/BUILD.gn index 30b80960..57e4f072 100644 --- a/services/core/BUILD.gn +++ b/services/core/BUILD.gn @@ -97,7 +97,6 @@ ohos_shared_library("distributed_device_profile_svr") { "src/deviceprofilemanager/switch_profile_manager.cpp", "src/dfx/device_profile_dumper.cpp", "src/distributed_device_profile_service_new.cpp", - "src/distributed_device_profile_stub_new.cpp", "src/dm_adapter/dm_adapter.cpp", "src/localserviceinfomanager/local_service_info_manager.cpp", "src/multiusermanager/multi_user_manager.cpp", @@ -128,6 +127,7 @@ ohos_shared_library("distributed_device_profile_svr") { deps = [ "${device_profile_common}:distributed_device_profile_common", "${device_profile_path}/radar:device_profile_radar", + "${device_profile_innerkits}:distributed_device_profile_interfaces_ipc", ] configs = [ ":device_info_manager_config" ] @@ -163,6 +163,8 @@ ohos_shared_library("distributed_device_profile_svr") { part_name = "device_info_manager" subsystem_name = "deviceprofile" + + public_configs = [ "${device_profile_innerkits}:distributed_device_profile_interfaces_ipc_config" ] } group("unittest") { diff --git a/services/core/include/distributed_device_profile_service_new.h b/services/core/include/distributed_device_profile_service_new.h index 47531045..9d11574a 100644 --- a/services/core/include/distributed_device_profile_service_new.h +++ b/services/core/include/distributed_device_profile_service_new.h @@ -23,7 +23,7 @@ #include "device_icon_info.h" #include "device_icon_info_filter_options.h" #include "device_profile_filter_options.h" -#include "distributed_device_profile_stub_new.h" +#include "distributed_device_profile_stub.h" #include "dp_account_common_event.h" #include "event_handler.h" #include "event_runner.h" @@ -38,7 +38,7 @@ namespace OHOS { namespace DistributedDeviceProfile { -class DistributedDeviceProfileServiceNew : public SystemAbility, public DistributedDeviceProfileStubNew { +class DistributedDeviceProfileServiceNew : public SystemAbility, public DistributedDeviceProfileStub { DECLARE_SYSTEM_ABILITY(DistributedDeviceProfileServiceNew); DECLARE_SINGLE_INSTANCE_BASE(DistributedDeviceProfileServiceNew); @@ -54,7 +54,7 @@ public: int32_t UpdateAccessControlProfile(const AccessControlProfile& aclProfile) override; int32_t GetTrustDeviceProfile(const std::string& deviceId, TrustDeviceProfile& trustDeviceProfile) override; int32_t GetAllTrustDeviceProfile(std::vector& trustDeviceProfiles) override; - int32_t GetAccessControlProfile(std::map queryParams, + int32_t GetAccessControlProfile(std::map& queryParams, std::vector& accessControlProfiles) override; int32_t GetAllAccessControlProfile(std::vector& accessControlProfiles) override; int32_t GetAllAclIncludeLnnAcl(std::vector& accessControlProfiles) override; @@ -93,25 +93,25 @@ public: int32_t GetAllServiceInfoProfileList(std::vector& serviceInfoProfiles) override; int32_t GetServiceInfoProfileListByBundleName(const ServiceInfoUniqueKey& key, std::vector& serviceInfoProfiles) override; - int32_t SubscribeDeviceProfile(const SubscribeInfo& subscribeInfo) override; - int32_t UnSubscribeDeviceProfile(const SubscribeInfo& subscribeInfo) override; + int32_t SubscribeDeviceProfile(const SubscribeInfoExtension& subscribeInfoExtension) override; + int32_t UnSubscribeDeviceProfile(const SubscribeInfoExtension& subscribeInfoExtension) override; int32_t SyncDeviceProfile(const DistributedDeviceProfile::DpSyncOptions& syncOptions, - sptr syncCompletedCallback) override; - int32_t SubscribeDeviceProfileInited(int32_t saId, sptr dpInitedCallback) override; + const sptr& syncCompletedCallback) override; + int32_t SubscribeDeviceProfileInited(int32_t saId,const sptr& dpInitedCallback) override; int32_t UnSubscribeDeviceProfileInited(int32_t saId) override; int32_t SubscribePinCodeInvalid(const std::string& bundleName, int32_t pinExchangeType, - sptr pinCodeCallback) override; + const sptr& pinCodeCallback) override; int32_t UnSubscribePinCodeInvalid(const std::string& bundleName, int32_t pinExchangeType) override; - int32_t PutAllTrustedDevices(const std::vector deviceInfos) override; + int32_t PutAllTrustedDevices(const std::vector& deviceInfos) override; int32_t PutLocalServiceInfo(const LocalServiceInfo& localServiceInfo)override; int32_t UpdateLocalServiceInfo(const LocalServiceInfo& localServiceInfo)override; int32_t GetLocalServiceInfoByBundleAndPinType(const std::string& bundleName, int32_t pinExchangeType, LocalServiceInfo& localServiceInfo)override; int32_t DeleteLocalServiceInfo(const std::string& bundleName, int32_t pinExchangeType)override; - int32_t SendSubscribeInfos(std::map listenerMap) override; + int32_t SendSubscribeInfos(std::map& listenerMap) override; int32_t Dump(int32_t fd, const std::vector& args) override; - void DelayUnloadTask() override; - bool IsInited() override; + void DelayUnloadTask(); + bool IsInited(); void SubscribeAccountCommonEvent(); protected: diff --git a/services/core/include/distributed_device_profile_stub_new.h b/services/core/include/distributed_device_profile_stub_new.h deleted file mode 100644 index be823eaf..00000000 --- a/services/core/include/distributed_device_profile_stub_new.h +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2021-2025 Huawei Device Co., Ltd. - * 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. - */ - -#ifndef OHOS_DP_DISTRIBUTED_DEVICE_PROFILE_STUB_H -#define OHOS_DP_DISTRIBUTED_DEVICE_PROFILE_STUB_H - -#include -#include - -#include "iremote_stub.h" - -#include "distributed_device_profile_errors.h" -#include "i_distributed_device_profile.h" -#include "ipc_utils.h" - -namespace OHOS { -namespace DistributedDeviceProfile { -class DistributedDeviceProfileStubNew : public IRemoteStub { -public: - DistributedDeviceProfileStubNew(); - ~DistributedDeviceProfileStubNew(); - - int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override; - - int32_t PutAccessControlProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t UpdateAccessControlProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t GetTrustDeviceProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t GetAllTrustDeviceProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t GetAccessControlProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t GetAllAccessControlProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t GetAllAclIncludeLnnAclInner(MessageParcel& data, MessageParcel& reply); - int32_t DeleteAccessControlProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t PutSessionKeyInner(MessageParcel& data, MessageParcel& reply); - int32_t GetSessionKeyInner(MessageParcel& data, MessageParcel& reply); - int32_t UpdateSessionKeyInner(MessageParcel& data, MessageParcel& reply); - int32_t PutDeviceProfileBatchInner(MessageParcel& data, MessageParcel& reply); - int32_t DeleteSessionKeyInner(MessageParcel& data, MessageParcel& reply); - int32_t PutServiceProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t PutServiceProfileBatchInner(MessageParcel& data, MessageParcel& reply); - int32_t PutCharacteristicProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t PutCharacteristicProfileBatchInner(MessageParcel& data, MessageParcel& reply); - int32_t GetDeviceProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t GetServiceProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t GetCharacteristicProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t DeleteServiceProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t DeleteCharacteristicProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t SubscribeDeviceProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t UnSubscribeDeviceProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t SyncDeviceProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t SendSubscribeInfosInner(MessageParcel& data, MessageParcel& reply); - int32_t SubscribeDeviceProfileInitedInner(MessageParcel& data, MessageParcel& reply); - int32_t UnSubscribeDeviceProfileInitedInner(MessageParcel& data, MessageParcel& reply); - int32_t PutAllTrustedDevicesInner(MessageParcel& data, MessageParcel& reply); - int32_t PutLocalServiceInfoInner(MessageParcel& data, MessageParcel& reply); - int32_t UpdateLocalServiceInfoInner(MessageParcel& data, MessageParcel& reply); - int32_t GetLocalServiceInfoByBundleAndPinTypeInner(MessageParcel& data, MessageParcel& reply); - int32_t DeleteLocalServiceInfoInner(MessageParcel& data, MessageParcel& reply); - int32_t GetDeviceProfilesInner(MessageParcel& data, MessageParcel& reply); - int32_t DeleteDeviceProfileBatchInner(MessageParcel& data, MessageParcel& reply); - int32_t PutProductInfoBatchInner(MessageParcel& data, MessageParcel& reply); - int32_t PutDeviceIconInfoBatchInner(MessageParcel& data, MessageParcel& reply); - int32_t GetDeviceIconInfosInner(MessageParcel& data, MessageParcel& reply); - int32_t PutServiceInfoProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t DeleteServiceInfoProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t UpdateServiceInfoProfileInner(MessageParcel& data, MessageParcel& reply); - int32_t GetServiceInfoProfileByUniqueKeyInner(MessageParcel& data, MessageParcel& reply); - int32_t GetServiceInfoProfileListByTokenIdInner(MessageParcel& data, MessageParcel& reply); - int32_t GetAllServiceInfoProfileListInner(MessageParcel& data, MessageParcel& reply); - int32_t GetServiceInfoProfileListByBundleNameInner(MessageParcel& data, MessageParcel& reply); - int32_t SubscribePinCodeInvalidInner(MessageParcel& data, MessageParcel& reply); - int32_t UnSubscribePinCodeInvalidInner(MessageParcel& data, MessageParcel& reply); - virtual void DelayUnloadTask() = 0; - virtual bool IsInited() = 0; - -private: - using Func = int32_t(DistributedDeviceProfileStubNew::*)(MessageParcel& data, MessageParcel& reply); - bool IsInterfaceTokenValid(MessageParcel& data); - void InitAclAndSubscribe(); - int32_t NotifyEventInner(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option); - int32_t NotifyAclEventInner(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option); - int32_t NotifyProfileDataEventInner(uint32_t code, MessageParcel& data, - MessageParcel& reply, MessageOption& option); - int32_t NotifyLocalServiceEventInner(uint32_t code, MessageParcel& data, MessageParcel& reply, - MessageOption& option); -private: - std::unordered_set aclAndSubscribeFuncs_; -}; -} // namespace DeviceProfile -} // namespace OHOS -#endif // OHOS_DP_DISTRIBUTED_DEVICE_PROFILE_STUB_H diff --git a/services/core/include/subscribeprofilemanager/subscribe_profile_manager.h b/services/core/include/subscribeprofilemanager/subscribe_profile_manager.h index 9fe77633..76ec51ed 100644 --- a/services/core/include/subscribeprofilemanager/subscribe_profile_manager.h +++ b/services/core/include/subscribeprofilemanager/subscribe_profile_manager.h @@ -23,6 +23,7 @@ #include "distributed_device_profile_enums.h" #include "device_profile.h" #include "dp_subscribe_info.h" +#include "dp_subscribe_info_extension.h" #include "service_profile.h" #include "characteristic_profile.h" @@ -41,9 +42,9 @@ public: int32_t NotifyTrustDeviceProfileDelete(const TrustDeviceProfile& trustDeviceProfile); int32_t NotifyTrustDeviceProfileActive(const TrustDeviceProfile& trustDeviceProfile); int32_t NotifyTrustDeviceProfileInactive(const TrustDeviceProfile& trustDeviceProfile); - int32_t SubscribeDeviceProfile(const SubscribeInfo& subscribeInfo); - int32_t SubscribeDeviceProfile(std::map subscribeInfos); - int32_t UnSubscribeDeviceProfile(const SubscribeInfo& subscribeInfo); + int32_t SubscribeDeviceProfile(const SubscribeInfoExtension& subscribeInfo); + int32_t SubscribeDeviceProfile(std::map subscribeInfos); + int32_t UnSubscribeDeviceProfile(const SubscribeInfoExtension& subscribeInfo); private: int32_t NotifyDeviceProfileAdd(const std::string& dbKey, const std::string& dbValue); @@ -55,7 +56,7 @@ private: int32_t NotifyCharProfileAdd(const std::string& dbKey, const std::string& dbValue); int32_t NotifyCharProfileUpdate(const std::string& dbKey, const std::string& dbValue); int32_t NotifyCharProfileDelete(const std::string& dbKey, const std::string& dbValue); - std::unordered_set GetSubscribeInfos(const std::string& dbKey); + std::unordered_set GetSubscribeInfos(const std::string& dbKey); std::string DBKeyToSubcribeKey(const std::string& dbkey); private: @@ -63,7 +64,7 @@ private: std::mutex funcsMutex_; std::map funcsMap_; std::mutex subscribeMutex_; - std::map> subscribeInfoMap_; + std::map> subscribeInfoExtensionMap_; }; } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/services/core/src/distributed_device_profile_service_new.cpp b/services/core/src/distributed_device_profile_service_new.cpp index 07fb1c5d..2225f397 100644 --- a/services/core/src/distributed_device_profile_service_new.cpp +++ b/services/core/src/distributed_device_profile_service_new.cpp @@ -350,7 +350,7 @@ int32_t DistributedDeviceProfileServiceNew::GetAllTrustDeviceProfile( return ret; } -int32_t DistributedDeviceProfileServiceNew::GetAccessControlProfile(std::map queryParams, +int32_t DistributedDeviceProfileServiceNew::GetAccessControlProfile(std::map& queryParams, std::vector& accessControlProfiles) { if (!PermissionManager::GetInstance().IsCallerTrust(GET_ACCESS_CONTROL_PROFILE)) { @@ -784,32 +784,32 @@ int32_t DistributedDeviceProfileServiceNew::DeleteLocalServiceInfo(const std::st return ret; } -int32_t DistributedDeviceProfileServiceNew::SubscribeDeviceProfile(const SubscribeInfo& subscriberInfo) +int32_t DistributedDeviceProfileServiceNew::SubscribeDeviceProfile(const SubscribeInfoExtension& subscribeInfoExtension) { if (!PermissionManager::GetInstance().CheckCallerPermission()) { HILOGE("this caller is permission denied!"); return DP_PERMISSION_DENIED; } HILOGD("CheckCallerPermission success interface SubscribeDeviceProfile"); - int32_t ret = SubscribeProfileManager::GetInstance().SubscribeDeviceProfile(subscriberInfo); - DpRadarHelper::GetInstance().ReportSubscribeDeviceProfile(ret, subscriberInfo); + int32_t ret = SubscribeProfileManager::GetInstance().SubscribeDeviceProfile(subscribeInfoExtension); + DpRadarHelper::GetInstance().ReportSubscribeDeviceProfile(ret, subscribeInfoExtension); return ret; } -int32_t DistributedDeviceProfileServiceNew::UnSubscribeDeviceProfile(const SubscribeInfo& subscriberInfo) +int32_t DistributedDeviceProfileServiceNew::UnSubscribeDeviceProfile(const SubscribeInfoExtension& subscribeInfoExtension) { if (!PermissionManager::GetInstance().CheckCallerPermission()) { HILOGE("this caller is permission denied!"); return DP_PERMISSION_DENIED; } HILOGD("CheckCallerPermission success interface UnSubscribeDeviceProfile"); - int32_t ret = SubscribeProfileManager::GetInstance().UnSubscribeDeviceProfile(subscriberInfo); - DpRadarHelper::GetInstance().ReportUnSubscribeDeviceProfile(ret, subscriberInfo); + int32_t ret = SubscribeProfileManager::GetInstance().UnSubscribeDeviceProfile(subscribeInfoExtension); + DpRadarHelper::GetInstance().ReportUnSubscribeDeviceProfile(ret, subscribeInfoExtension); return ret; } int32_t DistributedDeviceProfileServiceNew::SyncDeviceProfile( - const DistributedDeviceProfile::DpSyncOptions& syncOptions, sptr syncCompletedCallback) + const DistributedDeviceProfile::DpSyncOptions& syncOptions,const sptr& syncCompletedCallback) { if (!PermissionManager::GetInstance().CheckCallerSyncPermission()) { HILOGE("this caller is permission denied!"); @@ -821,7 +821,8 @@ int32_t DistributedDeviceProfileServiceNew::SyncDeviceProfile( return ret; } -int32_t DistributedDeviceProfileServiceNew::SendSubscribeInfos(std::map listenerMap) +int32_t DistributedDeviceProfileServiceNew::SendSubscribeInfos( + std::map& listenerMap) { return SubscribeProfileManager::GetInstance().SubscribeDeviceProfile(listenerMap); } @@ -1137,7 +1138,7 @@ void DistributedDeviceProfileServiceNew::ClearProfileCache() } int32_t DistributedDeviceProfileServiceNew::SubscribeDeviceProfileInited(int32_t saId, - sptr dpInitedCallback) + const sptr & dpInitedCallback) { if (!PermissionManager::GetInstance().CheckCallerPermission()) { HILOGE("this caller is permission denied!"); @@ -1177,7 +1178,7 @@ int32_t DistributedDeviceProfileServiceNew::UnSubscribeDeviceProfileInited(int32 } int32_t DistributedDeviceProfileServiceNew::SubscribePinCodeInvalid(const std::string& bundleName, - int32_t pinExchangeType, sptr pinCodeCallback) + int32_t pinExchangeType,const sptr& pinCodeCallback) { if (!PermissionManager::GetInstance().CheckCallerPermission()) { HILOGE("this caller is permission denied!"); @@ -1268,7 +1269,7 @@ int32_t DistributedDeviceProfileServiceNew::NotifyPinCodeInvalid(const LocalServ return DP_SUCCESS; } -int32_t DistributedDeviceProfileServiceNew::PutAllTrustedDevices(const std::vector deviceInfos) +int32_t DistributedDeviceProfileServiceNew::PutAllTrustedDevices(const std::vector& deviceInfos) { if (!PermissionManager::GetInstance().IsCallerTrust(PUT_ALL_TRUSTED_DEVICES)) { HILOGE("this caller is permission denied!"); diff --git a/services/core/src/distributed_device_profile_stub_new.cpp b/services/core/src/distributed_device_profile_stub_new.cpp index 9cbacdb9..e69de29b 100644 --- a/services/core/src/distributed_device_profile_stub_new.cpp +++ b/services/core/src/distributed_device_profile_stub_new.cpp @@ -1,1057 +0,0 @@ -/* - * Copyright (c) 2021-2025 Huawei Device Co., Ltd. - * 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. - */ - -#include "distributed_device_profile_stub_new.h" - -#include - -#include "ipc_skeleton.h" -#include "ipc_utils.h" - -#include "distributed_device_profile_errors.h" -#include "distributed_device_profile_log.h" -#include "distributed_device_profile_enums.h" -#include "profile_utils.h" - -namespace OHOS { -namespace DistributedDeviceProfile { -namespace { -const std::string TAG = "DistributedDeviceProfileStubNew"; -} - -DistributedDeviceProfileStubNew::DistributedDeviceProfileStubNew() -{ - InitAclAndSubscribe(); -} - -void DistributedDeviceProfileStubNew::InitAclAndSubscribe() -{ - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::PUT_ACL_PROFILE)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::UPDATE_ACL_PROFILE)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::GET_TRUST_DEVICE_PROFILE)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::GET_ALL_TRUST_DEVICE_PROFILE)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::GET_ACL_PROFILE)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::GET_ALL_ACL_PROFILE)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::GET_ALL_ACL_INCLUDE_LNN_ACL)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::DELETE_ACL_PROFILE)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::SEND_SUBSCRIBE_INFOS)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::PUT_SERVICE_PROFILE)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::PUT_SERVICE_PROFILE_BATCH)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::PUT_CHAR_PROFILE)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::PUT_CHAR_PROFILE_BATCH)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE_INITED)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE_INITED)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::PUT_ALL_TRUSTED_DEVICES)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::PUT_DEVICE_PROFILE_BATCH)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::GET_DEVICE_PROFILES)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::DELETE_DEVICE_PROFILE_BATCH)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::GET_DEVICE_ICON_INFOS)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::PUT_DEVICE_ICON_INFO_BATCH)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::PUT_PRODUCT_INFO_BATCH)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::PUT_SESSION_KEY)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::GET_SESSION_KEY)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::UPDATE_SESSION_KEY)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::DELETE_SESSION_KEY)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::SUBSCRIBE_PINCODE_INVALID)); - aclAndSubscribeFuncs_.insert(static_cast(DPInterfaceCode::UNSUBSCRIBE_PINCODE_INVALID)); -} - -DistributedDeviceProfileStubNew::~DistributedDeviceProfileStubNew() -{ - HILOGI("destructor!"); -} - -bool DistributedDeviceProfileStubNew::IsInterfaceTokenValid(MessageParcel& data) -{ - return data.ReadInterfaceToken() == IDistributedDeviceProfile::GetDescriptor(); -} - - -int32_t DistributedDeviceProfileStubNew::NotifyAclEventInner(uint32_t code, MessageParcel& data, - MessageParcel& reply, MessageOption& option) -{ - switch (code) { - case static_cast(DPInterfaceCode::PUT_ACL_PROFILE): - return PutAccessControlProfileInner(data, reply); - case static_cast(DPInterfaceCode::UPDATE_ACL_PROFILE): - return UpdateAccessControlProfileInner(data, reply); - case static_cast(DPInterfaceCode::GET_TRUST_DEVICE_PROFILE): - return GetTrustDeviceProfileInner(data, reply); - case static_cast(DPInterfaceCode::GET_ALL_TRUST_DEVICE_PROFILE): - return GetAllTrustDeviceProfileInner(data, reply); - case static_cast(DPInterfaceCode::GET_ACL_PROFILE): - return GetAccessControlProfileInner(data, reply); - case static_cast(DPInterfaceCode::GET_ALL_ACL_PROFILE): - return GetAllAccessControlProfileInner(data, reply); - case static_cast(DPInterfaceCode::GET_ALL_ACL_INCLUDE_LNN_ACL): - return GetAllAclIncludeLnnAclInner(data, reply); - case static_cast(DPInterfaceCode::DELETE_ACL_PROFILE): - return DeleteAccessControlProfileInner(data, reply); - case static_cast(DPInterfaceCode::PUT_SESSION_KEY): - return PutSessionKeyInner(data, reply); - case static_cast(DPInterfaceCode::GET_SESSION_KEY): - return GetSessionKeyInner(data, reply); - case static_cast(DPInterfaceCode::UPDATE_SESSION_KEY): - return UpdateSessionKeyInner(data, reply); - case static_cast(DPInterfaceCode::DELETE_SESSION_KEY): - return DeleteSessionKeyInner(data, reply); - default: - return NotifyProfileDataEventInner(code, data, reply, option); - } -} - -int32_t DistributedDeviceProfileStubNew::NotifyProfileDataEventInner( - uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) -{ - switch (code) { - case static_cast(DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE): - return SubscribeDeviceProfileInner(data, reply); - case static_cast(DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE): - return UnSubscribeDeviceProfileInner(data, reply); - case static_cast(DPInterfaceCode::SEND_SUBSCRIBE_INFOS): - return SendSubscribeInfosInner(data, reply); - case static_cast(DPInterfaceCode::PUT_SERVICE_PROFILE): - return PutServiceProfileInner(data, reply); - case static_cast(DPInterfaceCode::PUT_SERVICE_PROFILE_BATCH): - return PutServiceProfileBatchInner(data, reply); - case static_cast(DPInterfaceCode::PUT_CHAR_PROFILE): - return PutCharacteristicProfileInner(data, reply); - case static_cast(DPInterfaceCode::PUT_CHAR_PROFILE_BATCH): - return PutCharacteristicProfileBatchInner(data, reply); - case static_cast(DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE_INITED): - return SubscribeDeviceProfileInitedInner(data, reply); - case static_cast(DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE_INITED): - return UnSubscribeDeviceProfileInitedInner(data, reply); - case static_cast(DPInterfaceCode::PUT_ALL_TRUSTED_DEVICES): - return PutAllTrustedDevicesInner(data, reply); - case static_cast(DPInterfaceCode::PUT_DEVICE_PROFILE_BATCH): - return PutDeviceProfileBatchInner(data, reply); - case static_cast(DPInterfaceCode::GET_DEVICE_PROFILES): - return GetDeviceProfilesInner(data, reply); - case static_cast(DPInterfaceCode::GET_DEVICE_ICON_INFOS): - return GetDeviceIconInfosInner(data, reply); - case static_cast(DPInterfaceCode::PUT_DEVICE_ICON_INFO_BATCH): - return PutDeviceIconInfoBatchInner(data, reply); - case static_cast(DPInterfaceCode::PUT_PRODUCT_INFO_BATCH): - return PutProductInfoBatchInner(data, reply); - case static_cast(DPInterfaceCode::DELETE_DEVICE_PROFILE_BATCH): - return DeleteDeviceProfileBatchInner(data, reply); - case static_cast(DPInterfaceCode::SUBSCRIBE_PINCODE_INVALID): - return SubscribePinCodeInvalidInner(data, reply); - case static_cast(DPInterfaceCode::UNSUBSCRIBE_PINCODE_INVALID): - return UnSubscribePinCodeInvalidInner(data, reply); - default: - HILOGE("unknown request code, please check, code = %{public}u", code); - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } -} - -int32_t DistributedDeviceProfileStubNew::NotifyEventInner(uint32_t code, MessageParcel& data, - MessageParcel& reply, MessageOption& option) -{ - switch (code) { - case static_cast(DPInterfaceCode::GET_DEVICE_PROFILE_NEW): - return GetDeviceProfileInner(data, reply); - case static_cast(DPInterfaceCode::GET_SERVICE_PROFILE): - return GetServiceProfileInner(data, reply); - case static_cast(DPInterfaceCode::GET_CHAR_PROFILE): - return GetCharacteristicProfileInner(data, reply); - case static_cast(DPInterfaceCode::DEL_SERVICE_PROFILE): - return DeleteServiceProfileInner(data, reply); - case static_cast(DPInterfaceCode::DEL_CHAR_PROFILE): - return DeleteCharacteristicProfileInner(data, reply); - case static_cast(DPInterfaceCode::SYNC_DEVICE_PROFILE_NEW): - return SyncDeviceProfileInner(data, reply); - case static_cast(DPInterfaceCode::PUT_SERVICE_INFO_PROFILE): - return PutServiceInfoProfileInner(data, reply); - case static_cast(DPInterfaceCode::DELETE_SERVICE_INFO_PROFILE): - return DeleteServiceInfoProfileInner(data, reply); - case static_cast(DPInterfaceCode::UPDATE_SERVICE_INFO_PROFILE): - return UpdateServiceInfoProfileInner(data, reply); - case static_cast(DPInterfaceCode::GET_SERVICE_INFO_PROFILE_BY_UNIQUE_KEY): - return GetServiceInfoProfileByUniqueKeyInner(data, reply); - case static_cast(DPInterfaceCode::GET_SERVICE_INFO_PROFILE_LIST_BY_TOKEN_ID): - return GetServiceInfoProfileListByTokenIdInner(data, reply); - case static_cast(DPInterfaceCode::GET_ALL_SERVICE_INFO_PROFILE_LIST): - return GetAllServiceInfoProfileListInner(data, reply); - case static_cast(DPInterfaceCode::GET_SERVICE_INFO_PROFILE_LIST_BY_BUNDLE_NAME): - return GetServiceInfoProfileListByBundleNameInner(data, reply); - default: - return NotifyLocalServiceEventInner(code, data, reply, option); - } -} - -int32_t DistributedDeviceProfileStubNew::NotifyLocalServiceEventInner(uint32_t code, MessageParcel& data, - MessageParcel& reply, MessageOption& option) -{ - switch (code) { - case static_cast(DPInterfaceCode::PUT_LOCAL_SERVICE_INFO): - return PutLocalServiceInfoInner(data, reply); - case static_cast(DPInterfaceCode::UPDATE_LOCAL_SERVICE_INFO): - return UpdateLocalServiceInfoInner(data, reply); - case static_cast(DPInterfaceCode::GET_LOCAL_SERVICE_INFO_BY_BINDLE_AND_PINTYPE): - return GetLocalServiceInfoByBundleAndPinTypeInner(data, reply); - case static_cast(DPInterfaceCode::DELETE_LOCAL_SERVICE_INFO): - return DeleteLocalServiceInfoInner(data, reply); - default: - HILOGW("unknown request code, please check, code = %{public}u", code); - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } -} - -int32_t DistributedDeviceProfileStubNew::OnRemoteRequest(uint32_t code, MessageParcel& data, - MessageParcel& reply, MessageOption& option) -{ - HILOGI("code = %{public}u, CallingPid = %{public}u", code, IPCSkeleton::GetCallingPid()); - DelayUnloadTask(); - if (!IsInterfaceTokenValid(data)) { - HILOGE("check interface token failed"); - return DP_INTERFACE_CHECK_FAILED; - } - if (aclAndSubscribeFuncs_.find(code) != aclAndSubscribeFuncs_.end()) { - return NotifyAclEventInner(code, data, reply, option); - } - if (!IsInited()) { - HILOGE("DP not finish init"); - return DP_LOAD_SERVICE_ERR; - } - int32_t ret = NotifyEventInner(code, data, reply, option); - return ret; -} - -int32_t DistributedDeviceProfileStubNew::PutAccessControlProfileInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - AccessControlProfile accessControlProfile; - if (!accessControlProfile.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = PutAccessControlProfile(accessControlProfile); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::UpdateAccessControlProfileInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - AccessControlProfile accessControlProfile; - if (!accessControlProfile.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = UpdateAccessControlProfile(accessControlProfile); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::GetTrustDeviceProfileInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGD("called"); - std::string deviceId; - READ_HELPER(data, String, deviceId); - TrustDeviceProfile trustDeviceProfile; - int32_t ret = GetTrustDeviceProfile(deviceId, trustDeviceProfile); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - if (!trustDeviceProfile.Marshalling(reply)) { - HILOGE("write parcel fail!"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::GetAllTrustDeviceProfileInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - std::vector trustDeviceProfiles; - int32_t ret = GetAllTrustDeviceProfile(trustDeviceProfiles); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - if (!IpcUtils::Marshalling(reply, trustDeviceProfiles)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::GetAccessControlProfileInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - std::map queryParams; - if (!IpcUtils::UnMarshalling(data, queryParams)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - std::vector accessControlProfiles; - int32_t ret = GetAccessControlProfile(queryParams, accessControlProfiles); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - if (!IpcUtils::Marshalling(reply, accessControlProfiles)) { - HILOGE("write parcel fail!"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::GetAllAccessControlProfileInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - std::vector accessControlProfiles; - int32_t ret = GetAllAccessControlProfile(accessControlProfiles); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - if (!IpcUtils::Marshalling(reply, accessControlProfiles)) { - HILOGE("write parcel fail!"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::GetAllAclIncludeLnnAclInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - std::vector accessControlProfiles; - int32_t ret = GetAllAclIncludeLnnAcl(accessControlProfiles); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - if (!IpcUtils::Marshalling(reply, accessControlProfiles)) { - HILOGE("write parcel fail!"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::DeleteAccessControlProfileInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - int32_t accessControlId; - READ_HELPER(data, Int32, accessControlId); - int32_t ret = DeleteAccessControlProfile(accessControlId); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::PutSessionKeyInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - uint32_t userId = 0; - std::vector sessionKey; - int32_t sessionKeyId = 0; - READ_HELPER(data, Uint32, userId); - if (!IpcUtils::UnMarshalling(data, sessionKey)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - int32_t ret = PutSessionKey(userId, sessionKey, sessionKeyId); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return DP_WRITE_PARCEL_FAIL; - } - WRITE_HELPER(reply, Int32, sessionKeyId); - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::GetSessionKeyInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - uint32_t userId = 0; - int32_t sessionKeyId = 0; - std::vector sessionKey; - READ_HELPER(data, Uint32, userId); - READ_HELPER(data, Int32, sessionKeyId); - int32_t ret = GetSessionKey(userId, sessionKeyId, sessionKey); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return DP_WRITE_PARCEL_FAIL; - } - if (!IpcUtils::Marshalling(reply, sessionKey)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::UpdateSessionKeyInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - uint32_t userId = 0; - std::vector sessionKey; - int32_t sessionKeyId = 0; - READ_HELPER(data, Uint32, userId); - READ_HELPER(data, Int32, sessionKeyId); - if (!IpcUtils::UnMarshalling(data, sessionKey)) { - HILOGE("dp ipc write parcel fail"); - return DP_WRITE_PARCEL_FAIL; - } - int32_t ret = UpdateSessionKey(userId, sessionKeyId, sessionKey); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::DeleteSessionKeyInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - uint32_t userId = 0; - int32_t sessionKeyId = 0; - READ_HELPER(data, Uint32, userId); - READ_HELPER(data, Int32, sessionKeyId); - int32_t ret = DeleteSessionKey(userId, sessionKeyId); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::PutServiceProfileInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - ServiceProfile serviceProfile; - if (!serviceProfile.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = PutServiceProfile(serviceProfile); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::PutServiceProfileBatchInner(MessageParcel& data, MessageParcel& reply) -{ - std::vector serviceProfiles; - if (!IpcUtils::UnMarshalling(data, serviceProfiles)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = PutServiceProfileBatch(serviceProfiles); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::PutCharacteristicProfileInner(MessageParcel& data, MessageParcel& reply) -{ - CharacteristicProfile charProfile; - if (!charProfile.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = PutCharacteristicProfile(charProfile); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::PutCharacteristicProfileBatchInner(MessageParcel& data, MessageParcel& reply) -{ - std::vector charProfiles; - if (!IpcUtils::UnMarshalling(data, charProfiles)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = PutCharacteristicProfileBatch(charProfiles); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::GetDeviceProfileInner(MessageParcel& data, MessageParcel& reply) -{ - std::string deviceId; - bool isMultiUser = false; - int32_t userId = DEFAULT_USER_ID; - DeviceProfile deviceProfile; - READ_HELPER(data, String, deviceId); - READ_HELPER(data, Bool, isMultiUser); - READ_HELPER(data, Int32, userId); - deviceProfile.SetIsMultiUser(isMultiUser); - deviceProfile.SetUserId(userId); - int32_t ret = GetDeviceProfile(deviceId, deviceProfile); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - if (!deviceProfile.Marshalling(reply)) { - HILOGE("write parcel fail!"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::GetServiceProfileInner(MessageParcel& data, MessageParcel& reply) -{ - std::string deviceId; - std::string serviceName; - bool isMultiUser = false; - int32_t userId = DEFAULT_USER_ID; - ServiceProfile serviceProfile; - READ_HELPER(data, String, deviceId); - READ_HELPER(data, String, serviceName); - READ_HELPER(data, Bool, isMultiUser); - READ_HELPER(data, Int32, userId); - serviceProfile.SetIsMultiUser(isMultiUser); - serviceProfile.SetUserId(userId); - int32_t ret = GetServiceProfile(deviceId, serviceName, serviceProfile); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - if (!serviceProfile.Marshalling(reply)) { - HILOGE("write parcel fail!"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::GetCharacteristicProfileInner(MessageParcel& data, MessageParcel& reply) -{ - std::string deviceId; - std::string serviceName; - std::string characteristicKey; - bool isMultiUser = false; - int32_t userId = DEFAULT_USER_ID; - READ_HELPER(data, String, deviceId); - READ_HELPER(data, String, serviceName); - READ_HELPER(data, String, characteristicKey); - READ_HELPER(data, Bool, isMultiUser); - READ_HELPER(data, Int32, userId); - CharacteristicProfile charProfile; - charProfile.SetIsMultiUser(isMultiUser); - charProfile.SetUserId(userId); - int32_t ret = GetCharacteristicProfile(deviceId, serviceName, characteristicKey, charProfile); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - if (!charProfile.Marshalling(reply)) { - HILOGE("write parcel fail!"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::DeleteServiceProfileInner(MessageParcel& data, MessageParcel& reply) -{ - std::string deviceId; - std::string serviceName; - bool isMultiUser = false; - int32_t userId = DEFAULT_USER_ID; - READ_HELPER(data, String, deviceId); - READ_HELPER(data, String, serviceName); - READ_HELPER(data, Bool, isMultiUser); - READ_HELPER(data, Int32, userId); - int32_t ret = DeleteServiceProfile(deviceId, serviceName, isMultiUser, userId); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::DeleteCharacteristicProfileInner(MessageParcel& data, MessageParcel& reply) -{ - std::string deviceId; - std::string serviceName; - std::string characteristicKey; - bool isMultiUser = false; - int32_t userId = DEFAULT_USER_ID; - READ_HELPER(data, String, deviceId); - READ_HELPER(data, String, serviceName); - READ_HELPER(data, String, characteristicKey); - READ_HELPER(data, Bool, isMultiUser); - READ_HELPER(data, Int32, userId); - int32_t ret = DeleteCharacteristicProfile(deviceId, serviceName, characteristicKey, isMultiUser, userId); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::SubscribeDeviceProfileInner(MessageParcel& data, MessageParcel& reply) -{ - SubscribeInfo subscribeInfo; - if (!subscribeInfo.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = SubscribeDeviceProfile(subscribeInfo); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::UnSubscribeDeviceProfileInner(MessageParcel& data, MessageParcel& reply) -{ - SubscribeInfo subscribeInfo; - if (!subscribeInfo.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = UnSubscribeDeviceProfile(subscribeInfo); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::SyncDeviceProfileInner(MessageParcel& data, MessageParcel& reply) -{ - DistributedDeviceProfile::DpSyncOptions syncOptions; - if (!syncOptions.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - sptr syncCompletedCallback = data.ReadRemoteObject(); - int32_t ret = SyncDeviceProfile(syncOptions, syncCompletedCallback); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::SendSubscribeInfosInner(MessageParcel& data, MessageParcel& reply) -{ - std::map listenerMap; - if (!IpcUtils::UnMarshalling(data, listenerMap)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = SendSubscribeInfos(listenerMap); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::SubscribeDeviceProfileInitedInner(MessageParcel& data, MessageParcel& reply) -{ - int32_t saId = -1; - READ_HELPER(data, Int32, saId); - sptr dpInitedCallback = data.ReadRemoteObject(); - if (dpInitedCallback == nullptr) { - HILOGE("read remoteObject failed!"); - return ERR_FLATTEN_OBJECT; - } - int32_t ret = SubscribeDeviceProfileInited(saId, dpInitedCallback); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::UnSubscribeDeviceProfileInitedInner(MessageParcel& data, MessageParcel& reply) -{ - int32_t saId = -1; - READ_HELPER(data, Int32, saId); - int32_t ret = UnSubscribeDeviceProfileInited(saId); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::PutAllTrustedDevicesInner(MessageParcel& data, MessageParcel& reply) -{ - std::vector deviceInfos; - if (!IpcUtils::UnMarshalling(data, deviceInfos)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = PutAllTrustedDevices(deviceInfos); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::PutLocalServiceInfoInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - LocalServiceInfo localServiceInfo; - if (!localServiceInfo.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = PutLocalServiceInfo(localServiceInfo); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::UpdateLocalServiceInfoInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - LocalServiceInfo localServiceInfo; - if (!localServiceInfo.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = UpdateLocalServiceInfo(localServiceInfo); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::GetLocalServiceInfoByBundleAndPinTypeInner(MessageParcel& data, - MessageParcel& reply) -{ - LocalServiceInfo localServiceInfo; - int32_t pinExchangeType = 0; - std::string bundleName = ""; - READ_HELPER(data, String, bundleName); - READ_HELPER(data, Int32, pinExchangeType); - int32_t ret = GetLocalServiceInfoByBundleAndPinType(bundleName, pinExchangeType, localServiceInfo); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - if (!localServiceInfo.Marshalling(reply)) { - HILOGE("write parcel fail!"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::DeleteLocalServiceInfoInner(MessageParcel& data, MessageParcel& reply) -{ - int32_t pinExchangeType = 0; - std::string bundleName = ""; - READ_HELPER(data, String, bundleName); - READ_HELPER(data, Int32, pinExchangeType); - int32_t ret = DeleteLocalServiceInfo(bundleName, pinExchangeType); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::PutDeviceProfileBatchInner(MessageParcel& data, MessageParcel& reply) -{ - std::vector deviceProfiles; - if (!IpcUtils::UnMarshalling(data, deviceProfiles)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = PutDeviceProfileBatch(deviceProfiles); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::GetDeviceProfilesInner(MessageParcel& data, MessageParcel& reply) -{ - DeviceProfileFilterOptions options; - std::vector deviceProfiles; - if (!options.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = GetDeviceProfiles(options, deviceProfiles); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - if (!IpcUtils::Marshalling(reply, deviceProfiles)) { - HILOGE("write parcel fail!"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::SubscribePinCodeInvalidInner(MessageParcel& data, MessageParcel& reply) -{ - std::string bundleName = ""; - int32_t pinExchangeType = DEFAULT_PIN_EXCHANGE_TYPE; - READ_HELPER(data, String, bundleName); - READ_HELPER(data, Int32, pinExchangeType); - sptr pincodeInvalidCallback = data.ReadRemoteObject(); - if (pincodeInvalidCallback == nullptr) { - HILOGE("read remoteObject failed!"); - return ERR_FLATTEN_OBJECT; - } - int32_t ret = SubscribePinCodeInvalid(bundleName, - pinExchangeType, pincodeInvalidCallback); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::UnSubscribePinCodeInvalidInner(MessageParcel& data, MessageParcel& reply) -{ - std::string bundleName = ""; - int32_t pinExchangeType = DEFAULT_PIN_EXCHANGE_TYPE; - READ_HELPER(data, String, bundleName); - READ_HELPER(data, Int32, pinExchangeType); - int32_t ret = UnSubscribePinCodeInvalid(bundleName, - pinExchangeType); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::PutProductInfoBatchInner(MessageParcel& data, MessageParcel& reply) -{ - std::vector productInfos; - if (!IpcUtils::UnMarshalling(data, productInfos)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = PutProductInfoBatch(productInfos); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::PutDeviceIconInfoBatchInner(MessageParcel& data, MessageParcel& reply) -{ - std::vector deviceIconInfos; - if (!IpcUtils::UnMarshalling(data, deviceIconInfos)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = PutDeviceIconInfoBatch(deviceIconInfos); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::GetDeviceIconInfosInner(MessageParcel& data, MessageParcel& reply) -{ - DeviceIconInfoFilterOptions filterOptions; - std::vector deviceIconInfos; - if (!filterOptions.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = GetDeviceIconInfos(filterOptions, - deviceIconInfos); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - if (!IpcUtils::Marshalling(reply, deviceIconInfos)) { - HILOGE("Write parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::PutServiceInfoProfileInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - ServiceInfoProfile serviceInfoProfile; - if (!serviceInfoProfile.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = PutServiceInfoProfile(serviceInfoProfile); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::DeleteServiceInfoProfileInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - ServiceInfoUniqueKey key; - if (!key.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = DeleteServiceInfoProfile(key); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::UpdateServiceInfoProfileInner(MessageParcel& data, MessageParcel& reply) -{ - HILOGI("called"); - ServiceInfoProfile serviceInfoProfile; - if (!serviceInfoProfile.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = UpdateServiceInfoProfile(serviceInfoProfile); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return DP_WRITE_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::GetServiceInfoProfileByUniqueKeyInner(MessageParcel& data, - MessageParcel& reply) -{ - ServiceInfoUniqueKey key; - ServiceInfoProfile serviceInfoProfile; - if (!key.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = GetServiceInfoProfileByUniqueKey(key, - serviceInfoProfile); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - if (!serviceInfoProfile.Marshalling(reply)) { - HILOGE("write parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::GetServiceInfoProfileListByTokenIdInner(MessageParcel& data, - MessageParcel& reply) -{ - ServiceInfoUniqueKey key; - std::vector serviceInfoProfiles; - if (!key.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = GetServiceInfoProfileListByTokenId(key, - serviceInfoProfiles); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - - if (!IpcUtils::Marshalling(reply, serviceInfoProfiles)) { - HILOGE("Write parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::GetAllServiceInfoProfileListInner(MessageParcel& data, - MessageParcel& reply) -{ - std::vector serviceInfoProfiles; - int32_t ret = GetAllServiceInfoProfileList(serviceInfoProfiles); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - - if (!IpcUtils::Marshalling(reply, serviceInfoProfiles)) { - HILOGE("Write parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::GetServiceInfoProfileListByBundleNameInner(MessageParcel& data, - MessageParcel& reply) -{ - ServiceInfoUniqueKey key; - std::vector serviceInfoProfiles; - if (!key.UnMarshalling(data)) { - HILOGE("read parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = GetServiceInfoProfileListByBundleName(key, - serviceInfoProfiles); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - - if (!IpcUtils::Marshalling(reply, serviceInfoProfiles)) { - HILOGE("Write parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - return DP_SUCCESS; -} - -int32_t DistributedDeviceProfileStubNew::DeleteDeviceProfileBatchInner(MessageParcel& data, MessageParcel& reply) -{ - std::vector deviceProfiles; - if (!IpcUtils::UnMarshalling(data, deviceProfiles)) { - HILOGE("Write parcel fail!"); - return DP_READ_PARCEL_FAIL; - } - int32_t ret = DeleteDeviceProfileBatch(deviceProfiles); - if (!reply.WriteInt32(ret)) { - HILOGE("Write reply failed"); - return ERR_FLATTEN_OBJECT; - } - return DP_SUCCESS; -} -} // namespace DeviceProfile -} // namespace OHOS diff --git a/services/core/src/subscribeprofilemanager/subscribe_profile_manager.cpp b/services/core/src/subscribeprofilemanager/subscribe_profile_manager.cpp index 06cebceb..f636b8f5 100644 --- a/services/core/src/subscribeprofilemanager/subscribe_profile_manager.cpp +++ b/services/core/src/subscribeprofilemanager/subscribe_profile_manager.cpp @@ -59,7 +59,7 @@ int32_t SubscribeProfileManager::UnInit() HILOGI("call!"); { std::lock_guard lockGuard(subscribeMutex_); - subscribeInfoMap_.clear(); + subscribeInfoExtensionMap_.clear(); } { std::lock_guard lockGuard(funcsMutex_); @@ -199,32 +199,32 @@ int32_t SubscribeProfileManager::NotifyTrustDeviceProfileInactive(const TrustDev return DP_SUCCESS; } -int32_t SubscribeProfileManager::SubscribeDeviceProfile(const SubscribeInfo& subscribeInfo) +int32_t SubscribeProfileManager::SubscribeDeviceProfile(const SubscribeInfoExtension& subscribeInfo) { HILOGI("saId: %{public}d!, subscribeKey: %{public}s", subscribeInfo.GetSaId(), ProfileUtils::GetDbKeyAnonyString(subscribeInfo.GetSubscribeKey()).c_str()); { std::lock_guard lock(subscribeMutex_); - if (subscribeInfoMap_.size() > MAX_LISTENER_SIZE) { - HILOGE("SubscribeInfoMap size is invalid!size: %{public}zu!", subscribeInfoMap_.size()); + if (subscribeInfoExtensionMap_.size() > MAX_LISTENER_SIZE) { + HILOGE("SubscribeInfoMap size is invalid!size: %{public}zu!", subscribeInfoExtensionMap_.size()); return DP_EXCEED_MAX_SIZE_FAIL; } - if (subscribeInfoMap_[subscribeInfo.GetSubscribeKey()].size() > MAX_LISTENER_SIZE) { + if (subscribeInfoExtensionMap_[subscribeInfo.GetSubscribeKey()].size() > MAX_LISTENER_SIZE) { HILOGE("SubscribeInfoMap size is invalid!size: %{public}zu!", - subscribeInfoMap_[subscribeInfo.GetSubscribeKey()].size()); + subscribeInfoExtensionMap_[subscribeInfo.GetSubscribeKey()].size()); return DP_EXCEED_MAX_SIZE_FAIL; } - if (subscribeInfoMap_[subscribeInfo.GetSubscribeKey()].find(subscribeInfo) != - subscribeInfoMap_[subscribeInfo.GetSubscribeKey()].end()) { + if (subscribeInfoExtensionMap_[subscribeInfo.GetSubscribeKey()].find(subscribeInfo) != + subscribeInfoExtensionMap_[subscribeInfo.GetSubscribeKey()].end()) { HILOGI("this sa subscribeInfo is exist, saId : %{public}d", subscribeInfo.GetSaId()); - subscribeInfoMap_[subscribeInfo.GetSubscribeKey()].erase(subscribeInfo); + subscribeInfoExtensionMap_[subscribeInfo.GetSubscribeKey()].erase(subscribeInfo); } - subscribeInfoMap_[subscribeInfo.GetSubscribeKey()].emplace(subscribeInfo); + subscribeInfoExtensionMap_[subscribeInfo.GetSubscribeKey()].emplace(subscribeInfo); } return DP_SUCCESS; } -int32_t SubscribeProfileManager::SubscribeDeviceProfile(std::map subscribeInfos) +int32_t SubscribeProfileManager::SubscribeDeviceProfile(std::map subscribeInfos) { HILOGD("call!"); for (auto item : subscribeInfos) { @@ -233,16 +233,16 @@ int32_t SubscribeProfileManager::SubscribeDeviceProfile(std::map lock(subscribeMutex_); - if (subscribeInfoMap_.find(subscribeInfo.GetSubscribeKey()) != subscribeInfoMap_.end()) { - subscribeInfoMap_[subscribeInfo.GetSubscribeKey()].erase(subscribeInfo); - if (subscribeInfoMap_[subscribeInfo.GetSubscribeKey()].empty()) { - subscribeInfoMap_.erase(subscribeInfo.GetSubscribeKey()); + if (subscribeInfoExtensionMap_.find(subscribeInfo.GetSubscribeKey()) != subscribeInfoExtensionMap_.end()) { + subscribeInfoExtensionMap_[subscribeInfo.GetSubscribeKey()].erase(subscribeInfo); + if (subscribeInfoExtensionMap_[subscribeInfo.GetSubscribeKey()].empty()) { + subscribeInfoExtensionMap_.erase(subscribeInfo.GetSubscribeKey()); } } } @@ -514,16 +514,16 @@ int32_t SubscribeProfileManager::NotifyCharProfileDelete(const std::string& dbKe } return DP_SUCCESS; } -std::unordered_set SubscribeProfileManager::GetSubscribeInfos( +std::unordered_set SubscribeProfileManager::GetSubscribeInfos( const std::string& dbKey) { { std::lock_guard lock(subscribeMutex_); - if (subscribeInfoMap_.find(dbKey) == subscribeInfoMap_.end()) { + if (subscribeInfoExtensionMap_.find(dbKey) == subscribeInfoExtensionMap_.end()) { HILOGD("This dbKey is not subscribed, dbKey: %{public}s", ProfileUtils::GetDbKeyAnonyString(dbKey).c_str()); return {}; } - return subscribeInfoMap_[dbKey]; + return subscribeInfoExtensionMap_[dbKey]; } } diff --git a/services/core/test/BUILD.gn b/services/core/test/BUILD.gn index 5d82a44f..088fe7cb 100644 --- a/services/core/test/BUILD.gn +++ b/services/core/test/BUILD.gn @@ -324,20 +324,6 @@ ohos_unittest("dp_dm_adapter_test") { subsystem_name = "deviceprofile" } -ohos_unittest("distributed_device_profile_stub_new_test") { - module_out_path = module_output_path - sources = [ "unittest/distributed_device_profile_stub_new_test.cpp" ] - configs = device_profile_configs - deps = device_profile_deps - external_deps = device_profile_external_deps - part_name = "device_info_manager" - subsystem_name = "deviceprofile" - cflags = [ - "-Dprivate=public", - "-Dprotected=public", - ] -} - ohos_unittest("content_sensor_manager_utils_test") { module_out_path = module_output_path sources = [ "unittest/content_sensor_manager_utils_test.cpp" ] @@ -504,7 +490,6 @@ group("unittest") { ":device_profile_locd_callback_test", ":device_profile_manager_new_test", ":distributed_device_profile_client_kv_new_test", - ":distributed_device_profile_stub_new_test", ":dp_account_common_event_test", ":dp_content_sensor_test", ":dp_dm_adapter_test", diff --git a/services/core/test/fuzztest/newdeviceprofile_fuzzer/new_device_profile_fuzzer.cpp b/services/core/test/fuzztest/newdeviceprofile_fuzzer/new_device_profile_fuzzer.cpp index 56b98343..b2707cfb 100644 --- a/services/core/test/fuzztest/newdeviceprofile_fuzzer/new_device_profile_fuzzer.cpp +++ b/services/core/test/fuzztest/newdeviceprofile_fuzzer/new_device_profile_fuzzer.cpp @@ -101,7 +101,6 @@ void FuzzDeviceProfile(const uint8_t* rawData, size_t size) code += MIN_INTERFACE_CODE; } DistributedDeviceProfileServiceNew::GetInstance().OnRemoteRequest(code, data, reply, option); - DistributedDeviceProfileServiceNew::GetInstance().NotifyEventInner(code, data, reply, option); } } } diff --git a/services/core/test/unittest/distributed_device_profile_stub_new_test.cpp b/services/core/test/unittest/distributed_device_profile_stub_new_test.cpp deleted file mode 100644 index 4c77e733..00000000 --- a/services/core/test/unittest/distributed_device_profile_stub_new_test.cpp +++ /dev/null @@ -1,1132 +0,0 @@ -/* - * Copyright (c) 2024-2025 Huawei Device Co., Ltd. - * 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. - */ - -#include -#include -#include -#include -#include -#include - -#include "profile_utils.h" -#include "distributed_device_profile_constants.h" -#include "distributed_device_profile_client.h" -#include "distributed_device_profile_log.h" -#include "distributed_device_profile_errors.h" -#include "distributed_device_profile_enums.h" -#include "distributed_device_profile_stub_new.h" - -namespace OHOS { -namespace DistributedDeviceProfile { -using namespace testing::ext; -using namespace std; - -class MockDistributedDeviceProfileStubNew : public DistributedDeviceProfileStubNew { - int32_t PutAccessControlProfile(const AccessControlProfile& aclProfile) override; - int32_t UpdateAccessControlProfile(const AccessControlProfile& aclProfile) override; - int32_t GetTrustDeviceProfile(const std::string& deviceId, TrustDeviceProfile& trustDeviceProfile) override; - int32_t GetAllTrustDeviceProfile(std::vector& trustDeviceProfiles) override; - int32_t GetAccessControlProfile(std::map queryParams, - std::vector& accessControlProfiles) override; - int32_t GetAllAccessControlProfile(std::vector& accessControlProfiles) override; - int32_t GetAllAclIncludeLnnAcl(std::vector& accessControlProfiles) override; - int32_t DeleteAccessControlProfile(int32_t accessControlId) override; - int32_t PutSessionKey(uint32_t userId, const std::vector& sessionKey, int32_t& sessionKeyId) override; - int32_t GetSessionKey(uint32_t userId, int32_t sessionKeyId, std::vector& sessionKey) override; - int32_t UpdateSessionKey(uint32_t userId, int32_t sessionKeyId, const std::vector& sessionKey) override; - int32_t DeleteSessionKey(uint32_t userId, int32_t sessionKeyId) override; - int32_t PutServiceProfile(const ServiceProfile& serviceProfile) override; - int32_t PutServiceProfileBatch(const std::vector& serviceProfiles) override; - int32_t PutCharacteristicProfile(const CharacteristicProfile& charProfile) override; - int32_t PutCharacteristicProfileBatch(const std::vector& charProfiles) override; - int32_t GetDeviceProfile(const std::string& deviceId, DeviceProfile& deviceProfile) override; - int32_t DeleteDeviceProfileBatch(std::vector& deviceProfiles) override; - int32_t GetServiceProfile(const std::string& deviceId, const std::string& serviceName, - ServiceProfile& serviceProfile) override; - int32_t GetCharacteristicProfile(const std::string& deviceId, const std::string& serviceName, - const std::string& characteristicId, CharacteristicProfile& charProfile) override; - int32_t DeleteServiceProfile(const std::string& deviceId, const std::string& serviceName, bool isMultiUser = false, - int32_t userId = DEFAULT_USER_ID) override; - int32_t DeleteCharacteristicProfile(const std::string& deviceId, const std::string& serviceName, - const std::string& characteristicId, bool isMultiUser = false, int32_t userId = DEFAULT_USER_ID) override; - int32_t SubscribeDeviceProfile(const SubscribeInfo& subscribeInfo) override; - int32_t UnSubscribeDeviceProfile(const SubscribeInfo& subscribeInfo) override; - int32_t SubscribeDeviceProfileInited(int32_t saId, sptr dpInitedCallback) override; - int32_t UnSubscribeDeviceProfileInited(int32_t saId) override; - int32_t SubscribePinCodeInvalid(const std::string& bundleName, int32_t pinExchangeType, - sptr pinCodeCallback) override; - int32_t UnSubscribePinCodeInvalid(const std::string& bundleName, int32_t pinExchangeType) override; - int32_t PutAllTrustedDevices(const std::vector deviceInfos) override; - int32_t SyncDeviceProfile(const DistributedDeviceProfile::DpSyncOptions& syncOptions, - sptr syncCompletedCallback) override; - int32_t SendSubscribeInfos(std::map listenerMap) override; - int32_t PutDeviceProfileBatch(std::vector& deviceProfiles) override; - int32_t GetDeviceProfiles(DeviceProfileFilterOptions& options, - std::vector& deviceProfiles) override; - int32_t PutProductInfoBatch(const std::vector& productInfos) override; - int32_t PutDeviceIconInfoBatch(const std::vector& deviceIconInfos) override; - int32_t GetDeviceIconInfos(const DeviceIconInfoFilterOptions& filterOptions, - std::vector& deviceIconInfos) override; - int32_t PutServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) override; - int32_t DeleteServiceInfoProfile(const ServiceInfoUniqueKey& key) override; - int32_t UpdateServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) override; - int32_t GetServiceInfoProfileByUniqueKey(const ServiceInfoUniqueKey& key, - ServiceInfoProfile& serviceInfoProfile) override; - int32_t GetServiceInfoProfileListByTokenId(const ServiceInfoUniqueKey& key, - std::vector& serviceInfoProfiles) override; - int32_t GetAllServiceInfoProfileList(std::vector& serviceInfoProfiles) override; - int32_t GetServiceInfoProfileListByBundleName(const ServiceInfoUniqueKey& key, - std::vector& serviceInfoProfiles) override; - int32_t PutLocalServiceInfo(const LocalServiceInfo& localServiceInfo) override; - int32_t UpdateLocalServiceInfo(const LocalServiceInfo& localServiceInfo) override; - int32_t GetLocalServiceInfoByBundleAndPinType(const std::string& bundleName, - int32_t pinExchangeType, LocalServiceInfo& localServiceInfo) override; - int32_t DeleteLocalServiceInfo(const std::string& bundleName, int32_t pinExchangeType) override; - void DelayUnloadTask() override; - bool IsInited() override; -}; - -class DistributedDeviceProfileStubNewTest : public testing::Test { -public: - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - - std::shared_ptr ProfileStub_ = nullptr; -}; - -void DistributedDeviceProfileStubNewTest::SetUpTestCase(void) -{ -} - -void DistributedDeviceProfileStubNewTest::TearDownTestCase(void) -{ -} - -void DistributedDeviceProfileStubNewTest::SetUp() -{ - ProfileStub_ = std::make_shared(); -} - -void DistributedDeviceProfileStubNewTest::TearDown() -{ - ProfileStub_ = nullptr; -} - -int32_t MockDistributedDeviceProfileStubNew::PutAccessControlProfile(const AccessControlProfile& aclProfile) -{ - (void)aclProfile; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::UpdateAccessControlProfile(const AccessControlProfile& aclProfile) -{ - (void)aclProfile; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::GetTrustDeviceProfile(const std::string& deviceId, - TrustDeviceProfile& trustDeviceProfile) -{ - (void)deviceId; - (void)trustDeviceProfile; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::GetAllTrustDeviceProfile( - std::vector& trustDeviceProfiles) -{ - (void)trustDeviceProfiles; - return 0; -} - -int32_t MockDistributedDeviceProfileStubNew::DeleteDeviceProfileBatch(std::vector& deviceProfiles) -{ - (void)deviceProfiles; - return 0; -} - -int32_t MockDistributedDeviceProfileStubNew::GetAccessControlProfile(std::map queryParams, - std::vector& accessControlProfiles) -{ - (void)queryParams; - (void)accessControlProfiles; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::GetAllAccessControlProfile( - std::vector& accessControlProfiles) -{ - (void)accessControlProfiles; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::GetAllAclIncludeLnnAcl( - std::vector& accessControlProfiles) -{ - (void)accessControlProfiles; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::DeleteAccessControlProfile(int32_t accessControlId) -{ - (void)accessControlId; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::PutSessionKey( - uint32_t userId, const std::vector& sessionKey, int32_t& sessionKeyId) -{ - (void)userId; - (void)sessionKey; - (void)sessionKeyId; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::GetSessionKey( - uint32_t userId, int32_t sessionKeyId, std::vector& sessionKey) -{ - (void)userId; - (void)sessionKey; - (void)sessionKeyId; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::UpdateSessionKey( - uint32_t userId, int32_t sessionKeyId, const std::vector& sessionKey) -{ - (void)userId; - (void)sessionKey; - (void)sessionKeyId; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::DeleteSessionKey(uint32_t userId, int32_t sessionKeyId) -{ - (void)userId; - (void)sessionKeyId; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::PutServiceProfile(const ServiceProfile& serviceProfile) -{ - (void)serviceProfile; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::PutServiceProfileBatch(const std::vector& serviceProfiles) -{ - (void)serviceProfiles; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::PutCharacteristicProfile(const CharacteristicProfile& charProfile) -{ - (void)charProfile; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::PutCharacteristicProfileBatch( - const std::vector& charProfiles) -{ - (void)charProfiles; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::GetDeviceProfile(const std::string& deviceId, - DeviceProfile& deviceProfile) -{ - (void)deviceId; - (void)deviceProfile; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::GetServiceProfile(const std::string& deviceId, - const std::string& serviceName, ServiceProfile& serviceProfile) -{ - (void)deviceId; - (void)serviceName; - (void)serviceProfile; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::GetCharacteristicProfile(const std::string& deviceId, - const std::string& serviceName, const std::string& characteristicId, CharacteristicProfile& charProfile) -{ - (void)deviceId; - (void)serviceName; - (void)characteristicId; - (void)charProfile; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::DeleteServiceProfile(const std::string& deviceId, - const std::string& serviceName, bool isMultiUser, int32_t userId) -{ - (void)deviceId; - (void)serviceName; - (void)isMultiUser; - (void)userId; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::DeleteCharacteristicProfile(const std::string& deviceId, - const std::string& serviceName, const std::string& characteristicId, bool isMultiUser, int32_t userId) -{ - (void)deviceId; - (void)serviceName; - (void)characteristicId; - (void)isMultiUser; - (void)userId; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::SubscribeDeviceProfile(const SubscribeInfo& subscribeInfo) -{ - (void)subscribeInfo; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::UnSubscribeDeviceProfile(const SubscribeInfo& subscribeInfo) -{ - (void)subscribeInfo; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::SubscribeDeviceProfileInited(int32_t saId, - sptr dpInitedCallback) -{ - (void)saId; - (void)dpInitedCallback; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::UnSubscribeDeviceProfileInited(int32_t saId) -{ - (void)saId; - return 0; -} - -int32_t MockDistributedDeviceProfileStubNew::SubscribePinCodeInvalid(const std::string& bundleName, - int32_t pinExchangeType, sptr pinCodeCallback) -{ - (void)bundleName; - (void)pinExchangeType; - (void)pinCodeCallback; - return 0; -} - -int32_t MockDistributedDeviceProfileStubNew::UnSubscribePinCodeInvalid(const std::string& bundleName, - int32_t pinExchangeType) -{ - (void)bundleName; - (void)pinExchangeType; - return 0; -} - -int32_t MockDistributedDeviceProfileStubNew::PutAllTrustedDevices(const std::vector deviceInfos) -{ - (void)deviceInfos; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::SyncDeviceProfile( - const DistributedDeviceProfile::DpSyncOptions& syncOptions, sptr syncCompletedCallback) -{ - (void)syncOptions; - (void)syncCompletedCallback; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::SendSubscribeInfos(std::map listenerMap) -{ - (void)listenerMap; - return 0; -} -void MockDistributedDeviceProfileStubNew::DelayUnloadTask() -{ - return; -} -bool MockDistributedDeviceProfileStubNew::IsInited() -{ - return true; -} - -int32_t MockDistributedDeviceProfileStubNew::GetDeviceProfiles(DeviceProfileFilterOptions& options, - std::vector& deviceProfiles) -{ - (void)options; - (void)deviceProfiles; - return 0; -} - -int32_t MockDistributedDeviceProfileStubNew::PutDeviceProfileBatch(std::vector& deviceProfiles) -{ - (void)deviceProfiles; - return 0; -} - -int32_t MockDistributedDeviceProfileStubNew::PutProductInfoBatch(const std::vector& productInfos) -{ - (void)productInfos; - return 0; -} - -int32_t MockDistributedDeviceProfileStubNew::PutDeviceIconInfoBatch(const std::vector& deviceIconInfos) -{ - (void)deviceIconInfos; - return 0; -} - -int32_t MockDistributedDeviceProfileStubNew::GetDeviceIconInfos(const DeviceIconInfoFilterOptions& filterOptions, - std::vector& deviceIconInfos) -{ - (void)filterOptions; - (void)deviceIconInfos; - return 0; -} - -int32_t MockDistributedDeviceProfileStubNew::PutServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) -{ - (void)serviceInfoProfile; - return 0; -} - -int32_t MockDistributedDeviceProfileStubNew::DeleteServiceInfoProfile(const ServiceInfoUniqueKey& key) -{ - (void)key; - return 0; -} - -int32_t MockDistributedDeviceProfileStubNew::UpdateServiceInfoProfile(const ServiceInfoProfile& serviceInfoProfile) -{ - (void)serviceInfoProfile; - return 0; -} - -int32_t MockDistributedDeviceProfileStubNew::GetServiceInfoProfileByUniqueKey(const ServiceInfoUniqueKey& key, - ServiceInfoProfile& serviceInfoProfile) -{ - (void)key; - (void)serviceInfoProfile; - return 0; -} - -int32_t MockDistributedDeviceProfileStubNew::GetServiceInfoProfileListByTokenId(const ServiceInfoUniqueKey& key, - std::vector& serviceInfoProfiles) -{ - (void)key; - (void)serviceInfoProfiles; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::GetAllServiceInfoProfileList( - std::vector& serviceInfoProfiles) -{ - (void)serviceInfoProfiles; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::GetServiceInfoProfileListByBundleName(const ServiceInfoUniqueKey& key, - std::vector& serviceInfoProfiles) -{ - (void)key; - (void)serviceInfoProfiles; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::PutLocalServiceInfo(const LocalServiceInfo& localServiceInfo) -{ - (void)localServiceInfo; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::UpdateLocalServiceInfo(const LocalServiceInfo& localServiceInfo) -{ - (void)localServiceInfo; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::GetLocalServiceInfoByBundleAndPinType(const std::string& bundleName, - int32_t pinExchangeType, LocalServiceInfo& localServiceInfo) -{ - (void)bundleName; - (void)pinExchangeType; - (void)localServiceInfo; - return 0; -} -int32_t MockDistributedDeviceProfileStubNew::DeleteLocalServiceInfo(const std::string& bundleName, - int32_t pinExchangeType) -{ - (void)bundleName; - (void)pinExchangeType; - return 0; -} -/** - * @tc.name: IsInterfaceTokenValid001 - * @tc.desc: IsInterfaceTokenValid - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, IsInterfaceTokenValid_001, TestSize.Level1) -{ - std::shared_ptr devProStubNew = - std::make_shared(); - - MessageParcel data; - bool ret = ProfileStub_->IsInterfaceTokenValid(data); - EXPECT_EQ(false, ret); -} - -/** - * @tc.name: OnRemoteRequest001 - * @tc.desc: OnRemoteRequest - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, OnRemoteRequest_001, TestSize.Level1) -{ - uint32_t code = static_cast(DPInterfaceCode::ON_TRUST_DEVICE_PROFILE_ADD); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->OnRemoteRequest(code, data, reply, option); - EXPECT_EQ(DP_INTERFACE_CHECK_FAILED, ret); -} - -/** - * @tc.name: OnRemoteRequest002 - * @tc.desc: OnRemoteRequest - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, OnRemoteRequest_002, TestSize.Level1) -{ - uint32_t code = static_cast(DPInterfaceCode::PUT_ACL_PROFILE); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->OnRemoteRequest(code, data, reply, option); - EXPECT_EQ(DP_INTERFACE_CHECK_FAILED, ret); -} - -/** - * @tc.name: PutAccessControlProfileInner001 - * @tc.desc: PutAccessControlProfileInner - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, PutAccessControlProfileInner_001, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - int32_t ret = ProfileStub_->PutAccessControlProfileInner(data, reply); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: UpdateAccessControlProfileInner001 - * @tc.desc: UpdateAccessControlProfileInner - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, UpdateAccessControlProfileInner_001, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - int32_t ret = ProfileStub_->UpdateAccessControlProfileInner(data, reply); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: GetTrustDeviceProfileInner001 - * @tc.desc: GetTrustDeviceProfileInner - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, GetTrustDeviceProfileInner_001, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - int32_t ret = ProfileStub_->GetTrustDeviceProfileInner(data, reply); - EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); -} - -/** - * @tc.name: GetAllTrustDeviceProfileInner001 - * @tc.desc: GetAllTrustDeviceProfileInner - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, GetAllTrustDeviceProfileInner_001, TestSize.Level1) -{ - std::string udid = "udid"; - std::string serviceId = "serviceId"; - MessageParcel data; - MessageParcel reply; - data.WriteString(udid); - data.WriteString(serviceId); - int32_t ret = ProfileStub_->GetAllTrustDeviceProfileInner(data, reply); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: GetAccessControlProfileInner001 - * @tc.desc: GetAccessControlProfileInner - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, GetAccessControlProfileInner_001, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - int32_t ret = ProfileStub_->GetAccessControlProfileInner(data, reply); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: GetAllAccessControlProfileInner001 - * @tc.desc: GetAllAccessControlProfileInner - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, GetAllAccessControlProfileInner_001, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - int32_t ret = ProfileStub_->GetAllAccessControlProfileInner(data, reply); - EXPECT_EQ(DP_WRITE_PARCEL_FAIL, ret); -} - -/** - * @tc.name: DeleteAccessControlProfileInner001 - * @tc.desc: DeleteAccessControlProfileInner - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, DeleteAccessControlProfileInner_001, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - int32_t ret = ProfileStub_->DeleteAccessControlProfileInner(data, reply); - EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); -} - -/** - * @tc.name: PutServiceProfileInner001 - * @tc.desc: PutServiceProfileInner - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, PutServiceProfileInner_001, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - int32_t ret = ProfileStub_->PutServiceProfileInner(data, reply); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: PutServiceProfileBatchInner001 - * @tc.desc: PutServiceProfileBatchInner - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, PutServiceProfileBatchInner_001, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - int32_t ret = ProfileStub_->PutServiceProfileBatchInner(data, reply); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: PutCharacteristicProfileBatchInner001 - * @tc.desc: PutCharacteristicProfileBatchInner - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, PutCharacteristicProfileBatchInner_001, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - int32_t ret = ProfileStub_->PutCharacteristicProfileBatchInner(data, reply); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: GetDeviceProfileInner001 - * @tc.desc: GetDeviceProfileInner - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, GetDeviceProfileInner_001, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - int32_t ret = ProfileStub_->GetDeviceProfileInner(data, reply); - EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); -} - -/** - * @tc.name: GetServiceProfileInner001 - * @tc.desc: GetServiceProfileInner - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, GetServiceProfileInner_001, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - int32_t ret = ProfileStub_->GetServiceProfileInner(data, reply); - EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); -} - -/** - * @tc.name: GetCharacteristicProfileInner001 - * @tc.desc: GetCharacteristicProfileInner - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, GetCharacteristicProfileInner_001, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - int32_t ret = ProfileStub_->GetCharacteristicProfileInner(data, reply); - EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); -} - -/** - * @tc.name: DeleteServiceProfileInner001 - * @tc.desc: DeleteServiceProfileInner - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, DeleteServiceProfileInner_001, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - int32_t ret = ProfileStub_->DeleteServiceProfileInner(data, reply); - EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); -} - -/** - * @tc.name: DeleteCharacteristicProfileInner001 - * @tc.desc: DeleteCharacteristicProfileInner - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, DeleteCharacteristicProfileInner_001, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - int32_t ret = ProfileStub_->DeleteServiceProfileInner(data, reply); - EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); -} - -/** - * @tc.name: SubscribeDeviceProfileInner001 - * @tc.desc: SubscribeDeviceProfileInner - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, SubscribeDeviceProfileInner_001, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - int32_t ret = ProfileStub_->SubscribeDeviceProfileInner(data, reply); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: UnSubscribeDeviceProfileInner001 - * @tc.desc: UnSubscribeDeviceProfileInner - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, UnSubscribeDeviceProfileInner_001, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - int32_t ret = ProfileStub_->UnSubscribeDeviceProfileInner(data, reply); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: SyncDeviceProfileInner001 - * @tc.desc: SyncDeviceProfileInner - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, SyncDeviceProfileInner_001, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - int32_t ret = ProfileStub_->SyncDeviceProfileInner(data, reply); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: SendSubscribeInfosInner001 - * @tc.desc: SendSubscribeInfosInner - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, SendSubscribeInfosInner_001, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - int32_t ret = ProfileStub_->SendSubscribeInfosInner(data, reply); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: NotifyAclEventInner_001 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_001, TestSize.Level0) -{ - uint32_t code = 1000; - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(305, ret); -} - -/** - * @tc.name: NotifyAclEventInner_002 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_002, TestSize.Level0) -{ - uint32_t code = static_cast(DPInterfaceCode::PUT_ACL_PROFILE); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: NotifyAclEventInner_003 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_003, TestSize.Level0) -{ - uint32_t code = static_cast(DPInterfaceCode::UPDATE_ACL_PROFILE); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: NotifyAclEventInner_004 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_004, TestSize.Level0) -{ - uint32_t code = static_cast(DPInterfaceCode::GET_TRUST_DEVICE_PROFILE); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); -} - -/** - * @tc.name: NotifyAclEventInner_005 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_005, TestSize.Level0) -{ - uint32_t code = static_cast(DPInterfaceCode::GET_ALL_TRUST_DEVICE_PROFILE); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: NotifyAclEventInner_006 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_006, TestSize.Level0) -{ - uint32_t code = static_cast(DPInterfaceCode::GET_ACL_PROFILE); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: NotifyAclEventInner_007 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_007, TestSize.Level0) -{ - uint32_t code = static_cast(DPInterfaceCode::GET_ALL_ACL_PROFILE); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(DP_WRITE_PARCEL_FAIL, ret); -} - -/** - * @tc.name: NotifyAclEventInner_008 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_008, TestSize.Level0) -{ - uint32_t code = static_cast(DPInterfaceCode::DELETE_ACL_PROFILE); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); -} - -/** - * @tc.name: NotifyAclEventInner_009 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_009, TestSize.Level0) -{ - uint32_t code = static_cast(DPInterfaceCode::SUBSCRIBE_DEVICE_PROFILE); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: NotifyAclEventInner_010 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_010, TestSize.Level0) -{ - uint32_t code = static_cast(DPInterfaceCode::UNSUBSCRIBE_DEVICE_PROFILE); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: NotifyAclEventInner_011 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_011, TestSize.Level0) -{ - uint32_t code = static_cast(DPInterfaceCode::SEND_SUBSCRIBE_INFOS); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: NotifyAclEventInner_012 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_012, TestSize.Level0) -{ - uint32_t code = static_cast(DPInterfaceCode::PUT_SERVICE_PROFILE); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: NotifyAclEventInner_013 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_013, TestSize.Level0) -{ - uint32_t code = static_cast(DPInterfaceCode::PUT_SERVICE_PROFILE_BATCH); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: NotifyAclEventInner_014 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_014, TestSize.Level0) -{ - uint32_t code = static_cast(DPInterfaceCode::PUT_CHAR_PROFILE); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: NotifyAclEventInner_015 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyAclEventInner_015, TestSize.Level0) -{ - uint32_t code = static_cast(DPInterfaceCode::PUT_CHAR_PROFILE_BATCH); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyAclEventInner(code, data, reply, option); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: NotifyEventInner_001 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyEventInner_001, TestSize.Level0) -{ - uint32_t code = static_cast(DPInterfaceCode::GET_DEVICE_PROFILE_NEW); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyEventInner(code, data, reply, option); - EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); -} - -/** - * @tc.name: NotifyEventInner_002 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyEventInner_002, TestSize.Level0) -{ - uint32_t code = static_cast(DPInterfaceCode::GET_SERVICE_PROFILE); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyEventInner(code, data, reply, option); - EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); -} - -/** - * @tc.name: NotifyEventInner_003 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyEventInner_003, TestSize.Level0) -{ - uint32_t code = static_cast(DPInterfaceCode::GET_CHAR_PROFILE); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyEventInner(code, data, reply, option); - EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); -} - -/** - * @tc.name: NotifyEventInner_004 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyEventInner_004, TestSize.Level0) -{ - uint32_t code = static_cast(DPInterfaceCode::DEL_SERVICE_PROFILE); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyEventInner(code, data, reply, option); - EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); -} - -/** - * @tc.name: NotifyEventInner_005 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyEventInner_005, TestSize.Level0) -{ - uint32_t code = static_cast(DPInterfaceCode::DEL_CHAR_PROFILE); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyEventInner(code, data, reply, option); - EXPECT_EQ(ERR_FLATTEN_OBJECT, ret); -} - -/** - * @tc.name: NotifyEventInner_006 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyEventInner_006, TestSize.Level0) -{ - uint32_t code = static_cast(DPInterfaceCode::SYNC_DEVICE_PROFILE_NEW); - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyEventInner(code, data, reply, option); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} - -/** - * @tc.name: NotifyEventInner_007 - * @tc.desc: succeed - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, NotifyEventInner_007, TestSize.Level0) -{ - uint32_t code = 1000; - MessageParcel data; - MessageParcel reply; - MessageOption option; - int32_t ret = ProfileStub_->NotifyEventInner(code, data, reply, option); - EXPECT_EQ(305, ret); -} - -/** - * @tc.name: PutAllTrustedDevicesInner001 - * @tc.desc: PutAllTrustedDevicesInner - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F(DistributedDeviceProfileStubNewTest, PutAllTrustedDevicesInner_001, TestSize.Level1) -{ - MessageParcel data; - MessageParcel reply; - int32_t ret = ProfileStub_->PutAllTrustedDevicesInner(data, reply); - EXPECT_EQ(DP_READ_PARCEL_FAIL, ret); -} -} // namespace DistributedDeviceProfile -} // namespace OHOS -- Gitee From 28eeb3228569bae3913742680fcd73237cc0c72a Mon Sep 17 00:00:00 2001 From: BrainL Date: Wed, 4 Jun 2025 14:47:44 +0800 Subject: [PATCH 2/2] fixed the comments Signed-off-by: BrainL Change-Id: Icb42f5c961e39d080c70073b651f4a2405b4b66a --- .../interfaces/access_control_profile.h | 2 +- common/include/interfaces/accessee.h | 3 + common/include/interfaces/accesser.h | 3 + .../device_icon_info_filter_options.h | 2 +- .../device_profile_filter_options.h | 6 +- common/include/interfaces/dp_subscribe_info.h | 6 +- .../interfaces/dp_subscribe_info_extension.h | 10 ++- common/include/interfaces/dp_sync_options.h | 6 +- .../include/interfaces/local_service_info.h | 4 +- common/include/interfaces/product_info.h | 4 +- .../interfaces/service_info_unique_key.h | 8 +-- .../include/interfaces/trust_device_profile.h | 6 +- .../include/interfaces/trusted_device_info.h | 6 +- .../src/interfaces/access_control_profile.cpp | 4 ++ common/src/interfaces/accessee.cpp | 42 ++++++++++++ common/src/interfaces/accesser.cpp | 42 ++++++++++++ common/src/interfaces/device_icon_info.cpp | 33 ++++++++++ .../device_icon_info_filter_options.cpp | 19 ++++++ .../device_profile_filter_options.cpp | 65 +++++++++++++++++++ .../dp_subscribe_info_extension.cpp | 42 +++++++++--- common/src/interfaces/dp_sync_options.cpp | 1 - common/src/interfaces/local_service_info.cpp | 7 +- common/src/interfaces/product_info.cpp | 2 - .../src/interfaces/service_info_profile.cpp | 18 ++--- .../interfaces/service_info_unique_key.cpp | 2 +- services/core/BUILD.gn | 4 +- .../include/common/dp_services_constants.h | 2 +- .../distributed_device_profile_service_new.h | 2 +- .../subscribe_profile_manager.h | 6 +- ...distributed_device_profile_service_new.cpp | 7 +- .../distributed_device_profile_stub_new.cpp | 0 .../subscribe_profile_manager.cpp | 5 +- 32 files changed, 303 insertions(+), 66 deletions(-) delete mode 100644 services/core/src/distributed_device_profile_stub_new.cpp diff --git a/common/include/interfaces/access_control_profile.h b/common/include/interfaces/access_control_profile.h index c7c87314..ef8feee2 100644 --- a/common/include/interfaces/access_control_profile.h +++ b/common/include/interfaces/access_control_profile.h @@ -65,7 +65,7 @@ public: void SetExtraData(const std::string& extraData); bool Marshalling(MessageParcel& parcel) const ; bool UnMarshalling(MessageParcel& parcel) ; - std::string dump() const ; + std::string dump() const; bool ReadFromParcel(Parcel &parcel); virtual bool Marshalling(Parcel &parcel) const override; diff --git a/common/include/interfaces/accessee.h b/common/include/interfaces/accessee.h index 4bbac0bd..70c018b4 100644 --- a/common/include/interfaces/accessee.h +++ b/common/include/interfaces/accessee.h @@ -20,6 +20,7 @@ #include #include "distributed_device_profile_enums.h" #include "dp_parcel.h" +#include "message_parcel.h" namespace OHOS { namespace DistributedDeviceProfile { @@ -65,6 +66,8 @@ public: bool UnMarshalling(MessageParcel& parcel) override; std::string dump() const override; + bool Marshalling(Parcel& parcel) const; + bool UnMarshalling(Parcel& parcel); private: int64_t accesseeId_; std::string accesseeDeviceId_; diff --git a/common/include/interfaces/accesser.h b/common/include/interfaces/accesser.h index b565e43c..78fcf6c3 100644 --- a/common/include/interfaces/accesser.h +++ b/common/include/interfaces/accesser.h @@ -20,6 +20,7 @@ #include #include "distributed_device_profile_enums.h" #include "dp_parcel.h" +#include "message_parcel.h" namespace OHOS { namespace DistributedDeviceProfile { @@ -64,6 +65,8 @@ public: bool UnMarshalling(MessageParcel& parcel) override; std::string dump() const override; + bool Marshalling(Parcel& parcel) const; + bool UnMarshalling(Parcel& parcel); private: int64_t accesserId_; std::string accesserDeviceId_; diff --git a/common/include/interfaces/device_icon_info_filter_options.h b/common/include/interfaces/device_icon_info_filter_options.h index 1748eaa3..31c7ad1d 100644 --- a/common/include/interfaces/device_icon_info_filter_options.h +++ b/common/include/interfaces/device_icon_info_filter_options.h @@ -42,7 +42,7 @@ public: bool Marshalling(MessageParcel& parcel) const ; bool UnMarshalling(MessageParcel& parcel) ; - std::string dump() const ; + std::string dump() const; bool ReadFromParcel(Parcel &parcel); virtual bool Marshalling(Parcel &parcel) const override; static DeviceIconInfoFilterOptions *Unmarshalling(Parcel &parcel); diff --git a/common/include/interfaces/device_profile_filter_options.h b/common/include/interfaces/device_profile_filter_options.h index 4ebae664..ad001c46 100644 --- a/common/include/interfaces/device_profile_filter_options.h +++ b/common/include/interfaces/device_profile_filter_options.h @@ -43,9 +43,9 @@ public: std::vector GetDeviceProfileIds() const; void SetDeviceProfileIds(std::vector deviceProfileIds); void AddDeviceProfileIds(int32_t deviceProfileId); - bool Marshalling(MessageParcel& parcel) const ; - bool UnMarshalling(MessageParcel& parcel) ; - std::string dump() const ; + bool Marshalling(MessageParcel& parcel) const; + bool UnMarshalling(MessageParcel& parcel); + std::string dump() const; bool ReadFromParcel(Parcel &parcel); virtual bool Marshalling(Parcel &parcel) const override; diff --git a/common/include/interfaces/dp_subscribe_info.h b/common/include/interfaces/dp_subscribe_info.h index 99a03a01..f13a6fe5 100644 --- a/common/include/interfaces/dp_subscribe_info.h +++ b/common/include/interfaces/dp_subscribe_info.h @@ -50,9 +50,9 @@ public: void SetListener(sptr listener); std::unordered_set GetProfileChangeTypes() const; void AddProfileChangeType(ProfileChangeType profileChangeType); - bool Marshalling(MessageParcel& parcel) const ; - bool UnMarshalling(MessageParcel& parcel) ; - std::string dump() const ; + bool Marshalling(MessageParcel& parcel) const; + bool UnMarshalling(MessageParcel& parcel); + std::string dump() const; private: int32_t saId_ = -1; diff --git a/common/include/interfaces/dp_subscribe_info_extension.h b/common/include/interfaces/dp_subscribe_info_extension.h index d7ca7b91..359d5e60 100644 --- a/common/include/interfaces/dp_subscribe_info_extension.h +++ b/common/include/interfaces/dp_subscribe_info_extension.h @@ -28,16 +28,15 @@ namespace OHOS { namespace DistributedDeviceProfile { -class SubscribeInfoExtension : public Parcelable, public SubscribeInfo -{ +class SubscribeInfoExtension : public Parcelable, public SubscribeInfo { public: SubscribeInfoExtension(int32_t saId, const std::string& subscribeKey, std::unordered_set subscribeChangeTypes, sptr profileChangeListener, - int32_t userId = DEFAULT_USER_ID) ; + int32_t userId = DEFAULT_USER_ID); SubscribeInfoExtension(const SubscribeInfo& subscribeInfo); - SubscribeInfoExtension() ; - ~SubscribeInfoExtension() ; + SubscribeInfoExtension(); + ~SubscribeInfoExtension(); bool ReadFromParcel(Parcel &parcel); virtual bool Marshalling(Parcel &parcel) const override; @@ -48,7 +47,6 @@ private: std::string subscribeKey_ = ""; std::unordered_set subscribeChangeTypes_; sptr listener_ = nullptr; - }; class SubscribeExtensionCompare : public SubscribeCompare { diff --git a/common/include/interfaces/dp_sync_options.h b/common/include/interfaces/dp_sync_options.h index bd1617e7..db0ead6d 100644 --- a/common/include/interfaces/dp_sync_options.h +++ b/common/include/interfaces/dp_sync_options.h @@ -35,9 +35,9 @@ public: void AddDevice(const std::string& deviceId); void SetSyncMode(SyncMode mode); - bool Marshalling(MessageParcel& parcel) const ; - bool UnMarshalling(MessageParcel& parcel) ; - std::string dump() const ; + bool Marshalling(MessageParcel& parcel) const; + bool UnMarshalling(MessageParcel& parcel); + std::string dump() const; bool ReadFromParcel(Parcel &parcel); virtual bool Marshalling(Parcel &parcel) const override; diff --git a/common/include/interfaces/local_service_info.h b/common/include/interfaces/local_service_info.h index bd2386d1..51f17aa3 100644 --- a/common/include/interfaces/local_service_info.h +++ b/common/include/interfaces/local_service_info.h @@ -56,8 +56,8 @@ public: std::string GetExtraInfo() const; void SetExtraInfo(const std::string& extraInfo); - bool Marshalling(MessageParcel& parcel) const ; - bool UnMarshalling(MessageParcel& parcel) ; + bool Marshalling(MessageParcel& parcel) const; + bool UnMarshalling(MessageParcel& parcel); std::string dump() const; bool ReadFromParcel(Parcel &parcel); diff --git a/common/include/interfaces/product_info.h b/common/include/interfaces/product_info.h index bf03da9b..f6e8f699 100644 --- a/common/include/interfaces/product_info.h +++ b/common/include/interfaces/product_info.h @@ -43,11 +43,11 @@ public: void SetProductShortName(const std::string& productShortName); std::string GetImageVersion() const; void SetImageVersion(const std::string& imageVersion); - bool Marshalling(MessageParcel& parcel) const ; + bool Marshalling(MessageParcel& parcel) const; bool UnMarshalling(MessageParcel& parcel); bool operator!=(const ProductInfo& other) const; std::string dump() const; - + bool ReadFromParcel(Parcel &parcel); virtual bool Marshalling(Parcel &parcel) const override; static ProductInfo *Unmarshalling(Parcel &parcel); diff --git a/common/include/interfaces/service_info_unique_key.h b/common/include/interfaces/service_info_unique_key.h index a51aeca7..ad705be3 100644 --- a/common/include/interfaces/service_info_unique_key.h +++ b/common/include/interfaces/service_info_unique_key.h @@ -53,13 +53,13 @@ public: void SetBundleName(const std::string& bundleName); bool operator<(const ServiceInfoUniqueKey& rhs) const; - bool Marshalling(MessageParcel& parcel) const ; - bool UnMarshalling(MessageParcel& parcel) ; - std::string dump() const ; + bool Marshalling(MessageParcel& parcel) const; + bool UnMarshalling(MessageParcel& parcel); + std::string dump() const; bool ReadFromParcel(Parcel &parcel); virtual bool Marshalling(Parcel &parcel) const override; - static ServiceInfoUniqueKey*Unmarshalling(Parcel &parcel); + static ServiceInfoUniqueKey *Unmarshalling(Parcel &parcel); private: std::string deviceId_ = ""; diff --git a/common/include/interfaces/trust_device_profile.h b/common/include/interfaces/trust_device_profile.h index e8cd1f2b..69dc7e61 100644 --- a/common/include/interfaces/trust_device_profile.h +++ b/common/include/interfaces/trust_device_profile.h @@ -49,9 +49,9 @@ public: void SetPeerUserId(int32_t peerUserId); int32_t GetLocalUserId() const; void SetLocalUserId(int32_t localUserId); - bool Marshalling(MessageParcel& parcel) const ; - bool UnMarshalling(MessageParcel& parcel) ; - std::string dump() const ; + bool Marshalling(MessageParcel& parcel) const; + bool UnMarshalling(MessageParcel& parcel); + std::string dump() const; bool ReadFromParcel(Parcel &parcel); virtual bool Marshalling(Parcel &parcel) const override; diff --git a/common/include/interfaces/trusted_device_info.h b/common/include/interfaces/trusted_device_info.h index d94aceaa..a0f0127d 100644 --- a/common/include/interfaces/trusted_device_info.h +++ b/common/include/interfaces/trusted_device_info.h @@ -46,9 +46,9 @@ public: bool operator!=(const TrustedDeviceInfo& trustedDeviceInfo) const; bool operator<(const TrustedDeviceInfo& trustedDeviceInfo) const; - bool Marshalling(MessageParcel& parcel) const ; - bool UnMarshalling(MessageParcel& parcel) ; - std::string dump() const ; + bool Marshalling(MessageParcel& parcel) const; + bool UnMarshalling(MessageParcel& parcel); + std::string dump() const; bool ReadFromParcel(Parcel &parcel); virtual bool Marshalling(Parcel &parcel) const override; diff --git a/common/src/interfaces/access_control_profile.cpp b/common/src/interfaces/access_control_profile.cpp index cf06f65b..1615c973 100644 --- a/common/src/interfaces/access_control_profile.cpp +++ b/common/src/interfaces/access_control_profile.cpp @@ -299,6 +299,8 @@ bool AccessControlProfile::ReadFromParcel(Parcel &parcel) READ_HELPER_RET(parcel, Uint32, deviceIdType_, false); READ_HELPER_RET(parcel, String, deviceIdHash_, false); READ_HELPER_RET(parcel, String, extraData_, false); + accesser_.UnMarshalling(parcel); + accessee_.UnMarshalling(parcel); return true; } @@ -333,6 +335,8 @@ bool AccessControlProfile::Marshalling(Parcel& parcel) const WRITE_HELPER_RET(parcel, Uint32, deviceIdType_, false); WRITE_HELPER_RET(parcel, String, deviceIdHash_, false); WRITE_HELPER_RET(parcel, String, extraData_, false); + accesser_.Marshalling(parcel); + accessee_.Marshalling(parcel); return true; } } // namespace DistributedDeviceProfile diff --git a/common/src/interfaces/accessee.cpp b/common/src/interfaces/accessee.cpp index ede75755..fcfaf5dd 100644 --- a/common/src/interfaces/accessee.cpp +++ b/common/src/interfaces/accessee.cpp @@ -283,5 +283,47 @@ std::string Accessee::dump() const cJSON_free(jsonChars); return jsonStr; } + +bool Accessee::Marshalling(Parcel& parcel) const +{ + WRITE_HELPER_RET(parcel, Int64, accesseeId_, false); + WRITE_HELPER_RET(parcel, String, accesseeDeviceId_, false); + WRITE_HELPER_RET(parcel, Int32, accesseeUserId_, false); + WRITE_HELPER_RET(parcel, String, accesseeAccountId_, false); + WRITE_HELPER_RET(parcel, Int64, accesseeTokenId_, false); + WRITE_HELPER_RET(parcel, String, accesseeBundleName_, false); + WRITE_HELPER_RET(parcel, String, accesseeHapSignature_, false); + WRITE_HELPER_RET(parcel, Uint32, accesseeBindLevel_, false); + WRITE_HELPER_RET(parcel, String, accesseeDeviceName_, false); + WRITE_HELPER_RET(parcel, String, accesseeServiceName_, false); + WRITE_HELPER_RET(parcel, Int32, accesseeCredentialId_, false); + WRITE_HELPER_RET(parcel, String, accesseeCredentialIdStr_, false); + WRITE_HELPER_RET(parcel, Int32, accesseeStatus_, false); + WRITE_HELPER_RET(parcel, Int32, accesseeSessionKeyId_, false); + WRITE_HELPER_RET(parcel, Int64, accesseeSKTimeStamp_, false); + WRITE_HELPER_RET(parcel, String, accesseeExtraData_, false); + return true; +} + +bool Accessee::UnMarshalling(Parcel& parcel) +{ + READ_HELPER_RET(parcel, Int64, accesseeId_, false); + READ_HELPER_RET(parcel, String, accesseeDeviceId_, false); + READ_HELPER_RET(parcel, Int32, accesseeUserId_, false); + READ_HELPER_RET(parcel, String, accesseeAccountId_, false); + READ_HELPER_RET(parcel, Int64, accesseeTokenId_, false); + READ_HELPER_RET(parcel, String, accesseeBundleName_, false); + READ_HELPER_RET(parcel, String, accesseeHapSignature_, false); + READ_HELPER_RET(parcel, Uint32, accesseeBindLevel_, false); + READ_HELPER_RET(parcel, String, accesseeDeviceName_, false); + READ_HELPER_RET(parcel, String, accesseeServiceName_, false); + READ_HELPER_RET(parcel, Int32, accesseeCredentialId_, false); + READ_HELPER_RET(parcel, String, accesseeCredentialIdStr_, false); + READ_HELPER_RET(parcel, Int32, accesseeStatus_, false); + READ_HELPER_RET(parcel, Int32, accesseeSessionKeyId_, false); + READ_HELPER_RET(parcel, Int64, accesseeSKTimeStamp_, false); + READ_HELPER_RET(parcel, String, accesseeExtraData_, false); + return true; +} } // namespace DistributedDeviceProfile } // namespace OHOS \ No newline at end of file diff --git a/common/src/interfaces/accesser.cpp b/common/src/interfaces/accesser.cpp index aa7b4faa..3808fa73 100644 --- a/common/src/interfaces/accesser.cpp +++ b/common/src/interfaces/accesser.cpp @@ -281,5 +281,47 @@ std::string Accesser::dump() const cJSON_free(jsonChars); return jsonStr; } + +bool Accesser::Marshalling(Parcel& parcel) const +{ + WRITE_HELPER_RET(parcel, Int64, accesserId_, false); + WRITE_HELPER_RET(parcel, String, accesserDeviceId_, false); + WRITE_HELPER_RET(parcel, Int32, accesserUserId_, false); + WRITE_HELPER_RET(parcel, String, accesserAccountId_, false); + WRITE_HELPER_RET(parcel, Int64, accesserTokenId_, false); + WRITE_HELPER_RET(parcel, String, accesserBundleName_, false); + WRITE_HELPER_RET(parcel, String, accesserHapSignature_, false); + WRITE_HELPER_RET(parcel, Uint32, accesserBindLevel_, false); + WRITE_HELPER_RET(parcel, String, accesserDeviceName_, false); + WRITE_HELPER_RET(parcel, String, accesserServiceName_, false); + WRITE_HELPER_RET(parcel, Int32, accesserCredentialId_, false); + WRITE_HELPER_RET(parcel, String, accesserCredentialIdStr_, false); + WRITE_HELPER_RET(parcel, Int32, accesserStatus_, false); + WRITE_HELPER_RET(parcel, Int32, accesserSessionKeyId_, false); + WRITE_HELPER_RET(parcel, Int64, accesserSKTimeStamp_, false); + WRITE_HELPER_RET(parcel, String, accesserExtraData_, false); + return true; +} + +bool Accesser::UnMarshalling(Parcel& parcel) +{ + READ_HELPER_RET(parcel, Int64, accesserId_, false); + READ_HELPER_RET(parcel, String, accesserDeviceId_, false); + READ_HELPER_RET(parcel, Int32, accesserUserId_, false); + READ_HELPER_RET(parcel, String, accesserAccountId_, false); + READ_HELPER_RET(parcel, Int64, accesserTokenId_, false); + READ_HELPER_RET(parcel, String, accesserBundleName_, false); + READ_HELPER_RET(parcel, String, accesserHapSignature_, false); + READ_HELPER_RET(parcel, Uint32, accesserBindLevel_, false); + READ_HELPER_RET(parcel, String, accesserDeviceName_, false); + READ_HELPER_RET(parcel, String, accesserServiceName_, false); + READ_HELPER_RET(parcel, Int32, accesserCredentialId_, false); + READ_HELPER_RET(parcel, String, accesserCredentialIdStr_, false); + READ_HELPER_RET(parcel, Int32, accesserStatus_, false); + READ_HELPER_RET(parcel, Int32, accesserSessionKeyId_, false); + READ_HELPER_RET(parcel, Int64, accesserSKTimeStamp_, false); + READ_HELPER_RET(parcel, String, accesserExtraData_, false); + return true; +} } // namespace DistributedDeviceProfile } // namespace OHOS \ No newline at end of file diff --git a/common/src/interfaces/device_icon_info.cpp b/common/src/interfaces/device_icon_info.cpp index 71f930de..187b2a21 100644 --- a/common/src/interfaces/device_icon_info.cpp +++ b/common/src/interfaces/device_icon_info.cpp @@ -209,6 +209,23 @@ bool DeviceIconInfo::ReadFromParcel(Parcel &parcel) READ_HELPER_RET(parcel, String, version_, false); READ_HELPER_RET(parcel, String, wiseVersion_, false); READ_HELPER_RET(parcel, String, url_, false); + int32_t length = parcel.ReadInt32(); + if (length <= 0 || length > MAX_ICON_SIZE) { + HILOGE("uint8_t vector, params size is invalid! size : %{public}d", length); + return false; + } + + std::vector icon; + icon.reserve(length); + for (int32_t i = 0; i < length; ++i) { + uint8_t byte = 0; + if (!parcel.ReadUint8(byte)) { + HILOGE("ReadUint8 failed at index %{public}d", i); + return false; + } + icon.push_back(byte); + } + icon_ = icon; return true; } @@ -237,6 +254,22 @@ bool DeviceIconInfo::Marshalling(Parcel& parcel) const WRITE_HELPER_RET(parcel, String, version_, false); WRITE_HELPER_RET(parcel, String, wiseVersion_, false); WRITE_HELPER_RET(parcel, String, url_, false); + int32_t length = static_cast(icon_.size()); + WRITE_HELPER_RET(parcel, Int32, length, false); + if (icon_.empty() || icon_.size() > MAX_ICON_SIZE) { + HILOGE("uint8_t vector, params size is invalid! size : %{public}zu", icon_.size()); + return false; + } + if (length > 0) { + const uint8_t* buffer = reinterpret_cast(icon_.data()); + for (int32_t i = 0; i < length; ++i) { + if (!parcel.WriteUint8(buffer[i])) { + HILOGE("WriteUint8 failed at index %{public}d", i); + return false; + } + } + } + return true; } } // namespace DistributedDeviceProfile diff --git a/common/src/interfaces/device_icon_info_filter_options.cpp b/common/src/interfaces/device_icon_info_filter_options.cpp index a4143c81..2e6468f4 100644 --- a/common/src/interfaces/device_icon_info_filter_options.cpp +++ b/common/src/interfaces/device_icon_info_filter_options.cpp @@ -145,6 +145,16 @@ std::string DeviceIconInfoFilterOptions::dump() const bool DeviceIconInfoFilterOptions::ReadFromParcel(Parcel &parcel) { + size_t size = parcel.ReadUint32(); + if (size == 0 || size > MAX_ID_SIZE) { + HILOGE("string vector, strings size is invalid!size : %{public}zu", size); + return false; + } + for (uint32_t i = 0; i < size; i++) { + std::string item = ""; + READ_HELPER_RET(parcel, String, item, false); + productIds_.emplace_back(item); + } READ_HELPER_RET(parcel, String, internalModel_, false); READ_HELPER_RET(parcel, String, subProductId_, false); READ_HELPER_RET(parcel, String, imageType_, false); @@ -169,6 +179,15 @@ DeviceIconInfoFilterOptions *DeviceIconInfoFilterOptions::Unmarshalling(Parcel & bool DeviceIconInfoFilterOptions::Marshalling(Parcel& parcel) const { + size_t size = productIds_.size(); + WRITE_HELPER_RET(parcel, Uint32, size, false); + if (productIds_.empty() || productIds_.size() > MAX_ID_SIZE) { + HILOGE("string vector, strings size is invalid! size : %{public}zu", productIds_.size()); + return false; + } + for (const auto& item : productIds_) { + WRITE_HELPER_RET(parcel, String, item, false); + } WRITE_HELPER_RET(parcel, String, internalModel_, false); WRITE_HELPER_RET(parcel, String, subProductId_, false); WRITE_HELPER_RET(parcel, String, imageType_, false); diff --git a/common/src/interfaces/device_profile_filter_options.cpp b/common/src/interfaces/device_profile_filter_options.cpp index 4d4d78ef..48db66cf 100644 --- a/common/src/interfaces/device_profile_filter_options.cpp +++ b/common/src/interfaces/device_profile_filter_options.cpp @@ -154,6 +154,40 @@ bool DeviceProfileFilterOptions::ReadFromParcel(Parcel &parcel) { READ_HELPER_RET(parcel, Int32, userId_, false); READ_HELPER_RET(parcel, String, accountId_, false); + + size_t size1 = parcel.ReadUint32(); + if (size1 == 0 || size1 > MAX_ID_SIZE) { + HILOGE("string vector, strings size is invalid!size : %{public}zu", size1); + return false; + } + for (uint32_t i = 0; i < size1; i++) { + std::string item = ""; + READ_HELPER_RET(parcel, String, item, false); + deviceIds_.emplace_back(item); + } + + size_t size2 = parcel.ReadUint32(); + if (size2 == 0 || size2 > MAX_ID_SIZE) { + HILOGE("string vector, strings size is invalid!size : %{public}zu", size2); + return false; + } + for (uint32_t i = 0; i < size2; i++) { + std::string item = ""; + READ_HELPER_RET(parcel, String, item, false); + wiseDeviceIds_.emplace_back(item); + } + + size_t size3 = parcel.ReadUint32(); + if (size3 == 0 || size3 > MAX_ID_SIZE) { + HILOGE("int32_t vector, params size is invalid! size : %{public}zu", size3); + return false; + } + for (uint32_t i = 0; i < size3; i++) { + int32_t item = 0; + READ_HELPER_RET(parcel, Int32, item, false); + deviceProfileIds_.emplace_back(item); + } + return true; } @@ -176,6 +210,37 @@ bool DeviceProfileFilterOptions::Marshalling(Parcel& parcel) const { WRITE_HELPER_RET(parcel, Int32, userId_, false); WRITE_HELPER_RET(parcel, String, accountId_, false); + + size_t size1 = deviceIds_.size(); + WRITE_HELPER_RET(parcel, Uint32, size1, false); + if (deviceIds_.empty() || deviceIds_.size() > MAX_ID_SIZE) { + HILOGE("string vector, strings size is invalid! size : %{public}zu", deviceIds_.size()); + return false; + } + for (const auto& item : deviceIds_) { + WRITE_HELPER_RET(parcel, String, item, false); + } + + size_t size2 = wiseDeviceIds_.size(); + WRITE_HELPER_RET(parcel, Uint32, size2, false); + if (wiseDeviceIds_.empty() || wiseDeviceIds_.size() > MAX_ID_SIZE) { + HILOGE("string vector, strings size is invalid! size : %{public}zu", wiseDeviceIds_.size()); + return false; + } + for (const auto& item : wiseDeviceIds_) { + WRITE_HELPER_RET(parcel, String, item, false); + } + + size_t size3 = deviceProfileIds_.size(); + WRITE_HELPER_RET(parcel, Uint32, size3, false); + if (deviceProfileIds_.empty() || deviceProfileIds_.size() > MAX_ID_SIZE) { + HILOGE("int32_t vector, params size is invalid! size : %{public}zu", deviceProfileIds_.size()); + return false; + } + for (const auto& item : deviceProfileIds_) { + WRITE_HELPER_RET(parcel, Int32, item, false); + } + return true; } } // namespace DistributedDeviceProfile diff --git a/common/src/interfaces/dp_subscribe_info_extension.cpp b/common/src/interfaces/dp_subscribe_info_extension.cpp index 53773330..b78087a1 100644 --- a/common/src/interfaces/dp_subscribe_info_extension.cpp +++ b/common/src/interfaces/dp_subscribe_info_extension.cpp @@ -13,13 +13,13 @@ * limitations under the License. */ - #include "dp_subscribe_info_extension.h" - #include "cJSON.h" - #include "distributed_device_profile_constants.h" - #include "ipc_utils.h" - #include "macro_utils.h" - #include "profile_change_listener_stub.h" - #include "profile_utils.h" +#include "dp_subscribe_info_extension.h" +#include "cJSON.h" +#include "distributed_device_profile_constants.h" +#include "ipc_utils.h" +#include "macro_utils.h" +#include "profile_change_listener_stub.h" +#include "profile_utils.h" namespace OHOS { namespace DistributedDeviceProfile { @@ -72,8 +72,23 @@ bool SubscribeInfoExtension::ReadFromParcel(Parcel &parcel) { READ_HELPER_RET(parcel, Int32, saId_, false); READ_HELPER_RET(parcel, String, subscribeKey_, false); - return true; + uint32_t size = parcel.ReadUint32(); + if (size == 0 || size > MAX_SUBSCRIBE_CHANGE_SIZE) { + HILOGE("Params size is invalid! size: %{public}u", size); + return false; + } + for (uint32_t i = 0; i < size; ++i) { + uint32_t num = parcel.ReadUint32(); + if (num <= static_cast(ProfileChangeType::PROFILE_CHANGE_TYPE_MIN) || + num >= static_cast(ProfileChangeType::PROFILE_CHANGE_TYPE_MAX)) { + HILOGE("The value is invalid! index: %{public}u, value: %{public}u", i, num); + return false; + } + subscribeChangeTypes_.emplace(static_cast(num)); + } + + return true; } SubscribeInfoExtension *SubscribeInfoExtension::Unmarshalling(Parcel &parcel) @@ -95,6 +110,17 @@ bool SubscribeInfoExtension::Marshalling(Parcel& parcel) const { WRITE_HELPER_RET(parcel, Int32, saId_, false); WRITE_HELPER_RET(parcel, String, subscribeKey_, false); + + uint32_t size = subscribeChangeTypes_.size(); + WRITE_HELPER_RET(parcel, Uint32, size, false); + if (size == 0 || size > MAX_SUBSCRIBE_CHANGE_SIZE) { + HILOGE("changeTypes size is invalid! size: %{public}u", size); + return false; + } + for (ProfileChangeType item : subscribeChangeTypes_) { + WRITE_HELPER_RET(parcel, Int32, static_cast(item), false); + } + WRITE_HELPER_RET(parcel, RemoteObject, listener_, false); return true; } diff --git a/common/src/interfaces/dp_sync_options.cpp b/common/src/interfaces/dp_sync_options.cpp index 701fb32b..0a533af0 100644 --- a/common/src/interfaces/dp_sync_options.cpp +++ b/common/src/interfaces/dp_sync_options.cpp @@ -126,7 +126,6 @@ bool DpSyncOptions::ReadFromParcel(Parcel &parcel) syncDeviceIds_.emplace_back(deviceId); } return true; - } DpSyncOptions *DpSyncOptions::Unmarshalling(Parcel &parcel) diff --git a/common/src/interfaces/local_service_info.cpp b/common/src/interfaces/local_service_info.cpp index 25a50bd5..374df364 100644 --- a/common/src/interfaces/local_service_info.cpp +++ b/common/src/interfaces/local_service_info.cpp @@ -42,7 +42,7 @@ void LocalServiceInfo::SetBundleName(const std::string& bundleName) { bundleName_ = bundleName; } - + int32_t LocalServiceInfo::GetAuthBoxType() const { return authBoxType_; @@ -52,7 +52,7 @@ void LocalServiceInfo::SetAuthBoxType(const int32_t authBoxType) { authBoxType_ = authBoxType; } - + int32_t LocalServiceInfo::GetAuthType() const { return authType_; @@ -62,7 +62,7 @@ void LocalServiceInfo::SetAuthType(const int32_t authType) { authType_ = authType; } - + int32_t LocalServiceInfo::GetPinExchangeType() const { return pinExchangeType_; @@ -142,7 +142,6 @@ bool LocalServiceInfo::ReadFromParcel(Parcel &parcel) READ_HELPER_RET(parcel, String, description_, false); READ_HELPER_RET(parcel, String, extraInfo_, false); return true; - } LocalServiceInfo *LocalServiceInfo::Unmarshalling(Parcel &parcel) diff --git a/common/src/interfaces/product_info.cpp b/common/src/interfaces/product_info.cpp index 35cff796..fdcfb2bd 100644 --- a/common/src/interfaces/product_info.cpp +++ b/common/src/interfaces/product_info.cpp @@ -76,7 +76,6 @@ void ProductInfo::SetImageVersion(const std::string& imageVersion) this->imageVersion_ = imageVersion; } - bool ProductInfo::Marshalling(MessageParcel& parcel) const { WRITE_HELPER_RET(parcel, String, productId_, false); @@ -167,7 +166,6 @@ bool ProductInfo::ReadFromParcel(Parcel &parcel) READ_HELPER_RET(parcel, String, productShortName_, false); READ_HELPER_RET(parcel, String, imageVersion_, false); return true; - } ProductInfo *ProductInfo::Unmarshalling(Parcel &parcel) diff --git a/common/src/interfaces/service_info_profile.cpp b/common/src/interfaces/service_info_profile.cpp index 522c029b..64745cc2 100644 --- a/common/src/interfaces/service_info_profile.cpp +++ b/common/src/interfaces/service_info_profile.cpp @@ -74,7 +74,7 @@ void ServiceInfoProfile::SetTokenId(const std::string& tokenId) { tokenId_ = tokenId; } - + int64_t ServiceInfoProfile::GetServiceId() const { return serviceId_; @@ -99,12 +99,12 @@ std::string ServiceInfoProfile::GetServiceName() const { return serviceName_; } - + void ServiceInfoProfile::SetServiceName(const std::string& serviceName) { serviceName_ = serviceName; } - + std::string ServiceInfoProfile::GetServiceDisplayName() const { return serviceDisplayName_; @@ -124,7 +124,7 @@ void ServiceInfoProfile::SetCustomData(const std::string& customData) { customData_ = customData; } - + int32_t ServiceInfoProfile::GetCustomDataLen() const { return customDataLen_; @@ -164,7 +164,7 @@ void ServiceInfoProfile::SetAbilityName(const std::string& abilityName) { abilityName_ = abilityName; } - + int32_t ServiceInfoProfile::GetAuthBoxType() const { return authBoxType_; @@ -174,7 +174,7 @@ void ServiceInfoProfile::SetAuthBoxType(const int32_t authBoxType) { authBoxType_ = authBoxType; } - + int32_t ServiceInfoProfile::GetAuthType() const { return authType_; @@ -184,7 +184,7 @@ void ServiceInfoProfile::SetAuthType(const int32_t authType) { authType_ = authType; } - + int32_t ServiceInfoProfile::GetPinExchangeType() const { return pinExchangeType_; @@ -214,12 +214,12 @@ void ServiceInfoProfile::SetDescription(const std::string& description) { description_ = description; } - + std::string ServiceInfoProfile::GetServiceDicoveryScope() const { return serviceDicoveryScope_; } - + void ServiceInfoProfile::SetServiceDicoveryScope(const std::string& serviceDicoveryScope) { serviceDicoveryScope_ = serviceDicoveryScope; diff --git a/common/src/interfaces/service_info_unique_key.cpp b/common/src/interfaces/service_info_unique_key.cpp index 218adab5..e796a458 100644 --- a/common/src/interfaces/service_info_unique_key.cpp +++ b/common/src/interfaces/service_info_unique_key.cpp @@ -61,7 +61,7 @@ void ServiceInfoUniqueKey::SetTokenId(const std::string& tokenId) { tokenId_ = tokenId; } - + int64_t ServiceInfoUniqueKey::GetServiceId() const { return serviceId_; diff --git a/services/core/BUILD.gn b/services/core/BUILD.gn index 57e4f072..e374fd77 100644 --- a/services/core/BUILD.gn +++ b/services/core/BUILD.gn @@ -70,9 +70,11 @@ ohos_shared_library("distributed_device_profile_svr") { cflags_cc = cflags sanitize = { - boundary_sanitize = true integer_overflow = true ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true debug = false } diff --git a/services/core/include/common/dp_services_constants.h b/services/core/include/common/dp_services_constants.h index a861f216..cedf79d1 100644 --- a/services/core/include/common/dp_services_constants.h +++ b/services/core/include/common/dp_services_constants.h @@ -38,7 +38,7 @@ extern const std::string CREATE_DEVICE_PROFILE_WISE_DEVICEID_INDEX_SQL; extern const std::string ALTER_TABLE_DP_ADD_COLUMN_PRODUCT_NAME_SQL; extern const std::string ALTER_TABLE_DP_RENAME_COLUMN_INTERNAL_MODEL_SQL; // DeviceIconInfoDao -extern const std::string CREATE_DEVICE_ICON_INFO_TABLE_SQL ; +extern const std::string CREATE_DEVICE_ICON_INFO_TABLE_SQL; extern const std::string CREATE_DEVICE_ICON_INFO_TABLE_UNIQUE_INDEX_SQL; extern const std::string SELECT_DEVICE_ICON_INFO_TABLE; extern const std::string ALTER_TABLE_DEVICE_ICON_INFO_ADD_COLUMN_INTENAL_MODEL_SQL; diff --git a/services/core/include/distributed_device_profile_service_new.h b/services/core/include/distributed_device_profile_service_new.h index 9d11574a..fac2fa5b 100644 --- a/services/core/include/distributed_device_profile_service_new.h +++ b/services/core/include/distributed_device_profile_service_new.h @@ -97,7 +97,7 @@ public: int32_t UnSubscribeDeviceProfile(const SubscribeInfoExtension& subscribeInfoExtension) override; int32_t SyncDeviceProfile(const DistributedDeviceProfile::DpSyncOptions& syncOptions, const sptr& syncCompletedCallback) override; - int32_t SubscribeDeviceProfileInited(int32_t saId,const sptr& dpInitedCallback) override; + int32_t SubscribeDeviceProfileInited(int32_t saId, const sptr& dpInitedCallback) override; int32_t UnSubscribeDeviceProfileInited(int32_t saId) override; int32_t SubscribePinCodeInvalid(const std::string& bundleName, int32_t pinExchangeType, const sptr& pinCodeCallback) override; diff --git a/services/core/include/subscribeprofilemanager/subscribe_profile_manager.h b/services/core/include/subscribeprofilemanager/subscribe_profile_manager.h index 76ec51ed..f38687d5 100644 --- a/services/core/include/subscribeprofilemanager/subscribe_profile_manager.h +++ b/services/core/include/subscribeprofilemanager/subscribe_profile_manager.h @@ -56,7 +56,8 @@ private: int32_t NotifyCharProfileAdd(const std::string& dbKey, const std::string& dbValue); int32_t NotifyCharProfileUpdate(const std::string& dbKey, const std::string& dbValue); int32_t NotifyCharProfileDelete(const std::string& dbKey, const std::string& dbValue); - std::unordered_set GetSubscribeInfos(const std::string& dbKey); + std::unordered_set GetSubscribeInfos( + const std::string& dbKey); std::string DBKeyToSubcribeKey(const std::string& dbkey); private: @@ -64,7 +65,8 @@ private: std::mutex funcsMutex_; std::map funcsMap_; std::mutex subscribeMutex_; - std::map> subscribeInfoExtensionMap_; + std::map> + subscribeInfoExtensionMap_; }; } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/services/core/src/distributed_device_profile_service_new.cpp b/services/core/src/distributed_device_profile_service_new.cpp index 2225f397..74aaf7df 100644 --- a/services/core/src/distributed_device_profile_service_new.cpp +++ b/services/core/src/distributed_device_profile_service_new.cpp @@ -796,7 +796,8 @@ int32_t DistributedDeviceProfileServiceNew::SubscribeDeviceProfile(const Subscri return ret; } -int32_t DistributedDeviceProfileServiceNew::UnSubscribeDeviceProfile(const SubscribeInfoExtension& subscribeInfoExtension) +int32_t DistributedDeviceProfileServiceNew::UnSubscribeDeviceProfile( + const SubscribeInfoExtension& subscribeInfoExtension) { if (!PermissionManager::GetInstance().CheckCallerPermission()) { HILOGE("this caller is permission denied!"); @@ -809,7 +810,7 @@ int32_t DistributedDeviceProfileServiceNew::UnSubscribeDeviceProfile(const Subsc } int32_t DistributedDeviceProfileServiceNew::SyncDeviceProfile( - const DistributedDeviceProfile::DpSyncOptions& syncOptions,const sptr& syncCompletedCallback) + const DistributedDeviceProfile::DpSyncOptions& syncOptions, const sptr& syncCompletedCallback) { if (!PermissionManager::GetInstance().CheckCallerSyncPermission()) { HILOGE("this caller is permission denied!"); @@ -1178,7 +1179,7 @@ int32_t DistributedDeviceProfileServiceNew::UnSubscribeDeviceProfileInited(int32 } int32_t DistributedDeviceProfileServiceNew::SubscribePinCodeInvalid(const std::string& bundleName, - int32_t pinExchangeType,const sptr& pinCodeCallback) + int32_t pinExchangeType, const sptr& pinCodeCallback) { if (!PermissionManager::GetInstance().CheckCallerPermission()) { HILOGE("this caller is permission denied!"); diff --git a/services/core/src/distributed_device_profile_stub_new.cpp b/services/core/src/distributed_device_profile_stub_new.cpp deleted file mode 100644 index e69de29b..00000000 diff --git a/services/core/src/subscribeprofilemanager/subscribe_profile_manager.cpp b/services/core/src/subscribeprofilemanager/subscribe_profile_manager.cpp index f636b8f5..065e1c2d 100644 --- a/services/core/src/subscribeprofilemanager/subscribe_profile_manager.cpp +++ b/services/core/src/subscribeprofilemanager/subscribe_profile_manager.cpp @@ -514,8 +514,9 @@ int32_t SubscribeProfileManager::NotifyCharProfileDelete(const std::string& dbKe } return DP_SUCCESS; } -std::unordered_set SubscribeProfileManager::GetSubscribeInfos( - const std::string& dbKey) + +std::unordered_set +SubscribeProfileManager::GetSubscribeInfos(const std::string& dbKey) { { std::lock_guard lock(subscribeMutex_); -- Gitee