diff --git a/bundle.json b/bundle.json index 158a29ac55cbd509866b706bc6e40d4a1d7e0d35..583122d53f4d8eefde53b121113b31c3d68805fc 100644 --- a/bundle.json +++ b/bundle.json @@ -35,6 +35,8 @@ "camera_framework", "graphic_2d", "distributed_hardware_fwk", + "device_security_level", + "device_manager", "hdf_core", "drivers_interface_display", "drivers_interface_distributed_camera", diff --git a/common/include/constants/dcamera_ipc_interface_code.h b/common/include/constants/dcamera_ipc_interface_code.h index 659049e7ccc3884c18104c936e408d9741a1bb28..d18d37dd65753c89f53956fb151862b57f45c854 100644 --- a/common/include/constants/dcamera_ipc_interface_code.h +++ b/common/include/constants/dcamera_ipc_interface_code.h @@ -40,6 +40,9 @@ enum class IDCameraSinkInterfaceCode : uint32_t { GET_CAMERA_INFO = 6, OPEN_CHANNEL = 7, CLOSE_CHANNEL = 8, + PAUSE_DISTRIBUTED_HARDWARE = 9, + RESUME_DISTRIBUTED_HARDWARE = 10, + STOP_DISTRIBUTED_HARDWARE = 11, }; } // namespace DistributedHardware } // namespace OHOS diff --git a/common/include/constants/distributed_camera_constants.h b/common/include/constants/distributed_camera_constants.h index d6ae70c9c48a62df8e33a6bde217cdc1f67be534..e924d5260f02067faf5066038a2edf41ff260233 100644 --- a/common/include/constants/distributed_camera_constants.h +++ b/common/include/constants/distributed_camera_constants.h @@ -43,12 +43,14 @@ typedef enum { typedef enum { DCAMERA_MESSAGE = 0, DCAMERA_OPERATION = 1, + DCAMERA_SINK_STOP = 2, } DCameraEventType; typedef enum { DCAMERA_EVENT_CHANNEL_DISCONNECTED = 0, DCAMERA_EVENT_CHANNEL_CONNECTED = 1, DCAMERA_EVENT_CAMERA_SUCCESS = 2, + DCAMERA_EVENT_SINK_STOP = 3, DCAMERA_EVENT_CAMERA_ERROR = -1, DCAMERA_EVENT_OPEN_CHANNEL_ERROR = -2, diff --git a/interfaces/inner_kits/native_cpp/camera_sink/BUILD.gn b/interfaces/inner_kits/native_cpp/camera_sink/BUILD.gn index e3b04ab8cf448e6c470f8e93aafa7dbe24cafd0a..1d88c044a08a350691d5e277d97738b2fc361cb8 100644 --- a/interfaces/inner_kits/native_cpp/camera_sink/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/camera_sink/BUILD.gn @@ -30,11 +30,14 @@ ohos_shared_library("distributed_camera_sink_sdk") { include_dirs += [ "include", + "include/callback", "${common_path}/include/constants", "${common_path}/include/utils", ] sources = [ + "src/callback/dcamera_sink_callback.cpp", + "src/callback/dcamera_sink_callback_stub.cpp", "src/dcamera_sink_handler.cpp", "src/dcamera_sink_handler_ipc.cpp", "src/dcamera_sink_load_callback.cpp", diff --git a/interfaces/inner_kits/native_cpp/camera_sink/include/callback/dcamera_sink_callback.h b/interfaces/inner_kits/native_cpp/camera_sink/include/callback/dcamera_sink_callback.h new file mode 100644 index 0000000000000000000000000000000000000000..5d44e712347d5df5e5aa1c2d01faa5bdb1c65df0 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/camera_sink/include/callback/dcamera_sink_callback.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2023 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_DCAMERA_SINK_CALLBACK_H +#define OHOS_DCAMERA_SINK_CALLBACK_H + +#include +#include + +#include "dcamera_sink_callback_stub.h" +#include "idistributed_hardware_sink.h" + +namespace OHOS { +namespace DistributedHardware { +class DCameraSinkCallback : public DCameraSinkCallbackStub { +public: + DCameraSinkCallback() = default; + ~DCameraSinkCallback() override; + + int32_t OnNotifyResourceInfo(const ResourceEventType &type, const std::string &subtype, + const std::string &networkId, bool &isSensitive, bool &isSameAccout) override; + void PushPrivacyResCallback(const std::shared_ptr &listener); + +private: + std::mutex privacyResMutex_; + std::vector> privacyResCallback_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DCAMERA_SINK_CALLBACK_H diff --git a/interfaces/inner_kits/native_cpp/camera_sink/include/callback/dcamera_sink_callback_stub.h b/interfaces/inner_kits/native_cpp/camera_sink/include/callback/dcamera_sink_callback_stub.h new file mode 100644 index 0000000000000000000000000000000000000000..576b624b62df23534e2e76b527e8bc2615aea0de --- /dev/null +++ b/interfaces/inner_kits/native_cpp/camera_sink/include/callback/dcamera_sink_callback_stub.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2023 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_DCAMERA_SINK_CALLBACK_STUB_H +#define OHOS_DCAMERA_SINK_CALLBACK_STUB_H + +#include + +#include "iremote_stub.h" +#include "idcamera_sink_callback.h" +#include "refbase.h" +namespace OHOS { class MessageOption; } +namespace OHOS { class MessageParcel; } + +namespace OHOS { +namespace DistributedHardware { +class DCameraSinkCallbackStub : public IRemoteStub { +public: + DCameraSinkCallbackStub(); + virtual ~DCameraSinkCallbackStub(); + int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + +private: + int32_t OnNotifyResourceInfoInner(MessageParcel &data, MessageParcel &reply); + + using DCameraFunc = int32_t (DCameraSinkCallbackStub::*)(MessageParcel &data, MessageParcel &reply); + std::map memberFuncMap_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DCAMERA_SINK_CALLBACK_STUB_H diff --git a/interfaces/inner_kits/native_cpp/camera_sink/include/callback/idcamera_sink_callback.h b/interfaces/inner_kits/native_cpp/camera_sink/include/callback/idcamera_sink_callback.h new file mode 100644 index 0000000000000000000000000000000000000000..45e8754df8498620f746bed19b741ea4b031c7ee --- /dev/null +++ b/interfaces/inner_kits/native_cpp/camera_sink/include/callback/idcamera_sink_callback.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2023 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_IDCAMERA_SINK_CALLBACK_H +#define OHOS_IDCAMERA_SINK_CALLBACK_H + +#include "iremote_broker.h" +#include "idistributed_hardware_sink.h" + +namespace OHOS { +namespace DistributedHardware { +class IDCameraSinkCallback : public OHOS::IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.distributedhardware.dcamerasinkcallback"); + enum { + NOTIFY_RESOURCEINFO = 0, + }; + + virtual ~IDCameraSinkCallback() {} + virtual int32_t OnNotifyResourceInfo(const ResourceEventType &type, const std::string &subtype, + const std::string &networkId, bool &isSensitive, bool &isSameAccout) = 0; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_IDCAMERA_SINK_CALLBACK_H diff --git a/interfaces/inner_kits/native_cpp/camera_sink/include/dcamera_sink_handler.h b/interfaces/inner_kits/native_cpp/camera_sink/include/dcamera_sink_handler.h index e40ab91828b42bc78c264b42faf51dac2e697d82..083e2006d6d1fb7e6d7cfd403a5cba9403b807aa 100644 --- a/interfaces/inner_kits/native_cpp/camera_sink/include/dcamera_sink_handler.h +++ b/interfaces/inner_kits/native_cpp/camera_sink/include/dcamera_sink_handler.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 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 @@ -21,6 +21,7 @@ #include #include "idistributed_hardware_sink.h" +#include "dcamera_sink_callback.h" #include "single_instance.h" namespace OHOS { @@ -41,7 +42,7 @@ private: DCAMERA_SA_STATE_STOP = 0, DCAMERA_SA_STATE_START = 1, } DCameraSAState; - DCameraSinkHandler() = default; + DCameraSinkHandler(); ~DCameraSinkHandler(); void FinishStartSA(const std::string ¶ms); void FinishStartSAFailed(const int32_t systemAbilityId); @@ -50,6 +51,7 @@ private: std::mutex producerMutex_; DCameraSAState state_ = DCAMERA_SA_STATE_STOP; friend class DCameraSinkLoadCallback; + sptr dCameraSinkCallback_ = nullptr; }; #ifdef __cplusplus diff --git a/interfaces/inner_kits/native_cpp/camera_sink/include/distributed_camera_sink_proxy.h b/interfaces/inner_kits/native_cpp/camera_sink/include/distributed_camera_sink_proxy.h index 1f798e948936f9de05d4d1acd6d48638d78d28f0..498a105f1fe4d3f5d6abc5ce591f1488a4581fcc 100644 --- a/interfaces/inner_kits/native_cpp/camera_sink/include/distributed_camera_sink_proxy.h +++ b/interfaces/inner_kits/native_cpp/camera_sink/include/distributed_camera_sink_proxy.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 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 @@ -32,7 +32,7 @@ public: } ~DistributedCameraSinkProxy() {} - int32_t InitSink(const std::string& params) override; + int32_t InitSink(const std::string& params, const sptr &sinkCallback) override; int32_t ReleaseSink() override; int32_t SubscribeLocalHardware(const std::string& dhId, const std::string& parameters) override; int32_t UnsubscribeLocalHardware(const std::string& dhId) override; @@ -41,6 +41,9 @@ public: int32_t GetCameraInfo(const std::string& dhId, std::string& cameraInfo) override; int32_t OpenChannel(const std::string& dhId, std::string& openInfo) override; int32_t CloseChannel(const std::string& dhId) override; + int32_t PauseDistributedHardware(const std::string &networkId) override; + int32_t ResumeDistributedHardware(const std::string &networkId) override; + int32_t StopDistributedHardware(const std::string &networkId) override; private: static inline BrokerDelegator delegator_; diff --git a/interfaces/inner_kits/native_cpp/camera_sink/include/idistributed_camera_sink.h b/interfaces/inner_kits/native_cpp/camera_sink/include/idistributed_camera_sink.h index 8fd8b1a350e88873c694707f5cf8a6be935cd626..34ad338983d98950b55ed327d8983f62edf4fa15 100644 --- a/interfaces/inner_kits/native_cpp/camera_sink/include/idistributed_camera_sink.h +++ b/interfaces/inner_kits/native_cpp/camera_sink/include/idistributed_camera_sink.h @@ -16,6 +16,7 @@ #ifndef OHOS_IDISTRIBUTED_CAMERA_SINK_H #define OHOS_IDISTRIBUTED_CAMERA_SINK_H +#include "idcamera_sink_callback.h" #include "iremote_broker.h" namespace OHOS { @@ -26,7 +27,7 @@ public: IDistributedCameraSink() = default; virtual ~IDistributedCameraSink() = default; - virtual int32_t InitSink(const std::string& params) = 0; + virtual int32_t InitSink(const std::string& params, const sptr &sinkCallback) = 0; virtual int32_t ReleaseSink() = 0; virtual int32_t SubscribeLocalHardware(const std::string& dhId, const std::string& parameters) = 0; virtual int32_t UnsubscribeLocalHardware(const std::string& dhId) = 0; @@ -35,6 +36,9 @@ public: virtual int32_t GetCameraInfo(const std::string& dhId, std::string& cameraInfo) = 0; virtual int32_t OpenChannel(const std::string& dhId, std::string& openInfo) = 0; virtual int32_t CloseChannel(const std::string& dhId) = 0; + virtual int32_t PauseDistributedHardware(const std::string &networkId) = 0; + virtual int32_t ResumeDistributedHardware(const std::string &networkId) = 0; + virtual int32_t StopDistributedHardware(const std::string &networkId) = 0; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/camera_sink/src/callback/dcamera_sink_callback.cpp b/interfaces/inner_kits/native_cpp/camera_sink/src/callback/dcamera_sink_callback.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d9dd4060fd8ed169845b7d920561f137e0619ddd --- /dev/null +++ b/interfaces/inner_kits/native_cpp/camera_sink/src/callback/dcamera_sink_callback.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2023 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 "dcamera_sink_callback.h" + +#include "anonymous_string.h" +#include "distributed_camera_errno.h" +#include "distributed_hardware_log.h" + +namespace OHOS { +namespace DistributedHardware { +DCameraSinkCallback::~DCameraSinkCallback() +{ + privacyResCallback_.clear(); +} + +int32_t DCameraSinkCallback::OnNotifyResourceInfo(const ResourceEventType &type, const std::string &subtype, + const std::string &networkId, bool &isSensitive, bool &isSameAccout) +{ + DHLOGI("DCameraSinkCallback OnNotifyResourceInfo type: %d, subtype: %s, networkId: %s, " + "isSensitive: %d, isSameAccout: %d", (uint32_t)type, subtype.c_str(), + GetAnonyString(networkId).c_str(), isSensitive, isSameAccout); + int32_t ret = DCAMERA_OK; + std::lock_guard lock(privacyResMutex_); + auto iter = privacyResCallback_.begin(); + if (iter != privacyResCallback_.end()) { + ret = (*iter)->OnPrivaceResourceMessage(type, subtype, networkId, isSensitive, isSameAccout); + } + return ret; +} + +void DCameraSinkCallback::PushPrivacyResCallback(const std::shared_ptr &listener) +{ + DHLOGI("push resource info callback."); + std::lock_guard lock(privacyResMutex_); + privacyResCallback_.push_back(listener); +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/camera_sink/src/callback/dcamera_sink_callback_stub.cpp b/interfaces/inner_kits/native_cpp/camera_sink/src/callback/dcamera_sink_callback_stub.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5ff4fa28bb96ee7bc7112597bb9d3c48f16ed6f2 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/camera_sink/src/callback/dcamera_sink_callback_stub.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2023 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 "dcamera_sink_callback_stub.h" +#include "distributed_camera_errno.h" +#include "distributed_hardware_log.h" +#include "ipc_object_stub.h" +#include "ipc_types.h" +#include "message_parcel.h" +namespace OHOS { class MessageOption; } + +namespace OHOS { +namespace DistributedHardware { +DCameraSinkCallbackStub::DCameraSinkCallbackStub() +{ + memberFuncMap_[NOTIFY_RESOURCEINFO] = &DCameraSinkCallbackStub::OnNotifyResourceInfoInner; +} + +DCameraSinkCallbackStub::~DCameraSinkCallbackStub() +{} + +int32_t DCameraSinkCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) +{ + DHLOGI("DCameraSinkCallbackStub OnRemoteRequest code: %d", code); + std::u16string desc = DCameraSinkCallbackStub::GetDescriptor(); + std::u16string remoteDesc = data.ReadInterfaceToken(); + if (desc != remoteDesc) { + DHLOGE("remoteDesc is invalid!"); + return ERR_INVALID_DATA; + } + auto itFunc = memberFuncMap_.find(code); + if (itFunc == memberFuncMap_.end()) { + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + + auto memberFunc = itFunc->second; + return (this->*memberFunc)(data, reply); +} + +int32_t DCameraSinkCallbackStub::OnNotifyResourceInfoInner(MessageParcel &data, MessageParcel &reply) +{ + DHLOGI("DCameraSinkCallbackStub OnNotifyResourceInfoInner"); + int32_t ret = DCAMERA_OK; + bool isSensitive; + bool isSameAccout; + do { + ResourceEventType type = static_cast(data.ReadInt32()); + std::string subtype = data.ReadString(); + std::string networkId = data.ReadString(); + ret = OnNotifyResourceInfo(type, subtype, networkId, isSensitive, isSameAccout); + } while (0); + reply.WriteInt32(ret); + reply.WriteBool(isSensitive); + reply.WriteBool(isSameAccout); + return DCAMERA_OK; +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/camera_sink/src/dcamera_sink_handler.cpp b/interfaces/inner_kits/native_cpp/camera_sink/src/dcamera_sink_handler.cpp index e7e1e1e80f599f5f69e669e689cd0cad38f3a1db..7b7feca304eb353242d69eaf665189b8bc02e764 100644 --- a/interfaces/inner_kits/native_cpp/camera_sink/src/dcamera_sink_handler.cpp +++ b/interfaces/inner_kits/native_cpp/camera_sink/src/dcamera_sink_handler.cpp @@ -36,6 +36,14 @@ namespace OHOS { namespace DistributedHardware { IMPLEMENT_SINGLE_INSTANCE(DCameraSinkHandler); +DCameraSinkHandler::DCameraSinkHandler() +{ + DHLOGI("DCameraSinkHandler ctor."); + if (!dCameraSinkCallback_) { + dCameraSinkCallback_ = new DCameraSinkCallback(); + } +} + DCameraSinkHandler::~DCameraSinkHandler() { DHLOGI("~DCameraSinkHandler"); @@ -86,7 +94,7 @@ void DCameraSinkHandler::FinishStartSA(const std::string& params) DHLOGE("get Service failed"); return; } - dCameraSinkSrv->InitSink(params); + dCameraSinkSrv->InitSink(params, dCameraSinkCallback_); std::unique_lock lock(producerMutex_); state_ = DCAMERA_SA_STATE_START; producerCon_.notify_one(); @@ -147,22 +155,42 @@ int32_t DCameraSinkHandler::UnsubscribeLocalHardware(const std::string& dhId) int32_t DCameraSinkHandler::RegisterPrivacyResources(std::shared_ptr listener) { + DHLOGI("RegisterPrivacyResources start."); + dCameraSinkCallback_->PushPrivacyResCallback(listener); return DCAMERA_OK; } int32_t DCameraSinkHandler::PauseDistributedHardware(const std::string &networkId) { - return DCAMERA_OK; + DHLOGI("pause distributed hardware."); + sptr dCameraSinkSrv = DCameraSinkHandlerIpc::GetInstance().GetSinkLocalCamSrv(); + if (dCameraSinkSrv == nullptr) { + DHLOGE("get Service failed"); + return DCAMERA_BAD_VALUE; + } + return dCameraSinkSrv->PauseDistributedHardware(networkId); } int32_t DCameraSinkHandler::ResumeDistributedHardware(const std::string &networkId) { - return DCAMERA_OK; + DHLOGI("resume distributed hardware."); + sptr dCameraSinkSrv = DCameraSinkHandlerIpc::GetInstance().GetSinkLocalCamSrv(); + if (dCameraSinkSrv == nullptr) { + DHLOGE("get Service failed"); + return DCAMERA_BAD_VALUE; + } + return dCameraSinkSrv->ResumeDistributedHardware(networkId); } int32_t DCameraSinkHandler::StopDistributedHardware(const std::string &networkId) { - return DCAMERA_OK; + DHLOGI("stop distributed hardware."); + sptr dCameraSinkSrv = DCameraSinkHandlerIpc::GetInstance().GetSinkLocalCamSrv(); + if (dCameraSinkSrv == nullptr) { + DHLOGE("get Service failed"); + return DCAMERA_BAD_VALUE; + } + return dCameraSinkSrv->StopDistributedHardware(networkId); } IDistributedHardwareSink *GetSinkHardwareHandler() diff --git a/interfaces/inner_kits/native_cpp/camera_sink/src/distributed_camera_sink_proxy.cpp b/interfaces/inner_kits/native_cpp/camera_sink/src/distributed_camera_sink_proxy.cpp index eaca8b0d63479f8209cc2765e27323031eaea162..35a86f839fcd5e7d34a921d1645869bdad859544 100644 --- a/interfaces/inner_kits/native_cpp/camera_sink/src/distributed_camera_sink_proxy.cpp +++ b/interfaces/inner_kits/native_cpp/camera_sink/src/distributed_camera_sink_proxy.cpp @@ -24,7 +24,7 @@ namespace OHOS { namespace DistributedHardware { -int32_t DistributedCameraSinkProxy::InitSink(const std::string& params) +int32_t DistributedCameraSinkProxy::InitSink(const std::string& params, const sptr &sinkCallback) { DHLOGI("start"); if (params.empty() || params.size() > PARAM_MAX_SIZE) { @@ -48,6 +48,10 @@ int32_t DistributedCameraSinkProxy::InitSink(const std::string& params) DHLOGE("write params failed"); return DCAMERA_BAD_VALUE; } + if (!data.WriteRemoteObject(sinkCallback->AsObject())) { + DHLOGE("write sinkCallback failed"); + return DCAMERA_BAD_VALUE; + } remote->SendRequest(static_cast(IDCameraSinkInterfaceCode::INIT_SINK), data, reply, option); int32_t result = reply.ReadInt32(); return result; @@ -282,5 +286,83 @@ int32_t DistributedCameraSinkProxy::CloseChannel(const std::string& dhId) int32_t result = reply.ReadInt32(); return result; } + +int32_t DistributedCameraSinkProxy::PauseDistributedHardware(const std::string &networkId) +{ + DHLOGI("networkId: %s", GetAnonyString(networkId).c_str()); + sptr remote = Remote(); + if (remote == nullptr) { + DHLOGE("remote service is null"); + return DCAMERA_BAD_VALUE; + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(DistributedCameraSinkProxy::GetDescriptor())) { + DHLOGE("write token failed"); + return DCAMERA_BAD_VALUE; + } + if (!data.WriteString(networkId)) { + DHLOGE("write params failed"); + return DCAMERA_BAD_VALUE; + } + remote->SendRequest(static_cast(IDCameraSinkInterfaceCode::PAUSE_DISTRIBUTED_HARDWARE), + data, reply, option); + int32_t result = reply.ReadInt32(); + return result; +} + +int32_t DistributedCameraSinkProxy::ResumeDistributedHardware(const std::string &networkId) +{ + DHLOGI("networkId: %s", GetAnonyString(networkId).c_str()); + sptr remote = Remote(); + if (remote == nullptr) { + DHLOGE("remote service is null"); + return DCAMERA_BAD_VALUE; + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(DistributedCameraSinkProxy::GetDescriptor())) { + DHLOGE("write token failed"); + return DCAMERA_BAD_VALUE; + } + if (!data.WriteString(networkId)) { + DHLOGE("write params failed"); + return DCAMERA_BAD_VALUE; + } + remote->SendRequest(static_cast(IDCameraSinkInterfaceCode::RESUME_DISTRIBUTED_HARDWARE), + data, reply, option); + int32_t result = reply.ReadInt32(); + return result; +} + +int32_t DistributedCameraSinkProxy::StopDistributedHardware(const std::string &networkId) +{ + DHLOGI("networkId: %s", GetAnonyString(networkId).c_str()); + sptr remote = Remote(); + if (remote == nullptr) { + DHLOGE("remote service is null"); + return DCAMERA_BAD_VALUE; + } + + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(DistributedCameraSinkProxy::GetDescriptor())) { + DHLOGE("write token failed"); + return DCAMERA_BAD_VALUE; + } + if (!data.WriteString(networkId)) { + DHLOGE("write params failed"); + return DCAMERA_BAD_VALUE; + } + remote->SendRequest(static_cast(IDCameraSinkInterfaceCode::STOP_DISTRIBUTED_HARDWARE), + data, reply, option); + int32_t result = reply.ReadInt32(); + return result; +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/camera_source/include/callback/idcamera_source_callback.h b/interfaces/inner_kits/native_cpp/camera_source/include/callback/idcamera_source_callback.h index 00325e8419ee486a6f1d17f9486ab062f0057707..02ffc9142010bc010c1787044f4f26a026b95c45 100644 --- a/interfaces/inner_kits/native_cpp/camera_source/include/callback/idcamera_source_callback.h +++ b/interfaces/inner_kits/native_cpp/camera_source/include/callback/idcamera_source_callback.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_IDCAMERA_SOURCE_CALLBACL_H -#define OHOS_IDCAMERA_SOURCE_CALLBACL_H +#ifndef OHOS_IDCAMERA_SOURCE_CALLBACK_H +#define OHOS_IDCAMERA_SOURCE_CALLBACK_H #include "iremote_broker.h" @@ -36,4 +36,4 @@ public: }; } // namespace DistributedHardware } // namespace OHOS -#endif // OHOS_IDCAMERA_SOURCE_CALLBACL_H +#endif // OHOS_IDCAMERA_SOURCE_CALLBACK_H diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/onsinklocalcamsrvdied_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/onsinklocalcamsrvdied_fuzzer/BUILD.gn index 18d49bda4490bb9856f6d69170b414ce5fdff3d0..ca1a3af21eeac6f18d87685a40fabc5896285dd0 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/onsinklocalcamsrvdied_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/onsinklocalcamsrvdied_fuzzer/BUILD.gn @@ -33,6 +33,7 @@ ohos_fuzztest("OnSinkLocalCamSrvDiedFuzzTest") { "${common_path}/include", "${common_path}/include/constants", "${innerkits_path}/native_cpp/camera_sink/include", + "${innerkits_path}/native_cpp/camera_sink/include/callback", ] cflags = [ diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerinitsink_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerinitsink_fuzzer/BUILD.gn index 70e9ef8e39fdd0e6dd029af7e051b0e4b9a90c00..aefbd20114f50ce0a1228801c106ed567e07e1fb 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerinitsink_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerinitsink_fuzzer/BUILD.gn @@ -33,6 +33,7 @@ ohos_fuzztest("SinkHandlerInitSinkFuzzTest") { "${common_path}/include", "${common_path}/include/constants", "${innerkits_path}/native_cpp/camera_sink/include", + "${innerkits_path}/native_cpp/camera_sink/include/callback", ] cflags = [ diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlersubscribelocalhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlersubscribelocalhardware_fuzzer/BUILD.gn index bb4a05b83c11101f2c68e171870b63400072296f..62229d5751f57b006a5b163ac8744490ba26d3b0 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlersubscribelocalhardware_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlersubscribelocalhardware_fuzzer/BUILD.gn @@ -33,6 +33,7 @@ ohos_fuzztest("SinkHandlerSubscribeLocalHardwareFuzzTest") { "${common_path}/include", "${common_path}/include/constants", "${innerkits_path}/native_cpp/camera_sink/include", + "${innerkits_path}/native_cpp/camera_sink/include/callback", ] cflags = [ diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerunsubscribelocalhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerunsubscribelocalhardware_fuzzer/BUILD.gn index 063e351eac23fdb9e43b92ac69a9e2b71c144a62..7d3329985a50109536affa7a97522562d28e3201 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerunsubscribelocalhardware_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkhandlerunsubscribelocalhardware_fuzzer/BUILD.gn @@ -34,6 +34,7 @@ ohos_fuzztest("SinkHandlerUnsubscribeLocalHardwareFuzzTest") { "${common_path}/include", "${common_path}/include/constants", "${innerkits_path}/native_cpp/camera_sink/include", + "${innerkits_path}/native_cpp/camera_sink/include/callback", ] cflags = [ diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkonloadsystemabilityfail_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkonloadsystemabilityfail_fuzzer/BUILD.gn index 911ab69a86fa2a7a53c7564ba8b5c4db2e9cef2b..27d9977759801af73acf2816dc233858b4ec9064 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkonloadsystemabilityfail_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkonloadsystemabilityfail_fuzzer/BUILD.gn @@ -30,6 +30,7 @@ ohos_fuzztest("SinkOnLoadSystemAbilityFailFuzzTest") { "${common_path}/include", "${common_path}/include/constants", "${innerkits_path}/native_cpp/camera_sink/include", + "${innerkits_path}/native_cpp/camera_sink/include/callback", ] cflags = [ diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkonloadsystemabilitysuccess_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkonloadsystemabilitysuccess_fuzzer/BUILD.gn index e4926aacc1c02f8781ed86f87e11eb957c91c6a8..889c218b24369be3f54d3592d598e559911a68a0 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkonloadsystemabilitysuccess_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkonloadsystemabilitysuccess_fuzzer/BUILD.gn @@ -30,6 +30,7 @@ ohos_fuzztest("SinkOnLoadSystemAbilitySuccessFuzzTest") { "${common_path}/include", "${common_path}/include/constants", "${innerkits_path}/native_cpp/camera_sink/include", + "${innerkits_path}/native_cpp/camera_sink/include/callback", ] cflags = [ diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxychannelneg_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxychannelneg_fuzzer/BUILD.gn index f3b06f8a30d87efffe0e040e879791f4d7502dba..77342800e1eb5138e3da395c1f8df4116bb02dcc 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxychannelneg_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxychannelneg_fuzzer/BUILD.gn @@ -30,6 +30,7 @@ ohos_fuzztest("SinkProxyChannelNegFuzzTest") { "${common_path}/include", "${common_path}/include/constants", "${innerkits_path}/native_cpp/camera_sink/include", + "${innerkits_path}/native_cpp/camera_sink/include/callback", ] cflags = [ diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyclosechannel_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyclosechannel_fuzzer/BUILD.gn index 794993177036b16e109e33cac3d6b72763c296d6..5c9cc0104c9c709a5b10c508a76445f5d7f82bef 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyclosechannel_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyclosechannel_fuzzer/BUILD.gn @@ -30,6 +30,7 @@ ohos_fuzztest("SinkProxyCloseChannelFuzzTest") { "${common_path}/include", "${common_path}/include/constants", "${innerkits_path}/native_cpp/camera_sink/include", + "${innerkits_path}/native_cpp/camera_sink/include/callback", ] cflags = [ diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxygetcamerainfo_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxygetcamerainfo_fuzzer/BUILD.gn index 25ee98e7ba218f5e1e7d33b0475f6f865621862e..44eb156757b0578ddce46cdeb566766c236fde85 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxygetcamerainfo_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxygetcamerainfo_fuzzer/BUILD.gn @@ -30,6 +30,7 @@ ohos_fuzztest("SinkProxyGetCameraInfoFuzzTest") { "${common_path}/include", "${common_path}/include/constants", "${innerkits_path}/native_cpp/camera_sink/include", + "${innerkits_path}/native_cpp/camera_sink/include/callback", ] cflags = [ diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyinitsink_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyinitsink_fuzzer/BUILD.gn index e2e30e5e22e52076ee3deae4d612dcb0bcbb59f0..8cd72a590414737278c11ec5b92d8cb68bc46947 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyinitsink_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyinitsink_fuzzer/BUILD.gn @@ -31,6 +31,7 @@ ohos_fuzztest("SinkProxyInitSinkFuzzTest") { "${common_path}/include", "${common_path}/include/constants", "${innerkits_path}/native_cpp/camera_sink/include", + "${innerkits_path}/native_cpp/camera_sink/include/callback", ] cflags = [ diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyinitsink_fuzzer/sinkproxyinitsink_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyinitsink_fuzzer/sinkproxyinitsink_fuzzer.cpp index 9db14d0d5387ff4a6f24b88bbc5f26878c658ea7..fa85b599fc815b87920acd833695c1d93b11747b 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyinitsink_fuzzer/sinkproxyinitsink_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyinitsink_fuzzer/sinkproxyinitsink_fuzzer.cpp @@ -18,6 +18,7 @@ #include #include +#include "dcamera_sink_callback.h" #include "distributed_camera_constants.h" #include "distributed_camera_sink_proxy.h" #include "if_system_ability_manager.h" @@ -38,8 +39,8 @@ void SinkProxyInitSinkFuzzTest(const uint8_t* data, size_t size) sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_CAMERA_SINK_SA_ID); std::shared_ptr dCSinkProxy = std::make_shared(remoteObject); - - dCSinkProxy->InitSink(param); + sptr sinkCallback(new DCameraSinkCallback()); + dCSinkProxy->InitSink(param, sinkCallback); } } } diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyopenchannel_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyopenchannel_fuzzer/BUILD.gn index 37cbdd20382d133da4a4c767f78d497291edaf24..4d2ac7d9f60cc463b9eb2f2c22fa4e698c76fa81 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyopenchannel_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyopenchannel_fuzzer/BUILD.gn @@ -30,6 +30,7 @@ ohos_fuzztest("SinkProxyOpenChannelFuzzTest") { "${common_path}/include", "${common_path}/include/constants", "${innerkits_path}/native_cpp/camera_sink/include", + "${innerkits_path}/native_cpp/camera_sink/include/callback", ] cflags = [ diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxystopcapture_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxystopcapture_fuzzer/BUILD.gn index 614444b13ab7791f7d39284dc5aa01de0fd8c0d9..ffe992282c1f031aab016361b757e661b94343cb 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxystopcapture_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxystopcapture_fuzzer/BUILD.gn @@ -30,6 +30,7 @@ ohos_fuzztest("SinkProxyStopCaptureFuzzTest") { "${common_path}/include", "${common_path}/include/constants", "${innerkits_path}/native_cpp/camera_sink/include", + "${innerkits_path}/native_cpp/camera_sink/include/callback", ] cflags = [ diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxysubscribelocalhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxysubscribelocalhardware_fuzzer/BUILD.gn index 37bc51dca13200560a80402e4a2629de7aa57de3..e35505ab54317bccc13eeb0235dc2997e11e74dd 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxysubscribelocalhardware_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxysubscribelocalhardware_fuzzer/BUILD.gn @@ -30,6 +30,7 @@ ohos_fuzztest("SinkProxySubscribeLocalHardwareFuzzTest") { "${common_path}/include", "${common_path}/include/constants", "${innerkits_path}/native_cpp/camera_sink/include", + "${innerkits_path}/native_cpp/camera_sink/include/callback", ] cflags = [ diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyunsubscribelocalhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyunsubscribelocalhardware_fuzzer/BUILD.gn index 771e59e0ca06159e037df31cd9b0771cf2cf5984..d3eb639a252de78bd6ffdb664b6cae77dae7a27b 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyunsubscribelocalhardware_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkproxyunsubscribelocalhardware_fuzzer/BUILD.gn @@ -30,6 +30,7 @@ ohos_fuzztest("SinkProxyUnsubscribeLocalHardwareFuzzTest") { "${common_path}/include", "${common_path}/include/constants", "${innerkits_path}/native_cpp/camera_sink/include", + "${innerkits_path}/native_cpp/camera_sink/include/callback", ] cflags = [ diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicechannelneg_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicechannelneg_fuzzer/BUILD.gn index 4fd888f44832fa1c4ad9f2835b9ec6980b197980..da7bdb5490f421903804002abd1f62d7b7429ea0 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicechannelneg_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicechannelneg_fuzzer/BUILD.gn @@ -29,11 +29,19 @@ ohos_fuzztest("SinkServiceChannelNegFuzzTest") { "include", "${common_path}/include/constants", "${common_path}/include/utils", + "${graphicstandard_path}/frameworks/surface/include", "${innerkits_path}/native_cpp/camera_sink/include", + "${innerkits_path}/native_cpp/camera_sink/include/callback", "${services_path}/cameraservice/base/include", + "${services_path}/cameraservice/cameraoperator/client/include", "${services_path}/cameraservice/sinkservice/include/distributedcamera", "${services_path}/cameraservice/sinkservice/include/distributedcameramgr", "${services_path}/cameraservice/sinkservice/include/distributedcameramgr/interface", + "${services_path}/cameraservice/sinkservice/include/distributedcameramgr/eventbus", + "${services_path}/data_process/include/utils", + "${services_path}/channel/include", + "${fwk_utils_path}/include/eventbus", + "${feeding_smoother_path}/base", "//third_party/cJSON", "//third_party/jsoncpp/include", ] @@ -60,7 +68,9 @@ ohos_fuzztest("SinkServiceChannelNegFuzzTest") { external_deps = [ "c_utils:utils", + "device_manager:devicemanagersdk", "drivers_interface_distributed_camera:libdistributed_camera_provider_proxy_1.0", + "graphic_2d:surface", "hilog:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceclosechannel_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceclosechannel_fuzzer/BUILD.gn index 531298f47370c5e0cecd75ef8313b93b180ab0cc..398d7606bc5e5c3c4a61f29927369b6e17249ac0 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceclosechannel_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceclosechannel_fuzzer/BUILD.gn @@ -29,11 +29,19 @@ ohos_fuzztest("SinkServiceCloseChannelFuzzTest") { "include", "${common_path}/include/constants", "${common_path}/include/utils", + "${graphicstandard_path}/frameworks/surface/include", "${innerkits_path}/native_cpp/camera_sink/include", + "${innerkits_path}/native_cpp/camera_sink/include/callback", "${services_path}/cameraservice/base/include", + "${services_path}/cameraservice/cameraoperator/client/include", "${services_path}/cameraservice/sinkservice/include/distributedcamera", "${services_path}/cameraservice/sinkservice/include/distributedcameramgr", "${services_path}/cameraservice/sinkservice/include/distributedcameramgr/interface", + "${services_path}/cameraservice/sinkservice/include/distributedcameramgr/eventbus", + "${services_path}/data_process/include/utils", + "${services_path}/channel/include", + "${fwk_utils_path}/include/eventbus", + "${feeding_smoother_path}/base", "//third_party/cJSON", "//third_party/jsoncpp/include", ] @@ -60,7 +68,9 @@ ohos_fuzztest("SinkServiceCloseChannelFuzzTest") { external_deps = [ "c_utils:utils", + "device_manager:devicemanagersdk", "drivers_interface_distributed_camera:libdistributed_camera_provider_proxy_1.0", + "graphic_2d:surface", "hilog:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicegetcamerainfo_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicegetcamerainfo_fuzzer/BUILD.gn index 554b22ecb17d51e1ace76322fc2fbef15327c241..f9c5b8a0c069987c87022ca39dfd61190bc8a217 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicegetcamerainfo_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicegetcamerainfo_fuzzer/BUILD.gn @@ -29,11 +29,19 @@ ohos_fuzztest("SinkServiceGetCameraInfoFuzzTest") { "include", "${common_path}/include/constants", "${common_path}/include/utils", + "${graphicstandard_path}/frameworks/surface/include", "${innerkits_path}/native_cpp/camera_sink/include", + "${innerkits_path}/native_cpp/camera_sink/include/callback", "${services_path}/cameraservice/base/include", + "${services_path}/cameraservice/cameraoperator/client/include", "${services_path}/cameraservice/sinkservice/include/distributedcamera", "${services_path}/cameraservice/sinkservice/include/distributedcameramgr", "${services_path}/cameraservice/sinkservice/include/distributedcameramgr/interface", + "${services_path}/cameraservice/sinkservice/include/distributedcameramgr/eventbus", + "${services_path}/data_process/include/utils", + "${services_path}/channel/include", + "${fwk_utils_path}/include/eventbus", + "${feeding_smoother_path}/base", "//third_party/cJSON", "//third_party/jsoncpp/include", ] @@ -60,7 +68,9 @@ ohos_fuzztest("SinkServiceGetCameraInfoFuzzTest") { external_deps = [ "c_utils:utils", + "device_manager:devicemanagersdk", "drivers_interface_distributed_camera:libdistributed_camera_provider_proxy_1.0", + "graphic_2d:surface", "hilog:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceinitsink_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceinitsink_fuzzer/BUILD.gn index 00bce3862832dcec991b93c5179c6807103fdb67..1f0c9fe16402318c712965249e07abf229c552e3 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceinitsink_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceinitsink_fuzzer/BUILD.gn @@ -29,11 +29,19 @@ ohos_fuzztest("SinkServiceInitSinkFuzzTest") { "include", "${common_path}/include/constants", "${common_path}/include/utils", + "${graphicstandard_path}/frameworks/surface/include", "${innerkits_path}/native_cpp/camera_sink/include", + "${innerkits_path}/native_cpp/camera_sink/include/callback", "${services_path}/cameraservice/base/include", + "${services_path}/cameraservice/cameraoperator/client/include", "${services_path}/cameraservice/sinkservice/include/distributedcamera", "${services_path}/cameraservice/sinkservice/include/distributedcameramgr", "${services_path}/cameraservice/sinkservice/include/distributedcameramgr/interface", + "${services_path}/cameraservice/sinkservice/include/distributedcameramgr/eventbus", + "${services_path}/data_process/include/utils", + "${services_path}/channel/include", + "${fwk_utils_path}/include/eventbus", + "${feeding_smoother_path}/base", "//third_party/cJSON", "//third_party/jsoncpp/include", ] @@ -49,6 +57,7 @@ ohos_fuzztest("SinkServiceInitSinkFuzzTest") { deps = [ "${common_path}:distributed_camera_utils", + "${innerkits_path}/native_cpp/camera_sink:distributed_camera_sink_sdk", "${services_path}/cameraservice/sinkservice:distributed_camera_sink", ] @@ -60,7 +69,9 @@ ohos_fuzztest("SinkServiceInitSinkFuzzTest") { external_deps = [ "c_utils:utils", + "device_manager:devicemanagersdk", "drivers_interface_distributed_camera:libdistributed_camera_provider_proxy_1.0", + "graphic_2d:surface", "hilog:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceinitsink_fuzzer/sinkserviceinitsink_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceinitsink_fuzzer/sinkserviceinitsink_fuzzer.cpp index f0cc6f5223cd1b181e184b07a281891c7a8b0c9b..db25aeab2d94778703c3180798b8c9fdb2cded83 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceinitsink_fuzzer/sinkserviceinitsink_fuzzer.cpp +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceinitsink_fuzzer/sinkserviceinitsink_fuzzer.cpp @@ -18,6 +18,7 @@ #include #include +#include "dcamera_sink_callback.h" #include "distributed_camera_constants.h" #include "distributed_camera_sink_service.h" #include "if_system_ability_manager.h" @@ -35,8 +36,8 @@ void SinkServiceInitSinkFuzzTest(const uint8_t* data, size_t size) std::shared_ptr sinkService = std::make_shared(DISTRIBUTED_HARDWARE_CAMERA_SINK_SA_ID, true); - - sinkService->InitSink(param); + sptr sinkCallback(new DCameraSinkCallback()); + sinkService->InitSink(param, sinkCallback); } } } diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceopenchannel_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceopenchannel_fuzzer/BUILD.gn index b17c687118a2b411479b96f7f3b90f1bf76c2bfb..761def86b869e3b9dd65c0395dbcd832ae2238c9 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceopenchannel_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceopenchannel_fuzzer/BUILD.gn @@ -29,11 +29,19 @@ ohos_fuzztest("SinkServiceOpenChannelFuzzTest") { "include", "${common_path}/include/constants", "${common_path}/include/utils", + "${graphicstandard_path}/frameworks/surface/include", "${innerkits_path}/native_cpp/camera_sink/include", + "${innerkits_path}/native_cpp/camera_sink/include/callback", "${services_path}/cameraservice/base/include", + "${services_path}/cameraservice/cameraoperator/client/include", "${services_path}/cameraservice/sinkservice/include/distributedcamera", "${services_path}/cameraservice/sinkservice/include/distributedcameramgr", "${services_path}/cameraservice/sinkservice/include/distributedcameramgr/interface", + "${services_path}/cameraservice/sinkservice/include/distributedcameramgr/eventbus", + "${services_path}/data_process/include/utils", + "${services_path}/channel/include", + "${fwk_utils_path}/include/eventbus", + "${feeding_smoother_path}/base", "//third_party/cJSON", "//third_party/jsoncpp/include", ] @@ -60,7 +68,9 @@ ohos_fuzztest("SinkServiceOpenChannelFuzzTest") { external_deps = [ "c_utils:utils", + "device_manager:devicemanagersdk", "drivers_interface_distributed_camera:libdistributed_camera_provider_proxy_1.0", + "graphic_2d:surface", "hilog:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicereleasesink_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicereleasesink_fuzzer/BUILD.gn index 57e8536caa1051fe4934c3d87fc24f8e09045af6..bc60eb189828f33978212e4f37c0ecdc70fe21d9 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicereleasesink_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicereleasesink_fuzzer/BUILD.gn @@ -29,11 +29,19 @@ ohos_fuzztest("SinkServiceReleaseSinkFuzzTest") { "include", "${common_path}/include/constants", "${common_path}/include/utils", + "${graphicstandard_path}/frameworks/surface/include", "${innerkits_path}/native_cpp/camera_sink/include", + "${innerkits_path}/native_cpp/camera_sink/include/callback", "${services_path}/cameraservice/base/include", + "${services_path}/cameraservice/cameraoperator/client/include", "${services_path}/cameraservice/sinkservice/include/distributedcamera", "${services_path}/cameraservice/sinkservice/include/distributedcameramgr", "${services_path}/cameraservice/sinkservice/include/distributedcameramgr/interface", + "${services_path}/cameraservice/sinkservice/include/distributedcameramgr/eventbus", + "${services_path}/data_process/include/utils", + "${services_path}/channel/include", + "${fwk_utils_path}/include/eventbus", + "${feeding_smoother_path}/base", "//third_party/cJSON", "//third_party/jsoncpp/include", ] @@ -60,7 +68,9 @@ ohos_fuzztest("SinkServiceReleaseSinkFuzzTest") { external_deps = [ "c_utils:utils", + "device_manager:devicemanagersdk", "drivers_interface_distributed_camera:libdistributed_camera_provider_proxy_1.0", + "graphic_2d:surface", "hilog:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicestopcapture_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicestopcapture_fuzzer/BUILD.gn index b1902c05bd9ca82c799f1ff0f5e0486d2029bcf6..dbb7d7ef324eb871720b4d460c7401c3c2312d44 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicestopcapture_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicestopcapture_fuzzer/BUILD.gn @@ -29,11 +29,19 @@ ohos_fuzztest("SinkServiceStopCaptureFuzzTest") { "include", "${common_path}/include/constants", "${common_path}/include/utils", + "${graphicstandard_path}/frameworks/surface/include", "${innerkits_path}/native_cpp/camera_sink/include", + "${innerkits_path}/native_cpp/camera_sink/include/callback", "${services_path}/cameraservice/base/include", + "${services_path}/cameraservice/cameraoperator/client/include", "${services_path}/cameraservice/sinkservice/include/distributedcamera", "${services_path}/cameraservice/sinkservice/include/distributedcameramgr", "${services_path}/cameraservice/sinkservice/include/distributedcameramgr/interface", + "${services_path}/cameraservice/sinkservice/include/distributedcameramgr/eventbus", + "${services_path}/data_process/include/utils", + "${services_path}/channel/include", + "${fwk_utils_path}/include/eventbus", + "${feeding_smoother_path}/base", "//third_party/cJSON", "//third_party/jsoncpp/include", ] @@ -60,7 +68,9 @@ ohos_fuzztest("SinkServiceStopCaptureFuzzTest") { external_deps = [ "c_utils:utils", + "device_manager:devicemanagersdk", "drivers_interface_distributed_camera:libdistributed_camera_provider_proxy_1.0", + "graphic_2d:surface", "hilog:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicesubscribelocalhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicesubscribelocalhardware_fuzzer/BUILD.gn index 78572b1639b6f787bfdab5ccbaa8fa0cf73d833b..8bd7444c8ac435c17f6e3215011a6376519ce4e0 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicesubscribelocalhardware_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkservicesubscribelocalhardware_fuzzer/BUILD.gn @@ -29,11 +29,19 @@ ohos_fuzztest("SinkServiceSubscribeLocalHardwareFuzzTest") { "include", "${common_path}/include/constants", "${common_path}/include/utils", + "${graphicstandard_path}/frameworks/surface/include", "${innerkits_path}/native_cpp/camera_sink/include", + "${innerkits_path}/native_cpp/camera_sink/include/callback", "${services_path}/cameraservice/base/include", + "${services_path}/cameraservice/cameraoperator/client/include", "${services_path}/cameraservice/sinkservice/include/distributedcamera", "${services_path}/cameraservice/sinkservice/include/distributedcameramgr", "${services_path}/cameraservice/sinkservice/include/distributedcameramgr/interface", + "${services_path}/cameraservice/sinkservice/include/distributedcameramgr/eventbus", + "${services_path}/data_process/include/utils", + "${services_path}/channel/include", + "${fwk_utils_path}/include/eventbus", + "${feeding_smoother_path}/base", "//third_party/cJSON", "//third_party/jsoncpp/include", ] @@ -60,7 +68,9 @@ ohos_fuzztest("SinkServiceSubscribeLocalHardwareFuzzTest") { external_deps = [ "c_utils:utils", + "device_manager:devicemanagersdk", "drivers_interface_distributed_camera:libdistributed_camera_provider_proxy_1.0", + "graphic_2d:surface", "hilog:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", diff --git a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceunsubscribelocalhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceunsubscribelocalhardware_fuzzer/BUILD.gn index a323a69853d6d8842b7ae67b2e31a084807744ff..8196d45fb0357414bd9efe9ed3ce865ee18d2ba5 100644 --- a/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceunsubscribelocalhardware_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/sinkfuzztest/sinkserviceunsubscribelocalhardware_fuzzer/BUILD.gn @@ -30,11 +30,19 @@ ohos_fuzztest("SinkServiceUnsubscribeLocalHardwareFuzzTest") { "include", "${common_path}/include/constants", "${common_path}/include/utils", + "${graphicstandard_path}/frameworks/surface/include", "${innerkits_path}/native_cpp/camera_sink/include", + "${innerkits_path}/native_cpp/camera_sink/include/callback", "${services_path}/cameraservice/base/include", + "${services_path}/cameraservice/cameraoperator/client/include", "${services_path}/cameraservice/sinkservice/include/distributedcamera", "${services_path}/cameraservice/sinkservice/include/distributedcameramgr", "${services_path}/cameraservice/sinkservice/include/distributedcameramgr/interface", + "${services_path}/cameraservice/sinkservice/include/distributedcameramgr/eventbus", + "${services_path}/data_process/include/utils", + "${services_path}/channel/include", + "${fwk_utils_path}/include/eventbus", + "${feeding_smoother_path}/base", "//third_party/cJSON", "//third_party/jsoncpp/include", ] @@ -61,7 +69,9 @@ ohos_fuzztest("SinkServiceUnsubscribeLocalHardwareFuzzTest") { external_deps = [ "c_utils:utils", + "device_manager:devicemanagersdk", "drivers_interface_distributed_camera:libdistributed_camera_provider_proxy_1.0", + "graphic_2d:surface", "hilog:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", diff --git a/sa_profile/dcamera.cfg b/sa_profile/dcamera.cfg index a98ed061d18859ee244514ce8ff9b9ff18a1a983..cc5d2cfe33bf305c444702dbbf688c3fdcd83c9f 100644 --- a/sa_profile/dcamera.cfg +++ b/sa_profile/dcamera.cfg @@ -6,7 +6,12 @@ "gid" : ["dcamera"], "ondemand" : true, "apl" : "system_basic", - "permission" : ["ohos.permission.DISTRIBUTED_DATASYNC", "ohos.permission.DISTRIBUTED_SOFTBUS_CENTER", "ohos.permission.CAMERA"], + "permission" : [ + "ohos.permission.ACCESS_SERVICE_DM", + "ohos.permission.DISTRIBUTED_DATASYNC", + "ohos.permission.DISTRIBUTED_SOFTBUS_CENTER", + "ohos.permission.CAMERA" + ], "secon" : "u:r:dcamera:s0" }] } \ No newline at end of file diff --git a/services/cameraservice/base/include/icamera_controller.h b/services/cameraservice/base/include/icamera_controller.h index 4f49346528ac8ea1609123af8034a773e95180c9..ddbbe162d01a357a981b5843b400e12b55c4a1b6 100644 --- a/services/cameraservice/base/include/icamera_controller.h +++ b/services/cameraservice/base/include/icamera_controller.h @@ -40,6 +40,9 @@ public: virtual int32_t CloseChannel() = 0; virtual int32_t Init(std::vector& indexs) = 0; virtual int32_t UnInit() = 0; + virtual int32_t PauseDistributedHardware(const std::string &networkId) = 0; + virtual int32_t ResumeDistributedHardware(const std::string &networkId) = 0; + virtual int32_t StopDistributedHardware(const std::string &networkId) = 0; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/cameraservice/cameraoperator/client/include/dcamera_client.h b/services/cameraservice/cameraoperator/client/include/dcamera_client.h index f49dd9053917ef315fb4900614c0a0ed2aa442b1..e52799fb956cbc79d6be6bf86863901fbef7819c 100644 --- a/services/cameraservice/cameraoperator/client/include/dcamera_client.h +++ b/services/cameraservice/cameraoperator/client/include/dcamera_client.h @@ -47,6 +47,8 @@ public: int32_t StopCapture() override; int32_t SetStateCallback(std::shared_ptr& callback) override; int32_t SetResultCallback(std::shared_ptr& callback) override; + int32_t PauseCapture() override; + int32_t ResumeCapture() override; private: int32_t ConfigCaptureSession(std::vector>& captureInfos); diff --git a/services/cameraservice/cameraoperator/client/include/icamera_operator.h b/services/cameraservice/cameraoperator/client/include/icamera_operator.h index e5d33b7baac73f38bee921e8465b96cf6930f4dc..6540a455638dc4f588bb48eee3988e9e1786cd78 100644 --- a/services/cameraservice/cameraoperator/client/include/icamera_operator.h +++ b/services/cameraservice/cameraoperator/client/include/icamera_operator.h @@ -62,6 +62,8 @@ public: virtual int32_t StopCapture() = 0; virtual int32_t SetStateCallback(std::shared_ptr& callback) = 0; virtual int32_t SetResultCallback(std::shared_ptr& callback) = 0; + virtual int32_t PauseCapture() = 0; + virtual int32_t ResumeCapture() = 0; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp b/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp index 0dd1becd7e441b50b8b161566597bc543945b478..38e7a961cb74cb0f48fac6008ee60c543908e558 100644 --- a/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp +++ b/services/cameraservice/cameraoperator/client/src/dcamera_client.cpp @@ -645,5 +645,25 @@ void DCameraClient::SetPhotoCaptureLocation(const std::shared_ptrStop(); + if (ret != DCAMERA_OK) { + DHLOGE("PauseCapture captureSession stop failed, cameraId: %s, ret: %d", + GetAnonyString(cameraId_).c_str(), ret); + } + return ret; +} + +int32_t DCameraClient::ResumeCapture() +{ + int32_t ret = captureSession_->Start(); + if (ret != DCAMERA_OK) { + DHLOGE("ResumeCapture captureSession Start failed, cameraId: %s, ret: %d", + GetAnonyString(cameraId_).c_str(), ret); + } + return ret; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/cameraservice/sinkservice/BUILD.gn b/services/cameraservice/sinkservice/BUILD.gn index 3daa8b41c1f905c9a13d4f7141978d7ff0f99081..848b5e00de1f93ed078cf7211bcbc4b6f65f8439 100644 --- a/services/cameraservice/sinkservice/BUILD.gn +++ b/services/cameraservice/sinkservice/BUILD.gn @@ -54,6 +54,7 @@ ohos_shared_library("distributed_camera_sink") { "${common_path}/include/constants", "${common_path}/include/utils", "${innerkits_path}/native_cpp/camera_sink/include", + "${innerkits_path}/native_cpp/camera_sink/include/callback", "${innerkits_path}/native_cpp/camera_source/include", "${innerkits_path}/native_cpp/camera_source/include/callback", "${services_path}/cameraservice/base/include", @@ -81,6 +82,7 @@ ohos_shared_library("distributed_camera_sink") { "${services_path}/cameraservice/base/src/dcamera_info_cmd.cpp", "${services_path}/cameraservice/base/src/dcamera_metadata_setting_cmd.cpp", "${services_path}/cameraservice/base/src/dcamera_open_info_cmd.cpp", + "src/distributedcamera/dcamera_sink_callback_proxy.cpp", "src/distributedcamera/dcamera_sink_hidumper.cpp", "src/distributedcamera/distributed_camera_sink_service.cpp", "src/distributedcamera/distributed_camera_sink_stub.cpp", @@ -122,6 +124,8 @@ ohos_shared_library("distributed_camera_sink") { "access_token:libtokenid_sdk", "c_utils:utils", "camera_framework:camera_framework", + "device_manager:devicemanagersdk", + "device_security_level:dslm_sdk", "drivers_interface_distributed_camera:libdistributed_camera_provider_proxy_1.0", "drivers_peripheral_display:hdi_gralloc_client", "eventhandler:libeventhandler", diff --git a/services/cameraservice/sinkservice/include/distributedcamera/dcamera_sink_callback_proxy.h b/services/cameraservice/sinkservice/include/distributedcamera/dcamera_sink_callback_proxy.h new file mode 100644 index 0000000000000000000000000000000000000000..ebf3df15f941bc59034449de4b19caa54742ce42 --- /dev/null +++ b/services/cameraservice/sinkservice/include/distributedcamera/dcamera_sink_callback_proxy.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2023 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_DCAMERA_SINK_CALLBACK_PROXY_H +#define OHOS_DCAMERA_SINK_CALLBACK_PROXY_H +#include + +#include "iremote_proxy.h" +#include "iremote_broker.h" +#include "refbase.h" + +#include "idcamera_sink_callback.h" + +namespace OHOS { +namespace DistributedHardware { +class DCameraSinkCallbackProxy : public IRemoteProxy { +public: + explicit DCameraSinkCallbackProxy(const sptr &impl) : IRemoteProxy(impl) + {} + ~DCameraSinkCallbackProxy() + {} + + int32_t OnNotifyResourceInfo(const ResourceEventType &type, const std::string &subtype, + const std::string &networkId, bool &isSensitive, bool &isSameAccout) override; +private: + static inline BrokerDelegator delegator_; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DCAMERA_SINK_CALLBACK_PROXY_H diff --git a/services/cameraservice/sinkservice/include/distributedcamera/distributed_camera_sink_service.h b/services/cameraservice/sinkservice/include/distributedcamera/distributed_camera_sink_service.h index 67a0f5fbad6dc94616392f6416aa88b9ca06411a..601ef5befbae066d69f77ac4740b61f9e1b20ae7 100644 --- a/services/cameraservice/sinkservice/include/distributedcamera/distributed_camera_sink_service.h +++ b/services/cameraservice/sinkservice/include/distributedcamera/distributed_camera_sink_service.h @@ -34,7 +34,7 @@ public: DistributedCameraSinkService(int32_t saId, bool runOnCreate); ~DistributedCameraSinkService() override = default; - int32_t InitSink(const std::string& params) override; + int32_t InitSink(const std::string& params, const sptr &sinkCallback) override; int32_t ReleaseSink() override; int32_t SubscribeLocalHardware(const std::string& dhId, const std::string& parameters) override; int32_t UnsubscribeLocalHardware(const std::string& dhId) override; @@ -45,6 +45,9 @@ public: int32_t CloseChannel(const std::string& dhId) override; int Dump(int32_t fd, const std::vector& args) override; static void GetCamDumpInfo(CameraDumpInfo& camDump); + int32_t PauseDistributedHardware(const std::string &networkId) override; + int32_t ResumeDistributedHardware(const std::string &networkId) override; + int32_t StopDistributedHardware(const std::string &networkId) override; protected: void OnStart() override; @@ -52,6 +55,8 @@ protected: DISALLOW_COPY_AND_MOVE(DistributedCameraSinkService); private: + bool IsCurSinkDev(std::shared_ptr sinkDevice); + bool Init(); void GetCamIds(); bool registerToService_ = false; diff --git a/services/cameraservice/sinkservice/include/distributedcamera/distributed_camera_sink_stub.h b/services/cameraservice/sinkservice/include/distributedcamera/distributed_camera_sink_stub.h index 47464fbc0fe4dd549fa0a1cf1b480a0d83554711..3ec0f8208973496206177421ef4aad8f1e85a4cb 100644 --- a/services/cameraservice/sinkservice/include/distributedcamera/distributed_camera_sink_stub.h +++ b/services/cameraservice/sinkservice/include/distributedcamera/distributed_camera_sink_stub.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 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 @@ -40,6 +40,10 @@ private: int32_t OpenChannelInner(MessageParcel &data, MessageParcel &reply); int32_t CloseChannelInner(MessageParcel &data, MessageParcel &reply); bool HasEnableDHPermission(); + int32_t PauseDistributedHardwareInner(MessageParcel &data, MessageParcel &reply); + int32_t ResumeDistributedHardwareInner(MessageParcel &data, MessageParcel &reply); + int32_t StopDistributedHardwareInner(MessageParcel &data, MessageParcel &reply); + bool HasAccessDHPermission(); using DCameraFunc = int32_t (DistributedCameraSinkStub::*)(MessageParcel &data, MessageParcel &reply); std::map memberFuncMap_; diff --git a/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_controller.h b/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_controller.h index 870f53a2c90e04e07f426d67177b96e239883008..beee7451019c4cd41af71c202827b1b44005bf3c 100644 --- a/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_controller.h +++ b/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_controller.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 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 @@ -26,8 +26,11 @@ #include "icamera_sink_access_control.h" #include "icamera_sink_output.h" #include - +#include +#include "device_manager.h" +#include "device_manager_callback.h" #include "property_carrier.h" +#include "idcamera_sink_callback.h" namespace OHOS { namespace DistributedHardware { @@ -36,7 +39,8 @@ class DCameraSinkController : public ICameraController, public EventSender, public DistributedHardware::EventBusHandler, public std::enable_shared_from_this { public: - explicit DCameraSinkController(std::shared_ptr& accessControl); + explicit DCameraSinkController(std::shared_ptr& accessControl, + const sptr &sinkCallback); ~DCameraSinkController() override; int32_t StartCapture(std::vector>& captureInfos) override; @@ -49,6 +53,9 @@ public: int32_t CloseChannel() override; int32_t Init(std::vector& indexs) override; int32_t UnInit() override; + int32_t PauseDistributedHardware(const std::string &networkId) override; + int32_t ResumeDistributedHardware(const std::string &networkId) override; + int32_t StopDistributedHardware(const std::string &networkId) override; void OnEvent(DCameraFrameTriggerEvent& event) override; void OnEvent(DCameraPostAuthorizationEvent& event) override; @@ -65,6 +72,9 @@ private: int32_t DCameraNotifyInner(int32_t type, int32_t result, std::string content); int32_t HandleReceivedData(std::shared_ptr& dataBuffer); void PostAuthorization(std::vector>& captureInfos); + bool CheckDeviceSecurityLevel(const std::string &srcDeviceId, const std::string &dstDeviceId); + int32_t GetDeviceSecurityLevel(const std::string &udid); + std::string GetUdidByNetworkId(const std::string &networkId); bool isInit_; int32_t sessionState_; @@ -78,11 +88,20 @@ private: std::shared_ptr operator_; std::shared_ptr accessControl_; std::shared_ptr output_; + sptr sinkCallback_; + std::atomic isPageStatus_ = false; + std::shared_ptr initCallback_; + bool isSensitive_; + bool isSameAccount_; const std::string SESSION_FLAG = "control"; const std::string SRC_TYPE = "camera"; const size_t DATABUFF_MAX_SIZE = 100 * 1024 * 1024; }; + +class DeviceInitCallback : public DmInitCallback { + void OnRemoteDied() override; +}; } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DCAMERA_SINK_CONTROLLER_H \ No newline at end of file diff --git a/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_dev.h b/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_dev.h index 79721f537984d6b144ee1fd0b882a0ab106c14b1..8d6c15fd6b02173dac9389f17f960f58069658a1 100644 --- a/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_dev.h +++ b/services/cameraservice/sinkservice/include/distributedcameramgr/dcamera_sink_dev.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 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 @@ -22,12 +22,13 @@ #include "icamera_controller.h" #include "icamera_sink_access_control.h" +#include "idcamera_sink_callback.h" namespace OHOS { namespace DistributedHardware { class DCameraSinkDev { public: - explicit DCameraSinkDev(const std::string& dhId); + explicit DCameraSinkDev(const std::string& dhId, const sptr &sinkCallback); ~DCameraSinkDev(); int32_t Init(); @@ -40,12 +41,16 @@ public: int32_t OpenChannel(std::string& openInfo); int32_t CloseChannel(); std::string GetDhid(); + int32_t PauseDistributedHardware(const std::string &networkId); + int32_t ResumeDistributedHardware(const std::string &networkId); + int32_t StopDistributedHardware(const std::string &networkId); private: bool isInit_; std::string dhId_; std::shared_ptr controller_; std::shared_ptr accessControl_; + sptr sinkCallback_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/cameraservice/sinkservice/src/distributedcamera/dcamera_sink_callback_proxy.cpp b/services/cameraservice/sinkservice/src/distributedcamera/dcamera_sink_callback_proxy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c3f3aac4a1f833d5187f0f5992132ad2f17b486a --- /dev/null +++ b/services/cameraservice/sinkservice/src/distributedcamera/dcamera_sink_callback_proxy.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2023 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 "dcamera_sink_callback_proxy.h" + +#include "parcel.h" + +#include "anonymous_string.h" +#include "distributed_camera_errno.h" +#include "distributed_hardware_log.h" + +namespace OHOS { +namespace DistributedHardware { +int32_t DCameraSinkCallbackProxy::OnNotifyResourceInfo(const ResourceEventType &type, const std::string &subtype, + const std::string &networkId, bool &isSensitive, bool &isSameAccout) +{ + sptr remote = Remote(); + if (remote == nullptr) { + DHLOGE("DCameraSinkCallbackProxy remote service null"); + return DCAMERA_BAD_VALUE; + } + MessageParcel req; + MessageParcel reply; + MessageOption option; + if (!req.WriteInterfaceToken(DCameraSinkCallbackProxy::GetDescriptor())) { + DHLOGE("write token failed"); + return DCAMERA_BAD_VALUE; + } + + int32_t resType = static_cast(type); + if (!req.WriteInt32(resType) || !req.WriteString(subtype) || !req.WriteString(networkId)) { + DHLOGE("DCameraSinkCallbackProxy InitSink write params failed"); + return DCAMERA_BAD_VALUE; + } + remote->SendRequest(NOTIFY_RESOURCEINFO, req, reply, option); + int32_t result = reply.ReadInt32(); + isSensitive = reply.ReadBool(); + isSameAccout = reply.ReadBool(); + return result; +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/services/cameraservice/sinkservice/src/distributedcamera/distributed_camera_sink_service.cpp b/services/cameraservice/sinkservice/src/distributedcamera/distributed_camera_sink_service.cpp index 54aec91c87ceea643cb7a08c68911a2cc73f444d..5010c572044704516b103f7ebc09c50f3f21f67f 100644 --- a/services/cameraservice/sinkservice/src/distributedcamera/distributed_camera_sink_service.cpp +++ b/services/cameraservice/sinkservice/src/distributedcamera/distributed_camera_sink_service.cpp @@ -15,6 +15,7 @@ #include "distributed_camera_sink_service.h" +#include "icamera_channel_listener.h" #include "if_system_ability_manager.h" #include "ipc_skeleton.h" #include "ipc_types.h" @@ -81,7 +82,8 @@ void DistributedCameraSinkService::OnStop() DCameraSinkServiceIpc::GetInstance().UnInit(); } -int32_t DistributedCameraSinkService::InitSink(const std::string& params) +int32_t DistributedCameraSinkService::InitSink(const std::string& params, + const sptr &sinkCallback) { DHLOGI("start"); sinkVer_ = params; @@ -99,7 +101,7 @@ int32_t DistributedCameraSinkService::InitSink(const std::string& params) } g_camDump.camNumber = static_cast(cameras.size()); for (auto& dhId : cameras) { - std::shared_ptr sinkDevice = std::make_shared(dhId); + std::shared_ptr sinkDevice = std::make_shared(dhId, sinkCallback); ret = sinkDevice->Init(); if (ret != DCAMERA_OK) { DHLOGE("sink device init failed, ret: %d", ret); @@ -350,5 +352,92 @@ void DistributedCameraSinkService::GetCamDumpInfo(CameraDumpInfo& camDump) dcSinkService->GetCamIds(); camDump = g_camDump; } + +bool DistributedCameraSinkService::IsCurSinkDev(std::shared_ptr sinkDevice) +{ + std::string camInfoJson; + int32_t ret = sinkDevice->GetCameraInfo(camInfoJson); + if (ret != DCAMERA_OK) { + DHLOGE("GetCameraInfo failed, ret: %d", ret); + return false; + } + DCameraInfoCmd cmd; + ret = cmd.Unmarshal(camInfoJson); + if (ret != DCAMERA_OK) { + DHLOGE("DCameraInfoCmd Unmarshal failed: %d", ret); + return false; + } + std::shared_ptr camInfo = cmd.value_; + if (camInfo->state_ == DCAMERA_CHANNEL_STATE_CONNECTED) { + return true; + } + return false; +} + +int32_t DistributedCameraSinkService::PauseDistributedHardware(const std::string &networkId) +{ + DHLOGI("start."); + std::shared_ptr sinkDevice = nullptr; + { + std::lock_guard lock(mapMutex_); + for (auto iter = camerasMap_.begin(); iter != camerasMap_.end(); iter++) { + if (IsCurSinkDev(iter->second)) { + sinkDevice = iter->second; + } + } + } + + int32_t ret = sinkDevice->PauseDistributedHardware(networkId); + if (ret != DCAMERA_OK) { + DHLOGE("PauseDistributedHardware failed, ret: %d", ret); + return ret; + } + DHLOGI("PauseDistributedHardware success"); + return DCAMERA_OK; +} + +int32_t DistributedCameraSinkService::ResumeDistributedHardware(const std::string &networkId) +{ + DHLOGI("start."); + std::shared_ptr sinkDevice = nullptr; + { + std::lock_guard lock(mapMutex_); + for (auto iter = camerasMap_.begin(); iter != camerasMap_.end(); iter++) { + if (IsCurSinkDev(iter->second)) { + sinkDevice = iter->second; + } + } + } + + int32_t ret = sinkDevice->ResumeDistributedHardware(networkId); + if (ret != DCAMERA_OK) { + DHLOGE("ResumeDistributedHardware failed, ret: %d", ret); + return ret; + } + DHLOGI("ResumeDistributedHardware success"); + return DCAMERA_OK; +} + +int32_t DistributedCameraSinkService::StopDistributedHardware(const std::string &networkId) +{ + DHLOGI("start."); + std::shared_ptr sinkDevice = nullptr; + { + std::lock_guard lock(mapMutex_); + for (auto iter = camerasMap_.begin(); iter != camerasMap_.end(); iter++) { + if (IsCurSinkDev(iter->second)) { + sinkDevice = iter->second; + } + } + } + + int32_t ret = sinkDevice->StopDistributedHardware(networkId); + if (ret != DCAMERA_OK) { + DHLOGE("StopDistributedHardware failed, ret: %d", ret); + return ret; + } + DHLOGI("StopDistributedHardware success"); + return DCAMERA_OK; +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/cameraservice/sinkservice/src/distributedcamera/distributed_camera_sink_stub.cpp b/services/cameraservice/sinkservice/src/distributedcamera/distributed_camera_sink_stub.cpp index 6be1688afff477c4f64606fa41fcee84ab94d496..4b6058ee7c58fc8e8467c4ab29b52f0d2edf6a6d 100644 --- a/services/cameraservice/sinkservice/src/distributedcamera/distributed_camera_sink_stub.cpp +++ b/services/cameraservice/sinkservice/src/distributedcamera/distributed_camera_sink_stub.cpp @@ -19,6 +19,7 @@ #include "distributed_camera_errno.h" #include "distributed_hardware_log.h" #include "ipc_skeleton.h" +#include "dcamera_sink_callback_proxy.h" namespace OHOS { namespace DistributedHardware { @@ -42,6 +43,12 @@ DistributedCameraSinkStub::DistributedCameraSinkStub() &DistributedCameraSinkStub::OpenChannelInner; memberFuncMap_[static_cast(IDCameraSinkInterfaceCode::CLOSE_CHANNEL)] = &DistributedCameraSinkStub::CloseChannelInner; + memberFuncMap_[static_cast(IDCameraSinkInterfaceCode::PAUSE_DISTRIBUTED_HARDWARE)] = + &DistributedCameraSinkStub::PauseDistributedHardwareInner; + memberFuncMap_[static_cast(IDCameraSinkInterfaceCode::RESUME_DISTRIBUTED_HARDWARE)] = + &DistributedCameraSinkStub::ResumeDistributedHardwareInner; + memberFuncMap_[static_cast(IDCameraSinkInterfaceCode::STOP_DISTRIBUTED_HARDWARE)] = + &DistributedCameraSinkStub::StopDistributedHardwareInner; } DistributedCameraSinkStub::~DistributedCameraSinkStub() @@ -91,7 +98,15 @@ int32_t DistributedCameraSinkStub::InitSinkInner(MessageParcel &data, MessagePar ret = DCAMERA_BAD_VALUE; break; } - ret = InitSink(params); + sptr remoteObject = data.ReadRemoteObject(); + if (remoteObject == nullptr) { + DHLOGE("Read ReadRemoteObject failed."); + ret = DCAMERA_BAD_VALUE; + break; + } + + sptr dCameraSinkCallbackProxy(new DCameraSinkCallbackProxy(remoteObject)); + ret = InitSink(params, dCameraSinkCallbackProxy); } while (0); reply.WriteInt32(ret); return DCAMERA_OK; @@ -238,5 +253,80 @@ int32_t DistributedCameraSinkStub::CloseChannelInner(MessageParcel &data, Messag reply.WriteInt32(ret); return DCAMERA_OK; } + +bool DistributedCameraSinkStub::HasAccessDHPermission() +{ + Security::AccessToken::AccessTokenID callerToken = IPCSkeleton::GetCallingTokenID(); + const std::string permissionName = "ohos.permission.ACCESS_DISTRIBUTED_HARDWARE"; + int32_t result = Security::AccessToken::AccessTokenKit::VerifyAccessToken(callerToken, + permissionName); + return (result == Security::AccessToken::PERMISSION_GRANTED); +} + +int32_t DistributedCameraSinkStub::PauseDistributedHardwareInner(MessageParcel &data, MessageParcel &reply) +{ + DHLOGD("enter"); + int32_t ret = DCAMERA_OK; + do { + if (!HasAccessDHPermission()) { + DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); + ret = DCAMERA_BAD_VALUE; + break; + } + std::string networkId = data.ReadString(); + if (networkId.empty() || networkId.size() > DID_MAX_SIZE) { + DHLOGE("params is invalid"); + ret = DCAMERA_BAD_VALUE; + break; + } + ret = PauseDistributedHardware(networkId); + } while (0); + reply.WriteInt32(ret); + return DCAMERA_OK; +} + +int32_t DistributedCameraSinkStub::ResumeDistributedHardwareInner(MessageParcel &data, MessageParcel &reply) +{ + DHLOGD("enter"); + int32_t ret = DCAMERA_OK; + do { + if (!HasAccessDHPermission()) { + DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); + ret = DCAMERA_BAD_VALUE; + break; + } + std::string networkId = data.ReadString(); + if (networkId.empty() || networkId.size() > DID_MAX_SIZE) { + DHLOGE("params is invalid"); + ret = DCAMERA_BAD_VALUE; + break; + } + ret = ResumeDistributedHardware(networkId); + } while (0); + reply.WriteInt32(ret); + return DCAMERA_OK; +} + +int32_t DistributedCameraSinkStub::StopDistributedHardwareInner(MessageParcel &data, MessageParcel &reply) +{ + DHLOGD("enter"); + int32_t ret = DCAMERA_OK; + do { + if (!HasAccessDHPermission()) { + DHLOGE("The caller has no ACCESS_DISTRIBUTED_HARDWARE permission."); + ret = DCAMERA_BAD_VALUE; + break; + } + std::string networkId = data.ReadString(); + if (networkId.empty() || networkId.size() > DID_MAX_SIZE) { + DHLOGE("params is invalid"); + ret = DCAMERA_BAD_VALUE; + break; + } + ret = StopDistributedHardware(networkId); + } while (0); + reply.WriteInt32(ret); + return DCAMERA_OK; +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_controller.cpp b/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_controller.cpp index e31473f71f8830ba1c677619327ebdfe9e09375c..a97b7cec9baf221a59fd3eda51ba0a42ed7a6d37 100644 --- a/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_controller.cpp +++ b/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_controller.cpp @@ -34,6 +34,8 @@ #include "distributed_camera_constants.h" #include "distributed_camera_errno.h" #include "distributed_hardware_log.h" +#include "device_security_defines.h" +#include "device_security_info.h" #include "idistributed_camera_source.h" #include "json/json.h" #include "dcamera_low_latency.h" @@ -41,8 +43,12 @@ namespace OHOS { namespace DistributedHardware { -DCameraSinkController::DCameraSinkController(std::shared_ptr& accessControl) - : isInit_(false), sessionState_(DCAMERA_CHANNEL_STATE_DISCONNECTED), accessControl_(accessControl) +const int DEFAULT_DEVICE_SECURITY_LEVEL = -1; + +DCameraSinkController::DCameraSinkController(std::shared_ptr& accessControl, + const sptr &sinkCallback) + : isInit_(false), sessionState_(DCAMERA_CHANNEL_STATE_DISCONNECTED), accessControl_(accessControl), + sinkCallback_(sinkCallback) { } @@ -93,7 +99,17 @@ int32_t DCameraSinkController::StopCapture() DCameraNotifyInner(DCAMERA_MESSAGE, DCAMERA_EVENT_DEVICE_ERROR, std::string("output stop capture failed")); return ret; } - + if (isPageStatus_.load()) { + std::string subtype = "camera"; + bool isSensitive = false; + bool isSameAccout = false; + ret = sinkCallback_->OnNotifyResourceInfo(ResourceEventType::EVENT_TYPE_CLOSE_PAGE, subtype, srcDevId_, + isSensitive, isSameAccout); + if (ret != DCAMERA_OK) { + DHLOGE("close page failed, ret: %d", ret); + } + } + isPageStatus_.store(false); DHLOGI("StopCapture %s success", GetAnonyString(dhId_).c_str()); return DCAMERA_OK; } @@ -185,14 +201,37 @@ int32_t DCameraSinkController::OpenChannel(std::shared_ptr& ope DHLOGE("wrong state, dhId: %s, sessionState: %d", GetAnonyString(dhId_).c_str(), sessionState_); return DCAMERA_WRONG_STATE; } - DCameraLowLatency::GetInstance().EnableLowLatency(); srcDevId_ = openInfo->sourceDevId_; + std::string subtype = "camera"; + int32_t ret = sinkCallback_->OnNotifyResourceInfo(ResourceEventType::EVENT_TYPE_QUERY_RESOURCE, subtype, srcDevId_, + isSensitive_, isSameAccount_); + if (ret != DCAMERA_OK) { + DHLOGE("Query resource failed, ret: %d", ret); + return ret; + } + DHLOGI("OpenChannel isSensitive: %d, isSameAccout: %d", isSensitive_, isSameAccount_); + if (isSensitive_ && !isSameAccount_) { + DHLOGE("Privacy resource must be logged in with the same account."); + return DCAMERA_BAD_VALUE; + } + + std::string sinkDevId; + ret = GetLocalDeviceNetworkId(sinkDevId); + if (ret != DCAMERA_OK) { + DHLOGE("GetLocalDeviceNetworkId failed, ret: %d", ret); + return ret; + } + if (isSensitive_ && !CheckDeviceSecurityLevel(srcDevId_, sinkDevId)) { + DHLOGE("Check device security level failed!"); + return DCAMERA_BAD_VALUE; + } + DCameraLowLatency::GetInstance().EnableLowLatency(); std::vector indexs; indexs.push_back(DCameraIndex(srcDevId_, dhId_)); auto controller = std::shared_ptr(shared_from_this()); std::shared_ptr listener = std::make_shared(controller); - int32_t ret = channel_->CreateSession(indexs, SESSION_FLAG, DCAMERA_SESSION_MODE_CTRL, listener); + ret = channel_->CreateSession(indexs, SESSION_FLAG, DCAMERA_SESSION_MODE_CTRL, listener); if (ret != DCAMERA_OK) { DHLOGE("channel create session failed, dhId: %s, ret: %d", GetAnonyString(dhId_).c_str(), ret); return ret; @@ -253,6 +292,7 @@ int32_t DCameraSinkController::Init(std::vector& indexs) eventBus_->AddHandler(authEvent.GetType(), *this); isInit_ = true; + initCallback_ = std::make_shared(); DHLOGI("DCameraSinkController Init %s success", GetAnonyString(dhId_).c_str()); return DCAMERA_OK; } @@ -441,6 +481,18 @@ int32_t DCameraSinkController::StartCaptureInner(std::vectorOnNotifyResourceInfo(ResourceEventType::EVENT_TYPE_PULL_UP_PAGE, subtype, srcDevId_, + isSensitive, isSameAccout); + if (ret != DCAMERA_OK) { + DHLOGE("pull up page failed, ret %d", ret); + return ret; + } + isPageStatus_.store(true); + } DHLOGI("DCameraSinkController::StartCaptureInner %s success", GetAnonyString(dhId_).c_str()); return DCAMERA_OK; } @@ -496,5 +548,125 @@ int32_t DCameraSinkController::HandleReceivedData(std::shared_ptr& d } return DCAMERA_BAD_VALUE; } + +int32_t DCameraSinkController::PauseDistributedHardware(const std::string &networkId) +{ + DHLOGI("Pause distributed hardware dhId: %s", GetAnonyString(dhId_).c_str()); + if (networkId.empty()) { + DHLOGE("networkId is empty"); + return DCAMERA_BAD_VALUE; + } + int32_t ret = operator_->PauseCapture(); + if (ret != DCAMERA_OK) { + DHLOGE("Pause distributed hardware failed, dhId: %s, ret: %d", GetAnonyString(dhId_).c_str(), ret); + } + return ret; +} + +int32_t DCameraSinkController::ResumeDistributedHardware(const std::string &networkId) +{ + DHLOGI("Resume distributed hardware dhId: %s", GetAnonyString(dhId_).c_str()); + if (networkId.empty()) { + DHLOGE("networkId is empty"); + return DCAMERA_BAD_VALUE; + } + int32_t ret = operator_->ResumeCapture(); + if (ret != DCAMERA_OK) { + DHLOGE("Resume distributed hardware failed, dhId: %s, ret: %d", GetAnonyString(dhId_).c_str(), ret); + } + return ret; +} + +int32_t DCameraSinkController::StopDistributedHardware(const std::string &networkId) +{ + DHLOGI("Stop distributed hardware dhId: %s", GetAnonyString(dhId_).c_str()); + if (networkId.empty()) { + DHLOGE("networkId is empty"); + return DCAMERA_BAD_VALUE; + } + + isPageStatus_.store(false); + return DCameraNotifyInner(DCAMERA_SINK_STOP, DCAMERA_EVENT_SINK_STOP, std::string("sink stop dcamera business")); +} + +bool DCameraSinkController::CheckDeviceSecurityLevel(const std::string &srcDeviceId, const std::string &dstDeviceId) +{ + DHLOGD("CheckDeviceSecurityLevel srcDeviceId %s, dstDeviceId %s.", srcDeviceId.c_str(), dstDeviceId.c_str()); + std::string srcUdid = GetUdidByNetworkId(srcDeviceId); + if (srcUdid.empty()) { + DHLOGE("src udid is empty"); + return false; + } + std::string dstUdid = GetUdidByNetworkId(dstDeviceId); + if (dstUdid.empty()) { + DHLOGE("dst udid is empty"); + return false; + } + DHLOGD("CheckDeviceSecurityLevel srcUdid %s, dstUdid %s.", srcUdid.c_str(), dstUdid.c_str()); + int32_t srcDeviceSecurityLevel = GetDeviceSecurityLevel(srcUdid); + int32_t dstDeviceSecurityLevel = GetDeviceSecurityLevel(dstUdid); + DHLOGI("srcDeviceSecurityLevel is %d, dstDeviceSecurityLevel is %d.", + srcDeviceSecurityLevel, dstDeviceSecurityLevel); + if (srcDeviceSecurityLevel == DEFAULT_DEVICE_SECURITY_LEVEL || + srcDeviceSecurityLevel < dstDeviceSecurityLevel) { + DHLOGE("The device security of source device is lower."); + return false; + } + return true; +} + +int32_t DCameraSinkController::GetDeviceSecurityLevel(const std::string &udid) +{ + DeviceIdentify devIdentify; + devIdentify.length = DEVICE_ID_MAX_LEN; + int32_t ret = memcpy_s(devIdentify.identity, DEVICE_ID_MAX_LEN, udid.c_str(), DEVICE_ID_MAX_LEN); + if (ret != 0) { + DHLOGE("str copy failed %d", ret); + return DEFAULT_DEVICE_SECURITY_LEVEL; + } + DeviceSecurityInfo *info = nullptr; + ret = RequestDeviceSecurityInfo(&devIdentify, nullptr, &info); + if (ret != SUCCESS) { + DHLOGE("Request device security info failed %d", ret); + FreeDeviceSecurityInfo(info); + info = nullptr; + return DEFAULT_DEVICE_SECURITY_LEVEL; + } + int32_t level = 0; + ret = GetDeviceSecurityLevelValue(info, &level); + DHLOGD("Get device security level, level is %d", level); + FreeDeviceSecurityInfo(info); + info = nullptr; + if (ret != SUCCESS) { + DHLOGE("Get device security level failed %d", ret); + return DEFAULT_DEVICE_SECURITY_LEVEL; + } + return level; +} + +std::string DCameraSinkController::GetUdidByNetworkId(const std::string &networkId) +{ + if (networkId.empty()) { + DHLOGE("networkId is empty!"); + return ""; + } + int32_t ret = DeviceManager::GetInstance().InitDeviceManager(DCAMERA_PKG_NAME, initCallback_); + if (ret != DCAMERA_OK) { + DHLOGE("InitDeviceManager failed ret = %d", ret); + return ""; + } + std::string udid = ""; + ret = DeviceManager::GetInstance().GetUdidByNetworkId(DCAMERA_PKG_NAME, networkId, udid); + if (ret != DCAMERA_OK) { + DHLOGE("GetUdidByNetworkId failed ret = %d", ret); + return ""; + } + return udid; +} + +void DeviceInitCallback::OnRemoteDied() +{ + DHLOGI("DeviceInitCallback OnRemoteDied"); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_dev.cpp b/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_dev.cpp index 01eaa305085a2271d2074534195fe04601e53091..ade1ba42deb5fc46996614944bcf70eeda61b8f8 100644 --- a/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_dev.cpp +++ b/services/cameraservice/sinkservice/src/distributedcameramgr/dcamera_sink_dev.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 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 @@ -26,7 +26,8 @@ namespace OHOS { namespace DistributedHardware { -DCameraSinkDev::DCameraSinkDev(const std::string& dhId) : dhId_(dhId) +DCameraSinkDev::DCameraSinkDev(const std::string& dhId, const sptr &sinkCallback) + : dhId_(dhId), sinkCallback_(sinkCallback) { DHLOGI("DCameraSinkDev Constructor dhId: %s", GetAnonyString(dhId_).c_str()); isInit_ = false; @@ -43,7 +44,7 @@ int32_t DCameraSinkDev::Init() { DHLOGI("Init dhId: %s", GetAnonyString(dhId_).c_str()); accessControl_ = std::make_shared(); - controller_ = std::make_shared(accessControl_); + controller_ = std::make_shared(accessControl_, sinkCallback_); DCameraIndex index("", dhId_); std::vector indexs; indexs.push_back(index); @@ -159,5 +160,38 @@ std::string DCameraSinkDev::GetDhid() { return GetAnonyString(dhId_); } + +int32_t DCameraSinkDev::PauseDistributedHardware(const std::string &networkId) +{ + DHLOGI("Pause distributed hardware dhId: %s", GetAnonyString(dhId_).c_str()); + if (networkId.empty()) { + DHLOGE("networkId is empty"); + return DCAMERA_BAD_VALUE; + } + + return controller_->PauseDistributedHardware(networkId); +} + +int32_t DCameraSinkDev::ResumeDistributedHardware(const std::string &networkId) +{ + DHLOGI("Resume distributed hardware dhId: %s", GetAnonyString(dhId_).c_str()); + if (networkId.empty()) { + DHLOGE("networkId is empty"); + return DCAMERA_BAD_VALUE; + } + + return controller_->ResumeDistributedHardware(networkId); +} + +int32_t DCameraSinkDev::StopDistributedHardware(const std::string &networkId) +{ + DHLOGI("Stop distributed hardware dhId: %s", GetAnonyString(dhId_).c_str()); + if (networkId.empty()) { + DHLOGE("networkId is empty"); + return DCAMERA_BAD_VALUE; + } + + return controller_->StopDistributedHardware(networkId); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/BUILD.gn b/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/BUILD.gn index 7ba21cc673f1eb3843bebc4478cce485bff0bca5..52a57b128a460554c4da3fecc626d7d9393648fb 100644 --- a/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/BUILD.gn +++ b/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/BUILD.gn @@ -38,11 +38,18 @@ config("module_private_config") { "${common_path}/include/utils", "${fwk_common_path}/utils/include", "${innerkits_path}/native_cpp/camera_sink/include", + "${innerkits_path}/native_cpp/camera_sink/include/callback", "${services_path}/cameraservice/base/include", + "${services_path}/cameraservice/cameraoperator/client/include", "${services_path}/cameraservice/cameraoperator/handler/include", "${services_path}/cameraservice/sinkservice/include/distributedcamera", "${services_path}/cameraservice/sinkservice/include/distributedcameramgr", "${services_path}/cameraservice/sinkservice/include/distributedcameramgr/interface", + "${services_path}/cameraservice/sinkservice/include/distributedcameramgr/eventbus", + "${services_path}/data_process/include/eventbus", + "${services_path}/channel/include", + "${fwk_utils_path}/include/eventbus", + "${feeding_smoother_path}/base", ] } diff --git a/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/distributed_camera_sink_service_test.cpp b/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/distributed_camera_sink_service_test.cpp index 38c28aa8e9ae6834278dbc7b2727b629c6597f38..375737534e18cff1a02002548f7e2a0ec5870ae9 100644 --- a/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/distributed_camera_sink_service_test.cpp +++ b/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/distributed_camera_sink_service_test.cpp @@ -19,6 +19,7 @@ #define private public #include "distributed_camera_sink_service.h" #undef private +#include "dcamera_sink_callback.h" #include "distributed_camera_errno.h" #include "distributed_hardware_log.h" #include "idistributed_camera_sink.h" @@ -89,7 +90,8 @@ HWTEST_F(DistributedCameraSinkServiceTest, dcamera_sink_service_test_001, TestSi DHLOGI("dcamera_sink_service_test_001"); EXPECT_EQ(sinkService_ == nullptr, false); - int32_t ret = sinkService_->InitSink(g_testParams); + sptr sinkCallback(new DCameraSinkCallback()); + int32_t ret = sinkService_->InitSink(g_testParams, sinkCallback); EXPECT_EQ(DCAMERA_OK, ret); ret = sinkService_->SubscribeLocalHardware(g_dhId, g_testParams); @@ -110,7 +112,8 @@ HWTEST_F(DistributedCameraSinkServiceTest, dcamera_sink_service_test_002, TestSi DHLOGI("dcamera_sink_service_test_002"); EXPECT_EQ(sinkService_ == nullptr, false); - int32_t ret = sinkService_->InitSink(g_testParams); + sptr sinkCallback(new DCameraSinkCallback()); + int32_t ret = sinkService_->InitSink(g_testParams, sinkCallback); EXPECT_EQ(DCAMERA_OK, ret); ret = sinkService_->UnsubscribeLocalHardware(g_dhId); @@ -131,7 +134,8 @@ HWTEST_F(DistributedCameraSinkServiceTest, dcamera_sink_service_test_003, TestSi DHLOGI("dcamera_sink_service_test_003"); EXPECT_EQ(sinkService_ == nullptr, false); - int32_t ret = sinkService_->InitSink(g_testParams); + sptr sinkCallback(new DCameraSinkCallback()); + int32_t ret = sinkService_->InitSink(g_testParams, sinkCallback); EXPECT_EQ(DCAMERA_OK, ret); ret = sinkService_->StopCapture(g_dhId); @@ -152,7 +156,8 @@ HWTEST_F(DistributedCameraSinkServiceTest, dcamera_sink_service_test_004, TestSi DHLOGI("dcamera_sink_service_test_004"); EXPECT_EQ(sinkService_ == nullptr, false); - int32_t ret = sinkService_->InitSink(g_testParams); + sptr sinkCallback(new DCameraSinkCallback()); + int32_t ret = sinkService_->InitSink(g_testParams, sinkCallback); EXPECT_EQ(DCAMERA_OK, ret); ret = sinkService_->ChannelNeg(g_dhId, g_testChannelInfoContinue); @@ -173,7 +178,8 @@ HWTEST_F(DistributedCameraSinkServiceTest, dcamera_sink_service_test_005, TestSi DHLOGI("dcamera_sink_service_test_005"); EXPECT_EQ(sinkService_ == nullptr, false); - int32_t ret = sinkService_->InitSink(g_testParams); + sptr sinkCallback(new DCameraSinkCallback()); + int32_t ret = sinkService_->InitSink(g_testParams, sinkCallback); EXPECT_EQ(DCAMERA_OK, ret); ret = sinkService_->GetCameraInfo(g_dhId, g_testCameraInfo); @@ -194,7 +200,8 @@ HWTEST_F(DistributedCameraSinkServiceTest, dcamera_sink_service_test_006, TestSi DHLOGI("dcamera_sink_service_test_006"); EXPECT_EQ(sinkService_ == nullptr, false); - int32_t ret = sinkService_->InitSink(g_testParams); + sptr sinkCallback(new DCameraSinkCallback()); + int32_t ret = sinkService_->InitSink(g_testParams, sinkCallback); EXPECT_EQ(DCAMERA_OK, ret); ret = sinkService_->OpenChannel(g_dhId, g_testOpenInfoService); @@ -239,7 +246,8 @@ HWTEST_F(DistributedCameraSinkServiceTest, dcamera_sink_service_test_008, TestSi DHLOGI("dcamera_sink_service_test_008"); EXPECT_EQ(sinkService_ == nullptr, false); - int32_t ret = sinkService_->InitSink(g_testParams); + sptr sinkCallback(new DCameraSinkCallback()); + int32_t ret = sinkService_->InitSink(g_testParams, sinkCallback); EXPECT_EQ(DCAMERA_OK, ret); ret = sinkService_->SubscribeLocalHardware("", g_testParams); @@ -260,7 +268,8 @@ HWTEST_F(DistributedCameraSinkServiceTest, dcamera_sink_service_test_009, TestSi DHLOGI("dcamera_sink_service_test_009"); EXPECT_EQ(sinkService_ == nullptr, false); - int32_t ret = sinkService_->InitSink(g_testParams); + sptr sinkCallback(new DCameraSinkCallback()); + int32_t ret = sinkService_->InitSink(g_testParams, sinkCallback); EXPECT_EQ(DCAMERA_OK, ret); ret = sinkService_->UnsubscribeLocalHardware(""); @@ -280,7 +289,8 @@ HWTEST_F(DistributedCameraSinkServiceTest, dcamera_sink_service_test_010, TestSi DHLOGI("dcamera_sink_service_test_010"); EXPECT_EQ(sinkService_ == nullptr, false); - int32_t ret = sinkService_->InitSink(g_testParams); + sptr sinkCallback(new DCameraSinkCallback()); + int32_t ret = sinkService_->InitSink(g_testParams, sinkCallback); EXPECT_EQ(DCAMERA_OK, ret); ret = sinkService_->ChannelNeg("", g_testChannelInfoContinue); @@ -300,7 +310,8 @@ HWTEST_F(DistributedCameraSinkServiceTest, dcamera_sink_service_test_011, TestSi DHLOGI("dcamera_sink_service_test_011"); EXPECT_EQ(sinkService_ == nullptr, false); - int32_t ret = sinkService_->InitSink(g_testParams); + sptr sinkCallback(new DCameraSinkCallback()); + int32_t ret = sinkService_->InitSink(g_testParams, sinkCallback); EXPECT_EQ(DCAMERA_OK, ret); ret = sinkService_->GetCameraInfo("", g_testCameraInfo); @@ -320,7 +331,8 @@ HWTEST_F(DistributedCameraSinkServiceTest, dcamera_sink_service_test_012, TestSi DHLOGI("dcamera_sink_service_test_012"); EXPECT_EQ(sinkService_ == nullptr, false); - int32_t ret = sinkService_->InitSink(g_testParams); + sptr sinkCallback(new DCameraSinkCallback()); + int32_t ret = sinkService_->InitSink(g_testParams, sinkCallback); EXPECT_EQ(DCAMERA_OK, ret); ret = sinkService_->OpenChannel("", g_testOpenInfoService); @@ -361,7 +373,8 @@ HWTEST_F(DistributedCameraSinkServiceTest, dcamera_sink_service_test_014, TestSi DHLOGI("dcamera_sink_service_test_014"); EXPECT_EQ(sinkService_ == nullptr, false); - int32_t ret = sinkService_->InitSink(g_testParams); + sptr sinkCallback(new DCameraSinkCallback()); + int32_t ret = sinkService_->InitSink(g_testParams, sinkCallback); EXPECT_EQ(DCAMERA_OK, ret); ret = sinkService_->StopCapture(""); diff --git a/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/distributed_camera_sink_stub_test.cpp b/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/distributed_camera_sink_stub_test.cpp index 587473305025ab12120a7fc735e54f845ba85a6a..f39b2f7683f905ce35464dd205a4870c928ff656 100644 --- a/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/distributed_camera_sink_stub_test.cpp +++ b/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/distributed_camera_sink_stub_test.cpp @@ -15,6 +15,7 @@ #include +#include "dcamera_sink_callback.h" #include "distributed_camera_sink_proxy.h" #include "distributed_camera_sink_stub.h" #include "distributed_hardware_log.h" @@ -61,10 +62,11 @@ void DcameraSinkStubTest::TearDown(void) HWTEST_F(DcameraSinkStubTest, dcamera_sink_stub_test_001, TestSize.Level1) { DHLOGI("dcamera_sink_stub_test_001"); + sptr sinkCallback(new DCameraSinkCallback()); sptr sinkStubPtr(new MockDistributedCameraSinkStub()); DistributedCameraSinkProxy sinkProxy(sinkStubPtr); std::string params = "params000"; - int32_t ret = sinkProxy.InitSink(params); + int32_t ret = sinkProxy.InitSink(params, sinkCallback); EXPECT_EQ(DCAMERA_OK, ret); } diff --git a/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/mock_distributed_camera_sink_stub.h b/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/mock_distributed_camera_sink_stub.h index 02220306919d033601c2b98294ac2fb9e339001a..3951fbed17a025efffb206ca763247b01ebcf80c 100644 --- a/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/mock_distributed_camera_sink_stub.h +++ b/services/cameraservice/sinkservice/test/unittest/common/distributedcamera/mock_distributed_camera_sink_stub.h @@ -25,9 +25,10 @@ class MockDistributedCameraSinkStub : public DistributedCameraSinkStub { public: MockDistributedCameraSinkStub() = default; virtual ~MockDistributedCameraSinkStub() = default; - int32_t InitSink(const std::string ¶ms) + int32_t InitSink(const std::string ¶ms, const sptr &sinkCallback) { (void)params; + (void)sinkCallback; return DCAMERA_OK; } @@ -81,9 +82,25 @@ public: (void)dhId; return DCAMERA_OK; } -}; + int32_t PauseDistributedHardware(const std::string &networkId) + { + (void)networkId; + return DCAMERA_OK; + } + + int32_t ResumeDistributedHardware(const std::string &networkId) + { + (void)networkId; + return DCAMERA_OK; + } + int32_t StopDistributedHardware(const std::string &networkId) + { + (void)networkId; + return DCAMERA_OK; + } +}; } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_MOCK_DISTRIBUTED_CAMERA_SINK_STUB_H \ No newline at end of file diff --git a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/BUILD.gn b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/BUILD.gn index 1e5933c89c1f2d0085c4551d9f27741197926dac..018c1286714bada68c1d889acf628bb89f13de1a 100644 --- a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/BUILD.gn +++ b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/BUILD.gn @@ -45,6 +45,7 @@ config("module_private_config") { "${common_path}/include/utils", "${innerkits_path}/native_cpp/camera_source/include", "${innerkits_path}/native_cpp/camera_source/include/callback", + "${innerkits_path}/native_cpp/camera_sink/include/callback", "${fwk_common_path}/utils/include", "${fwk_utils_path}/include/eventbus", @@ -76,6 +77,7 @@ ohos_unittest("DCameraSinkMgrTest") { "${camerastandard_path}/frameworks/native/camera:camera_framework", "${common_path}:distributed_camera_utils", "${graphicstandard_path}:libsurface", + "${innerkits_path}/native_cpp/camera_sink:distributed_camera_sink_sdk", "${services_path}/cameraservice/cameraoperator/handler:distributed_camera_handler", "${services_path}/cameraservice/sinkservice:distributed_camera_sink", "${services_path}/channel:distributed_camera_channel", @@ -86,6 +88,7 @@ ohos_unittest("DCameraSinkMgrTest") { external_deps = [ "av_codec:av_codec_client", "c_utils:utils", + "device_manager:devicemanagersdk", "drivers_interface_camera:metadata", "drivers_interface_distributed_camera:libdistributed_camera_provider_proxy_1.0", "drivers_peripheral_display:hdi_gralloc_client", diff --git a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_controller_test.cpp b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_controller_test.cpp index 7f0681cb5e1efe3d5dfc4a9a7e03045fa648a43a..ce5766ac5a9ecefbaac9d9dfe45b3ffd9aa36c02 100644 --- a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_controller_test.cpp +++ b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_controller_test.cpp @@ -25,7 +25,7 @@ #include "mock_camera_channel.h" #include "mock_camera_operator.h" #include "mock_dcamera_sink_output.h" - +#include "dcamera_sink_callback.h" #include "dcamera_handler.h" #include "dcamera_metadata_setting_cmd.h" #include "dcamera_sink_access_control.h" @@ -122,7 +122,8 @@ void DCameraSinkControllerTest::TearDownTestCase(void) void DCameraSinkControllerTest::SetUp(void) { accessControl_ = std::make_shared(); - controller_ = std::make_shared(accessControl_); + sptr sinkCallback(new DCameraSinkCallback()); + controller_ = std::make_shared(accessControl_, sinkCallback); DCameraHandler::GetInstance().Initialize(); std::vector cameras = DCameraHandler::GetInstance().GetCameras(); diff --git a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_dev_test.cpp b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_dev_test.cpp index 34b9d34eabb8c9e55b8baa3c22a50ce41101dd3e..2572af580e09be5e274729476340ef2bcda8ccc8 100644 --- a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_dev_test.cpp +++ b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/dcamera_sink_dev_test.cpp @@ -25,6 +25,7 @@ #include "dcamera_sink_dev.h" #undef private +#include "dcamera_sink_callback.h" #include "dcamera_handler.h" #include "dcamera_utils_tools.h" #include "distributed_camera_errno.h" @@ -79,7 +80,8 @@ void DCameraSinkDevTest::SetUp(void) { DCameraHandler::GetInstance().Initialize(); std::vector cameras = DCameraHandler::GetInstance().GetCameras(); - dev_ = std::make_shared(cameras[0]); + sptr sinkCallback(new DCameraSinkCallback()); + dev_ = std::make_shared(cameras[0], sinkCallback); dev_->accessControl_ = std::make_shared(); dev_->controller_ = std::make_shared(dev_->accessControl_); diff --git a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/mock_camera_operator.h b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/mock_camera_operator.h index aa1ea3690ad0fe073f5d63253be4f0f3bbc15e04..5f3857515a1bac3d9607ba22879b125d18f36324 100644 --- a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/mock_camera_operator.h +++ b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/mock_camera_operator.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 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 @@ -88,6 +88,16 @@ public: { return DCAMERA_OK; } + + int32_t PauseCapture() + { + return DCAMERA_OK; + } + + int32_t ResumeCapture() + { + return DCAMERA_OK; + } }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/mock_dcamera_sink_controller.h b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/mock_dcamera_sink_controller.h index c4c540006e6c2414aecaec3d8e0185ed25507b24..36e0b2fa7d1c5e9c6b5a69a371342663c4adf2b9 100644 --- a/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/mock_dcamera_sink_controller.h +++ b/services/cameraservice/sinkservice/test/unittest/common/distributedcameramgr/mock_dcamera_sink_controller.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 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 @@ -71,6 +71,18 @@ public: { return DCAMERA_OK; } + int32_t PauseDistributedHardware(const std::string &networkId) + { + return DCAMERA_OK; + } + int32_t ResumeDistributedHardware(const std::string &networkId) + { + return DCAMERA_OK; + } + int32_t StopDistributedHardware(const std::string &networkId) + { + return DCAMERA_OK; + } }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/cameraservice/sourceservice/BUILD.gn b/services/cameraservice/sourceservice/BUILD.gn index ff69dc8b5b3827db27b40641ff9c69933b8bec09..ef08a5d87a49a8e69edcc8d366a8c3c401c5f1d6 100644 --- a/services/cameraservice/sourceservice/BUILD.gn +++ b/services/cameraservice/sourceservice/BUILD.gn @@ -51,6 +51,7 @@ ohos_shared_library("distributed_camera_source") { "${common_path}/include/utils", "${innerkits_path}/native_cpp/camera_source/include", "${innerkits_path}/native_cpp/camera_sink/include", + "${innerkits_path}/native_cpp/camera_sink/include/callback", "${innerkits_path}/native_cpp/camera_source/include/callback", "${services_path}/cameraservice/base/include", "${services_path}/channel/include", @@ -105,6 +106,7 @@ ohos_shared_library("distributed_camera_source") { deps = [ "${common_path}:distributed_camera_utils", + "${innerkits_path}/native_cpp/camera_sink:distributed_camera_sink_sdk", "${services_path}/channel:distributed_camera_channel", "${services_path}/data_process:distributed_camera_data_process", "//third_party/cJSON:cjson", diff --git a/services/cameraservice/sourceservice/include/distributedcameramgr/dcameracontrol/dcamera_source_controller.h b/services/cameraservice/sourceservice/include/distributedcameramgr/dcameracontrol/dcamera_source_controller.h index 6141e286cedf5c61b957a46ff421ce91577ebe8a..47a3be02e191aaf283f8e9094b4ab252e75a98b3 100644 --- a/services/cameraservice/sourceservice/include/distributedcameramgr/dcameracontrol/dcamera_source_controller.h +++ b/services/cameraservice/sourceservice/include/distributedcameramgr/dcameracontrol/dcamera_source_controller.h @@ -45,6 +45,9 @@ public: int32_t CloseChannel() override; int32_t Init(std::vector& indexs) override; int32_t UnInit() override; + int32_t PauseDistributedHardware(const std::string &networkId) override; + int32_t ResumeDistributedHardware(const std::string &networkId) override; + int32_t StopDistributedHardware(const std::string &networkId) override; void OnSessionState(int32_t state); void OnSessionError(int32_t eventType, int32_t eventReason, std::string detail); diff --git a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameracontrol/dcamera_source_controller.cpp b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameracontrol/dcamera_source_controller.cpp index 432d8d33d23eec491dfbf606029aba2662a3e962..65da4d41032464498e2d4ee5b2301b2628922db0 100644 --- a/services/cameraservice/sourceservice/src/distributedcameramgr/dcameracontrol/dcamera_source_controller.cpp +++ b/services/cameraservice/sourceservice/src/distributedcameramgr/dcameracontrol/dcamera_source_controller.cpp @@ -180,6 +180,10 @@ int32_t DCameraSourceController::DCameraNotify(std::shared_ptr& ev DHBase dhBase; dhBase.deviceId_ = devId_; dhBase.dhId_ = dhId_; + if (events->eventType_ == DCAMERA_SINK_STOP && events->eventResult_ == DCAMERA_EVENT_SINK_STOP) { + events->eventType_ = DCAMERA_OPERATION; + events->eventResult_ = DCAMERA_EVENT_DEVICE_ERROR; + } DCameraHDFEvent hdiEvent; hdiEvent.type_ = events->eventType_; hdiEvent.result_ = events->eventResult_; @@ -507,5 +511,20 @@ void DCameraSourceController::PostChannelDisconnectedEvent() } camDev->OnChannelDisconnectedEvent(); } + +int32_t DCameraSourceController::PauseDistributedHardware(const std::string &networkId) +{ + return DCAMERA_OK; +} + +int32_t DCameraSourceController::ResumeDistributedHardware(const std::string &networkId) +{ + return DCAMERA_OK; +} + +int32_t DCameraSourceController::StopDistributedHardware(const std::string &networkId) +{ + return DCAMERA_OK; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/BUILD.gn b/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/BUILD.gn index 4ff940092ea7ded6553cbbac6cb06d342c43c58a..458650c260ff164af3298b57e9a99e05c1e01126 100644 --- a/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/BUILD.gn +++ b/services/cameraservice/sourceservice/test/unittest/common/distributedcameramgr/BUILD.gn @@ -40,6 +40,7 @@ config("module_private_config") { "${innerkits_path}/native_cpp/camera_source/include", "${innerkits_path}/native_cpp/camera_source/include/callback", "${innerkits_path}/native_cpp/camera_sink/include", + "${innerkits_path}/native_cpp/camera_sink/include/callback", "${fwk_utils_path}/include", "${fwk_utils_path}/include/eventbus",