diff --git a/bundle.json b/bundle.json index 3250cc91439c7ad8c6a3337be41d285c0e132dc5..42aaf9b242d4cb5cfac9a82e26cb26885b6c0629 100644 --- a/bundle.json +++ b/bundle.json @@ -52,7 +52,8 @@ "//foundation/distributedhardware/distributedscreen/services/screentransport/screensourcetrans:distributed_screen_sourcetrans", "//foundation/distributedhardware/distributedscreen/services/screenservice/sinkservice:distributed_screen_sink", "//foundation/distributedhardware/distributedscreen/services/screenservice/sourceservice:distributed_screen_source", - "//foundation/distributedhardware/distributedscreen/sa_profile:dscreen_sa_profile" + "//foundation/distributedhardware/distributedscreen/sa_profile:dscreen_sa_profile", + "//foundation/distributedhardware/distributedscreen/sa_profile:dscreen.cfg" ], "inner_kits":[ { diff --git a/common/include/dscreen_constants.h b/common/include/dscreen_constants.h index cce75aab13b162d6744c895848824d1c48ed8351..c4b08a4b15ca14fa32b802a062b98f3c87059d89 100644 --- a/common/include/dscreen_constants.h +++ b/common/include/dscreen_constants.h @@ -58,7 +58,7 @@ enum VideoFormat : uint8_t { }; /* Screen package name */ -const std::string PKG_NAME = "ohos.dhardware"; +const std::string PKG_NAME = "ohos.dhardware.dscreen"; /* Screen data session name */ const std::string DATA_SESSION_NAME = "ohos.dhardware.dscreen.data"; @@ -125,6 +125,7 @@ constexpr int32_t DISTRIBUTED_HARDWARE_SCREEN_SOURCE_SA_ID = 4807; constexpr int32_t DISTRIBUTED_HARDWARE_SCREEN_SINK_SA_ID = 4808; constexpr uint64_t SCREEN_ID_INVALID = -1ULL; constexpr uint64_t SCREEN_ID_DEFAULT = 0; +constexpr int32_t SCREEN_LOADSA_TIMEOUT_MS = 10000; } // namespace DistributedHardware } // namespace OHOS #endif \ No newline at end of file diff --git a/common/include/dscreen_errcode.h b/common/include/dscreen_errcode.h index a6101bbebb3150de870007eba4d5d3aa68fb1acc..987e9195c9054b11cb22a90e67e78cd9c68e9c32 100644 --- a/common/include/dscreen_errcode.h +++ b/common/include/dscreen_errcode.h @@ -53,6 +53,7 @@ enum DScreenErrorCode { ERR_DH_SCREEN_SA_REGISTER_SCREENLISTENER_FAIL = -500029, ERR_DH_SCREEN_SA_UNREGISTER_SCREENLISTENER_FAIL = -500030, ERR_DH_SCREEN_SA_DSCREEN_NEGOTIATE_CODEC_FAIL = -500031, + ERR_DH_SCREEN_SA_LOAD_TIMEOUT = -500032, // Transport component error code ERR_DH_SCREEN_TRANS_ERROR = -51000, ERR_DH_SCREEN_TRANS_TIMEOUT = -51001, diff --git a/interfaces/innerkits/native_cpp/screen_sink/BUILD.gn b/interfaces/innerkits/native_cpp/screen_sink/BUILD.gn index bcbb3e9b0c1f0757fcabceb1fd95bbc8cf1d1317..adc10a540538a713700035ebf28382004c631f2f 100644 --- a/interfaces/innerkits/native_cpp/screen_sink/BUILD.gn +++ b/interfaces/innerkits/native_cpp/screen_sink/BUILD.gn @@ -13,43 +13,46 @@ import("//build/ohos.gni") import("//build/ohos_var.gni") -import("//foundation/distributedhardware/distributedscreen/distributedscreen.gni") +import( + "//foundation/distributedhardware/distributedscreen/distributedscreen.gni") ohos_shared_library("distributed_screen_sink_sdk") { - include_dirs = [ - "//utils/system/safwk/native/include", - "${fwk_common_path}/utils/include", - ] - - include_dirs += [ - "include", - "${common_path}/include", - ] - - sources = [ - "src/dscreen_sink_handler.cpp", - "src/dscreen_sink_proxy.cpp", - ] - - deps = [ - "//utils/native/base:utils", - "${common_path}:distributed_screen_utils", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"dscreensinksdk\"", - "LOG_DOMAIN=0xD004100", - ] - - external_deps = [ - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr_standard:samgr_proxy", - ] - - subsystem_name = "distributedhardware" - - part_name = "distributed_screen" -} \ No newline at end of file + include_dirs = [ + "//utils/system/safwk/native/include", + "${fwk_common_path}/utils/include", + ] + + include_dirs += [ + "include", + "include/callback", + "${common_path}/include", + ] + + sources = [ + "src/callback/dscreen_sink_load_callback.cpp", + "src/dscreen_sink_handler.cpp", + "src/dscreen_sink_proxy.cpp", + ] + + deps = [ + "${common_path}:distributed_screen_utils", + "//utils/native/base:utils", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"dscreensinksdk\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] + + subsystem_name = "distributedhardware" + + part_name = "distributed_screen" +} diff --git a/interfaces/innerkits/native_cpp/screen_sink/include/callback/dscreen_sink_load_callback.h b/interfaces/innerkits/native_cpp/screen_sink/include/callback/dscreen_sink_load_callback.h new file mode 100644 index 0000000000000000000000000000000000000000..92496721342a9ba0315006790021ca19840dad93 --- /dev/null +++ b/interfaces/innerkits/native_cpp/screen_sink/include/callback/dscreen_sink_load_callback.h @@ -0,0 +1,34 @@ +/* + * 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_DSCREEN_SINK_LOAD_CALLBACK_H +#define OHOS_DSCREEN_SINK_LOAD_CALLBACK_H + +#include "system_ability_load_callback_stub.h" + +namespace OHOS { +namespace DistributedHardware { +class DScreenSinkLoadCallback : public SystemAbilityLoadCallbackStub { +public: + explicit DScreenSinkLoadCallback(const std::string ¶ms); + void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, + const sptr &remoteObject) override; + void OnLoadSystemAbilityFail(int32_t systemAbilityId) override; +private: + std::string params_; +}; +} +} +#endif \ No newline at end of file diff --git a/interfaces/innerkits/native_cpp/screen_sink/include/dscreen_sink_handler.h b/interfaces/innerkits/native_cpp/screen_sink/include/dscreen_sink_handler.h index 152884ded32f1622fff676707a4840e759c8c4a1..400e510621dd5fe8743d4f66c26fb4a4a7de84c5 100644 --- a/interfaces/innerkits/native_cpp/screen_sink/include/dscreen_sink_handler.h +++ b/interfaces/innerkits/native_cpp/screen_sink/include/dscreen_sink_handler.h @@ -16,6 +16,7 @@ #ifndef OHOS_DSCREEN_SINK_HANDLER_H #define OHOS_DSCREEN_SINK_HANDLER_H +#include #include #include "idistributed_hardware_sink.h" @@ -33,6 +34,7 @@ public: int32_t SubscribeLocalHardware(const std::string &dhId, const std::string ¶m) override; int32_t UnsubscribeLocalHardware(const std::string &dhId) override; void OnRemoteSinkSvrDied(const wptr &remote); + void FinishStartSA(const std::string ¶ms, const sptr &remoteObject); private: class DScreenSinkSvrRecipient : public IRemoteObject::DeathRecipient { public: @@ -42,7 +44,8 @@ private: DScreenSinkHandler(); ~DScreenSinkHandler(); - std::mutex mutex_; + std::mutex proxyMutex_; + std::condition_variable proxyConVar_; sptr dScreenSinkProxy_ = nullptr; sptr sinkSvrRecipient_ = nullptr; }; diff --git a/interfaces/innerkits/native_cpp/screen_sink/src/callback/dscreen_sink_load_callback.cpp b/interfaces/innerkits/native_cpp/screen_sink/src/callback/dscreen_sink_load_callback.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2911bce44c5de42b0cffe66bda1b3f2838e81ef9 --- /dev/null +++ b/interfaces/innerkits/native_cpp/screen_sink/src/callback/dscreen_sink_load_callback.cpp @@ -0,0 +1,43 @@ +/* + * 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 "dscreen_sink_load_callback.h" + +#include "dscreen_log.h" +#include "dscreen_sink_handler.h" + +namespace OHOS { +namespace DistributedHardware { +DScreenSinkLoadCallback::DScreenSinkLoadCallback( + const std::string ¶ms) : params_(params) {} + +void DScreenSinkLoadCallback::OnLoadSystemAbilitySuccess( + int32_t systemAbilityId, const sptr &remoteObject) +{ + DHLOGI("load screen SA success, systemAbilityId:%d, remoteObject result:%s", + systemAbilityId, (remoteObject != nullptr) ? "true" : "false"); + if (remoteObject == nullptr) { + DHLOGE("remoteObject is nullptr"); + return; + } + + DScreenSinkHandler::GetInstance().FinishStartSA(params_, remoteObject); +} + +void DScreenSinkLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) +{ + DHLOGE("load screen SA failed, systemAbilityId:%d", systemAbilityId); +} +} +} \ No newline at end of file diff --git a/interfaces/innerkits/native_cpp/screen_sink/src/dscreen_sink_handler.cpp b/interfaces/innerkits/native_cpp/screen_sink/src/dscreen_sink_handler.cpp index d672bcbbea0a6923a0940ee74fe80e4923114675..40390679c01d95c244769b5c2691e7d69b57a500 100644 --- a/interfaces/innerkits/native_cpp/screen_sink/src/dscreen_sink_handler.cpp +++ b/interfaces/innerkits/native_cpp/screen_sink/src/dscreen_sink_handler.cpp @@ -21,6 +21,7 @@ #include "dscreen_constants.h" #include "dscreen_errcode.h" #include "dscreen_log.h" +#include "dscreen_sink_load_callback.h" namespace OHOS { namespace DistributedHardware { @@ -29,7 +30,7 @@ IMPLEMENT_SINGLE_INSTANCE(DScreenSinkHandler); DScreenSinkHandler::DScreenSinkHandler() { DHLOGI("DScreenSinkHandler construct."); - std::lock_guard lock(mutex_); + std::lock_guard lock(proxyMutex_); if (!sinkSvrRecipient_) { sinkSvrRecipient_ = new DScreenSinkSvrRecipient(); } @@ -43,49 +44,65 @@ DScreenSinkHandler::~DScreenSinkHandler() int32_t DScreenSinkHandler::InitSink(const std::string ¶ms) { DHLOGD("InitSink"); - std::lock_guard lock(mutex_); - if (!dScreenSinkProxy_) { - sptr samgr = - SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (!samgr) { DHLOGE("Failed to get system ability mgr."); return ERR_DH_SCREEN_SA_GET_SAMGR_FAIL; } - sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_SCREEN_SINK_SA_ID); - if (!remoteObject) { - DHLOGE("Failed to get dscreen sink service."); - return ERR_DH_SCREEN_SA_GET_SINKSERVICE_FAIL; - } - - remoteObject->AddDeathRecipient(sinkSvrRecipient_); - dScreenSinkProxy_ = iface_cast(remoteObject); - if ((!dScreenSinkProxy_) || (!dScreenSinkProxy_->AsObject())) { - DHLOGE("Failed to get dscreen sink proxy."); + sptr loadCallback = new DScreenSinkLoadCallback(params); + int32_t ret = samgr->LoadSystemAbility(DISTRIBUTED_HARDWARE_SCREEN_SINK_SA_ID, loadCallback); + if (ret != ERR_OK) { + DHLOGE("Failed to Load systemAbility, systemAbilityId:%d, ret code:%d", + DISTRIBUTED_HARDWARE_SCREEN_SINK_SA_ID, ret); return ERR_DH_SCREEN_SA_GET_SINKPROXY_FAIL; } } - int32_t ret = dScreenSinkProxy_->InitSink(params); - return ret; + + std::unique_lock lock(proxyMutex_); + auto waitStatus = proxyConVar_.wait_for(lock, std::chrono::milliseconds(SCREEN_LOADSA_TIMEOUT_MS), + [this]() { return dScreenSinkProxy_ != nullptr; }); + if (!waitStatus) { + DHLOGE("screen load sa timeout"); + return ERR_DH_SCREEN_SA_LOAD_TIMEOUT; + } + + return DH_SUCCESS; +} + +void DScreenSinkHandler::FinishStartSA(const std::string ¶ms, + const sptr &remoteObject) +{ + DHLOGD("FinishStartSA"); + std::lock_guard lock(proxyMutex_); + remoteObject->AddDeathRecipient(sinkSvrRecipient_); + dScreenSinkProxy_ = iface_cast(remoteObject); + if ((!dScreenSinkProxy_) || (!dScreenSinkProxy_->AsObject())) { + DHLOGE("Failed to get dscreen sink proxy."); + return; + } + dScreenSinkProxy_->InitSink(params); + proxyConVar_.notify_one(); } int32_t DScreenSinkHandler::ReleaseSink() { DHLOGD("ReleaseSink"); - std::lock_guard lock(mutex_); + std::lock_guard lock(proxyMutex_); if (!dScreenSinkProxy_) { DHLOGE("screen sink proxy not init."); return ERR_DH_SCREEN_SA_SINKPROXY_NOT_INIT; } int32_t ret = dScreenSinkProxy_->ReleaseSink(); + dScreenSinkProxy_ = nullptr; return ret; } int32_t DScreenSinkHandler::SubscribeLocalHardware(const std::string &dhId, const std::string ¶m) { DHLOGD("SubscribeLocalHardware"); - std::lock_guard lock(mutex_); + std::lock_guard lock(proxyMutex_); if (!dScreenSinkProxy_) { DHLOGE("screen sink proxy not init."); return ERR_DH_SCREEN_SA_SINKPROXY_NOT_INIT; @@ -97,7 +114,7 @@ int32_t DScreenSinkHandler::SubscribeLocalHardware(const std::string &dhId, cons int32_t DScreenSinkHandler::UnsubscribeLocalHardware(const std::string &dhId) { DHLOGD("UnsubscribeLocalHardware"); - std::lock_guard lock(mutex_); + std::lock_guard lock(proxyMutex_); if (!dScreenSinkProxy_) { DHLOGE("screen sink proxy not init."); return ERR_DH_SCREEN_SA_SINKPROXY_NOT_INIT; @@ -120,7 +137,7 @@ void DScreenSinkHandler::OnRemoteSinkSvrDied(const wptr &remote) DHLOGE("OnRemoteDied remote promoted failed"); return; } - std::lock_guard lock(mutex_); + std::lock_guard lock(proxyMutex_); if (dScreenSinkProxy_ != nullptr) { dScreenSinkProxy_->AsObject()->RemoveDeathRecipient(sinkSvrRecipient_); dScreenSinkProxy_ = nullptr; diff --git a/interfaces/innerkits/native_cpp/screen_source/BUILD.gn b/interfaces/innerkits/native_cpp/screen_source/BUILD.gn index fec91820c36aa63208f420b31e63f6815ff8b66d..565bc5e61bda647f0e5e617f73a483889092ebdc 100644 --- a/interfaces/innerkits/native_cpp/screen_source/BUILD.gn +++ b/interfaces/innerkits/native_cpp/screen_source/BUILD.gn @@ -13,46 +13,48 @@ import("//build/ohos.gni") import("//build/ohos_var.gni") -import("//foundation/distributedhardware/distributedscreen/distributedscreen.gni") +import( + "//foundation/distributedhardware/distributedscreen/distributedscreen.gni") ohos_shared_library("distributed_screen_source_sdk") { - include_dirs = [ - "//utils/system/safwk/native/include", - "${fwk_common_path}/utils/include", - ] - - include_dirs += [ - "include", - "include/callback", - "${common_path}/include", - ] - - sources = [ - "src/dscreen_source_handler.cpp", - "src/dscreen_source_proxy.cpp", - "src/callback/dscreen_source_callback_stub.cpp", - "src/callback/dscreen_source_callback.cpp", - ] - - deps = [ - "//utils/native/base:utils", - "${common_path}:distributed_screen_utils", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"dscreensourcesdk\"", - "LOG_DOMAIN=0xD004100", - ] - - external_deps = [ - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr_standard:samgr_proxy", - ] - - subsystem_name = "distributedhardware" - - part_name = "distributed_screen" -} \ No newline at end of file + include_dirs = [ + "//utils/system/safwk/native/include", + "${fwk_common_path}/utils/include", + ] + + include_dirs += [ + "include", + "include/callback", + "${common_path}/include", + ] + + sources = [ + "src/callback/dscreen_source_callback.cpp", + "src/callback/dscreen_source_callback_stub.cpp", + "src/callback/dscreen_source_load_callback.cpp", + "src/dscreen_source_handler.cpp", + "src/dscreen_source_proxy.cpp", + ] + + deps = [ + "${common_path}:distributed_screen_utils", + "//utils/native/base:utils", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"dscreensourcesdk\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] + + subsystem_name = "distributedhardware" + + part_name = "distributed_screen" +} diff --git a/interfaces/innerkits/native_cpp/screen_source/include/callback/dscreen_source_load_callback.h b/interfaces/innerkits/native_cpp/screen_source/include/callback/dscreen_source_load_callback.h new file mode 100644 index 0000000000000000000000000000000000000000..17688f1b4bf3628da040cf05fb4652db5f08bf3c --- /dev/null +++ b/interfaces/innerkits/native_cpp/screen_source/include/callback/dscreen_source_load_callback.h @@ -0,0 +1,34 @@ +/* + * 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_DSCREEN_SOURCE_LOAD_CALLBACK_H +#define OHOS_DSCREEN_SOURCE_LOAD_CALLBACK_H + +#include "system_ability_load_callback_stub.h" + +namespace OHOS { +namespace DistributedHardware { +class DScreenSourceLoadCallback : public SystemAbilityLoadCallbackStub { +public: + explicit DScreenSourceLoadCallback(const std::string ¶ms); + void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, + const sptr &remoteObject) override; + void OnLoadSystemAbilityFail(int32_t systemAbilityId) override; +private: + std::string params_; +}; +} +} +#endif \ No newline at end of file diff --git a/interfaces/innerkits/native_cpp/screen_source/include/dscreen_source_handler.h b/interfaces/innerkits/native_cpp/screen_source/include/dscreen_source_handler.h index 0ee40a01795f4aca6ec503cbeb4690d0d68b2c66..a602ab613df22e00daa8c0b4dab97307c379a6e7 100644 --- a/interfaces/innerkits/native_cpp/screen_source/include/dscreen_source_handler.h +++ b/interfaces/innerkits/native_cpp/screen_source/include/dscreen_source_handler.h @@ -16,6 +16,7 @@ #ifndef OHOS_DSCREEN_SOURCE_HANDLER_H #define OHOS_DSCREEN_SOURCE_HANDLER_H +#include #include #include "dscreen_source_callback.h" @@ -37,6 +38,7 @@ public: int32_t ConfigDistributedHardware(const std::string &devId, const std::string &dhId, const std::string &key, const std::string &value) override; void OnRemoteSourceSvrDied(const wptr &remote); + void FinishStartSA(const std::string ¶ms, const sptr &remoteObject); private: class DScreenSourceSvrRecipient : public IRemoteObject::DeathRecipient { public: @@ -46,7 +48,8 @@ private: DScreenSourceHandler(); ~DScreenSourceHandler(); - std::mutex mutex_; + std::mutex proxyMutex_; + std::condition_variable proxyConVar_; sptr dScreenSourceProxy_ = nullptr; sptr dScreenSourceCallback_ = nullptr; sptr sourceSvrRecipient_ = nullptr; diff --git a/interfaces/innerkits/native_cpp/screen_source/src/callback/dscreen_source_callback_stub.cpp b/interfaces/innerkits/native_cpp/screen_source/src/callback/dscreen_source_callback_stub.cpp index 08f9ce8c09529a817f41cf9ae864512c0332c40a..c9ac9a53a5102d3c7218b43f13a3280bbf532f2d 100644 --- a/interfaces/innerkits/native_cpp/screen_source/src/callback/dscreen_source_callback_stub.cpp +++ b/interfaces/innerkits/native_cpp/screen_source/src/callback/dscreen_source_callback_stub.cpp @@ -33,6 +33,14 @@ DScreenSourceCallbackStub::~DScreenSourceCallbackStub() int32_t DScreenSourceCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { + DHLOGI("OnRemoteRequest, code: %d", code); + std::u16string desc = DScreenSourceCallbackStub::GetDescriptor(); + std::u16string remoteDesc = data.ReadInterfaceToken(); + if (desc != remoteDesc) { + DHLOGE("DScreenSourceCallbackStub::OnRemoteRequest remoteDesc is invalid!"); + return ERR_INVALID_DATA; + } + std::map::iterator iter = memberFuncMap_.find(code); if (iter == memberFuncMap_.end()) { DHLOGE("invalid request code."); diff --git a/interfaces/innerkits/native_cpp/screen_source/src/callback/dscreen_source_load_callback.cpp b/interfaces/innerkits/native_cpp/screen_source/src/callback/dscreen_source_load_callback.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9c7cdcb45e4a004164424831e5361fb8668efcb2 --- /dev/null +++ b/interfaces/innerkits/native_cpp/screen_source/src/callback/dscreen_source_load_callback.cpp @@ -0,0 +1,43 @@ +/* + * 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 "dscreen_source_load_callback.h" + +#include "dscreen_log.h" +#include "dscreen_source_handler.h" + +namespace OHOS { +namespace DistributedHardware { +DScreenSourceLoadCallback::DScreenSourceLoadCallback( + const std::string ¶ms) : params_(params) {} + +void DScreenSourceLoadCallback::OnLoadSystemAbilitySuccess( + int32_t systemAbilityId, const sptr &remoteObject) +{ + DHLOGI("load screen SA success, systemAbilityId:%d, remoteObject result:%s", + systemAbilityId, (remoteObject != nullptr) ? "true" : "false"); + if (remoteObject == nullptr) { + DHLOGE("remoteObject is nullptr"); + return; + } + + DScreenSourceHandler::GetInstance().FinishStartSA(params_, remoteObject); +} + +void DScreenSourceLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) +{ + DHLOGE("load screen SA failed, systemAbilityId:%d", systemAbilityId); +} +} +} diff --git a/interfaces/innerkits/native_cpp/screen_source/src/dscreen_source_handler.cpp b/interfaces/innerkits/native_cpp/screen_source/src/dscreen_source_handler.cpp index 55adeebe908e9ac3ebac9ce533211b79b54826e1..a45b0502bf71df9f31998c0ad0016f90c54866ff 100644 --- a/interfaces/innerkits/native_cpp/screen_source/src/dscreen_source_handler.cpp +++ b/interfaces/innerkits/native_cpp/screen_source/src/dscreen_source_handler.cpp @@ -21,6 +21,7 @@ #include "dscreen_constants.h" #include "dscreen_errcode.h" #include "dscreen_log.h" +#include "dscreen_source_load_callback.h" #include "dscreen_util.h" namespace OHOS { @@ -30,7 +31,7 @@ IMPLEMENT_SINGLE_INSTANCE(DScreenSourceHandler); DScreenSourceHandler::DScreenSourceHandler() { DHLOGI("DScreenSourceHandler construct."); - std::lock_guard lock(mutex_); + std::lock_guard lock(proxyMutex_); if (!sourceSvrRecipient_) { sourceSvrRecipient_ = new DScreenSourceSvrRecipient(); } @@ -48,42 +49,58 @@ DScreenSourceHandler::~DScreenSourceHandler() int32_t DScreenSourceHandler::InitSource(const std::string ¶ms) { DHLOGD("InitSource"); - std::lock_guard lock(mutex_); if (!dScreenSourceProxy_) { - sptr samgr = - SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (!samgr) { DHLOGE("Failed to get system ability mgr."); return ERR_DH_SCREEN_SA_GET_SAMGR_FAIL; } - sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_SCREEN_SOURCE_SA_ID); - if (!remoteObject) { - DHLOGE("Failed to get dscreen source service."); - return ERR_DH_SCREEN_SA_GET_SOURCESERVICE_FAIL; - } - - remoteObject->AddDeathRecipient(sourceSvrRecipient_); - dScreenSourceProxy_ = iface_cast(remoteObject); - if ((!dScreenSourceProxy_) || (!dScreenSourceProxy_->AsObject())) { - DHLOGE("Failed to get dscreen source proxy."); + sptr loadCallback = new DScreenSourceLoadCallback(params); + int32_t ret = samgr->LoadSystemAbility(DISTRIBUTED_HARDWARE_SCREEN_SOURCE_SA_ID, loadCallback); + if (ret != ERR_OK) { + DHLOGE("Failed to Load systemAbility, systemAbilityId:%d, ret code:%d", + DISTRIBUTED_HARDWARE_SCREEN_SOURCE_SA_ID, ret); return ERR_DH_SCREEN_SA_GET_SOURCEPROXY_FAIL; } } - int32_t ret = dScreenSourceProxy_->InitSource(params, dScreenSourceCallback_); - return ret; + std::unique_lock lock(proxyMutex_); + auto waitStatus = proxyConVar_.wait_for(lock, std::chrono::milliseconds(SCREEN_LOADSA_TIMEOUT_MS), + [this]() { return (dScreenSourceProxy_ != nullptr); }); + if (!waitStatus) { + DHLOGE("screen load sa timeout."); + return ERR_DH_SCREEN_SA_LOAD_TIMEOUT; + } + + return DH_SUCCESS; +} + +void DScreenSourceHandler::FinishStartSA(const std::string ¶ms, + const sptr &remoteObject) +{ + DHLOGD("FinishStartSA"); + std::lock_guard lock(proxyMutex_); + remoteObject->AddDeathRecipient(sourceSvrRecipient_); + dScreenSourceProxy_ = iface_cast(remoteObject); + if ((!dScreenSourceProxy_) || (!dScreenSourceProxy_->AsObject())) { + DHLOGE("Failed to get dscreen source proxy."); + return; + } + dScreenSourceProxy_->InitSource(params, dScreenSourceCallback_); + proxyConVar_.notify_one(); } int32_t DScreenSourceHandler::ReleaseSource() { DHLOGD("ReleaseSource"); - std::lock_guard lock(mutex_); + std::lock_guard lock(proxyMutex_); if (!dScreenSourceProxy_) { DHLOGE("screen source proxy not init."); return ERR_DH_SCREEN_SA_SOURCEPROXY_NOT_INIT; } int32_t ret = dScreenSourceProxy_->ReleaseSource(); + dScreenSourceProxy_ = nullptr; return ret; } @@ -92,7 +109,7 @@ int32_t DScreenSourceHandler::RegisterDistributedHardware(const std::string &dev { DHLOGD("RegisterDistributedHardware, devId: %s, dhId: %s", GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); - std::lock_guard lock(mutex_); + std::lock_guard lock(proxyMutex_); if (!dScreenSourceProxy_) { DHLOGE("screen source proxy not init."); return ERR_DH_SCREEN_SA_SOURCEPROXY_NOT_INIT; @@ -113,7 +130,7 @@ int32_t DScreenSourceHandler::UnregisterDistributedHardware(const std::string &d { DHLOGD("UnregisterDistributedHardware, devId: %s, dhId: %s", GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); - std::lock_guard lock(mutex_); + std::lock_guard lock(proxyMutex_); if (!dScreenSourceProxy_) { DHLOGE("screen source proxy not init."); return ERR_DH_SCREEN_SA_SOURCEPROXY_NOT_INIT; @@ -150,7 +167,7 @@ void DScreenSourceHandler::OnRemoteSourceSvrDied(const wptr &remo DHLOGE("OnRemoteDied remote promoted failed"); return; } - std::lock_guard lock(mutex_); + std::lock_guard lock(proxyMutex_); if (dScreenSourceProxy_ != nullptr) { dScreenSourceProxy_->AsObject()->RemoveDeathRecipient(sourceSvrRecipient_); dScreenSourceProxy_ = nullptr; diff --git a/sa_profile/4807.xml b/sa_profile/4807.xml index f3f552e2f137992fe8b494662d5a02ea6e3b40cd..6cc4818f529551f7b232cda6673a7c06acc3eb2f 100644 --- a/sa_profile/4807.xml +++ b/sa_profile/4807.xml @@ -14,13 +14,13 @@ * limitations under the License. --> - dhardware + dscreen 4807 libdistributed_screen_source.z.so - true + false true 1 diff --git a/sa_profile/4808.xml b/sa_profile/4808.xml index 6ec95fd48110875d465d97392409fb23b3d3a4d9..6b1647959d97071edf114bbc9d1eeaa1c8980621 100644 --- a/sa_profile/4808.xml +++ b/sa_profile/4808.xml @@ -14,13 +14,13 @@ * limitations under the License. --> - dhardware + dscreen 4808 libdistributed_screen_sink.z.so - true + false true 1 diff --git a/sa_profile/BUILD.gn b/sa_profile/BUILD.gn index 6b167fbbb2f4159d4b1883a946714a5ea5f51368..8d64abb9f89ed4db44087d5304c31da15e6c95de 100644 --- a/sa_profile/BUILD.gn +++ b/sa_profile/BUILD.gn @@ -11,7 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import("//build/ohos/sa_profile/sa_profile.gni") +import("//build/ohos.gni") ohos_sa_profile("dscreen_sa_profile") { sources = [ @@ -20,4 +20,11 @@ ohos_sa_profile("dscreen_sa_profile") { ] part_name = "distributed_screen" -} \ No newline at end of file +} + +ohos_prebuilt_etc("dscreen.cfg") { + relative_install_dir = "init" + source = "dscreen.cfg" + part_name = "distributed_screen" + subsystem_name = "distributedhardware" +} diff --git a/sa_profile/dscreen.cfg b/sa_profile/dscreen.cfg new file mode 100644 index 0000000000000000000000000000000000000000..f623798508de9a1de4202e095ef0b421b014988f --- /dev/null +++ b/sa_profile/dscreen.cfg @@ -0,0 +1,9 @@ +{ + "services" : [{ + "name" : "dscreen", + "path" : ["/system/bin/sa_main", "/system/profile/dscreen.xml"], + "uid" : "system", + "gid" : ["system"], + "ondemand" : true + }] +} \ No newline at end of file diff --git a/services/screenservice/sinkservice/BUILD.gn b/services/screenservice/sinkservice/BUILD.gn index 0564cbdaec59d980d6869dd9703c545604bb68d2..1b85c0e040074352cafed65d44f304dde3998d16 100644 --- a/services/screenservice/sinkservice/BUILD.gn +++ b/services/screenservice/sinkservice/BUILD.gn @@ -13,70 +13,71 @@ import("//build/ohos.gni") import("//build/ohos_var.gni") -import("//foundation/distributedhardware/distributedscreen/distributedscreen.gni") +import( + "//foundation/distributedhardware/distributedscreen/distributedscreen.gni") ohos_shared_library("distributed_screen_sink") { - include_dirs = [ - "//third_party/json/include", - "//utils/native/base/include", - "//utils/system/safwk/native/include", - "//foundation/graphic/standard/interfaces/innerkits/surface", - "${windowmanager_path}/interfaces/innerkits/dm", - "${fwk_common_path}/utils/include", - ] + include_dirs = [ + "//third_party/json/include", + "//utils/native/base/include", + "//utils/system/safwk/native/include", + "//foundation/graphic/standard/interfaces/innerkits/surface", + "${windowmanager_path}/interfaces/innerkits/dm", + "${fwk_common_path}/utils/include", + ] - include_dirs += [ - "./dscreenservice/include", - "./screenregionmgr/include", - "${interfaces_path}/innerkits/native_cpp/screen_sink/include", - "${interfaces_path}/innerkits/native_cpp/screen_sink/include/callback", - "${interfaces_path}/innerkits/native_cpp/screen_source/include", - "${interfaces_path}/innerkits/native_cpp/screen_source/include/callback", - "${common_path}/include", - "${services_path}/common/utils/include", - "${services_path}/common/databuffer/include", - "${services_path}/common/screen_channel/include", - "${services_path}/screentransport/screensinktrans/include", - "${services_path}/screentransport/screensinkprocessor/include", - "${services_path}/screentransport/screensinkprocessor/decoder/include", - "${services_path}/screenclient/include/", - ] + include_dirs += [ + "./dscreenservice/include", + "./screenregionmgr/include", + "${interfaces_path}/innerkits/native_cpp/screen_sink/include", + "${interfaces_path}/innerkits/native_cpp/screen_sink/include/callback", + "${interfaces_path}/innerkits/native_cpp/screen_source/include", + "${interfaces_path}/innerkits/native_cpp/screen_source/include/callback", + "${common_path}/include", + "${services_path}/common/utils/include", + "${services_path}/common/databuffer/include", + "${services_path}/common/screen_channel/include", + "${services_path}/screentransport/screensinktrans/include", + "${services_path}/screentransport/screensinkprocessor/include", + "${services_path}/screentransport/screensinkprocessor/decoder/include", + "${services_path}/screenclient/include/", + ] - sources = [ - "${services_path}/common/utils/src/dscreen_maprelation.cpp", - "${services_path}/common/utils/src/video_param.cpp", - "${interfaces_path}/innerkits/native_cpp/screen_sink/src/dscreen_sink_proxy.cpp", - "${interfaces_path}/innerkits/native_cpp/screen_source/src/dscreen_source_proxy.cpp", - "./dscreenservice/src/dscreen_sink_service.cpp", - "./dscreenservice/src/dscreen_sink_stub.cpp", - "./screenregionmgr/src/screenregion.cpp", - "./screenregionmgr/src/screenregionmgr.cpp", - ] + sources = [ + "${interfaces_path}/innerkits/native_cpp/screen_sink/src/dscreen_sink_proxy.cpp", + "${interfaces_path}/innerkits/native_cpp/screen_source/src/dscreen_source_proxy.cpp", + "${services_path}/common/utils/src/dscreen_maprelation.cpp", + "${services_path}/common/utils/src/video_param.cpp", + "./dscreenservice/src/dscreen_sink_service.cpp", + "./dscreenservice/src/dscreen_sink_stub.cpp", + "./screenregionmgr/src/screenregion.cpp", + "./screenregionmgr/src/screenregionmgr.cpp", + ] - deps = [ - "//utils/native/base:utils", - "${common_path}:distributed_screen_utils", - "${services_path}/screentransport/screensinktrans:distributed_screen_sinktrans", - "${services_path}/screenclient:distributed_screen_client", - "//foundation/graphic/standard/frameworks/surface:surface", - "${windowmanager_path}/dm:libdm", - ] + deps = [ + "${common_path}:distributed_screen_utils", + "${services_path}/screenclient:distributed_screen_client", + "${services_path}/screentransport/screensinktrans:distributed_screen_sinktrans", + "${windowmanager_path}/dm:libdm", + "//foundation/graphic/standard/frameworks/surface:surface", + "//utils/native/base:utils", + ] - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"dscreensink\"", - "LOG_DOMAIN=0xD004100", - ] + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"dscreensink\"", + "LOG_DOMAIN=0xD004100", + ] - external_deps = [ - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr_standard:samgr_proxy", - "multimedia_media_standard:media_client", - ] + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "multimedia_media_standard:media_client", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] - subsystem_name = "distributedhardware" + subsystem_name = "distributedhardware" - part_name = "distributed_screen" -} \ No newline at end of file + part_name = "distributed_screen" +} diff --git a/services/screenservice/sinkservice/dscreenservice/src/dscreen_sink_service.cpp b/services/screenservice/sinkservice/dscreenservice/src/dscreen_sink_service.cpp index 643b4155930d7ae1a8cdb572b4da137129c0e06f..020ce9546d3a440e14ff2841542a8cf841dafe43 100644 --- a/services/screenservice/sinkservice/dscreenservice/src/dscreen_sink_service.cpp +++ b/services/screenservice/sinkservice/dscreenservice/src/dscreen_sink_service.cpp @@ -76,7 +76,10 @@ int32_t DScreenSinkService::InitSink(const std::string ¶ms) int32_t DScreenSinkService::ReleaseSink() { DHLOGI("ReleaseSink"); - return ScreenRegionManager::GetInstance().ReleaseAllRegions(); + ScreenRegionManager::GetInstance().ReleaseAllRegions(); + DHLOGI("exit sink sa process"); + exit(0); + return DH_SUCCESS; } int32_t DScreenSinkService::SubscribeLocalHardware(const std::string &dhId, const std::string ¶m) diff --git a/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp b/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp index e1cb0ef3530824bcaaac58a418cfc7ad6d814d72..3a7c561db3c72bc7756bec8f0fd2238bddad4018 100644 --- a/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp +++ b/services/screenservice/sourceservice/dscreenservice/src/dscreen_source_service.cpp @@ -93,6 +93,8 @@ int32_t DScreenSourceService::ReleaseSource() DHLOGE("UnInit DScreenManager failed. err: %d", ret); return ret; } + DHLOGI("exit source sa process"); + exit(0); return DH_SUCCESS; } diff --git a/services/softbusadapter/src/softbus_adapter.cpp b/services/softbusadapter/src/softbus_adapter.cpp index 540590b01a1d578df6bcfdaed850ec22c264ba1f..29a1378c881ed2cf5112a9fd0f0163b3f142eca5 100644 --- a/services/softbusadapter/src/softbus_adapter.cpp +++ b/services/softbusadapter/src/softbus_adapter.cpp @@ -133,6 +133,12 @@ int32_t SoftbusAdapter::RemoveSoftbusSessionServer(const std::string &pkgname, c return ERR_DH_SCREEN_TRANS_ILLEGAL_OPERATION; } + int32_t ret = RemoveSessionServer(pkgname.c_str(), sessionName.c_str()); + if (ret != DH_SUCCESS) { + DHLOGE("%s: RemoveSessionServer failed.", LOG_TAG); + return ret; + } + mapSessionSet_[sessionName].erase(peerDevId); if (mapSessionSet_[sessionName].empty()) { mapSessionSet_.erase(sessionName);