| @@ -48,6 +48,7 @@ enum class IDCameraSinkInterfaceCode : uint32_t { | |||
| 48 | SET_ACCESS_LISTENER = 12, | 48 | SET_ACCESS_LISTENER = 12, |
| 49 | REMOVE_ACCESS_LISTENER = 13, | 49 | REMOVE_ACCESS_LISTENER = 13, |
| 50 | SET_AUTHORIZATION_RESULT = 14, | 50 | SET_AUTHORIZATION_RESULT = 14, |
| 51 | + CONFIG_DISTRIBUTED_HARDWARE = 15, | ||
| 51 | }; | 52 | }; |
| 52 | } // namespace DistributedHardware | 53 | } // namespace DistributedHardware |
| 53 | } // namespace OHOS | 54 | } // namespace OHOS |
| @@ -128,6 +128,11 @@ constexpr static int8_t FRAME_HEAD = 0; | |||
| 128 | const int32_t VALID_OS_TYPE = 10; | 128 | const int32_t VALID_OS_TYPE = 10; |
| 129 | const int32_t INVALID_OS_TYPE = -1; | 129 | const int32_t INVALID_OS_TYPE = -1; |
| 130 | const std::string KEY_OS_TYPE = "OS_TYPE"; | 130 | const std::string KEY_OS_TYPE = "OS_TYPE"; |
| 131 | +constexpr const char *KEY_ENABLE_FIRST_TOKENID = "enableFirstTokenId"; | ||
| 132 | +constexpr const char *KEY_TRIGGER_FIRST_TOKENID = "triggerFirstTokenId"; | ||
| 133 | +constexpr const char *KEY_TRIGGER_FIRST_USERID = "triggerFirstUserId"; | ||
| 134 | +constexpr const char *KEY_ENABLE_INIT_PARAM = "enable_init_params"; | ||
| 135 | +constexpr const char *KEY_TOKEN_ID = "tokenId"; | ||
| 131 | 136 | ||
| 132 | const int32_t RESOLUTION_MAX_WIDTH_SNAPSHOT = 4096; | 137 | const int32_t RESOLUTION_MAX_WIDTH_SNAPSHOT = 4096; |
| 133 | const int32_t RESOLUTION_MAX_HEIGHT_SNAPSHOT = 3072; | 138 | const int32_t RESOLUTION_MAX_HEIGHT_SNAPSHOT = 3072; |
| @@ -41,6 +41,8 @@ public: | |||
| 41 | const std::string &pkgName) override; | 41 | const std::string &pkgName) override; |
| 42 | int32_t RemoveAccessListener(const std::string &pkgName) override; | 42 | int32_t RemoveAccessListener(const std::string &pkgName) override; |
| 43 | int32_t SetAuthorizationResult(const std::string &requestId, bool granted) override; | 43 | int32_t SetAuthorizationResult(const std::string &requestId, bool granted) override; |
| 44 | + int32_t ConfigDistributedHardware(const std::string& dhId, const std::string& key, | ||
| 45 | + const std::string& value) override; | ||
| 44 | void RegisterDistributedHardwareSinkStateListener( | 46 | void RegisterDistributedHardwareSinkStateListener( |
| 45 | std::shared_ptr<DistributedHardwareSinkStateListener> listener) override; | 47 | std::shared_ptr<DistributedHardwareSinkStateListener> listener) override; |
| 46 | void UnregisterDistributedHardwareSinkStateListener() override; | 48 | void UnregisterDistributedHardwareSinkStateListener() override; |
| @@ -48,6 +48,8 @@ public: | |||
| 48 | const std::string &pkgName) override; | 48 | const std::string &pkgName) override; |
| 49 | int32_t RemoveAccessListener(const std::string &pkgName) override; | 49 | int32_t RemoveAccessListener(const std::string &pkgName) override; |
| 50 | int32_t SetAuthorizationResult(const std::string &requestId, bool granted) override; | 50 | int32_t SetAuthorizationResult(const std::string &requestId, bool granted) override; |
| 51 | + int32_t ConfigDistributedHardware(const std::string& devId, const std::string& dhId, const std::string& key, | ||
| 52 | + const std::string& value) override; | ||
| 51 | 53 | ||
| 52 | private: | 54 | private: |
| 53 | static inline BrokerDelegator<DistributedCameraSinkProxy> delegator_; | 55 | static inline BrokerDelegator<DistributedCameraSinkProxy> delegator_; |
| @@ -44,6 +44,8 @@ public: | |||
| 44 | const std::string &pkgName) = 0; | 44 | const std::string &pkgName) = 0; |
| 45 | virtual int32_t RemoveAccessListener(const std::string &pkgName) = 0; | 45 | virtual int32_t RemoveAccessListener(const std::string &pkgName) = 0; |
| 46 | virtual int32_t SetAuthorizationResult(const std::string &requestId, bool granted) = 0; | 46 | virtual int32_t SetAuthorizationResult(const std::string &requestId, bool granted) = 0; |
| 47 | + virtual int32_t ConfigDistributedHardware(const std::string& devId, const std::string& dhId, | ||
| 48 | + const std::string& key, const std::string& value) = 0; | ||
| 47 | }; | 49 | }; |
| 48 | } // namespace DistributedHardware | 50 | } // namespace DistributedHardware |
| 49 | } // namespace OHOS | 51 | } // namespace OHOS |
| @@ -251,6 +251,22 @@ int32_t DCameraSinkHandler::SetAuthorizationResult(const std::string &requestId, | |||
| 251 | return dCameraSinkSrv->SetAuthorizationResult(requestId, granted); | 251 | return dCameraSinkSrv->SetAuthorizationResult(requestId, granted); |
| 252 | } | 252 | } |
| 253 | 253 | ||
| 254 | +int32_t DCameraSinkHandler::ConfigDistributedHardware(const std::string& dhId, const std::string& key, | ||
| 255 | + const std::string& value) | ||
| 256 | +{ | ||
| 257 | + DHLOGI("dhId: %{public}s", GetAnonyString(dhId).c_str()); | ||
| 258 | + sptr<IDistributedCameraSink> dCameraSinkSrv = DCameraSinkHandlerIpc::GetInstance().GetSinkLocalCamSrv(); | ||
| 259 | + if (dCameraSinkSrv == nullptr) { | ||
| 260 | + DHLOGE("get Service failed"); | ||
| 261 | + return DCAMERA_BAD_VALUE; | ||
| 262 | + } | ||
| 263 | + int32_t ret = dCameraSinkSrv->ConfigDistributedHardware("", dhId, key, value); | ||
| 264 | + if (ret != DCAMERA_OK) { | ||
| 265 | + DHLOGE("ConfigDistributedHardware failed ret = %{public}d", ret); | ||
| 266 | + } | ||
| 267 | + return ret; | ||
| 268 | +} | ||
| 269 | + | ||
| 254 | void DCameraSinkHandler::RegisterDistributedHardwareSinkStateListener( | 270 | void DCameraSinkHandler::RegisterDistributedHardwareSinkStateListener( |
| 255 | std::shared_ptr<DistributedHardwareSinkStateListener> listener) | 271 | std::shared_ptr<DistributedHardwareSinkStateListener> listener) |
| 256 | { | 272 | { |
| @@ -583,5 +583,36 @@ int32_t DistributedCameraSinkProxy::SetAuthorizationResult(const std::string &re | |||
| 583 | DHLOGI("SetAuthorizationResult end, result: %{public}d", result); | 583 | DHLOGI("SetAuthorizationResult end, result: %{public}d", result); |
| 584 | return result; | 584 | return result; |
| 585 | } | 585 | } |
| 586 | + | ||
| 587 | +int32_t DistributedCameraSinkProxy::ConfigDistributedHardware(const std::string& devId, const std::string& dhId, | ||
| 588 | + const std::string& key, const std::string& value) | ||
| 589 | +{ | ||
| 590 | + DHLOGI("dhId: %{public}s", GetAnonyString(dhId).c_str()); | ||
| 591 | + if (dhId.empty() || key.empty() || value.empty()) { | ||
| 592 | + DHLOGE("param is invalid"); | ||
| 593 | + return DCAMERA_BAD_VALUE; | ||
| 594 | + } | ||
| 595 | + sptr<IRemoteObject> remote = Remote(); | ||
| 596 | + if (remote == nullptr) { | ||
| 597 | + DHLOGE("remote service is null"); | ||
| 598 | + return DCAMERA_BAD_VALUE; | ||
| 599 | + } | ||
| 600 | + MessageParcel data; | ||
| 601 | + MessageParcel reply; | ||
| 602 | + MessageOption option; | ||
| 603 | + if (!data.WriteInterfaceToken(DistributedCameraSinkProxy::GetDescriptor())) { | ||
| 604 | + DHLOGE("write token failed"); | ||
| 605 | + return DCAMERA_BAD_VALUE; | ||
| 606 | + } | ||
| 607 | + if (!data.WriteString(devId) || !data.WriteString(dhId) || !data.WriteString(key) || | ||
| 608 | + !data.WriteString(value)) { | ||
| 609 | + DHLOGE("write params failed"); | ||
| 610 | + return DCAMERA_BAD_VALUE; | ||
| 611 | + } | ||
| 612 | + remote->SendRequest(static_cast<uint32_t>(IDCameraSinkInterfaceCode::CONFIG_DISTRIBUTED_HARDWARE), | ||
| 613 | + data, reply, option); | ||
| 614 | + int32_t result = reply.ReadInt32(); | ||
| 615 | + return result; | ||
| 616 | +} | ||
| 586 | } // namespace DistributedHardware | 617 | } // namespace DistributedHardware |
| 587 | } // namespace OHOS | 618 | } // namespace OHOS |
| @@ -223,7 +223,6 @@ int32_t DCameraSourceHandler::ConfigDistributedHardware(const std::string& devId | |||
| 223 | } | 223 | } |
| 224 | std::string reqId = GetRandomID(); | 224 | std::string reqId = GetRandomID(); |
| 225 | std::lock_guard<std::mutex> autoLock(optLock_); | 225 | std::lock_guard<std::mutex> autoLock(optLock_); |
| 226 | - | ||
| 227 | int32_t ret = dCameraSourceSrv->ConfigDistributedHardware(devId, dhId, key, value); | 226 | int32_t ret = dCameraSourceSrv->ConfigDistributedHardware(devId, dhId, key, value); |
| 228 | if (ret != DCAMERA_OK) { | 227 | if (ret != DCAMERA_OK) { |
| 229 | DHLOGE("ConfigDistributedHardware failed ret = %{public}d", ret); | 228 | DHLOGE("ConfigDistributedHardware failed ret = %{public}d", ret); |
| @@ -59,6 +59,7 @@ group("fuzztest") { | |||
| 59 | "sinkservicestopdistributedhardware_fuzzer:fuzztest", | 59 | "sinkservicestopdistributedhardware_fuzzer:fuzztest", |
| 60 | "sinkservicesubscribelocalhardware_fuzzer:fuzztest", | 60 | "sinkservicesubscribelocalhardware_fuzzer:fuzztest", |
| 61 | "sinkserviceunsubscribelocalhardware_fuzzer:fuzztest", | 61 | "sinkserviceunsubscribelocalhardware_fuzzer:fuzztest", |
| 62 | + "sinkserviceconfigdistributedhardware_fuzzer:fuzztest", | ||
| 62 | "softbusonsinkbytesreceived_fuzzer:fuzztest", | 63 | "softbusonsinkbytesreceived_fuzzer:fuzztest", |
| 63 | "softbusonsinkmessagereceived_fuzzer:fuzztest", | 64 | "softbusonsinkmessagereceived_fuzzer:fuzztest", |
| 64 | "softbusonsinksessionclosed_fuzzer:fuzztest", | 65 | "softbusonsinksessionclosed_fuzzer:fuzztest", |
| @@ -0,0 +1,86 @@ | |||
| 1 | +# Copyright (c) 2026 Huawei Device Co., Ltd. | ||
| 2 | +# Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | +# you may not use this file except in compliance with the License. | ||
| 4 | +# You may obtain a copy of the License at | ||
| 5 | +# | ||
| 6 | +# http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | +# | ||
| 8 | +# Unless required by applicable law or agreed to in writing, software | ||
| 9 | +# distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | +# See the License for the specific language governing permissions and | ||
| 12 | +# limitations under the License. | ||
| 13 | + | ||
| 14 | +#####################hydra-fuzz################### | ||
| 15 | +import("//build/config/features.gni") | ||
| 16 | +import("//build/test.gni") | ||
| 17 | +import( | ||
| 18 | + "//foundation/distributedhardware/distributed_camera/distributedcamera.gni") | ||
| 19 | + | ||
| 20 | +##############################fuzztest########################################## | ||
| 21 | +ohos_fuzztest("SinkServiceConfigDistributedHardwareFuzzTest") { | ||
| 22 | + module_out_path = "${fuzz_test_output_path}/sinkserviceconfigdistributedhardware" | ||
| 23 | + | ||
| 24 | + fuzz_config_file = "${innerkits_path}/native_cpp/test/sinkfuzztest/sinkserviceconfigdistributedhardware_fuzzer" | ||
| 25 | + | ||
| 26 | + include_dirs = [ | ||
| 27 | + "include", | ||
| 28 | + "${common_path}/include/constants", | ||
| 29 | + "${common_path}/include/utils", | ||
| 30 | + "${innerkits_path}/native_cpp/camera_sink/include", | ||
| 31 | + "${innerkits_path}/native_cpp/camera_sink/include/callback", | ||
| 32 | + "${services_path}/cameraservice/base/include", | ||
| 33 | + "${services_path}/cameraservice/cameraoperator/client/include", | ||
| 34 | + "${services_path}/cameraservice/sinkservice/include/distributedcamera", | ||
| 35 | + "${services_path}/cameraservice/sinkservice/include/distributedcameramgr", | ||
| 36 | + "${services_path}/cameraservice/sinkservice/include/distributedcameramgr/interface", | ||
| 37 | + "${services_path}/cameraservice/sinkservice/include/distributedcameramgr/eventbus", | ||
| 38 | + "${services_path}/data_process/include/utils", | ||
| 39 | + "${services_path}/channel/include", | ||
| 40 | + "${feeding_smoother_path}/base", | ||
| 41 | + ] | ||
| 42 | + | ||
| 43 | + cflags = [ | ||
| 44 | + "-g", | ||
| 45 | + "-O0", | ||
| 46 | + "-Wno-unused-variable", | ||
| 47 | + "-fno-omit-frame-pointer", | ||
| 48 | + "-Dprivate=public", | ||
| 49 | + "-Dprotected=public", | ||
| 50 | + ] | ||
| 51 | + | ||
| 52 | + sources = [ "sinkserviceconfigdistributedhardware_fuzzer.cpp" ] | ||
| 53 | + | ||
| 54 | + deps = [ | ||
| 55 | + "${common_path}:distributed_camera_utils", | ||
| 56 | + "${innerkits_path}/native_cpp/camera_sink:distributed_camera_sink_sdk", | ||
| 57 | + "${services_path}/cameraservice/sinkservice:distributed_camera_sink", | ||
| 58 | + ] | ||
| 59 | + | ||
| 60 | + defines = [ | ||
| 61 | + "HI_LOG_ENABLE", | ||
| 62 | + "DH_LOG_TAG=\"SinkServiceConfigDHFuzzTest\"", | ||
| 63 | + "LOG_DOMAIN=0xD004150", | ||
| 64 | + ] | ||
| 65 | + | ||
| 66 | + external_deps = [ | ||
| 67 | + "cJSON:cjson", | ||
| 68 | + "c_utils:utils", | ||
| 69 | + "device_manager:devicemanagersdk", | ||
| 70 | + "distributed_hardware_fwk:distributedhardwareutils", | ||
| 71 | + "drivers_interface_distributed_camera:libdistributed_camera_provider_proxy_1.1", | ||
| 72 | + "eventhandler:libeventhandler", | ||
| 73 | + "graphic_surface:surface", | ||
| 74 | + "hilog:libhilog", | ||
| 75 | + "ipc:ipc_core", | ||
| 76 | + "safwk:system_ability_fwk", | ||
| 77 | + "samgr:samgr_proxy", | ||
| 78 | + ] | ||
| 79 | +} | ||
| 80 | + | ||
| 81 | +############################################################################### | ||
| 82 | +group("fuzztest") { | ||
| 83 | + testonly = true | ||
| 84 | + deps = [ ":SinkServiceConfigDistributedHardwareFuzzTest" ] | ||
| 85 | +} | ||
| 86 | +############################################################################### | ||
| @@ -0,0 +1,14 @@ | |||
| 1 | +/* | ||
| 2 | + * Copyright (c) 2026 Huawei Device Co., Ltd. | ||
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 4 | + * you may not use this file except in compliance with the License. | ||
| 5 | + * You may obtain a copy of the License at | ||
| 6 | + * | ||
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 8 | + * | ||
| 9 | + * Unless required by applicable law or agreed to in writing, software | ||
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 12 | + * See the License for the specific language governing permissions and | ||
| 13 | + * limitations under the License. | ||
| 14 | + */ | ||
| @@ -0,0 +1,25 @@ | |||
| 1 | +<?xml version="1.0" encoding="utf-8"?> | ||
| 2 | +<!-- Copyright (c) 2026 Huawei Device Co., Ltd. | ||
| 3 | + | ||
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + you may not use this file except in compliance with the License. | ||
| 6 | + You may obtain a copy of the License at | ||
| 7 | + | ||
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + | ||
| 10 | + Unless required by applicable law or agreed to in writing, software | ||
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + See the License for the specific language governing permissions and | ||
| 14 | + limitations under the License. | ||
| 15 | +--> | ||
| 16 | +<fuzz_config> | ||
| 17 | + <fuzztest> | ||
| 18 | + <!-- maximum length of a test input --> | ||
| 19 | + <max_len>1000</max_len> | ||
| 20 | + <!-- maximum total time in seconds to run the fuzzer --> | ||
| 21 | + <max_total_time>300</max_total_time> | ||
| 22 | + <!-- memory usage limit in Mb --> | ||
| 23 | + <rss_limit_mb>4096</rss_limit_mb> | ||
| 24 | + </fuzztest> | ||
| 25 | +</fuzz_config> | ||
| @@ -0,0 +1,115 @@ | |||
| 1 | +/* | ||
| 2 | + * Copyright (c) 2026 Huawei Device Co., Ltd. | ||
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 4 | + * you may not use this file except in compliance with the License. | ||
| 5 | + * You may obtain a copy of the License at | ||
| 6 | + * | ||
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 8 | + * | ||
| 9 | + * Unless required by applicable law or agreed to in writing, software | ||
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 12 | + * See the License for the specific language governing permissions and | ||
| 13 | + * limitations under the License. | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | +#include "sinkserviceconfigdistributedhardware_fuzzer.h" | ||
| 17 | + | ||
| 18 | +#include <cstddef> | ||
| 19 | +#include <cstdint> | ||
| 20 | +#include <string> | ||
| 21 | + | ||
| 22 | +#include <fuzzer/FuzzedDataProvider.h> | ||
| 23 | + | ||
| 24 | +#include "cJSON.h" | ||
| 25 | +#include "dcamera_sink_callback.h" | ||
| 26 | +#include "distributed_camera_constants.h" | ||
| 27 | +#include "distributed_camera_sink_service.h" | ||
| 28 | + | ||
| 29 | +namespace OHOS { | ||
| 30 | +namespace DistributedHardware { | ||
| 31 | + | ||
| 32 | +void SinkServiceConfigDHFuzzTest(const uint8_t* data, size_t size) | ||
| 33 | +{ | ||
| 34 | + FuzzedDataProvider fdp(data, size); | ||
| 35 | + std::string devId = fdp.ConsumeRandomLengthString(); | ||
| 36 | + std::string dhId = fdp.ConsumeRandomLengthString(); | ||
| 37 | + std::string key = fdp.ConsumeRandomLengthString(); | ||
| 38 | + std::string value = fdp.ConsumeRemainingBytesAsString(); | ||
| 39 | + auto sinkService = std::make_shared<DistributedCameraSinkService>( | ||
| 40 | + DISTRIBUTED_HARDWARE_CAMERA_SINK_SA_ID, true); | ||
| 41 | + if (sinkService == nullptr) { | ||
| 42 | + return; | ||
| 43 | + } | ||
| 44 | + sinkService->ConfigDistributedHardware(devId, dhId, key, value); | ||
| 45 | +} | ||
| 46 | + | ||
| 47 | +void SinkServiceConfigDHEnableParamFuzzTest(const uint8_t* data, size_t size) | ||
| 48 | +{ | ||
| 49 | + FuzzedDataProvider fdp(data, size); | ||
| 50 | + std::string dhId = fdp.ConsumeRandomLengthString(); | ||
| 51 | + std::string value = fdp.ConsumeRemainingBytesAsString(); | ||
| 52 | + auto sinkService = std::make_shared<DistributedCameraSinkService>( | ||
| 53 | + DISTRIBUTED_HARDWARE_CAMERA_SINK_SA_ID, true); | ||
| 54 | + if (sinkService == nullptr) { | ||
| 55 | + return; | ||
| 56 | + } | ||
| 57 | + sinkService->ConfigDistributedHardware("", dhId, KEY_ENABLE_INIT_PARAM, value); | ||
| 58 | + sinkService->enableFirstTokenId_ = 0; | ||
| 59 | + sinkService->ConfigDistributedHardware("", dhId, KEY_ENABLE_INIT_PARAM, value); | ||
| 60 | +} | ||
| 61 | + | ||
| 62 | +void SinkServiceConfigDHInvalidJsonFuzzTest(const uint8_t* data, size_t size) | ||
| 63 | +{ | ||
| 64 | + if (data == nullptr || size == 0) { | ||
| 65 | + return; | ||
| 66 | + } | ||
| 67 | + std::string value(reinterpret_cast<const char*>(data), size); | ||
| 68 | + auto sinkService = std::make_shared<DistributedCameraSinkService>( | ||
| 69 | + DISTRIBUTED_HARDWARE_CAMERA_SINK_SA_ID, true); | ||
| 70 | + if (sinkService == nullptr) { | ||
| 71 | + return; | ||
| 72 | + } | ||
| 73 | + sinkService->ConfigDistributedHardware("", "camera_0", KEY_ENABLE_INIT_PARAM, value); | ||
| 74 | + sinkService->ConfigDistributedHardware("", "camera_0", "other_key", value); | ||
| 75 | +} | ||
| 76 | + | ||
| 77 | +void SinkServiceConfigDHValidJsonFuzzTest(const uint8_t* data, size_t size) | ||
| 78 | +{ | ||
| 79 | + FuzzedDataProvider fdp(data, size); | ||
| 80 | + uint32_t tokenId = fdp.ConsumeIntegral<uint32_t>(); | ||
| 81 | + std::string dhId = fdp.ConsumeRandomLengthString(); | ||
| 82 | + cJSON* root = cJSON_CreateObject(); | ||
| 83 | + if (root == nullptr) { | ||
| 84 | + return; | ||
| 85 | + } | ||
| 86 | + cJSON_AddNumberToObject(root, KEY_TOKEN_ID, static_cast<double>(tokenId)); | ||
| 87 | + char* jsonStr = cJSON_PrintUnformatted(root); | ||
| 88 | + if (jsonStr == nullptr) { | ||
| 89 | + cJSON_Delete(root); | ||
| 90 | + return; | ||
| 91 | + } | ||
| 92 | + std::string value(jsonStr); | ||
| 93 | + auto sinkService = std::make_shared<DistributedCameraSinkService>( | ||
| 94 | + DISTRIBUTED_HARDWARE_CAMERA_SINK_SA_ID, true); | ||
| 95 | + if (sinkService == nullptr) { | ||
| 96 | + cJSON_Delete(root); | ||
| 97 | + free(jsonStr); | ||
| 98 | + return; | ||
| 99 | + } | ||
| 100 | + sinkService->enableFirstTokenId_ = 0; | ||
| 101 | + sinkService->ConfigDistributedHardware("", dhId, KEY_ENABLE_INIT_PARAM, value); | ||
| 102 | + cJSON_Delete(root); | ||
| 103 | + free(jsonStr); | ||
| 104 | +} | ||
| 105 | +} | ||
| 106 | +} | ||
| 107 | + | ||
| 108 | +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) | ||
| 109 | +{ | ||
| 110 | + OHOS::DistributedHardware::SinkServiceConfigDHFuzzTest(data, size); | ||
| 111 | + OHOS::DistributedHardware::SinkServiceConfigDHEnableParamFuzzTest(data, size); | ||
| 112 | + OHOS::DistributedHardware::SinkServiceConfigDHInvalidJsonFuzzTest(data, size); | ||
| 113 | + OHOS::DistributedHardware::SinkServiceConfigDHValidJsonFuzzTest(data, size); | ||
| 114 | + return 0; | ||
| 115 | +} | ||
| @@ -0,0 +1,21 @@ | |||
| 1 | +/* | ||
| 2 | + * Copyright (c) 2026 Huawei Device Co., Ltd. | ||
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 4 | + * you may not use this file except in compliance with the License. | ||
| 5 | + * You may obtain a copy of the License at | ||
| 6 | + * | ||
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 8 | + * | ||
| 9 | + * Unless required by applicable law or agreed to in writing, software | ||
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 12 | + * See the License for the specific language governing permissions and | ||
| 13 | + * limitations under the License. | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | +#ifndef SINKSERVICECONFIGDISTRIBUTEDHARDWARE_FUZZER_H | ||
| 17 | +#define SINKSERVICECONFIGDISTRIBUTEDHARDWARE_FUZZER_H | ||
| 18 | + | ||
| 19 | +#define FUZZ_PROJECT_NAME "sinkserviceconfigdistributedhardware_fuzzer" | ||
| 20 | + | ||
| 21 | +#endif | ||
| @@ -46,6 +46,7 @@ group("fuzztest") { | |||
| 46 | "sourceservicecamdeverase_fuzzer:fuzztest", | 46 | "sourceservicecamdeverase_fuzzer:fuzztest", |
| 47 | "sourceserviceinitsource_fuzzer:fuzztest", | 47 | "sourceserviceinitsource_fuzzer:fuzztest", |
| 48 | "sourceserviceregisterdistributedhardware_fuzzer:fuzztest", | 48 | "sourceserviceregisterdistributedhardware_fuzzer:fuzztest", |
| 49 | + "sourceserviceregisterdhext_fuzzer:fuzztest", | ||
| 49 | "sourceservicereleasesource_fuzzer:fuzztest", | 50 | "sourceservicereleasesource_fuzzer:fuzztest", |
| 50 | "sourceserviceunregisterdistributedhardware_fuzzer:fuzztest", | 51 | "sourceserviceunregisterdistributedhardware_fuzzer:fuzztest", |
| 51 | "sourceserviceupdateworkmode_fuzzer:fuzztest", | 52 | "sourceserviceupdateworkmode_fuzzer:fuzztest", |
| @@ -0,0 +1,83 @@ | |||
| 1 | +# Copyright (c) 2026 Huawei Device Co., Ltd. | ||
| 2 | +# Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | +# you may not use this file except in compliance with the License. | ||
| 4 | +# You may obtain a copy of the License at | ||
| 5 | +# | ||
| 6 | +# http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | +# | ||
| 8 | +# Unless required by applicable law or agreed to in writing, software | ||
| 9 | +# distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | +# See the License for the specific language governing permissions and | ||
| 12 | +# limitations under the License. | ||
| 13 | + | ||
| 14 | +#####################hydra-fuzz################### | ||
| 15 | +import("//build/config/features.gni") | ||
| 16 | +import("//build/test.gni") | ||
| 17 | +import( | ||
| 18 | + "//foundation/distributedhardware/distributed_camera/distributedcamera.gni") | ||
| 19 | + | ||
| 20 | +##############################fuzztest########################################## | ||
| 21 | +ohos_fuzztest("SourceServiceRegisterDHExtFuzzTest") { | ||
| 22 | + module_out_path = | ||
| 23 | + "${fuzz_test_output_path}/sourceserviceregisterdhext" | ||
| 24 | + | ||
| 25 | + fuzz_config_file = "${innerkits_path}/native_cpp/test/sourcefuzztest/sourceserviceregisterdhext_fuzzer" | ||
| 26 | + | ||
| 27 | + include_dirs = [ | ||
| 28 | + "include", | ||
| 29 | + "${common_path}/include/constants", | ||
| 30 | + "${common_path}/include/utils", | ||
| 31 | + "${innerkits_path}/native_cpp/camera_source/include", | ||
| 32 | + "${innerkits_path}/native_cpp/camera_source/include/callback", | ||
| 33 | + "${services_path}/cameraservice/base/include", | ||
| 34 | + "${services_path}/cameraservice/sourceservice/include/distributedcamera", | ||
| 35 | + "${services_path}/cameraservice/sourceservice/include/distributedcameramgr", | ||
| 36 | + "${services_path}/cameraservice/sourceservice/include/distributedcameramgr/dcameracontrol", | ||
| 37 | + "${services_path}/cameraservice/sourceservice/include/distributedcameramgr/dcameradata", | ||
| 38 | + "${services_path}/cameraservice/sourceservice/include/distributedcameramgr/dcamerahdf", | ||
| 39 | + "${services_path}/cameraservice/sourceservice/include/distributedcameramgr/dcamerainterface", | ||
| 40 | + "${services_path}/cameraservice/sourceservice/include/distributedcameramgr/dcamerastate", | ||
| 41 | + ] | ||
| 42 | + | ||
| 43 | + cflags = [ | ||
| 44 | + "-g", | ||
| 45 | + "-O0", | ||
| 46 | + "-Wno-unused-variable", | ||
| 47 | + "-fno-omit-frame-pointer", | ||
| 48 | + ] | ||
| 49 | + | ||
| 50 | + sources = [ "sourceserviceregisterdhext_fuzzer.cpp" ] | ||
| 51 | + | ||
| 52 | + deps = [ | ||
| 53 | + "${common_path}:distributed_camera_utils", | ||
| 54 | + "${services_path}/cameraservice/sourceservice:distributed_camera_source", | ||
| 55 | + ] | ||
| 56 | + | ||
| 57 | + defines = [ | ||
| 58 | + "HI_LOG_ENABLE", | ||
| 59 | + "DH_LOG_TAG=\"SourceServiceRegisterDHExtFuzzTest\"", | ||
| 60 | + "LOG_DOMAIN=0xD004150", | ||
| 61 | + ] | ||
| 62 | + | ||
| 63 | + external_deps = [ | ||
| 64 | + "cJSON:cjson", | ||
| 65 | + "c_utils:utils", | ||
| 66 | + "distributed_hardware_fwk:distributed_av_receiver", | ||
| 67 | + "distributed_hardware_fwk:distributedhardwareutils", | ||
| 68 | + "distributed_hardware_fwk:libdhfwk_sdk", | ||
| 69 | + "drivers_interface_distributed_camera:libdistributed_camera_provider_proxy_1.1", | ||
| 70 | + "eventhandler:libeventhandler", | ||
| 71 | + "hilog:libhilog", | ||
| 72 | + "ipc:ipc_core", | ||
| 73 | + "safwk:system_ability_fwk", | ||
| 74 | + "samgr:samgr_proxy", | ||
| 75 | + ] | ||
| 76 | +} | ||
| 77 | + | ||
| 78 | +############################################################################### | ||
| 79 | +group("fuzztest") { | ||
| 80 | + testonly = true | ||
| 81 | + deps = [ ":SourceServiceRegisterDHExtFuzzTest" ] | ||
| 82 | +} | ||
| 83 | +############################################################################### | ||
| @@ -0,0 +1,14 @@ | |||
| 1 | +/* | ||
| 2 | + * Copyright (c) 2026 Huawei Device Co., Ltd. | ||
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 4 | + * you may not use this file except in compliance with the License. | ||
| 5 | + * You may obtain a copy of the License at | ||
| 6 | + * | ||
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 8 | + * | ||
| 9 | + * Unless required by applicable law or agreed to in writing, software | ||
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 12 | + * See the License for the specific language governing permissions and | ||
| 13 | + * limitations under the License. | ||
| 14 | + */ | ||
| @@ -0,0 +1,25 @@ | |||
| 1 | +<?xml version="1.0" encoding="utf-8"?> | ||
| 2 | +<!-- Copyright (c) 2026 Huawei Device Co., Ltd. | ||
| 3 | + | ||
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + you may not use this file except in compliance with the License. | ||
| 6 | + You may obtain a copy of the License at | ||
| 7 | + | ||
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + | ||
| 10 | + Unless required by applicable law or agreed to in writing, software | ||
| 11 | + distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + See the License for the specific language governing permissions and | ||
| 14 | + limitations under the License. | ||
| 15 | +--> | ||
| 16 | +<fuzz_config> | ||
| 17 | + <fuzztest> | ||
| 18 | + <!-- maximum length of a test input --> | ||
| 19 | + <max_len>1000</max_len> | ||
| 20 | + <!-- maximum total time in seconds to run the fuzzer --> | ||
| 21 | + <max_total_time>300</max_total_time> | ||
| 22 | + <!-- memory usage limit in Mb --> | ||
| 23 | + <rss_limit_mb>4096</rss_limit_mb> | ||
| 24 | + </fuzztest> | ||
| 25 | +</fuzz_config> | ||
| @@ -0,0 +1,102 @@ | |||
| 1 | +/* | ||
| 2 | + * Copyright (c) 2026 Huawei Device Co., Ltd. | ||
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 4 | + * you may not use this file except in compliance with the License. | ||
| 5 | + * You may obtain a copy of the License at | ||
| 6 | + * | ||
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 8 | + * | ||
| 9 | + * Unless required by applicable law or agreed to in writing, software | ||
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 12 | + * See the License for the specific language governing permissions and | ||
| 13 | + * limitations under the License. | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | +#include "sourceserviceregisterdhext_fuzzer.h" | ||
| 17 | + | ||
| 18 | +#include <cstddef> | ||
| 19 | +#include <cstdint> | ||
| 20 | +#include <string> | ||
| 21 | +#include <memory> | ||
| 22 | +#include <unistd.h> | ||
| 23 | + | ||
| 24 | +#include <fuzzer/FuzzedDataProvider.h> | ||
| 25 | + | ||
| 26 | +#include "dcamera_source_callback.h" | ||
| 27 | +#include "distributed_camera_constants.h" | ||
| 28 | +#include "distributed_camera_source_service.h" | ||
| 29 | +#include "if_system_ability_manager.h" | ||
| 30 | +#include "iservice_registry.h" | ||
| 31 | + | ||
| 32 | +namespace OHOS { | ||
| 33 | +namespace DistributedHardware { | ||
| 34 | + | ||
| 35 | +void SourceServiceRegisterDHExtFuzzTest(const uint8_t* data, size_t size) | ||
| 36 | +{ | ||
| 37 | + FuzzedDataProvider fdp(data, size); | ||
| 38 | + std::string devId = fdp.ConsumeRandomLengthString(); | ||
| 39 | + std::string dhId = fdp.ConsumeRandomLengthString(); | ||
| 40 | + std::string reqId = fdp.ConsumeRandomLengthString(); | ||
| 41 | + EnableParam param; | ||
| 42 | + param.sourceVersion = fdp.ConsumeRandomLengthString(); | ||
| 43 | + param.sourceAttrs = fdp.ConsumeRandomLengthString(); | ||
| 44 | + param.sinkVersion = fdp.ConsumeRandomLengthString(); | ||
| 45 | + param.sinkAttrs = fdp.ConsumeRemainingBytesAsString(); | ||
| 46 | + auto sourceService = std::make_shared<DistributedCameraSourceService>( | ||
| 47 | + DISTRIBUTED_HARDWARE_CAMERA_SOURCE_SA_ID, true); | ||
| 48 | + if (sourceService == nullptr) { | ||
| 49 | + return; | ||
| 50 | + } | ||
| 51 | + sourceService->RegisterDistributedHardware(devId, dhId, reqId, param); | ||
| 52 | + uint32_t time = 500000; | ||
| 53 | + usleep(time); | ||
| 54 | +} | ||
| 55 | + | ||
| 56 | +void SourceServiceRegisterDHMultiCallFuzzTest(const uint8_t* data, size_t size) | ||
| 57 | +{ | ||
| 58 | + FuzzedDataProvider fdp(data, size); | ||
| 59 | + std::string devId = fdp.ConsumeRandomLengthString(); | ||
| 60 | + std::string dhId = fdp.ConsumeRandomLengthString(); | ||
| 61 | + std::string reqId = fdp.ConsumeRandomLengthString(); | ||
| 62 | + EnableParam param; | ||
| 63 | + param.sourceVersion = fdp.ConsumeRandomLengthString(); | ||
| 64 | + param.sourceAttrs = fdp.ConsumeRandomLengthString(); | ||
| 65 | + param.sinkVersion = fdp.ConsumeRandomLengthString(); | ||
| 66 | + param.sinkAttrs = fdp.ConsumeRemainingBytesAsString(); | ||
| 67 | + auto sourceService = std::make_shared<DistributedCameraSourceService>( | ||
| 68 | + DISTRIBUTED_HARDWARE_CAMERA_SOURCE_SA_ID, true); | ||
| 69 | + if (sourceService == nullptr) { | ||
| 70 | + return; | ||
| 71 | + } | ||
| 72 | + sourceService->RegisterDistributedHardware(devId, dhId, reqId, param); | ||
| 73 | + sourceService->UnregisterDistributedHardware(devId, dhId, reqId); | ||
| 74 | +} | ||
| 75 | + | ||
| 76 | +void SourceServiceRegisterDHEmptyParamFuzzTest(const uint8_t* data, size_t size) | ||
| 77 | +{ | ||
| 78 | + FuzzedDataProvider fdp(data, size); | ||
| 79 | + std::string devId = fdp.ConsumeRandomLengthString(); | ||
| 80 | + std::string dhId = fdp.ConsumeRandomLengthString(); | ||
| 81 | + std::string reqId = fdp.ConsumeRandomLengthString(); | ||
| 82 | + EnableParam param; | ||
| 83 | + auto sourceService = std::make_shared<DistributedCameraSourceService>( | ||
| 84 | + DISTRIBUTED_HARDWARE_CAMERA_SOURCE_SA_ID, true); | ||
| 85 | + if (sourceService == nullptr) { | ||
| 86 | + return; | ||
| 87 | + } | ||
| 88 | + sourceService->RegisterDistributedHardware(devId, dhId, reqId, param); | ||
| 89 | + sourceService->UnregisterDistributedHardware(devId, dhId, reqId); | ||
| 90 | + uint32_t time = 500000; | ||
| 91 | + usleep(time); | ||
| 92 | +} | ||
| 93 | +} | ||
| 94 | +} | ||
| 95 | + | ||
| 96 | +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) | ||
| 97 | +{ | ||
| 98 | + OHOS::DistributedHardware::SourceServiceRegisterDHExtFuzzTest(data, size); | ||
| 99 | + OHOS::DistributedHardware::SourceServiceRegisterDHMultiCallFuzzTest(data, size); | ||
| 100 | + OHOS::DistributedHardware::SourceServiceRegisterDHEmptyParamFuzzTest(data, size); | ||
| 101 | + return 0; | ||
| 102 | +} | ||
| @@ -0,0 +1,21 @@ | |||
| 1 | +/* | ||
| 2 | + * Copyright (c) 2026 Huawei Device Co., Ltd. | ||
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 4 | + * you may not use this file except in compliance with the License. | ||
| 5 | + * You may obtain a copy of the License at | ||
| 6 | + * | ||
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 8 | + * | ||
| 9 | + * Unless required by applicable law or agreed to in writing, software | ||
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 12 | + * See the License for the specific language governing permissions and | ||
| 13 | + * limitations under the License. | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | +#ifndef SOURCESERVICEREGISTERDHEXT_FUZZER_H | ||
| 17 | +#define SOURCESERVICEREGISTERDHEXT_FUZZER_H | ||
| 18 | + | ||
| 19 | +#define FUZZ_PROJECT_NAME "sourceserviceregisterdhext_fuzzer" | ||
| 20 | + | ||
| 21 | +#endif | ||
| @@ -3,7 +3,7 @@ | |||
| 3 | "name" : "dcamera", | 3 | "name" : "dcamera", |
| 4 | "path" : ["/system/bin/sa_main","/system/profile/dcamera.json"], | 4 | "path" : ["/system/bin/sa_main","/system/profile/dcamera.json"], |
| 5 | "uid" : "dcamera", | 5 | "uid" : "dcamera", |
| 6 | - "gid" : ["dcamera"], | 6 | + "gid" : ["dcamera","access_token"], |
| 7 | "ondemand" : true, | 7 | "ondemand" : true, |
| 8 | "apl" : "system_basic", | 8 | "apl" : "system_basic", |
| 9 | "permission" : [ | 9 | "permission" : [ |
| @@ -46,6 +46,8 @@ public: | |||
| 46 | uint64_t tokenId_; | 46 | uint64_t tokenId_; |
| 47 | std::string accountId_; | 47 | std::string accountId_; |
| 48 | bool eis_ = false; | 48 | bool eis_ = false; |
| 49 | + uint32_t triggerFirstTokenId_ = 0; | ||
| 50 | + int32_t triggerFirstUserId_ = -1; | ||
| 49 | 51 | ||
| 50 | public: | 52 | public: |
| 51 | int32_t Marshal(std::string& jsonStr); | 53 | int32_t Marshal(std::string& jsonStr); |
| @@ -54,6 +56,10 @@ public: | |||
| 54 | private: | 56 | private: |
| 55 | int32_t UmarshalValue(cJSON* rootValue); | 57 | int32_t UmarshalValue(cJSON* rootValue); |
| 56 | int32_t UmarshalSettings(cJSON* valueJson, std::shared_ptr<DCameraCaptureInfo>& captureInfo); | 58 | int32_t UmarshalSettings(cJSON* valueJson, std::shared_ptr<DCameraCaptureInfo>& captureInfo); |
| 59 | + int32_t MarshalValue(cJSON* captureInfos, cJSON* rootValue); | ||
| 60 | + int32_t MarshalSettings(cJSON* captureSettings, std::shared_ptr<DCameraCaptureInfo>& capture, cJSON* rootValue); | ||
| 61 | + void UmarshalControlInfo(cJSON* rootValue); | ||
| 62 | + void UmarshalControlExtraInfo(cJSON* rootValue); | ||
| 57 | }; | 63 | }; |
| 58 | } // namespace DistributedHardware | 64 | } // namespace DistributedHardware |
| 59 | } // namespace OHOS | 65 | } // namespace OHOS |
| @@ -45,6 +45,8 @@ public: | |||
| 45 | virtual int32_t ResumeDistributedHardware(const std::string &networkId) = 0; | 45 | virtual int32_t ResumeDistributedHardware(const std::string &networkId) = 0; |
| 46 | virtual int32_t StopDistributedHardware(const std::string &networkId) = 0; | 46 | virtual int32_t StopDistributedHardware(const std::string &networkId) = 0; |
| 47 | virtual void SetTokenId(uint64_t token) = 0; | 47 | virtual void SetTokenId(uint64_t token) = 0; |
| 48 | + virtual void SetEnableFirstTokenId(uint32_t tokenId) = 0; | ||
| 49 | + virtual void SetTriggerFirstTokenId(uint32_t tokenId) = 0; | ||
| 48 | }; | 50 | }; |
| 49 | } // namespace DistributedHardware | 51 | } // namespace DistributedHardware |
| 50 | } // namespace OHOS | 52 | } // namespace OHOS |
| @@ -33,6 +33,31 @@ int32_t DCameraCaptureInfoCmd::Marshal(std::string& jsonStr) | |||
| 33 | cJSON *captureInfos = cJSON_CreateArray(); | 33 | cJSON *captureInfos = cJSON_CreateArray(); |
| 34 | CHECK_NULL_FREE_RETURN(captureInfos, DCAMERA_BAD_VALUE, rootValue); | 34 | CHECK_NULL_FREE_RETURN(captureInfos, DCAMERA_BAD_VALUE, rootValue); |
| 35 | cJSON_AddItemToObject(rootValue, "Value", captureInfos); | 35 | cJSON_AddItemToObject(rootValue, "Value", captureInfos); |
| 36 | + int32_t ret = MarshalValue(captureInfos, rootValue); | ||
| 37 | + if (ret != DCAMERA_OK) { | ||
| 38 | + return ret; | ||
| 39 | + } | ||
| 40 | + cJSON_AddNumberToObject(rootValue, "mode", sceneMode_); | ||
| 41 | + cJSON_AddNumberToObject(rootValue, "userId", userId_); | ||
| 42 | + cJSON_AddNumberToObject(rootValue, "tokenId", tokenId_); | ||
| 43 | + cJSON_AddStringToObject(rootValue, "accountId", accountId_.c_str()); | ||
| 44 | + cJSON_AddBoolToObject(rootValue, "eis", eis_); | ||
| 45 | + cJSON_AddNumberToObject(rootValue, KEY_TRIGGER_FIRST_TOKENID, triggerFirstTokenId_); | ||
| 46 | + cJSON_AddNumberToObject(rootValue, KEY_TRIGGER_FIRST_USERID, triggerFirstUserId_); | ||
| 47 | + | ||
| 48 | + char *data = cJSON_Print(rootValue); | ||
| 49 | + if (data == nullptr) { | ||
| 50 | + cJSON_Delete(rootValue); | ||
| 51 | + return DCAMERA_BAD_VALUE; | ||
| 52 | + } | ||
| 53 | + jsonStr = std::string(data); | ||
| 54 | + cJSON_Delete(rootValue); | ||
| 55 | + cJSON_free(data); | ||
| 56 | + return DCAMERA_OK; | ||
| 57 | +} | ||
| 58 | + | ||
| 59 | +int32_t DCameraCaptureInfoCmd::MarshalValue(cJSON *captureInfos, cJSON *rootValue) | ||
| 60 | +{ | ||
| 36 | for (auto iter = value_.begin(); iter != value_.end(); iter++) { | 61 | for (auto iter = value_.begin(); iter != value_.end(); iter++) { |
| 37 | std::shared_ptr<DCameraCaptureInfo> capture = *iter; | 62 | std::shared_ptr<DCameraCaptureInfo> capture = *iter; |
| 38 | CHECK_NULL_FREE_RETURN(capture, DCAMERA_BAD_VALUE, rootValue); | 63 | CHECK_NULL_FREE_RETURN(capture, DCAMERA_BAD_VALUE, rootValue); |
| @@ -49,29 +74,25 @@ int32_t DCameraCaptureInfoCmd::Marshal(std::string& jsonStr) | |||
| 49 | cJSON *captureSettings = cJSON_CreateArray(); | 74 | cJSON *captureSettings = cJSON_CreateArray(); |
| 50 | CHECK_NULL_FREE_RETURN(captureSettings, DCAMERA_BAD_VALUE, rootValue); | 75 | CHECK_NULL_FREE_RETURN(captureSettings, DCAMERA_BAD_VALUE, rootValue); |
| 51 | cJSON_AddItemToObject(captureInfo, "CaptureSettings", captureSettings); | 76 | cJSON_AddItemToObject(captureInfo, "CaptureSettings", captureSettings); |
| 52 | - for (auto settingIter = capture->captureSettings_.begin(); | 77 | + int32_t ret = MarshalSettings(captureSettings, capture, rootValue); |
| 53 | - settingIter != capture->captureSettings_.end(); settingIter++) { | 78 | + if (ret != DCAMERA_OK) { |
| 54 | - cJSON *captureSetting = cJSON_CreateObject(); | 79 | + return ret; |
| 55 | - CHECK_NULL_FREE_RETURN(captureSetting, DCAMERA_BAD_VALUE, rootValue); | ||
| 56 | - cJSON_AddNumberToObject(captureSetting, "SettingType", (*settingIter)->type_); | ||
| 57 | - cJSON_AddStringToObject(captureSetting, "SettingValue", (*settingIter)->value_.c_str()); | ||
| 58 | - cJSON_AddItemToArray(captureSettings, captureSetting); | ||
| 59 | } | 80 | } |
| 60 | } | 81 | } |
| 61 | - cJSON_AddNumberToObject(rootValue, "mode", sceneMode_); | 82 | + return DCAMERA_OK; |
| 62 | - cJSON_AddNumberToObject(rootValue, "userId", userId_); | 83 | +} |
| 63 | - cJSON_AddNumberToObject(rootValue, "tokenId", tokenId_); | ||
| 64 | - cJSON_AddStringToObject(rootValue, "accountId", accountId_.c_str()); | ||
| 65 | - cJSON_AddBoolToObject(rootValue, "eis", eis_); | ||
| 66 | 84 | ||
| 67 | - char *data = cJSON_Print(rootValue); | 85 | +int32_t DCameraCaptureInfoCmd::MarshalSettings(cJSON *captureSettings, |
| 68 | - if (data == nullptr) { | 86 | + std::shared_ptr<DCameraCaptureInfo>& capture, cJSON *rootValue) |
| 69 | - cJSON_Delete(rootValue); | 87 | +{ |
| 70 | - return DCAMERA_BAD_VALUE; | 88 | + for (auto settingIter = capture->captureSettings_.begin(); |
| 89 | + settingIter != capture->captureSettings_.end(); settingIter++) { | ||
| 90 | + cJSON *captureSetting = cJSON_CreateObject(); | ||
| 91 | + CHECK_NULL_FREE_RETURN(captureSetting, DCAMERA_BAD_VALUE, rootValue); | ||
| 92 | + cJSON_AddNumberToObject(captureSetting, "SettingType", (*settingIter)->type_); | ||
| 93 | + cJSON_AddStringToObject(captureSetting, "SettingValue", (*settingIter)->value_.c_str()); | ||
| 94 | + cJSON_AddItemToArray(captureSettings, captureSetting); | ||
| 71 | } | 95 | } |
| 72 | - jsonStr = std::string(data); | ||
| 73 | - cJSON_Delete(rootValue); | ||
| 74 | - cJSON_free(data); | ||
| 75 | return DCAMERA_OK; | 96 | return DCAMERA_OK; |
| 76 | } | 97 | } |
| 77 | 98 | ||
| @@ -98,7 +119,13 @@ int32_t DCameraCaptureInfoCmd::Unmarshal(const std::string& jsonStr) | |||
| 98 | command_ = command->valuestring; | 119 | command_ = command->valuestring; |
| 99 | 120 | ||
| 100 | int32_t ret = UmarshalValue(rootValue); | 121 | int32_t ret = UmarshalValue(rootValue); |
| 122 | + UmarshalControlInfo(rootValue); | ||
| 123 | + cJSON_Delete(rootValue); | ||
| 124 | + return ret; | ||
| 125 | +} | ||
| 101 | 126 | ||
| 127 | +void DCameraCaptureInfoCmd::UmarshalControlInfo(cJSON *rootValue) | ||
| 128 | +{ | ||
| 102 | cJSON *mode = cJSON_GetObjectItemCaseSensitive(rootValue, "mode"); | 129 | cJSON *mode = cJSON_GetObjectItemCaseSensitive(rootValue, "mode"); |
| 103 | if (mode == nullptr || !cJSON_IsNumber(mode)) { | 130 | if (mode == nullptr || !cJSON_IsNumber(mode)) { |
| 104 | sceneMode_ = 0; | 131 | sceneMode_ = 0; |
| @@ -123,12 +150,27 @@ int32_t DCameraCaptureInfoCmd::Unmarshal(const std::string& jsonStr) | |||
| 123 | } else { | 150 | } else { |
| 124 | accountId_ = accountId->valuestring; | 151 | accountId_ = accountId->valuestring; |
| 125 | } | 152 | } |
| 153 | + UmarshalControlExtraInfo(rootValue); | ||
| 154 | +} | ||
| 155 | + | ||
| 156 | +void DCameraCaptureInfoCmd::UmarshalControlExtraInfo(cJSON *rootValue) | ||
| 157 | +{ | ||
| 126 | cJSON *eis = cJSON_GetObjectItemCaseSensitive(rootValue, "eis"); | 158 | cJSON *eis = cJSON_GetObjectItemCaseSensitive(rootValue, "eis"); |
| 127 | if (eis != nullptr && cJSON_IsBool(eis) && cJSON_IsTrue(eis)) { | 159 | if (eis != nullptr && cJSON_IsBool(eis) && cJSON_IsTrue(eis)) { |
| 128 | eis_ = true; | 160 | eis_ = true; |
| 129 | } | 161 | } |
| 130 | - cJSON_Delete(rootValue); | 162 | + cJSON *triggerFirstTokenId = cJSON_GetObjectItemCaseSensitive(rootValue, KEY_TRIGGER_FIRST_TOKENID); |
| 131 | - return ret; | 163 | + if (triggerFirstTokenId == nullptr || !cJSON_IsNumber(triggerFirstTokenId)) { |
| 164 | + triggerFirstTokenId_ = 0; | ||
| 165 | + } else { | ||
| 166 | + triggerFirstTokenId_ = static_cast<uint32_t>(triggerFirstTokenId->valuedouble); | ||
| 167 | + } | ||
| 168 | + cJSON *triggerFirstUserId = cJSON_GetObjectItemCaseSensitive(rootValue, KEY_TRIGGER_FIRST_USERID); | ||
| 169 | + if (triggerFirstUserId == nullptr || !cJSON_IsNumber(triggerFirstUserId)) { | ||
| 170 | + triggerFirstUserId_ = -1; | ||
| 171 | + } else { | ||
| 172 | + triggerFirstUserId_ = triggerFirstUserId->valueint; | ||
| 173 | + } | ||
| 132 | } | 174 | } |
| 133 | 175 | ||
| 134 | int32_t DCameraCaptureInfoCmd::UmarshalValue(cJSON *rootValue) | 176 | int32_t DCameraCaptureInfoCmd::UmarshalValue(cJSON *rootValue) |
| @@ -531,5 +531,143 @@ HWTEST_F(DCameraCaptureInfoCmdlTest, Unmarshal_004, TestSize.Level1) | |||
| 531 | EXPECT_EQ(DCAMERA_BAD_VALUE, ret); | 531 | EXPECT_EQ(DCAMERA_BAD_VALUE, ret); |
| 532 | } | 532 | } |
| 533 | 533 | ||
| 534 | +/** | ||
| 535 | + * @tc.name: Unmarshal_005. | ||
| 536 | + * @tc.desc: Verify Unmarshal with triggerFirstTokenId and triggerFirstUserId fields present. | ||
| 537 | + * @tc.type: FUNC | ||
| 538 | + * @tc.require: Issue Number | ||
| 539 | + */ | ||
| 540 | +HWTEST_F(DCameraCaptureInfoCmdlTest, Unmarshal_005, TestSize.Level1) | ||
| 541 | +{ | ||
| 542 | + static const std::string jsonWithTriggerFields = R"({ | ||
| 543 | + "Type": "OPERATION", | ||
| 544 | + "dhId": "camera_0", | ||
| 545 | + "Command": "CAPTURE", | ||
| 546 | + "Value": [ | ||
| 547 | + {"Width": 1920, "Height": 1080, "Format": 1, "DataSpace": 1, | ||
| 548 | + "IsCapture": true, "EncodeType": 1, "StreamType": 1, | ||
| 549 | + "CaptureSettings": [{"SettingType": 1, "SettingValue": "TestSetting"}]} | ||
| 550 | + ], | ||
| 551 | + "mode": 1, | ||
| 552 | + "userId": 100, | ||
| 553 | + "tokenId": 200, | ||
| 554 | + "accountId": "accountId", | ||
| 555 | + "eis": true, | ||
| 556 | + "triggerFirstTokenId": 12345, | ||
| 557 | + "triggerFirstUserId": 100 | ||
| 558 | + })"; | ||
| 559 | + DCameraCaptureInfoCmd cmd; | ||
| 560 | + int32_t ret = cmd.Unmarshal(jsonWithTriggerFields); | ||
| 561 | + EXPECT_EQ(DCAMERA_OK, ret); | ||
| 562 | + EXPECT_EQ(cmd.triggerFirstTokenId_, static_cast<uint32_t>(12345)); | ||
| 563 | + EXPECT_EQ(cmd.triggerFirstUserId_, 100); | ||
| 564 | + EXPECT_EQ(cmd.sceneMode_, 1); | ||
| 565 | + EXPECT_EQ(cmd.userId_, 100); | ||
| 566 | + EXPECT_EQ(cmd.tokenId_, static_cast<uint64_t>(200)); | ||
| 567 | + EXPECT_TRUE(cmd.eis_); | ||
| 568 | +} | ||
| 569 | + | ||
| 570 | +/** | ||
| 571 | + * @tc.name: Unmarshal_006. | ||
| 572 | + * @tc.desc: Verify Unmarshal without triggerFirstTokenId and triggerFirstUserId fields defaults to 0 and -1. | ||
| 573 | + * @tc.type: FUNC | ||
| 574 | + * @tc.require: Issue Number | ||
| 575 | + */ | ||
| 576 | +HWTEST_F(DCameraCaptureInfoCmdlTest, Unmarshal_006, TestSize.Level1) | ||
| 577 | +{ | ||
| 578 | + static const std::string jsonWithoutTriggerFields = R"({ | ||
| 579 | + "Type": "OPERATION", | ||
| 580 | + "dhId": "camera_0", | ||
| 581 | + "Command": "CAPTURE", | ||
| 582 | + "Value": [ | ||
| 583 | + {"Width": 1920, "Height": 1080, "Format": 1, "DataSpace": 1, | ||
| 584 | + "IsCapture": true, "EncodeType": 1, "StreamType": 1, | ||
| 585 | + "CaptureSettings": [{"SettingType": 1, "SettingValue": "TestSetting"}]} | ||
| 586 | + ], | ||
| 587 | + "mode": 0, | ||
| 588 | + "userId": 0, | ||
| 589 | + "tokenId": 0, | ||
| 590 | + "accountId": "" | ||
| 591 | + })"; | ||
| 592 | + DCameraCaptureInfoCmd cmd; | ||
| 593 | + int32_t ret = cmd.Unmarshal(jsonWithoutTriggerFields); | ||
| 594 | + EXPECT_EQ(DCAMERA_OK, ret); | ||
| 595 | + EXPECT_EQ(cmd.triggerFirstTokenId_, static_cast<uint32_t>(0)); | ||
| 596 | + EXPECT_EQ(cmd.triggerFirstUserId_, -1); | ||
| 597 | + EXPECT_FALSE(cmd.eis_); | ||
| 598 | +} | ||
| 599 | + | ||
| 600 | +/** | ||
| 601 | + * @tc.name: Unmarshal_007. | ||
| 602 | + * @tc.desc: Verify Unmarshal with triggerFirstTokenId/triggerFirstUserId of wrong type defaults to 0 and -1. | ||
| 603 | + * @tc.type: FUNC | ||
| 604 | + * @tc.require: Issue Number | ||
| 605 | + */ | ||
| 606 | +HWTEST_F(DCameraCaptureInfoCmdlTest, Unmarshal_007, TestSize.Level1) | ||
| 607 | +{ | ||
| 608 | + static const std::string jsonTriggerWrongType = R"({ | ||
| 609 | + "Type": "OPERATION", | ||
| 610 | + "dhId": "camera_0", | ||
| 611 | + "Command": "CAPTURE", | ||
| 612 | + "Value": [ | ||
| 613 | + {"Width": 1920, "Height": 1080, "Format": 1, "DataSpace": 1, | ||
| 614 | + "IsCapture": true, "EncodeType": 1, "StreamType": 1, | ||
| 615 | + "CaptureSettings": [{"SettingType": 1, "SettingValue": "TestSetting"}]} | ||
| 616 | + ], | ||
| 617 | + "mode": 1, | ||
| 618 | + "userId": 100, | ||
| 619 | + "tokenId": 200, | ||
| 620 | + "accountId": "accountId", | ||
| 621 | + "triggerFirstTokenId": "not_a_number", | ||
| 622 | + "triggerFirstUserId": "not_a_number" | ||
| 623 | + })"; | ||
| 624 | + DCameraCaptureInfoCmd cmd; | ||
| 625 | + int32_t ret = cmd.Unmarshal(jsonTriggerWrongType); | ||
| 626 | + EXPECT_EQ(DCAMERA_OK, ret); | ||
| 627 | + EXPECT_EQ(cmd.triggerFirstTokenId_, static_cast<uint32_t>(0)); | ||
| 628 | + EXPECT_EQ(cmd.triggerFirstUserId_, -1); | ||
| 629 | +} | ||
| 630 | + | ||
| 631 | +/** | ||
| 632 | + * @tc.name: Marshal_002. | ||
| 633 | + * @tc.desc: Verify Marshal with empty value_ vector. | ||
| 634 | + * @tc.type: FUNC | ||
| 635 | + * @tc.require: Issue Number | ||
| 636 | + */ | ||
| 637 | +HWTEST_F(DCameraCaptureInfoCmdlTest, Marshal_002, TestSize.Level1) | ||
| 638 | +{ | ||
| 639 | + DCameraCaptureInfoCmd cmd; | ||
| 640 | + cmd.dhId_ = "camera_0"; | ||
| 641 | + cmd.type_ = "OPERATION"; | ||
| 642 | + cmd.command_ = "CAPTURE"; | ||
| 643 | + cmd.triggerFirstTokenId_ = 99999; | ||
| 644 | + cmd.triggerFirstUserId_ = 200; | ||
| 645 | + std::string jsonStr; | ||
| 646 | + int32_t ret = cmd.Marshal(jsonStr); | ||
| 647 | + EXPECT_EQ(DCAMERA_OK, ret); | ||
| 648 | + EXPECT_NE(jsonStr.find("triggerFirstTokenId"), std::string::npos); | ||
| 649 | + EXPECT_NE(jsonStr.find("99999"), std::string::npos); | ||
| 650 | + EXPECT_NE(jsonStr.find("triggerFirstUserId"), std::string::npos); | ||
| 651 | + EXPECT_NE(jsonStr.find("200"), std::string::npos); | ||
| 652 | +} | ||
| 653 | + | ||
| 654 | +/** | ||
| 655 | + * @tc.name: Marshal_003. | ||
| 656 | + * @tc.desc: Verify Marshal with null capture in value_ vector returns DCAMERA_BAD_VALUE. | ||
| 657 | + * @tc.type: FUNC | ||
| 658 | + * @tc.require: Issue Number | ||
| 659 | + */ | ||
| 660 | +HWTEST_F(DCameraCaptureInfoCmdlTest, Marshal_003, TestSize.Level1) | ||
| 661 | +{ | ||
| 662 | + DCameraCaptureInfoCmd cmd; | ||
| 663 | + cmd.dhId_ = "camera_0"; | ||
| 664 | + cmd.type_ = "OPERATION"; | ||
| 665 | + cmd.command_ = "CAPTURE"; | ||
| 666 | + std::shared_ptr<DCameraCaptureInfo> nullCapture = nullptr; | ||
| 667 | + cmd.value_.push_back(nullCapture); | ||
| 668 | + std::string jsonStr; | ||
| 669 | + int32_t ret = cmd.Marshal(jsonStr); | ||
| 670 | + EXPECT_EQ(DCAMERA_BAD_VALUE, ret); | ||
| 671 | +} | ||
| 534 | } // namespace DistributedHardware | 672 | } // namespace DistributedHardware |
| 535 | } // namespace OHOS | 673 | } // namespace OHOS |
| @@ -12,12 +12,9 @@ | |||
| 12 | * See the License for the specific language governing permissions and | 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. | 13 | * limitations under the License. |
| 14 | */ | 14 | */ |
| 15 | - | ||
| 16 | #ifndef OHOS_DCAMERA_CLIENT_DEMO_H | 15 | #ifndef OHOS_DCAMERA_CLIENT_DEMO_H |
| 17 | #define OHOS_DCAMERA_CLIENT_DEMO_H | 16 | #define OHOS_DCAMERA_CLIENT_DEMO_H |
| 18 | - | ||
| 19 | #include <fstream> | 17 | #include <fstream> |
| 20 | - | ||
| 21 | #include "anonymous_string.h" | 18 | #include "anonymous_string.h" |
| 22 | #include "camera_device_ability_items.h" | 19 | #include "camera_device_ability_items.h" |
| 23 | #include "camera_input.h" | 20 | #include "camera_input.h" |
| @@ -38,7 +35,6 @@ | |||
| 38 | #include "surface.h" | 35 | #include "surface.h" |
| 39 | #include "video_output.h" | 36 | #include "video_output.h" |
| 40 | #include "iconsumer_surface.h" | 37 | #include "iconsumer_surface.h" |
| 41 | - | ||
| 42 | namespace OHOS { | 38 | namespace OHOS { |
| 43 | namespace DistributedHardware { | 39 | namespace DistributedHardware { |
| 44 | class DemoDCameraBufferConsumerListener : public IBufferConsumerListener { | 40 | class DemoDCameraBufferConsumerListener : public IBufferConsumerListener { |
| @@ -46,7 +42,6 @@ public: | |||
| 46 | explicit DemoDCameraBufferConsumerListener(const sptr<IConsumerSurface>& surface) : surface_(surface) | 42 | explicit DemoDCameraBufferConsumerListener(const sptr<IConsumerSurface>& surface) : surface_(surface) |
| 47 | { | 43 | { |
| 48 | } | 44 | } |
| 49 | - | ||
| 50 | void OnBufferAvailable() | 45 | void OnBufferAvailable() |
| 51 | { | 46 | { |
| 52 | DHLOGI("DemoDCameraBufferConsumerListener::OnBufferAvailable"); | 47 | DHLOGI("DemoDCameraBufferConsumerListener::OnBufferAvailable"); |
| @@ -54,7 +49,6 @@ public: | |||
| 54 | DHLOGE("DemoDCameraBufferConsumerListener surface is null"); | 49 | DHLOGE("DemoDCameraBufferConsumerListener surface is null"); |
| 55 | return; | 50 | return; |
| 56 | } | 51 | } |
| 57 | - | ||
| 58 | int32_t flushFence = 0; | 52 | int32_t flushFence = 0; |
| 59 | int64_t timestamp = 0; | 53 | int64_t timestamp = 0; |
| 60 | OHOS::Rect damage; | 54 | OHOS::Rect damage; |
| @@ -64,31 +58,25 @@ public: | |||
| 64 | DHLOGE("DemoDCameraBufferConsumerListener AcquireBuffer failed"); | 58 | DHLOGE("DemoDCameraBufferConsumerListener AcquireBuffer failed"); |
| 65 | return; | 59 | return; |
| 66 | } | 60 | } |
| 67 | - | ||
| 68 | width_ = buffer->GetWidth(); | 61 | width_ = buffer->GetWidth(); |
| 69 | height_ = buffer->GetHeight(); | 62 | height_ = buffer->GetHeight(); |
| 70 | size_ = buffer->GetSize(); | 63 | size_ = buffer->GetSize(); |
| 71 | address_ = static_cast<char *>(buffer->GetVirAddr()); | 64 | address_ = static_cast<char *>(buffer->GetVirAddr()); |
| 72 | buffer->GetExtraData()->ExtraGet("dataSize", dataSize_); | 65 | buffer->GetExtraData()->ExtraGet("dataSize", dataSize_); |
| 73 | - | ||
| 74 | #ifdef DCAMERA_YUV | 66 | #ifdef DCAMERA_YUV |
| 75 | actualSize_ = width_ * height_ * YUV_BYTES_PER_PIXEL / Y2UV_RATIO; | 67 | actualSize_ = width_ * height_ * YUV_BYTES_PER_PIXEL / Y2UV_RATIO; |
| 76 | #else | 68 | #else |
| 77 | actualSize_ = width_ * height_ * RGB_BYTES_PER_PIXEL; | 69 | actualSize_ = width_ * height_ * RGB_BYTES_PER_PIXEL; |
| 78 | #endif | 70 | #endif |
| 79 | - | ||
| 80 | SaveFile(); | 71 | SaveFile(); |
| 81 | surface_->ReleaseBuffer(buffer, -1); | 72 | surface_->ReleaseBuffer(buffer, -1); |
| 82 | } | 73 | } |
| 83 | - | ||
| 84 | protected: | 74 | protected: |
| 85 | virtual void SaveFile() const = 0; | 75 | virtual void SaveFile() const = 0; |
| 86 | - | ||
| 87 | protected: | 76 | protected: |
| 88 | constexpr static int32_t Y2UV_RATIO = 2; | 77 | constexpr static int32_t Y2UV_RATIO = 2; |
| 89 | constexpr static int32_t YUV_BYTES_PER_PIXEL = 3; | 78 | constexpr static int32_t YUV_BYTES_PER_PIXEL = 3; |
| 90 | constexpr static int32_t RGB_BYTES_PER_PIXEL = 4; | 79 | constexpr static int32_t RGB_BYTES_PER_PIXEL = 4; |
| 91 | - | ||
| 92 | char *address_ = nullptr; | 80 | char *address_ = nullptr; |
| 93 | int32_t actualSize_ = 0; | 81 | int32_t actualSize_ = 0; |
| 94 | int32_t dataSize_ = 0; | 82 | int32_t dataSize_ = 0; |
| @@ -97,14 +85,12 @@ protected: | |||
| 97 | int32_t size_ = 0; | 85 | int32_t size_ = 0; |
| 98 | sptr<IConsumerSurface> surface_; | 86 | sptr<IConsumerSurface> surface_; |
| 99 | }; | 87 | }; |
| 100 | - | ||
| 101 | class DemoDCameraPhotoSurfaceListener : public DemoDCameraBufferConsumerListener { | 88 | class DemoDCameraPhotoSurfaceListener : public DemoDCameraBufferConsumerListener { |
| 102 | public: | 89 | public: |
| 103 | explicit DemoDCameraPhotoSurfaceListener(const sptr<IConsumerSurface>& surface) | 90 | explicit DemoDCameraPhotoSurfaceListener(const sptr<IConsumerSurface>& surface) |
| 104 | : DemoDCameraBufferConsumerListener(surface) | 91 | : DemoDCameraBufferConsumerListener(surface) |
| 105 | { | 92 | { |
| 106 | } | 93 | } |
| 107 | - | ||
| 108 | protected: | 94 | protected: |
| 109 | void SaveFile() const override | 95 | void SaveFile() const override |
| 110 | { | 96 | { |
| @@ -114,7 +100,6 @@ protected: | |||
| 114 | DHLOGE("DemoDCameraPhotoSurfaceListener invalid params, dataSize: %{public}d", dataSize_); | 100 | DHLOGE("DemoDCameraPhotoSurfaceListener invalid params, dataSize: %{public}d", dataSize_); |
| 115 | return; | 101 | return; |
| 116 | } | 102 | } |
| 117 | - | ||
| 118 | std::ofstream ofs; | 103 | std::ofstream ofs; |
| 119 | std::cout << "saving photo ..." << std::endl; | 104 | std::cout << "saving photo ..." << std::endl; |
| 120 | std::string fileName = "/data/log/dcamera_photo_" + std::to_string(GetNowTimeStampMs()) + ".jpg"; | 105 | std::string fileName = "/data/log/dcamera_photo_" + std::to_string(GetNowTimeStampMs()) + ".jpg"; |
| @@ -128,14 +113,12 @@ protected: | |||
| 128 | std::cout << "saving photo success" << std::endl; | 113 | std::cout << "saving photo success" << std::endl; |
| 129 | } | 114 | } |
| 130 | }; | 115 | }; |
| 131 | - | ||
| 132 | class DemoDCameraPreviewSurfaceListener : public DemoDCameraBufferConsumerListener { | 116 | class DemoDCameraPreviewSurfaceListener : public DemoDCameraBufferConsumerListener { |
| 133 | public: | 117 | public: |
| 134 | explicit DemoDCameraPreviewSurfaceListener(const sptr<IConsumerSurface>& surface) | 118 | explicit DemoDCameraPreviewSurfaceListener(const sptr<IConsumerSurface>& surface) |
| 135 | : DemoDCameraBufferConsumerListener(surface) | 119 | : DemoDCameraBufferConsumerListener(surface) |
| 136 | { | 120 | { |
| 137 | } | 121 | } |
| 138 | - | ||
| 139 | protected: | 122 | protected: |
| 140 | void SaveFile() const override | 123 | void SaveFile() const override |
| 141 | { | 124 | { |
| @@ -145,7 +128,6 @@ protected: | |||
| 145 | DHLOGE("DemoDCameraPreviewSurfaceListener invalid params, actualSize: %{public}d", actualSize_); | 128 | DHLOGE("DemoDCameraPreviewSurfaceListener invalid params, actualSize: %{public}d", actualSize_); |
| 146 | return; | 129 | return; |
| 147 | } | 130 | } |
| 148 | - | ||
| 149 | std::ofstream ofs; | 131 | std::ofstream ofs; |
| 150 | std::cout << "saving preview ..." << std::endl; | 132 | std::cout << "saving preview ..." << std::endl; |
| 151 | std::string resolution = std::to_string(width_) + "_" + std::to_string(height_); | 133 | std::string resolution = std::to_string(width_) + "_" + std::to_string(height_); |
| @@ -160,14 +142,12 @@ protected: | |||
| 160 | std::cout << "saving preview success" << std::endl; | 142 | std::cout << "saving preview success" << std::endl; |
| 161 | } | 143 | } |
| 162 | }; | 144 | }; |
| 163 | - | ||
| 164 | class DemoDCameraVideoSurfaceListener : public DemoDCameraBufferConsumerListener { | 145 | class DemoDCameraVideoSurfaceListener : public DemoDCameraBufferConsumerListener { |
| 165 | public: | 146 | public: |
| 166 | explicit DemoDCameraVideoSurfaceListener(const sptr<IConsumerSurface>& surface) | 147 | explicit DemoDCameraVideoSurfaceListener(const sptr<IConsumerSurface>& surface) |
| 167 | : DemoDCameraBufferConsumerListener(surface) | 148 | : DemoDCameraBufferConsumerListener(surface) |
| 168 | { | 149 | { |
| 169 | } | 150 | } |
| 170 | - | ||
| 171 | protected: | 151 | protected: |
| 172 | void SaveFile() const override | 152 | void SaveFile() const override |
| 173 | { | 153 | { |
| @@ -177,7 +157,6 @@ protected: | |||
| 177 | DHLOGE("DemoDCameraVideoSurfaceListener invalid params, actualSize: %{public}d", actualSize_); | 157 | DHLOGE("DemoDCameraVideoSurfaceListener invalid params, actualSize: %{public}d", actualSize_); |
| 178 | return; | 158 | return; |
| 179 | } | 159 | } |
| 180 | - | ||
| 181 | std::ofstream ofs; | 160 | std::ofstream ofs; |
| 182 | std::cout << "saving video ..." << std::endl; | 161 | std::cout << "saving video ..." << std::endl; |
| 183 | std::string resolution = std::to_string(width_) + "_" + std::to_string(height_); | 162 | std::string resolution = std::to_string(width_) + "_" + std::to_string(height_); |
| @@ -192,122 +171,101 @@ protected: | |||
| 192 | std::cout << "saving video success" << std::endl; | 171 | std::cout << "saving video success" << std::endl; |
| 193 | } | 172 | } |
| 194 | }; | 173 | }; |
| 195 | - | ||
| 196 | class DemoDCameraPhotoCallback : public CameraStandard::PhotoStateCallback { | 174 | class DemoDCameraPhotoCallback : public CameraStandard::PhotoStateCallback { |
| 197 | public: | 175 | public: |
| 198 | void OnCaptureStarted(const int32_t captureID) const | 176 | void OnCaptureStarted(const int32_t captureID) const |
| 199 | { | 177 | { |
| 200 | DHLOGI("DemoDCameraPhotoCallback::OnCaptureStarted captureID: %{public}d", captureID); | 178 | DHLOGI("DemoDCameraPhotoCallback::OnCaptureStarted captureID: %{public}d", captureID); |
| 201 | } | 179 | } |
| 202 | - | ||
| 203 | void OnCaptureStarted(const int32_t captureID, uint32_t exposureTime) const | 180 | void OnCaptureStarted(const int32_t captureID, uint32_t exposureTime) const |
| 204 | { | 181 | { |
| 205 | DHLOGI("DemoDCameraPhotoCallback::OnCaptureStarted captureID: %{public}d, exposureTime: %{public}u", | 182 | DHLOGI("DemoDCameraPhotoCallback::OnCaptureStarted captureID: %{public}d, exposureTime: %{public}u", |
| 206 | captureID, exposureTime); | 183 | captureID, exposureTime); |
| 207 | } | 184 | } |
| 208 | - | ||
| 209 | void OnCaptureEnded(const int32_t captureID, int32_t frameCount) const | 185 | void OnCaptureEnded(const int32_t captureID, int32_t frameCount) const |
| 210 | { | 186 | { |
| 211 | DHLOGI("DemoDCameraPhotoCallback::OnCaptureEnded captureID: %{public}d frameCount: %{public}d", | 187 | DHLOGI("DemoDCameraPhotoCallback::OnCaptureEnded captureID: %{public}d frameCount: %{public}d", |
| 212 | captureID, frameCount); | 188 | captureID, frameCount); |
| 213 | } | 189 | } |
| 214 | - | ||
| 215 | void OnFrameShutter(const int32_t captureId, const uint64_t timestamp) const | 190 | void OnFrameShutter(const int32_t captureId, const uint64_t timestamp) const |
| 216 | { | 191 | { |
| 217 | DHLOGI("DemoDCameraPhotoCallback::OnFrameShutter captureID: %{public}d timestamp: %{public}" PRIu64, | 192 | DHLOGI("DemoDCameraPhotoCallback::OnFrameShutter captureID: %{public}d timestamp: %{public}" PRIu64, |
| 218 | captureId, timestamp); | 193 | captureId, timestamp); |
| 219 | } | 194 | } |
| 220 | - | ||
| 221 | void OnFrameShutterEnd(const int32_t captureId, const uint64_t timestamp) const | 195 | void OnFrameShutterEnd(const int32_t captureId, const uint64_t timestamp) const |
| 222 | { | 196 | { |
| 223 | DHLOGI("DemoDCameraPhotoCallback::OnFrameShutterEnd captureID: %{public}d timestamp: %{public}" PRIu64, | 197 | DHLOGI("DemoDCameraPhotoCallback::OnFrameShutterEnd captureID: %{public}d timestamp: %{public}" PRIu64, |
| 224 | captureId, timestamp); | 198 | captureId, timestamp); |
| 225 | } | 199 | } |
| 226 | - | ||
| 227 | void OnCaptureReady(const int32_t captureId, const uint64_t timestamp) const | 200 | void OnCaptureReady(const int32_t captureId, const uint64_t timestamp) const |
| 228 | { | 201 | { |
| 229 | DHLOGI("DemoDCameraPhotoCallback::OnCaptureReady captureID: %{public}d timestamp: %{public}" PRIu64, | 202 | DHLOGI("DemoDCameraPhotoCallback::OnCaptureReady captureID: %{public}d timestamp: %{public}" PRIu64, |
| 230 | captureId, timestamp); | 203 | captureId, timestamp); |
| 231 | } | 204 | } |
| 232 | - | ||
| 233 | void OnEstimatedCaptureDuration(const int32_t duration) const | 205 | void OnEstimatedCaptureDuration(const int32_t duration) const |
| 234 | { | 206 | { |
| 235 | DHLOGI("DemoDCameraPhotoCallback::OnEstimatedCaptureDuration duration: %{public}d", duration); | 207 | DHLOGI("DemoDCameraPhotoCallback::OnEstimatedCaptureDuration duration: %{public}d", duration); |
| 236 | } | 208 | } |
| 237 | - | ||
| 238 | void OnCaptureError(const int32_t captureId, const int32_t errorCode) const | 209 | void OnCaptureError(const int32_t captureId, const int32_t errorCode) const |
| 239 | { | 210 | { |
| 240 | DHLOGI("DemoDCameraPhotoCallback::OnCaptureError captureID: %{public}d errorCode: %{public}d", | 211 | DHLOGI("DemoDCameraPhotoCallback::OnCaptureError captureID: %{public}d errorCode: %{public}d", |
| 241 | captureId, errorCode); | 212 | captureId, errorCode); |
| 242 | } | 213 | } |
| 243 | - | ||
| 244 | void OnOfflineDeliveryFinished(const int32_t captureId) const | 214 | void OnOfflineDeliveryFinished(const int32_t captureId) const |
| 245 | { | 215 | { |
| 246 | DHLOGI("DemoDCameraPhotoCallback::OnOfflineDeliveryFinished duration: %{public}d", captureId); | 216 | DHLOGI("DemoDCameraPhotoCallback::OnOfflineDeliveryFinished duration: %{public}d", captureId); |
| 247 | } | 217 | } |
| 248 | - | ||
| 249 | void OnConstellationDrawingState(const int32_t drawingState) const | 218 | void OnConstellationDrawingState(const int32_t drawingState) const |
| 250 | { | 219 | { |
| 251 | DHLOGI("enter, drawingState: %{public}d", drawingState); | 220 | DHLOGI("enter, drawingState: %{public}d", drawingState); |
| 252 | } | 221 | } |
| 253 | }; | 222 | }; |
| 254 | - | ||
| 255 | class DemoDCameraPreviewCallback : public CameraStandard::PreviewStateCallback { | 223 | class DemoDCameraPreviewCallback : public CameraStandard::PreviewStateCallback { |
| 256 | public: | 224 | public: |
| 257 | void OnFrameStarted() const | 225 | void OnFrameStarted() const |
| 258 | { | 226 | { |
| 259 | DHLOGI("DemoDCameraPreviewCallback::OnFrameStarted."); | 227 | DHLOGI("DemoDCameraPreviewCallback::OnFrameStarted."); |
| 260 | } | 228 | } |
| 261 | - | ||
| 262 | void OnFrameEnded(const int32_t frameCount) const | 229 | void OnFrameEnded(const int32_t frameCount) const |
| 263 | { | 230 | { |
| 264 | DHLOGI("DemoDCameraPreviewCallback::OnFrameEnded frameCount: %{public}d", frameCount); | 231 | DHLOGI("DemoDCameraPreviewCallback::OnFrameEnded frameCount: %{public}d", frameCount); |
| 265 | } | 232 | } |
| 266 | - | ||
| 267 | void OnError(const int32_t errorCode) const | 233 | void OnError(const int32_t errorCode) const |
| 268 | { | 234 | { |
| 269 | DHLOGI("DemoDCameraPreviewCallback::OnError errorCode: %{public}d", errorCode); | 235 | DHLOGI("DemoDCameraPreviewCallback::OnError errorCode: %{public}d", errorCode); |
| 270 | } | 236 | } |
| 271 | - | ||
| 272 | void OnSketchStatusDataChanged(const CameraStandard::SketchStatusData& statusData) const | 237 | void OnSketchStatusDataChanged(const CameraStandard::SketchStatusData& statusData) const |
| 273 | { | 238 | { |
| 274 | DHLOGI("DemoDCameraPreviewCallback::OnSketchStatusDataChanged."); | 239 | DHLOGI("DemoDCameraPreviewCallback::OnSketchStatusDataChanged."); |
| 275 | } | 240 | } |
| 276 | - | ||
| 277 | void OnFramePaused() const | 241 | void OnFramePaused() const |
| 278 | { | 242 | { |
| 279 | DHLOGI("enter"); | 243 | DHLOGI("enter"); |
| 280 | } | 244 | } |
| 281 | - | ||
| 282 | void OnFrameResumed() const | 245 | void OnFrameResumed() const |
| 283 | { | 246 | { |
| 284 | DHLOGI("enter"); | 247 | DHLOGI("enter"); |
| 285 | } | 248 | } |
| 286 | }; | 249 | }; |
| 287 | - | ||
| 288 | class DemoDCameraVideoCallback : public CameraStandard::VideoStateCallback { | 250 | class DemoDCameraVideoCallback : public CameraStandard::VideoStateCallback { |
| 289 | public: | 251 | public: |
| 290 | void OnFrameStarted() const | 252 | void OnFrameStarted() const |
| 291 | { | 253 | { |
| 292 | DHLOGI("DemoDCameraVideoCallback::OnFrameStarted."); | 254 | DHLOGI("DemoDCameraVideoCallback::OnFrameStarted."); |
| 293 | } | 255 | } |
| 294 | - | ||
| 295 | void OnFrameEnded(const int32_t frameCount) const | 256 | void OnFrameEnded(const int32_t frameCount) const |
| 296 | { | 257 | { |
| 297 | DHLOGI("DemoDCameraVideoCallback::OnFrameEnded frameCount: %{public}d", frameCount); | 258 | DHLOGI("DemoDCameraVideoCallback::OnFrameEnded frameCount: %{public}d", frameCount); |
| 298 | } | 259 | } |
| 299 | - | ||
| 300 | void OnError(const int32_t errorCode) const | 260 | void OnError(const int32_t errorCode) const |
| 301 | { | 261 | { |
| 302 | DHLOGI("DemoDCameraVideoCallback::OnError errorCode: %{public}d", errorCode); | 262 | DHLOGI("DemoDCameraVideoCallback::OnError errorCode: %{public}d", errorCode); |
| 303 | } | 263 | } |
| 304 | - | ||
| 305 | void OnDeferredVideoEnhancementInfo(const CameraStandard::CaptureEndedInfoExt info) const | 264 | void OnDeferredVideoEnhancementInfo(const CameraStandard::CaptureEndedInfoExt info) const |
| 306 | { | 265 | { |
| 307 | DHLOGI("DemoDCameraVideoCallback::OnDeferredVideoEnhancementInfo videoId: %{public}s", info.videoId.c_str()); | 266 | DHLOGI("DemoDCameraVideoCallback::OnDeferredVideoEnhancementInfo videoId: %{public}s", info.videoId.c_str()); |
| 308 | } | 267 | } |
| 309 | }; | 268 | }; |
| 310 | - | ||
| 311 | class DemoDCameraInputCallback : public CameraStandard::ErrorCallback { | 269 | class DemoDCameraInputCallback : public CameraStandard::ErrorCallback { |
| 312 | public: | 270 | public: |
| 313 | void OnError(const int32_t errorType, const int32_t errorMsg) const | 271 | void OnError(const int32_t errorType, const int32_t errorMsg) const |
| @@ -315,7 +273,6 @@ public: | |||
| 315 | DHLOGI("DemoDCameraInputCallback::OnError errorType: %{public}d errorMsg: %{public}d", errorType, errorMsg); | 273 | DHLOGI("DemoDCameraInputCallback::OnError errorType: %{public}d errorMsg: %{public}d", errorType, errorMsg); |
| 316 | } | 274 | } |
| 317 | }; | 275 | }; |
| 318 | - | ||
| 319 | class DemoDCameraManagerCallback : public CameraStandard::CameraManagerCallback { | 276 | class DemoDCameraManagerCallback : public CameraStandard::CameraManagerCallback { |
| 320 | public: | 277 | public: |
| 321 | void OnCameraStatusChanged(const CameraStandard::CameraStatusInfo &cameraStatusInfo) const | 278 | void OnCameraStatusChanged(const CameraStandard::CameraStatusInfo &cameraStatusInfo) const |
| @@ -323,7 +280,6 @@ public: | |||
| 323 | DHLOGI("DemoDCameraManagerCallback::OnCameraStatusChanged cameraStatus: %{public}d", | 280 | DHLOGI("DemoDCameraManagerCallback::OnCameraStatusChanged cameraStatus: %{public}d", |
| 324 | cameraStatusInfo.cameraStatus); | 281 | cameraStatusInfo.cameraStatus); |
| 325 | } | 282 | } |
| 326 | - | ||
| 327 | void OnFlashlightStatusChanged(const std::string &cameraID, | 283 | void OnFlashlightStatusChanged(const std::string &cameraID, |
| 328 | const CameraStandard::FlashStatus flashStatus) const | 284 | const CameraStandard::FlashStatus flashStatus) const |
| 329 | { | 285 | { |
| @@ -331,14 +287,12 @@ public: | |||
| 331 | GetAnonyString(cameraID).c_str(), flashStatus); | 287 | GetAnonyString(cameraID).c_str(), flashStatus); |
| 332 | } | 288 | } |
| 333 | }; | 289 | }; |
| 334 | - | ||
| 335 | class DemoDCameraSessionCallback : public CameraStandard::SessionCallback, public CameraStandard::FocusCallback { | 290 | class DemoDCameraSessionCallback : public CameraStandard::SessionCallback, public CameraStandard::FocusCallback { |
| 336 | public: | 291 | public: |
| 337 | void OnError(int32_t errorCode) | 292 | void OnError(int32_t errorCode) |
| 338 | { | 293 | { |
| 339 | DHLOGI("DemoDCameraSessionCallback::OnError errorCode: %{public}d", errorCode); | 294 | DHLOGI("DemoDCameraSessionCallback::OnError errorCode: %{public}d", errorCode); |
| 340 | } | 295 | } |
| 341 | - | ||
| 342 | void OnFocusState(FocusState state) | 296 | void OnFocusState(FocusState state) |
| 343 | { | 297 | { |
| 344 | DHLOGI("DemoDCameraSessionCallback::OnFocusState state: %{public}d", state); | 298 | DHLOGI("DemoDCameraSessionCallback::OnFocusState state: %{public}d", state); |
| @@ -53,6 +53,8 @@ public: | |||
| 53 | const std::string &pkgName) override; | 53 | const std::string &pkgName) override; |
| 54 | int32_t RemoveAccessListener(const std::string &pkgName) override; | 54 | int32_t RemoveAccessListener(const std::string &pkgName) override; |
| 55 | int32_t SetAuthorizationResult(const std::string &requestId, bool granted) override; | 55 | int32_t SetAuthorizationResult(const std::string &requestId, bool granted) override; |
| 56 | + int32_t ConfigDistributedHardware(const std::string& devId, const std::string& dhId, const std::string& key, | ||
| 57 | + const std::string& value) override; | ||
| 56 | 58 | ||
| 57 | protected: | 59 | protected: |
| 58 | void OnStart() override; | 60 | void OnStart() override; |
| @@ -72,6 +74,7 @@ private: | |||
| 72 | std::map<std::string, std::shared_ptr<DCameraSinkDev>> camerasMap_; | 74 | std::map<std::string, std::shared_ptr<DCameraSinkDev>> camerasMap_; |
| 73 | static DistributedCameraSinkService* dcSinkService; | 75 | static DistributedCameraSinkService* dcSinkService; |
| 74 | const size_t DUMP_MAX_SIZE = 10 * 1024; | 76 | const size_t DUMP_MAX_SIZE = 10 * 1024; |
| 77 | + uint32_t enableFirstTokenId_ = 0; | ||
| 75 | }; | 78 | }; |
| 76 | } // namespace DistributedHardware | 79 | } // namespace DistributedHardware |
| 77 | } // namespace OHOS | 80 | } // namespace OHOS |
| @@ -46,6 +46,7 @@ private: | |||
| 46 | int32_t SetAccessListenerInner(MessageParcel &data, MessageParcel &reply); | 46 | int32_t SetAccessListenerInner(MessageParcel &data, MessageParcel &reply); |
| 47 | int32_t RemoveAccessListenerInner(MessageParcel &data, MessageParcel &reply); | 47 | int32_t RemoveAccessListenerInner(MessageParcel &data, MessageParcel &reply); |
| 48 | int32_t SetAuthorizationResultInner(MessageParcel &data, MessageParcel &reply); | 48 | int32_t SetAuthorizationResultInner(MessageParcel &data, MessageParcel &reply); |
| 49 | + int32_t ConfigDistributedHardwareInner(MessageParcel &data, MessageParcel &reply); | ||
| 49 | bool HasAccessDHPermission(); | 50 | bool HasAccessDHPermission(); |
| 50 | 51 | ||
| 51 | using DCameraFunc = int32_t (DistributedCameraSinkStub::*)(MessageParcel &data, MessageParcel &reply); | 52 | using DCameraFunc = int32_t (DistributedCameraSinkStub::*)(MessageParcel &data, MessageParcel &reply); |
| @@ -61,6 +61,8 @@ public: | |||
| 61 | int32_t ResumeDistributedHardware(const std::string &networkId) override; | 61 | int32_t ResumeDistributedHardware(const std::string &networkId) override; |
| 62 | int32_t StopDistributedHardware(const std::string &networkId) override; | 62 | int32_t StopDistributedHardware(const std::string &networkId) override; |
| 63 | void SetTokenId(uint64_t token) override; | 63 | void SetTokenId(uint64_t token) override; |
| 64 | + void SetEnableFirstTokenId(uint32_t tokenId) override; | ||
| 65 | + void SetTriggerFirstTokenId(uint32_t tokenId) override; | ||
| 64 | 66 | ||
| 65 | void OnStateChanged(std::shared_ptr<DCameraEvent>& event); | 67 | void OnStateChanged(std::shared_ptr<DCameraEvent>& event); |
| 66 | void OnMetadataResult(std::vector<std::shared_ptr<DCameraSettings>>& settings); | 68 | void OnMetadataResult(std::vector<std::shared_ptr<DCameraSettings>>& settings); |
| @@ -89,6 +91,7 @@ private: | |||
| 89 | int32_t StartCaptureInner(std::vector<std::shared_ptr<DCameraCaptureInfo>>& captureInfos); | 91 | int32_t StartCaptureInner(std::vector<std::shared_ptr<DCameraCaptureInfo>>& captureInfos); |
| 90 | int32_t DCameraNotifyInner(int32_t type, int32_t result, std::string content); | 92 | int32_t DCameraNotifyInner(int32_t type, int32_t result, std::string content); |
| 91 | int32_t HandleReceivedData(std::shared_ptr<DataBuffer>& dataBuffer); | 93 | int32_t HandleReceivedData(std::shared_ptr<DataBuffer>& dataBuffer); |
| 94 | + int32_t HandleCaptureCommand(const std::string &jsonStr); | ||
| 92 | void PostAuthorization(std::vector<std::shared_ptr<DCameraCaptureInfo>>& captureInfos); | 95 | void PostAuthorization(std::vector<std::shared_ptr<DCameraCaptureInfo>>& captureInfos); |
| 93 | bool CheckDeviceSecurityLevel(const std::string &srcDeviceId, const std::string &dstDeviceId); | 96 | bool CheckDeviceSecurityLevel(const std::string &srcDeviceId, const std::string &dstDeviceId); |
| 94 | int32_t GetDeviceSecurityLevel(const std::string &udid); | 97 | int32_t GetDeviceSecurityLevel(const std::string &udid); |
| @@ -99,6 +102,7 @@ private: | |||
| 99 | int32_t CreateCtrlSession(); | 102 | int32_t CreateCtrlSession(); |
| 100 | int32_t CheckSensitive(); | 103 | int32_t CheckSensitive(); |
| 101 | bool CheckAclRight(); | 104 | bool CheckAclRight(); |
| 105 | + bool ResolveEnableUser(int32_t &userId, uint32_t &enableTokenId); | ||
| 102 | bool IsIdenticalAccount(const std::string &networkId); | 106 | bool IsIdenticalAccount(const std::string &networkId); |
| 103 | class DCameraSurfaceHolder { | 107 | class DCameraSurfaceHolder { |
| 104 | public: | 108 | public: |
| @@ -148,6 +152,9 @@ private: | |||
| 148 | uint64_t tokenId_ = 0; | 152 | uint64_t tokenId_ = 0; |
| 149 | uint64_t sinkTokenId_ = 0; | 153 | uint64_t sinkTokenId_ = 0; |
| 150 | std::string accountId_ = ""; | 154 | std::string accountId_ = ""; |
| 155 | + uint32_t enableFirstTokenId_ = 0; | ||
| 156 | + uint32_t sourceTrigFirstTokenId_ = 0; | ||
| 157 | + int32_t sourceTrigFirstUserId_ = -1; | ||
| 151 | 158 | ||
| 152 | const std::string SESSION_FLAG = "control"; | 159 | const std::string SESSION_FLAG = "control"; |
| 153 | const std::string SRC_TYPE = "camera"; | 160 | const std::string SRC_TYPE = "camera"; |
| @@ -45,6 +45,7 @@ public: | |||
| 45 | int32_t ResumeDistributedHardware(const std::string &networkId); | 45 | int32_t ResumeDistributedHardware(const std::string &networkId); |
| 46 | int32_t StopDistributedHardware(const std::string &networkId); | 46 | int32_t StopDistributedHardware(const std::string &networkId); |
| 47 | void SetTokenId(uint64_t token); | 47 | void SetTokenId(uint64_t token); |
| 48 | + void SetEnableFirstTokenId(uint32_t tokenId); | ||
| 48 | 49 | ||
| 49 | private: | 50 | private: |
| 50 | bool isInit_; | 51 | bool isInit_; |
| @@ -24,6 +24,7 @@ | |||
| 24 | #include "system_ability_definition.h" | 24 | #include "system_ability_definition.h" |
| 25 | 25 | ||
| 26 | #include "anonymous_string.h" | 26 | #include "anonymous_string.h" |
| 27 | +#include "cJSON.h" | ||
| 27 | #include "dcamera_handler.h" | 28 | #include "dcamera_handler.h" |
| 28 | #include "dcamera_hisysevent_adapter.h" | 29 | #include "dcamera_hisysevent_adapter.h" |
| 29 | #include "dcamera_sink_service_ipc.h" | 30 | #include "dcamera_sink_service_ipc.h" |
| @@ -124,7 +125,7 @@ int32_t DistributedCameraSinkService::InitSink(const std::string& params, | |||
| 124 | } | 125 | } |
| 125 | for (auto& dhId : cameras) { | 126 | for (auto& dhId : cameras) { |
| 126 | std::shared_ptr<DCameraSinkDev> sinkDevice = std::make_shared<DCameraSinkDev>(dhId, sinkCallback); | 127 | std::shared_ptr<DCameraSinkDev> sinkDevice = std::make_shared<DCameraSinkDev>(dhId, sinkCallback); |
| 127 | - sinkDevice->SetTokenId(GetFirstCallerTokenID()); | 128 | + sinkDevice->SetTokenId(OHOS::IPCSkeleton::GetFirstTokenID()); |
| 128 | ret = sinkDevice->Init(); | 129 | ret = sinkDevice->Init(); |
| 129 | CHECK_AND_RETURN_RET_LOG(ret != DCAMERA_OK, ret, "sink device init failed, ret: %{public}d", ret); | 130 | CHECK_AND_RETURN_RET_LOG(ret != DCAMERA_OK, ret, "sink device init failed, ret: %{public}d", ret); |
| 130 | { | 131 | { |
| @@ -475,5 +476,31 @@ int32_t DistributedCameraSinkService::SetAuthorizationResult(const std::string & | |||
| 475 | DHLOGI("SetAuthorizationResult success"); | 476 | DHLOGI("SetAuthorizationResult success"); |
| 476 | return DCAMERA_OK; | 477 | return DCAMERA_OK; |
| 477 | } | 478 | } |
| 479 | + | ||
| 480 | +int32_t DistributedCameraSinkService::ConfigDistributedHardware(const std::string& devId, const std::string& dhId, | ||
| 481 | + const std::string& key, const std::string& value) | ||
| 482 | +{ | ||
| 483 | + DHLOGI("ConfigDistributedHardware dhId: %{public}s", GetAnonyString(dhId).c_str()); | ||
| 484 | + if (key == KEY_ENABLE_INIT_PARAM) { | ||
| 485 | + cJSON* root = cJSON_Parse(value.c_str()); | ||
| 486 | + if (root == nullptr) { | ||
| 487 | + DHLOGI("root is null."); | ||
| 488 | + return DCAMERA_OK; | ||
| 489 | + } | ||
| 490 | + cJSON* item = cJSON_GetObjectItemCaseSensitive(root, KEY_TOKEN_ID); | ||
| 491 | + if (item != nullptr && cJSON_IsNumber(item)) { | ||
| 492 | + enableFirstTokenId_ = static_cast<uint32_t>(item->valuedouble); | ||
| 493 | + DHLOGI("[MultiUserEnable] ConfigDistributedHardware enableFirstTokenId=%{public}s", | ||
| 494 | + GetAnonyString(std::to_string(enableFirstTokenId_)).c_str()); | ||
| 495 | + std::lock_guard<std::mutex> lock(mapMutex_); | ||
| 496 | + auto it = camerasMap_.find(dhId); | ||
| 497 | + if (it != camerasMap_.end() && it->second != nullptr) { | ||
| 498 | + it->second->SetEnableFirstTokenId(enableFirstTokenId_); | ||
| 499 | + } | ||
| 500 | + } | ||
| 501 | + cJSON_Delete(root); | ||
| 502 | + } | ||
| 503 | + return DCAMERA_OK; | ||
| 504 | +} | ||
| 478 | } // namespace DistributedHardware | 505 | } // namespace DistributedHardware |
| 479 | } // namespace OHOS | 506 | } // namespace OHOS |
| @@ -56,6 +56,8 @@ DistributedCameraSinkStub::DistributedCameraSinkStub() : IRemoteStub(true) | |||
| 56 | &DistributedCameraSinkStub::RemoveAccessListenerInner; | 56 | &DistributedCameraSinkStub::RemoveAccessListenerInner; |
| 57 | memberFuncMap_[static_cast<uint32_t>(IDCameraSinkInterfaceCode::SET_AUTHORIZATION_RESULT)] = | 57 | memberFuncMap_[static_cast<uint32_t>(IDCameraSinkInterfaceCode::SET_AUTHORIZATION_RESULT)] = |
| 58 | &DistributedCameraSinkStub::SetAuthorizationResultInner; | 58 | &DistributedCameraSinkStub::SetAuthorizationResultInner; |
| 59 | + memberFuncMap_[static_cast<uint32_t>(IDCameraSinkInterfaceCode::CONFIG_DISTRIBUTED_HARDWARE)] = | ||
| 60 | + &DistributedCameraSinkStub::ConfigDistributedHardwareInner; | ||
| 59 | } | 61 | } |
| 60 | 62 | ||
| 61 | DistributedCameraSinkStub::~DistributedCameraSinkStub() | 63 | DistributedCameraSinkStub::~DistributedCameraSinkStub() |
| @@ -112,6 +114,8 @@ int32_t DistributedCameraSinkStub::OnRemoteRequest(uint32_t code, MessageParcel | |||
| 112 | return RemoveAccessListenerInner(data, reply); | 114 | return RemoveAccessListenerInner(data, reply); |
| 113 | case static_cast<uint32_t>(IDCameraSinkInterfaceCode::SET_AUTHORIZATION_RESULT): | 115 | case static_cast<uint32_t>(IDCameraSinkInterfaceCode::SET_AUTHORIZATION_RESULT): |
| 114 | return SetAuthorizationResultInner(data, reply); | 116 | return SetAuthorizationResultInner(data, reply); |
| 117 | + case static_cast<uint32_t>(IDCameraSinkInterfaceCode::CONFIG_DISTRIBUTED_HARDWARE): | ||
| 118 | + return ConfigDistributedHardwareInner(data, reply); | ||
| 115 | default: | 119 | default: |
| 116 | DHLOGE("Invalid OnRemoteRequest code=%{public}d", code); | 120 | DHLOGE("Invalid OnRemoteRequest code=%{public}d", code); |
| 117 | return IPCObjectStub::OnRemoteRequest(code, data, reply, option); | 121 | return IPCObjectStub::OnRemoteRequest(code, data, reply, option); |
| @@ -441,5 +445,26 @@ int32_t DistributedCameraSinkStub::SetAuthorizationResultInner(MessageParcel &da | |||
| 441 | reply.WriteInt32(ret); | 445 | reply.WriteInt32(ret); |
| 442 | return DCAMERA_OK; | 446 | return DCAMERA_OK; |
| 443 | } | 447 | } |
| 448 | + | ||
| 449 | +int32_t DistributedCameraSinkStub::ConfigDistributedHardwareInner(MessageParcel &data, MessageParcel &reply) | ||
| 450 | +{ | ||
| 451 | + DHLOGD("enter"); | ||
| 452 | + int32_t ret = DCAMERA_OK; | ||
| 453 | + do { | ||
| 454 | + if (!HasEnableDHPermission()) { | ||
| 455 | + DHLOGE("The caller has no ENABLE_DISTRIBUTED_HARDWARE permission."); | ||
| 456 | + ret = DCAMERA_BAD_VALUE; | ||
| 457 | + break; | ||
| 458 | + } | ||
| 459 | + std::string devId = data.ReadString(); | ||
| 460 | + std::string dhId = data.ReadString(); | ||
| 461 | + std::string key = data.ReadString(); | ||
| 462 | + std::string value = data.ReadString(); | ||
| 463 | + ret = ConfigDistributedHardware(devId, dhId, key, value); | ||
| 464 | + DHLOGI("DistributedCameraSinkStub ConfigDistributedHardware %{public}d", ret); | ||
| 465 | + } while (0); | ||
| 466 | + reply.WriteInt32(ret); | ||
| 467 | + return DCAMERA_OK; | ||
| 468 | +} | ||
| 444 | } // namespace DistributedHardware | 469 | } // namespace DistributedHardware |
| 445 | } // namespace OHOS | 470 | } // namespace OHOS |
| @@ -43,10 +43,12 @@ | |||
| 43 | #include "ffrt_inner.h" | 43 | #include "ffrt_inner.h" |
| 44 | #include "idistributed_camera_source.h" | 44 | #include "idistributed_camera_source.h" |
| 45 | #include "ipc_skeleton.h" | 45 | #include "ipc_skeleton.h" |
| 46 | +#include "accesstoken_kit.h" | ||
| 46 | #include "dcamera_low_latency.h" | 47 | #include "dcamera_low_latency.h" |
| 47 | #ifdef OS_ACCOUNT_ENABLE | 48 | #ifdef OS_ACCOUNT_ENABLE |
| 48 | #include "ohos_account_kits.h" | 49 | #include "ohos_account_kits.h" |
| 49 | #include "os_account_manager.h" | 50 | #include "os_account_manager.h" |
| 51 | +#include "os_account_info.h" | ||
| 50 | #endif | 52 | #endif |
| 51 | #include <sys/prctl.h> | 53 | #include <sys/prctl.h> |
| 52 | 54 | ||
| @@ -874,25 +876,7 @@ int32_t DCameraSinkController::HandleReceivedData(std::shared_ptr<DataBuffer>& d | |||
| 874 | std::string command = std::string(comvalue->valuestring); | 876 | std::string command = std::string(comvalue->valuestring); |
| 875 | cJSON_Delete(rootValue); | 877 | cJSON_Delete(rootValue); |
| 876 | if ((!command.empty()) && (command.compare(DCAMERA_PROTOCOL_CMD_CAPTURE) == 0)) { | 878 | if ((!command.empty()) && (command.compare(DCAMERA_PROTOCOL_CMD_CAPTURE) == 0)) { |
| 877 | - DCameraCaptureInfoCmd captureInfoCmd; | 879 | + return HandleCaptureCommand(jsonStr); |
| 878 | - int32_t ret = captureInfoCmd.Unmarshal(jsonStr); | ||
| 879 | - if (ret != DCAMERA_OK) { | ||
| 880 | - DHLOGE("Capture Info Unmarshal failed, dhId: %{public}s ret: %{public}d", | ||
| 881 | - GetAnonyString(dhId_).c_str(), ret); | ||
| 882 | - return ret; | ||
| 883 | - } | ||
| 884 | - sceneMode_ = captureInfoCmd.sceneMode_; | ||
| 885 | - userId_ = captureInfoCmd.userId_; | ||
| 886 | - tokenId_ = captureInfoCmd.tokenId_; | ||
| 887 | - accountId_ = captureInfoCmd.accountId_; | ||
| 888 | - if (!CheckAclRight()) { | ||
| 889 | - DHLOGE("ACL check failed."); | ||
| 890 | - return DCAMERA_BAD_VALUE; | ||
| 891 | - } | ||
| 892 | -#ifdef DCAMERA_OPEN_STABILE | ||
| 893 | - CHECK_AND_RETURN_RET_LOG(!IsIdenticalAccount(srcDevId_), DCAMERA_BAD_VALUE, "Account check failed."); | ||
| 894 | -#endif | ||
| 895 | - return StartCapture(captureInfoCmd.value_, sceneMode_, captureInfoCmd.eis_); | ||
| 896 | } else if ((!command.empty()) && (command.compare(DCAMERA_PROTOCOL_CMD_UPDATE_METADATA) == 0)) { | 880 | } else if ((!command.empty()) && (command.compare(DCAMERA_PROTOCOL_CMD_UPDATE_METADATA) == 0)) { |
| 897 | DCameraMetadataSettingCmd metadataSettingCmd; | 881 | DCameraMetadataSettingCmd metadataSettingCmd; |
| 898 | int32_t ret = metadataSettingCmd.Unmarshal(jsonStr); | 882 | int32_t ret = metadataSettingCmd.Unmarshal(jsonStr); |
| @@ -908,10 +892,36 @@ int32_t DCameraSinkController::HandleReceivedData(std::shared_ptr<DataBuffer>& d | |||
| 908 | return DCAMERA_BAD_VALUE; | 892 | return DCAMERA_BAD_VALUE; |
| 909 | } | 893 | } |
| 910 | 894 | ||
| 895 | +int32_t DCameraSinkController::HandleCaptureCommand(const std::string &jsonStr) | ||
| 896 | +{ | ||
| 897 | + DCameraCaptureInfoCmd captureInfoCmd; | ||
| 898 | + int32_t ret = captureInfoCmd.Unmarshal(jsonStr); | ||
| 899 | + if (ret != DCAMERA_OK) { | ||
| 900 | + DHLOGE("Capture Info Unmarshal failed, dhId: %{public}s ret: %{public}d", | ||
| 901 | + GetAnonyString(dhId_).c_str(), ret); | ||
| 902 | + return ret; | ||
| 903 | + } | ||
| 904 | + sceneMode_ = captureInfoCmd.sceneMode_; | ||
| 905 | + userId_ = captureInfoCmd.userId_; | ||
| 906 | + tokenId_ = captureInfoCmd.tokenId_; | ||
| 907 | + accountId_ = captureInfoCmd.accountId_; | ||
| 908 | + sourceTrigFirstTokenId_ = captureInfoCmd.triggerFirstTokenId_; | ||
| 909 | + sourceTrigFirstUserId_ = captureInfoCmd.triggerFirstUserId_; | ||
| 910 | + DHLOGI("[MultiUserSink] Sink received sourceTrigFirstTokenId=%{public}s, sourceTrigFirstUserId=%{public}d", | ||
| 911 | + GetAnonyString(std::to_string(sourceTrigFirstTokenId_)).c_str(), sourceTrigFirstUserId_); | ||
| 912 | + if (!CheckAclRight()) { | ||
| 913 | + DHLOGE("ACL check failed."); | ||
| 914 | + return DCAMERA_BAD_VALUE; | ||
| 915 | + } | ||
| 916 | +#ifdef DCAMERA_OPEN_STABILE | ||
| 917 | + CHECK_AND_RETURN_RET_LOG(!IsIdenticalAccount(srcDevId_), DCAMERA_BAD_VALUE, "Account check failed."); | ||
| 918 | +#endif | ||
| 919 | + return StartCapture(captureInfoCmd.value_, sceneMode_, captureInfoCmd.eis_); | ||
| 920 | +} | ||
| 921 | + | ||
| 911 | bool DCameraSinkController::CheckAclRight() | 922 | bool DCameraSinkController::CheckAclRight() |
| 912 | { | 923 | { |
| 913 | if (userId_ == -1) { | 924 | if (userId_ == -1) { |
| 914 | - DHLOGI("Acl check version compatibility processing."); | ||
| 915 | return true; | 925 | return true; |
| 916 | } | 926 | } |
| 917 | std::string sinkDevId; | 927 | std::string sinkDevId; |
| @@ -922,16 +932,17 @@ bool DCameraSinkController::CheckAclRight() | |||
| 922 | #ifdef OS_ACCOUNT_ENABLE | 932 | #ifdef OS_ACCOUNT_ENABLE |
| 923 | std::vector<int32_t> ids; | 933 | std::vector<int32_t> ids; |
| 924 | ret = AccountSA::OsAccountManager::QueryActiveOsAccountIds(ids); | 934 | ret = AccountSA::OsAccountManager::QueryActiveOsAccountIds(ids); |
| 925 | - CHECK_AND_RETURN_RET_LOG(ret != DCAMERA_OK || ids.empty(), false, | 935 | + CHECK_AND_RETURN_RET_LOG(ret != DCAMERA_OK, false, "Get userId fail, ret: %{public}d", ret); |
| 926 | - "Get userId from active os accountIds fail, ret: %{public}d", ret); | 936 | + userId = ids.empty() ? 0 : ids[0]; |
| 927 | - userId = ids[0]; | ||
| 928 | - | ||
| 929 | AccountSA::OhosAccountInfo osAccountInfo; | 937 | AccountSA::OhosAccountInfo osAccountInfo; |
| 930 | ret = AccountSA::OhosAccountKits::GetInstance().GetOhosAccountInfo(osAccountInfo); | 938 | ret = AccountSA::OhosAccountKits::GetInstance().GetOhosAccountInfo(osAccountInfo); |
| 931 | - CHECK_AND_RETURN_RET_LOG(ret != DCAMERA_OK, false, | 939 | + CHECK_AND_RETURN_RET_LOG(ret != DCAMERA_OK, false, "Get accountId fail, ret: %{public}d", ret); |
| 932 | - "Get accountId from ohos account info fail, ret: %{public}d", ret); | ||
| 933 | accountId = osAccountInfo.uid_; | 940 | accountId = osAccountInfo.uid_; |
| 934 | #endif | 941 | #endif |
| 942 | + uint32_t enableTokenId = 0; | ||
| 943 | + if (!ResolveEnableUser(userId, enableTokenId)) { | ||
| 944 | + return false; | ||
| 945 | + } | ||
| 935 | ret = DeviceManager::GetInstance().InitDeviceManager(DCAMERA_PKG_NAME, initCallback_); | 946 | ret = DeviceManager::GetInstance().InitDeviceManager(DCAMERA_PKG_NAME, initCallback_); |
| 936 | if (ret != DCAMERA_OK) { | 947 | if (ret != DCAMERA_OK) { |
| 937 | DHLOGE("InitDeviceManager failed ret = %{public}d", ret); | 948 | DHLOGE("InitDeviceManager failed ret = %{public}d", ret); |
| @@ -942,20 +953,60 @@ bool DCameraSinkController::CheckAclRight() | |||
| 942 | .pkgName = DCAMERA_PKG_NAME, | 953 | .pkgName = DCAMERA_PKG_NAME, |
| 943 | .networkId = srcDevId_, | 954 | .networkId = srcDevId_, |
| 944 | .userId = userId_, | 955 | .userId = userId_, |
| 945 | - .tokenId = tokenId_, | 956 | + .tokenId = (sourceTrigFirstTokenId_ != 0) ? sourceTrigFirstTokenId_ : tokenId_, |
【安全检视意见|自动扫描】【中危】认证与授权绕过(身份伪造) CheckAclRight 中 dmSrcCaller.tokenId 改为优先采用对端命令 JSON 下发的 triggerFirstTokenId,该值在本端未做任何绑定或一致性校验即作为访问控制身份使用;随命令一同下发的 triggerFirstUserId 也只用于日志、未参与校验。伪造该字段会影响 CheckSinkAccessControl 判定时使用的调用方身份。 建议:对 sourceTrigFirstTokenId 做绑定校验(如与既有 tokenId_ 一致性校验、或经 DeviceManager 校验 token 归属),至少校验 sourceTrigFirstUserId_ 与本端活跃账户匹配后再采用;无法验证时回落使用 tokenId_。
![]() ![]() | |||
| 946 | }; | 957 | }; |
| 947 | DmAccessCallee dmDstCallee = { | 958 | DmAccessCallee dmDstCallee = { |
| 948 | .accountId = accountId, | 959 | .accountId = accountId, |
| 949 | .networkId = sinkDevId, | 960 | .networkId = sinkDevId, |
| 950 | .pkgName = DCAMERA_PKG_NAME, | 961 | .pkgName = DCAMERA_PKG_NAME, |
| 951 | .userId = userId, | 962 | .userId = userId, |
| 952 | - .tokenId = sinkTokenId_, | 963 | + .tokenId = enableTokenId, |
| 953 | }; | 964 | }; |
| 954 | - DHLOGI("CheckAclRight srcDevId: %{public}s, accountId: %{public}s, sinkDevId: %{public}s", | 965 | + DHLOGI("[MultiUserSink] CheckAclRight srcUserId=%{public}d, sinkEnableUserId=%{public}d, enableTokenId=%{public}s", |
| 955 | - GetAnonyString(srcDevId_).c_str(), GetAnonyString(accountId).c_str(), GetAnonyString(sinkDevId).c_str()); | 966 | + userId_, userId, GetAnonyString(std::to_string(enableTokenId)).c_str()); |
| 956 | return DeviceManager::GetInstance().CheckSinkAccessControl(dmSrcCaller, dmDstCallee); | 967 | return DeviceManager::GetInstance().CheckSinkAccessControl(dmSrcCaller, dmDstCallee); |
| 957 | } | 968 | } |
| 958 | 969 | ||
| 970 | +bool DCameraSinkController::ResolveEnableUser(int32_t &userId, uint32_t &enableTokenId) | ||
| 971 | +{ | ||
| 972 | + enableTokenId = enableFirstTokenId_; | ||
| 973 | + DHLOGI("[MultiUserSink] enableTokenId=%{public}s", GetAnonyString(std::to_string(enableTokenId)).c_str()); | ||
| 974 | + Security::AccessToken::HapTokenInfo enableTokenInfo; | ||
| 975 | + int32_t enableUserId = -1; | ||
| 976 | + bool isSA = Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(enableTokenId) == | ||
| 977 | + Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE; | ||
| 978 | + if (!isSA && enableTokenId != 0) { | ||
| 979 | + int32_t res = Security::AccessToken::AccessTokenKit::GetHapTokenInfo(enableTokenId, enableTokenInfo); | ||
| 980 | + if (res != 0) { | ||
| 981 | + DHLOGI("[MultiUserSink] get hap token info failed, ret = %{public}d", res); | ||
| 982 | + return false; | ||
| 983 | + } | ||
| 984 | + enableUserId = enableTokenInfo.userID; | ||
| 985 | + } | ||
| 986 | + | ||
| 987 | + int32_t matchedUserId = -1; | ||
| 988 | + if (enableUserId != -1) { | ||
| 989 | +#ifdef OS_ACCOUNT_ENABLE | ||
| 990 | + std::vector<int32_t> activeIds; | ||
| 991 | + AccountSA::OsAccountManager::QueryActiveOsAccountIds(activeIds); | ||
| 992 | + for (auto &localId : activeIds) { | ||
| 993 | + if (localId == enableUserId) { | ||
| 994 | + matchedUserId = localId; | ||
| 995 | + break; | ||
| 996 | + } | ||
| 997 | + } | ||
| 998 | +#endif | ||
| 999 | + if (matchedUserId == -1) { | ||
| 1000 | + DHLOGE("[MultiUserSink] no active match for sourceTrigFirstUserId=%{public}d", | ||
| 1001 | + sourceTrigFirstUserId_); | ||
| 1002 | + return false; | ||
| 1003 | + } | ||
| 1004 | + userId = matchedUserId; | ||
| 1005 | + } | ||
| 1006 | + DHLOGI("[MultiUserSink] use userId_=%{public}d, userId=%{public}d", userId_, userId); | ||
| 1007 | + return true; | ||
| 1008 | +} | ||
| 1009 | + | ||
| 959 | int32_t DCameraSinkController::PauseDistributedHardware(const std::string &networkId) | 1010 | int32_t DCameraSinkController::PauseDistributedHardware(const std::string &networkId) |
| 960 | { | 1011 | { |
| 961 | DHLOGI("Pause distributed hardware dhId: %{public}s", GetAnonyString(dhId_).c_str()); | 1012 | DHLOGI("Pause distributed hardware dhId: %{public}s", GetAnonyString(dhId_).c_str()); |
| @@ -1092,6 +1143,16 @@ void DCameraSinkController::SetTokenId(uint64_t token) | |||
| 1092 | sinkTokenId_ = token; | 1143 | sinkTokenId_ = token; |
| 1093 | } | 1144 | } |
| 1094 | 1145 | ||
| 1146 | +void DCameraSinkController::SetEnableFirstTokenId(uint32_t tokenId) | ||
| 1147 | +{ | ||
| 1148 | + enableFirstTokenId_ = tokenId; | ||
| 1149 | +} | ||
| 1150 | + | ||
| 1151 | +void DCameraSinkController::SetTriggerFirstTokenId(uint32_t tokenId) | ||
| 1152 | +{ | ||
| 1153 | + sourceTrigFirstTokenId_ = tokenId; | ||
| 1154 | +} | ||
| 1155 | + | ||
| 1095 | void DeviceInitCallback::OnRemoteDied() | 1156 | void DeviceInitCallback::OnRemoteDied() |
| 1096 | { | 1157 | { |
| 1097 | DHLOGI("DeviceInitCallback OnRemoteDied"); | 1158 | DHLOGI("DeviceInitCallback OnRemoteDied"); |
| @@ -216,5 +216,12 @@ void DCameraSinkDev::SetTokenId(uint64_t token) | |||
| 216 | { | 216 | { |
| 217 | tokenId_ = token; | 217 | tokenId_ = token; |
| 218 | } | 218 | } |
| 219 | + | ||
| 220 | +void DCameraSinkDev::SetEnableFirstTokenId(uint32_t tokenId) | ||
| 221 | +{ | ||
| 222 | + if (controller_ != nullptr) { | ||
| 223 | + controller_->SetEnableFirstTokenId(tokenId); | ||
| 224 | + } | ||
| 225 | +} | ||
| 219 | } // namespace DistributedHardware | 226 | } // namespace DistributedHardware |
| 220 | } // namespace OHOS | 227 | } // namespace OHOS |
| @@ -428,5 +428,124 @@ HWTEST_F(DistributedCameraSinkServiceTest, dcamera_sink_service_test_020, TestSi | |||
| 428 | ret = sinkService_->SetAuthorizationResult(requestId, granted); | 428 | ret = sinkService_->SetAuthorizationResult(requestId, granted); |
| 429 | EXPECT_EQ(DCAMERA_OK, ret); | 429 | EXPECT_EQ(DCAMERA_OK, ret); |
| 430 | } | 430 | } |
| 431 | + | ||
| 432 | +/** | ||
| 433 | + * @tc.name: dcamera_sink_service_test_021 | ||
| 434 | + * @tc.desc: Verify ConfigDistributedHardware with enable_init_params key and valid tokenId. | ||
| 435 | + * @tc.type: FUNC | ||
| 436 | + * @tc.require: Issue Number | ||
| 437 | + */ | ||
| 438 | +HWTEST_F(DistributedCameraSinkServiceTest, dcamera_sink_service_test_021, TestSize.Level1) | ||
| 439 | +{ | ||
| 440 | + DHLOGI("dcamera_sink_service_test_021"); | ||
| 441 | + EXPECT_EQ(sinkService_ == nullptr, false); | ||
| 442 | + sinkService_->enableFirstTokenId_ = 0; | ||
| 443 | + std::string dhId = "camera_0"; | ||
| 444 | + std::string key = KEY_ENABLE_INIT_PARAM; | ||
| 445 | + std::string value = R"({"tokenId": 12345})"; | ||
| 446 | + int32_t ret = sinkService_->ConfigDistributedHardware("", dhId, key, value); | ||
| 447 | + EXPECT_EQ(DCAMERA_OK, ret); | ||
| 448 | + EXPECT_EQ(sinkService_->enableFirstTokenId_, static_cast<uint32_t>(12345)); | ||
| 449 | +} | ||
| 450 | + | ||
| 451 | +/** | ||
| 452 | + * @tc.name: dcamera_sink_service_test_022 | ||
| 453 | + * @tc.desc: Verify ConfigDistributedHardware with non-enable_init_params key. | ||
| 454 | + * @tc.type: FUNC | ||
| 455 | + * @tc.require: Issue Number | ||
| 456 | + */ | ||
| 457 | +HWTEST_F(DistributedCameraSinkServiceTest, dcamera_sink_service_test_022, TestSize.Level1) | ||
| 458 | +{ | ||
| 459 | + DHLOGI("dcamera_sink_service_test_022"); | ||
| 460 | + EXPECT_EQ(sinkService_ == nullptr, false); | ||
| 461 | + sinkService_->enableFirstTokenId_ = 0; | ||
| 462 | + std::string dhId = "camera_0"; | ||
| 463 | + std::string key = "other_key"; | ||
| 464 | + std::string value = R"({"tokenId": 99999})"; | ||
| 465 | + int32_t ret = sinkService_->ConfigDistributedHardware("", dhId, key, value); | ||
| 466 | + EXPECT_EQ(DCAMERA_OK, ret); | ||
| 467 | + EXPECT_EQ(sinkService_->enableFirstTokenId_, static_cast<uint32_t>(0)); | ||
| 468 | +} | ||
| 469 | + | ||
| 470 | +/** | ||
| 471 | + * @tc.name: dcamera_sink_service_test_023 | ||
| 472 | + * @tc.desc: Verify ConfigDistributedHardware with invalid JSON value. | ||
| 473 | + * @tc.type: FUNC | ||
| 474 | + * @tc.require: Issue Number | ||
| 475 | + */ | ||
| 476 | +HWTEST_F(DistributedCameraSinkServiceTest, dcamera_sink_service_test_023, TestSize.Level1) | ||
| 477 | +{ | ||
| 478 | + DHLOGI("dcamera_sink_service_test_023"); | ||
| 479 | + EXPECT_EQ(sinkService_ == nullptr, false); | ||
| 480 | + sinkService_->enableFirstTokenId_ = 0; | ||
| 481 | + std::string dhId = "camera_0"; | ||
| 482 | + std::string key = KEY_ENABLE_INIT_PARAM; | ||
| 483 | + std::string value = "invalid_json"; | ||
| 484 | + int32_t ret = sinkService_->ConfigDistributedHardware("", dhId, key, value); | ||
| 485 | + EXPECT_EQ(DCAMERA_OK, ret); | ||
| 486 | + EXPECT_EQ(sinkService_->enableFirstTokenId_, static_cast<uint32_t>(0)); | ||
| 487 | +} | ||
| 488 | + | ||
| 489 | +/** | ||
| 490 | + * @tc.name: dcamera_sink_service_test_024 | ||
| 491 | + * @tc.desc: Verify ConfigDistributedHardware with enable_init_params key but no tokenId field. | ||
| 492 | + * @tc.type: FUNC | ||
| 493 | + * @tc.require: Issue Number | ||
| 494 | + */ | ||
| 495 | +HWTEST_F(DistributedCameraSinkServiceTest, dcamera_sink_service_test_024, TestSize.Level1) | ||
| 496 | +{ | ||
| 497 | + DHLOGI("dcamera_sink_service_test_024"); | ||
| 498 | + EXPECT_EQ(sinkService_ == nullptr, false); | ||
| 499 | + sinkService_->enableFirstTokenId_ = 0; | ||
| 500 | + std::string dhId = "camera_0"; | ||
| 501 | + std::string key = KEY_ENABLE_INIT_PARAM; | ||
| 502 | + std::string value = R"({"otherField": "value"})"; | ||
| 503 | + int32_t ret = sinkService_->ConfigDistributedHardware("", dhId, key, value); | ||
| 504 | + EXPECT_EQ(DCAMERA_OK, ret); | ||
| 505 | + EXPECT_EQ(sinkService_->enableFirstTokenId_, static_cast<uint32_t>(0)); | ||
| 506 | +} | ||
| 507 | + | ||
| 508 | +/** | ||
| 509 | + * @tc.name: dcamera_sink_service_test_025 | ||
| 510 | + * @tc.desc: Verify ConfigDistributedHardware with tokenId of wrong type (string instead of number). | ||
| 511 | + * @tc.type: FUNC | ||
| 512 | + * @tc.require: Issue Number | ||
| 513 | + */ | ||
| 514 | +HWTEST_F(DistributedCameraSinkServiceTest, dcamera_sink_service_test_025, TestSize.Level1) | ||
| 515 | +{ | ||
| 516 | + DHLOGI("dcamera_sink_service_test_025"); | ||
| 517 | + EXPECT_EQ(sinkService_ == nullptr, false); | ||
| 518 | + sinkService_->enableFirstTokenId_ = 0; | ||
| 519 | + std::string dhId = "camera_0"; | ||
| 520 | + std::string key = KEY_ENABLE_INIT_PARAM; | ||
| 521 | + std::string value = R"({"tokenId": "not_a_number"})"; | ||
| 522 | + int32_t ret = sinkService_->ConfigDistributedHardware("", dhId, key, value); | ||
| 523 | + EXPECT_EQ(DCAMERA_OK, ret); | ||
| 524 | + EXPECT_EQ(sinkService_->enableFirstTokenId_, static_cast<uint32_t>(0)); | ||
| 525 | +} | ||
| 526 | + | ||
| 527 | +/** | ||
| 528 | + * @tc.name: dcamera_sink_service_test_026 | ||
| 529 | + * @tc.desc: Verify ConfigDistributedHardware called multiple times updates enableFirstTokenId_. | ||
| 530 | + * @tc.type: FUNC | ||
| 531 | + * @tc.require: Issue Number | ||
| 532 | + */ | ||
| 533 | +HWTEST_F(DistributedCameraSinkServiceTest, dcamera_sink_service_test_026, TestSize.Level1) | ||
| 534 | +{ | ||
| 535 | + DHLOGI("dcamera_sink_service_test_026"); | ||
| 536 | + EXPECT_EQ(sinkService_ == nullptr, false); | ||
| 537 | + sinkService_->enableFirstTokenId_ = 0; | ||
| 538 | + std::string dhId = "camera_0"; | ||
| 539 | + std::string key = KEY_ENABLE_INIT_PARAM; | ||
| 540 | + std::string value1 = R"({"tokenId": 111})"; | ||
| 541 | + int32_t ret = sinkService_->ConfigDistributedHardware("", dhId, key, value1); | ||
| 542 | + EXPECT_EQ(DCAMERA_OK, ret); | ||
| 543 | + EXPECT_EQ(sinkService_->enableFirstTokenId_, static_cast<uint32_t>(111)); | ||
| 544 | + | ||
| 545 | + std::string value2 = R"({"tokenId": 222})"; | ||
| 546 | + ret = sinkService_->ConfigDistributedHardware("", dhId, key, value2); | ||
| 547 | + EXPECT_EQ(DCAMERA_OK, ret); | ||
| 548 | + EXPECT_EQ(sinkService_->enableFirstTokenId_, static_cast<uint32_t>(222)); | ||
| 549 | +} | ||
| 431 | } // namespace DistributedHardware | 550 | } // namespace DistributedHardware |
| 432 | } // namespace OHOS | 551 | } // namespace OHOS |
| @@ -19,6 +19,7 @@ | |||
| 19 | #include "nativetoken_kit.h" | 19 | #include "nativetoken_kit.h" |
| 20 | #include "token_setproc.h" | 20 | #include "token_setproc.h" |
| 21 | #include "softbus_common.h" | 21 | #include "softbus_common.h" |
| 22 | +#include "dcamera_ipc_interface_code.h" | ||
| 22 | #include "dcamera_sink_callback.h" | 23 | #include "dcamera_sink_callback.h" |
| 23 | #include "distributed_camera_sink_proxy.h" | 24 | #include "distributed_camera_sink_proxy.h" |
| 24 | #include "distributed_camera_sink_stub.h" | 25 | #include "distributed_camera_sink_stub.h" |
| @@ -405,5 +406,138 @@ HWTEST_F(DcameraSinkStubTest, dcamera_sink_stub_test_018, TestSize.Level1) | |||
| 405 | MessageParcel reply; | 406 | MessageParcel reply; |
| 406 | EXPECT_EQ(DCAMERA_OK, sinkStubPtr->SetAuthorizationResultInner(data, reply)); | 407 | EXPECT_EQ(DCAMERA_OK, sinkStubPtr->SetAuthorizationResultInner(data, reply)); |
| 407 | } | 408 | } |
| 409 | + | ||
| 410 | +/** | ||
| 411 | + * @tc.name: dcamera_sink_stub_test_019 | ||
| 412 | + * @tc.desc: Verify ConfigDistributedHardware via proxy with valid params. | ||
| 413 | + * @tc.type: FUNC | ||
| 414 | + * @tc.require: issue | ||
| 415 | + */ | ||
| 416 | +HWTEST_F(DcameraSinkStubTest, dcamera_sink_stub_test_019, TestSize.Level1) | ||
| 417 | +{ | ||
| 418 | + DHLOGI("dcamera_sink_stub_test_019"); | ||
| 419 | + sptr<IRemoteObject> sinkStubPtr(new MockDistributedCameraSinkStub()); | ||
| 420 | + DistributedCameraSinkProxy sinkProxy(sinkStubPtr); | ||
| 421 | + std::string devId = "devId_test"; | ||
| 422 | + std::string dhId = "camera_0"; | ||
| 423 | + std::string key = "enable_init_params"; | ||
| 424 | + std::string value = R"({"tokenId": 12345})"; | ||
| 425 | + int32_t ret = sinkProxy.ConfigDistributedHardware(devId, dhId, key, value); | ||
| 426 | + EXPECT_EQ(DCAMERA_OK, ret); | ||
| 427 | +} | ||
| 428 | + | ||
| 429 | +/** | ||
| 430 | + * @tc.name: dcamera_sink_stub_test_020 | ||
| 431 | + * @tc.desc: Verify ConfigDistributedHardware via proxy with empty dhId returns DCAMERA_BAD_VALUE. | ||
| 432 | + * @tc.type: FUNC | ||
| 433 | + * @tc.require: issue | ||
| 434 | + */ | ||
| 435 | +HWTEST_F(DcameraSinkStubTest, dcamera_sink_stub_test_020, TestSize.Level1) | ||
| 436 | +{ | ||
| 437 | + DHLOGI("dcamera_sink_stub_test_020"); | ||
| 438 | + sptr<IRemoteObject> sinkStubPtr(new MockDistributedCameraSinkStub()); | ||
| 439 | + DistributedCameraSinkProxy sinkProxy(sinkStubPtr); | ||
| 440 | + std::string devId = "devId_test"; | ||
| 441 | + std::string dhId = ""; | ||
| 442 | + std::string key = "enable_init_params"; | ||
| 443 | + std::string value = R"({"tokenId": 12345})"; | ||
| 444 | + int32_t ret = sinkProxy.ConfigDistributedHardware(devId, dhId, key, value); | ||
| 445 | + EXPECT_EQ(DCAMERA_BAD_VALUE, ret); | ||
| 446 | +} | ||
| 447 | + | ||
| 448 | +/** | ||
| 449 | + * @tc.name: dcamera_sink_stub_test_021 | ||
| 450 | + * @tc.desc: Verify ConfigDistributedHardware via proxy with empty key returns DCAMERA_BAD_VALUE. | ||
| 451 | + * @tc.type: FUNC | ||
| 452 | + * @tc.require: issue | ||
| 453 | + */ | ||
| 454 | +HWTEST_F(DcameraSinkStubTest, dcamera_sink_stub_test_021, TestSize.Level1) | ||
| 455 | +{ | ||
| 456 | + DHLOGI("dcamera_sink_stub_test_021"); | ||
| 457 | + sptr<IRemoteObject> sinkStubPtr(new MockDistributedCameraSinkStub()); | ||
| 458 | + DistributedCameraSinkProxy sinkProxy(sinkStubPtr); | ||
| 459 | + std::string devId = "devId_test"; | ||
| 460 | + std::string dhId = "camera_0"; | ||
| 461 | + std::string key = ""; | ||
| 462 | + std::string value = R"({"tokenId": 12345})"; | ||
| 463 | + int32_t ret = sinkProxy.ConfigDistributedHardware(devId, dhId, key, value); | ||
| 464 | + EXPECT_EQ(DCAMERA_BAD_VALUE, ret); | ||
| 465 | +} | ||
| 466 | + | ||
| 467 | +/** | ||
| 468 | + * @tc.name: dcamera_sink_stub_test_022 | ||
| 469 | + * @tc.desc: Verify ConfigDistributedHardware via proxy with empty value returns DCAMERA_BAD_VALUE. | ||
| 470 | + * @tc.type: FUNC | ||
| 471 | + * @tc.require: issue | ||
| 472 | + */ | ||
| 473 | +HWTEST_F(DcameraSinkStubTest, dcamera_sink_stub_test_022, TestSize.Level1) | ||
| 474 | +{ | ||
| 475 | + DHLOGI("dcamera_sink_stub_test_022"); | ||
| 476 | + sptr<IRemoteObject> sinkStubPtr(new MockDistributedCameraSinkStub()); | ||
| 477 | + DistributedCameraSinkProxy sinkProxy(sinkStubPtr); | ||
| 478 | + std::string devId = "devId_test"; | ||
| 479 | + std::string dhId = "camera_0"; | ||
| 480 | + std::string key = "enable_init_params"; | ||
| 481 | + std::string value = ""; | ||
| 482 | + int32_t ret = sinkProxy.ConfigDistributedHardware(devId, dhId, key, value); | ||
| 483 | + EXPECT_EQ(DCAMERA_BAD_VALUE, ret); | ||
| 484 | +} | ||
| 485 | + | ||
| 486 | +/** | ||
| 487 | + * @tc.name: dcamera_sink_stub_test_023 | ||
| 488 | + * @tc.desc: Verify ConfigDistributedHardwareInner directly with valid params. | ||
| 489 | + * @tc.type: FUNC | ||
| 490 | + * @tc.require: issue | ||
| 491 | + */ | ||
| 492 | +HWTEST_F(DcameraSinkStubTest, dcamera_sink_stub_test_023, TestSize.Level1) | ||
| 493 | +{ | ||
| 494 | + DHLOGI("dcamera_sink_stub_test_023"); | ||
| 495 | + sptr<DistributedCameraSinkStub> sinkStubPtr(new MockDistributedCameraSinkStub()); | ||
| 496 | + MessageParcel data; | ||
| 497 | + MessageParcel reply; | ||
| 498 | + data.WriteString("devId_test"); | ||
| 499 | + data.WriteString("camera_0"); | ||
| 500 | + data.WriteString("enable_init_params"); | ||
| 501 | + data.WriteString(R"({"tokenId": 12345})"); | ||
| 502 | + EXPECT_EQ(DCAMERA_OK, sinkStubPtr->ConfigDistributedHardwareInner(data, reply)); | ||
| 503 | + EXPECT_EQ(DCAMERA_OK, reply.ReadInt32()); | ||
| 504 | +} | ||
| 505 | + | ||
| 506 | +/** | ||
| 507 | + * @tc.name: dcamera_sink_stub_test_024 | ||
| 508 | + * @tc.desc: Verify ConfigDistributedHardwareInner with empty data still returns DCAMERA_OK (read empty strings). | ||
| 509 | + * @tc.type: FUNC | ||
| 510 | + * @tc.require: issue | ||
| 511 | + */ | ||
| 512 | +HWTEST_F(DcameraSinkStubTest, dcamera_sink_stub_test_024, TestSize.Level1) | ||
| 513 | +{ | ||
| 514 | + DHLOGI("dcamera_sink_stub_test_024"); | ||
| 515 | + sptr<DistributedCameraSinkStub> sinkStubPtr(new MockDistributedCameraSinkStub()); | ||
| 516 | + MessageParcel data; | ||
| 517 | + MessageParcel reply; | ||
| 518 | + EXPECT_EQ(DCAMERA_OK, sinkStubPtr->ConfigDistributedHardwareInner(data, reply)); | ||
| 519 | +} | ||
| 520 | + | ||
| 521 | +/** | ||
| 522 | + * @tc.name: dcamera_sink_stub_test_025 | ||
| 523 | + * @tc.desc: Verify OnRemoteRequest routes CONFIG_DISTRIBUTED_HARDWARE code. | ||
| 524 | + * @tc.type: FUNC | ||
| 525 | + * @tc.require: issue | ||
| 526 | + */ | ||
| 527 | +HWTEST_F(DcameraSinkStubTest, dcamera_sink_stub_test_025, TestSize.Level1) | ||
| 528 | +{ | ||
| 529 | + DHLOGI("dcamera_sink_stub_test_025"); | ||
| 530 | + sptr<DistributedCameraSinkStub> sinkStubPtr(new MockDistributedCameraSinkStub()); | ||
| 531 | + MessageParcel data; | ||
| 532 | + MessageParcel reply; | ||
| 533 | + MessageOption option; | ||
| 534 | + data.WriteString("devId_test"); | ||
| 535 | + data.WriteString("camera_0"); | ||
| 536 | + data.WriteString("enable_init_params"); | ||
| 537 | + data.WriteString(R"({"tokenId": 12345})"); | ||
| 538 | + uint32_t code = static_cast<uint32_t>(IDCameraSinkInterfaceCode::CONFIG_DISTRIBUTED_HARDWARE); | ||
| 539 | + sinkStubPtr->OnRemoteRequest(code, data, reply, option); | ||
| 540 | + EXPECT_EQ(DCAMERA_OK, reply.ReadInt32()); | ||
| 541 | +} | ||
| 408 | } // namespace DistributedHardware | 542 | } // namespace DistributedHardware |
| 409 | } // namespace OHOS | 543 | } // namespace OHOS |
| @@ -119,6 +119,15 @@ public: | |||
| 119 | (void)granted; | 119 | (void)granted; |
| 120 | return DCAMERA_OK; | 120 | return DCAMERA_OK; |
| 121 | } | 121 | } |
| 122 | + int32_t ConfigDistributedHardware(const std::string &devId, const std::string &dhId, const std::string &key, | ||
| 123 | + const std::string &value) | ||
| 124 | + { | ||
| 125 | + (void)devId; | ||
| 126 | + (void)dhId; | ||
| 127 | + (void)key; | ||
| 128 | + (void)value; | ||
| 129 | + return DCAMERA_OK; | ||
| 130 | + } | ||
| 122 | }; | 131 | }; |
| 123 | } // namespace DistributedHardware | 132 | } // namespace DistributedHardware |
| 124 | } // namespace OHOS | 133 | } // namespace OHOS |
| @@ -1552,5 +1552,173 @@ HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_encoder_prepare | |||
| 1552 | EXPECT_FALSE(controller_->isEncoderReady_); | 1552 | EXPECT_FALSE(controller_->isEncoderReady_); |
| 1553 | } | 1553 | } |
| 1554 | #endif | 1554 | #endif |
| 1555 | + | ||
| 1556 | +/** | ||
| 1557 | + * @tc.name: dcamera_sink_controller_test_set_enable_first_tokenid_001 | ||
| 1558 | + * @tc.desc: Verify SetEnableFirstTokenId sets the value correctly. | ||
| 1559 | + * @tc.type: FUNC | ||
| 1560 | + * @tc.require: DTS | ||
| 1561 | + */ | ||
| 1562 | +HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_set_enable_first_tokenid_001, TestSize.Level1) | ||
| 1563 | +{ | ||
| 1564 | + controller_->enableFirstTokenId_ = 0; | ||
| 1565 | + controller_->SetEnableFirstTokenId(12345u); | ||
| 1566 | + EXPECT_EQ(controller_->enableFirstTokenId_, 12345u); | ||
| 1567 | + controller_->SetEnableFirstTokenId(0u); | ||
| 1568 | + EXPECT_EQ(controller_->enableFirstTokenId_, 0u); | ||
| 1569 | +} | ||
| 1570 | + | ||
| 1571 | +/** | ||
| 1572 | + * @tc.name: dcamera_sink_controller_test_set_trigger_first_tokenid_001 | ||
| 1573 | + * @tc.desc: Verify SetTriggerFirstTokenId sets the value correctly. | ||
| 1574 | + * @tc.type: FUNC | ||
| 1575 | + * @tc.require: DTS | ||
| 1576 | + */ | ||
| 1577 | +HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_set_trigger_first_tokenid_001, TestSize.Level1) | ||
| 1578 | +{ | ||
| 1579 | + controller_->sourceTrigFirstTokenId_ = 0; | ||
| 1580 | + controller_->SetTriggerFirstTokenId(67890u); | ||
| 1581 | + EXPECT_EQ(controller_->sourceTrigFirstTokenId_, 67890u); | ||
| 1582 | + controller_->SetTriggerFirstTokenId(0u); | ||
| 1583 | + EXPECT_EQ(controller_->sourceTrigFirstTokenId_, 0u); | ||
| 1584 | +} | ||
| 1585 | + | ||
| 1586 | +/** | ||
| 1587 | + * @tc.name: dcamera_sink_controller_test_resolve_enable_user_001 | ||
| 1588 | + * @tc.desc: Verify ResolveEnableUser returns true when enableFirstTokenId_ is 0. | ||
| 1589 | + * @tc.type: FUNC | ||
| 1590 | + * @tc.require: DTS | ||
| 1591 | + */ | ||
| 1592 | +HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_resolve_enable_user_001, TestSize.Level1) | ||
| 1593 | +{ | ||
| 1594 | + controller_->enableFirstTokenId_ = 0; | ||
| 1595 | + int32_t userId = 100; | ||
| 1596 | + uint32_t enableTokenId = 999; | ||
| 1597 | + bool ret = controller_->ResolveEnableUser(userId, enableTokenId); | ||
| 1598 | + EXPECT_TRUE(ret); | ||
| 1599 | + EXPECT_EQ(enableTokenId, 0u); | ||
| 1600 | + EXPECT_EQ(userId, 100); | ||
| 1601 | +} | ||
| 1602 | + | ||
| 1603 | +/** | ||
| 1604 | + * @tc.name: dcamera_sink_controller_test_resolve_enable_user_002 | ||
| 1605 | + * @tc.desc: Verify ResolveEnableUser returns false when enableFirstTokenId_ is invalid. | ||
| 1606 | + * @tc.type: FUNC | ||
| 1607 | + * @tc.require: DTS | ||
| 1608 | + */ | ||
| 1609 | +HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_resolve_enable_user_002, TestSize.Level1) | ||
| 1610 | +{ | ||
| 1611 | + controller_->enableFirstTokenId_ = 9999; | ||
| 1612 | + int32_t userId = 100; | ||
| 1613 | + uint32_t enableTokenId = 0; | ||
| 1614 | + bool ret = controller_->ResolveEnableUser(userId, enableTokenId); | ||
| 1615 | + EXPECT_FALSE(ret); | ||
| 1616 | +} | ||
| 1617 | + | ||
| 1618 | +/** | ||
| 1619 | + * @tc.name: dcamera_sink_controller_test_handle_capture_command_001 | ||
| 1620 | + * @tc.desc: Verify HandleCaptureCommand with invalid JSON returns error. | ||
| 1621 | + * @tc.type: FUNC | ||
| 1622 | + * @tc.require: DTS | ||
| 1623 | + */ | ||
| 1624 | +HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_handle_capture_command_001, TestSize.Level1) | ||
| 1625 | +{ | ||
| 1626 | + std::string invalidJson = "invalid_json"; | ||
| 1627 | + int32_t ret = controller_->HandleCaptureCommand(invalidJson); | ||
| 1628 | + EXPECT_EQ(DCAMERA_BAD_VALUE, ret); | ||
| 1629 | +} | ||
| 1630 | + | ||
| 1631 | +/** | ||
| 1632 | + * @tc.name: dcamera_sink_controller_test_handle_capture_command_002 | ||
| 1633 | + * @tc.desc: Verify HandleCaptureCommand with empty string returns error. | ||
| 1634 | + * @tc.type: FUNC | ||
| 1635 | + * @tc.require: DTS | ||
| 1636 | + */ | ||
| 1637 | +HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_handle_capture_command_002, TestSize.Level1) | ||
| 1638 | +{ | ||
| 1639 | + std::string emptyJson = ""; | ||
| 1640 | + int32_t ret = controller_->HandleCaptureCommand(emptyJson); | ||
| 1641 | + EXPECT_EQ(DCAMERA_BAD_VALUE, ret); | ||
| 1642 | +} | ||
| 1643 | + | ||
| 1644 | +/** | ||
| 1645 | + * @tc.name: dcamera_sink_controller_test_handle_capture_command_003 | ||
| 1646 | + * @tc.desc: Verify HandleCaptureCommand with valid JSON sets trigger fields. | ||
| 1647 | + * @tc.type: FUNC | ||
| 1648 | + * @tc.require: DTS | ||
| 1649 | + */ | ||
| 1650 | +HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_handle_capture_command_003, TestSize.Level1) | ||
| 1651 | +{ | ||
| 1652 | + std::string validJson = R"({ | ||
| 1653 | + "Type": "OPERATION", | ||
| 1654 | + "dhId": "camera_0", | ||
| 1655 | + "Command": "CAPTURE", | ||
| 1656 | + "Value": [ | ||
| 1657 | + {"Width": 1920, "Height": 1080, "Format": 1, "DataSpace": 1, | ||
| 1658 | + "IsCapture": true, "EncodeType": 1, "StreamType": 1, | ||
| 1659 | + "CaptureSettings": [{"SettingType": 1, "SettingValue": "TestSetting"}]} | ||
| 1660 | + ], | ||
| 1661 | + "mode": 1, | ||
| 1662 | + "userId": 100, | ||
| 1663 | + "tokenId": 200, | ||
| 1664 | + "accountId": "accountId", | ||
| 1665 | + "eis": false, | ||
| 1666 | + "triggerFirstTokenId": 12345, | ||
| 1667 | + "triggerFirstUserId": 100 | ||
| 1668 | + })"; | ||
| 1669 | + controller_->sourceTrigFirstTokenId_ = 0; | ||
| 1670 | + controller_->sourceTrigFirstUserId_ = -1; | ||
| 1671 | + controller_->userId_ = -1; | ||
| 1672 | + controller_->HandleCaptureCommand(validJson); | ||
| 1673 | + EXPECT_EQ(controller_->sourceTrigFirstTokenId_, static_cast<uint32_t>(12345)); | ||
| 1674 | + EXPECT_EQ(controller_->sourceTrigFirstUserId_, 100); | ||
| 1675 | + EXPECT_EQ(controller_->sceneMode_, 1); | ||
| 1676 | + EXPECT_EQ(controller_->userId_, 100); | ||
| 1677 | + EXPECT_EQ(controller_->tokenId_, static_cast<uint64_t>(200)); | ||
| 1678 | +} | ||
| 1679 | + | ||
| 1680 | +/** | ||
| 1681 | + * @tc.name: dcamera_sink_controller_test_handle_capture_command_004 | ||
| 1682 | + * @tc.desc: Verify HandleCaptureCommand with userId=-1 skips ACL check and returns success or capture error. | ||
| 1683 | + * @tc.type: FUNC | ||
| 1684 | + * @tc.require: DTS | ||
| 1685 | + */ | ||
| 1686 | +HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_handle_capture_command_004, TestSize.Level1) | ||
| 1687 | +{ | ||
| 1688 | + std::string jsonWithNegOneUser = R"({ | ||
| 1689 | + "Type": "OPERATION", | ||
| 1690 | + "dhId": "camera_0", | ||
| 1691 | + "Command": "CAPTURE", | ||
| 1692 | + "Value": [ | ||
| 1693 | + {"Width": 1920, "Height": 1080, "Format": 1, "DataSpace": 1, | ||
| 1694 | + "IsCapture": true, "EncodeType": 1, "StreamType": 1, | ||
| 1695 | + "CaptureSettings": [{"SettingType": 1, "SettingValue": "TestSetting"}]} | ||
| 1696 | + ], | ||
| 1697 | + "mode": 0, | ||
| 1698 | + "userId": -1, | ||
| 1699 | + "tokenId": 0, | ||
| 1700 | + "accountId": "" | ||
| 1701 | + })"; | ||
| 1702 | + controller_->sourceTrigFirstUserId_ = -1; | ||
| 1703 | + controller_->HandleCaptureCommand(jsonWithNegOneUser); | ||
| 1704 | + EXPECT_EQ(controller_->userId_, -1); | ||
| 1705 | +} | ||
| 1706 | + | ||
| 1707 | +/** | ||
| 1708 | + * @tc.name: dcamera_sink_controller_test_check_acl_right_trigger_tokenid_001 | ||
| 1709 | + * @tc.desc: Verify CheckAclRight uses sourceTrigFirstTokenId_ when set. | ||
| 1710 | + * @tc.type: FUNC | ||
| 1711 | + * @tc.require: DTS | ||
| 1712 | + */ | ||
| 1713 | +HWTEST_F(DCameraSinkControllerTest, dcamera_sink_controller_test_check_acl_right_trigger_tokenid_001, TestSize.Level1) | ||
| 1714 | +{ | ||
| 1715 | + controller_->userId_ = -1; | ||
| 1716 | + controller_->sourceTrigFirstTokenId_ = 0; | ||
| 1717 | + controller_->tokenId_ = 100; | ||
| 1718 | + EXPECT_TRUE(controller_->CheckAclRight()); | ||
| 1719 | + | ||
| 1720 | + controller_->sourceTrigFirstTokenId_ = 55555; | ||
| 1721 | + EXPECT_TRUE(controller_->CheckAclRight()); | ||
| 1722 | +} | ||
| 1555 | } // namespace DistributedHardware | 1723 | } // namespace DistributedHardware |
| 1556 | } // namespace OHOS | 1724 | } // namespace OHOS |
| @@ -96,6 +96,12 @@ public: | |||
| 96 | void SetTokenId(uint64_t token) | 96 | void SetTokenId(uint64_t token) |
| 97 | { | 97 | { |
| 98 | } | 98 | } |
| 99 | + void SetEnableFirstTokenId(uint32_t tokenId) | ||
| 100 | + { | ||
| 101 | + } | ||
| 102 | + void SetTriggerFirstTokenId(uint32_t tokenId) | ||
| 103 | + { | ||
| 104 | + } | ||
| 99 | }; | 105 | }; |
| 100 | } // namespace DistributedHardware | 106 | } // namespace DistributedHardware |
| 101 | } // namespace OHOS | 107 | } // namespace OHOS |
| @@ -52,4 +52,12 @@ bool DeviceManagerImpl::CheckSrcAccessControl(const DmAccessCaller &caller, cons | |||
| 52 | return 0; | 52 | return 0; |
| 53 | } | 53 | } |
| 54 | return IDeviceManager::deviceMgrMock->CheckSrcAccessControl(caller, callee); | 54 | return IDeviceManager::deviceMgrMock->CheckSrcAccessControl(caller, callee); |
| 55 | +} | ||
| 56 | + | ||
| 57 | +bool DeviceManagerImpl::CheckSinkAccessControl(const DmAccessCaller &caller, const DmAccessCallee &callee) | ||
| 58 | +{ | ||
| 59 | + if (IDeviceManager::deviceMgrMock == nullptr) { | ||
| 60 | + return 0; | ||
| 61 | + } | ||
| 62 | + return IDeviceManager::deviceMgrMock->CheckSinkAccessControl(caller, callee); | ||
| 55 | } | 63 | } |
| @@ -31,6 +31,7 @@ public: | |||
| 31 | virtual int32_t GetUdidByNetworkId(const std::string &pkgName, const std::string &nextworkId, | 31 | virtual int32_t GetUdidByNetworkId(const std::string &pkgName, const std::string &nextworkId, |
| 32 | std::string &udid); | 32 | std::string &udid); |
| 33 | virtual bool CheckSrcAccessControl(const DmAccessCaller &caller, const DmAccessCallee &callee); | 33 | virtual bool CheckSrcAccessControl(const DmAccessCaller &caller, const DmAccessCallee &callee); |
| 34 | + virtual bool CheckSinkAccessControl(const DmAccessCaller &caller, const DmAccessCallee &callee); | ||
| 34 | public: | 35 | public: |
| 35 | static inline std::shared_ptr<IDeviceManager> deviceMgrMock = nullptr; | 36 | static inline std::shared_ptr<IDeviceManager> deviceMgrMock = nullptr; |
| 36 | }; | 37 | }; |
| @@ -44,6 +45,7 @@ public: | |||
| 44 | MOCK_METHOD3(GetUdidByNetworkId, int32_t(const std::string &pkgName, const std::string &nextworkId, | 45 | MOCK_METHOD3(GetUdidByNetworkId, int32_t(const std::string &pkgName, const std::string &nextworkId, |
| 45 | std::string &udid)); | 46 | std::string &udid)); |
| 46 | MOCK_METHOD2(CheckSrcAccessControl, bool(const DmAccessCaller &caller, const DmAccessCallee &callee)); | 47 | MOCK_METHOD2(CheckSrcAccessControl, bool(const DmAccessCaller &caller, const DmAccessCallee &callee)); |
| 48 | + MOCK_METHOD2(CheckSinkAccessControl, bool(const DmAccessCaller &caller, const DmAccessCallee &callee)); | ||
| 47 | }; | 49 | }; |
| 48 | } | 50 | } |
| 49 | } | 51 | } |
| @@ -126,6 +126,7 @@ private: | |||
| 126 | sptr<IDCameraProviderCallback> hdiCallback_; | 126 | sptr<IDCameraProviderCallback> hdiCallback_; |
| 127 | int32_t sceneMode_ = 0; | 127 | int32_t sceneMode_ = 0; |
| 128 | uint64_t tokenId_ = 0; | 128 | uint64_t tokenId_ = 0; |
| 129 | + uint32_t enableFirstTokenId_ = 0; | ||
| 129 | bool eis_ = false; | 130 | bool eis_ = false; |
| 130 | 131 | ||
| 131 | std::map<uint32_t, DCameraNotifyFunc> memberFuncMap_; | 132 | std::map<uint32_t, DCameraNotifyFunc> memberFuncMap_; |
| @@ -52,6 +52,8 @@ public: | |||
| 52 | int32_t ResumeDistributedHardware(const std::string &networkId) override; | 52 | int32_t ResumeDistributedHardware(const std::string &networkId) override; |
| 53 | int32_t StopDistributedHardware(const std::string &networkId) override; | 53 | int32_t StopDistributedHardware(const std::string &networkId) override; |
| 54 | void SetTokenId(uint64_t token) override; | 54 | void SetTokenId(uint64_t token) override; |
| 55 | + void SetEnableFirstTokenId(uint32_t tokenId) override; | ||
| 56 | + void SetTriggerFirstTokenId(uint32_t tokenId) override; | ||
| 55 | 57 | ||
| 56 | void OnSessionState(int32_t state, std::string networkId, int32_t shutdownReason = 0); | 58 | void OnSessionState(int32_t state, std::string networkId, int32_t shutdownReason = 0); |
| 57 | void OnSessionError(int32_t eventType, int32_t eventReason, std::string detail); | 59 | void OnSessionError(int32_t eventType, int32_t eventReason, std::string detail); |
| @@ -63,6 +65,7 @@ private: | |||
| 63 | int32_t PublishEnableLatencyMsg(const std::string& devId); | 65 | int32_t PublishEnableLatencyMsg(const std::string& devId); |
| 64 | void HandleReceivedData(std::shared_ptr<DataBuffer> &dataBuffer); | 66 | void HandleReceivedData(std::shared_ptr<DataBuffer> &dataBuffer); |
| 65 | bool CheckAclRight(); | 67 | bool CheckAclRight(); |
| 68 | + bool GetTriggerUserId(uint32_t &callerTokenId, int32_t &triggerUserId, int32_t &enableUserId); | ||
| 66 | bool GetOsAccountInfo(); | 69 | bool GetOsAccountInfo(); |
| 67 | int32_t CheckOsType(const std::string &networkId, bool &isInvalid); | 70 | int32_t CheckOsType(const std::string &networkId, bool &isInvalid); |
| 68 | int32_t ParseValueFromCjson(std::string args, std::string key); | 71 | int32_t ParseValueFromCjson(std::string args, std::string key); |
| @@ -109,6 +112,9 @@ private: | |||
| 109 | int32_t userId_ = -1; | 112 | int32_t userId_ = -1; |
| 110 | std::string srcDevId_ = ""; | 113 | std::string srcDevId_ = ""; |
| 111 | uint64_t tokenId_ = 0; | 114 | uint64_t tokenId_ = 0; |
| 115 | + uint32_t enableFirstTokenId_ = 0; | ||
| 116 | + uint32_t triggerFirstTokenId_ = 0; | ||
| 117 | + int32_t triggerFirstUserId_ = -1; | ||
| 112 | }; | 118 | }; |
| 113 | 119 | ||
| 114 | class DeviceInitCallback : public DmInitCallback { | 120 | class DeviceInitCallback : public DmInitCallback { |
| @@ -282,7 +282,7 @@ int32_t DistributedCameraSourceService::RegisterDistributedHardware(const std::s | |||
| 282 | "dcamera source RegisterDistributedHardware fail."); | 282 | "dcamera source RegisterDistributedHardware fail."); |
| 283 | CamDevErase(camIndex); | 283 | CamDevErase(camIndex); |
| 284 | } | 284 | } |
| 285 | - camDev->SetTokenId(GetFirstCallerTokenID()); | 285 | + camDev->SetTokenId(OHOS::IPCSkeleton::GetFirstTokenID()); |
| 286 | DHLOGI("RegisterDistributedHardware end devId: %{public}s, dhId: %{public}s, sinkVersion: %{public}s", | 286 | DHLOGI("RegisterDistributedHardware end devId: %{public}s, dhId: %{public}s, sinkVersion: %{public}s", |
| 287 | GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), params.sinkVersion.c_str()); | 287 | GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), params.sinkVersion.c_str()); |
| 288 | return ret; | 288 | return ret; |
| @@ -16,6 +16,7 @@ | |||
| 16 | #include "dcamera_source_dev.h" | 16 | #include "dcamera_source_dev.h" |
| 17 | 17 | ||
| 18 | #include "anonymous_string.h" | 18 | #include "anonymous_string.h" |
| 19 | +#include "cJSON.h" | ||
| 19 | #include "dcamera_hisysevent_adapter.h" | 20 | #include "dcamera_hisysevent_adapter.h" |
| 20 | #include "dcamera_hitrace_adapter.h" | 21 | #include "dcamera_hitrace_adapter.h" |
| 21 | #include "dcamera_radar.h" | 22 | #include "dcamera_radar.h" |
| @@ -31,6 +32,7 @@ | |||
| 31 | #include "dcamera_source_input.h" | 32 | #include "dcamera_source_input.h" |
| 32 | #include "dcamera_utils_tools.h" | 33 | #include "dcamera_utils_tools.h" |
| 33 | #include "distributed_camera_allconnect_manager.h" | 34 | #include "distributed_camera_allconnect_manager.h" |
| 35 | +#include "accesstoken_kit.h" | ||
| 34 | 36 | ||
| 35 | namespace OHOS { | 37 | namespace OHOS { |
| 36 | namespace DistributedHardware { | 38 | namespace DistributedHardware { |
| @@ -154,6 +156,18 @@ int32_t DCameraSourceDev::ConfigDistributedHardware(const std::string& devId, co | |||
| 154 | { | 156 | { |
| 155 | DHLOGI("DCameraSourceDev ConfigDistributedHardware value %{public}s", value.c_str()); | 157 | DHLOGI("DCameraSourceDev ConfigDistributedHardware value %{public}s", value.c_str()); |
| 156 | DCameraSrcImuSensor::GetInstance().SetInitParam(value); | 158 | DCameraSrcImuSensor::GetInstance().SetInitParam(value); |
| 159 | + if (key == KEY_ENABLE_INIT_PARAM) { | ||
| 160 | + cJSON* root = cJSON_Parse(value.c_str()); | ||
| 161 | + if (root != nullptr) { | ||
| 162 | + cJSON* item = cJSON_GetObjectItemCaseSensitive(root, KEY_TOKEN_ID); | ||
| 163 | + if (item != nullptr && cJSON_IsNumber(item)) { | ||
| 164 | + enableFirstTokenId_ = static_cast<uint32_t>(item->valuedouble); | ||
| 165 | + DHLOGI("[MultiUserEnable] ConfigDistributedHardware enableFirstTokenId=%{public}s", | ||
| 166 | + GetAnonyString(std::to_string(enableFirstTokenId_)).c_str()); | ||
| 167 | + } | ||
| 168 | + cJSON_Delete(root); | ||
| 169 | + } | ||
| 170 | + } | ||
| 157 | return DCAMERA_OK; | 171 | return DCAMERA_OK; |
| 158 | } | 172 | } |
| 159 | 173 | ||
| @@ -275,6 +289,19 @@ int32_t DCameraSourceDev::ProcessHDFEvent(const DCameraHDFEvent& event) | |||
| 275 | { | 289 | { |
| 276 | DHLOGI("DCameraSourceDev ProcessHDFEvent devId %{public}s dhId %{public}s event_type %{public}d", | 290 | DHLOGI("DCameraSourceDev ProcessHDFEvent devId %{public}s dhId %{public}s event_type %{public}d", |
| 277 | GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), event.type_); | 291 | GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), event.type_); |
| 292 | + cJSON* root = cJSON_Parse(event.content_.c_str()); | ||
| 293 | + if (root != nullptr) { | ||
| 294 | + cJSON* item = cJSON_GetObjectItemCaseSensitive(root, KEY_TRIGGER_FIRST_TOKENID); | ||
| 295 | + if (item != nullptr && cJSON_IsNumber(item)) { | ||
| 296 | + uint32_t triggerFirstTokenId = static_cast<uint32_t>(item->valuedouble); | ||
| 297 | + DHLOGI("[MultiUserTrigger] ProcessHDFEvent triggerFirstTokenId=%{public}s", | ||
| 298 | + GetAnonyString(std::to_string(triggerFirstTokenId)).c_str()); | ||
| 299 | + if (controller_ != nullptr) { | ||
| 300 | + controller_->SetTriggerFirstTokenId(triggerFirstTokenId); | ||
| 301 | + } | ||
| 302 | + } | ||
| 303 | + cJSON_Delete(root); | ||
| 304 | + } | ||
| 278 | if (event.type_ == EVENT_DCAMERA_FORCE_SWITCH) { | 305 | if (event.type_ == EVENT_DCAMERA_FORCE_SWITCH) { |
| 279 | DCameraSystemSwitchInfo::GetInstance().SetSystemSwitchFlagAndRotation(devId_, true, event.result_); | 306 | DCameraSystemSwitchInfo::GetInstance().SetSystemSwitchFlagAndRotation(devId_, true, event.result_); |
| 280 | DHLOGI("recv force switch event from hdf, result: %{public}d", event.result_); | 307 | DHLOGI("recv force switch event from hdf, result: %{public}d", event.result_); |
| @@ -494,6 +521,7 @@ int32_t DCameraSourceDev::OpenCamera() | |||
| 494 | GetAnonyString(dhId_).c_str()); | 521 | GetAnonyString(dhId_).c_str()); |
| 495 | ReportCameraOperaterEvent(OPEN_CAMERA_EVENT, GetAnonyString(devId_), dhId_, "execute open camera event."); | 522 | ReportCameraOperaterEvent(OPEN_CAMERA_EVENT, GetAnonyString(devId_), dhId_, "execute open camera event."); |
| 496 | controller_->SetTokenId(tokenId_); | 523 | controller_->SetTokenId(tokenId_); |
| 524 | + controller_->SetEnableFirstTokenId(enableFirstTokenId_); | ||
| 497 | std::shared_ptr<DCameraOpenInfo> openInfo = std::make_shared<DCameraOpenInfo>(); | 525 | std::shared_ptr<DCameraOpenInfo> openInfo = std::make_shared<DCameraOpenInfo>(); |
| 498 | int32_t ret = GetLocalDeviceNetworkId(openInfo->sourceDevId_); | 526 | int32_t ret = GetLocalDeviceNetworkId(openInfo->sourceDevId_); |
| 499 | DcameraRadar::GetInstance().ReportDcameraOpen("GetLocalDeviceNetworkId", CameraOpen::OPEN_CAMERA, | 527 | DcameraRadar::GetInstance().ReportDcameraOpen("GetLocalDeviceNetworkId", CameraOpen::OPEN_CAMERA, |
| @@ -39,6 +39,8 @@ | |||
| 39 | #include "distributed_hardware_log.h" | 39 | #include "distributed_hardware_log.h" |
| 40 | #include "idistributed_camera_sink.h" | 40 | #include "idistributed_camera_sink.h" |
| 41 | #include "dcamera_low_latency.h" | 41 | #include "dcamera_low_latency.h" |
| 42 | +#include "accesstoken_kit.h" | ||
| 43 | +#include "ipc_skeleton.h" | ||
| 42 | #ifdef OS_ACCOUNT_ENABLE | 44 | #ifdef OS_ACCOUNT_ENABLE |
| 43 | #include "ohos_account_kits.h" | 45 | #include "ohos_account_kits.h" |
| 44 | #include "os_account_manager.h" | 46 | #include "os_account_manager.h" |
| @@ -89,6 +91,8 @@ int32_t DCameraSourceController::StartCapture(std::vector<std::shared_ptr<DCamer | |||
| 89 | cmd.tokenId_ = tokenId_; | 91 | cmd.tokenId_ = tokenId_; |
| 90 | cmd.accountId_ = accountId_; | 92 | cmd.accountId_ = accountId_; |
| 91 | cmd.eis_ = eis; | 93 | cmd.eis_ = eis; |
| 94 | + cmd.triggerFirstTokenId_ = triggerFirstTokenId_; | ||
| 95 | + cmd.triggerFirstUserId_ = triggerFirstUserId_; | ||
| 92 | std::string jsonStr; | 96 | std::string jsonStr; |
| 93 | int32_t ret = cmd.Marshal(jsonStr); | 97 | int32_t ret = cmd.Marshal(jsonStr); |
| 94 | if (ret != DCAMERA_OK) { | 98 | if (ret != DCAMERA_OK) { |
| @@ -96,8 +100,9 @@ int32_t DCameraSourceController::StartCapture(std::vector<std::shared_ptr<DCamer | |||
| 96 | GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); | 100 | GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); |
| 97 | return ret; | 101 | return ret; |
| 98 | } | 102 | } |
| 99 | - DHLOGI("devId: %{public}s, dhId: %{public}s captureCommand: %{public}s", GetAnonyString(devId).c_str(), | 103 | + DHLOGI("devId: %{public}s, dhId: %{public}s captureCommand: %{public}s, TokenId=%{public}s, UserId=%{public}d", |
| 100 | - GetAnonyString(dhId).c_str(), cmd.command_.c_str()); | 104 | + GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), cmd.command_.c_str(), |
| 105 | + GetAnonyString(std::to_string(triggerFirstTokenId_)).c_str(), triggerFirstUserId_); | ||
| 101 | std::shared_ptr<DataBuffer> buffer = std::make_shared<DataBuffer>(jsonStr.length() + 1); | 106 | std::shared_ptr<DataBuffer> buffer = std::make_shared<DataBuffer>(jsonStr.length() + 1); |
| 102 | ret = memcpy_s(buffer->Data(), buffer->Capacity(), reinterpret_cast<uint8_t *>(const_cast<char *>(jsonStr.c_str())), | 107 | ret = memcpy_s(buffer->Data(), buffer->Capacity(), reinterpret_cast<uint8_t *>(const_cast<char *>(jsonStr.c_str())), |
| 103 | jsonStr.length()); | 108 | jsonStr.length()); |
| @@ -425,17 +430,24 @@ bool DCameraSourceController::CheckAclRight() | |||
| 425 | if (!GetOsAccountInfo()) { | 430 | if (!GetOsAccountInfo()) { |
| 426 | return false; | 431 | return false; |
| 427 | } | 432 | } |
| 428 | - std::shared_ptr<DmInitCallback> initCallback = std::make_shared<DeviceInitCallback>(); | 433 | + uint32_t callerTokenId = 0; |
| 429 | - int32_t ret = DeviceManager::GetInstance().InitDeviceManager(DCAMERA_PKG_NAME, initCallback); | 434 | + int32_t triggerUserId = -1; |
| 430 | - if (ret != DCAMERA_OK) { | 435 | + int32_t enableUserId = -1; |
| 431 | - DHLOGE("InitDeviceManager failed ret = %{public}d", ret); | 436 | + if (!GetTriggerUserId(callerTokenId, triggerUserId, enableUserId)) { |
| 432 | return false; | 437 | return false; |
| 433 | } | 438 | } |
| 439 | + std::shared_ptr<DmInitCallback> initCallback = std::make_shared<DeviceInitCallback>(); | ||
| 440 | + int32_t dmRet = DeviceManager::GetInstance().InitDeviceManager(DCAMERA_PKG_NAME, initCallback); | ||
| 441 | + if (dmRet != DCAMERA_OK) { | ||
| 442 | + DHLOGE("InitDeviceManager failed ret = %{public}d", dmRet); | ||
| 443 | + return false; | ||
| 444 | + } | ||
| 445 | + int32_t aclUserId = (triggerUserId != -1) ? triggerUserId : userId_; | ||
| 434 | DmAccessCaller dmSrcCaller = { | 446 | DmAccessCaller dmSrcCaller = { |
| 435 | .accountId = accountId_, | 447 | .accountId = accountId_, |
| 436 | .pkgName = DCAMERA_PKG_NAME, | 448 | .pkgName = DCAMERA_PKG_NAME, |
| 437 | .networkId = srcDevId_, | 449 | .networkId = srcDevId_, |
| 438 | - .userId = userId_, | 450 | + .userId = aclUserId, |
| 439 | .tokenId = tokenId_, | 451 | .tokenId = tokenId_, |
| 440 | }; | 452 | }; |
| 441 | DmAccessCallee dmDstCallee = { | 453 | DmAccessCallee dmDstCallee = { |
| @@ -443,10 +455,39 @@ bool DCameraSourceController::CheckAclRight() | |||
| 443 | }; | 455 | }; |
| 444 | DHLOGI("CheckAclRight dmSrcCaller networkId: %{public}s, accountId: %{public}s, devId: %{public}s", | 456 | DHLOGI("CheckAclRight dmSrcCaller networkId: %{public}s, accountId: %{public}s, devId: %{public}s", |
| 445 | GetAnonyString(srcDevId_).c_str(), GetAnonyString(accountId_).c_str(), GetAnonyString(devId_).c_str()); | 457 | GetAnonyString(srcDevId_).c_str(), GetAnonyString(accountId_).c_str(), GetAnonyString(devId_).c_str()); |
| 446 | - if (DeviceManager::GetInstance().CheckSrcAccessControl(dmSrcCaller, dmDstCallee)) { | 458 | + return DeviceManager::GetInstance().CheckSrcAccessControl(dmSrcCaller, dmDstCallee); |
| 447 | - return true; | 459 | +} |
| 460 | + | ||
| 461 | +bool DCameraSourceController::GetTriggerUserId(uint32_t &callerTokenId, int32_t &triggerUserId, | ||
| 462 | + int32_t &enableUserId) | ||
| 463 | +{ | ||
| 464 | + callerTokenId = (triggerFirstTokenId_ != 0) ? triggerFirstTokenId_ : IPCSkeleton::GetCallingTokenID(); | ||
【安全检视意见|自动扫描】【中危】认证与授权绕过(身份伪造) GetTriggerUserId 中 callerTokenId 优先取自 HDF 事件 JSON 解析出的 triggerFirstTokenId,覆盖了框架验证的 IPCSkeleton::GetCallingTokenID(),且该值直接影响 ACL 校验所用的 userId(aclUserId)。HDF 事件内容被伪造或异常时,授权判定使用的身份会随之改变。 建议:以 GetCallingTokenID() 为权威身份来源,triggerFirstTokenId 仅作辅助信息;确需使用时应校验其与当前调用方身份一致后再参与授权判定。
![]() ![]() | |||
| 465 | + Security::AccessToken::HapTokenInfo callerTokenInfo; | ||
| 466 | + triggerUserId = -1; | ||
| 467 | + enableUserId = -1; | ||
| 468 | + bool isSA = Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(callerTokenId) == | ||
| 469 | + Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE; | ||
| 470 | + if (!isSA) { | ||
| 471 | + int32_t res = Security::AccessToken::AccessTokenKit::GetHapTokenInfo(callerTokenId, callerTokenInfo); | ||
| 472 | + if (res != 0) { | ||
| 473 | + DHLOGI("[MultiUserTrigger] get hap token info failed,ret = %{public}d", res); | ||
| 474 | + return false; | ||
| 475 | + } | ||
| 476 | + triggerUserId = callerTokenInfo.userID; | ||
| 477 | + triggerFirstUserId_ = triggerUserId; | ||
| 448 | } | 478 | } |
| 449 | - return false; | 479 | + if (enableFirstTokenId_ != 0) { |
| 480 | + Security::AccessToken::HapTokenInfo enableTokenInfo; | ||
| 481 | + int32_t enableRet = Security::AccessToken::AccessTokenKit::GetHapTokenInfo( | ||
| 482 | + enableFirstTokenId_, enableTokenInfo); | ||
| 483 | + enableUserId = (enableRet == 0) ? enableTokenInfo.userID : -1; | ||
| 484 | + } | ||
| 485 | + if (enableUserId != -1 && triggerUserId != -1 && enableUserId != triggerUserId) { | ||
| 486 | + DHLOGE("[MultiUserTrigger] userId mismatch! enableUserId=%{public}d != triggerUserId=%{public}d", | ||
tokenId匿名打印 ![]() ![]() | |||
| 487 | + enableUserId, triggerUserId); | ||
| 488 | + return false; | ||
| 489 | + } | ||
| 490 | + return true; | ||
| 450 | } | 491 | } |
| 451 | 492 | ||
| 452 | bool DCameraSourceController::GetOsAccountInfo() | 493 | bool DCameraSourceController::GetOsAccountInfo() |
| @@ -745,6 +786,16 @@ void DCameraSourceController::SetTokenId(uint64_t token) | |||
| 745 | tokenId_ = token; | 786 | tokenId_ = token; |
| 746 | } | 787 | } |
| 747 | 788 | ||
| 789 | +void DCameraSourceController::SetEnableFirstTokenId(uint32_t tokenId) | ||
| 790 | +{ | ||
| 791 | + enableFirstTokenId_ = tokenId; | ||
| 792 | +} | ||
| 793 | + | ||
| 794 | +void DCameraSourceController::SetTriggerFirstTokenId(uint32_t tokenId) | ||
| 795 | +{ | ||
| 796 | + triggerFirstTokenId_ = tokenId; | ||
| 797 | +} | ||
| 798 | + | ||
| 748 | void DeviceInitCallback::OnRemoteDied() | 799 | void DeviceInitCallback::OnRemoteDied() |
| 749 | { | 800 | { |
| 750 | DHLOGI("DeviceInitCallback OnRemoteDied"); | 801 | DHLOGI("DeviceInitCallback OnRemoteDied"); |
| @@ -212,7 +212,7 @@ HWTEST_F(DCameraSourceControllerTest, dcamera_source_controller_test_003, TestSi | |||
| 212 | int32_t mode = 0; | 212 | int32_t mode = 0; |
| 213 | ret = controller_->StartCapture(captureInfos, mode, false); | 213 | ret = controller_->StartCapture(captureInfos, mode, false); |
| 214 | controller_->UnInit(); | 214 | controller_->UnInit(); |
| 215 | - EXPECT_EQ(ret, DCAMERA_OK); | 215 | + EXPECT_EQ(ret, DCAMERA_BAD_VALUE); |
| 216 | } | 216 | } |
| 217 | 217 | ||
| 218 | /** | 218 | /** |
| @@ -1670,7 +1670,6 @@ HWTEST_F(DCameraSourceControllerTest, dcamera_source_controller_test_check_os_ty | |||
| 1670 | */ | 1670 | */ |
| 1671 | HWTEST_F(DCameraSourceControllerTest, dcamera_source_controller_test_check_acl_right_001, TestSize.Level1) | 1671 | HWTEST_F(DCameraSourceControllerTest, dcamera_source_controller_test_check_acl_right_001, TestSize.Level1) |
| 1672 | { | 1672 | { |
| 1673 | - // Given: Setup controller state | ||
| 1674 | controller_->accountId_ = "test_account_id"; | 1673 | controller_->accountId_ = "test_account_id"; |
| 1675 | controller_->srcDevId_ = "test_src_dev_id"; | 1674 | controller_->srcDevId_ = "test_src_dev_id"; |
| 1676 | controller_->devId_ = "test_dev_id"; | 1675 | controller_->devId_ = "test_dev_id"; |
| @@ -1955,5 +1954,162 @@ HWTEST_F(DCameraSourceControllerTest, dcamera_source_controller_test_on_session_ | |||
| 1955 | EXPECT_EQ(state, controller_->channelState_); | 1954 | EXPECT_EQ(state, controller_->channelState_); |
| 1956 | EXPECT_TRUE(controller_->isChannelConnected_.load()); | 1955 | EXPECT_TRUE(controller_->isChannelConnected_.load()); |
| 1957 | } | 1956 | } |
| 1957 | + | ||
| 1958 | +/** | ||
| 1959 | + * @tc.name: dcamera_source_controller_test_set_enable_first_tokenid_001 | ||
| 1960 | + * @tc.desc: Verify SetEnableFirstTokenId sets the value correctly. | ||
| 1961 | + * @tc.type: FUNC | ||
| 1962 | + * @tc.require: DTS | ||
| 1963 | + */ | ||
| 1964 | +HWTEST_F(DCameraSourceControllerTest, dcamera_source_controller_test_set_enable_first_tokenid_001, TestSize.Level1) | ||
| 1965 | +{ | ||
| 1966 | + controller_->enableFirstTokenId_ = 0; | ||
| 1967 | + controller_->SetEnableFirstTokenId(12345u); | ||
| 1968 | + EXPECT_EQ(controller_->enableFirstTokenId_, 12345u); | ||
| 1969 | + controller_->SetEnableFirstTokenId(0u); | ||
| 1970 | + EXPECT_EQ(controller_->enableFirstTokenId_, 0u); | ||
| 1971 | +} | ||
| 1972 | + | ||
| 1973 | +/** | ||
| 1974 | + * @tc.name: dcamera_source_controller_test_set_trigger_first_tokenid_001 | ||
| 1975 | + * @tc.desc: Verify SetTriggerFirstTokenId sets the value correctly. | ||
| 1976 | + * @tc.type: FUNC | ||
| 1977 | + * @tc.require: DTS | ||
| 1978 | + */ | ||
| 1979 | +HWTEST_F(DCameraSourceControllerTest, dcamera_source_controller_test_set_trigger_first_tokenid_001, TestSize.Level1) | ||
| 1980 | +{ | ||
| 1981 | + controller_->triggerFirstTokenId_ = 0; | ||
| 1982 | + controller_->SetTriggerFirstTokenId(67890u); | ||
| 1983 | + EXPECT_EQ(controller_->triggerFirstTokenId_, 67890u); | ||
| 1984 | + controller_->SetTriggerFirstTokenId(0u); | ||
| 1985 | + EXPECT_EQ(controller_->triggerFirstTokenId_, 0u); | ||
| 1986 | +} | ||
| 1987 | + | ||
| 1988 | +/** | ||
| 1989 | + * @tc.name: dcamera_source_controller_test_get_trigger_user_id_001 | ||
| 1990 | + * @tc.desc: Verify GetTriggerUserId with triggerFirstTokenId_ set to non-zero uses it as callerTokenId. | ||
| 1991 | + * @tc.type: FUNC | ||
| 1992 | + * @tc.require: DTS | ||
| 1993 | + */ | ||
| 1994 | +HWTEST_F(DCameraSourceControllerTest, dcamera_source_controller_test_get_trigger_user_id_001, TestSize.Level1) | ||
| 1995 | +{ | ||
| 1996 | + controller_->triggerFirstTokenId_ = 67890u; | ||
| 1997 | + controller_->enableFirstTokenId_ = 0; | ||
| 1998 | + controller_->triggerFirstUserId_ = -1; | ||
| 1999 | + uint32_t callerTokenId = 0; | ||
| 2000 | + int32_t triggerUserId = -1; | ||
| 2001 | + int32_t enableUserId = -1; | ||
| 2002 | + controller_->GetTriggerUserId(callerTokenId, triggerUserId, enableUserId); | ||
| 2003 | + EXPECT_EQ(callerTokenId, 67890u); | ||
| 2004 | +} | ||
| 2005 | + | ||
| 2006 | +/** | ||
| 2007 | + * @tc.name: dcamera_source_controller_test_get_trigger_user_id_002 | ||
| 2008 | + * @tc.desc: Verify GetTriggerUserId with enableFirstTokenId_ set but triggerFirstTokenId_ zero. | ||
| 2009 | + * @tc.type: FUNC | ||
| 2010 | + * @tc.require: DTS | ||
| 2011 | + */ | ||
| 2012 | +HWTEST_F(DCameraSourceControllerTest, dcamera_source_controller_test_get_trigger_user_id_002, TestSize.Level1) | ||
| 2013 | +{ | ||
| 2014 | + controller_->triggerFirstTokenId_ = 0; | ||
| 2015 | + controller_->enableFirstTokenId_ = 12345u; | ||
| 2016 | + uint32_t callerTokenId = 0; | ||
| 2017 | + int32_t triggerUserId = -1; | ||
| 2018 | + int32_t enableUserId = -1; | ||
| 2019 | + controller_->GetTriggerUserId(callerTokenId, triggerUserId, enableUserId); | ||
| 2020 | + EXPECT_EQ(enableUserId, -1); | ||
| 2021 | +} | ||
| 2022 | + | ||
| 2023 | +/** | ||
| 2024 | + * @tc.name: dcamera_source_controller_test_get_trigger_user_id_003 | ||
| 2025 | + * @tc.desc: Verify GetTriggerUserId with both enableFirstTokenId_ and triggerFirstTokenId_ set to non-zero. | ||
| 2026 | + * @tc.type: FUNC | ||
| 2027 | + * @tc.require: DTS | ||
| 2028 | + */ | ||
| 2029 | +HWTEST_F(DCameraSourceControllerTest, dcamera_source_controller_test_get_trigger_user_id_003, TestSize.Level1) | ||
| 2030 | +{ | ||
| 2031 | + controller_->triggerFirstTokenId_ = 111u; | ||
| 2032 | + controller_->enableFirstTokenId_ = 222u; | ||
| 2033 | + uint32_t callerTokenId = 0; | ||
| 2034 | + int32_t triggerUserId = -1; | ||
| 2035 | + int32_t enableUserId = -1; | ||
| 2036 | + controller_->GetTriggerUserId(callerTokenId, triggerUserId, enableUserId); | ||
| 2037 | + EXPECT_EQ(callerTokenId, 111u); | ||
| 2038 | +} | ||
| 2039 | + | ||
| 2040 | +/** | ||
| 2041 | + * @tc.name: dcamera_source_controller_test_check_acl_right_with_trigger_001 | ||
| 2042 | + * @tc.desc: Verify CheckAclRight with triggerFirstTokenId_ set (uses triggerUserId for ACL). | ||
| 2043 | + * @tc.type: FUNC | ||
| 2044 | + * @tc.require: DTS | ||
| 2045 | + */ | ||
| 2046 | +HWTEST_F(DCameraSourceControllerTest, dcamera_source_controller_test_check_acl_right_with_trigger_001, TestSize.Level1) | ||
| 2047 | +{ | ||
| 2048 | + controller_->accountId_ = "test_account_id"; | ||
| 2049 | + controller_->srcDevId_ = "test_src_dev_id"; | ||
| 2050 | + controller_->devId_ = "test_dev_id"; | ||
| 2051 | + controller_->userId_ = 100; | ||
| 2052 | + controller_->tokenId_ = 200; | ||
| 2053 | + controller_->triggerFirstTokenId_ = 67890u; | ||
| 2054 | + controller_->enableFirstTokenId_ = 0; | ||
| 2055 | + | ||
| 2056 | + bool result = controller_->CheckAclRight(); | ||
| 2057 | + EXPECT_FALSE(result); | ||
| 2058 | +} | ||
| 2059 | + | ||
| 2060 | +/** | ||
| 2061 | + * @tc.name: dcamera_source_controller_test_check_acl_right_with_trigger_002 | ||
| 2062 | + * @tc.desc: Verify CheckAclRight with both triggerFirstTokenId_ and enableFirstTokenId_ set. | ||
| 2063 | + * @tc.type: FUNC | ||
| 2064 | + * @tc.require: DTS | ||
| 2065 | + */ | ||
| 2066 | +HWTEST_F(DCameraSourceControllerTest, dcamera_source_controller_test_check_acl_right_with_trigger_002, TestSize.Level1) | ||
| 2067 | +{ | ||
| 2068 | + controller_->accountId_ = "test_account_id"; | ||
| 2069 | + controller_->srcDevId_ = "test_src_dev_id"; | ||
| 2070 | + controller_->devId_ = "test_dev_id"; | ||
| 2071 | + controller_->userId_ = 100; | ||
| 2072 | + controller_->tokenId_ = 200; | ||
| 2073 | + controller_->triggerFirstTokenId_ = 111u; | ||
| 2074 | + controller_->enableFirstTokenId_ = 222u; | ||
| 2075 | + | ||
| 2076 | + bool result = controller_->CheckAclRight(); | ||
| 2077 | + EXPECT_FALSE(result); | ||
| 2078 | +} | ||
| 2079 | + | ||
| 2080 | +/** | ||
| 2081 | + * @tc.name: dcamera_source_controller_test_start_capture_with_trigger_001 | ||
| 2082 | + * @tc.desc: Verify StartCapture sets triggerFirstTokenId_ and triggerFirstUserId_ in the cmd. | ||
| 2083 | + * @tc.type: FUNC | ||
| 2084 | + * @tc.require: DTS | ||
| 2085 | + */ | ||
| 2086 | +HWTEST_F(DCameraSourceControllerTest, dcamera_source_controller_test_start_capture_with_trigger_001, TestSize.Level1) | ||
| 2087 | +{ | ||
| 2088 | + DCameraIndex index; | ||
| 2089 | + index.devId_ = TEST_DEVICE_ID; | ||
| 2090 | + index.dhId_ = TEST_CAMERA_DH_ID_0; | ||
| 2091 | + controller_->indexs_.push_back(index); | ||
| 2092 | + controller_->triggerFirstTokenId_ = 12345u; | ||
| 2093 | + controller_->triggerFirstUserId_ = 100; | ||
| 2094 | + controller_->accountId_ = "test_account"; | ||
| 2095 | + controller_->tokenId_ = 200; | ||
| 2096 | + controller_->userId_ = 100; | ||
| 2097 | + | ||
| 2098 | + std::vector<std::shared_ptr<DCameraCaptureInfo>> captureInfos; | ||
| 2099 | + std::shared_ptr<DCameraCaptureInfo> capture = std::make_shared<DCameraCaptureInfo>(); | ||
| 2100 | + capture->width_ = TEST_WIDTH; | ||
| 2101 | + capture->height_ = TEST_HEIGTH; | ||
| 2102 | + capture->format_ = TEST_FORMAT; | ||
| 2103 | + capture->dataspace_ = TEST_DATASPACE; | ||
| 2104 | + capture->isCapture_ = TEST_ISCAPTURE; | ||
| 2105 | + capture->encodeType_ = DCEncodeType::ENCODE_TYPE_H264; | ||
| 2106 | + capture->streamType_ = DCStreamType::SNAPSHOT_FRAME; | ||
| 2107 | + captureInfos.push_back(capture); | ||
| 2108 | + | ||
| 2109 | + int32_t mode = 0; | ||
| 2110 | + int32_t ret = controller_->StartCapture(captureInfos, mode, false); | ||
| 2111 | + EXPECT_EQ(ret, DCAMERA_BAD_VALUE); | ||
| 2112 | + controller_->UnInit(); | ||
| 2113 | +} | ||
| 1958 | } | 2114 | } |
| 1959 | } | 2115 | } |
| @@ -22,6 +22,7 @@ | |||
| 22 | #include "accesstoken_kit.h" | 22 | #include "accesstoken_kit.h" |
| 23 | #include "dcamera_source_state.h" | 23 | #include "dcamera_source_state.h" |
| 24 | #include "dcamera_utils_tools.h" | 24 | #include "dcamera_utils_tools.h" |
| 25 | +#include "distributed_camera_constants.h" | ||
| 25 | #include "distributed_camera_errno.h" | 26 | #include "distributed_camera_errno.h" |
| 26 | #include "dcamera_source_dev.h" | 27 | #include "dcamera_source_dev.h" |
| 27 | #include "mock_dcamera_source_dev.h" | 28 | #include "mock_dcamera_source_dev.h" |
| @@ -796,5 +797,178 @@ HWTEST_F(DCameraSourceDevTest, processHDFEvent_001, TestSize.Level1) { | |||
| 796 | int32_t rotate = DCameraSystemSwitchInfo::GetInstance().GetSystemSwitchRotation(TEST_DEVICE_ID); | 797 | int32_t rotate = DCameraSystemSwitchInfo::GetInstance().GetSystemSwitchRotation(TEST_DEVICE_ID); |
| 797 | EXPECT_EQ(rotate, 90); | 798 | EXPECT_EQ(rotate, 90); |
| 798 | } | 799 | } |
| 800 | + | ||
| 801 | +/** | ||
| 802 | + * @tc.name: dcamera_source_dev_test_config_dh_001 | ||
| 803 | + * @tc.desc: Verify ConfigDistributedHardware with enable_init_params key sets enableFirstTokenId_. | ||
| 804 | + * @tc.type: FUNC | ||
| 805 | + * @tc.require: Issue Number | ||
| 806 | + */ | ||
| 807 | +HWTEST_F(DCameraSourceDevTest, dcamera_source_dev_test_config_dh_001, TestSize.Level1) | ||
| 808 | +{ | ||
| 809 | + camDev_->enableFirstTokenId_ = 0; | ||
| 810 | + std::string key = KEY_ENABLE_INIT_PARAM; | ||
| 811 | + std::string value = R"({"tokenId": 12345})"; | ||
| 812 | + int32_t ret = camDev_->ConfigDistributedHardware(TEST_DEVICE_ID, TEST_CAMERA_DH_ID_0, key, value); | ||
| 813 | + EXPECT_EQ(DCAMERA_OK, ret); | ||
| 814 | + EXPECT_EQ(camDev_->enableFirstTokenId_, static_cast<uint32_t>(12345)); | ||
| 815 | +} | ||
| 816 | + | ||
| 817 | +/** | ||
| 818 | + * @tc.name: dcamera_source_dev_test_config_dh_002 | ||
| 819 | + * @tc.desc: Verify ConfigDistributedHardware with non-enable_init_params key does not set enableFirstTokenId_. | ||
| 820 | + * @tc.type: FUNC | ||
| 821 | + * @tc.require: Issue Number | ||
| 822 | + */ | ||
| 823 | +HWTEST_F(DCameraSourceDevTest, dcamera_source_dev_test_config_dh_002, TestSize.Level1) | ||
| 824 | +{ | ||
| 825 | + camDev_->enableFirstTokenId_ = 0; | ||
| 826 | + std::string key = "other_key"; | ||
| 827 | + std::string value = R"({"tokenId": 99999})"; | ||
| 828 | + int32_t ret = camDev_->ConfigDistributedHardware(TEST_DEVICE_ID, TEST_CAMERA_DH_ID_0, key, value); | ||
| 829 | + EXPECT_EQ(DCAMERA_OK, ret); | ||
| 830 | + EXPECT_EQ(camDev_->enableFirstTokenId_, static_cast<uint32_t>(0)); | ||
| 831 | +} | ||
| 832 | + | ||
| 833 | +/** | ||
| 834 | + * @tc.name: dcamera_source_dev_test_config_dh_003 | ||
| 835 | + * @tc.desc: Verify ConfigDistributedHardware with invalid JSON does not crash. | ||
| 836 | + * @tc.type: FUNC | ||
| 837 | + * @tc.require: Issue Number | ||
| 838 | + */ | ||
| 839 | +HWTEST_F(DCameraSourceDevTest, dcamera_source_dev_test_config_dh_003, TestSize.Level1) | ||
| 840 | +{ | ||
| 841 | + camDev_->enableFirstTokenId_ = 0; | ||
| 842 | + std::string key = KEY_ENABLE_INIT_PARAM; | ||
| 843 | + std::string value = "invalid_json"; | ||
| 844 | + int32_t ret = camDev_->ConfigDistributedHardware(TEST_DEVICE_ID, TEST_CAMERA_DH_ID_0, key, value); | ||
| 845 | + EXPECT_EQ(DCAMERA_OK, ret); | ||
| 846 | + EXPECT_EQ(camDev_->enableFirstTokenId_, static_cast<uint32_t>(0)); | ||
| 847 | +} | ||
| 848 | + | ||
| 849 | +/** | ||
| 850 | + * @tc.name: dcamera_source_dev_test_config_dh_004 | ||
| 851 | + * @tc.desc: Verify ConfigDistributedHardware with enable_init_params key but no tokenId field. | ||
| 852 | + * @tc.type: FUNC | ||
| 853 | + * @tc.require: Issue Number | ||
| 854 | + */ | ||
| 855 | +HWTEST_F(DCameraSourceDevTest, dcamera_source_dev_test_config_dh_004, TestSize.Level1) | ||
| 856 | +{ | ||
| 857 | + camDev_->enableFirstTokenId_ = 0; | ||
| 858 | + std::string key = KEY_ENABLE_INIT_PARAM; | ||
| 859 | + std::string value = R"({"otherField": "value"})"; | ||
| 860 | + int32_t ret = camDev_->ConfigDistributedHardware(TEST_DEVICE_ID, TEST_CAMERA_DH_ID_0, key, value); | ||
| 861 | + EXPECT_EQ(DCAMERA_OK, ret); | ||
| 862 | + EXPECT_EQ(camDev_->enableFirstTokenId_, static_cast<uint32_t>(0)); | ||
| 863 | +} | ||
| 864 | + | ||
| 865 | +/** | ||
| 866 | + * @tc.name: dcamera_source_dev_test_config_dh_005 | ||
| 867 | + * @tc.desc: Verify ConfigDistributedHardware with tokenId of wrong type (string instead of number). | ||
| 868 | + * @tc.type: FUNC | ||
| 869 | + * @tc.require: Issue Number | ||
| 870 | + */ | ||
| 871 | +HWTEST_F(DCameraSourceDevTest, dcamera_source_dev_test_config_dh_005, TestSize.Level1) | ||
| 872 | +{ | ||
| 873 | + camDev_->enableFirstTokenId_ = 0; | ||
| 874 | + std::string key = KEY_ENABLE_INIT_PARAM; | ||
| 875 | + std::string value = R"({"tokenId": "not_a_number"})"; | ||
| 876 | + int32_t ret = camDev_->ConfigDistributedHardware(TEST_DEVICE_ID, TEST_CAMERA_DH_ID_0, key, value); | ||
| 877 | + EXPECT_EQ(DCAMERA_OK, ret); | ||
| 878 | + EXPECT_EQ(camDev_->enableFirstTokenId_, static_cast<uint32_t>(0)); | ||
| 879 | +} | ||
| 880 | + | ||
| 881 | +/** | ||
| 882 | + * @tc.name: dcamera_source_dev_test_config_dh_006 | ||
| 883 | + * @tc.desc: Verify ConfigDistributedHardware called multiple times updates enableFirstTokenId_. | ||
| 884 | + * @tc.type: FUNC | ||
| 885 | + * @tc.require: Issue Number | ||
| 886 | + */ | ||
| 887 | +HWTEST_F(DCameraSourceDevTest, dcamera_source_dev_test_config_dh_006, TestSize.Level1) | ||
| 888 | +{ | ||
| 889 | + camDev_->enableFirstTokenId_ = 0; | ||
| 890 | + std::string key = KEY_ENABLE_INIT_PARAM; | ||
| 891 | + int32_t ret = camDev_->ConfigDistributedHardware(TEST_DEVICE_ID, TEST_CAMERA_DH_ID_0, key, | ||
| 892 | + R"({"tokenId": 111})"); | ||
| 893 | + EXPECT_EQ(DCAMERA_OK, ret); | ||
| 894 | + EXPECT_EQ(camDev_->enableFirstTokenId_, static_cast<uint32_t>(111)); | ||
| 895 | + | ||
| 896 | + ret = camDev_->ConfigDistributedHardware(TEST_DEVICE_ID, TEST_CAMERA_DH_ID_0, key, | ||
| 897 | + R"({"tokenId": 222})"); | ||
| 898 | + EXPECT_EQ(DCAMERA_OK, ret); | ||
| 899 | + EXPECT_EQ(camDev_->enableFirstTokenId_, static_cast<uint32_t>(222)); | ||
| 900 | +} | ||
| 901 | + | ||
| 902 | +/** | ||
| 903 | + * @tc.name: dcamera_source_dev_test_process_hdf_trigger_001 | ||
| 904 | + * @tc.desc: Verify ProcessHDFEvent parses triggerFirstTokenId from event content. | ||
| 905 | + * @tc.type: FUNC | ||
| 906 | + * @tc.require: Issue Number | ||
| 907 | + */ | ||
| 908 | +HWTEST_F(DCameraSourceDevTest, dcamera_source_dev_test_process_hdf_trigger_001, TestSize.Level1) | ||
| 909 | +{ | ||
| 910 | + camDev_->InitDCameraSourceDev(); | ||
| 911 | + camDev_->controller_ = std::make_shared<MockDCameraSourceController>(); | ||
| 912 | + DCameraHDFEvent event; | ||
| 913 | + event.type_ = EVENT_DCAMERA_FORCE_SWITCH; | ||
| 914 | + event.result_ = 0; | ||
| 915 | + event.content_ = R"({"triggerFirstTokenId": 12345})"; | ||
| 916 | + int32_t result = camDev_->ProcessHDFEvent(event); | ||
| 917 | + EXPECT_EQ(result, DCAMERA_OK); | ||
| 918 | +} | ||
| 919 | + | ||
| 920 | +/** | ||
| 921 | + * @tc.name: dcamera_source_dev_test_process_hdf_trigger_002 | ||
| 922 | + * @tc.desc: Verify ProcessHDFEvent with content without triggerFirstTokenId does not crash. | ||
| 923 | + * @tc.type: FUNC | ||
| 924 | + * @tc.require: Issue Number | ||
| 925 | + */ | ||
| 926 | +HWTEST_F(DCameraSourceDevTest, dcamera_source_dev_test_process_hdf_trigger_002, TestSize.Level1) | ||
| 927 | +{ | ||
| 928 | + camDev_->InitDCameraSourceDev(); | ||
| 929 | + camDev_->controller_ = std::make_shared<MockDCameraSourceController>(); | ||
| 930 | + DCameraHDFEvent event; | ||
| 931 | + event.type_ = EVENT_DCAMERA_FORCE_SWITCH; | ||
| 932 | + event.result_ = 0; | ||
| 933 | + event.content_ = R"({"otherField": "value"})"; | ||
| 934 | + int32_t result = camDev_->ProcessHDFEvent(event); | ||
| 935 | + EXPECT_EQ(result, DCAMERA_OK); | ||
| 936 | +} | ||
| 937 | + | ||
| 938 | +/** | ||
| 939 | + * @tc.name: dcamera_source_dev_test_process_hdf_trigger_003 | ||
| 940 | + * @tc.desc: Verify ProcessHDFEvent with invalid JSON content does not crash. | ||
| 941 | + * @tc.type: FUNC | ||
| 942 | + * @tc.require: Issue Number | ||
| 943 | + */ | ||
| 944 | +HWTEST_F(DCameraSourceDevTest, dcamera_source_dev_test_process_hdf_trigger_003, TestSize.Level1) | ||
| 945 | +{ | ||
| 946 | + camDev_->InitDCameraSourceDev(); | ||
| 947 | + camDev_->controller_ = std::make_shared<MockDCameraSourceController>(); | ||
| 948 | + DCameraHDFEvent event; | ||
| 949 | + event.type_ = EVENT_DCAMERA_FORCE_SWITCH; | ||
| 950 | + event.result_ = 0; | ||
| 951 | + event.content_ = "invalid_json"; | ||
| 952 | + int32_t result = camDev_->ProcessHDFEvent(event); | ||
| 953 | + EXPECT_EQ(result, DCAMERA_OK); | ||
| 954 | +} | ||
| 955 | + | ||
| 956 | +/** | ||
| 957 | + * @tc.name: dcamera_source_dev_test_process_hdf_trigger_004 | ||
| 958 | + * @tc.desc: Verify ProcessHDFEvent with null controller does not crash. | ||
| 959 | + * @tc.type: FUNC | ||
| 960 | + * @tc.require: Issue Number | ||
| 961 | + */ | ||
| 962 | +HWTEST_F(DCameraSourceDevTest, dcamera_source_dev_test_process_hdf_trigger_004, TestSize.Level1) | ||
| 963 | +{ | ||
| 964 | + camDev_->InitDCameraSourceDev(); | ||
| 965 | + camDev_->controller_ = nullptr; | ||
| 966 | + DCameraHDFEvent event; | ||
| 967 | + event.type_ = EVENT_DCAMERA_FORCE_SWITCH; | ||
| 968 | + event.result_ = 0; | ||
| 969 | + event.content_ = R"({"triggerFirstTokenId": 12345})"; | ||
| 970 | + int32_t result = camDev_->ProcessHDFEvent(event); | ||
| 971 | + EXPECT_EQ(result, DCAMERA_OK); | ||
| 972 | +} | ||
| 799 | } // namespace DistributedHardware | 973 | } // namespace DistributedHardware |
| 800 | } // namespace OHOS | 974 | } // namespace OHOS |
| @@ -88,6 +88,12 @@ public: | |||
| 88 | void SetTokenId(uint64_t token) | 88 | void SetTokenId(uint64_t token) |
| 89 | { | 89 | { |
| 90 | } | 90 | } |
| 91 | + void SetEnableFirstTokenId(uint32_t tokenId) | ||
| 92 | + { | ||
| 93 | + } | ||
| 94 | + void SetTriggerFirstTokenId(uint32_t tokenId) | ||
| 95 | + { | ||
| 96 | + } | ||
| 91 | }; | 97 | }; |
| 92 | class MockDCameraSourceControllerRetErr : public MockDCameraSourceController { | 98 | class MockDCameraSourceControllerRetErr : public MockDCameraSourceController { |
| 93 | public: | 99 | public: |


新老版本兼容性验证下