From 86eb344a585892a080ce24d467ac2fed1e7d10dd Mon Sep 17 00:00:00 2001 From: hanlu Date: Wed, 24 May 2023 11:22:36 +0800 Subject: [PATCH 1/4] f Signed-off-by: hanlu --- .../include/js_datashare_ext_ability.h | 1 + .../provider/src/js_datashare_ext_ability.cpp | 41 ++++++++++++++++--- .../proxy/include/idata_share_service.h | 2 +- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/frameworks/native/provider/include/js_datashare_ext_ability.h b/frameworks/native/provider/include/js_datashare_ext_ability.h index 41a61e33..dd81f07f 100644 --- a/frameworks/native/provider/include/js_datashare_ext_ability.h +++ b/frameworks/native/provider/include/js_datashare_ext_ability.h @@ -308,6 +308,7 @@ private: napi_value MakePredicates(napi_env env, const DataSharePredicates &predicates); static NativeValue* AsyncCallback(NativeEngine* engine, NativeCallbackInfo* info); void CheckAndSetAsyncResult(NativeEngine* engine); + void NotifyToDataShareService(); static void UnWrapBusinessError(napi_env env, napi_value info, DatashareBusinessError &businessError); static napi_valuetype UnWrapPropertyType(napi_env env, napi_value info, const std::string &key); diff --git a/frameworks/native/provider/src/js_datashare_ext_ability.cpp b/frameworks/native/provider/src/js_datashare_ext_ability.cpp index dfbe00de..aac4c8f1 100644 --- a/frameworks/native/provider/src/js_datashare_ext_ability.cpp +++ b/frameworks/native/provider/src/js_datashare_ext_ability.cpp @@ -16,20 +16,20 @@ #include "js_datashare_ext_ability.h" #include "ability_info.h" +#include "data_share_manager_impl.h" #include "dataobs_mgr_client.h" -#include "datashare_stub_impl.h" #include "datashare_log.h" +#include "datashare_predicates_proxy.h" +#include "datashare_stub_impl.h" +#include "iservice_registry.h" #include "js_datashare_ext_ability_context.h" #include "js_runtime.h" #include "js_runtime_utils.h" -#include "napi/native_api.h" -#include "napi/native_node_api.h" #include "napi_common_util.h" #include "napi_common_want.h" -#include "napi_remote_object.h" - #include "napi_datashare_values_bucket.h" -#include "datashare_predicates_proxy.h" +#include "napi_remote_object.h" +#include "system_ability_definition.h" namespace OHOS { namespace DataShare { @@ -131,6 +131,7 @@ void JsDataShareExtAbility::OnStart(const AAFwk::Want &want) NativeValue* argv[] = {nativeWant}; CallObjectMethod("onCreate", argv, sizeof(argv)/sizeof(argv[0])); napi_close_handle_scope(env, scope); + NotifyToDataShareService(); } sptr JsDataShareExtAbility::OnConnect(const AAFwk::Want &want) @@ -780,6 +781,34 @@ napi_valuetype JsDataShareExtAbility::UnWrapPropertyType(napi_env env, napi_valu return type; } +void JsDataShareExtAbility::NotifyToDataShareService() +{ + auto manager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (manager == nullptr) { + LOG_ERROR("get system ability manager failed"); + return; + } + auto remoteObject = manager->CheckSystemAbility(DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID); + if (remoteObject == nullptr) { + LOG_ERROR("CheckSystemAbility failed"); + return; + } + auto serviceProxy = std::make_shared(remoteObject); + if (serviceProxy == nullptr) { + LOG_ERROR("make_shared failed"); + return; + } + auto remote = serviceProxy->GetFeatureInterface("data_share"); + if (remote == nullptr) { + LOG_ERROR("Get DataShare service failed!"); + return; + } + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + remote->SendRequest(DataShareServiceProxy::DATA_SHARE_SERVICE_CMD_NOTIFY, data, reply, option); +} + bool MakeNapiColumn(napi_env env, napi_value &napiColumns, const std::vector &columns) { napi_status status = napi_create_array(env, &napiColumns); diff --git a/frameworks/native/proxy/include/idata_share_service.h b/frameworks/native/proxy/include/idata_share_service.h index 568dd1a1..9c2fe7a3 100644 --- a/frameworks/native/proxy/include/idata_share_service.h +++ b/frameworks/native/proxy/include/idata_share_service.h @@ -42,7 +42,7 @@ public: DATA_SHARE_SERVICE_CMD_UNSUBSCRIBE_PUBLISHED, DATA_SHARE_SERVICE_CMD_ENABLE_SUBSCRIBE_PUBLISHED, DATA_SHARE_SERVICE_CMD_DISABLE_SUBSCRIBE_PUBLISHED, - DATA_SHARE_SERVICE_CMD_QUERY_ASSERT, + DATA_SHARE_SERVICE_CMD_NOTIFY, DATA_SHARE_SERVICE_CMD_MAX }; -- Gitee From affcefa922194fff2c6a5815cb7e7115cee70580 Mon Sep 17 00:00:00 2001 From: hanlu Date: Wed, 24 May 2023 11:40:30 +0800 Subject: [PATCH 2/4] f Signed-off-by: hanlu --- interfaces/inner_api/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/interfaces/inner_api/BUILD.gn b/interfaces/inner_api/BUILD.gn index ca280e64..ba6b9cec 100644 --- a/interfaces/inner_api/BUILD.gn +++ b/interfaces/inner_api/BUILD.gn @@ -123,6 +123,7 @@ ohos_shared_library("datashare_provider") { "ipc:ipc_single", "ipc_js:rpc", "napi:ace_napi", + "samgr:samgr_proxy", ] subsystem_name = "distributeddatamgr" -- Gitee From d83c8dfbd47d2729b9201b6efa0424c19243497a Mon Sep 17 00:00:00 2001 From: hanlu Date: Wed, 24 May 2023 15:14:58 +0800 Subject: [PATCH 3/4] f Signed-off-by: hanlu --- .../native/{consumer => common}/include/base_connection.h | 0 frameworks/native/common/src/ishared_result_set_stub.cpp | 1 - frameworks/native/provider/src/js_datashare_ext_ability.cpp | 2 +- interfaces/inner_api/BUILD.gn | 3 --- interfaces/inner_api/common/BUILD.gn | 4 ++++ interfaces/inner_api/common/libdatashare_common.map | 3 +++ interfaces/inner_api/consumer/include/datashare_helper.h | 4 ++-- 7 files changed, 10 insertions(+), 7 deletions(-) rename frameworks/native/{consumer => common}/include/base_connection.h (100%) diff --git a/frameworks/native/consumer/include/base_connection.h b/frameworks/native/common/include/base_connection.h similarity index 100% rename from frameworks/native/consumer/include/base_connection.h rename to frameworks/native/common/include/base_connection.h diff --git a/frameworks/native/common/src/ishared_result_set_stub.cpp b/frameworks/native/common/src/ishared_result_set_stub.cpp index d56c11d7..722daae4 100644 --- a/frameworks/native/common/src/ishared_result_set_stub.cpp +++ b/frameworks/native/common/src/ishared_result_set_stub.cpp @@ -14,7 +14,6 @@ */ #include "ishared_result_set_stub.h" -#include #include "datashare_log.h" #include "datashare_errno.h" diff --git a/frameworks/native/provider/src/js_datashare_ext_ability.cpp b/frameworks/native/provider/src/js_datashare_ext_ability.cpp index aac4c8f1..a22f50a5 100644 --- a/frameworks/native/provider/src/js_datashare_ext_ability.cpp +++ b/frameworks/native/provider/src/js_datashare_ext_ability.cpp @@ -806,7 +806,7 @@ void JsDataShareExtAbility::NotifyToDataShareService() MessageParcel data; MessageParcel reply; MessageOption option(MessageOption::TF_ASYNC); - remote->SendRequest(DataShareServiceProxy::DATA_SHARE_SERVICE_CMD_NOTIFY, data, reply, option); + remote->SendRequest(IDataShareService::DATA_SHARE_SERVICE_CMD_NOTIFY, data, reply, option); } bool MakeNapiColumn(napi_env env, napi_value &napiColumns, const std::vector &columns) diff --git a/interfaces/inner_api/BUILD.gn b/interfaces/inner_api/BUILD.gn index ba6b9cec..0388b5b4 100644 --- a/interfaces/inner_api/BUILD.gn +++ b/interfaces/inner_api/BUILD.gn @@ -58,8 +58,6 @@ ohos_shared_library("datashare_consumer") { "${datashare_native_consumer_path}/src/datashare_helper.cpp", "${datashare_native_consumer_path}/src/datashare_proxy.cpp", "${datashare_native_proxy_path}/src/data_proxy_observer_stub.cpp", - "${datashare_native_proxy_path}/src/data_share_manager_impl.cpp", - "${datashare_native_proxy_path}/src/data_share_service_proxy.cpp", "${datashare_native_proxy_path}/src/published_data_subscriber_manager.cpp", "${datashare_native_proxy_path}/src/rdb_subscriber_manager.cpp", ] @@ -82,7 +80,6 @@ ohos_shared_library("datashare_consumer") { "ipc:ipc_single", "ipc_js:rpc", "napi:ace_napi", - "samgr:samgr_proxy", ] subsystem_name = "distributeddatamgr" diff --git a/interfaces/inner_api/common/BUILD.gn b/interfaces/inner_api/common/BUILD.gn index 06abf4c7..3871042c 100644 --- a/interfaces/inner_api/common/BUILD.gn +++ b/interfaces/inner_api/common/BUILD.gn @@ -37,6 +37,7 @@ ohos_shared_library("datashare_common") { "${datashare_base_path}/interfaces/inner_api/common/include", "${datashare_base_path}/interfaces/inner_api/consumer/include", "${datashare_base_path}/interfaces/inner_api/provider/include", + "${datashare_native_proxy_path}/include", "//foundation/communication/ipc/ipc/native/src/napi_common/include", "//foundation/distributeddatamgr/kv_store/frameworks/common", ] @@ -55,6 +56,8 @@ ohos_shared_library("datashare_common") { "${datashare_common_native_path}/src/ishared_result_set_proxy.cpp", "${datashare_common_native_path}/src/ishared_result_set_stub.cpp", "${datashare_common_native_path}/src/shared_block.cpp", + "${datashare_native_proxy_path}/src/data_share_manager_impl.cpp", + "${datashare_native_proxy_path}/src/data_share_service_proxy.cpp", ] deps = [ "${ability_runtime_path}/frameworks/native/ability/native:abilitykit_native" ] @@ -76,6 +79,7 @@ ohos_shared_library("datashare_common") { "ipc:ipc_napi_common", "ipc:ipc_single", "napi:ace_napi", + "samgr:samgr_proxy", ] subsystem_name = "distributeddatamgr" diff --git a/interfaces/inner_api/common/libdatashare_common.map b/interfaces/inner_api/common/libdatashare_common.map index d0120308..673d7496 100644 --- a/interfaces/inner_api/common/libdatashare_common.map +++ b/interfaces/inner_api/common/libdatashare_common.map @@ -22,6 +22,9 @@ *Error*; *ISharedResultSet*; *ITypesUtil*; + *DataShareManagerImpl*; + *DataShareServiceProxy*; + *DataShareKvServiceProxy*; local: *; }; \ No newline at end of file diff --git a/interfaces/inner_api/consumer/include/datashare_helper.h b/interfaces/inner_api/consumer/include/datashare_helper.h index ff2bc8a8..c0107ad5 100644 --- a/interfaces/inner_api/consumer/include/datashare_helper.h +++ b/interfaces/inner_api/consumer/include/datashare_helper.h @@ -19,13 +19,13 @@ #include #include #include -#include #include -#include "base_connection.h" #include "app/context.h" +#include "base_connection.h" #include "datashare_business_error.h" #include "datashare_template.h" +#include "published_data_subscriber_manager.h" #include "rdb_subscriber_manager.h" #include "uri.h" -- Gitee From 8c82e9c3309aa08edb4597cba5e73a5990469579 Mon Sep 17 00:00:00 2001 From: hanlu Date: Wed, 24 May 2023 18:09:35 +0800 Subject: [PATCH 4/4] f Signed-off-by: hanlu --- frameworks/native/provider/src/js_datashare_ext_ability.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/frameworks/native/provider/src/js_datashare_ext_ability.cpp b/frameworks/native/provider/src/js_datashare_ext_ability.cpp index a22f50a5..6040d487 100644 --- a/frameworks/native/provider/src/js_datashare_ext_ability.cpp +++ b/frameworks/native/provider/src/js_datashare_ext_ability.cpp @@ -806,6 +806,10 @@ void JsDataShareExtAbility::NotifyToDataShareService() MessageParcel data; MessageParcel reply; MessageOption option(MessageOption::TF_ASYNC); + if (!data.WriteInterfaceToken(IDataShareService::GetDescriptor())) { + LOG_ERROR("Write descriptor failed!"); + return; + } remote->SendRequest(IDataShareService::DATA_SHARE_SERVICE_CMD_NOTIFY, data, reply, option); } -- Gitee