diff --git a/bundle.json b/bundle.json index fcd77c3..3cedd46 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 cce75aa..c4b08a4 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 a6101bb..987e919 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 bcbb3e9..adc10a5 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 = [ + "//utils/system/safwk/native/include", + "${fwk_common_path}/utils/include", + ] - include_dirs += [ - "include", - "${common_path}/include", - ] + include_dirs += [ + "include", + "include/callback", + "${common_path}/include", + ] - sources = [ - "src/dscreen_sink_handler.cpp", - "src/dscreen_sink_proxy.cpp", - ] + sources = [ + "src/callback/dscreen_sink_load_callback.cpp", + "src/dscreen_sink_handler.cpp", + "src/dscreen_sink_proxy.cpp", + ] - deps = [ - "//utils/native/base:utils", - "${common_path}:distributed_screen_utils", - ] + deps = [ + "${common_path}:distributed_screen_utils", + "//utils/native/base:utils", + ] - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"dscreensinksdk\"", - "LOG_DOMAIN=0xD004100", - ] + 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", - ] + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "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/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 0000000..9249672 --- /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 152884d..400e510 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 0000000..2911bce --- /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 d672bcb..4039067 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 fec9182..565bc5e 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 = [ + "//utils/system/safwk/native/include", + "${fwk_common_path}/utils/include", + ] - include_dirs += [ - "include", - "include/callback", - "${common_path}/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", - ] + 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 = [ - "//utils/native/base:utils", - "${common_path}:distributed_screen_utils", - ] + deps = [ + "${common_path}:distributed_screen_utils", + "//utils/native/base:utils", + ] - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"dscreensourcesdk\"", - "LOG_DOMAIN=0xD004100", - ] + 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", - ] + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "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/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 0000000..17688f1 --- /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 0ee40a0..a602ab6 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 08f9ce8..c9ac9a5 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 0000000..9c7cdcb --- /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 55adeeb..a45b050 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 f3f552e..6cc4818 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 6ec95fd..6b16479 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 6b167fb..8d64abb 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 0000000..f623798 --- /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 0564cbd..1b85c0e 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 643b415..020ce95 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 e1cb0ef..3a7c561 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 540590b..29a1378 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);