已开启
MultiUser: add trigger token support, extract magic constants, fix CheckAclRight #971
韦国庆创建于 14 天前
MultiUser: add trigger token support, extract magic constants, fix CheckAclRight #971
已开启
共 31 个文件变更+889-109
| @@ -74,7 +74,8 @@ | |||
| 74 | "//foundation/distributedhardware/distributed_camera/services/data_process:distributed_camera_data_process", | 74 | "//foundation/distributedhardware/distributed_camera/services/data_process:distributed_camera_data_process", |
| 75 | "//foundation/distributedhardware/distributed_camera/sa_profile:dcamera_sa_profile", | 75 | "//foundation/distributedhardware/distributed_camera/sa_profile:dcamera_sa_profile", |
| 76 | "//foundation/distributedhardware/distributed_camera/sa_profile:dcamera.cfg", | 76 | "//foundation/distributedhardware/distributed_camera/sa_profile:dcamera.cfg", |
| 77 | - "//foundation/distributedhardware/distributed_camera/services/channel:distributed_camera_channel" | 77 | + "//foundation/distributedhardware/distributed_camera/services/channel:distributed_camera_channel", |
| 78 | + "//foundation/distributedhardware/distributed_camera/services/test_example:distributed_camera_demo_test" | ||
| 78 | ], | 79 | ], |
| 79 | "test": [ | 80 | "test": [ |
| 80 | "//foundation/distributedhardware/distributed_camera/common/test/unittest:common_utils_test", | 81 | "//foundation/distributedhardware/distributed_camera/common/test/unittest:common_utils_test", |
| @@ -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); |
| @@ -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) |
| @@ -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 | 15 | ||
| 17 | 16 | ||
| 18 | - | ||
| 19 | 17 | ||
| 20 | - | ||
| 21 | 18 | ||
| 22 | 19 | ||
| 23 | 20 | ||
| @@ -38,7 +35,6 @@ | |||
| 38 | 35 | ||
| 39 | 36 | ||
| 40 | 37 | ||
| 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 | 66 | ||
| 75 | actualSize_ = width_ * height_ * YUV_BYTES_PER_PIXEL / Y2UV_RATIO; | 67 | actualSize_ = width_ * height_ * YUV_BYTES_PER_PIXEL / Y2UV_RATIO; |
| 76 | 68 | ||
| 77 | actualSize_ = width_ * height_ * RGB_BYTES_PER_PIXEL; | 69 | actualSize_ = width_ * height_ * RGB_BYTES_PER_PIXEL; |
| 78 | 70 | ||
| 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 MatchForegroundUser(int32_t &matchedUserId); | ||
| 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"; |
| @@ -24,6 +24,7 @@ | |||
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | 26 | ||
| 27 | + | ||
| 27 | 28 | ||
| 28 | 29 | ||
| 29 | 30 | ||
| @@ -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,24 @@ 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 | + cJSON* item = cJSON_GetObjectItemCaseSensitive(root, KEY_TOKEN_ID); | ||
| 488 | + if (item != nullptr && cJSON_IsNumber(item)) { | ||
| 489 | + enableFirstTokenId_ = static_cast<uint32_t>(item->valuedouble); | ||
| 490 | + DHLOGI("[MultiUserEnable] ConfigDistributedHardware enableFirstTokenId=%{public}u", | ||
| 491 | + enableFirstTokenId_); | ||
| 492 | + } | ||
| 493 | + cJSON_Delete(root); | ||
| 494 | + } | ||
| 495 | + } | ||
| 496 | + return DCAMERA_OK; | ||
| 497 | +} | ||
| 478 | } // namespace DistributedHardware | 498 | } // namespace DistributedHardware |
| 479 | } // namespace OHOS | 499 | } // 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 |
| @@ -47,6 +47,7 @@ | |||
| 47 | 47 | ||
| 48 | 48 | ||
| 49 | 49 | ||
| 50 | + | ||
| 50 | 51 | ||
| 51 | 52 | ||
| 52 | 53 | ||
| @@ -874,25 +875,7 @@ int32_t DCameraSinkController::HandleReceivedData(std::shared_ptr<DataBuffer>& d | |||
| 874 | std::string command = std::string(comvalue->valuestring); | 875 | std::string command = std::string(comvalue->valuestring); |
| 875 | cJSON_Delete(rootValue); | 876 | cJSON_Delete(rootValue); |
| 876 | if ((!command.empty()) && (command.compare(DCAMERA_PROTOCOL_CMD_CAPTURE) == 0)) { | 877 | if ((!command.empty()) && (command.compare(DCAMERA_PROTOCOL_CMD_CAPTURE) == 0)) { |
| 877 | - DCameraCaptureInfoCmd captureInfoCmd; | 878 | + 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 | - | ||
| 893 | - CHECK_AND_RETURN_RET_LOG(!IsIdenticalAccount(srcDevId_), DCAMERA_BAD_VALUE, "Account check failed."); | ||
| 894 | - | ||
| 895 | - return StartCapture(captureInfoCmd.value_, sceneMode_, captureInfoCmd.eis_); | ||
| 896 | } else if ((!command.empty()) && (command.compare(DCAMERA_PROTOCOL_CMD_UPDATE_METADATA) == 0)) { | 879 | } else if ((!command.empty()) && (command.compare(DCAMERA_PROTOCOL_CMD_UPDATE_METADATA) == 0)) { |
| 897 | DCameraMetadataSettingCmd metadataSettingCmd; | 880 | DCameraMetadataSettingCmd metadataSettingCmd; |
| 898 | int32_t ret = metadataSettingCmd.Unmarshal(jsonStr); | 881 | int32_t ret = metadataSettingCmd.Unmarshal(jsonStr); |
| @@ -908,10 +891,36 @@ int32_t DCameraSinkController::HandleReceivedData(std::shared_ptr<DataBuffer>& d | |||
| 908 | return DCAMERA_BAD_VALUE; | 891 | return DCAMERA_BAD_VALUE; |
| 909 | } | 892 | } |
| 910 | 893 | ||
| 894 | +int32_t DCameraSinkController::HandleCaptureCommand(const std::string &jsonStr) | ||
| 895 | +{ | ||
| 896 | + DCameraCaptureInfoCmd captureInfoCmd; | ||
| 897 | + int32_t ret = captureInfoCmd.Unmarshal(jsonStr); | ||
| 898 | + if (ret != DCAMERA_OK) { | ||
| 899 | + DHLOGE("Capture Info Unmarshal failed, dhId: %{public}s ret: %{public}d", | ||
| 900 | + GetAnonyString(dhId_).c_str(), ret); | ||
| 901 | + return ret; | ||
| 902 | + } | ||
| 903 | + sceneMode_ = captureInfoCmd.sceneMode_; | ||
| 904 | + userId_ = captureInfoCmd.userId_; | ||
| 905 | + tokenId_ = captureInfoCmd.tokenId_; | ||
| 906 | + accountId_ = captureInfoCmd.accountId_; | ||
| 907 | + sourceTrigFirstTokenId_ = captureInfoCmd.triggerFirstTokenId_; | ||
| 908 | + sourceTrigFirstUserId_ = captureInfoCmd.triggerFirstUserId_; | ||
| 909 | + DHLOGI("[MultiUserSink] Sink received sourceTrigFirstTokenId=%{public}u, sourceTrigFirstUserId=%{public}d", | ||
| 910 | + sourceTrigFirstTokenId_, sourceTrigFirstUserId_); | ||
| 911 | + if (!CheckAclRight()) { | ||
| 912 | + DHLOGE("ACL check failed."); | ||
| 913 | + return DCAMERA_BAD_VALUE; | ||
| 914 | + } | ||
| 915 | + | ||
| 916 | + CHECK_AND_RETURN_RET_LOG(!IsIdenticalAccount(srcDevId_), DCAMERA_BAD_VALUE, "Account check failed."); | ||
| 917 | + | ||
| 918 | + return StartCapture(captureInfoCmd.value_, sceneMode_, captureInfoCmd.eis_); | ||
| 919 | +} | ||
| 920 | + | ||
| 911 | bool DCameraSinkController::CheckAclRight() | 921 | bool DCameraSinkController::CheckAclRight() |
| 912 | { | 922 | { |
| 913 | if (userId_ == -1) { | 923 | if (userId_ == -1) { |
| 914 | - DHLOGI("Acl check version compatibility processing."); | ||
| 915 | return true; | 924 | return true; |
| 916 | } | 925 | } |
| 917 | std::string sinkDevId; | 926 | std::string sinkDevId; |
| @@ -922,16 +931,20 @@ bool DCameraSinkController::CheckAclRight() | |||
| 922 | 931 | ||
| 923 | std::vector<int32_t> ids; | 932 | std::vector<int32_t> ids; |
| 924 | ret = AccountSA::OsAccountManager::QueryActiveOsAccountIds(ids); | 933 | ret = AccountSA::OsAccountManager::QueryActiveOsAccountIds(ids); |
| 925 | - CHECK_AND_RETURN_RET_LOG(ret != DCAMERA_OK || ids.empty(), false, | 934 | + CHECK_AND_RETURN_RET_LOG(ret != DCAMERA_OK || ids.empty(), false, "Get userId fail, ret: %{public}d", ret); |
| 926 | - "Get userId from active os accountIds fail, ret: %{public}d", ret); | ||
| 927 | userId = ids[0]; | 935 | userId = ids[0]; |
| 928 | - | ||
| 929 | AccountSA::OhosAccountInfo osAccountInfo; | 936 | AccountSA::OhosAccountInfo osAccountInfo; |
| 930 | ret = AccountSA::OhosAccountKits::GetInstance().GetOhosAccountInfo(osAccountInfo); | 937 | ret = AccountSA::OhosAccountKits::GetInstance().GetOhosAccountInfo(osAccountInfo); |
| 931 | - CHECK_AND_RETURN_RET_LOG(ret != DCAMERA_OK, false, | 938 | + 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_; | 939 | accountId = osAccountInfo.uid_; |
| 934 | 940 | ||
| 941 | + int32_t matchedUserId = -1; | ||
| 942 | + if (!MatchForegroundUser(matchedUserId)) { | ||
| 943 | + return false; | ||
| 944 | + } | ||
| 945 | + if (matchedUserId != -1) { | ||
| 946 | + userId = matchedUserId; | ||
| 947 | + } | ||
| 935 | ret = DeviceManager::GetInstance().InitDeviceManager(DCAMERA_PKG_NAME, initCallback_); | 948 | ret = DeviceManager::GetInstance().InitDeviceManager(DCAMERA_PKG_NAME, initCallback_); |
| 936 | if (ret != DCAMERA_OK) { | 949 | if (ret != DCAMERA_OK) { |
| 937 | DHLOGE("InitDeviceManager failed ret = %{public}d", ret); | 950 | DHLOGE("InitDeviceManager failed ret = %{public}d", ret); |
| @@ -942,7 +955,7 @@ bool DCameraSinkController::CheckAclRight() | |||
| 942 | .pkgName = DCAMERA_PKG_NAME, | 955 | .pkgName = DCAMERA_PKG_NAME, |
| 943 | .networkId = srcDevId_, | 956 | .networkId = srcDevId_, |
| 944 | .userId = userId_, | 957 | .userId = userId_, |
| 945 | - .tokenId = tokenId_, | 958 | + .tokenId = (sourceTrigFirstTokenId_ != 0) ? sourceTrigFirstTokenId_ : tokenId_, |
| 946 | }; | 959 | }; |
| 947 | DmAccessCallee dmDstCallee = { | 960 | DmAccessCallee dmDstCallee = { |
| 948 | .accountId = accountId, | 961 | .accountId = accountId, |
| @@ -951,11 +964,32 @@ bool DCameraSinkController::CheckAclRight() | |||
| 951 | .userId = userId, | 964 | .userId = userId, |
| 952 | .tokenId = sinkTokenId_, | 965 | .tokenId = sinkTokenId_, |
| 953 | }; | 966 | }; |
| 954 | - DHLOGI("CheckAclRight srcDevId: %{public}s, accountId: %{public}s, sinkDevId: %{public}s", | ||
| 955 | - GetAnonyString(srcDevId_).c_str(), GetAnonyString(accountId).c_str(), GetAnonyString(sinkDevId).c_str()); | ||
| 956 | return DeviceManager::GetInstance().CheckSinkAccessControl(dmSrcCaller, dmDstCallee); | 967 | return DeviceManager::GetInstance().CheckSinkAccessControl(dmSrcCaller, dmDstCallee); |
| 957 | } | 968 | } |
| 958 | 969 | ||
| 970 | +bool DCameraSinkController::MatchForegroundUser(int32_t &matchedUserId) | ||
| 971 | +{ | ||
| 972 | + matchedUserId = -1; | ||
| 973 | + if (sourceTrigFirstUserId_ == -1) { | ||
| 974 | + return true; | ||
| 975 | + } | ||
| 976 | + | ||
| 977 | + std::vector<int32_t> activeIds; | ||
| 978 | + AccountSA::OsAccountManager::QueryActiveOsAccountIds(activeIds); | ||
| 979 | + for (auto &localId : activeIds) { | ||
| 980 | + if (localId == sourceTrigFirstUserId_) { | ||
| 981 | + matchedUserId = localId; | ||
| 982 | + break; | ||
| 983 | + } | ||
| 984 | + } | ||
| 985 | + | ||
| 986 | + if (matchedUserId == -1) { | ||
| 987 | + DHLOGE("[MultiUserSink] no active match for sourceTrigFirstUserId=%{public}d", sourceTrigFirstUserId_); | ||
| 988 | + return false; | ||
| 989 | + } | ||
| 990 | + return true; | ||
| 991 | +} | ||
| 992 | + | ||
| 959 | int32_t DCameraSinkController::PauseDistributedHardware(const std::string &networkId) | 993 | int32_t DCameraSinkController::PauseDistributedHardware(const std::string &networkId) |
| 960 | { | 994 | { |
| 961 | DHLOGI("Pause distributed hardware dhId: %{public}s", GetAnonyString(dhId_).c_str()); | 995 | DHLOGI("Pause distributed hardware dhId: %{public}s", GetAnonyString(dhId_).c_str()); |
| @@ -1092,6 +1126,16 @@ void DCameraSinkController::SetTokenId(uint64_t token) | |||
| 1092 | sinkTokenId_ = token; | 1126 | sinkTokenId_ = token; |
| 1093 | } | 1127 | } |
| 1094 | 1128 | ||
| 1129 | +void DCameraSinkController::SetEnableFirstTokenId(uint32_t tokenId) | ||
| 1130 | +{ | ||
| 1131 | + enableFirstTokenId_ = tokenId; | ||
| 1132 | +} | ||
| 1133 | + | ||
| 1134 | +void DCameraSinkController::SetTriggerFirstTokenId(uint32_t tokenId) | ||
| 1135 | +{ | ||
| 1136 | + sourceTrigFirstTokenId_ = tokenId; | ||
| 1137 | +} | ||
| 1138 | + | ||
| 1095 | void DeviceInitCallback::OnRemoteDied() | 1139 | void DeviceInitCallback::OnRemoteDied() |
| 1096 | { | 1140 | { |
| 1097 | DHLOGI("DeviceInitCallback OnRemoteDied"); | 1141 | DHLOGI("DeviceInitCallback OnRemoteDied"); |
| @@ -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 |
| @@ -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 { |
Mservices/cameraservice/sourceservice/src/distributedcamera/distributed_camera_source_service.cpp+1-1
| @@ -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 | 16 | ||
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | + | ||
| 19 | 20 | ||
| 20 | 21 | ||
| 21 | 22 | ||
| @@ -31,6 +32,7 @@ | |||
| 31 | 32 | ||
| 32 | 33 | ||
| 33 | 34 | ||
| 35 | + | ||
| 34 | 36 | ||
| 35 | namespace OHOS { | 37 | namespace OHOS { |
| 36 | namespace DistributedHardware { | 38 | namespace DistributedHardware { |
| @@ -155,6 +157,18 @@ int32_t DCameraSourceDev::ConfigDistributedHardware(const std::string& devId, co | |||
| 155 | { | 157 | { |
| 156 | DHLOGI("DCameraSourceDev ConfigDistributedHardware value %{public}s", value.c_str()); | 158 | DHLOGI("DCameraSourceDev ConfigDistributedHardware value %{public}s", value.c_str()); |
| 157 | DCameraSrcImuSensor::GetInstance().SetInitParam(value); | 159 | DCameraSrcImuSensor::GetInstance().SetInitParam(value); |
| 160 | + if (key == KEY_ENABLE_INIT_PARAM) { | ||
| 161 | + cJSON* root = cJSON_Parse(value.c_str()); | ||
| 162 | + if (root != nullptr) { | ||
| 163 | + cJSON* item = cJSON_GetObjectItemCaseSensitive(root, KEY_TOKEN_ID); | ||
| 164 | + if (item != nullptr && cJSON_IsNumber(item)) { | ||
| 165 | + enableFirstTokenId_ = static_cast<uint32_t>(item->valuedouble); | ||
| 166 | + DHLOGI("[MultiUserEnable] ConfigDistributedHardware enableFirstTokenId=%{public}u", | ||
| 167 | + enableFirstTokenId_); | ||
| 168 | + } | ||
| 169 | + cJSON_Delete(root); | ||
| 170 | + } | ||
| 171 | + } | ||
| 158 | return DCAMERA_OK; | 172 | return DCAMERA_OK; |
| 159 | } | 173 | } |
| 160 | 174 | ||
| @@ -276,6 +290,18 @@ int32_t DCameraSourceDev::ProcessHDFEvent(const DCameraHDFEvent& event) | |||
| 276 | { | 290 | { |
| 277 | DHLOGI("DCameraSourceDev ProcessHDFEvent devId %{public}s dhId %{public}s event_type %{public}d", | 291 | DHLOGI("DCameraSourceDev ProcessHDFEvent devId %{public}s dhId %{public}s event_type %{public}d", |
| 278 | GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), event.type_); | 292 | GetAnonyString(devId_).c_str(), GetAnonyString(dhId_).c_str(), event.type_); |
| 293 | + cJSON* root = cJSON_Parse(event.content_.c_str()); | ||
| 294 | + if (root != nullptr) { | ||
| 295 | + cJSON* item = cJSON_GetObjectItemCaseSensitive(root, KEY_TRIGGER_FIRST_TOKENID); | ||
| 296 | + if (item != nullptr && cJSON_IsNumber(item)) { | ||
| 297 | + uint32_t triggerFirstTokenId = static_cast<uint32_t>(item->valuedouble); | ||
| 298 | + DHLOGI("[MultiUserTrigger] ProcessHDFEvent triggerFirstTokenId=%{public}u", triggerFirstTokenId); | ||
| 299 | + if (controller_ != nullptr) { | ||
| 300 | + controller_->SetTriggerFirstTokenId(triggerFirstTokenId); | ||
| 301 | + } | ||
| 302 | + } | ||
| 303 | + cJSON_Delete(root); | ||
| 304 | + } | ||
| 279 | if (event.type_ == EVENT_DCAMERA_FORCE_SWITCH) { | 305 | if (event.type_ == EVENT_DCAMERA_FORCE_SWITCH) { |
| 280 | DCameraSystemSwitchInfo::GetInstance().SetSystemSwitchFlagAndRotation(devId_, true, event.result_); | 306 | DCameraSystemSwitchInfo::GetInstance().SetSystemSwitchFlagAndRotation(devId_, true, event.result_); |
| 281 | 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_); |
| @@ -495,6 +521,7 @@ int32_t DCameraSourceDev::OpenCamera() | |||
| 495 | GetAnonyString(dhId_).c_str()); | 521 | GetAnonyString(dhId_).c_str()); |
| 496 | ReportCameraOperaterEvent(OPEN_CAMERA_EVENT, GetAnonyString(devId_), dhId_, "execute open camera event."); | 522 | ReportCameraOperaterEvent(OPEN_CAMERA_EVENT, GetAnonyString(devId_), dhId_, "execute open camera event."); |
| 497 | controller_->SetTokenId(tokenId_); | 523 | controller_->SetTokenId(tokenId_); |
| 524 | + controller_->SetEnableFirstTokenId(enableFirstTokenId_); | ||
| 498 | std::shared_ptr<DCameraOpenInfo> openInfo = std::make_shared<DCameraOpenInfo>(); | 525 | std::shared_ptr<DCameraOpenInfo> openInfo = std::make_shared<DCameraOpenInfo>(); |
| 499 | int32_t ret = GetLocalDeviceNetworkId(openInfo->sourceDevId_); | 526 | int32_t ret = GetLocalDeviceNetworkId(openInfo->sourceDevId_); |
| 500 | DcameraRadar::GetInstance().ReportDcameraOpen("GetLocalDeviceNetworkId", CameraOpen::OPEN_CAMERA, | 527 | DcameraRadar::GetInstance().ReportDcameraOpen("GetLocalDeviceNetworkId", CameraOpen::OPEN_CAMERA, |
| @@ -39,6 +39,8 @@ | |||
| 39 | 39 | ||
| 40 | 40 | ||
| 41 | 41 | ||
| 42 | + | ||
| 43 | + | ||
| 42 | 44 | ||
| 43 | 45 | ||
| 44 | 46 | ||
| @@ -89,6 +91,9 @@ 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_; | ||
| 96 | + DHLOGI("TokenId=%{public}u, UserId=%{public}d to sink", triggerFirstTokenId_, triggerFirstUserId_); | ||
| 92 | std::string jsonStr; | 97 | std::string jsonStr; |
| 93 | int32_t ret = cmd.Marshal(jsonStr); | 98 | int32_t ret = cmd.Marshal(jsonStr); |
| 94 | if (ret != DCAMERA_OK) { | 99 | if (ret != DCAMERA_OK) { |
| @@ -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(); | ||
| 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", | ||
| 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"); |
| @@ -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"; |
| @@ -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: |
| @@ -0,0 +1,82 @@ | |||
| 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 | +import("//build/ohos.gni") | ||
| 15 | +import("../../distributedcamera.gni") | ||
| 16 | + | ||
| 17 | +ohos_executable("distributed_camera_demo_test") { | ||
| 18 | + sanitize = { | ||
| 19 | + cfi = true | ||
| 20 | + cfi_cross_dso = true | ||
| 21 | + debug = false | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + include_dirs = [ | ||
| 25 | + "${common_path}/include/constants", | ||
| 26 | + "${common_path}/include/utils", | ||
| 27 | + "${innerkits_path}/native_cpp/camera_source/include", | ||
| 28 | + ] | ||
| 29 | + | ||
| 30 | + sources = [ | ||
| 31 | + "distributedcameratest.cpp", | ||
| 32 | + "${innerkits_path}/native_cpp/camera_source/src/dcamera_hdf_operate.cpp", | ||
| 33 | + ] | ||
| 34 | + | ||
| 35 | + deps = [ "${common_path}:distributed_camera_utils" ] | ||
| 36 | + | ||
| 37 | + external_deps = [ | ||
| 38 | + "access_token:libtoken_setproc", | ||
| 39 | + "access_token:libaccesstoken_sdk", | ||
| 40 | + "access_token:libnativetoken_shared", | ||
| 41 | + "access_token:libtokensetproc_shared", | ||
| 42 | + "c_utils:utils", | ||
| 43 | + "distributed_hardware_fwk:distributedhardwareutils", | ||
| 44 | + "drivers_interface_camera:libcamera_stub_1.3", | ||
| 45 | + "drivers_interface_camera:metadata", | ||
| 46 | + "drivers_interface_distributed_camera:libdistributed_camera_provider_proxy_1.1", | ||
| 47 | + "drivers_interface_distributed_camera:libdistributed_camera_provider_stub_1.1", | ||
| 48 | + "hilog:libhilog", | ||
| 49 | + "hdf_core:libhdf_ipc_adapter", | ||
| 50 | + "hdf_core:libhdi", | ||
| 51 | + "hdf_core:libpub_utils", | ||
| 52 | + "ipc:ipc_core", | ||
| 53 | + "samgr:samgr_proxy", | ||
| 54 | + "drivers_interface_camera:libcamera_proxy_1.0", | ||
| 55 | + "drivers_interface_camera:libcamera_proxy_1.1", | ||
| 56 | + "drivers_interface_camera:libcamera_proxy_1.2", | ||
| 57 | + "drivers_interface_camera:libcamera_proxy_1.3", | ||
| 58 | + "drivers_interface_camera:libcamera_proxy_1.4", | ||
| 59 | + "drivers_interface_camera:libcamera_proxy_1.5", | ||
| 60 | + "drivers_interface_camera:libcamera_proxy_1.6", | ||
| 61 | + "drivers_interface_camera:libcamera_proxy_1.7", | ||
| 62 | + "drivers_interface_camera:libbuffer_producer_sequenceable_1.0", | ||
| 63 | + "drivers_interface_display:libdisplay_composer_hdi_impl_1.3", | ||
| 64 | + "drivers_interface_display:libdisplay_composer_proxy_1.0", | ||
| 65 | + "drivers_interface_distributed_camera:libdistributed_camera_provider_stub_1.1", | ||
| 66 | + "graphic_surface:buffer_handle", | ||
| 67 | + "graphic_surface:surface", | ||
| 68 | + "graphic_surface:sync_fence", | ||
| 69 | + "hdf_core:libhdf_utils", | ||
| 70 | + "ipc:ipc_single", | ||
| 71 | + ] | ||
| 72 | + | ||
| 73 | + defines = [ | ||
| 74 | + "DH_LOG_TAG=\"dcameraTest\"", | ||
| 75 | + "HI_LOG_ENABLE", | ||
| 76 | + "LOG_DOMAIN=0xD004150", | ||
| 77 | + ] | ||
| 78 | + | ||
| 79 | + install_enable = false | ||
| 80 | + subsystem_name = "distributedhardware" | ||
| 81 | + part_name = "distributed_camera" | ||
| 82 | +} | ||
| @@ -0,0 +1,413 @@ | |||
| 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 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + | ||
| 23 | + | ||
| 24 | + | ||
| 25 | + | ||
| 26 | + | ||
| 27 | + | ||
| 28 | + | ||
| 29 | + | ||
| 30 | + | ||
| 31 | + | ||
| 32 | + | ||
| 33 | + | ||
| 34 | + | ||
| 35 | + | ||
| 36 | + | ||
| 37 | + | ||
| 38 | + | ||
| 39 | + | ||
| 40 | + | ||
| 41 | + | ||
| 42 | + | ||
| 43 | +namespace { | ||
| 44 | +constexpr int32_t RET_OK = 0; | ||
| 45 | +constexpr int32_t RET_ERR = -1; | ||
| 46 | + | ||
| 47 | +// connectionType 取值(OHOS_ABILITY_CAMERA_CONNECTION_TYPE):0=本机,1=USB,2=远端 | ||
| 48 | +constexpr uint8_t CONNECTION_TYPE_BUILTIN = 0; | ||
| 49 | +constexpr uint8_t CONNECTION_TYPE_USB = 1; | ||
| 50 | +constexpr uint8_t CONNECTION_TYPE_REMOTE = 2; | ||
| 51 | + | ||
| 52 | +const int32_t CMD_QUIT = 0; | ||
| 53 | +const int32_t CMD_FIND = 1; | ||
| 54 | +const int32_t CMD_SELECT_CAMERA = 2; | ||
| 55 | +const int32_t CMD_OPEN_CAMERA = 3; | ||
| 56 | +const int32_t CMD_CLOSE_CAMERA = 4; | ||
| 57 | +const int32_t CMD_INPUT_TOKENID = 5; | ||
| 58 | +constexpr const char *DCAMERA_SERVICE = "distributed_camera_service"; | ||
| 59 | + | ||
| 60 | +enum DeviceStatus { | ||
| 61 | + DEVICE_IDLE = 0, | ||
| 62 | + DEVICE_OPEN = 1, | ||
| 63 | + DEVICE_START = 2, | ||
| 64 | + DEVICE_STOP = 3, | ||
| 65 | +}; | ||
| 66 | + | ||
| 67 | +uint64_t g_inputTokenId = 0; | ||
| 68 | +static DeviceStatus g_cameraStatus = DeviceStatus::DEVICE_IDLE; | ||
| 69 | +static std::string g_serviceName = DCAMERA_SERVICE; | ||
| 70 | +static std::vector<std::string> g_cameraIds; | ||
| 71 | +static size_t g_selectCameraIndex = 0; | ||
| 72 | +static OHOS::sptr<OHOS::HDI::Camera::V1_0::ICameraHost> g_cameraHost = nullptr; | ||
| 73 | +static OHOS::sptr<OHOS::HDI::Camera::V1_3::ICameraHost> g_cameraHostV1_3 = nullptr; | ||
| 74 | +static OHOS::sptr<OHOS::HDI::Camera::V1_3::ICameraDevice> g_cameraDevice = nullptr; | ||
| 75 | + | ||
| 76 | +static const char *ConnectionTypeStr(uint8_t type) | ||
| 77 | +{ | ||
| 78 | + switch (type) { | ||
| 79 | + case CONNECTION_TYPE_REMOTE: | ||
| 80 | + return "REMOTE(对端)"; | ||
| 81 | + case CONNECTION_TYPE_USB: | ||
| 82 | + return "USB"; | ||
| 83 | + case CONNECTION_TYPE_BUILTIN: | ||
| 84 | + default: | ||
| 85 | + return "BUILTIN(本端)"; | ||
| 86 | + } | ||
| 87 | +} | ||
| 88 | + | ||
| 89 | +static uint8_t GetCameraConnectionType(const std::string &cameraId) | ||
| 90 | +{ | ||
| 91 | + if (g_cameraHost == nullptr) { | ||
| 92 | + return CONNECTION_TYPE_BUILTIN; | ||
| 93 | + } | ||
| 94 | + std::vector<uint8_t> abilityVec; | ||
| 95 | + int32_t ret = g_cameraHost->GetCameraAbility(cameraId, abilityVec); | ||
| 96 | + if (ret != OHOS::HDI::Camera::V1_0::NO_ERROR || abilityVec.empty()) { | ||
| 97 | + return CONNECTION_TYPE_BUILTIN; | ||
| 98 | + } | ||
| 99 | + std::shared_ptr<OHOS::Camera::CameraMetadata> ability; | ||
| 100 | + OHOS::Camera::MetadataUtils::ConvertVecToMetadata(abilityVec, ability); | ||
| 101 | + if (ability == nullptr) { | ||
| 102 | + return CONNECTION_TYPE_BUILTIN; | ||
| 103 | + } | ||
| 104 | + camera_metadata_item_t item; | ||
| 105 | + ret = OHOS::Camera::FindCameraMetadataItem(ability->get(), OHOS_ABILITY_CAMERA_CONNECTION_TYPE, &item); | ||
| 106 | + if (ret == CAM_META_SUCCESS && item.count > 0) { | ||
| 107 | + return item.data.u8[0]; | ||
| 108 | + } | ||
| 109 | + return CONNECTION_TYPE_BUILTIN; | ||
| 110 | +} | ||
| 111 | + | ||
| 112 | +class DemoCameraDeviceCallback : public OHOS::HDI::Camera::V1_0::ICameraDeviceCallback { | ||
| 113 | +public: | ||
| 114 | + DemoCameraDeviceCallback() = default; | ||
| 115 | + ~DemoCameraDeviceCallback() = default; | ||
| 116 | + | ||
| 117 | + int32_t OnError(OHOS::HDI::Camera::V1_0::ErrorType type, int32_t errorCode) override | ||
| 118 | + { | ||
| 119 | + std::cout << "DeviceCallback OnError type:" << type << " code:" << errorCode << std::endl; | ||
| 120 | + return OHOS::HDI::Camera::V1_0::NO_ERROR; | ||
| 121 | + } | ||
| 122 | + | ||
| 123 | + int32_t OnResult(uint64_t timestamp, const std::vector<uint8_t>& result) override | ||
| 124 | + { | ||
| 125 | + return OHOS::HDI::Camera::V1_0::NO_ERROR; | ||
| 126 | + } | ||
| 127 | +}; | ||
| 128 | + | ||
| 129 | +class DemoCameraHostCallback : public OHOS::HDI::Camera::V1_0::ICameraHostCallback { | ||
| 130 | +public: | ||
| 131 | + DemoCameraHostCallback() = default; | ||
| 132 | + ~DemoCameraHostCallback() = default; | ||
| 133 | + | ||
| 134 | + int32_t OnCameraStatus(const std::string& cameraId, OHOS::HDI::Camera::V1_0::CameraStatus status) override | ||
| 135 | + { | ||
| 136 | + std::cout << "HostCallback OnCameraStatus id:" << cameraId << " status:" << static_cast<int32_t>(status) | ||
| 137 | + << std::endl; | ||
| 138 | + return OHOS::HDI::Camera::V1_0::NO_ERROR; | ||
| 139 | + } | ||
| 140 | + | ||
| 141 | + int32_t OnFlashlightStatus(const std::string& cameraId, OHOS::HDI::Camera::V1_0::FlashlightStatus status) override | ||
| 142 | + { | ||
| 143 | + std::cout << "HostCallback OnFlashlightStatus id:" << cameraId | ||
| 144 | + << " status:" << static_cast<int32_t>(status) << std::endl; | ||
| 145 | + return OHOS::HDI::Camera::V1_0::NO_ERROR; | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + int32_t OnCameraEvent(const std::string& cameraId, OHOS::HDI::Camera::V1_0::CameraEvent event) override | ||
| 149 | + { | ||
| 150 | + std::cout << "HostCallback OnCameraEvent id:" << cameraId << " event:" << static_cast<int32_t>(event) | ||
| 151 | + << std::endl; | ||
| 152 | + return OHOS::HDI::Camera::V1_0::NO_ERROR; | ||
| 153 | + } | ||
| 154 | +}; | ||
| 155 | + | ||
| 156 | +static int32_t GetUserInput() | ||
| 157 | +{ | ||
| 158 | + int32_t res = -1; | ||
| 159 | + size_t count = 3; | ||
| 160 | + std::cout << ">>"; | ||
| 161 | + int ret = scanf_s("%d", &res); | ||
| 162 | + if (ret == -1) { | ||
| 163 | + std::cout << "get input error" << std::endl; | ||
| 164 | + } | ||
| 165 | + while (std::cin.fail() && count > 0) { | ||
| 166 | + std::cin.clear(); | ||
| 167 | + std::cin.ignore(); | ||
| 168 | + std::cout << "invalid input, not a number! Please retry with a number." << std::endl; | ||
| 169 | + std::cout << ">>"; | ||
| 170 | + ret = scanf_s("%d", &res); | ||
| 171 | + if (ret == -1) { | ||
| 172 | + std::cout << "get input error" << std::endl; | ||
| 173 | + } | ||
| 174 | + count--; | ||
| 175 | + } | ||
| 176 | + return res; | ||
| 177 | +} | ||
| 178 | + | ||
| 179 | +static void InputTokenId() | ||
| 180 | +{ | ||
| 181 | + std::cout << "Please input tokenId." << std::endl; | ||
| 182 | + int ret = scanf_s("%llu", &g_inputTokenId); | ||
| 183 | + if (ret != 1) { | ||
| 184 | + std::cout << "get input error" << std::endl; | ||
| 185 | + } | ||
| 186 | +} | ||
| 187 | + | ||
| 188 | +static void SetPermissions() | ||
| 189 | +{ | ||
| 190 | + const char *perms[1]; | ||
| 191 | + perms[0] = "ohos.permission.CAMERA"; | ||
| 192 | + NativeTokenInfoParams infoInstance = { | ||
| 193 | + .dcapsNum = 0, | ||
| 194 | + .permsNum = 1, | ||
| 195 | + .aclsNum = 0, | ||
| 196 | + .dcaps = NULL, | ||
| 197 | + .perms = perms, | ||
| 198 | + .acls = NULL, | ||
| 199 | + .processName = "camera_host_sample", | ||
| 200 | + .aplStr = "system_basic", | ||
| 201 | + }; | ||
| 202 | + uint64_t tokenId = GetAccessTokenId(&infoInstance); | ||
| 203 | + SetSelfTokenID(tokenId); | ||
| 204 | + OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo(); | ||
| 205 | +} | ||
| 206 | + | ||
| 207 | +static int32_t InitTestDemo() | ||
| 208 | +{ | ||
| 209 | + std::cout << "**********************************************************************************" << std::endl; | ||
| 210 | + std::cout << "Camera Host Sample (ICameraHost V1_3) v1.0" << std::endl; | ||
| 211 | + std::cout << "**********************************************************************************" << std::endl; | ||
| 212 | + std::cout << "Init camera host service, name: " << g_serviceName << std::endl; | ||
| 213 | + | ||
| 214 | + g_cameraHost = OHOS::HDI::Camera::V1_0::ICameraHost::Get(g_serviceName.c_str(), false); | ||
| 215 | + if (g_cameraHost == nullptr) { | ||
| 216 | + std::cout << "Get ICameraHost failed, check camera_host service." << std::endl; | ||
| 217 | + return RET_ERR; | ||
| 218 | + } | ||
| 219 | + std::cout << "Get V1_0 ICameraHost success." << std::endl; | ||
| 220 | + | ||
| 221 | + uint32_t majorVer = 0; | ||
| 222 | + uint32_t minorVer = 0; | ||
| 223 | + g_cameraHost->GetVersion(majorVer, minorVer); | ||
| 224 | + std::cout << "CameraHost version: " << majorVer << "." << minorVer << std::endl; | ||
| 225 | + | ||
| 226 | + g_cameraHostV1_3 = OHOS::HDI::Camera::V1_3::ICameraHost::CastFrom(g_cameraHost); | ||
| 227 | + if (g_cameraHostV1_3 == nullptr) { | ||
| 228 | + std::cout << "Cast to V1_3 ICameraHost failed, host does not support V1_3." << std::endl; | ||
| 229 | + } else { | ||
| 230 | + std::cout << "Cast to V1_3 ICameraHost success." << std::endl; | ||
| 231 | + } | ||
| 232 | + | ||
| 233 | + OHOS::sptr<DemoCameraHostCallback> hostCallback = new DemoCameraHostCallback(); | ||
| 234 | + int32_t ret = g_cameraHost->SetCallback(hostCallback); | ||
| 235 | + if (ret != OHOS::HDI::Camera::V1_0::NO_ERROR) { | ||
| 236 | + std::cout << "SetCallback failed, ret: " << ret << std::endl; | ||
| 237 | + } else { | ||
| 238 | + std::cout << "SetCallback success." << std::endl; | ||
| 239 | + } | ||
| 240 | + | ||
| 241 | + ret = g_cameraHost->GetCameraIds(g_cameraIds); | ||
| 242 | + if (ret != OHOS::HDI::Camera::V1_0::NO_ERROR) { | ||
| 243 | + std::cout << "GetCameraIds failed, ret: " << ret << std::endl; | ||
| 244 | + return RET_ERR; | ||
| 245 | + } | ||
| 246 | + std::cout << "GetCameraIds success, count: " << g_cameraIds.size() << std::endl; | ||
| 247 | + for (const auto &id : g_cameraIds) { | ||
| 248 | + std::cout << " cameraId: " << id << std::endl; | ||
| 249 | + } | ||
| 250 | + return RET_OK; | ||
| 251 | +} | ||
| 252 | + | ||
| 253 | +static void OpenCamera() | ||
| 254 | +{ | ||
| 255 | + if (g_cameraStatus != DeviceStatus::DEVICE_IDLE) { | ||
| 256 | + std::cout << "Camera device is already opened." << std::endl; | ||
| 257 | + return; | ||
| 258 | + } | ||
| 259 | + if (g_cameraHostV1_3 == nullptr) { | ||
| 260 | + std::cout << "V1_3 ICameraHost is null, cannot OpenCamera_V1_3." << std::endl; | ||
| 261 | + return; | ||
| 262 | + } | ||
| 263 | + if (g_cameraIds.empty()) { | ||
| 264 | + std::cout << "No camera id available, run find first." << std::endl; | ||
| 265 | + return; | ||
| 266 | + } | ||
| 267 | + | ||
| 268 | + if (g_inputTokenId != 0) { | ||
| 269 | + SetFirstCallerTokenID(g_inputTokenId); | ||
| 270 | + } | ||
| 271 | + | ||
| 272 | + std::string cameraId = g_cameraIds.front(); | ||
| 273 | + if (g_selectCameraIndex < g_cameraIds.size()) { | ||
| 274 | + cameraId = g_cameraIds[g_selectCameraIndex]; | ||
| 275 | + } | ||
| 276 | + uint8_t connType = GetCameraConnectionType(cameraId); | ||
| 277 | + std::cout << "Opening cameraId: " << cameraId << " connectionType: " << ConnectionTypeStr(connType) << std::endl; | ||
| 278 | + OHOS::sptr<OHOS::HDI::Camera::V1_0::ICameraDeviceCallback> callback = new DemoCameraDeviceCallback(); | ||
| 279 | + OHOS::sptr<OHOS::HDI::Camera::V1_3::ICameraDevice> device = nullptr; | ||
| 280 | + int32_t ret = g_cameraHostV1_3->OpenCamera_V1_3(cameraId, callback, device); | ||
| 281 | + if (ret != OHOS::HDI::Camera::V1_0::NO_ERROR || device == nullptr) { | ||
| 282 | + std::cout << "OpenCamera_V1_3 failed, ret: " << ret << std::endl; | ||
| 283 | + return; | ||
| 284 | + } | ||
| 285 | + g_cameraDevice = device; | ||
| 286 | + g_cameraStatus = DeviceStatus::DEVICE_OPEN; | ||
| 287 | + std::cout << "OpenCamera_V1_3 success, cameraId: " << cameraId << std::endl; | ||
| 288 | +} | ||
| 289 | + | ||
| 290 | +static void CloseCamera() | ||
| 291 | +{ | ||
| 292 | + if (g_cameraStatus == DeviceStatus::DEVICE_IDLE) { | ||
| 293 | + std::cout << "Camera device is not opened." << std::endl; | ||
| 294 | + return; | ||
| 295 | + } | ||
| 296 | + if (g_cameraDevice != nullptr) { | ||
| 297 | + g_cameraDevice->Close(); | ||
| 298 | + g_cameraDevice = nullptr; | ||
| 299 | + } | ||
| 300 | + g_cameraStatus = DeviceStatus::DEVICE_IDLE; | ||
| 301 | + std::cout << "CloseCamera success." << std::endl; | ||
| 302 | +} | ||
| 303 | + | ||
| 304 | +static void FindCameraDevice() | ||
| 305 | +{ | ||
| 306 | + if (g_cameraHost == nullptr) { | ||
| 307 | + g_cameraHost = OHOS::HDI::Camera::V1_0::ICameraHost::Get(g_serviceName.c_str(), false); | ||
| 308 | + if (g_cameraHost == nullptr) { | ||
| 309 | + std::cout << "Camera host is null, check service." << std::endl; | ||
| 310 | + return; | ||
| 311 | + } | ||
| 312 | + } | ||
| 313 | + if (g_cameraHostV1_3 == nullptr) { | ||
| 314 | + g_cameraHostV1_3 = OHOS::HDI::Camera::V1_3::ICameraHost::CastFrom(g_cameraHost); | ||
| 315 | + } | ||
| 316 | + int32_t ret = g_cameraHost->GetCameraIds(g_cameraIds); | ||
| 317 | + if (ret != OHOS::HDI::Camera::V1_0::NO_ERROR) { | ||
| 318 | + std::cout << "GetCameraIds failed, ret: " << ret << std::endl; | ||
| 319 | + return; | ||
| 320 | + } | ||
| 321 | + std::cout << "Find camera device success, count: " << g_cameraIds.size() << std::endl; | ||
| 322 | + for (size_t i = 0; i < g_cameraIds.size(); i++) { | ||
| 323 | + uint8_t connType = GetCameraConnectionType(g_cameraIds[i]); | ||
| 324 | + std::cout << " [" << i << "] cameraId: " << g_cameraIds[i] | ||
| 325 | + << " connectionType: " << ConnectionTypeStr(connType) << std::endl; | ||
| 326 | + } | ||
| 327 | + if (g_selectCameraIndex >= g_cameraIds.size()) { | ||
| 328 | + g_selectCameraIndex = 0; | ||
| 329 | + } | ||
| 330 | + std::cout << "current select index: " << g_selectCameraIndex | ||
| 331 | + << " (use 14 to change)" << std::endl; | ||
| 332 | +} | ||
| 333 | + | ||
| 334 | +static void SelectCamera() | ||
| 335 | +{ | ||
| 336 | + if (g_cameraIds.empty()) { | ||
| 337 | + std::cout << "No camera id available, run find(9) first." << std::endl; | ||
| 338 | + return; | ||
| 339 | + } | ||
| 340 | + std::cout << "Please input camera index (0-" << (g_cameraIds.size() - 1) << ")." << std::endl; | ||
| 341 | + int32_t index = -1; | ||
| 342 | + int ret = scanf_s("%d", &index); | ||
| 343 | + if (ret == -1) { | ||
| 344 | + std::cout << "get input error" << std::endl; | ||
| 345 | + } | ||
| 346 | + if (index < 0 || static_cast<size_t>(index) >= g_cameraIds.size()) { | ||
| 347 | + std::cout << "invalid index: " << index << std::endl; | ||
| 348 | + return; | ||
| 349 | + } | ||
| 350 | + g_selectCameraIndex = static_cast<size_t>(index); | ||
| 351 | + uint8_t connType = GetCameraConnectionType(g_cameraIds[g_selectCameraIndex]); | ||
| 352 | + std::cout << "selected [" << g_selectCameraIndex << "] " << g_cameraIds[g_selectCameraIndex] | ||
| 353 | + << " connectionType: " << ConnectionTypeStr(connType) << std::endl; | ||
| 354 | +} | ||
| 355 | + | ||
| 356 | +static void HandleCameraEvent(const int32_t cmd) | ||
| 357 | +{ | ||
| 358 | + switch (cmd) { | ||
| 359 | + case CMD_FIND: | ||
| 360 | + FindCameraDevice(); | ||
| 361 | + break; | ||
| 362 | + case CMD_OPEN_CAMERA: | ||
| 363 | + OpenCamera(); | ||
| 364 | + break; | ||
| 365 | + case CMD_CLOSE_CAMERA: | ||
| 366 | + CloseCamera(); | ||
| 367 | + break; | ||
| 368 | + case CMD_INPUT_TOKENID: | ||
| 369 | + InputTokenId(); | ||
| 370 | + break; | ||
| 371 | + case CMD_SELECT_CAMERA: | ||
| 372 | + SelectCamera(); | ||
| 373 | + break; | ||
| 374 | + default: | ||
| 375 | + std::cout << "Unknown operation." << std::endl; | ||
| 376 | + break; | ||
| 377 | + } | ||
| 378 | +} | ||
| 379 | + | ||
| 380 | +static void PrintInteractiveUsage() | ||
| 381 | +{ | ||
| 382 | + std::cout << std::endl << "=============== InteractiveRunTestSelect ================" << std::endl; | ||
| 383 | + std::cout << "You can respond to instructions for corresponding option:" << std::endl; | ||
| 384 | + std::cout << "\t enter 1 to find camera device. " << std::endl; | ||
| 385 | + std::cout << "\t enter 2 to select camera index (find first). " << std::endl; | ||
| 386 | + std::cout << "\t enter 3 to open camera (selected index). " << std::endl; | ||
| 387 | + std::cout << "\t enter 4 to close camera. " << std::endl; | ||
| 388 | + std::cout << "\t enter 5 to input tokenId. " << std::endl; | ||
| 389 | + std::cout << "\t enter 0 to exit. " << std::endl; | ||
| 390 | + std::cout << "hint: use service \"camera_service\"; the remote (对端) camera is the id whose " | ||
| 391 | + << "connectionType == REMOTE(对端)." << std::endl; | ||
| 392 | +} | ||
| 393 | +} // namespace | ||
| 394 | + | ||
| 395 | +int main(int argc, char *argv[]) | ||
| 396 | +{ | ||
| 397 | + SetPermissions(); | ||
| 398 | + if (InitTestDemo() != RET_OK) { | ||
| 399 | + std::cout << "InitTestDemo failed, retry find(9) after camera_host ready, or exit(0)." << std::endl; | ||
| 400 | + } | ||
| 401 | + bool quit = false; | ||
| 402 | + while (!quit) { | ||
| 403 | + PrintInteractiveUsage(); | ||
| 404 | + int32_t cmd = GetUserInput(); | ||
| 405 | + if (cmd == CMD_QUIT) { | ||
| 406 | + CloseCamera(); | ||
| 407 | + quit = true; // 退出循环 | ||
| 408 | + } else { | ||
| 409 | + HandleCameraEvent(cmd); | ||
| 410 | + } | ||
| 411 | + } | ||
| 412 | + return 0; | ||
| 413 | +} | ||
| @@ -0,0 +1,23 @@ | |||
| 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 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + | ||
| 23 | + | ||