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 d56c11d762d57b696c30bc5c352236d513948e5c..722daae49a57f75d8edadc2db8612e75171e9646 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/include/js_datashare_ext_ability.h b/frameworks/native/provider/include/js_datashare_ext_ability.h index 41a61e333d60743ddc2e2210c9030dcd4b2a2c5d..dd81f07fade86a42919e2c205d7847fe23f03205 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 dfbe00de78233a6e54d0e8a908db599000af4a26..6040d487bc83e8a7c9806e9ea822916a68caeb76 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,38 @@ 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); + if (!data.WriteInterfaceToken(IDataShareService::GetDescriptor())) { + LOG_ERROR("Write descriptor failed!"); + return; + } + remote->SendRequest(IDataShareService::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 568dd1a16a4381eb3ef94e12381374b984e6aa55..9c2fe7a3f589dedd24b3bd1155a1eb5a12ea0e17 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 }; diff --git a/interfaces/inner_api/BUILD.gn b/interfaces/inner_api/BUILD.gn index ca280e64c278c4800bfbb7b8b733d5cf45887573..0388b5b45215b89b935ebb708dd4771bb8f2131c 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" @@ -123,6 +120,7 @@ ohos_shared_library("datashare_provider") { "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 06abf4c76e5fe4aeceb4941b2c68b6662d0cc051..3871042c5ccf336fee49277c48499c13fa6ceb1e 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 d0120308527894f4cba43739e9f4486ead40d9ad..673d7496974e344af4a067755c9aa7831e5631bf 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 ff2bc8a8c510bc29dfb9f62031eae79953acdffb..c0107ad5b9f8b04152f24748d3e4d1b7f2cb1782 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"