From 6005bce7a8060a564a02170bf939281e8f0ac947 Mon Sep 17 00:00:00 2001 From: qinlong0101 Date: Tue, 16 Aug 2022 10:24:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8C=87=E9=92=88=E5=88=A4?= =?UTF-8?q?=E7=A9=BA=E5=8F=8Alog=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qinlong0101 --- common/include/dscreen_errcode.h | 2 + .../callback/dscreen_sink_load_callback.cpp | 8 ++- .../screen_sink/src/dscreen_sink_handler.cpp | 32 +++++------ .../screen_sink/src/dscreen_sink_proxy.cpp | 47 ++++++++++++---- .../src/callback/dscreen_source_callback.cpp | 7 ++- .../callback/dscreen_source_callback_stub.cpp | 2 + .../callback/dscreen_source_load_callback.cpp | 6 ++- .../src/dscreen_source_handler.cpp | 39 +++++++------- .../src/dscreen_source_proxy.cpp | 54 ++++++++++++++++--- .../dscreennotify_fuzzer.cpp | 2 +- screenhandler/src/dscreen_handler.cpp | 15 ++++-- services/screendemo/BUILD.gn | 4 ++ services/screendemo/test.cpp | 23 +++++++- .../screenregionmgr/src/screenregion.cpp | 8 +-- .../screenregionmgr/src/screenregionmgr.cpp | 8 +-- .../sourceservice/dscreenmgr/src/dscreen.cpp | 20 ++++--- .../dscreenmgr/src/dscreen_manager.cpp | 20 +++---- .../dscreenmgr/src/screen_manager_adapter.cpp | 10 +++- .../dscreen_source_callback_proxy.cpp | 14 ++++- .../src/screen_data_channel_impl.cpp | 12 ++--- .../decoder/src/image_sink_decoder.cpp | 18 ++++--- .../encoder/src/image_source_encoder.cpp | 18 +++---- .../src/image_source_processor.cpp | 8 +-- .../src/screen_source_trans.cpp | 32 +++++++---- .../softbusadapter/src/softbus_adapter.cpp | 8 +-- 25 files changed, 283 insertions(+), 134 deletions(-) diff --git a/common/include/dscreen_errcode.h b/common/include/dscreen_errcode.h index 303979d0..6b11c11e 100644 --- a/common/include/dscreen_errcode.h +++ b/common/include/dscreen_errcode.h @@ -20,6 +20,8 @@ namespace OHOS { namespace DistributedHardware { enum DScreenErrorCode { DH_SUCCESS = 0, + DSCREEN_INIT_ERR = -1, + DSCREEN_BAD_VALUE = -2, // SA error code ERR_DH_SCREEN_SA_GET_SAMGR_FAIL = -50000, ERR_DH_SCREEN_SA_GET_SOURCESERVICE_FAIL = -50001, 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 index bb6b0aa0..37e7be1c 100644 --- 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 @@ -32,6 +32,10 @@ void DScreenSinkLoadCallback::OnLoadSystemAbilitySuccess( { DHLOGI("load screen SA success, systemAbilityId:%d, remoteObject result:%s", systemAbilityId, (remoteObject != nullptr) ? "true" : "false"); + if (systemAbilityId != DISTRIBUTED_HARDWARE_SCREEN_SINK_SA_ID) { + DHLOGE("start systemabilityId is not sinkSAId!"); + return; + } if (remoteObject == nullptr) { DHLOGE("remoteObject is nullptr"); return; @@ -42,8 +46,8 @@ void DScreenSinkLoadCallback::OnLoadSystemAbilitySuccess( void DScreenSinkLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) { - DHLOGE("load screen SA failed, systemAbilityId:%d", systemAbilityId); - ReportSaFail(DSCREEN_INIT_FAIL, ERR_DH_SCREEN_SA_SINKPROXY_NOT_INIT, DISTRIBUTED_HARDWARE_SCREEN_SINK_SA_ID, + DHLOGE("load screen SA failed, systemAbilityId: %d", systemAbilityId); + ReportSaFail(DSCREEN_INIT_FAIL, ERR_DH_SCREEN_SA_SINKPROXY_NOT_INIT, systemAbilityId, "dscreen sink OnLoadSystemAbilityFail."); } } 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 a9742647..e503e1f7 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 @@ -31,6 +31,7 @@ #include "dscreen_hisysevent.h" #include "dscreen_log.h" #include "dscreen_sink_load_callback.h" +#include "dscreen_util.h" namespace OHOS { namespace DistributedHardware { @@ -52,11 +53,11 @@ DScreenSinkHandler::~DScreenSinkHandler() int32_t DScreenSinkHandler::InitSink(const std::string ¶ms) { - DHLOGD("InitSink"); + DHLOGI("DScreenSinkHandler InitSink"); std::unique_lock lock(proxyMutex_); - if (!dScreenSinkProxy_) { + if (dScreenSinkProxy_ == nullptr) { sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (!samgr) { + if (samgr == nullptr) { DHLOGE("Failed to get system ability mgr."); ReportSaFail(DSCREEN_INIT_FAIL, ERR_DH_SCREEN_SA_GET_SAMGR_FAIL, DISTRIBUTED_HARDWARE_SCREEN_SINK_SA_ID, "dscreen sink get samgr failed."); @@ -93,10 +94,9 @@ int32_t DScreenSinkHandler::InitSink(const std::string ¶ms) return DH_SUCCESS; } -void DScreenSinkHandler::FinishStartSA(const std::string ¶ms, - const sptr &remoteObject) +void DScreenSinkHandler::FinishStartSA(const std::string ¶ms, const sptr &remoteObject) { - DHLOGD("FinishStartSA"); + DHLOGI("DScreenSinkHandler FinishStartSA"); std::unique_lock lock(proxyMutex_); if (sinkSvrRecipient_ == nullptr) { DHLOGE("sinkSvrRecipient is nullptr."); @@ -106,7 +106,7 @@ void DScreenSinkHandler::FinishStartSA(const std::string ¶ms, } remoteObject->AddDeathRecipient(sinkSvrRecipient_); dScreenSinkProxy_ = iface_cast(remoteObject); - if ((!dScreenSinkProxy_) || (!dScreenSinkProxy_->AsObject())) { + if ((dScreenSinkProxy_== nullptr) || (!dScreenSinkProxy_->AsObject())) { DHLOGE("Failed to get dscreen sink proxy."); ReportSaFail(DSCREEN_INIT_FAIL, ERR_DH_SCREEN_SA_SINKPROXY_NOT_INIT, DISTRIBUTED_HARDWARE_SCREEN_SINK_SA_ID, "dscreen sink get proxy failed."); @@ -119,9 +119,9 @@ void DScreenSinkHandler::FinishStartSA(const std::string ¶ms, int32_t DScreenSinkHandler::ReleaseSink() { - DHLOGD("ReleaseSink"); + DHLOGI("DScreenSinkHandler ReleaseSink"); std::lock_guard lock(proxyMutex_); - if (!dScreenSinkProxy_) { + if (dScreenSinkProxy_ == nullptr) { DHLOGE("screen sink proxy not init."); ReportSaFail(DSCREEN_INIT_FAIL, ERR_DH_SCREEN_SA_SINKPROXY_NOT_INIT, DISTRIBUTED_HARDWARE_SCREEN_SINK_SA_ID, "dscreen sink proxy not init."); @@ -135,9 +135,9 @@ int32_t DScreenSinkHandler::ReleaseSink() int32_t DScreenSinkHandler::SubscribeLocalHardware(const std::string &dhId, const std::string ¶m) { - DHLOGD("SubscribeLocalHardware"); + DHLOGI("DScreenSinkHandler SubscribeLocalHardware dhId: %s", GetAnonyString(dhId).c_str()); std::lock_guard lock(proxyMutex_); - if (!dScreenSinkProxy_) { + if (dScreenSinkProxy_ == nullptr) { DHLOGE("screen sink proxy not init."); return ERR_DH_SCREEN_SA_SINKPROXY_NOT_INIT; } @@ -147,9 +147,9 @@ int32_t DScreenSinkHandler::SubscribeLocalHardware(const std::string &dhId, cons int32_t DScreenSinkHandler::UnsubscribeLocalHardware(const std::string &dhId) { - DHLOGD("UnsubscribeLocalHardware"); + DHLOGI("DScreenSinkHandler UnsubscribeLocalHardware dhId: %s", GetAnonyString(dhId).c_str()); std::lock_guard lock(proxyMutex_); - if (!dScreenSinkProxy_) { + if (dScreenSinkProxy_ == nullptr) { DHLOGE("screen sink proxy not init."); return ERR_DH_SCREEN_SA_SINKPROXY_NOT_INIT; } @@ -165,9 +165,9 @@ void DScreenSinkHandler::DScreenSinkSvrRecipient::OnRemoteDied(const wptr &remote) { - DHLOGI("OnRemoteSinkSvrDied"); + DHLOGI("DScreenSinkHandler OnRemoteSinkSvrDied"); sptr remoteObject = remote.promote(); - if (!remoteObject) { + if (remoteObject == nullptr) { DHLOGE("OnRemoteDied remote promoted failed"); return; } @@ -180,7 +180,7 @@ void DScreenSinkHandler::OnRemoteSinkSvrDied(const wptr &remote) IDistributedHardwareSink *GetSinkHardwareHandler() { - DHLOGD("GetSinkHardwareHandler"); + DHLOGI("GetSinkHardwareHandler"); return &DScreenSinkHandler::GetInstance(); } } // namespace DistributedHardware diff --git a/interfaces/innerkits/native_cpp/screen_sink/src/dscreen_sink_proxy.cpp b/interfaces/innerkits/native_cpp/screen_sink/src/dscreen_sink_proxy.cpp index b2e30981..92c5688c 100644 --- a/interfaces/innerkits/native_cpp/screen_sink/src/dscreen_sink_proxy.cpp +++ b/interfaces/innerkits/native_cpp/screen_sink/src/dscreen_sink_proxy.cpp @@ -21,12 +21,18 @@ #include "dscreen_errcode.h" #include "dscreen_log.h" +#include "dscreen_util.h" namespace OHOS { namespace DistributedHardware { int32_t DScreenSinkProxy::InitSink(const std::string ¶ms) { - DHLOGD("InitSink"); + DHLOGI("DScreenSinkProxy InitSink"); + sptr remote = Remote(); + if (remote == nullptr) { + DHLOGE("DScreenSinkProxy remote service null"); + return DSCREEN_BAD_VALUE; + } MessageParcel data; MessageParcel reply; MessageOption option; @@ -40,14 +46,19 @@ int32_t DScreenSinkProxy::InitSink(const std::string ¶ms) return ERR_DH_SCREEN_SA_WRITEPARAM_FAILED; } - Remote()->SendRequest(INIT_SINK, data, reply, option); + remote->SendRequest(INIT_SINK, data, reply, option); int32_t ret = reply.ReadInt32(); return ret; } int32_t DScreenSinkProxy::ReleaseSink() { - DHLOGD("ReleaseSink"); + DHLOGI("DScreenSinkProxy ReleaseSink"); + sptr remote = Remote(); + if (remote == nullptr) { + DHLOGE("DScreenSinkProxy remote service null"); + return DSCREEN_BAD_VALUE; + } MessageParcel data; MessageParcel reply; MessageOption option; @@ -56,14 +67,19 @@ int32_t DScreenSinkProxy::ReleaseSink() return ERR_DH_SCREEN_SA_WRITEINTERFACETOKEN_FAILED; } - Remote()->SendRequest(RELEASE_SINK, data, reply, option); + remote->SendRequest(RELEASE_SINK, data, reply, option); int32_t ret = reply.ReadInt32(); return ret; } int32_t DScreenSinkProxy::SubscribeLocalHardware(const std::string &dhId, const std::string ¶m) { - DHLOGD("SubscribeLocalHardware"); + DHLOGI("DScreenSinkProxy SubscribeLocalHardware dhId: %s", GetAnonyString(dhId).c_str()); + sptr remote = Remote(); + if (remote == nullptr) { + DHLOGE("DScreenSinkProxy remote service null"); + return DSCREEN_BAD_VALUE; + } MessageParcel data; MessageParcel reply; MessageOption option; @@ -77,14 +93,19 @@ int32_t DScreenSinkProxy::SubscribeLocalHardware(const std::string &dhId, const return ERR_DH_SCREEN_SA_WRITEPARAM_FAILED; } - Remote()->SendRequest(SUBSCRIBE_DISTRIBUTED_HARDWARE, data, reply, option); + remote->SendRequest(SUBSCRIBE_DISTRIBUTED_HARDWARE, data, reply, option); int32_t ret = reply.ReadInt32(); return ret; } int32_t DScreenSinkProxy::UnsubscribeLocalHardware(const std::string &dhId) { - DHLOGD("UnsubscribeLocalHardware"); + DHLOGI("DScreenSinkProxy UnsubscribeLocalHardware dhId: %s", GetAnonyString(dhId).c_str()); + sptr remote = Remote(); + if (remote == nullptr) { + DHLOGE("DScreenSinkProxy remote service null"); + return DSCREEN_BAD_VALUE; + } MessageParcel data; MessageParcel reply; MessageOption option; @@ -98,14 +119,20 @@ int32_t DScreenSinkProxy::UnsubscribeLocalHardware(const std::string &dhId) return ERR_DH_SCREEN_SA_WRITEPARAM_FAILED; } - Remote()->SendRequest(UNSUBSCRIBE_DISTRIBUTED_HARDWARE, data, reply, option); + remote->SendRequest(UNSUBSCRIBE_DISTRIBUTED_HARDWARE, data, reply, option); int32_t ret = reply.ReadInt32(); return ret; } void DScreenSinkProxy::DScreenNotify(const std::string &devId, int32_t eventCode, const std::string &eventContent) { - DHLOGD("DScreenNotify"); + DHLOGI("DScreenNotify devId: %s eventCode: %d eventContent: %s", + GetAnonyString(devId).c_str(), eventCode, eventContent.c_str()); + sptr remote = Remote(); + if (remote == nullptr) { + DHLOGE("DScreenSinkProxy remote service null"); + return; + } MessageParcel data; MessageParcel reply; MessageOption option = { MessageOption::TF_ASYNC }; @@ -119,7 +146,7 @@ void DScreenSinkProxy::DScreenNotify(const std::string &devId, int32_t eventCode return; } - Remote()->SendRequest(DSCREEN_NOTIFY, data, reply, option); + remote->SendRequest(DSCREEN_NOTIFY, data, reply, option); } } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/interfaces/innerkits/native_cpp/screen_source/src/callback/dscreen_source_callback.cpp b/interfaces/innerkits/native_cpp/screen_source/src/callback/dscreen_source_callback.cpp index 038f6c19..e22ba562 100644 --- a/interfaces/innerkits/native_cpp/screen_source/src/callback/dscreen_source_callback.cpp +++ b/interfaces/innerkits/native_cpp/screen_source/src/callback/dscreen_source_callback.cpp @@ -17,6 +17,7 @@ #include "dscreen_errcode.h" #include "dscreen_log.h" +#include "dscreen_util.h" namespace OHOS { namespace DistributedHardware { @@ -25,7 +26,8 @@ DScreenSourceCallback::~DScreenSourceCallback() {} int32_t DScreenSourceCallback::OnNotifyRegResult(const std::string &devId, const std::string &dhId, const std::string &reqId, int32_t status, const std::string &data) { - DHLOGD("OnNotifyRegResult"); + DHLOGI("DScreenSourceCallback OnNotifyRegResult devId: %s dhId: %s status: %d", + GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), status); auto iter = registerCallbackMap_.find(reqId); if (iter != registerCallbackMap_.end()) { iter->second->OnRegisterResult(devId, dhId, status, data); @@ -39,7 +41,8 @@ int32_t DScreenSourceCallback::OnNotifyRegResult(const std::string &devId, const int32_t DScreenSourceCallback::OnNotifyUnregResult(const std::string &devId, const std::string &dhId, const std::string &reqId, int32_t status, const std::string &data) { - DHLOGD("OnNotifyUnregResult"); + DHLOGI("DScreenSourceCallback OnNotifyUnregResult devId: %s dhId: %s status: %d", + GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), status); auto iter = unregisterCallbackMap_.find(reqId); if (iter != unregisterCallbackMap_.end()) { iter->second->OnUnregisterResult(devId, dhId, status, data); 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 00b55fe1..5c4fdf17 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 @@ -60,6 +60,7 @@ int32_t DScreenSourceCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel int32_t DScreenSourceCallbackStub::OnNotifyRegResultInner(MessageParcel &data, MessageParcel &reply, MessageOption &option) { + DHLOGI("DScreenSourceCallbackStub OnNotifyRegResultInner"); std::string devId = data.ReadString(); std::string dhId = data.ReadString(); std::string reqId = data.ReadString(); @@ -72,6 +73,7 @@ int32_t DScreenSourceCallbackStub::OnNotifyRegResultInner(MessageParcel &data, M int32_t DScreenSourceCallbackStub::OnNotifyUnregResultInner(MessageParcel &data, MessageParcel &reply, MessageOption &option) { + DHLOGI("DScreenSourceCallbackStub OnNotifyUnregResultInner"); std::string devId = data.ReadString(); std::string dhId = data.ReadString(); std::string reqId = data.ReadString(); 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 index a4e4e571..1e0943a5 100644 --- 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 @@ -31,6 +31,10 @@ void DScreenSourceLoadCallback::OnLoadSystemAbilitySuccess( { DHLOGI("load screen SA success, systemAbilityId:%d, remoteObject result:%s", systemAbilityId, (remoteObject != nullptr) ? "true" : "false"); + if (systemAbilityId != DISTRIBUTED_HARDWARE_SCREEN_SOURCE_SA_ID) { + DHLOGE("start systemabilityId is not sourceSAId!"); + return; + } if (remoteObject == nullptr) { DHLOGE("remoteObject is nullptr"); return; @@ -41,7 +45,7 @@ void DScreenSourceLoadCallback::OnLoadSystemAbilitySuccess( void DScreenSourceLoadCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) { DHLOGE("load screen SA failed, systemAbilityId:%d", systemAbilityId); - ReportSaFail(DSCREEN_INIT_FAIL, ERR_DH_SCREEN_SA_SINKPROXY_NOT_INIT, DISTRIBUTED_HARDWARE_SCREEN_SOURCE_SA_ID, + ReportSaFail(DSCREEN_INIT_FAIL, ERR_DH_SCREEN_SA_SOURCEPROXY_NOT_INIT, systemAbilityId, "dscreen source OnLoadSystemAbilityFail."); } } 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 86e3c206..beff2a16 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 @@ -43,11 +43,11 @@ DScreenSourceHandler::DScreenSourceHandler() { DHLOGI("DScreenSourceHandler construct."); std::lock_guard lock(proxyMutex_); - if (!sourceSvrRecipient_) { + if (sourceSvrRecipient_ == nullptr) { sourceSvrRecipient_ = new (std::nothrow) DScreenSourceSvrRecipient(); } - if (!dScreenSourceCallback_) { + if (dScreenSourceCallback_ == nullptr) { dScreenSourceCallback_ = new (std::nothrow) DScreenSourceCallback(); } } @@ -59,11 +59,11 @@ DScreenSourceHandler::~DScreenSourceHandler() int32_t DScreenSourceHandler::InitSource(const std::string ¶ms) { - DHLOGD("InitSource"); + DHLOGI("DScreenSourceHandler InitSource"); std::unique_lock lock(proxyMutex_); - if (!dScreenSourceProxy_) { + if (dScreenSourceProxy_ == nullptr) { sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (!samgr) { + if (samgr == nullptr) { DHLOGE("Failed to get system ability mgr."); ReportSaFail(DSCREEN_INIT_FAIL, ERR_DH_SCREEN_SA_GET_SAMGR_FAIL, DISTRIBUTED_HARDWARE_SCREEN_SOURCE_SA_ID, "dscreen source get samgr failed."); @@ -94,10 +94,9 @@ int32_t DScreenSourceHandler::InitSource(const std::string ¶ms) return DH_SUCCESS; } -void DScreenSourceHandler::FinishStartSA(const std::string ¶ms, - const sptr &remoteObject) +void DScreenSourceHandler::FinishStartSA(const std::string ¶ms, const sptr &remoteObject) { - DHLOGD("FinishStartSA"); + DHLOGI("DScreenSourceHandler FinishStartSA"); std::unique_lock lock(proxyMutex_); if (sourceSvrRecipient_ == nullptr) { DHLOGE("sourceSvrRecipient is nullptr."); @@ -107,7 +106,7 @@ void DScreenSourceHandler::FinishStartSA(const std::string ¶ms, } remoteObject->AddDeathRecipient(sourceSvrRecipient_); dScreenSourceProxy_ = iface_cast(remoteObject); - if ((!dScreenSourceProxy_) || (!dScreenSourceProxy_->AsObject())) { + if ((dScreenSourceProxy_ == nullptr) || (!dScreenSourceProxy_->AsObject())) { DHLOGE("Failed to get dscreen source proxy."); ReportSaFail(DSCREEN_INIT_FAIL, ERR_DH_SCREEN_SA_SOURCEPROXY_NOT_INIT, DISTRIBUTED_HARDWARE_SCREEN_SOURCE_SA_ID, "dscreen source get proxy failed."); @@ -126,9 +125,9 @@ void DScreenSourceHandler::FinishStartSA(const std::string ¶ms, int32_t DScreenSourceHandler::ReleaseSource() { - DHLOGD("ReleaseSource"); + DHLOGI("DScreenSourceHandler ReleaseSource"); std::lock_guard lock(proxyMutex_); - if (!dScreenSourceProxy_) { + if (dScreenSourceProxy_ == nullptr) { DHLOGE("screen source proxy not init."); ReportSaFail(DSCREEN_INIT_FAIL, ERR_DH_SCREEN_SA_SOURCEPROXY_NOT_INIT, DISTRIBUTED_HARDWARE_SCREEN_SOURCE_SA_ID, "dscreen source proxy not init."); @@ -142,18 +141,18 @@ int32_t DScreenSourceHandler::ReleaseSource() int32_t DScreenSourceHandler::RegisterDistributedHardware(const std::string &devId, const std::string &dhId, const EnableParam ¶m, std::shared_ptr callback) { - DHLOGD("RegisterDistributedHardware, devId: %s, dhId: %s", GetAnonyString(devId).c_str(), + DHLOGI("RegisterDistributedHardware, devId: %s, dhId: %s", GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); if (callback == nullptr) { DHLOGE("callback is nullptr."); return ERR_DH_SCREEN_REGISTER_CALLBACK_NOT_INIT; } std::lock_guard lock(proxyMutex_); - if (!dScreenSourceProxy_) { + if (dScreenSourceProxy_ == nullptr) { DHLOGE("screen source proxy not init."); return ERR_DH_SCREEN_SA_SOURCEPROXY_NOT_INIT; } - if (!dScreenSourceCallback_) { + if (dScreenSourceCallback_ == nullptr) { DHLOGE("screen source callback is null."); return ERR_DH_SCREEN_SA_SOURCEPCALLBACK_NOT_INIT; } @@ -167,18 +166,18 @@ int32_t DScreenSourceHandler::RegisterDistributedHardware(const std::string &dev int32_t DScreenSourceHandler::UnregisterDistributedHardware(const std::string &devId, const std::string &dhId, std::shared_ptr callback) { - DHLOGD("UnregisterDistributedHardware, devId: %s, dhId: %s", GetAnonyString(devId).c_str(), + DHLOGI("UnregisterDistributedHardware, devId: %s, dhId: %s", GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); if (callback == nullptr) { DHLOGE("callback is nullptr."); return ERR_DH_SCREEN_REGISTER_CALLBACK_NOT_INIT; } std::lock_guard lock(proxyMutex_); - if (!dScreenSourceProxy_) { + if (dScreenSourceProxy_ == nullptr) { DHLOGE("screen source proxy not init."); return ERR_DH_SCREEN_SA_SOURCEPROXY_NOT_INIT; } - if (!dScreenSourceCallback_) { + if (dScreenSourceCallback_ == nullptr) { DHLOGE("screen source callback is null."); return ERR_DH_SCREEN_SA_SOURCEPCALLBACK_NOT_INIT; } @@ -192,7 +191,7 @@ int32_t DScreenSourceHandler::UnregisterDistributedHardware(const std::string &d int32_t DScreenSourceHandler::ConfigDistributedHardware(const std::string &devId, const std::string &dhId, const std::string &key, const std::string &value) { - DHLOGD("ConfigDistributedHardware"); + DHLOGI("ConfigDistributedHardware"); return DH_SUCCESS; } @@ -206,7 +205,7 @@ void DScreenSourceHandler::OnRemoteSourceSvrDied(const wptr &remo { DHLOGI("OnRemoteSourceSvrDied"); sptr remoteObject = remote.promote(); - if (!remoteObject) { + if (remoteObject == nullptr) { DHLOGE("OnRemoteDied remote promoted failed"); return; } @@ -219,7 +218,7 @@ void DScreenSourceHandler::OnRemoteSourceSvrDied(const wptr &remo IDistributedHardwareSource *GetSourceHardwareHandler() { - DHLOGD("GetSourceHardwareHandler"); + DHLOGI("GetSourceHardwareHandler"); return &DScreenSourceHandler::GetInstance(); } } diff --git a/interfaces/innerkits/native_cpp/screen_source/src/dscreen_source_proxy.cpp b/interfaces/innerkits/native_cpp/screen_source/src/dscreen_source_proxy.cpp index f4ab20d0..e0b1dc7e 100644 --- a/interfaces/innerkits/native_cpp/screen_source/src/dscreen_source_proxy.cpp +++ b/interfaces/innerkits/native_cpp/screen_source/src/dscreen_source_proxy.cpp @@ -22,11 +22,18 @@ #include "dscreen_errcode.h" #include "dscreen_log.h" +#include "dscreen_util.h" namespace OHOS { namespace DistributedHardware { int32_t DScreenSourceProxy::InitSource(const std::string ¶ms, const sptr &callback) { + DHLOGI("DScreenSourceProxy InitSource"); + sptr remote = Remote(); + if (remote == nullptr) { + DHLOGE("DScreenSourceProxy remote service null"); + return DSCREEN_BAD_VALUE; + } MessageParcel data; MessageParcel reply; MessageOption option; @@ -41,13 +48,19 @@ int32_t DScreenSourceProxy::InitSource(const std::string ¶ms, const sptrSendRequest(INIT_SOURCE, data, reply, option); + remote->SendRequest(INIT_SOURCE, data, reply, option); int32_t ret = reply.ReadInt32(); return ret; } int32_t DScreenSourceProxy::ReleaseSource() { + DHLOGI("DScreenSourceProxy ReleaseSource"); + sptr remote = Remote(); + if (remote == nullptr) { + DHLOGE("DScreenSourceProxy remote service null"); + return DSCREEN_BAD_VALUE; + } MessageParcel data; MessageParcel reply; MessageOption option; @@ -56,7 +69,7 @@ int32_t DScreenSourceProxy::ReleaseSource() return ERR_DH_SCREEN_SA_WRITEINTERFACETOKEN_FAILED; } - Remote()->SendRequest(RELEASE_SOURCE, data, reply, option); + remote->SendRequest(RELEASE_SOURCE, data, reply, option); int32_t ret = reply.ReadInt32(); return ret; } @@ -64,6 +77,13 @@ int32_t DScreenSourceProxy::ReleaseSource() int32_t DScreenSourceProxy::RegisterDistributedHardware(const std::string &devId, const std::string &dhId, const EnableParam ¶m, const std::string &reqId) { + DHLOGI("DScreenSourceProxy RegisterDistributedHardware devId: %s dhId: %s", + GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); + sptr remote = Remote(); + if (remote == nullptr) { + DHLOGE("DScreenSourceProxy remote service null"); + return DSCREEN_BAD_VALUE; + } MessageParcel data; MessageParcel reply; MessageOption option; @@ -78,7 +98,7 @@ int32_t DScreenSourceProxy::RegisterDistributedHardware(const std::string &devId DHLOGE("Write param failed."); return ERR_DH_SCREEN_SA_WRITEPARAM_FAILED; } - Remote()->SendRequest(REGISTER_DISTRIBUTED_HARDWARE, data, reply, option); + remote->SendRequest(REGISTER_DISTRIBUTED_HARDWARE, data, reply, option); int32_t ret = reply.ReadInt32(); return ret; } @@ -86,6 +106,13 @@ int32_t DScreenSourceProxy::RegisterDistributedHardware(const std::string &devId int32_t DScreenSourceProxy::UnregisterDistributedHardware(const std::string &devId, const std::string &dhId, const std::string &reqId) { + DHLOGI("DScreenSourceProxy UnregisterDistributedHardware devId: %s dhId: %s", + GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); + sptr remote = Remote(); + if (remote == nullptr) { + DHLOGE("DScreenSourceProxy remote service null"); + return DSCREEN_BAD_VALUE; + } MessageParcel data; MessageParcel reply; MessageOption option; @@ -99,7 +126,7 @@ int32_t DScreenSourceProxy::UnregisterDistributedHardware(const std::string &dev DHLOGE("Write param failed."); return ERR_DH_SCREEN_SA_WRITEPARAM_FAILED; } - Remote()->SendRequest(UNREGISTER_DISTRIBUTED_HARDWARE, data, reply, option); + remote->SendRequest(UNREGISTER_DISTRIBUTED_HARDWARE, data, reply, option); int32_t ret = reply.ReadInt32(); return ret; } @@ -107,6 +134,13 @@ int32_t DScreenSourceProxy::UnregisterDistributedHardware(const std::string &dev int32_t DScreenSourceProxy::ConfigDistributedHardware(const std::string &devId, const std::string &dhId, const std::string &key, const std::string &value) { + DHLOGI("DScreenSourceProxy ConfigDistributedHardware devId: %s dhId: %s", + GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); + sptr remote = Remote(); + if (remote == nullptr) { + DHLOGE("DScreenSourceProxy remote service null"); + return DSCREEN_BAD_VALUE; + } MessageParcel data; MessageParcel reply; MessageOption option; @@ -120,7 +154,7 @@ int32_t DScreenSourceProxy::ConfigDistributedHardware(const std::string &devId, DHLOGE("Write param failed."); return ERR_DH_SCREEN_SA_WRITEPARAM_FAILED; } - Remote()->SendRequest(CONFIG_DISTRIBUTED_HARDWARE, data, reply, option); + remote->SendRequest(CONFIG_DISTRIBUTED_HARDWARE, data, reply, option); int32_t ret = reply.ReadInt32(); return ret; } @@ -128,7 +162,13 @@ int32_t DScreenSourceProxy::ConfigDistributedHardware(const std::string &devId, void DScreenSourceProxy::DScreenNotify(const std::string &devId, int32_t eventCode, const std::string &eventContent) { - DHLOGD("DScreenNotify"); + DHLOGI("DScreenNotify devId: %s eventCode: %d eventContent: %s", + GetAnonyString(devId).c_str(), eventCode, eventContent.c_str()); + sptr remote = Remote(); + if (remote == nullptr) { + DHLOGE("DScreenSourceProxy remote service null"); + return; + } MessageParcel data; MessageParcel reply; MessageOption option = { MessageOption::TF_ASYNC }; @@ -142,7 +182,7 @@ void DScreenSourceProxy::DScreenNotify(const std::string &devId, return; } - Remote()->SendRequest(DSCREEN_NOTIFY, data, reply, option); + remote->SendRequest(DSCREEN_NOTIFY, data, reply, option); } } } diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxydscreennotify_fuzzer/dscreennotify_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxydscreennotify_fuzzer/dscreennotify_fuzzer.cpp index 77dcd719..32acc082 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxydscreennotify_fuzzer/dscreennotify_fuzzer.cpp +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_source_proxy/proxydscreennotify_fuzzer/dscreennotify_fuzzer.cpp @@ -27,7 +27,7 @@ namespace OHOS { namespace DistributedHardware { void DScreenNotifyFuzzTest(const uint8_t* data, size_t size) { - if ((data == nullptr) || (size <= 0)) { + if ((data == nullptr) || (size < sizeof(int32_t))) { return; } diff --git a/screenhandler/src/dscreen_handler.cpp b/screenhandler/src/dscreen_handler.cpp index 099c2151..1685d9f9 100644 --- a/screenhandler/src/dscreen_handler.cpp +++ b/screenhandler/src/dscreen_handler.cpp @@ -45,12 +45,13 @@ DScreenHandler::~DScreenHandler() int32_t DScreenHandler::Initialize() { DHLOGI("DScreenHandler Initialize"); - if (!screenListener_) { - screenListener_ = new ScreenListener(); + if (screenListener_ == nullptr) { + screenListener_ = new (std::nothrow) ScreenListener(); } bool ret = Rosen::ScreenManager::GetInstance().RegisterScreenListener(screenListener_); if (!ret) { DHLOGE("register screen listener failed."); + return DSCREEN_INIT_ERR; } return DH_SUCCESS; } @@ -59,6 +60,7 @@ void ScreenListener::OnConnect(uint64_t screenId) { DHLOGI("on screen connect"); if (screenId != SCREEN_ID_DEFAULT) { + DHLOGE("screenId is invalid, screenId: %ulld", screenId); return; } sptr screen = Rosen::ScreenManager::GetInstance().GetScreenById(screenId); @@ -90,6 +92,7 @@ void ScreenListener::OnDisconnect(uint64_t screenId) void DScreenHandler::PluginHardware(const std::string &dhId, const std::string &attr) { + DHLOGI("DScreenHandler PluginHardware"); if (listener_ != nullptr) { listener_->PluginHardware(dhId, attr); } @@ -97,6 +100,7 @@ void DScreenHandler::PluginHardware(const std::string &dhId, const std::string & void DScreenHandler::UnPluginHardware(const std::string &dhId) { + DHLOGI("DScreenHandler UnPluginHardware"); if (listener_ != nullptr) { listener_->UnPluginHardware(dhId); } @@ -151,6 +155,10 @@ bool DScreenHandler::IsSupportPlugin() void DScreenHandler::RegisterPluginListener(std::shared_ptr listener) { DHLOGD("DScreenHandler register plugin listener"); + if (listener == nullptr) { + DHLOGE("DScreenHandler unregistering plugin listener"); + return; + } listener_ = listener; } @@ -174,7 +182,7 @@ std::string DScreenHandler::QueryCodecInfo() } std::vector> caps = codecList->GetVideoEncoderCaps(); json codecTypeArray = json::array(); - + for (const auto &cap : caps) { if (cap == nullptr) { continue; @@ -192,6 +200,7 @@ std::string DScreenHandler::QueryCodecInfo() IHardwareHandler* GetHardwareHandler() { + DHLOGI("DScreenHandler::GetHardwareHandler"); return &DScreenHandler::GetInstance(); } } // namespace DistributedHardware diff --git a/services/screendemo/BUILD.gn b/services/screendemo/BUILD.gn index 86acc100..7dd37e6f 100644 --- a/services/screendemo/BUILD.gn +++ b/services/screendemo/BUILD.gn @@ -26,6 +26,8 @@ ohos_executable("distributedScreenTest") { "${services_path}/screenclient/include", "${windowmanager_path}/interfaces/innerkits/wm", "${common_path}/include", + "//base/security/access_token/interfaces/innerkits/nativetoken/include/", + "//base/security/access_token/interfaces/innerkits/token_setproc/include/", ] include_dirs += @@ -43,6 +45,8 @@ ohos_executable("distributedScreenTest") { "${services_path}/screenclient:distributed_screen_client", "${windowmanager_path}/dm:libdm", "${windowmanager_path}/wm:libwm", + "//base/security/access_token/interfaces/innerkits/nativetoken:libnativetoken", + "//base/security/access_token/interfaces/innerkits/token_setproc:libtoken_setproc", "//foundation/communication/dsoftbus/adapter:softbus_adapter", "//foundation/communication/dsoftbus/sdk:softbus_client", "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", diff --git a/services/screendemo/test.cpp b/services/screendemo/test.cpp index 5d07ccef..9cfd52ee 100644 --- a/services/screendemo/test.cpp +++ b/services/screendemo/test.cpp @@ -29,6 +29,8 @@ #include "wm_common.h" #include "window.h" #include "window_option.h" +#include "nativetoken_kit.h" +#include "token_setproc.h" #include "decoder_demo.h" #include "softbus_adapter_mem.h" @@ -103,7 +105,7 @@ static void StartMirror() } sptr defaultDisplay = DisplayManager::GetInstance().GetDefaultDisplay(); - cout << "------------start mirror----------" < mirrorIds; mirrorIds.push_back(mirrorId); @@ -240,6 +242,25 @@ static void PrintNodeProperty(NodeBasicInfo *nodeInfo) static void QueryRemoteDeviceInfo() { + uint64_t tokenId; + const char **perms = new const char *[1]; + perms[0] = "ohos.permission.DISTRIBUTED_DATASYNC"; + NativeTokenInfoParams infoInstance = { + .dcapsNum = 0, + .permsNum = 1, + .dcaps = nullptr, + .perms = perms, + .aplStr = "system_basic", + }; + + infoInstance.acls = NULL; + infoInstance.aclsNum = 0; + infoInstance.processName = "test_attest"; + tokenId = GetAccessTokenId(&infoInstance); + cout << "tokenId ====== " << tokenId << endl; + int32_t ret = SetSelfTokenID(tokenId); + cout << "ret ======" << ret << endl; + NodeBasicInfo localNodeinfo; NodeBasicInfo *remoteNodeInfo = nullptr; int32_t infoNum = 0; diff --git a/services/screenservice/sinkservice/screenregionmgr/src/screenregion.cpp b/services/screenservice/sinkservice/screenregionmgr/src/screenregion.cpp index 408b7adb..f3708406 100644 --- a/services/screenservice/sinkservice/screenregionmgr/src/screenregion.cpp +++ b/services/screenservice/sinkservice/screenregionmgr/src/screenregion.cpp @@ -117,7 +117,7 @@ int32_t ScreenRegion::SetUp() } sptr surface = ScreenClient::GetInstance().GetSurface(windowId_); - if (!surface) { + if (surface == nullptr) { DHLOGE("get window surface failed."); ReportOptFail(DSCREEN_OPT_FAIL, ERR_DH_SCREEN_SA_DSCREEN_SCREENGION_SETUP_FAILED, "get window surface failed."); return ERR_DH_SCREEN_SA_DSCREEN_SCREENGION_SETUP_FAILED; @@ -125,7 +125,7 @@ int32_t ScreenRegion::SetUp() surface_ = surface; - if (!sinkTrans_) { + if (sinkTrans_ == nullptr) { sinkTrans_ = std::make_shared(); } @@ -143,7 +143,7 @@ int32_t ScreenRegion::SetUp() int32_t ScreenRegion::Start() { DHLOGI("ScreenRegion::Start remoteDevId: %s", GetAnonyString(remoteDevId_).c_str()); - if (!sinkTrans_) { + if (sinkTrans_ == nullptr) { DHLOGE("sink trans not init."); return ERR_DH_SCREEN_SA_SINKTRANS_NOT_INIT; } @@ -165,7 +165,7 @@ int32_t ScreenRegion::Stop() return DH_SUCCESS; } - if (!sinkTrans_) { + if (sinkTrans_ == nullptr) { DHLOGE("sink trans not init."); return ERR_DH_SCREEN_SA_SINKTRANS_NOT_INIT; } diff --git a/services/screenservice/sinkservice/screenregionmgr/src/screenregionmgr.cpp b/services/screenservice/sinkservice/screenregionmgr/src/screenregionmgr.cpp index 812126d6..54bb00e1 100644 --- a/services/screenservice/sinkservice/screenregionmgr/src/screenregionmgr.cpp +++ b/services/screenservice/sinkservice/screenregionmgr/src/screenregionmgr.cpp @@ -51,7 +51,7 @@ int32_t ScreenRegionManager::ReleaseAllRegions() std::lock_guard lock(screenRegionsMtx_); for (const auto &item : screenRegions_) { std::shared_ptr screenRegion = item.second; - if (!screenRegion) { + if (screenRegion == nullptr) { continue; } int32_t ret = screenRegion->Stop(); @@ -89,7 +89,7 @@ void ScreenRegionManager::GetScreenDumpInfo(std::string &result) for (const auto &iter : screenRegions_) { result.append(" {\n"); std::shared_ptr screenRegion = iter.second; - if (!screenRegion) { + if (screenRegion == nullptr) { continue; } uint64_t screenId = screenRegion->GetScreenId(); @@ -197,7 +197,7 @@ int32_t ScreenRegionManager::NotifyRemoteScreenService(const std::string &remote DHLOGI("Notify remote source screen service, remote devId: %s, eventCode: %d", GetAnonyString(remoteDevId).c_str(), eventCode); sptr remoteSourceSA = GetDScreenSourceSA(remoteDevId); - if (!remoteSourceSA) { + if (remoteSourceSA == nullptr) { DHLOGE("get remote source sa failed."); return ERR_DH_SCREEN_SA_GET_REMOTE_SOURCE_SERVICE_FAIL; } @@ -238,7 +238,7 @@ sptr ScreenRegionManager::GetDScreenSourceSA(const std::string & void ScreenRegionManager::PublishMessage(const DHTopic topic, const uint64_t &screenId, const std::string &remoteDevId, const int32_t &windowId, std::shared_ptr windowProperty) { - DHLOGD("PublishMessage"); + DHLOGI("ScreenRegionManager PublishMessage"); if (DScreenFwkKit::GetInstance().GetDHFwkKit() == nullptr) { DHLOGE("GetDHFwkKit fail."); return; diff --git a/services/screenservice/sourceservice/dscreenmgr/src/dscreen.cpp b/services/screenservice/sourceservice/dscreenmgr/src/dscreen.cpp index f41ed6fe..6a9ee8b6 100644 --- a/services/screenservice/sourceservice/dscreenmgr/src/dscreen.cpp +++ b/services/screenservice/sourceservice/dscreenmgr/src/dscreen.cpp @@ -51,7 +51,7 @@ DScreen::~DScreen() taskQueueThread_.join(); } int32_t ret = DH_SUCCESS; - if (sourceTrans_) { + if (sourceTrans_ != nullptr) { ret = sourceTrans_->Release(); } if (ret != DH_SUCCESS) { @@ -117,7 +117,7 @@ int32_t DScreen::AddTask(const std::shared_ptr &task) { DHLOGI("DScreen::AddTask, devId: %s, dhId: %s", GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); - if (!task) { + if (task == nullptr) { DHLOGE("AddTask, task is invalid."); return ERR_DH_SCREEN_SA_DSCREEN_TASK_NOT_VALID; } @@ -189,7 +189,7 @@ void DScreen::HandleEnable(const std::string ¶m, const std::string &taskId) } SetState(ENABLING); - if (!videoParam_) { + if (videoParam_ == nullptr) { videoParam_ = std::make_shared(); } @@ -260,12 +260,16 @@ int32_t DScreen::NegotiateCodecType(const std::string &remoteCodecInfoStr) std::vector localCodecArray; // query local support encoder type std::shared_ptr codecList = Media::AVCodecListFactory::CreateAVCodecList(); + if (codecList == nullptr) { + DHLOGE("codecList is nullptr."); + return ERR_DH_SCREEN_SA_DSCREEN_NEGOTIATE_CODEC_FAIL; + } std::vector> caps = codecList->GetVideoEncoderCaps(); for (const auto &cap : caps) { std::shared_ptr codecInfo = cap->GetCodecInfo(); localCodecArray.push_back(codecInfo->GetName()); } - + std::vector codecTypeCandidates; for (const auto &remoteCodecType : remoteCodecArray) { if (std::find(localCodecArray.begin(), localCodecArray.end(), @@ -273,7 +277,7 @@ int32_t DScreen::NegotiateCodecType(const std::string &remoteCodecInfoStr) codecTypeCandidates.push_back(remoteCodecType); } } - + if (std::find(codecTypeCandidates.begin(), codecTypeCandidates.end(), CODEC_NAME_H264) != codecTypeCandidates.end()) { videoParam_->SetCodecType(VIDEO_CODEC_TYPE_VIDEO_H264); @@ -359,7 +363,7 @@ int32_t DScreen::SetUp() DHLOGD("SetUp, devId: %s, dhId: %s", GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); - if (!sourceTrans_) { + if (sourceTrans_ == nullptr) { sourceTrans_ = std::make_shared(); } @@ -381,7 +385,7 @@ int32_t DScreen::Start() { DHLOGD("Start, devId: %s, dhId: %s", GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); - if (!sourceTrans_) { + if (sourceTrans_ == nullptr) { DHLOGE("source trans not init."); return ERR_DH_SCREEN_SA_SOURCETRANS_NOT_INIT; } @@ -398,7 +402,7 @@ int32_t DScreen::Stop() { DHLOGD("Stop, devId: %s, dhId: %s", GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str()); - if (!sourceTrans_) { + if (sourceTrans_ == nullptr) { DHLOGE("source trans not init."); return ERR_DH_SCREEN_SA_SOURCETRANS_NOT_INIT; } diff --git a/services/screenservice/sourceservice/dscreenmgr/src/dscreen_manager.cpp b/services/screenservice/sourceservice/dscreenmgr/src/dscreen_manager.cpp index 11739ae6..e5dfbe52 100644 --- a/services/screenservice/sourceservice/dscreenmgr/src/dscreen_manager.cpp +++ b/services/screenservice/sourceservice/dscreenmgr/src/dscreen_manager.cpp @@ -59,13 +59,13 @@ int32_t DScreenManager::Init() { DHLOGI("DScreenManager::Init"); if (dScreenGroupListener_ == nullptr) { - dScreenGroupListener_ = new DScreenGroupListener(); + dScreenGroupListener_ = new (std::nothrow) DScreenGroupListener(); } int32_t ret = ScreenMgrAdapter::GetInstance().RegisterScreenGroupListener(dScreenGroupListener_); if (ret != DH_SUCCESS) { DHLOGE("DScreenManager Init failed, err: %d", ret); } - if (!dScreenCallback_) { + if (dScreenCallback_ == nullptr) { dScreenCallback_ = std::make_shared(); } @@ -105,7 +105,7 @@ void DScreenGroupListener::OnChange(const std::vector &screenIds, Rose for (uint64_t screenId : screenIds) { std::shared_ptr changedScreen = nullptr; changedScreen = DScreenManager::GetInstance().FindDScreenByScreenId(screenId); - if (!changedScreen) { + if (changedScreen == nullptr) { DHLOGD("screen change not about remote screen, screenId: %ulld", screenId); continue; } @@ -116,7 +116,7 @@ void DScreenGroupListener::OnChange(const std::vector &screenIds, Rose void DScreenManager::HandleScreenChange(const std::shared_ptr &changedScreen, Rosen::ScreenGroupChangeEvent event) { - if (!changedScreen) { + if (changedScreen == nullptr) { DHLOGE("DScreenManager::HandleScreenChange, dScreen is null."); return; } @@ -140,7 +140,7 @@ void DScreenManager::HandleScreenChange(const std::shared_ptr &changedS void DScreenManager::AddToGroup(const std::shared_ptr &changedScreen, uint64_t screenId) { DHLOGI("DScreenManager::ADDToGroup, screenId: %ulld", screenId); - if (!changedScreen) { + if (changedScreen == nullptr) { DHLOGE("DScreenManager::ADDToGroup, dScreen is null."); return; } @@ -150,7 +150,7 @@ void DScreenManager::AddToGroup(const std::shared_ptr &changedScreen, u return; } std::shared_ptr mapRelation = ScreenMgrAdapter::GetInstance().GetMapRelation(screenId); - if (!mapRelation) { + if (mapRelation == nullptr) { DHLOGE("mapRelation construct failed. screenId: %ulld", screenId); return; } @@ -170,7 +170,7 @@ void DScreenManager::AddToGroup(const std::shared_ptr &changedScreen, u void DScreenManager::RemoveFromGroup(const std::shared_ptr &changedScreen, uint64_t screenId) { DHLOGI("DScreenManager::RemoveFromGroup, screenId: %ulld", screenId); - if (!changedScreen) { + if (changedScreen == nullptr) { DHLOGE("DScreenManager::RemoveFromGroup, dScreen is null."); return; } @@ -213,7 +213,7 @@ void DScreenManager::OnRegResult(const std::shared_ptr &dScreen, { DHLOGI("DScreenManager::OnRegResult, devId: %s, dhId: %s, reqId: %s", GetAnonyString(dScreen->GetDevId()).c_str(), GetAnonyString(dScreen->GetDHId()).c_str(), reqId.c_str()); - if (!dScreenSourceCallbackProxy_) { + if (dScreenSourceCallbackProxy_ == nullptr) { DHLOGE("dScreenSourceCallbackProxy is null"); return; } @@ -225,7 +225,7 @@ void DScreenManager::OnUnregResult(const std::shared_ptr &dScreen, { DHLOGI("DScreenManager::OnUnregResult, devId: %s, dhId: %s, reqId: %s", GetAnonyString(dScreen->GetDevId()).c_str(), GetAnonyString(dScreen->GetDHId()).c_str(), reqId.c_str()); - if (!dScreenSourceCallbackProxy_) { + if (dScreenSourceCallbackProxy_ == nullptr) { DHLOGE("dScreenSourceCallbackProxy is null"); return; } @@ -237,7 +237,7 @@ int32_t DScreenManager::EnableDistributedScreen(const std::string &devId, const { DHLOGI("EnableDistributedScreen, devId: %s, dhId:%s", GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); - if (!dScreenCallback_) { + if (dScreenCallback_ == nullptr) { DHLOGE("dscreen manager not init."); return ERR_DH_SCREEN_SA_ENABLE_FAILED; } diff --git a/services/screenservice/sourceservice/dscreenmgr/src/screen_manager_adapter.cpp b/services/screenservice/sourceservice/dscreenmgr/src/screen_manager_adapter.cpp index 317cb0d3..7141040b 100644 --- a/services/screenservice/sourceservice/dscreenmgr/src/screen_manager_adapter.cpp +++ b/services/screenservice/sourceservice/dscreenmgr/src/screen_manager_adapter.cpp @@ -130,10 +130,18 @@ int32_t ScreenMgrAdapter::SetImageSurface(uint64_t screenId, sptr std::shared_ptr ScreenMgrAdapter::GetMapRelation(uint64_t screenId) { - DHLOGI("GetMapRelation"); + DHLOGI("GetMapRelation screenId: %ulld", screenId); std::shared_ptr mapRelation = std::make_shared(); sptr screen = Rosen::ScreenManager::GetInstance().GetScreenById(screenId); + if (screen == nullptr) { + DHLOGE("screen is nullptr."); + return nullptr; + } sptr display = Rosen::DisplayManager::GetInstance().GetDefaultDisplay(); + if (display == nullptr) { + DHLOGE("display is nullptr."); + return nullptr; + } mapRelation->SetDisplayId(display->GetId()); mapRelation->SetScreenId(screenId); diff --git a/services/screenservice/sourceservice/dscreenservice/src/callback/dscreen_source_callback_proxy.cpp b/services/screenservice/sourceservice/dscreenservice/src/callback/dscreen_source_callback_proxy.cpp index fd099abe..574988e0 100644 --- a/services/screenservice/sourceservice/dscreenservice/src/callback/dscreen_source_callback_proxy.cpp +++ b/services/screenservice/sourceservice/dscreenservice/src/callback/dscreen_source_callback_proxy.cpp @@ -28,6 +28,11 @@ int32_t DScreenSourceCallbackProxy::OnNotifyRegResult(const std::string &devId, { DHLOGD("OnNotifyRegResult, devId: %s, dhId: %s, reqId: %s, status: %d", GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), reqId.c_str(), status); + sptr remote = Remote(); + if (remote == nullptr) { + DHLOGE("DScreenSourceCallbackProxy remote service null"); + return DSCREEN_BAD_VALUE; + } MessageParcel data; MessageParcel reply; MessageOption option; @@ -43,7 +48,7 @@ int32_t DScreenSourceCallbackProxy::OnNotifyRegResult(const std::string &devId, return ERR_DH_SCREEN_SA_WRITEPARAM_FAILED; } - Remote()->SendRequest(NOTIFY_REG_RESULT, data, reply, option); + remote->SendRequest(NOTIFY_REG_RESULT, data, reply, option); return reply.ReadInt32(); } @@ -52,6 +57,11 @@ int32_t DScreenSourceCallbackProxy::OnNotifyUnregResult(const std::string &devId { DHLOGD("OnNotifyUnregResult, devId: %s, dhId: %s, reqId: %s, status: %d", GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), reqId.c_str(), status); + sptr remote = Remote(); + if (remote == nullptr) { + DHLOGE("DScreenSourceCallbackProxy remote service null"); + return DSCREEN_BAD_VALUE; + } MessageParcel data; MessageParcel reply; MessageOption option; @@ -67,7 +77,7 @@ int32_t DScreenSourceCallbackProxy::OnNotifyUnregResult(const std::string &devId return ERR_DH_SCREEN_SA_WRITEPARAM_FAILED; } - Remote()->SendRequest(NOTIFY_UNREG_RESULT, data, reply, option); + remote->SendRequest(NOTIFY_UNREG_RESULT, data, reply, option); return reply.ReadInt32(); } } // namespace DistributedHardware diff --git a/services/screentransport/screendatachannel/src/screen_data_channel_impl.cpp b/services/screentransport/screendatachannel/src/screen_data_channel_impl.cpp index 8a1c390a..b19f70b7 100644 --- a/services/screentransport/screendatachannel/src/screen_data_channel_impl.cpp +++ b/services/screentransport/screendatachannel/src/screen_data_channel_impl.cpp @@ -28,7 +28,7 @@ namespace DistributedHardware { int32_t ScreenDataChannelImpl::CreateSession(const std::shared_ptr &listener) { DHLOGI("%s: CreateSession, peerDevId(%s)", LOG_TAG, GetAnonyString(peerDevId_).c_str()); - if (!listener) { + if (listener == nullptr) { DHLOGE("%s: Channel listener is null", LOG_TAG); return ERR_DH_SCREEN_TRANS_NULL_VALUE; } @@ -109,7 +109,7 @@ int32_t ScreenDataChannelImpl::CloseSession() int32_t ScreenDataChannelImpl::SendData(const std::shared_ptr &screenData) { DHLOGD("%s: SendData, sessionId(%d)", LOG_TAG, sessionId_); - if (!screenData) { + if (screenData == nullptr) { DHLOGE("%s: Screen data is null", LOG_TAG); return ERR_DH_SCREEN_TRANS_NULL_VALUE; } @@ -136,7 +136,7 @@ void ScreenDataChannelImpl::OnSessionOpened(int32_t sessionId, int32_t result) } std::shared_ptr listener = channelListener_.lock(); - if (!listener) { + if (listener == nullptr) { DHLOGE("%s: Channel listener is null", LOG_TAG); return; } @@ -148,7 +148,7 @@ void ScreenDataChannelImpl::OnSessionClosed(int32_t sessionId) { DHLOGI("%s: OnScreenSessionClosed, sessionId(%d).", LOG_TAG, sessionId); std::shared_ptr listener = channelListener_.lock(); - if (!listener) { + if (listener == nullptr) { DHLOGE("%s: Channel listener is null", LOG_TAG); return; } @@ -176,14 +176,14 @@ void ScreenDataChannelImpl::OnStreamReceived(int32_t sessionId, const StreamData } std::shared_ptr listener = channelListener_.lock(); - if (!listener) { + if (listener == nullptr) { DHLOGE("%s: Channel listener is null.", LOG_TAG); return; } DHLOGI("%s: OnScreenStreamReceived, sessionId(%d) dataSize(%zu).", LOG_TAG, sessionId, data->bufLen); auto dataBuffer = std::make_shared(data->bufLen); - if (!dataBuffer) { + if (dataBuffer == nullptr) { DHLOGE("%s: DataBuffer is null.", LOG_TAG); return; } diff --git a/services/screentransport/screensinkprocessor/decoder/src/image_sink_decoder.cpp b/services/screentransport/screensinkprocessor/decoder/src/image_sink_decoder.cpp index 7c6309ec..2d85f41e 100644 --- a/services/screentransport/screensinkprocessor/decoder/src/image_sink_decoder.cpp +++ b/services/screentransport/screensinkprocessor/decoder/src/image_sink_decoder.cpp @@ -46,7 +46,7 @@ int32_t ImageSinkDecoder::ConfigureDecoder(const VideoParam &configParam) int32_t ImageSinkDecoder::ReleaseDecoder() { DHLOGI("%s: ReleaseDecoder.", LOG_TAG); - if (!videoDecoder_) { + if (videoDecoder_ == nullptr) { DHLOGE("%s: Decoder is null.", LOG_TAG); return ERR_DH_SCREEN_TRANS_NULL_VALUE; } @@ -65,7 +65,7 @@ int32_t ImageSinkDecoder::ReleaseDecoder() int32_t ImageSinkDecoder::StartDecoder() { DHLOGI("%s: StartDecoder.", LOG_TAG); - if (!videoDecoder_) { + if (videoDecoder_ == nullptr) { DHLOGE("%s: Decoder is null.", LOG_TAG); return ERR_DH_SCREEN_TRANS_NULL_VALUE; } @@ -89,7 +89,7 @@ int32_t ImageSinkDecoder::StartDecoder() int32_t ImageSinkDecoder::StopDecoder() { DHLOGI("%s: StopDecoder.", LOG_TAG); - if (!videoDecoder_) { + if (videoDecoder_ == nullptr) { DHLOGE("%s: Decoder is null.", LOG_TAG); return ERR_DH_SCREEN_TRANS_NULL_VALUE; } @@ -146,7 +146,7 @@ int32_t ImageSinkDecoder::InitVideoDecoder(const VideoParam &configParam) int32_t ImageSinkDecoder::SetDecoderFormat(const VideoParam &configParam) { DHLOGI("%s: SetDecoderFormat.", LOG_TAG); - if (!videoDecoder_) { + if (videoDecoder_ == nullptr) { DHLOGE("%s: Decoder is null.", LOG_TAG); return ERR_DH_SCREEN_TRANS_NULL_VALUE; } @@ -200,7 +200,7 @@ int32_t ImageSinkDecoder::SetDecoderFormat(const VideoParam &configParam) int32_t ImageSinkDecoder::SetOutputSurface(sptr &surface) { DHLOGI("%s: SetOutputSurface.", LOG_TAG); - if (!videoDecoder_) { + if (videoDecoder_ == nullptr) { DHLOGE("%s: Decoder is null.", LOG_TAG); return ERR_DH_SCREEN_TRANS_NULL_VALUE; } @@ -232,7 +232,7 @@ void ImageSinkDecoder::OnError(Media::AVCodecErrorType errorType, int32_t errorC { DHLOGI("%s: OnImageDecodeError, errorType(%d), errorCode(%d)", LOG_TAG, errorType, errorCode); std::shared_ptr listener = imageProcessorListener_.lock(); - if (!listener) { + if (listener == nullptr) { DHLOGE("%s: Listener is null.", LOG_TAG); return; } @@ -250,7 +250,7 @@ void ImageSinkDecoder::OnOutputBufferAvailable(uint32_t index, Media::AVCodecBuf Media::AVCodecBufferFlag flag) { DHLOGI("%s: OnDecodeOutputBufferAvailable.", LOG_TAG); - if (!videoDecoder_) { + if (videoDecoder_ == nullptr) { DHLOGE("%s: Decoder is null.", LOG_TAG); return; } @@ -296,6 +296,7 @@ int32_t ImageSinkDecoder::StopInputThread() void ImageSinkDecoder::DecodeScreenData() { + DHLOGI("%s: DecodeScreenData.", LOG_TAG); while (isDecoderReady_) { std::shared_ptr screenData; int32_t bufferIndex = 0; @@ -325,7 +326,8 @@ void ImageSinkDecoder::DecodeScreenData() int32_t ImageSinkDecoder::ProcessData(const std::shared_ptr &screenData, const int32_t bufferIndex) { - if (!videoDecoder_) { + DHLOGI("%s: ProcessData.", LOG_TAG); + if (videoDecoder_ == nullptr) { DHLOGE("%s: Decoder is null.", LOG_TAG); return ERR_DH_SCREEN_TRANS_NULL_VALUE; } diff --git a/services/screentransport/screensourceprocessor/encoder/src/image_source_encoder.cpp b/services/screentransport/screensourceprocessor/encoder/src/image_source_encoder.cpp index a8872f4d..77c04caa 100644 --- a/services/screentransport/screensourceprocessor/encoder/src/image_source_encoder.cpp +++ b/services/screentransport/screensourceprocessor/encoder/src/image_source_encoder.cpp @@ -52,7 +52,7 @@ int32_t ImageSourceEncoder::ConfigureEncoder(const VideoParam &configParam) int32_t ImageSourceEncoder::ReleaseEncoder() { DHLOGI("%s: ReleaseEncoder.", LOG_TAG); - if (!videoEncoder_) { + if (videoEncoder_ == nullptr) { DHLOGE("%s: Encoder is null.", LOG_TAG); return ERR_DH_SCREEN_TRANS_NULL_VALUE; } @@ -71,7 +71,7 @@ int32_t ImageSourceEncoder::ReleaseEncoder() int32_t ImageSourceEncoder::StartEncoder() { DHLOGI("%s: StartEncoder.", LOG_TAG); - if (!videoEncoder_) { + if (videoEncoder_ == nullptr) { DHLOGE("%s: Encoder is null.", LOG_TAG); return ERR_DH_SCREEN_TRANS_NULL_VALUE; } @@ -94,7 +94,7 @@ int32_t ImageSourceEncoder::StartEncoder() int32_t ImageSourceEncoder::StopEncoder() { DHLOGI("%s: StopEncoder.", LOG_TAG); - if (!videoEncoder_) { + if (videoEncoder_ == nullptr) { DHLOGE("%s: Encoder is null.", LOG_TAG); return ERR_DH_SCREEN_TRANS_NULL_VALUE; } @@ -149,7 +149,7 @@ int32_t ImageSourceEncoder::InitVideoEncoder(const VideoParam &configParam) int32_t ImageSourceEncoder::SetEncoderFormat(const VideoParam &configParam) { DHLOGI("%s: SetEncoderFormat.", LOG_TAG); - if (!videoEncoder_) { + if (videoEncoder_ == nullptr) { DHLOGE("%s: Encoder is null.", LOG_TAG); return ERR_DH_SCREEN_TRANS_NULL_VALUE; } @@ -202,7 +202,7 @@ void ImageSourceEncoder::OnError(Media::AVCodecErrorType errorType, int32_t erro { DHLOGI("%s: Encoder error, errorType(%d), errorCode(%d)", LOG_TAG, errorType, errorCode); std::shared_ptr listener = imageProcessorListener_.lock(); - if (!listener) { + if (listener == nullptr) { DHLOGE("%s: Processor listener is null", LOG_TAG); return; } @@ -214,25 +214,25 @@ void ImageSourceEncoder::OnOutputBufferAvailable(uint32_t index, Media::AVCodecB { DHLOGD("%s: OnOutputBufferAvailable.", LOG_TAG); std::shared_ptr listener = imageProcessorListener_.lock(); - if (!listener) { + if (listener == nullptr) { DHLOGE("%s: Processor listener is null", LOG_TAG); return; } - if (!videoEncoder_) { + if (videoEncoder_ == nullptr) { DHLOGE("%s: Encoder is null.", LOG_TAG); return; } encoderBufferInfo_ = info; videoSharedMemory_ = videoEncoder_->GetOutputBuffer(index); - if (!videoSharedMemory_) { + if (videoSharedMemory_ == nullptr) { DHLOGE("%s: GetOutputBuffer failed.", LOG_TAG); return; } size_t dataSize = static_cast(info.size); auto dataBuf = std::make_shared(dataSize); - if (!dataBuf) { + if (dataBuf == nullptr) { DHLOGE("%s: Create buffer failed.", LOG_TAG); return; } diff --git a/services/screentransport/screensourceprocessor/src/image_source_processor.cpp b/services/screentransport/screensourceprocessor/src/image_source_processor.cpp index 4181d895..52cc5b52 100644 --- a/services/screentransport/screensourceprocessor/src/image_source_processor.cpp +++ b/services/screentransport/screensourceprocessor/src/image_source_processor.cpp @@ -27,7 +27,7 @@ int32_t ImageSourceProcessor::ConfigureImageProcessor(const VideoParam &localPar { DHLOGI("%s: ConfigureImageProcessor.", LOG_TAG); imageEncoder_ = std::make_shared(listener); - if (!imageEncoder_) { + if (imageEncoder_ == nullptr) { DHLOGE("%s: Create screen encoder failed.", LOG_TAG); return ERR_DH_SCREEN_TRANS_NULL_VALUE; } @@ -46,7 +46,7 @@ int32_t ImageSourceProcessor::ConfigureImageProcessor(const VideoParam &localPar int32_t ImageSourceProcessor::ReleaseImageProcessor() { DHLOGI("%s: ReleaseImageProcessor.", LOG_TAG); - if (!imageEncoder_) { + if (imageEncoder_ == nullptr) { DHLOGE("%s: Create screen encoder failed.", LOG_TAG); ReportOptFail(DSCREEN_OPT_FAIL, ERR_DH_SCREEN_TRANS_NULL_VALUE, "ReleaseImageProcessor encoder is nullptr."); return ERR_DH_SCREEN_TRANS_NULL_VALUE; @@ -67,7 +67,7 @@ int32_t ImageSourceProcessor::ReleaseImageProcessor() int32_t ImageSourceProcessor::StartImageProcessor() { DHLOGI("%s: StartImageProcessor.", LOG_TAG); - if (!imageEncoder_) { + if (imageEncoder_ == nullptr) { DHLOGE("%s: Create screen encoder failed.", LOG_TAG); ReportOptFail(DSCREEN_OPT_FAIL, ERR_DH_SCREEN_TRANS_NULL_VALUE, "StartImageProcessor encoder is nullptr."); return ERR_DH_SCREEN_TRANS_NULL_VALUE; @@ -88,7 +88,7 @@ int32_t ImageSourceProcessor::StartImageProcessor() int32_t ImageSourceProcessor::StopImageProcessor() { DHLOGI("%s: StopImageProcessor.", LOG_TAG); - if (!imageEncoder_) { + if (imageEncoder_ == nullptr) { DHLOGE("%s: Create screen encoder failed.", LOG_TAG); ReportOptFail(DSCREEN_OPT_FAIL, ERR_DH_SCREEN_TRANS_NULL_VALUE, "StopImageProcessor encoder is nullptr."); return ERR_DH_SCREEN_TRANS_NULL_VALUE; diff --git a/services/screentransport/screensourcetrans/src/screen_source_trans.cpp b/services/screentransport/screensourcetrans/src/screen_source_trans.cpp index 2ad9f920..fc075ca9 100644 --- a/services/screentransport/screensourcetrans/src/screen_source_trans.cpp +++ b/services/screentransport/screensourcetrans/src/screen_source_trans.cpp @@ -49,7 +49,7 @@ int32_t ScreenSourceTrans::SetUp(const VideoParam &localParam, const VideoParam int32_t ScreenSourceTrans::Release() { DHLOGI("%s: Release.", LOG_TAG); - if (!imageProcessor_ || !screenChannel_) { + if (imageProcessor_ == nullptr || screenChannel_ == nullptr) { DHLOGE("%s: Processor or channel is null, Setup first.", LOG_TAG); return ERR_DH_SCREEN_TRANS_NULL_VALUE; } @@ -80,7 +80,7 @@ int32_t ScreenSourceTrans::Release() int32_t ScreenSourceTrans::Start() { DHLOGI("%s: Start.", LOG_TAG); - if (!imageProcessor_ || !screenChannel_) { + if (imageProcessor_ == nullptr || screenChannel_ == nullptr) { DHLOGE("%s: Processor or channel is null, Setup first.", LOG_TAG); return ERR_DH_SCREEN_TRANS_NULL_VALUE; } @@ -109,7 +109,7 @@ int32_t ScreenSourceTrans::Start() int32_t ScreenSourceTrans::Stop() { DHLOGI("%s: Stop.", LOG_TAG); - if (!imageProcessor_ || !screenChannel_) { + if (imageProcessor_ == nullptr || screenChannel_ == nullptr) { DHLOGE("%s: Processor or channel is null, Setup first.", LOG_TAG); return ERR_DH_SCREEN_TRANS_NULL_VALUE; } @@ -144,7 +144,7 @@ int32_t ScreenSourceTrans::Stop() int32_t ScreenSourceTrans::RegisterStateCallback(const std::shared_ptr &callback) { DHLOGI("%s:RegisterStateCallback.", LOG_TAG); - if (!callback) { + if (callback == nullptr) { DHLOGE("%s: Trans callback is null.", LOG_TAG); return ERR_DH_SCREEN_TRANS_NULL_VALUE; } @@ -194,6 +194,7 @@ int32_t ScreenSourceTrans::CheckVideoParam(const VideoParam ¶m) int32_t ScreenSourceTrans::CheckTransParam(const VideoParam &localParam, const VideoParam &remoteParam, const std::string &peerDevId) { + DHLOGI("%s:CheckTransParam.", LOG_TAG); if (peerDevId.empty()) { DHLOGE("%s: Remote device id is null.", LOG_TAG); return ERR_DH_SCREEN_TRANS_NULL_VALUE; @@ -223,8 +224,9 @@ int32_t ScreenSourceTrans::CheckTransParam(const VideoParam &localParam, const V int32_t ScreenSourceTrans::InitScreenTrans(const VideoParam &localParam, const VideoParam &remoteParam, const std::string &peerDevId) { + DHLOGI("%s:InitScreenTrans.", LOG_TAG); screenChannel_ = std::make_shared(peerDevId); - if (!screenChannel_) { + if (screenChannel_ == nullptr) { DHLOGE("%s: Create screen data channel failed.", LOG_TAG); return ERR_DH_SCREEN_TRANS_NULL_VALUE; } @@ -236,7 +238,7 @@ int32_t ScreenSourceTrans::InitScreenTrans(const VideoParam &localParam, const V } imageProcessor_ = std::make_shared(); - if (!imageProcessor_) { + if (imageProcessor_ == nullptr) { DHLOGE("%s: Create image processor failed.", LOG_TAG); screenChannel_ = nullptr; return ERR_DH_SCREEN_TRANS_NULL_VALUE; @@ -256,7 +258,7 @@ int32_t ScreenSourceTrans::RegisterChannelListener() { DHLOGI("%s: RegisterChannelListener.", LOG_TAG); std::shared_ptr listener = shared_from_this(); - if (!listener) { + if (listener == nullptr) { DHLOGE("%s: Channel listener is null", LOG_TAG); return ERR_DH_SCREEN_TRANS_NULL_VALUE; } @@ -279,11 +281,15 @@ int32_t ScreenSourceTrans::RegisterProcessorListener(const VideoParam &localPara { DHLOGI("%s: RegisterProcessorListener.", LOG_TAG); std::shared_ptr listener = shared_from_this(); - if (!listener) { + if (listener == nullptr) { DHLOGE("%s: Processor listener is null", LOG_TAG); return ERR_DH_SCREEN_TRANS_ERROR; } + if (imageProcessor_ == nullptr) { + DHLOGE("%s: imageProcessor is null", LOG_TAG); + return ERR_DH_SCREEN_TRANS_NULL_VALUE; + } int32_t ret = imageProcessor_->ConfigureImageProcessor(localParam, remoteParam, listener); if (ret != DH_SUCCESS) { DHLOGE("%s: Config image processor failed ret: %d.", LOG_TAG, ret); @@ -292,7 +298,7 @@ int32_t ScreenSourceTrans::RegisterProcessorListener(const VideoParam &localPara } encoderSurface_ = imageProcessor_->GetImageSurface(); - if (!encoderSurface_) { + if (encoderSurface_ == nullptr) { DHLOGE("%s: Surface is null.", LOG_TAG); return ERR_DH_SCREEN_TRANS_NULL_VALUE; } @@ -303,6 +309,10 @@ int32_t ScreenSourceTrans::RegisterProcessorListener(const VideoParam &localPara void ScreenSourceTrans::OnSessionOpened() { DHLOGI("%s: OnChannelSessionOpened.", LOG_TAG); + if (imageProcessor_ == nullptr) { + DHLOGE("%s: imageProcessor is null", LOG_TAG); + return; + } int32_t ret = imageProcessor_->StartImageProcessor(); if (ret != DH_SUCCESS) { DHLOGE("%s: Start image processor failed ret: %d.", LOG_TAG, ret); @@ -326,7 +336,7 @@ void ScreenSourceTrans::OnSessionClosed() } std::shared_ptr callback = transCallback_.lock(); - if (!callback) { + if (callback == nullptr) { DHLOGE("%s: Trans callback is null.", LOG_TAG); return; } @@ -355,7 +365,7 @@ void ScreenSourceTrans::OnProcessorStateNotify(int32_t state) { DHLOGI("%s:OnProcessorStateNotify.", LOG_TAG); std::shared_ptr callback = transCallback_.lock(); - if (!callback) { + if (callback == nullptr) { DHLOGE("%s: Trans callback is null.", LOG_TAG); return; } diff --git a/services/softbusadapter/src/softbus_adapter.cpp b/services/softbusadapter/src/softbus_adapter.cpp index 99781076..503c226f 100644 --- a/services/softbusadapter/src/softbus_adapter.cpp +++ b/services/softbusadapter/src/softbus_adapter.cpp @@ -272,7 +272,7 @@ int32_t SoftbusAdapter::OnSoftbusSessionOpened(int32_t sessionId, int32_t result } std::shared_ptr &listener = GetSoftbusListenerByName(sessionId); - if (!listener) { + if (listener == nullptr) { DHLOGE("Get softbus listener failed."); return ERR_DH_SCREEN_TRANS_ERROR; } @@ -288,7 +288,7 @@ void SoftbusAdapter::OnSoftbusSessionClosed(int32_t sessionId) { DHLOGI("%s: OnSessionClosed sessionId:%d.", LOG_TAG, sessionId); std::shared_ptr &listener = GetSoftbusListenerById(sessionId); - if (!listener) { + if (listener == nullptr) { DHLOGE("Get softbus listener failed."); return; } @@ -311,7 +311,7 @@ void SoftbusAdapter::OnBytesReceived(int32_t sessionId, const void *data, uint32 } std::shared_ptr &listener = GetSoftbusListenerByName(sessionId); - if (!listener) { + if (listener == nullptr) { DHLOGE("Get softbus listener failed."); return; } @@ -332,7 +332,7 @@ void SoftbusAdapter::OnStreamReceived(int32_t sessionId, const StreamData *data, } std::shared_ptr &listener = GetSoftbusListenerByName(sessionId); - if (!listener) { + if (listener == nullptr) { DHLOGE("Get softbus listener failed."); return; } -- Gitee