1 /*
2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "hcamera_service.h"
17
18 #include <algorithm>
19 #include <memory>
20 #include <mutex>
21 #include <parameter.h>
22 #include <parameters.h>
23 #include <securec.h>
24 #include <string>
25 #include <unordered_set>
26 #include <vector>
27
28 #include "access_token.h"
29 #include "accesstoken_kit.h"
30 #ifdef NOTIFICATION_ENABLE
31 #include "camera_beauty_notification.h"
32 #endif
33 #include "camera_info_dumper.h"
34 #include "camera_log.h"
35 #include "camera_report_uitls.h"
36 #include "camera_util.h"
37 #include "camera_common_event_manager.h"
38 #include "datashare_predicates.h"
39 #include "datashare_result_set.h"
40 #include "deferred_processing_service.h"
41 #include "display_manager.h"
42 #include "hcamera_device_manager.h"
43 #include "hcamera_preconfig.h"
44 #ifdef DEVICE_MANAGER
45 #include "device_manager_impl.h"
46 #endif
47 #include "ipc_skeleton.h"
48 #include "iservice_registry.h"
49 #include "os_account_manager.h"
50 #include "system_ability_definition.h"
51 #include "tokenid_kit.h"
52 #include "uri.h"
53
54 namespace OHOS {
55 namespace CameraStandard {
56 REGISTER_SYSTEM_ABILITY_BY_ID(HCameraService, CAMERA_SERVICE_ID, true)
57 constexpr uint8_t POSITION_FOLD_INNER = 3;
58 constexpr uint32_t ROOT_UID = 0;
59 constexpr uint32_t FACE_CLIENT_UID = 1088;
60 constexpr uint32_t RSS_UID = 1096;
61 static const uint32_t DEVICE_DROP_INTERVAL = 600000;
62 static std::mutex g_cameraServiceInstanceMutex;
63 static HCameraService* g_cameraServiceInstance = nullptr;
64 static sptr<HCameraService> g_cameraServiceHolder = nullptr;
65 static bool g_isFoldScreen = system::GetParameter("const.window.foldscreen.type", "") != "";
66 static int64_t g_lastDeviceDropTime = 0;
67
68 std::vector<uint32_t> restoreMetadataTag { // item.type is uint8
69 OHOS_CONTROL_VIDEO_STABILIZATION_MODE,
70 OHOS_CONTROL_DEFERRED_IMAGE_DELIVERY,
71 OHOS_CONTROL_SUPPORTED_COLOR_MODES,
72 OHOS_CONTROL_PORTRAIT_EFFECT_TYPE,
73 OHOS_CONTROL_FILTER_TYPE,
74 OHOS_CONTROL_EFFECT_SUGGESTION,
75 OHOS_CONTROL_MOTION_DETECTION,
76 OHOS_CONTROL_HIGH_QUALITY_MODE,
77 OHOS_CONTROL_CAMERA_USED_AS_POSITION,
78 OHOS_CONTROL_MOVING_PHOTO,
79 OHOS_CONTROL_AUTO_CLOUD_IMAGE_ENHANCE,
80 OHOS_CONTROL_BEAUTY_TYPE,
81 OHOS_CONTROL_BEAUTY_AUTO_VALUE,
82 OHOS_CONTROL_FOCUS_DRIVEN_TYPE,
83 OHOS_CONTROL_COLOR_RESERVATION_TYPE,
84 OHOS_CONTROL_FOCUS_RANGE_TYPE,
85 OHOS_CONTROL_CAMERA_VIRTUAL_APERTURE_VALUE,
86 };
87 mutex g_dataShareHelperMutex;
88 mutex g_dmDeviceInfoMutex;
89 thread_local uint32_t g_dumpDepth = 0;
90
HCameraService(int32_t systemAbilityId,bool runOnCreate)91 HCameraService::HCameraService(int32_t systemAbilityId, bool runOnCreate)
92 : SystemAbility(systemAbilityId, runOnCreate), muteModeStored_(false), isRegisterSensorSuccess(false)
93 {
94 MEDIA_INFO_LOG("HCameraService Construct begin");
95 g_cameraServiceHolder = this;
96 {
97 std::lock_guard<std::mutex> lock(g_cameraServiceInstanceMutex);
98 g_cameraServiceInstance = this;
99 }
100 statusCallback_ = std::make_shared<ServiceHostStatus>(this);
101 cameraHostManager_ = new (std::nothrow) HCameraHostManager(statusCallback_);
102 CHECK_AND_RETURN_LOG(
103 cameraHostManager_ != nullptr, "HCameraService OnStart failed to create HCameraHostManager obj");
104 MEDIA_INFO_LOG("HCameraService Construct end");
105 serviceStatus_ = CameraServiceStatus::SERVICE_NOT_READY;
106 }
107
HCameraService(sptr<HCameraHostManager> cameraHostManager)108 HCameraService::HCameraService(sptr<HCameraHostManager> cameraHostManager)
109 : cameraHostManager_(cameraHostManager), muteModeStored_(false), isRegisterSensorSuccess(false)
110 {}
111
~HCameraService()112 HCameraService::~HCameraService() {}
113
114 #ifdef DEVICE_MANAGER
115 class HCameraService::DeviceInitCallBack : public DistributedHardware::DmInitCallback {
116 void OnRemoteDied() override;
117 };
118
OnRemoteDied()119 void HCameraService::DeviceInitCallBack::OnRemoteDied()
120 {
121 MEDIA_INFO_LOG("CameraManager::DeviceInitCallBack OnRemoteDied");
122 }
123 #endif
124
OnStart()125 void HCameraService::OnStart()
126 {
127 MEDIA_INFO_LOG("HCameraService OnStart begin");
128 CHECK_ERROR_PRINT_LOG(cameraHostManager_->Init() != CAMERA_OK,
129 "HCameraService OnStart failed to init camera host manager.");
130 // initialize deferred processing service.
131 DeferredProcessing::DeferredProcessingService::GetInstance().Initialize();
132 DeferredProcessing::DeferredProcessingService::GetInstance().Start();
133
134 #ifdef CAMERA_USE_SENSOR
135 RegisterSensorCallback();
136 #endif
137 cameraDataShareHelper_ = std::make_shared<CameraDataShareHelper>();
138 AddSystemAbilityListener(DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID);
139 #ifdef NOTIFICATION_ENABLE
140 AddSystemAbilityListener(COMMON_EVENT_SERVICE_ID);
141 #endif
142 if (Publish(this)) {
143 MEDIA_INFO_LOG("HCameraService publish OnStart sucess");
144 } else {
145 MEDIA_INFO_LOG("HCameraService publish OnStart failed");
146 }
147 MEDIA_INFO_LOG("HCameraService OnStart end");
148 }
149
OnDump()150 void HCameraService::OnDump()
151 {
152 MEDIA_INFO_LOG("HCameraService::OnDump called");
153 }
154
OnStop()155 void HCameraService::OnStop()
156 {
157 MEDIA_INFO_LOG("HCameraService::OnStop called");
158 cameraHostManager_->DeInit();
159 UnRegisterFoldStatusListener();
160 #ifdef CAMERA_USE_SENSOR
161 UnRegisterSensorCallback();
162 #endif
163 DeferredProcessing::DeferredProcessingService::GetInstance().Stop();
164 }
165
GetMuteModeFromDataShareHelper(bool & muteMode)166 int32_t HCameraService::GetMuteModeFromDataShareHelper(bool &muteMode)
167 {
168 lock_guard<mutex> lock(g_dataShareHelperMutex);
169 CHECK_ERROR_RETURN_RET_LOG(cameraDataShareHelper_ == nullptr, CAMERA_INVALID_ARG,
170 "GetMuteModeFromDataShareHelper NULL");
171 std::string value = "";
172 auto ret = cameraDataShareHelper_->QueryOnce(PREDICATES_STRING, value);
173 MEDIA_INFO_LOG("GetMuteModeFromDataShareHelper Query ret = %{public}d, value = %{public}s", ret, value.c_str());
174 CHECK_ERROR_RETURN_RET_LOG(ret != CAMERA_OK, CAMERA_INVALID_ARG, "GetMuteModeFromDataShareHelper QueryOnce fail.");
175 value = (value == "0" || value == "1") ? value : "0";
176 int32_t muteModeVal = std::stoi(value);
177 CHECK_ERROR_RETURN_RET_LOG(muteModeVal != 0 && muteModeVal != 1, CAMERA_INVALID_ARG,
178 "GetMuteModeFromDataShareHelper Query MuteMode invald, value = %{public}d", muteModeVal);
179 muteMode = (muteModeVal == 1) ? true: false;
180 this->muteModeStored_ = muteMode;
181 return CAMERA_OK;
182 }
183
SetMuteModeFromDataShareHelper()184 bool HCameraService::SetMuteModeFromDataShareHelper()
185 {
186 if (GetServiceStatus() == CameraServiceStatus::SERVICE_READY) {
187 return true;
188 }
189 this->SetServiceStatus(CameraServiceStatus::SERVICE_READY);
190 bool muteMode = false;
191 int32_t ret = GetMuteModeFromDataShareHelper(muteMode);
192 CHECK_AND_RETURN_RET_LOG((ret == CAMERA_OK), false, "GetMuteModeFromDataShareHelper failed");
193 MuteCameraFunc(muteMode);
194 muteModeStored_ = muteMode;
195 MEDIA_INFO_LOG("SetMuteModeFromDataShareHelper Success, muteMode = %{public}d", muteMode);
196 return true;
197 }
198
OnReceiveEvent(const EventFwk::CommonEventData & data)199 void HCameraService::OnReceiveEvent(const EventFwk::CommonEventData &data)
200 {
201 auto const &want = data.GetWant();
202 std::string action = want.GetAction();
203 if (action == COMMON_EVENT_DATA_SHARE_READY) {
204 MEDIA_INFO_LOG("on receive datashare ready.");
205 SetMuteModeFromDataShareHelper();
206 }
207 #ifdef NOTIFICATION_ENABLE
208 if (action == EVENT_CAMERA_BEAUTY_NOTIFICATION) {
209 MEDIA_INFO_LOG("on receive camera beauty.");
210 OHOS::AAFwk::WantParams wantParams = data.GetWant().GetParams();
211 int32_t currentFlag = wantParams.GetIntParam(BEAUTY_NOTIFICATION_ACTION_PARAM, -1);
212 MEDIA_INFO_LOG("currentFlag: %{public}d", currentFlag);
213 int32_t beautyStatus = currentFlag == BEAUTY_STATUS_OFF ? BEAUTY_STATUS_ON : BEAUTY_STATUS_OFF;
214 CameraBeautyNotification::GetInstance()->SetBeautyStatusFromDataShareHelper(beautyStatus);
215 SetBeauty(beautyStatus);
216 CameraBeautyNotification::GetInstance()->SetBeautyStatus(beautyStatus);
217 CameraBeautyNotification::GetInstance()->PublishNotification(false);
218 }
219 #endif
220 }
221
222 #ifdef NOTIFICATION_ENABLE
SetBeauty(int32_t beautyStatus)223 int32_t HCameraService::SetBeauty(int32_t beautyStatus)
224 {
225 constexpr int32_t DEFAULT_ITEMS = 1;
226 constexpr int32_t DEFAULT_DATA_LENGTH = 1;
227 shared_ptr<OHOS::Camera::CameraMetadata> changedMetadata =
228 make_shared<OHOS::Camera::CameraMetadata>(DEFAULT_ITEMS, DEFAULT_DATA_LENGTH);
229 int32_t ret;
230 int32_t count = 1;
231 uint8_t beautyLevel = 0;
232 uint8_t beautyType = OHOS_CAMERA_BEAUTY_TYPE_OFF;
233 if (beautyStatus == BEAUTY_STATUS_ON) {
234 beautyLevel = BEAUTY_LEVEL;
235 beautyType = OHOS_CAMERA_BEAUTY_TYPE_AUTO;
236 }
237 MEDIA_INFO_LOG("HCameraService::SetBeauty beautyType: %{public}d, beautyLevel: %{public}d",
238 beautyType, beautyLevel);
239 camera_metadata_item_t item;
240 ret = OHOS::Camera::FindCameraMetadataItem(changedMetadata->get(), OHOS_CONTROL_BEAUTY_TYPE, &item);
241 if (ret == CAM_META_ITEM_NOT_FOUND) {
242 changedMetadata->addEntry(OHOS_CONTROL_BEAUTY_TYPE, &beautyType, count);
243 } else if (ret == CAM_META_SUCCESS) {
244 changedMetadata->updateEntry(OHOS_CONTROL_BEAUTY_TYPE, &beautyType, count);
245 }
246
247 ret = OHOS::Camera::FindCameraMetadataItem(changedMetadata->get(), OHOS_CONTROL_BEAUTY_AUTO_VALUE, &item);
248 if (ret == CAM_META_ITEM_NOT_FOUND) {
249 changedMetadata->addEntry(OHOS_CONTROL_BEAUTY_AUTO_VALUE, &beautyLevel, count);
250 } else if (ret == CAM_META_SUCCESS) {
251 changedMetadata->updateEntry(OHOS_CONTROL_BEAUTY_AUTO_VALUE, &beautyLevel, count);
252 }
253
254 sptr<HCameraDeviceManager> deviceManager = HCameraDeviceManager::GetInstance();
255 std::vector<sptr<HCameraDeviceHolder>> deviceHolderVector = deviceManager->GetActiveCameraHolders();
256 for (sptr<HCameraDeviceHolder> activeDeviceHolder : deviceHolderVector) {
257 sptr<HCameraDevice> activeDevice = activeDeviceHolder->GetDevice();
258 if (activeDevice != nullptr && activeDevice->IsOpenedCameraDevice()) {
259 activeDevice->UpdateSetting(changedMetadata);
260 MEDIA_INFO_LOG("HCameraService::SetBeauty UpdateSetting");
261 }
262 }
263 return CAMERA_OK;
264 }
265 #endif
266
SetMuteModeByDataShareHelper(bool muteMode)267 int32_t HCameraService::SetMuteModeByDataShareHelper(bool muteMode)
268 {
269 MEDIA_INFO_LOG("SetMuteModeByDataShareHelper enter.");
270 lock_guard<mutex> lock(g_dataShareHelperMutex);
271 CHECK_ERROR_RETURN_RET_LOG(cameraDataShareHelper_ == nullptr, CAMERA_ALLOC_ERROR,
272 "GetMuteModeFromDataShareHelper NULL");
273 std::string unMuteModeStr = "0";
274 std::string muteModeStr = "1";
275 std::string value = muteMode? muteModeStr : unMuteModeStr;
276 auto ret = cameraDataShareHelper_->UpdateOnce(PREDICATES_STRING, value);
277 CHECK_ERROR_RETURN_RET_LOG(ret != CAMERA_OK, CAMERA_ALLOC_ERROR, "SetMuteModeByDataShareHelper UpdateOnce fail.");
278 return CAMERA_OK;
279 }
280
OnAddSystemAbility(int32_t systemAbilityId,const std::string & deviceId)281 void HCameraService::OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId)
282 {
283 MEDIA_INFO_LOG("OnAddSystemAbility systemAbilityId:%{public}d", systemAbilityId);
284 switch (systemAbilityId) {
285 case DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID:
286 MEDIA_INFO_LOG("OnAddSystemAbility RegisterObserver start");
287 CameraCommonEventManager::GetInstance()->SubscribeCommonEvent(COMMON_EVENT_DATA_SHARE_READY,
288 std::bind(&HCameraService::OnReceiveEvent, this, std::placeholders::_1));
289 if (cameraDataShareHelper_->IsDataShareReady()) {
290 SetMuteModeFromDataShareHelper();
291 }
292 break;
293 #ifdef NOTIFICATION_ENABLE
294 case COMMON_EVENT_SERVICE_ID:
295 MEDIA_INFO_LOG("OnAddSystemAbility COMMON_EVENT_SERVICE");
296 CameraCommonEventManager::GetInstance()->SubscribeCommonEvent(EVENT_CAMERA_BEAUTY_NOTIFICATION,
297 std::bind(&HCameraService::OnReceiveEvent, this, std::placeholders::_1));
298 break;
299 #endif
300 default:
301 MEDIA_INFO_LOG("OnAddSystemAbility unhandled sysabilityId:%{public}d", systemAbilityId);
302 break;
303 }
304 MEDIA_INFO_LOG("OnAddSystemAbility done");
305 }
306
OnRemoveSystemAbility(int32_t systemAbilityId,const std::string & deviceId)307 void HCameraService::OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId)
308 {
309 MEDIA_DEBUG_LOG("HCameraService::OnRemoveSystemAbility systemAbilityId:%{public}d removed", systemAbilityId);
310 switch (systemAbilityId) {
311 case DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID:
312 CameraCommonEventManager::GetInstance()->UnSubscribeCommonEvent(COMMON_EVENT_DATA_SHARE_READY);
313 break;
314 default:
315 break;
316 }
317 MEDIA_DEBUG_LOG("HCameraService::OnRemoveSystemAbility done");
318 }
319
GetCameras(vector<string> & cameraIds,vector<shared_ptr<OHOS::Camera::CameraMetadata>> & cameraAbilityList)320 int32_t HCameraService::GetCameras(
321 vector<string>& cameraIds, vector<shared_ptr<OHOS::Camera::CameraMetadata>>& cameraAbilityList)
322 {
323 CAMERA_SYNC_TRACE;
324 isFoldable = isFoldableInit ? isFoldable : g_isFoldScreen;
325 isFoldableInit = true;
326 int32_t ret = cameraHostManager_->GetCameras(cameraIds);
327 CHECK_ERROR_RETURN_RET_LOG(ret != CAMERA_OK, ret, "HCameraService::GetCameras failed");
328 shared_ptr<OHOS::Camera::CameraMetadata> cameraAbility;
329 vector<shared_ptr<CameraMetaInfo>> cameraInfos;
330 for (auto id : cameraIds) {
331 ret = cameraHostManager_->GetCameraAbility(id, cameraAbility);
332 CHECK_ERROR_RETURN_RET_LOG(ret != CAMERA_OK || cameraAbility == nullptr, ret,
333 "HCameraService::GetCameraAbility failed");
334 auto cameraMetaInfo = GetCameraMetaInfo(id, cameraAbility);
335 if (cameraMetaInfo == nullptr) {
336 continue;
337 }
338 cameraInfos.emplace_back(cameraMetaInfo);
339 }
340 FillCameras(cameraInfos, cameraIds, cameraAbilityList);
341 return ret;
342 }
343
GetCameraMetaInfo(std::string & cameraId,shared_ptr<OHOS::Camera::CameraMetadata> cameraAbility)344 shared_ptr<CameraMetaInfo>HCameraService::GetCameraMetaInfo(std::string &cameraId,
345 shared_ptr<OHOS::Camera::CameraMetadata>cameraAbility)
346 {
347 camera_metadata_item_t item;
348 common_metadata_header_t* metadata = cameraAbility->get();
349 int32_t res = OHOS::Camera::FindCameraMetadataItem(metadata, OHOS_ABILITY_CAMERA_POSITION, &item);
350 uint8_t cameraPosition = (res == CAM_META_SUCCESS) ? item.data.u8[0] : OHOS_CAMERA_POSITION_OTHER;
351 res = OHOS::Camera::FindCameraMetadataItem(metadata, OHOS_ABILITY_CAMERA_FOLDSCREEN_TYPE, &item);
352 uint8_t foldType = (res == CAM_META_SUCCESS) ? item.data.u8[0] : OHOS_CAMERA_FOLDSCREEN_OTHER;
353 if (isFoldable && cameraPosition == OHOS_CAMERA_POSITION_FRONT && foldType == OHOS_CAMERA_FOLDSCREEN_OTHER &&
354 system::GetParameter("const.window.foldscreen.type", "")[0] == '1') {
355 return nullptr;
356 }
357 if (isFoldable && cameraPosition == OHOS_CAMERA_POSITION_FRONT && foldType == OHOS_CAMERA_FOLDSCREEN_INNER) {
358 cameraPosition = POSITION_FOLD_INNER;
359 }
360 res = OHOS::Camera::FindCameraMetadataItem(metadata, OHOS_ABILITY_CAMERA_TYPE, &item);
361 uint8_t cameraType = (res == CAM_META_SUCCESS) ? item.data.u8[0] : OHOS_CAMERA_TYPE_UNSPECIFIED;
362 res = OHOS::Camera::FindCameraMetadataItem(metadata, OHOS_ABILITY_CAMERA_CONNECTION_TYPE, &item);
363 uint8_t connectionType = (res == CAM_META_SUCCESS) ? item.data.u8[0] : OHOS_CAMERA_CONNECTION_TYPE_BUILTIN;
364 res = OHOS::Camera::FindCameraMetadataItem(metadata, OHOS_CONTROL_CAPTURE_MIRROR_SUPPORTED, &item);
365 bool isMirrorSupported = (res == CAM_META_SUCCESS) ? (item.count != 0) : false;
366 res = OHOS::Camera::FindCameraMetadataItem(metadata, OHOS_ABILITY_CAMERA_FOLD_STATUS, &item);
367 uint8_t foldStatus = (res == CAM_META_SUCCESS) ? item.data.u8[0] : OHOS_CAMERA_FOLD_STATUS_NONFOLDABLE;
368 res = OHOS::Camera::FindCameraMetadataItem(metadata, OHOS_ABILITY_CAMERA_MODES, &item);
369 std::vector<uint8_t> supportModes = {};
370 for (uint32_t i = 0; i < item.count; i++) {
371 supportModes.push_back(item.data.u8[i]);
372 }
373 CAMERA_SYSEVENT_STATISTIC(CreateMsg("CameraManager GetCameras camera ID:%s, Camera position:%d, "
374 "Camera Type:%d, Connection Type:%d, Mirror support:%d, Fold status %d",
375 cameraId.c_str(), cameraPosition, cameraType, connectionType, isMirrorSupported, foldStatus));
376 return make_shared<CameraMetaInfo>(cameraId, cameraType, cameraPosition, connectionType,
377 foldStatus, supportModes, cameraAbility);
378 }
379
FillCameras(vector<shared_ptr<CameraMetaInfo>> & cameraInfos,vector<string> & cameraIds,vector<shared_ptr<OHOS::Camera::CameraMetadata>> & cameraAbilityList)380 void HCameraService::FillCameras(vector<shared_ptr<CameraMetaInfo>>& cameraInfos,
381 vector<string>& cameraIds, vector<shared_ptr<OHOS::Camera::CameraMetadata>>& cameraAbilityList)
382 {
383 vector<shared_ptr<CameraMetaInfo>> choosedCameras = ChooseDeFaultCameras(cameraInfos);
384 cameraIds.clear();
385 cameraAbilityList.clear();
386 for (const auto& camera: choosedCameras) {
387 cameraIds.emplace_back(camera->cameraId);
388 cameraAbilityList.emplace_back(camera->cameraAbility);
389 }
390 int32_t uid = IPCSkeleton::GetCallingUid();
391 if (uid == ROOT_UID || uid == FACE_CLIENT_UID || uid == RSS_UID ||
392 OHOS::Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(IPCSkeleton::GetCallingFullTokenID())) {
393 vector<shared_ptr<CameraMetaInfo>> physicalCameras = ChoosePhysicalCameras(cameraInfos, choosedCameras);
394 for (const auto& camera: physicalCameras) {
395 cameraIds.emplace_back(camera->cameraId);
396 cameraAbilityList.emplace_back(camera->cameraAbility);
397 }
398 } else {
399 MEDIA_INFO_LOG("current token id not support physical camera");
400 }
401 }
402
ChoosePhysicalCameras(const vector<shared_ptr<CameraMetaInfo>> & cameraInfos,const vector<shared_ptr<CameraMetaInfo>> & choosedCameras)403 vector<shared_ptr<CameraMetaInfo>> HCameraService::ChoosePhysicalCameras(
404 const vector<shared_ptr<CameraMetaInfo>>& cameraInfos, const vector<shared_ptr<CameraMetaInfo>>& choosedCameras)
405 {
406 std::vector<OHOS::HDI::Camera::V1_3::OperationMode> supportedPhysicalCamerasModes = {
407 OHOS::HDI::Camera::V1_3::OperationMode::PROFESSIONAL_PHOTO,
408 OHOS::HDI::Camera::V1_3::OperationMode::PROFESSIONAL_VIDEO,
409 OHOS::HDI::Camera::V1_3::OperationMode::HIGH_RESOLUTION_PHOTO,
410 };
411 vector<shared_ptr<CameraMetaInfo>> physicalCameraInfos = {};
412 for (auto& camera : cameraInfos) {
413 if (std::any_of(choosedCameras.begin(), choosedCameras.end(), [camera](const auto& defaultCamera) {
414 return camera->cameraId == defaultCamera->cameraId;
415 })
416 ) {
417 MEDIA_INFO_LOG("ChoosePhysicalCameras alreadly has default camera: %{public}s", camera->cameraId.c_str());
418 } else {
419 physicalCameraInfos.push_back(camera);
420 }
421 }
422 vector<shared_ptr<CameraMetaInfo>> physicalCameras = {};
423 for (auto& camera : physicalCameraInfos) {
424 MEDIA_INFO_LOG("ChoosePhysicalCameras camera ID:%s, CameraType: %{public}d, Camera position:%{public}d, "
425 "Connection Type:%{public}d",
426 camera->cameraId.c_str(), camera->cameraType, camera->position, camera->connectionType);
427 bool isSupportPhysicalCamera = std::any_of(camera->supportModes.begin(), camera->supportModes.end(),
428 [&supportedPhysicalCamerasModes](auto mode) -> bool {
429 return any_of(supportedPhysicalCamerasModes.begin(), supportedPhysicalCamerasModes.end(),
430 [mode](auto it)-> bool { return it == mode; });
431 });
432 if (camera->cameraType != camera_type_enum_t::OHOS_CAMERA_TYPE_UNSPECIFIED && isSupportPhysicalCamera) {
433 physicalCameras.emplace_back(camera);
434 MEDIA_INFO_LOG("ChoosePhysicalCameras add camera ID:%{public}s", camera->cameraId.c_str());
435 }
436 }
437 return physicalCameras;
438 }
439
ChooseDeFaultCameras(vector<shared_ptr<CameraMetaInfo>> cameraInfos)440 vector<shared_ptr<CameraMetaInfo>> HCameraService::ChooseDeFaultCameras(vector<shared_ptr<CameraMetaInfo>> cameraInfos)
441 {
442 vector<shared_ptr<CameraMetaInfo>> choosedCameras;
443 for (auto& camera : cameraInfos) {
444 MEDIA_INFO_LOG("ChooseDeFaultCameras camera ID:%s, Camera position:%{public}d, Connection Type:%{public}d",
445 camera->cameraId.c_str(), camera->position, camera->connectionType);
446 if (any_of(choosedCameras.begin(), choosedCameras.end(),
447 [camera](const auto& defaultCamera) {
448 return (camera->connectionType != OHOS_CAMERA_CONNECTION_TYPE_USB_PLUGIN &&
449 defaultCamera->position == camera->position &&
450 defaultCamera->connectionType == camera->connectionType &&
451 defaultCamera->foldStatus == camera->foldStatus);
452 })
453 ) {
454 MEDIA_INFO_LOG("ChooseDeFaultCameras alreadly has default camera");
455 } else {
456 choosedCameras.emplace_back(camera);
457 MEDIA_INFO_LOG("add camera ID:%{public}s", camera->cameraId.c_str());
458 }
459 }
460 return choosedCameras;
461 }
462
GetCameraIds(vector<string> & cameraIds)463 int32_t HCameraService::GetCameraIds(vector<string>& cameraIds)
464 {
465 CAMERA_SYNC_TRACE;
466 int32_t ret = CAMERA_OK;
467 MEDIA_DEBUG_LOG("HCameraService::GetCameraIds");
468 std::vector<std::shared_ptr<OHOS::Camera::CameraMetadata>> cameraAbilityList;
469 ret = GetCameras(cameraIds, cameraAbilityList);
470 CHECK_ERROR_PRINT_LOG(ret != CAMERA_OK, "HCameraService::GetCameraIds failed");
471 return ret;
472 }
473
GetCameraAbility(std::string & cameraId,std::shared_ptr<OHOS::Camera::CameraMetadata> & cameraAbility)474 int32_t HCameraService::GetCameraAbility(std::string& cameraId,
475 std::shared_ptr<OHOS::Camera::CameraMetadata>& cameraAbility)
476 {
477 CAMERA_SYNC_TRACE;
478 int32_t ret = CAMERA_OK;
479 MEDIA_DEBUG_LOG("HCameraService::GetCameraAbility");
480
481 std::vector<std::string> cameraIds;
482 std::vector<std::shared_ptr<OHOS::Camera::CameraMetadata>> cameraAbilityList;
483 ret = GetCameras(cameraIds, cameraAbilityList);
484 CHECK_ERROR_RETURN_RET_LOG(ret != CAMERA_OK, ret, "HCameraService::GetCameraAbility failed");
485
486 int32_t index = 0;
487 for (auto id : cameraIds) {
488 if (id.compare(cameraId) == 0) {
489 break;
490 }
491 index++;
492 }
493 int32_t abilityIndex = 0;
494 for (auto it : cameraAbilityList) {
495 if (abilityIndex == index) {
496 cameraAbility = it;
497 break;
498 }
499 abilityIndex++;
500 }
501 return ret;
502 }
503
CreateCameraDevice(string cameraId,sptr<ICameraDeviceService> & device)504 int32_t HCameraService::CreateCameraDevice(string cameraId, sptr<ICameraDeviceService>& device)
505 {
506 CAMERA_SYNC_TRACE;
507 OHOS::Security::AccessToken::AccessTokenID callerToken = IPCSkeleton::GetCallingTokenID();
508 MEDIA_INFO_LOG("HCameraService::CreateCameraDevice prepare execute, cameraId:%{public}s", cameraId.c_str());
509
510 string permissionName = OHOS_PERMISSION_CAMERA;
511 int32_t ret = CheckPermission(permissionName, callerToken);
512 CHECK_ERROR_RETURN_RET_LOG(ret != CAMERA_OK, ret,
513 "HCameraService::CreateCameraDevice Check OHOS_PERMISSION_CAMERA fail %{public}d", ret);
514 // if callerToken is invalid, will not call IsAllowedUsingPermission
515 CHECK_ERROR_RETURN_RET_LOG(!IsInForeGround(callerToken), CAMERA_ALLOC_ERROR,
516 "HCameraService::CreateCameraDevice is not allowed!");
517 sptr<HCameraDevice> cameraDevice = new (nothrow) HCameraDevice(cameraHostManager_, cameraId, callerToken);
518 CHECK_ERROR_RETURN_RET_LOG(cameraDevice == nullptr, CAMERA_ALLOC_ERROR,
519 "HCameraService::CreateCameraDevice HCameraDevice allocation failed");
520 CHECK_ERROR_RETURN_RET_LOG(GetServiceStatus() != CameraServiceStatus::SERVICE_READY, CAMERA_INVALID_STATE,
521 "HCameraService::CreateCameraDevice CameraService not ready!");
522 {
523 lock_guard<mutex> lock(g_dataShareHelperMutex);
524 // when create camera device, update mute setting truely.
525 if (IsCameraMuteSupported(cameraId)) {
526 if (UpdateMuteSetting(cameraDevice, muteModeStored_) != CAMERA_OK) {
527 MEDIA_ERR_LOG("UpdateMuteSetting Failed, cameraId: %{public}s", cameraId.c_str());
528 }
529 } else {
530 MEDIA_ERR_LOG("HCameraService::CreateCameraDevice MuteCamera not Supported");
531 }
532 device = cameraDevice;
533 cameraDevice->SetDeviceMuteMode(muteModeStored_);
534 }
535 #ifdef CAMERA_USE_SENSOR
536 g_lastDeviceDropTime = 0;
537 RegisterSensorCallback();
538 #endif
539 CAMERA_SYSEVENT_STATISTIC(CreateMsg("CameraManager_CreateCameraInput CameraId:%s", cameraId.c_str()));
540 MEDIA_INFO_LOG("HCameraService::CreateCameraDevice execute success");
541 return CAMERA_OK;
542 }
543
CreateCaptureSession(sptr<ICaptureSession> & session,int32_t opMode)544 int32_t HCameraService::CreateCaptureSession(sptr<ICaptureSession>& session, int32_t opMode)
545 {
546 CAMERA_SYNC_TRACE;
547 std::lock_guard<std::mutex> lock(mutex_);
548 int32_t rc = CAMERA_OK;
549 MEDIA_INFO_LOG("HCameraService::CreateCaptureSession opMode_= %{public}d", opMode);
550
551 OHOS::Security::AccessToken::AccessTokenID callerToken = IPCSkeleton::GetCallingTokenID();
552 sptr<HCaptureSession> captureSession = HCaptureSession::NewInstance(callerToken, opMode);
553 if (captureSession == nullptr) {
554 rc = CAMERA_ALLOC_ERROR;
555 MEDIA_ERR_LOG("HCameraService::CreateCaptureSession allocation failed");
556 CameraReportUtils::ReportCameraError(
557 "HCameraService::CreateCaptureSession", rc, false, CameraReportUtils::GetCallerInfo());
558 return rc;
559 }
560 session = captureSession;
561 pid_t pid = IPCSkeleton::GetCallingPid();
562 captureSessionsManager_.EnsureInsert(pid, captureSession);
563 return rc;
564 }
565
CreateDeferredPhotoProcessingSession(int32_t userId,sptr<DeferredProcessing::IDeferredPhotoProcessingSessionCallback> & callback,sptr<DeferredProcessing::IDeferredPhotoProcessingSession> & session)566 int32_t HCameraService::CreateDeferredPhotoProcessingSession(int32_t userId,
567 sptr<DeferredProcessing::IDeferredPhotoProcessingSessionCallback>& callback,
568 sptr<DeferredProcessing::IDeferredPhotoProcessingSession>& session)
569 {
570 CAMERA_SYNC_TRACE;
571 MEDIA_INFO_LOG("HCameraService::CreateDeferredPhotoProcessingSession enter.");
572 sptr<DeferredProcessing::IDeferredPhotoProcessingSession> photoSession;
573 int32_t uid = IPCSkeleton::GetCallingUid();
574 AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid, userId);
575 MEDIA_INFO_LOG("CreateDeferredPhotoProcessingSession get uid:%{public}d userId:%{public}d", uid, userId);
576 photoSession =
577 DeferredProcessing::DeferredProcessingService::GetInstance().CreateDeferredPhotoProcessingSession(userId,
578 callback);
579 session = photoSession;
580 return CAMERA_OK;
581 }
582
CreateDeferredVideoProcessingSession(int32_t userId,sptr<DeferredProcessing::IDeferredVideoProcessingSessionCallback> & callback,sptr<DeferredProcessing::IDeferredVideoProcessingSession> & session)583 int32_t HCameraService::CreateDeferredVideoProcessingSession(int32_t userId,
584 sptr<DeferredProcessing::IDeferredVideoProcessingSessionCallback>& callback,
585 sptr<DeferredProcessing::IDeferredVideoProcessingSession>& session)
586 {
587 CAMERA_SYNC_TRACE;
588 MEDIA_INFO_LOG("HCameraService::CreateDeferredVideoProcessingSession enter.");
589 sptr<DeferredProcessing::IDeferredVideoProcessingSession> videoSession;
590 int32_t uid = IPCSkeleton::GetCallingUid();
591 AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid, userId);
592 MEDIA_INFO_LOG("CreateDeferredVideoProcessingSession get uid:%{public}d userId:%{public}d", uid, userId);
593 videoSession =
594 DeferredProcessing::DeferredProcessingService::GetInstance().CreateDeferredVideoProcessingSession(userId,
595 callback);
596 session = videoSession;
597 return CAMERA_OK;
598 }
599
CreatePhotoOutput(const sptr<OHOS::IBufferProducer> & producer,int32_t format,int32_t width,int32_t height,sptr<IStreamCapture> & photoOutput)600 int32_t HCameraService::CreatePhotoOutput(const sptr<OHOS::IBufferProducer>& producer, int32_t format, int32_t width,
601 int32_t height, sptr<IStreamCapture>& photoOutput)
602 {
603 CAMERA_SYNC_TRACE;
604 int32_t rc = CAMERA_OK;
605 MEDIA_INFO_LOG("HCameraService::CreatePhotoOutput prepare execute");
606 if ((producer == nullptr) || (width == 0) || (height == 0)) {
607 rc = CAMERA_INVALID_ARG;
608 MEDIA_ERR_LOG("HCameraService::CreatePhotoOutput producer is null");
609 CameraReportUtils::ReportCameraError(
610 "HCameraService::CreatePhotoOutput", rc, false, CameraReportUtils::GetCallerInfo());
611 return rc;
612 }
613 sptr<HStreamCapture> streamCapture = new (nothrow) HStreamCapture(producer, format, width, height);
614 if (streamCapture == nullptr) {
615 rc = CAMERA_ALLOC_ERROR;
616 MEDIA_ERR_LOG("HCameraService::CreatePhotoOutput streamCapture is null");
617 CameraReportUtils::ReportCameraError(
618 "HCameraService::CreatePhotoOutput", rc, false, CameraReportUtils::GetCallerInfo());
619 return rc;
620 }
621
622 stringstream ss;
623 ss << "format=" << format << " width=" << width << " height=" << height;
624 CameraReportUtils::GetInstance().UpdateProfileInfo(ss.str());
625 photoOutput = streamCapture;
626 MEDIA_INFO_LOG("HCameraService::CreatePhotoOutput execute success");
627 return rc;
628 }
629
CreateDeferredPreviewOutput(int32_t format,int32_t width,int32_t height,sptr<IStreamRepeat> & previewOutput)630 int32_t HCameraService::CreateDeferredPreviewOutput(
631 int32_t format, int32_t width, int32_t height, sptr<IStreamRepeat>& previewOutput)
632 {
633 CAMERA_SYNC_TRACE;
634 sptr<HStreamRepeat> streamDeferredPreview;
635 MEDIA_INFO_LOG("HCameraService::CreateDeferredPreviewOutput prepare execute");
636 CHECK_ERROR_RETURN_RET_LOG((width == 0) || (height == 0), CAMERA_INVALID_ARG,
637 "HCameraService::CreateDeferredPreviewOutput producer is null!");
638 streamDeferredPreview = new (nothrow) HStreamRepeat(nullptr, format, width, height, RepeatStreamType::PREVIEW);
639 CHECK_ERROR_RETURN_RET_LOG(streamDeferredPreview == nullptr, CAMERA_ALLOC_ERROR,
640 "HCameraService::CreateDeferredPreviewOutput HStreamRepeat allocation failed");
641 previewOutput = streamDeferredPreview;
642 MEDIA_INFO_LOG("HCameraService::CreateDeferredPreviewOutput execute success");
643 return CAMERA_OK;
644 }
645
CreatePreviewOutput(const sptr<OHOS::IBufferProducer> & producer,int32_t format,int32_t width,int32_t height,sptr<IStreamRepeat> & previewOutput)646 int32_t HCameraService::CreatePreviewOutput(const sptr<OHOS::IBufferProducer>& producer, int32_t format, int32_t width,
647 int32_t height, sptr<IStreamRepeat>& previewOutput)
648 {
649 CAMERA_SYNC_TRACE;
650 sptr<HStreamRepeat> streamRepeatPreview;
651 int32_t rc = CAMERA_OK;
652 MEDIA_INFO_LOG("HCameraService::CreatePreviewOutput prepare execute");
653
654 if ((producer == nullptr) || (width == 0) || (height == 0)) {
655 rc = CAMERA_INVALID_ARG;
656 MEDIA_ERR_LOG("HCameraService::CreatePreviewOutput producer is null");
657 CameraReportUtils::ReportCameraError(
658 "HCameraService::CreatePreviewOutput", rc, false, CameraReportUtils::GetCallerInfo());
659 return rc;
660 }
661 streamRepeatPreview = new (nothrow) HStreamRepeat(producer, format, width, height, RepeatStreamType::PREVIEW);
662 if (streamRepeatPreview == nullptr) {
663 rc = CAMERA_ALLOC_ERROR;
664 MEDIA_ERR_LOG("HCameraService::CreatePreviewOutput HStreamRepeat allocation failed");
665 CameraReportUtils::ReportCameraError(
666 "HCameraService::CreatePreviewOutput", rc, false, CameraReportUtils::GetCallerInfo());
667 return rc;
668 }
669 previewOutput = streamRepeatPreview;
670 MEDIA_INFO_LOG("HCameraService::CreatePreviewOutput execute success");
671 return rc;
672 }
673
CreateDepthDataOutput(const sptr<OHOS::IBufferProducer> & producer,int32_t format,int32_t width,int32_t height,sptr<IStreamDepthData> & depthDataOutput)674 int32_t HCameraService::CreateDepthDataOutput(const sptr<OHOS::IBufferProducer>& producer, int32_t format,
675 int32_t width, int32_t height, sptr<IStreamDepthData>& depthDataOutput)
676 {
677 CAMERA_SYNC_TRACE;
678 sptr<HStreamDepthData> streamDepthData;
679 int32_t rc = CAMERA_OK;
680 MEDIA_INFO_LOG("HCameraService::CreateDepthDataOutput prepare execute");
681
682 if ((producer == nullptr) || (width == 0) || (height == 0)) {
683 rc = CAMERA_INVALID_ARG;
684 MEDIA_ERR_LOG("HCameraService::CreateDepthDataOutput producer is null");
685 CameraReportUtils::ReportCameraError(
686 "HCameraService::CreateDepthDataOutput", rc, false, CameraReportUtils::GetCallerInfo());
687 return rc;
688 }
689 streamDepthData = new (nothrow) HStreamDepthData(producer, format, width, height);
690 if (streamDepthData == nullptr) {
691 rc = CAMERA_ALLOC_ERROR;
692 MEDIA_ERR_LOG("HCameraService::CreateDepthDataOutput HStreamRepeat allocation failed");
693 CameraReportUtils::ReportCameraError(
694 "HCameraService::CreateDepthDataOutput", rc, false, CameraReportUtils::GetCallerInfo());
695 return rc;
696 }
697 depthDataOutput = streamDepthData;
698 MEDIA_INFO_LOG("HCameraService::CreateDepthDataOutput execute success");
699 return rc;
700 }
701
CreateMetadataOutput(const sptr<OHOS::IBufferProducer> & producer,int32_t format,std::vector<int32_t> metadataTypes,sptr<IStreamMetadata> & metadataOutput)702 int32_t HCameraService::CreateMetadataOutput(const sptr<OHOS::IBufferProducer>& producer, int32_t format,
703 std::vector<int32_t> metadataTypes, sptr<IStreamMetadata>& metadataOutput)
704 {
705 CAMERA_SYNC_TRACE;
706 sptr<HStreamMetadata> streamMetadata;
707 MEDIA_INFO_LOG("HCameraService::CreateMetadataOutput prepare execute");
708
709 CHECK_ERROR_RETURN_RET_LOG(producer == nullptr, CAMERA_INVALID_ARG,
710 "HCameraService::CreateMetadataOutput producer is null");
711 streamMetadata = new (nothrow) HStreamMetadata(producer, format, metadataTypes);
712 CHECK_ERROR_RETURN_RET_LOG(streamMetadata == nullptr, CAMERA_ALLOC_ERROR,
713 "HCameraService::CreateMetadataOutput HStreamMetadata allocation failed");
714
715 metadataOutput = streamMetadata;
716 MEDIA_INFO_LOG("HCameraService::CreateMetadataOutput execute success");
717 return CAMERA_OK;
718 }
719
CreateVideoOutput(const sptr<OHOS::IBufferProducer> & producer,int32_t format,int32_t width,int32_t height,sptr<IStreamRepeat> & videoOutput)720 int32_t HCameraService::CreateVideoOutput(const sptr<OHOS::IBufferProducer>& producer, int32_t format, int32_t width,
721 int32_t height, sptr<IStreamRepeat>& videoOutput)
722 {
723 CAMERA_SYNC_TRACE;
724 sptr<HStreamRepeat> streamRepeatVideo;
725 int32_t rc = CAMERA_OK;
726 MEDIA_INFO_LOG("HCameraService::CreateVideoOutput prepare execute");
727
728 if ((producer == nullptr) || (width == 0) || (height == 0)) {
729 rc = CAMERA_INVALID_ARG;
730 MEDIA_ERR_LOG("HCameraService::CreateVideoOutput producer is null");
731 CameraReportUtils::ReportCameraError(
732 "HCameraService::CreateVideoOutput", rc, false, CameraReportUtils::GetCallerInfo());
733 return rc;
734 }
735 streamRepeatVideo = new (nothrow) HStreamRepeat(producer, format, width, height, RepeatStreamType::VIDEO);
736 if (streamRepeatVideo == nullptr) {
737 rc = CAMERA_ALLOC_ERROR;
738 MEDIA_ERR_LOG("HCameraService::CreateVideoOutput HStreamRepeat allocation failed");
739 CameraReportUtils::ReportCameraError(
740 "HCameraService::CreateVideoOutput", rc, false, CameraReportUtils::GetCallerInfo());
741 return rc;
742 }
743 stringstream ss;
744 ss << "format=" << format << " width=" << width << " height=" << height;
745 CameraReportUtils::GetInstance().UpdateProfileInfo(ss.str());
746 videoOutput = streamRepeatVideo;
747 MEDIA_INFO_LOG("HCameraService::CreateVideoOutput execute success");
748 return rc;
749 }
750
ShouldSkipStatusUpdates(pid_t pid)751 bool HCameraService::ShouldSkipStatusUpdates(pid_t pid)
752 {
753 std::lock_guard<std::mutex> lock(freezedPidListMutex_);
754 CHECK_AND_RETURN_RET(freezedPidList_.count(pid) != 0, false);
755 MEDIA_INFO_LOG("ShouldSkipStatusUpdates pid = %{public}d", pid);
756 return true;
757 }
758
OnCameraStatus(const string & cameraId,CameraStatus status,CallbackInvoker invoker)759 void HCameraService::OnCameraStatus(const string& cameraId, CameraStatus status, CallbackInvoker invoker)
760 {
761 lock_guard<mutex> lock(cameraCbMutex_);
762 std::string bundleName = "";
763 if (invoker == CallbackInvoker::APPLICATION) {
764 bundleName = GetClientBundle(IPCSkeleton::GetCallingUid());
765 }
766 MEDIA_INFO_LOG("HCameraService::OnCameraStatus callbacks.size = %{public}zu, cameraId = %{public}s, "
767 "status = %{public}d, pid = %{public}d, bundleName = %{public}s", cameraServiceCallbacks_.size(),
768 cameraId.c_str(), status, IPCSkeleton::GetCallingPid(), bundleName.c_str());
769 for (auto it : cameraServiceCallbacks_) {
770 if (it.second == nullptr) {
771 MEDIA_ERR_LOG("HCameraService::OnCameraStatus pid:%{public}d cameraServiceCallback is null", it.first);
772 continue;
773 }
774 uint32_t pid = it.first;
775 if (ShouldSkipStatusUpdates(pid)) {
776 continue;
777 }
778 it.second->OnCameraStatusChanged(cameraId, status, bundleName);
779 cameraStatusCallbacks_[cameraId] = CameraStatusCallbacksInfo{status, bundleName};
780 CAMERA_SYSEVENT_BEHAVIOR(CreateMsg("OnCameraStatusChanged! for cameraId:%s, current Camera Status:%d",
781 cameraId.c_str(), status));
782 }
783 }
784
OnFlashlightStatus(const string & cameraId,FlashStatus status)785 void HCameraService::OnFlashlightStatus(const string& cameraId, FlashStatus status)
786 {
787 lock_guard<mutex> lock(cameraCbMutex_);
788 MEDIA_INFO_LOG("HCameraService::OnFlashlightStatus callbacks.size = %{public}zu, cameraId = %{public}s, "
789 "status = %{public}d, pid = %{public}d", cameraServiceCallbacks_.size(), cameraId.c_str(), status,
790 IPCSkeleton::GetCallingPid());
791 for (auto it : cameraServiceCallbacks_) {
792 if (it.second == nullptr) {
793 MEDIA_ERR_LOG("HCameraService::OnCameraStatus pid:%{public}d cameraServiceCallback is null", it.first);
794 continue;
795 }
796 uint32_t pid = it.first;
797 if (ShouldSkipStatusUpdates(pid)) {
798 continue;
799 }
800 it.second->OnFlashlightStatusChanged(cameraId, status);
801 }
802 }
803
OnMute(bool muteMode)804 void HCameraService::OnMute(bool muteMode)
805 {
806 lock_guard<mutex> lock(muteCbMutex_);
807 if (!cameraMuteServiceCallbacks_.empty()) {
808 for (auto it : cameraMuteServiceCallbacks_) {
809 if (it.second == nullptr) {
810 MEDIA_ERR_LOG("HCameraService::OnMute pid:%{public}d cameraMuteServiceCallback is null", it.first);
811 continue;
812 }
813 uint32_t pid = it.first;
814 if (ShouldSkipStatusUpdates(pid)) {
815 continue;
816 }
817 it.second->OnCameraMute(muteMode);
818 CAMERA_SYSEVENT_BEHAVIOR(CreateMsg("OnCameraMute! current Camera muteMode:%d", muteMode));
819 }
820 }
821 if (peerCallback_ != nullptr) {
822 MEDIA_INFO_LOG("HCameraService::NotifyMuteCamera peerCallback current camera muteMode:%{public}d", muteMode);
823 peerCallback_->NotifyMuteCamera(muteMode);
824 }
825 }
826
OnTorchStatus(TorchStatus status)827 void HCameraService::OnTorchStatus(TorchStatus status)
828 {
829 lock_guard<recursive_mutex> lock(torchCbMutex_);
830 torchStatus_ = status;
831 MEDIA_INFO_LOG("HCameraService::OnTorchtStatus callbacks.size = %{public}zu, status = %{public}d, pid = %{public}d",
832 torchServiceCallbacks_.size(), status, IPCSkeleton::GetCallingPid());
833 for (auto it : torchServiceCallbacks_) {
834 if (it.second == nullptr) {
835 MEDIA_ERR_LOG("HCameraService::OnTorchtStatus pid:%{public}d torchServiceCallback is null", it.first);
836 continue;
837 }
838 uint32_t pid = it.first;
839 if (ShouldSkipStatusUpdates(pid)) {
840 continue;
841 }
842 it.second->OnTorchStatusChange(status);
843 }
844 }
845
OnFoldStatusChanged(OHOS::Rosen::FoldStatus foldStatus)846 void HCameraService::OnFoldStatusChanged(OHOS::Rosen::FoldStatus foldStatus)
847 {
848 MEDIA_INFO_LOG("OnFoldStatusChanged preFoldStatus = %{public}d, foldStatus = %{public}d, pid = %{public}d",
849 preFoldStatus_, foldStatus, IPCSkeleton::GetCallingPid());
850 auto curFoldStatus = (FoldStatus)foldStatus;
851 if ((curFoldStatus == FoldStatus::HALF_FOLD && preFoldStatus_ == FoldStatus::EXPAND) ||
852 (curFoldStatus == FoldStatus::EXPAND && preFoldStatus_ == FoldStatus::HALF_FOLD)) {
853 preFoldStatus_ = curFoldStatus;
854 return;
855 }
856 preFoldStatus_ = curFoldStatus;
857 if (curFoldStatus == FoldStatus::HALF_FOLD) {
858 curFoldStatus = FoldStatus::EXPAND;
859 }
860 lock_guard<recursive_mutex> lock(foldCbMutex_);
861 CHECK_EXECUTE(innerFoldCallback_, innerFoldCallback_->OnFoldStatusChanged(curFoldStatus));
862 CHECK_ERROR_RETURN_LOG(foldServiceCallbacks_.empty(), "OnFoldStatusChanged foldServiceCallbacks is empty");
863 MEDIA_INFO_LOG("OnFoldStatusChanged foldStatusCallback size = %{public}zu", foldServiceCallbacks_.size());
864 for (auto it : foldServiceCallbacks_) {
865 if (it.second == nullptr) {
866 MEDIA_ERR_LOG("OnFoldStatusChanged pid:%{public}d foldStatusCallbacks is null", it.first);
867 continue;
868 }
869 uint32_t pid = it.first;
870 if (ShouldSkipStatusUpdates(pid)) {
871 continue;
872 }
873 it.second->OnFoldStatusChanged(curFoldStatus);
874 }
875 }
876
CloseCameraForDestory(pid_t pid)877 int32_t HCameraService::CloseCameraForDestory(pid_t pid)
878 {
879 MEDIA_INFO_LOG("HCameraService::CloseCameraForDestory enter");
880 sptr<HCameraDeviceManager> deviceManager = HCameraDeviceManager::GetInstance();
881 sptr<HCameraDevice> deviceNeedClose = deviceManager->GetCameraByPid(pid);
882 if (deviceNeedClose != nullptr) {
883 deviceNeedClose->Close();
884 }
885 return CAMERA_OK;
886 }
887
ExecutePidSetCallback(sptr<ICameraServiceCallback> & callback,std::vector<std::string> & cameraIds)888 void HCameraService::ExecutePidSetCallback(sptr<ICameraServiceCallback>& callback, std::vector<std::string> &cameraIds)
889 {
890 for (const auto& cameraId : cameraIds) {
891 auto it = cameraStatusCallbacks_.find(cameraId);
892 if (it != cameraStatusCallbacks_.end()) {
893 MEDIA_INFO_LOG("ExecutePidSetCallback cameraId = %{public}s, status = %{public}d, bundleName = %{public}s",
894 cameraId.c_str(), it->second.status, it->second.bundleName.c_str());
895 callback->OnCameraStatusChanged(cameraId, it->second.status, it->second.bundleName);
896 } else {
897 MEDIA_INFO_LOG("ExecutePidSetCallback cameraId = %{public}s, status = 2", cameraId.c_str());
898 callback->OnCameraStatusChanged(cameraId, CameraStatus::CAMERA_STATUS_AVAILABLE);
899 }
900 }
901 }
902
SetCameraCallback(sptr<ICameraServiceCallback> & callback)903 int32_t HCameraService::SetCameraCallback(sptr<ICameraServiceCallback>& callback)
904 {
905 std::vector<std::string> cameraIds;
906 GetCameraIds(cameraIds);
907 lock_guard<mutex> lock(cameraCbMutex_);
908 pid_t pid = IPCSkeleton::GetCallingPid();
909 MEDIA_INFO_LOG("HCameraService::SetCameraCallback pid = %{public}d", pid);
910 CHECK_ERROR_RETURN_RET_LOG(callback == nullptr, CAMERA_INVALID_ARG,
911 "HCameraService::SetCameraCallback callback is null");
912 auto callbackItem = cameraServiceCallbacks_.find(pid);
913 if (callbackItem != cameraServiceCallbacks_.end()) {
914 callbackItem->second = nullptr;
915 (void)cameraServiceCallbacks_.erase(callbackItem);
916 }
917 cameraServiceCallbacks_.insert(make_pair(pid, callback));
918 ExecutePidSetCallback(callback, cameraIds);
919 return CAMERA_OK;
920 }
921
SetMuteCallback(sptr<ICameraMuteServiceCallback> & callback)922 int32_t HCameraService::SetMuteCallback(sptr<ICameraMuteServiceCallback>& callback)
923 {
924 lock_guard<mutex> lock(muteCbMutex_);
925 pid_t pid = IPCSkeleton::GetCallingPid();
926 MEDIA_INFO_LOG("HCameraService::SetMuteCallback pid = %{public}d", pid);
927 CHECK_ERROR_RETURN_RET_LOG(callback == nullptr, CAMERA_INVALID_ARG,
928 "HCameraService::SetMuteCallback callback is null");
929 // If the callback set by the SA caller is later than the camera service is started,
930 // the callback cannot be triggered to obtain the mute state. Therefore,
931 // when the SA sets the callback, the callback is triggered immediately to return the mute state.
932 constexpr int32_t maxSaUid = 10000;
933 if (IPCSkeleton::GetCallingUid() > 0 && IPCSkeleton::GetCallingUid() < maxSaUid) {
934 callback->OnCameraMute(muteModeStored_);
935 }
936 cameraMuteServiceCallbacks_.insert(make_pair(pid, callback));
937 return CAMERA_OK;
938 }
939
SetTorchCallback(sptr<ITorchServiceCallback> & callback)940 int32_t HCameraService::SetTorchCallback(sptr<ITorchServiceCallback>& callback)
941 {
942 lock_guard<recursive_mutex> lock(torchCbMutex_);
943 pid_t pid = IPCSkeleton::GetCallingPid();
944 MEDIA_INFO_LOG("HCameraService::SetTorchCallback pid = %{public}d", pid);
945 CHECK_ERROR_RETURN_RET_LOG(callback == nullptr, CAMERA_INVALID_ARG,
946 "HCameraService::SetTorchCallback callback is null");
947 torchServiceCallbacks_.insert(make_pair(pid, callback));
948
949 MEDIA_INFO_LOG("HCameraService::SetTorchCallback notify pid = %{public}d", pid);
950 callback->OnTorchStatusChange(torchStatus_);
951 return CAMERA_OK;
952 }
953
SetFoldStatusCallback(sptr<IFoldServiceCallback> & callback,bool isInnerCallback)954 int32_t HCameraService::SetFoldStatusCallback(sptr<IFoldServiceCallback>& callback, bool isInnerCallback)
955 {
956 lock_guard<recursive_mutex> lock(foldCbMutex_);
957 isFoldable = isFoldableInit ? isFoldable : g_isFoldScreen;
958 CHECK_EXECUTE((isFoldable && !isFoldRegister), RegisterFoldStatusListener());
959 if (isInnerCallback) {
960 innerFoldCallback_ = callback;
961 } else {
962 pid_t pid = IPCSkeleton::GetCallingPid();
963 MEDIA_INFO_LOG("HCameraService::SetFoldStatusCallback pid = %{public}d", pid);
964 CHECK_ERROR_RETURN_RET_LOG(callback == nullptr, CAMERA_INVALID_ARG,
965 "HCameraService::SetFoldStatusCallback callback is null");
966 foldServiceCallbacks_.insert(make_pair(pid, callback));
967 }
968 return CAMERA_OK;
969 }
970
UnSetCameraCallback(pid_t pid)971 int32_t HCameraService::UnSetCameraCallback(pid_t pid)
972 {
973 lock_guard<mutex> lock(cameraCbMutex_);
974 MEDIA_INFO_LOG("HCameraService::UnSetCameraCallback pid = %{public}d, size = %{public}zu",
975 pid, cameraServiceCallbacks_.size());
976 if (!cameraServiceCallbacks_.empty()) {
977 MEDIA_INFO_LOG("HCameraService::UnSetCameraCallback cameraServiceCallbacks_ is not empty, reset it");
978 auto it = cameraServiceCallbacks_.find(pid);
979 if ((it != cameraServiceCallbacks_.end()) && (it->second != nullptr)) {
980 it->second = nullptr;
981 cameraServiceCallbacks_.erase(it);
982 }
983 }
984 MEDIA_INFO_LOG("HCameraService::UnSetCameraCallback after erase pid = %{public}d, size = %{public}zu",
985 pid, cameraServiceCallbacks_.size());
986 return CAMERA_OK;
987 }
988
UnSetMuteCallback(pid_t pid)989 int32_t HCameraService::UnSetMuteCallback(pid_t pid)
990 {
991 lock_guard<mutex> lock(muteCbMutex_);
992 MEDIA_INFO_LOG("HCameraService::UnSetMuteCallback pid = %{public}d, size = %{public}zu",
993 pid, cameraMuteServiceCallbacks_.size());
994 if (!cameraMuteServiceCallbacks_.empty()) {
995 MEDIA_INFO_LOG("HCameraService::UnSetMuteCallback cameraMuteServiceCallbacks_ is not empty, reset it");
996 auto it = cameraMuteServiceCallbacks_.find(pid);
997 if ((it != cameraMuteServiceCallbacks_.end()) && (it->second)) {
998 it->second = nullptr;
999 cameraMuteServiceCallbacks_.erase(it);
1000 }
1001 }
1002
1003 MEDIA_INFO_LOG("HCameraService::UnSetMuteCallback after erase pid = %{public}d, size = %{public}zu",
1004 pid, cameraMuteServiceCallbacks_.size());
1005 return CAMERA_OK;
1006 }
1007
UnSetTorchCallback(pid_t pid)1008 int32_t HCameraService::UnSetTorchCallback(pid_t pid)
1009 {
1010 lock_guard<recursive_mutex> lock(torchCbMutex_);
1011 MEDIA_INFO_LOG("HCameraService::UnSetTorchCallback pid = %{public}d, size = %{public}zu",
1012 pid, torchServiceCallbacks_.size());
1013 if (!torchServiceCallbacks_.empty()) {
1014 MEDIA_INFO_LOG("HCameraService::UnSetTorchCallback torchServiceCallbacks_ is not empty, reset it");
1015 auto it = torchServiceCallbacks_.find(pid);
1016 if ((it != torchServiceCallbacks_.end()) && (it->second)) {
1017 it->second = nullptr;
1018 torchServiceCallbacks_.erase(it);
1019 }
1020 }
1021
1022 MEDIA_INFO_LOG("HCameraService::UnSetTorchCallback after erase pid = %{public}d, size = %{public}zu",
1023 pid, torchServiceCallbacks_.size());
1024 return CAMERA_OK;
1025 }
1026
UnSetFoldStatusCallback(pid_t pid)1027 int32_t HCameraService::UnSetFoldStatusCallback(pid_t pid)
1028 {
1029 lock_guard<recursive_mutex> lock(foldCbMutex_);
1030 MEDIA_INFO_LOG("HCameraService::UnSetFoldStatusCallback pid = %{public}d, size = %{public}zu",
1031 pid, foldServiceCallbacks_.size());
1032 if (!foldServiceCallbacks_.empty()) {
1033 MEDIA_INFO_LOG("HCameraService::UnSetFoldStatusCallback foldServiceCallbacks_ is not empty, reset it");
1034 auto it = foldServiceCallbacks_.find(pid);
1035 if ((it != foldServiceCallbacks_.end()) && (it->second)) {
1036 it->second = nullptr;
1037 foldServiceCallbacks_.erase(it);
1038 }
1039 }
1040 MEDIA_INFO_LOG("HCameraService::UnSetFoldStatusCallback after erase pid = %{public}d, size = %{public}zu",
1041 pid, foldServiceCallbacks_.size());
1042 innerFoldCallback_ = nullptr;
1043 return CAMERA_OK;
1044 }
1045
RegisterFoldStatusListener()1046 void HCameraService::RegisterFoldStatusListener()
1047 {
1048 MEDIA_INFO_LOG("RegisterFoldStatusListener is called");
1049 preFoldStatus_ = (FoldStatus)OHOS::Rosen::DisplayManager::GetInstance().GetFoldStatus();
1050 auto ret = OHOS::Rosen::DisplayManager::GetInstance().RegisterFoldStatusListener(this);
1051 CHECK_ERROR_RETURN_LOG(ret != OHOS::Rosen::DMError::DM_OK, "RegisterFoldStatusListener failed");
1052 isFoldRegister = true;
1053 }
1054
UnRegisterFoldStatusListener()1055 void HCameraService::UnRegisterFoldStatusListener()
1056 {
1057 MEDIA_INFO_LOG("UnRegisterFoldStatusListener is called");
1058 auto ret = OHOS::Rosen::DisplayManager::GetInstance().UnregisterFoldStatusListener(this);
1059 preFoldStatus_ = FoldStatus::UNKNOWN_FOLD;
1060 CHECK_ERROR_PRINT_LOG(ret != OHOS::Rosen::DMError::DM_OK, "UnRegisterFoldStatusListener failed");
1061 isFoldRegister = false;
1062 }
1063
UnSetAllCallback(pid_t pid)1064 int32_t HCameraService::UnSetAllCallback(pid_t pid)
1065 {
1066 MEDIA_INFO_LOG("HCameraService::UnSetAllCallback enter");
1067 UnSetCameraCallback(pid);
1068 UnSetMuteCallback(pid);
1069 UnSetTorchCallback(pid);
1070 UnSetFoldStatusCallback(pid);
1071 return CAMERA_OK;
1072 }
1073
IsCameraMuteSupported(string cameraId)1074 bool HCameraService::IsCameraMuteSupported(string cameraId)
1075 {
1076 bool isMuteSupported = false;
1077 shared_ptr<OHOS::Camera::CameraMetadata> cameraAbility;
1078 int32_t ret = cameraHostManager_->GetCameraAbility(cameraId, cameraAbility);
1079 CHECK_ERROR_RETURN_RET_LOG(ret != CAMERA_OK, false, "HCameraService::IsCameraMuted GetCameraAbility failed");
1080 camera_metadata_item_t item;
1081 common_metadata_header_t* metadata = cameraAbility->get();
1082 ret = OHOS::Camera::FindCameraMetadataItem(metadata, OHOS_ABILITY_MUTE_MODES, &item);
1083 if (ret == CAM_META_SUCCESS) {
1084 for (uint32_t i = 0; i < item.count; i++) {
1085 MEDIA_INFO_LOG("OHOS_ABILITY_MUTE_MODES %{public}d th is %{public}d", i, item.data.u8[i]);
1086 if (item.data.u8[i] == OHOS_CAMERA_MUTE_MODE_SOLID_COLOR_BLACK) {
1087 isMuteSupported = true;
1088 break;
1089 }
1090 }
1091 } else {
1092 isMuteSupported = false;
1093 MEDIA_ERR_LOG("HCameraService::IsCameraMuted not find MUTE ability");
1094 }
1095 MEDIA_DEBUG_LOG("HCameraService::IsCameraMuted supported: %{public}d", isMuteSupported);
1096 return isMuteSupported;
1097 }
1098
UpdateMuteSetting(sptr<HCameraDevice> cameraDevice,bool muteMode)1099 int32_t HCameraService::UpdateMuteSetting(sptr<HCameraDevice> cameraDevice, bool muteMode)
1100 {
1101 constexpr int32_t DEFAULT_ITEMS = 1;
1102 constexpr int32_t DEFAULT_DATA_LENGTH = 1;
1103 shared_ptr<OHOS::Camera::CameraMetadata> changedMetadata =
1104 make_shared<OHOS::Camera::CameraMetadata>(DEFAULT_ITEMS, DEFAULT_DATA_LENGTH);
1105 bool status = false;
1106 int32_t ret;
1107 int32_t count = 1;
1108 uint8_t mode = muteMode ? OHOS_CAMERA_MUTE_MODE_SOLID_COLOR_BLACK : OHOS_CAMERA_MUTE_MODE_OFF;
1109 camera_metadata_item_t item;
1110
1111 MEDIA_DEBUG_LOG("UpdateMuteSetting muteMode: %{public}d", muteMode);
1112
1113 ret = OHOS::Camera::FindCameraMetadataItem(changedMetadata->get(), OHOS_CONTROL_MUTE_MODE, &item);
1114 if (ret == CAM_META_ITEM_NOT_FOUND) {
1115 status = changedMetadata->addEntry(OHOS_CONTROL_MUTE_MODE, &mode, count);
1116 } else if (ret == CAM_META_SUCCESS) {
1117 status = changedMetadata->updateEntry(OHOS_CONTROL_MUTE_MODE, &mode, count);
1118 }
1119 ret = cameraDevice->UpdateSetting(changedMetadata);
1120 CHECK_ERROR_RETURN_RET_LOG(!status || ret != CAMERA_OK, CAMERA_UNKNOWN_ERROR, "UpdateMuteSetting muteMode Failed");
1121 return CAMERA_OK;
1122 }
1123
MuteCameraFunc(bool muteMode)1124 int32_t HCameraService::MuteCameraFunc(bool muteMode)
1125 {
1126 {
1127 lock_guard<mutex> lock(g_dataShareHelperMutex);
1128 cameraHostManager_->SetMuteMode(muteMode);
1129 }
1130 int32_t ret = CAMERA_OK;
1131 bool currentMuteMode = muteModeStored_;
1132 sptr<HCameraDeviceManager> deviceManager = HCameraDeviceManager::GetInstance();
1133 pid_t activeClient = deviceManager->GetActiveClient();
1134 if (activeClient == -1) {
1135 OnMute(muteMode);
1136 int32_t retCode = SetMuteModeByDataShareHelper(muteMode);
1137 muteModeStored_ = muteMode;
1138 if (retCode != CAMERA_OK) {
1139 MEDIA_ERR_LOG("no activeClient, SetMuteModeByDataShareHelper: ret=%{public}d", retCode);
1140 muteModeStored_ = currentMuteMode;
1141 }
1142 return retCode;
1143 }
1144 sptr<HCameraDevice> activeDevice = deviceManager->GetCameraByPid(activeClient);
1145 if (activeDevice != nullptr) {
1146 string cameraId = activeDevice->GetCameraId();
1147 CHECK_ERROR_RETURN_RET_LOG(!IsCameraMuteSupported(cameraId), CAMERA_UNSUPPORTED,
1148 "Not Supported Mute,cameraId: %{public}s", cameraId.c_str());
1149 if (activeDevice != nullptr) {
1150 ret = UpdateMuteSetting(activeDevice, muteMode);
1151 }
1152 if (ret != CAMERA_OK) {
1153 MEDIA_ERR_LOG("UpdateMuteSetting Failed, cameraId: %{public}s", cameraId.c_str());
1154 muteModeStored_ = currentMuteMode;
1155 }
1156 }
1157 if (ret == CAMERA_OK) {
1158 OnMute(muteMode);
1159 }
1160 if (activeDevice != nullptr) {
1161 activeDevice->SetDeviceMuteMode(muteMode);
1162 }
1163 ret = SetMuteModeByDataShareHelper(muteMode);
1164 if (ret == CAMERA_OK) {
1165 muteModeStored_ = muteMode;
1166 }
1167 return ret;
1168 }
1169
1170 static std::map<PolicyType, Security::AccessToken::PolicyType> g_policyTypeMap_ = {
1171 {PolicyType::EDM, Security::AccessToken::PolicyType::EDM},
1172 {PolicyType::PRIVACY, Security::AccessToken::PolicyType::PRIVACY},
1173 };
1174
MuteCamera(bool muteMode)1175 int32_t HCameraService::MuteCamera(bool muteMode)
1176 {
1177 int32_t ret = CheckPermission(OHOS_PERMISSION_MANAGE_CAMERA_CONFIG, IPCSkeleton::GetCallingTokenID());
1178 CHECK_ERROR_RETURN_RET_LOG(ret != CAMERA_OK, ret, "CheckPermission argumentis failed!");
1179 CameraReportUtils::GetInstance().ReportUserBehavior(DFX_UB_MUTE_CAMERA,
1180 to_string(muteMode), CameraReportUtils::GetCallerInfo());
1181 return MuteCameraFunc(muteMode);
1182 }
1183
MuteCameraPersist(PolicyType policyType,bool isMute)1184 int32_t HCameraService::MuteCameraPersist(PolicyType policyType, bool isMute)
1185 {
1186 OHOS::Security::AccessToken::AccessTokenID callerToken = IPCSkeleton::GetCallingTokenID();
1187 int32_t ret = CheckPermission(OHOS_PERMISSION_CAMERA_CONTROL, callerToken);
1188 CHECK_ERROR_RETURN_RET_LOG(ret != CAMERA_OK, ret, "CheckPermission arguments failed!");
1189 CameraReportUtils::GetInstance().ReportUserBehavior(DFX_UB_MUTE_CAMERA,
1190 to_string(isMute), CameraReportUtils::GetCallerInfo());
1191 CHECK_ERROR_RETURN_RET_LOG(g_policyTypeMap_.count(policyType) == 0, CAMERA_INVALID_ARG,
1192 "MuteCameraPersist Failed, invalid param policyType = %{public}d", static_cast<int32_t>(policyType));
1193 bool targetMuteMode = isMute;
1194 const Security::AccessToken::PolicyType secPolicyType = g_policyTypeMap_[policyType];
1195 const Security::AccessToken::CallerType secCaller = Security::AccessToken::CallerType::CAMERA;
1196 ret = Security::AccessToken::PrivacyKit::SetMutePolicy(secPolicyType, secCaller, isMute, callerToken);
1197 if (ret != Security::AccessToken::RET_SUCCESS) {
1198 MEDIA_ERR_LOG("MuteCameraPersist SetMutePolicy return false, policyType = %{public}d, retCode = %{public}d",
1199 static_cast<int32_t>(policyType), static_cast<int32_t>(ret));
1200 targetMuteMode = muteModeStored_;
1201 }
1202 return MuteCameraFunc(targetMuteMode);
1203 }
1204
PrelaunchCamera()1205 int32_t HCameraService::PrelaunchCamera()
1206 {
1207 CAMERA_SYNC_TRACE;
1208 MEDIA_INFO_LOG("HCameraService::PrelaunchCamera");
1209 CHECK_ERROR_RETURN_RET_LOG(HCameraDeviceManager::GetInstance()->GetCameraStateOfASide().Size() != 0,
1210 CAMERA_DEVICE_CONFLICT, "HCameraService::PrelaunchCamera there is a device active in A side, abort!");
1211 if (preCameraId_.empty()) {
1212 vector<string> cameraIds_;
1213 cameraHostManager_->GetCameras(cameraIds_);
1214 if (cameraIds_.empty()) {
1215 return CAMERA_OK;
1216 }
1217 preCameraId_ = cameraIds_.front();
1218 }
1219 MEDIA_INFO_LOG("HCameraService::PrelaunchCamera preCameraId_ is: %{public}s", preCameraId_.c_str());
1220 CAMERA_SYSEVENT_STATISTIC(CreateMsg("Camera Prelaunch CameraId:%s", preCameraId_.c_str()));
1221 CameraReportUtils::GetInstance().SetOpenCamPerfPreInfo(preCameraId_.c_str(), CameraReportUtils::GetCallerInfo());
1222 int32_t ret = cameraHostManager_->Prelaunch(preCameraId_, preCameraClient_);
1223 CHECK_ERROR_PRINT_LOG(ret != CAMERA_OK, "HCameraService::Prelaunch failed");
1224 return ret;
1225 }
1226
PreSwitchCamera(const std::string cameraId)1227 int32_t HCameraService::PreSwitchCamera(const std::string cameraId)
1228 {
1229 CAMERA_SYNC_TRACE;
1230 MEDIA_INFO_LOG("HCameraService::PreSwitchCamera");
1231 if (cameraId.empty()) {
1232 return CAMERA_INVALID_ARG;
1233 }
1234 std::vector<std::string> cameraIds_;
1235 cameraHostManager_->GetCameras(cameraIds_);
1236 CHECK_AND_RETURN_RET(!cameraIds_.empty(), CAMERA_INVALID_STATE);
1237 auto it = std::find(cameraIds_.begin(), cameraIds_.end(), cameraId);
1238 CHECK_AND_RETURN_RET(it != cameraIds_.end(), CAMERA_INVALID_ARG);
1239 MEDIA_INFO_LOG("HCameraService::PreSwitchCamera cameraId is: %{public}s", cameraId.c_str());
1240 CameraReportUtils::GetInstance().SetSwitchCamPerfStartInfo(CameraReportUtils::GetCallerInfo());
1241 int32_t ret = cameraHostManager_->PreSwitchCamera(cameraId);
1242 CHECK_ERROR_PRINT_LOG(ret != CAMERA_OK, "HCameraService::Prelaunch failed");
1243 return ret;
1244 }
1245
SetPrelaunchConfig(string cameraId,RestoreParamTypeOhos restoreParamType,int activeTime,EffectParam effectParam)1246 int32_t HCameraService::SetPrelaunchConfig(string cameraId, RestoreParamTypeOhos restoreParamType, int activeTime,
1247 EffectParam effectParam)
1248 {
1249 CAMERA_SYNC_TRACE;
1250 OHOS::Security::AccessToken::AccessTokenID callerToken = IPCSkeleton::GetCallingTokenID();
1251 string permissionName = OHOS_PERMISSION_CAMERA;
1252 int32_t ret = CheckPermission(permissionName, callerToken);
1253 CHECK_ERROR_RETURN_RET_LOG(ret != CAMERA_OK, ret,
1254 "HCameraService::SetPrelaunchConfig failed permission is: %{public}s", permissionName.c_str());
1255
1256 MEDIA_INFO_LOG("HCameraService::SetPrelaunchConfig cameraId %{public}s", (cameraId).c_str());
1257 vector<string> cameraIds_;
1258 cameraHostManager_->GetCameras(cameraIds_);
1259 if ((find(cameraIds_.begin(), cameraIds_.end(), cameraId) != cameraIds_.end()) && IsPrelaunchSupported(cameraId)) {
1260 preCameraId_ = cameraId;
1261 MEDIA_INFO_LOG("CameraHostInfo::prelaunch 111 for cameraId %{public}s", (cameraId).c_str());
1262 sptr<HCaptureSession> captureSession_ = nullptr;
1263 pid_t pid = IPCSkeleton::GetCallingPid();
1264 captureSessionsManager_.Find(pid, captureSession_);
1265 SaveCurrentParamForRestore(cameraId, static_cast<RestoreParamTypeOhos>(restoreParamType), activeTime,
1266 effectParam, captureSession_);
1267 captureSessionsManager_.Clear();
1268 captureSessionsManager_.EnsureInsert(pid, captureSession_);
1269 } else {
1270 MEDIA_ERR_LOG("HCameraService::SetPrelaunchConfig illegal");
1271 ret = CAMERA_INVALID_ARG;
1272 }
1273 return ret;
1274 }
1275
SetTorchLevel(float level)1276 int32_t HCameraService::SetTorchLevel(float level)
1277 {
1278 int32_t ret = cameraHostManager_->SetTorchLevel(level);
1279 CHECK_ERROR_PRINT_LOG(ret != CAMERA_OK, "Failed to SetTorchLevel");
1280 return ret;
1281 }
1282
AllowOpenByOHSide(std::string cameraId,int32_t state,bool & canOpenCamera)1283 int32_t HCameraService::AllowOpenByOHSide(std::string cameraId, int32_t state, bool& canOpenCamera)
1284 {
1285 MEDIA_INFO_LOG("HCameraService::AllowOpenByOHSide start");
1286 pid_t activePid = HCameraDeviceManager::GetInstance()->GetActiveClient();
1287 if (activePid == -1) {
1288 MEDIA_INFO_LOG("AllowOpenByOHSide::Open allow open camera");
1289 NotifyCameraState(cameraId, 0);
1290 canOpenCamera = true;
1291 return CAMERA_OK;
1292 }
1293 sptr<HCameraDevice> cameraNeedEvict = HCameraDeviceManager::GetInstance()->GetCameraByPid(activePid);
1294 if (cameraNeedEvict != nullptr) {
1295 cameraNeedEvict->OnError(DEVICE_PREEMPT, 0);
1296 cameraNeedEvict->Close();
1297 NotifyCameraState(cameraId, 0);
1298 canOpenCamera = true;
1299 }
1300 MEDIA_INFO_LOG("HCameraService::AllowOpenByOHSide end");
1301 return CAMERA_OK;
1302 }
1303
NotifyCameraState(std::string cameraId,int32_t state)1304 int32_t HCameraService::NotifyCameraState(std::string cameraId, int32_t state)
1305 {
1306 // 把cameraId和前后台状态刷新给device manager
1307 MEDIA_INFO_LOG(
1308 "HCameraService::NotifyCameraState SetStateOfACamera %{public}s:%{public}d", cameraId.c_str(), state);
1309 HCameraDeviceManager::GetInstance()->SetStateOfACamera(cameraId, state);
1310 return CAMERA_OK;
1311 }
1312
SetPeerCallback(sptr<ICameraBroker> & callback)1313 int32_t HCameraService::SetPeerCallback(sptr<ICameraBroker>& callback)
1314 {
1315 MEDIA_INFO_LOG("SetPeerCallback get callback");
1316 CHECK_ERROR_RETURN_RET(callback == nullptr, CAMERA_INVALID_ARG);
1317 peerCallback_ = callback;
1318 MEDIA_INFO_LOG("HCameraService::SetPeerCallback current muteMode:%{public}d", muteModeStored_);
1319 callback->NotifyMuteCamera(muteModeStored_);
1320 HCameraDeviceManager::GetInstance()->SetPeerCallback(callback);
1321 return CAMERA_OK;
1322 }
1323
UnsetPeerCallback()1324 int32_t HCameraService::UnsetPeerCallback()
1325 {
1326 MEDIA_INFO_LOG("UnsetPeerCallback callback");
1327 peerCallback_ = nullptr;
1328 HCameraDeviceManager::GetInstance()->UnsetPeerCallback();
1329 return CAMERA_OK;
1330 }
1331
IsPrelaunchSupported(string cameraId)1332 bool HCameraService::IsPrelaunchSupported(string cameraId)
1333 {
1334 bool isPrelaunchSupported = false;
1335 shared_ptr<OHOS::Camera::CameraMetadata> cameraAbility;
1336 int32_t ret = cameraHostManager_->GetCameraAbility(cameraId, cameraAbility);
1337 CHECK_ERROR_RETURN_RET_LOG(ret != CAMERA_OK, isPrelaunchSupported,
1338 "HCameraService::IsCameraMuted GetCameraAbility failed");
1339 camera_metadata_item_t item;
1340 common_metadata_header_t* metadata = cameraAbility->get();
1341 ret = OHOS::Camera::FindCameraMetadataItem(metadata, OHOS_ABILITY_PRELAUNCH_AVAILABLE, &item);
1342 if (ret == 0) {
1343 MEDIA_INFO_LOG(
1344 "CameraManager::IsPrelaunchSupported() OHOS_ABILITY_PRELAUNCH_AVAILABLE is %{public}d", item.data.u8[0]);
1345 isPrelaunchSupported = (item.data.u8[0] == 1);
1346 } else {
1347 MEDIA_ERR_LOG("Failed to get OHOS_ABILITY_PRELAUNCH_AVAILABLE ret = %{public}d", ret);
1348 }
1349 return isPrelaunchSupported;
1350 }
1351
GetServiceStatus()1352 CameraServiceStatus HCameraService::GetServiceStatus()
1353 {
1354 lock_guard<mutex> lock(serviceStatusMutex_);
1355 return serviceStatus_;
1356 }
1357
SetServiceStatus(CameraServiceStatus serviceStatus)1358 void HCameraService::SetServiceStatus(CameraServiceStatus serviceStatus)
1359 {
1360 lock_guard<mutex> lock(serviceStatusMutex_);
1361 serviceStatus_ = serviceStatus;
1362 MEDIA_DEBUG_LOG("HCameraService::SetServiceStatus success. serviceStatus: %{public}d", serviceStatus);
1363 }
1364
IsCameraMuted(bool & muteMode)1365 int32_t HCameraService::IsCameraMuted(bool& muteMode)
1366 {
1367 lock_guard<mutex> lock(g_dataShareHelperMutex);
1368 CHECK_ERROR_RETURN_RET(GetServiceStatus() != CameraServiceStatus::SERVICE_READY, CAMERA_INVALID_STATE);
1369 muteMode = muteModeStored_;
1370
1371 MEDIA_DEBUG_LOG("HCameraService::IsCameraMuted success. isMuted: %{public}d", muteMode);
1372 return CAMERA_OK;
1373 }
1374
DumpCameraSummary(vector<string> cameraIds,CameraInfoDumper & infoDumper)1375 void HCameraService::DumpCameraSummary(vector<string> cameraIds, CameraInfoDumper& infoDumper)
1376 {
1377 infoDumper.Tip("--------Dump Summary Begin-------");
1378 infoDumper.Title("Number of Cameras:[" + to_string(cameraIds.size()) + "]");
1379 infoDumper.Title("Number of Active Cameras:[" + to_string(1) + "]");
1380 infoDumper.Title("Current session summary:");
1381 HCaptureSession::DumpCameraSessionSummary(infoDumper);
1382 }
1383
DumpCameraInfo(CameraInfoDumper & infoDumper,std::vector<std::string> & cameraIds,std::vector<std::shared_ptr<OHOS::Camera::CameraMetadata>> & cameraAbilityList)1384 void HCameraService::DumpCameraInfo(CameraInfoDumper& infoDumper, std::vector<std::string>& cameraIds,
1385 std::vector<std::shared_ptr<OHOS::Camera::CameraMetadata>>& cameraAbilityList)
1386 {
1387 infoDumper.Tip("--------Dump CameraDevice Begin-------");
1388 int32_t capIdx = 0;
1389 for (auto& it : cameraIds) {
1390 auto metadata = cameraAbilityList[capIdx++];
1391 common_metadata_header_t* metadataEntry = metadata->get();
1392 infoDumper.Title("Camera ID:[" + it + "]:");
1393 infoDumper.Push();
1394 DumpCameraAbility(metadataEntry, infoDumper);
1395 DumpCameraStreamInfo(metadataEntry, infoDumper);
1396 DumpCameraZoom(metadataEntry, infoDumper);
1397 DumpCameraFlash(metadataEntry, infoDumper);
1398 DumpCameraAF(metadataEntry, infoDumper);
1399 DumpCameraAE(metadataEntry, infoDumper);
1400 DumpCameraSensorInfo(metadataEntry, infoDumper);
1401 DumpCameraVideoStabilization(metadataEntry, infoDumper);
1402 DumpCameraVideoFrameRateRange(metadataEntry, infoDumper);
1403 DumpCameraPrelaunch(metadataEntry, infoDumper);
1404 DumpCameraThumbnail(metadataEntry, infoDumper);
1405 infoDumper.Pop();
1406 }
1407 }
1408
DumpCameraAbility(common_metadata_header_t * metadataEntry,CameraInfoDumper & infoDumper)1409 void HCameraService::DumpCameraAbility(common_metadata_header_t* metadataEntry, CameraInfoDumper& infoDumper)
1410 {
1411 camera_metadata_item_t item;
1412 int ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_CAMERA_POSITION, &item);
1413 if (ret == CAM_META_SUCCESS) {
1414 map<int, string>::const_iterator iter = g_cameraPos.find(item.data.u8[0]);
1415 if (iter != g_cameraPos.end()) {
1416 infoDumper.Title("Camera Position:[" + iter->second + "]");
1417 }
1418 }
1419
1420 ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_CAMERA_TYPE, &item);
1421 if (ret == CAM_META_SUCCESS) {
1422 map<int, string>::const_iterator iter = g_cameraType.find(item.data.u8[0]);
1423 if (iter != g_cameraType.end()) {
1424 infoDumper.Title("Camera Type:[" + iter->second + "]");
1425 }
1426 }
1427
1428 ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_CAMERA_CONNECTION_TYPE, &item);
1429 if (ret == CAM_META_SUCCESS) {
1430 map<int, string>::const_iterator iter = g_cameraConType.find(item.data.u8[0]);
1431 if (iter != g_cameraConType.end()) {
1432 infoDumper.Title("Camera Connection Type:[" + iter->second + "]");
1433 }
1434 }
1435 }
1436
DumpCameraStreamInfo(common_metadata_header_t * metadataEntry,CameraInfoDumper & infoDumper)1437 void HCameraService::DumpCameraStreamInfo(common_metadata_header_t* metadataEntry, CameraInfoDumper& infoDumper)
1438 {
1439 camera_metadata_item_t item;
1440 int ret;
1441 constexpr uint32_t unitLen = 3;
1442 uint32_t widthOffset = 1;
1443 uint32_t heightOffset = 2;
1444 infoDumper.Title("Camera Available stream configuration List:");
1445 infoDumper.Push();
1446 ret =
1447 OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_STREAM_AVAILABLE_BASIC_CONFIGURATIONS, &item);
1448 if (ret == CAM_META_SUCCESS) {
1449 infoDumper.Title("Basic Stream Info Size: " + to_string(item.count / unitLen));
1450 for (uint32_t index = 0; index < item.count; index += unitLen) {
1451 map<int, string>::const_iterator iter = g_cameraFormat.find(item.data.i32[index]);
1452 if (iter != g_cameraFormat.end()) {
1453 infoDumper.Msg("Format:[" + iter->second + "] " +
1454 "Size:[Width:" + to_string(item.data.i32[index + widthOffset]) +
1455 " Height:" + to_string(item.data.i32[index + heightOffset]) + "]");
1456 } else {
1457 infoDumper.Msg("Format:[" + to_string(item.data.i32[index]) + "] " +
1458 "Size:[Width:" + to_string(item.data.i32[index + widthOffset]) +
1459 " Height:" + to_string(item.data.i32[index + heightOffset]) + "]");
1460 }
1461 }
1462 }
1463
1464 infoDumper.Pop();
1465 }
1466
DumpCameraZoom(common_metadata_header_t * metadataEntry,CameraInfoDumper & infoDumper)1467 void HCameraService::DumpCameraZoom(common_metadata_header_t* metadataEntry, CameraInfoDumper& infoDumper)
1468 {
1469 camera_metadata_item_t item;
1470 int ret;
1471 int32_t minIndex = 0;
1472 int32_t maxIndex = 1;
1473 uint32_t zoomRangeCount = 2;
1474 infoDumper.Title("Zoom Related Info:");
1475
1476 ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_ZOOM_CAP, &item);
1477 if (ret == CAM_META_SUCCESS) {
1478 infoDumper.Msg("OHOS_ABILITY_ZOOM_CAP data size:" + to_string(item.count));
1479 if (item.count == zoomRangeCount) {
1480 infoDumper.Msg("Available Zoom Capability:[" + to_string(item.data.i32[minIndex]) + " " +
1481 to_string(item.data.i32[maxIndex]) + "]");
1482 }
1483 }
1484
1485 ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_SCENE_ZOOM_CAP, &item);
1486 if (ret == CAM_META_SUCCESS) {
1487 infoDumper.Msg("OHOS_ABILITY_SCENE_ZOOM_CAP data size:" + to_string(item.count));
1488 if (item.count == zoomRangeCount) {
1489 infoDumper.Msg("Available scene Zoom Capability:[" + to_string(item.data.i32[minIndex]) + " " +
1490 to_string(item.data.i32[maxIndex]) + "]");
1491 }
1492 }
1493
1494 ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_ZOOM_RATIO_RANGE, &item);
1495 if (ret == CAM_META_SUCCESS) {
1496 infoDumper.Msg("OHOS_ABILITY_ZOOM_RATIO_RANGE data size:" + to_string(item.count));
1497 if (item.count == zoomRangeCount) {
1498 infoDumper.Msg("Available Zoom Ratio Range:[" + to_string(item.data.f[minIndex]) +
1499 to_string(item.data.f[maxIndex]) + "]");
1500 }
1501 }
1502 }
1503
DumpCameraFlash(common_metadata_header_t * metadataEntry,CameraInfoDumper & infoDumper)1504 void HCameraService::DumpCameraFlash(common_metadata_header_t* metadataEntry, CameraInfoDumper& infoDumper)
1505 {
1506 camera_metadata_item_t item;
1507 int ret;
1508 infoDumper.Title("Flash Related Info:");
1509 ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_FLASH_MODES, &item);
1510 if (ret == CAM_META_SUCCESS) {
1511 string flashAbilityString = "Available Flash Modes:[ ";
1512 for (uint32_t i = 0; i < item.count; i++) {
1513 map<int, string>::const_iterator iter = g_cameraFlashMode.find(item.data.u8[i]);
1514 if (iter != g_cameraFlashMode.end()) {
1515 flashAbilityString.append(iter->second + " ");
1516 }
1517 }
1518 flashAbilityString.append("]");
1519 infoDumper.Msg(flashAbilityString);
1520 }
1521 }
1522
DumpCameraAF(common_metadata_header_t * metadataEntry,CameraInfoDumper & infoDumper)1523 void HCameraService::DumpCameraAF(common_metadata_header_t* metadataEntry, CameraInfoDumper& infoDumper)
1524 {
1525 camera_metadata_item_t item;
1526 int ret;
1527 infoDumper.Title("AF Related Info:");
1528 ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_FOCUS_MODES, &item);
1529 if (ret == CAM_META_SUCCESS) {
1530 string afAbilityString = "Available Focus Modes:[ ";
1531 for (uint32_t i = 0; i < item.count; i++) {
1532 map<int, string>::const_iterator iter = g_cameraFocusMode.find(item.data.u8[i]);
1533 if (iter != g_cameraFocusMode.end()) {
1534 afAbilityString.append(iter->second + " ");
1535 }
1536 }
1537 afAbilityString.append("]");
1538 infoDumper.Msg(afAbilityString);
1539 }
1540 }
1541
DumpCameraAE(common_metadata_header_t * metadataEntry,CameraInfoDumper & infoDumper)1542 void HCameraService::DumpCameraAE(common_metadata_header_t* metadataEntry, CameraInfoDumper& infoDumper)
1543 {
1544 camera_metadata_item_t item;
1545 int ret;
1546 infoDumper.Title("AE Related Info:");
1547 ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_EXPOSURE_MODES, &item);
1548 if (ret == CAM_META_SUCCESS) {
1549 string aeAbilityString = "Available Exposure Modes:[ ";
1550 for (uint32_t i = 0; i < item.count; i++) {
1551 map<int, string>::const_iterator iter = g_cameraExposureMode.find(item.data.u8[i]);
1552 if (iter != g_cameraExposureMode.end()) {
1553 aeAbilityString.append(iter->second + " ");
1554 }
1555 }
1556 aeAbilityString.append("]");
1557 infoDumper.Msg(aeAbilityString);
1558 }
1559 }
1560
DumpCameraSensorInfo(common_metadata_header_t * metadataEntry,CameraInfoDumper & infoDumper)1561 void HCameraService::DumpCameraSensorInfo(common_metadata_header_t* metadataEntry, CameraInfoDumper& infoDumper)
1562 {
1563 camera_metadata_item_t item;
1564 int ret;
1565 int32_t leftIndex = 0;
1566 int32_t topIndex = 1;
1567 int32_t rightIndex = 2;
1568 int32_t bottomIndex = 3;
1569 infoDumper.Title("Sensor Related Info:");
1570 ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_SENSOR_INFO_ACTIVE_ARRAY_SIZE, &item);
1571 if (ret == CAM_META_SUCCESS) {
1572 infoDumper.Msg("Array:[" +
1573 to_string(item.data.i32[leftIndex]) + " " +
1574 to_string(item.data.i32[topIndex]) + " " +
1575 to_string(item.data.i32[rightIndex]) + " " +
1576 to_string(item.data.i32[bottomIndex]) + "]:\n");
1577 }
1578 }
1579
DumpCameraVideoStabilization(common_metadata_header_t * metadataEntry,CameraInfoDumper & infoDumper)1580 void HCameraService::DumpCameraVideoStabilization(common_metadata_header_t* metadataEntry, CameraInfoDumper& infoDumper)
1581 {
1582 camera_metadata_item_t item;
1583 int ret;
1584 infoDumper.Title("Video Stabilization Related Info:");
1585 ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_VIDEO_STABILIZATION_MODES, &item);
1586 if (ret == CAM_META_SUCCESS) {
1587 std::string infoString = "Available Video Stabilization Modes:[ ";
1588 for (uint32_t i = 0; i < item.count; i++) {
1589 map<int, string>::const_iterator iter = g_cameraVideoStabilizationMode.find(item.data.u8[i]);
1590 if (iter != g_cameraVideoStabilizationMode.end()) {
1591 infoString.append(iter->second + " ");
1592 }
1593 }
1594 infoString.append("]:");
1595 infoDumper.Msg(infoString);
1596 }
1597 }
1598
DumpCameraVideoFrameRateRange(common_metadata_header_t * metadataEntry,CameraInfoDumper & infoDumper)1599 void HCameraService::DumpCameraVideoFrameRateRange(
1600 common_metadata_header_t* metadataEntry, CameraInfoDumper& infoDumper)
1601 {
1602 camera_metadata_item_t item;
1603 const int32_t FRAME_RATE_RANGE_STEP = 2;
1604 int ret;
1605 infoDumper.Title("Video FrameRateRange Related Info:");
1606 ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_FPS_RANGES, &item);
1607 if (ret == CAM_META_SUCCESS && item.count > 0) {
1608 infoDumper.Msg("Available FrameRateRange:");
1609 for (uint32_t i = 0; i < (item.count - 1); i += FRAME_RATE_RANGE_STEP) {
1610 infoDumper.Msg("[ " + to_string(item.data.i32[i]) + ", " + to_string(item.data.i32[i + 1]) + " ]");
1611 }
1612 }
1613 }
1614
DumpCameraPrelaunch(common_metadata_header_t * metadataEntry,CameraInfoDumper & infoDumper)1615 void HCameraService::DumpCameraPrelaunch(common_metadata_header_t* metadataEntry, CameraInfoDumper& infoDumper)
1616 {
1617 camera_metadata_item_t item;
1618 int ret;
1619 infoDumper.Title("Camera Prelaunch Related Info:");
1620 ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_PRELAUNCH_AVAILABLE, &item);
1621 if (ret == CAM_META_SUCCESS) {
1622 map<int, string>::const_iterator iter = g_cameraPrelaunchAvailable.find(item.data.u8[0]);
1623 bool isSupport = false;
1624 if (iter != g_cameraPrelaunchAvailable.end()) {
1625 isSupport = true;
1626 }
1627 std::string infoString = "Available Prelaunch Info:[";
1628 infoString.append(isSupport ? "True" : "False");
1629 infoString.append("]");
1630 infoDumper.Msg(infoString);
1631 }
1632 }
1633
DumpCameraThumbnail(common_metadata_header_t * metadataEntry,CameraInfoDumper & infoDumper)1634 void HCameraService::DumpCameraThumbnail(common_metadata_header_t* metadataEntry, CameraInfoDumper& infoDumper)
1635 {
1636 camera_metadata_item_t item;
1637 int ret;
1638 infoDumper.Title("Camera Thumbnail Related Info:");
1639 ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_STREAM_QUICK_THUMBNAIL_AVAILABLE, &item);
1640 if (ret == CAM_META_SUCCESS) {
1641 map<int, string>::const_iterator iter = g_cameraQuickThumbnailAvailable.find(item.data.u8[0]);
1642 bool isSupport = false;
1643 if (iter != g_cameraQuickThumbnailAvailable.end()) {
1644 isSupport = true;
1645 }
1646 std::string infoString = "Available Thumbnail Info:[";
1647 infoString.append(isSupport ? "True" : "False");
1648 infoString.append("]");
1649 infoDumper.Msg(infoString);
1650 }
1651 }
1652
Dump(int fd,const vector<u16string> & args)1653 int32_t HCameraService::Dump(int fd, const vector<u16string>& args)
1654 {
1655 unordered_set<u16string> argSets;
1656 for (decltype(args.size()) index = 0; index < args.size(); ++index) {
1657 argSets.insert(args[index]);
1658 }
1659 std::string dumpString;
1660 std::vector<std::string> cameraIds;
1661 std::vector<std::shared_ptr<OHOS::Camera::CameraMetadata>> cameraAbilityList;
1662 int ret = GetCameras(cameraIds, cameraAbilityList);
1663 CHECK_ERROR_RETURN_RET((ret != CAMERA_OK) || cameraIds.empty() || cameraAbilityList.empty(), OHOS::UNKNOWN_ERROR);
1664 CameraInfoDumper infoDumper(fd);
1665 if (args.empty() || argSets.count(u16string(u"summary"))) {
1666 DumpCameraSummary(cameraIds, infoDumper);
1667 }
1668 if (args.empty() || argSets.count(u16string(u"ability"))) {
1669 DumpCameraInfo(infoDumper, cameraIds, cameraAbilityList);
1670 }
1671 if (args.empty() || argSets.count(u16string(u"preconfig"))) {
1672 infoDumper.Tip("--------Dump PreconfigInfo Begin-------");
1673 DumpPreconfigInfo(infoDumper, cameraHostManager_);
1674 }
1675 if (args.empty() || argSets.count(u16string(u"clientwiseinfo"))) {
1676 infoDumper.Tip("--------Dump Clientwise Info Begin-------");
1677 HCaptureSession::DumpSessions(infoDumper);
1678 }
1679 if (argSets.count(std::u16string(u"debugOn"))) {
1680 SetCameraDebugValue(true);
1681 }
1682 infoDumper.Print();
1683 return OHOS::NO_ERROR;
1684 }
1685
1686 #ifdef CAMERA_USE_SENSOR
RegisterSensorCallback()1687 void HCameraService::RegisterSensorCallback()
1688 {
1689 if (isRegisterSensorSuccess) {
1690 MEDIA_INFO_LOG("HCameraService::RegisterSensorCallback isRegisterSensorSuccess return");
1691 return;
1692 }
1693 isRegisterSensorSuccess = false;
1694 MEDIA_INFO_LOG("HCameraService::RegisterDropDetectionListener start");
1695 CHECK_ERROR_RETURN_LOG(!OHOS::Rosen::LoadMotionSensor(), "RegisterDropDetectionListener LoadMotionSensor fail");
1696 CHECK_ERROR_RETURN_LOG(!OHOS::Rosen::SubscribeCallback(OHOS::Rosen::MOTION_TYPE_DROP_DETECTION,
1697 DropDetectionDataCallbackImpl), "RegisterDropDetectionListener SubscribeCallback fail");
1698 isRegisterSensorSuccess = true;
1699 }
1700
UnRegisterSensorCallback()1701 void HCameraService::UnRegisterSensorCallback()
1702 {
1703 CHECK_ERROR_RETURN_LOG(!UnsubscribeCallback(OHOS::Rosen::MOTION_TYPE_DROP_DETECTION, DropDetectionDataCallbackImpl),
1704 "UnRegisterDropDetectionListener fail");
1705 OHOS::Rosen::UnloadMotionSensor();
1706 }
1707
DropDetectionDataCallbackImpl(const OHOS::Rosen::MotionSensorEvent & motionData)1708 void HCameraService::DropDetectionDataCallbackImpl(const OHOS::Rosen::MotionSensorEvent &motionData)
1709 {
1710 MEDIA_INFO_LOG("HCameraService::DropDetectionCallback type = %{public}d, status = %{public}d",
1711 motionData.type, motionData.status);
1712 {
1713 std::lock_guard<std::mutex> lock(g_cameraServiceInstanceMutex);
1714 if (GetTimestamp() - g_lastDeviceDropTime < DEVICE_DROP_INTERVAL) {
1715 return;
1716 }
1717 g_cameraServiceInstance->cameraHostManager_->NotifyDeviceStateChangeInfo(
1718 DeviceType::FALLING_TYPE, FallingState::FALLING_STATE);
1719 }
1720 }
1721 #endif
1722
SaveCurrentParamForRestore(std::string cameraId,RestoreParamTypeOhos restoreParamType,int activeTime,EffectParam effectParam,sptr<HCaptureSession> captureSession)1723 int32_t HCameraService::SaveCurrentParamForRestore(std::string cameraId, RestoreParamTypeOhos restoreParamType,
1724 int activeTime, EffectParam effectParam, sptr<HCaptureSession> captureSession)
1725 {
1726 MEDIA_INFO_LOG("HCameraService::SaveCurrentParamForRestore enter");
1727 int32_t rc = CAMERA_OK;
1728 preCameraClient_ = GetClientBundle(IPCSkeleton::GetCallingUid());
1729 sptr<HCameraRestoreParam> cameraRestoreParam = new HCameraRestoreParam(
1730 preCameraClient_, cameraId);
1731 cameraRestoreParam->SetRestoreParamType(restoreParamType);
1732 cameraRestoreParam->SetStartActiveTime(activeTime);
1733 int foldStatus = static_cast<int>(OHOS::Rosen::DisplayManager::GetInstance().GetFoldStatus());
1734 cameraRestoreParam->SetFoldStatus(foldStatus);
1735 if (captureSession == nullptr || restoreParamType == NO_NEED_RESTORE_PARAM_OHOS) {
1736 cameraHostManager_->SaveRestoreParam(cameraRestoreParam);
1737 return rc;
1738 }
1739
1740 sptr<HCameraDeviceManager> deviceManager = HCameraDeviceManager::GetInstance();
1741 pid_t activeClient = deviceManager->GetActiveClient();
1742 CHECK_ERROR_RETURN_RET_LOG(activeClient == -1, CAMERA_OPERATION_NOT_ALLOWED,
1743 "HCaptureSession::SaveCurrentParamForRestore() Failed to save param");
1744 sptr<HCameraDevice> activeDevice = deviceManager->GetCameraByPid(activeClient);
1745 CHECK_AND_RETURN_RET(activeDevice != nullptr, CAMERA_OK);
1746 std::vector<StreamInfo_V1_1> allStreamInfos;
1747
1748 if (activeDevice != nullptr) {
1749 std::shared_ptr<OHOS::Camera::CameraMetadata> defaultSettings = CreateDefaultSettingForRestore(activeDevice);
1750 UpdateSkinSmoothSetting(defaultSettings, effectParam.skinSmoothLevel);
1751 UpdateFaceSlenderSetting(defaultSettings, effectParam.faceSlender);
1752 UpdateSkinToneSetting(defaultSettings, effectParam.skinTone);
1753 cameraRestoreParam->SetSetting(defaultSettings);
1754 }
1755 CHECK_AND_RETURN_RET(activeDevice != nullptr, CAMERA_UNKNOWN_ERROR);
1756 MEDIA_DEBUG_LOG("HCameraService::SaveCurrentParamForRestore param %{public}d", effectParam.skinSmoothLevel);
1757 rc = captureSession->GetCurrentStreamInfos(allStreamInfos);
1758 CHECK_ERROR_RETURN_RET_LOG(rc != CAMERA_OK, rc,
1759 "HCaptureSession::SaveCurrentParamForRestore() Failed to get streams info, %{public}d", rc);
1760 for (auto& info : allStreamInfos) {
1761 MEDIA_INFO_LOG("HCameraService::SaveCurrentParamForRestore: streamId is:%{public}d", info.v1_0.streamId_);
1762 }
1763 cameraRestoreParam->SetStreamInfo(allStreamInfos);
1764 cameraRestoreParam->SetCameraOpMode(captureSession->GetopMode());
1765 cameraHostManager_->SaveRestoreParam(cameraRestoreParam);
1766 MEDIA_INFO_LOG("HCameraService::SaveCurrentParamForRestore end");
1767 return rc;
1768 }
1769
CreateDefaultSettingForRestore(sptr<HCameraDevice> activeDevice)1770 std::shared_ptr<OHOS::Camera::CameraMetadata> HCameraService::CreateDefaultSettingForRestore(
1771 sptr<HCameraDevice> activeDevice)
1772 {
1773 constexpr int32_t DEFAULT_ITEMS = 1;
1774 constexpr int32_t DEFAULT_DATA_LENGTH = 1;
1775 auto defaultSettings = std::make_shared<OHOS::Camera::CameraMetadata>(DEFAULT_ITEMS, DEFAULT_DATA_LENGTH);
1776 float zoomRatio = 1.0f;
1777 int32_t count = 1;
1778 int32_t ret = 0;
1779 camera_metadata_item_t item;
1780 defaultSettings->addEntry(OHOS_CONTROL_ZOOM_RATIO, &zoomRatio, count);
1781 defaultSettings->addEntry(OHOS_CONTROL_TIME_LAPSE_RECORD_STATE, &ret, count);
1782 std::shared_ptr<OHOS::Camera::CameraMetadata> currentSetting = activeDevice->CloneCachedSettings();
1783 CHECK_ERROR_RETURN_RET_LOG(currentSetting == nullptr, defaultSettings,
1784 "HCameraService::CreateDefaultSettingForRestore:currentSetting is null");
1785 ret = OHOS::Camera::FindCameraMetadataItem(currentSetting->get(), OHOS_CONTROL_FPS_RANGES, &item);
1786 if (ret == CAM_META_SUCCESS) {
1787 uint32_t fpscount = item.count;
1788 std::vector<int32_t> fpsRange;
1789 for (uint32_t i = 0; i < fpscount; i++) {
1790 fpsRange.push_back(*(item.data.i32 + i));
1791 }
1792 defaultSettings->addEntry(OHOS_CONTROL_FPS_RANGES, fpsRange.data(), fpscount);
1793 }
1794
1795 ret = OHOS::Camera::FindCameraMetadataItem(currentSetting->get(), OHOS_CAMERA_USER_ID, &item);
1796 if (ret == CAM_META_SUCCESS) {
1797 int32_t userId = item.data.i32[0];
1798 defaultSettings->addEntry(OHOS_CAMERA_USER_ID, &userId, count);
1799 }
1800
1801 uint8_t enableValue = true;
1802 defaultSettings->addEntry(OHOS_CONTROL_VIDEO_DEBUG_SWITCH, &enableValue, 1);
1803
1804 for (uint32_t metadataTag : restoreMetadataTag) { // item.type is uint8
1805 ret = OHOS::Camera::FindCameraMetadataItem(currentSetting->get(), metadataTag, &item);
1806 if (ret == 0 && item.count != 0) {
1807 defaultSettings->addEntry(item.item, item.data.u8, item.count);
1808 }
1809 }
1810 return defaultSettings;
1811 }
1812
UpdateSkinSmoothSetting(std::shared_ptr<OHOS::Camera::CameraMetadata> changedMetadata,int skinSmoothValue)1813 int32_t HCameraService::UpdateSkinSmoothSetting(std::shared_ptr<OHOS::Camera::CameraMetadata> changedMetadata,
1814 int skinSmoothValue)
1815 {
1816 if (skinSmoothValue <= 0 || changedMetadata == nullptr) {
1817 return CAMERA_OK;
1818 }
1819 bool status = false;
1820 int32_t count = 1;
1821 int ret;
1822 camera_metadata_item_t item;
1823
1824 MEDIA_DEBUG_LOG("UpdateBeautySetting skinsmooth: %{public}d", skinSmoothValue);
1825 uint8_t beauty = OHOS_CAMERA_BEAUTY_TYPE_SKIN_SMOOTH;
1826 ret = OHOS::Camera::FindCameraMetadataItem(changedMetadata->get(), OHOS_CONTROL_BEAUTY_TYPE, &item);
1827 if (ret == CAM_META_ITEM_NOT_FOUND) {
1828 status = changedMetadata->addEntry(OHOS_CONTROL_BEAUTY_TYPE, &beauty, count);
1829 } else if (ret == CAM_META_SUCCESS) {
1830 status = changedMetadata->updateEntry(OHOS_CONTROL_BEAUTY_TYPE, &beauty, count);
1831 }
1832
1833 ret = OHOS::Camera::FindCameraMetadataItem(changedMetadata->get(), OHOS_CONTROL_BEAUTY_SKIN_SMOOTH_VALUE, &item);
1834 if (ret == CAM_META_ITEM_NOT_FOUND) {
1835 status = changedMetadata->addEntry(OHOS_CONTROL_BEAUTY_SKIN_SMOOTH_VALUE, &skinSmoothValue, count);
1836 } else if (ret == CAM_META_SUCCESS) {
1837 status = changedMetadata->updateEntry(OHOS_CONTROL_BEAUTY_SKIN_SMOOTH_VALUE, &skinSmoothValue, count);
1838 }
1839 if (status) {
1840 MEDIA_INFO_LOG("UpdateBeautySetting status: %{public}d", status);
1841 }
1842
1843 return CAMERA_OK;
1844 }
1845
UpdateFaceSlenderSetting(std::shared_ptr<OHOS::Camera::CameraMetadata> changedMetadata,int faceSlenderValue)1846 int32_t HCameraService::UpdateFaceSlenderSetting(std::shared_ptr<OHOS::Camera::CameraMetadata> changedMetadata,
1847 int faceSlenderValue)
1848 {
1849 if (faceSlenderValue <= 0 || changedMetadata == nullptr) {
1850 return CAMERA_OK;
1851 }
1852 bool status = false;
1853 int32_t count = 1;
1854 int ret;
1855 camera_metadata_item_t item;
1856
1857 MEDIA_DEBUG_LOG("UpdateBeautySetting faceSlender: %{public}d", faceSlenderValue);
1858 uint8_t beauty = OHOS_CAMERA_BEAUTY_TYPE_FACE_SLENDER;
1859 ret = OHOS::Camera::FindCameraMetadataItem(changedMetadata->get(), OHOS_CONTROL_BEAUTY_TYPE, &item);
1860 if (ret == CAM_META_ITEM_NOT_FOUND) {
1861 status = changedMetadata->addEntry(OHOS_CONTROL_BEAUTY_TYPE, &beauty, count);
1862 } else if (ret == CAM_META_SUCCESS) {
1863 status = changedMetadata->updateEntry(OHOS_CONTROL_BEAUTY_TYPE, &beauty, count);
1864 }
1865
1866 ret = OHOS::Camera::FindCameraMetadataItem(changedMetadata->get(), OHOS_CONTROL_BEAUTY_FACE_SLENDER_VALUE, &item);
1867 if (ret == CAM_META_ITEM_NOT_FOUND) {
1868 status = changedMetadata->addEntry(OHOS_CONTROL_BEAUTY_FACE_SLENDER_VALUE, &faceSlenderValue, count);
1869 } else if (ret == CAM_META_SUCCESS) {
1870 status = changedMetadata->updateEntry(OHOS_CONTROL_BEAUTY_FACE_SLENDER_VALUE, &faceSlenderValue, count);
1871 }
1872 if (status) {
1873 MEDIA_INFO_LOG("UpdateBeautySetting status: %{public}d", status);
1874 }
1875
1876 return CAMERA_OK;
1877 }
1878
UpdateSkinToneSetting(std::shared_ptr<OHOS::Camera::CameraMetadata> changedMetadata,int skinToneValue)1879 int32_t HCameraService::UpdateSkinToneSetting(std::shared_ptr<OHOS::Camera::CameraMetadata> changedMetadata,
1880 int skinToneValue)
1881 {
1882 if (skinToneValue <= 0 || changedMetadata == nullptr) {
1883 return CAMERA_OK;
1884 }
1885 bool status = false;
1886 int32_t count = 1;
1887 int ret;
1888 camera_metadata_item_t item;
1889
1890 MEDIA_DEBUG_LOG("UpdateBeautySetting skinTone: %{public}d", skinToneValue);
1891 uint8_t beauty = OHOS_CAMERA_BEAUTY_TYPE_SKIN_TONE;
1892 ret = OHOS::Camera::FindCameraMetadataItem(changedMetadata->get(), OHOS_CONTROL_BEAUTY_TYPE, &item);
1893 if (ret == CAM_META_ITEM_NOT_FOUND) {
1894 status = changedMetadata->addEntry(OHOS_CONTROL_BEAUTY_TYPE, &beauty, count);
1895 } else if (ret == CAM_META_SUCCESS) {
1896 status = changedMetadata->updateEntry(OHOS_CONTROL_BEAUTY_TYPE, &beauty, count);
1897 }
1898
1899 ret = OHOS::Camera::FindCameraMetadataItem(changedMetadata->get(), OHOS_CONTROL_BEAUTY_SKIN_TONE_VALUE, &item);
1900 if (ret == CAM_META_ITEM_NOT_FOUND) {
1901 status = changedMetadata->addEntry(OHOS_CONTROL_BEAUTY_SKIN_TONE_VALUE, &skinToneValue, count);
1902 } else if (ret == CAM_META_SUCCESS) {
1903 status = changedMetadata->updateEntry(OHOS_CONTROL_BEAUTY_SKIN_TONE_VALUE, &skinToneValue, count);
1904 }
1905 if (status) {
1906 MEDIA_INFO_LOG("UpdateBeautySetting status: %{public}d", status);
1907 }
1908
1909 return CAMERA_OK;
1910 }
1911
g_toString(std::set<int32_t> & pidList)1912 std::string g_toString(std::set<int32_t>& pidList)
1913 {
1914 std::string ret = "[";
1915 for (const auto& pid : pidList) {
1916 ret += std::to_string(pid) + ",";
1917 }
1918 ret += "]";
1919 return ret;
1920 }
1921
ProxyForFreeze(const std::set<int32_t> & pidList,bool isProxy)1922 int32_t HCameraService::ProxyForFreeze(const std::set<int32_t>& pidList, bool isProxy)
1923 {
1924 constexpr int32_t maxSaUid = 10000;
1925 CHECK_ERROR_RETURN_RET_LOG(IPCSkeleton::GetCallingUid() >= maxSaUid, CAMERA_OPERATION_NOT_ALLOWED, "not allow");
1926 MEDIA_INFO_LOG("isProxy value: %{public}d", isProxy);
1927 {
1928 std::lock_guard<std::mutex> lock(freezedPidListMutex_);
1929 if (isProxy) {
1930 freezedPidList_.insert(pidList.begin(), pidList.end());
1931 MEDIA_DEBUG_LOG("after freeze freezedPidList_:%{public}s", g_toString(freezedPidList_).c_str());
1932 return CAMERA_OK;
1933 } else {
1934 for (auto pid : pidList) {
1935 freezedPidList_.erase(pid);
1936 }
1937 MEDIA_DEBUG_LOG("after unfreeze freezedPidList_:%{public}s", g_toString(freezedPidList_).c_str());
1938 }
1939 }
1940
1941 {
1942 std::lock_guard<std::mutex> lock(cameraCbMutex_);
1943 for (auto pid : pidList) {
1944 auto it = delayCbtaskMap.find(pid);
1945 if (it != delayCbtaskMap.end()) {
1946 it->second();
1947 delayCbtaskMap.erase(it);
1948 }
1949 }
1950 }
1951 return CAMERA_OK;
1952 }
1953
ResetAllFreezeStatus()1954 int32_t HCameraService::ResetAllFreezeStatus()
1955 {
1956 if (IPCSkeleton::GetCallingUid() != 0) {
1957 return CAMERA_OPERATION_NOT_ALLOWED;
1958 }
1959 std::lock_guard<std::mutex> lock(freezedPidListMutex_);
1960 freezedPidList_.clear();
1961 MEDIA_INFO_LOG("freezedPidList_ has been clear");
1962 return CAMERA_OK;
1963 }
1964
GetDmDeviceInfo(std::vector<std::string> & deviceInfos)1965 int32_t HCameraService::GetDmDeviceInfo(std::vector<std::string> &deviceInfos)
1966 {
1967 #ifdef DEVICE_MANAGER
1968 lock_guard<mutex> lock(g_dmDeviceInfoMutex);
1969 std::vector <DistributedHardware::DmDeviceInfo> deviceInfoList;
1970 auto &deviceManager = DistributedHardware::DeviceManager::GetInstance();
1971 std::shared_ptr<DistributedHardware::DmInitCallback> initCallback = std::make_shared<DeviceInitCallBack>();
1972 std::string pkgName = std::to_string(IPCSkeleton::GetCallingTokenID());
1973 const string extraInfo = "";
1974 deviceManager.InitDeviceManager(pkgName, initCallback);
1975 deviceManager.RegisterDevStateCallback(pkgName, extraInfo, NULL);
1976 deviceManager.GetTrustedDeviceList(pkgName, extraInfo, deviceInfoList);
1977 deviceManager.UnInitDeviceManager(pkgName);
1978 int size = static_cast<int>(deviceInfoList.size());
1979 MEDIA_INFO_LOG("HCameraService::GetDmDeviceInfo size=%{public}d", size);
1980 if (size > 0) {
1981 for (int i = 0; i < size; i++) {
1982 nlohmann::json deviceInfo;
1983 deviceInfo["deviceName"] = deviceInfoList[i].deviceName;
1984 deviceInfo["deviceTypeId"] = deviceInfoList[i].deviceTypeId;
1985 deviceInfo["networkId"] = deviceInfoList[i].networkId;
1986 std::string deviceInfoStr = deviceInfo.dump();
1987 MEDIA_INFO_LOG("HCameraService::GetDmDeviceInfo deviceInfo:%{public}s", deviceInfoStr.c_str());
1988 deviceInfos.emplace_back(deviceInfoStr);
1989 }
1990 }
1991 #endif
1992 return CAMERA_OK;
1993 }
1994
GetCameraOutputStatus(int32_t pid,int32_t & status)1995 int32_t HCameraService::GetCameraOutputStatus(int32_t pid, int32_t &status)
1996 {
1997 sptr<HCaptureSession> captureSession = nullptr;
1998 captureSessionsManager_.Find(pid, captureSession);
1999 if (captureSession) {
2000 captureSession->GetOutputStatus(status);
2001 } else {
2002 status = 0;
2003 }
2004 return CAMERA_OK;
2005 }
2006
RequireMemorySize(int32_t requiredMemSizeKB)2007 int32_t HCameraService::RequireMemorySize(int32_t requiredMemSizeKB)
2008 {
2009 #ifdef MEMMGR_OVERRID
2010 int32_t pid = getpid();
2011 const std::string reason = "HW_CAMERA_TO_PHOTO";
2012 std::string clientName = SYSTEM_CAMERA;
2013 int32_t ret = Memory::MemMgrClient::GetInstance().RequireBigMem(pid, reason, requiredMemSizeKB, clientName);
2014 MEDIA_INFO_LOG("HCameraDevice::RequireMemory reason:%{public}s, clientName:%{public}s, ret:%{public}d",
2015 reason.c_str(), clientName.c_str(), ret);
2016 if (ret == 0) {
2017 return CAMERA_OK;
2018 }
2019 #endif
2020 return CAMERA_UNKNOWN_ERROR;
2021 }
2022
SetDeviceRetryTime()2023 int32_t HCameraService::SetDeviceRetryTime()
2024 {
2025 g_lastDeviceDropTime = GetTimestamp();
2026 return CAMERA_OK;
2027 }
2028 } // namespace CameraStandard
2029 } // namespace OHOS
2030