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 <cstdint>
25 #include <string>
26 #include <unordered_set>
27 #include <utility>
28 #include <vector>
29
30 #include "anonymization.h"
31 #include "ability/camera_ability_const.h"
32 #include "access_token.h"
33 #include "bms_adapter.h"
34 #include "icapture_session_callback.h"
35 #include "session/capture_scene_const.h"
36 #ifdef NOTIFICATION_ENABLE
37 #include "camera_beauty_notification.h"
38 #endif
39 #include "camera_info_dumper.h"
40 #include "camera_log.h"
41 #include "camera_report_uitls.h"
42 #include "camera_util.h"
43 #include "camera_common_event_manager.h"
44 #include "datashare_predicates.h"
45 #include "deferred_processing_service.h"
46 #include "hcamera_preconfig.h"
47 #include "hcamera_session_manager.h"
48 #include "icamera_service_callback.h"
49 #ifdef DEVICE_MANAGER
50 #include "device_manager.h"
51 #endif
52 #include "hcamera_device_manager.h"
53 #include "hstream_operator_manager.h"
54 #include "ipc_skeleton.h"
55 #include "iservice_registry.h"
56 #include "os_account_manager.h"
57 #include "system_ability_definition.h"
58 #include "tokenid_kit.h"
59 #include "uri.h"
60 #ifdef MEMMGR_OVERRID
61 #include "mem_mgr_client.h"
62 #include "mem_mgr_constant.h"
63 #endif
64 #include "camera_rotate_param_manager.h"
65 #include "camera_xcollie.h"
66 #include "res_type.h"
67 #include "res_sched_client.h"
68 #ifdef HOOK_CAMERA_OPERATOR
69 #include "camera_rotate_plugin.h"
70 #endif
71 #include "camera_metadata.h"
72
73 namespace OHOS {
74 namespace CameraStandard {
75 REGISTER_SYSTEM_ABILITY_BY_ID(HCameraService, CAMERA_SERVICE_ID, true)
76 constexpr uint8_t POSITION_FOLD_INNER = 3;
77 constexpr uint32_t ROOT_UID = 0;
78 constexpr uint32_t FACE_CLIENT_UID = 1088;
79 constexpr uint32_t RSS_UID = 1096;
80 #ifdef MEMMGR_OVERRID
81 constexpr int32_t OLD_LAUNCH = -1;
82 constexpr int32_t TOUCH_DOWN = 0;
83 constexpr int32_t TOUCH_UP = 1;
84 constexpr int32_t TOUCH_CANCEL = 2;
85 #endif
86 static sptr<HCameraService> g_cameraServiceHolder = nullptr;
87 static bool g_isFoldScreen = system::GetParameter("const.window.foldscreen.type", "") != "";
88
89 std::vector<uint32_t> restoreMetadataTag { // item.type is uint8
90 OHOS_CONTROL_VIDEO_STABILIZATION_MODE,
91 OHOS_CONTROL_DEFERRED_IMAGE_DELIVERY,
92 OHOS_CONTROL_SUPPORTED_COLOR_MODES,
93 OHOS_CONTROL_PORTRAIT_EFFECT_TYPE,
94 OHOS_CONTROL_FILTER_TYPE,
95 OHOS_CONTROL_EFFECT_SUGGESTION,
96 OHOS_CONTROL_MOTION_DETECTION,
97 OHOS_CONTROL_HIGH_QUALITY_MODE,
98 OHOS_CONTROL_CAMERA_USED_AS_POSITION,
99 OHOS_CONTROL_MOVING_PHOTO,
100 OHOS_CONTROL_AUTO_CLOUD_IMAGE_ENHANCE,
101 OHOS_CONTROL_BEAUTY_TYPE,
102 OHOS_CONTROL_BEAUTY_AUTO_VALUE,
103 OHOS_CONTROL_FOCUS_DRIVEN_TYPE,
104 OHOS_CONTROL_COLOR_RESERVATION_TYPE,
105 OHOS_CONTROL_FOCUS_RANGE_TYPE,
106 OHOS_CONTROL_CAMERA_VIRTUAL_APERTURE_VALUE,
107 };
108 mutex g_dataShareHelperMutex;
109 mutex g_dmDeviceInfoMutex;
110 thread_local uint32_t g_dumpDepth = 0;
111
HCameraService(int32_t systemAbilityId,bool runOnCreate)112 HCameraService::HCameraService(int32_t systemAbilityId, bool runOnCreate)
113 : SystemAbility(systemAbilityId, runOnCreate), muteModeStored_(false), pressurePid_(0)
114 {
115 MEDIA_INFO_LOG("HCameraService Construct begin");
116 g_cameraServiceHolder = this;
117 statusCallback_ = std::make_shared<ServiceHostStatus>(this);
118 cameraHostManager_ = new (std::nothrow) HCameraHostManager(statusCallback_);
119 CHECK_RETURN_ELOG(
120 cameraHostManager_ == nullptr, "HCameraService OnStart failed to create HCameraHostManager obj");
121 MEDIA_INFO_LOG("HCameraService Construct end");
122 serviceStatus_ = CameraServiceStatus::SERVICE_NOT_READY;
123 pressurePid_ = 0;
124 }
125
HCameraService(sptr<HCameraHostManager> cameraHostManager)126 HCameraService::HCameraService(sptr<HCameraHostManager> cameraHostManager)
127 : cameraHostManager_(cameraHostManager), muteModeStored_(false)
128 {}
129
~HCameraService()130 HCameraService::~HCameraService() {}
131
132 #ifdef DEVICE_MANAGER
133 class HCameraService::DeviceInitCallBack : public DistributedHardware::DmInitCallback {
134 void OnRemoteDied() override;
135 };
136
OnRemoteDied()137 void HCameraService::DeviceInitCallBack::OnRemoteDied()
138 {
139 MEDIA_INFO_LOG("CameraManager::DeviceInitCallBack OnRemoteDied");
140 }
141 #endif
142
OnStart()143 void HCameraService::OnStart()
144 {
145 MEDIA_INFO_LOG("HCameraService OnStart begin");
146 CHECK_PRINT_ELOG(cameraHostManager_->Init() != CAMERA_OK,
147 "HCameraService OnStart failed to init camera host manager.");
148 // initialize deferred processing service.
149 DeferredProcessing::DeferredProcessingService::GetInstance().Initialize();
150 cameraDataShareHelper_ = std::make_shared<CameraDataShareHelper>();
151 AddSystemAbilityListener(DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID);
152 #ifdef NOTIFICATION_ENABLE
153 AddSystemAbilityListener(COMMON_EVENT_SERVICE_ID);
154 #endif
155 if (Publish(this)) {
156 MEDIA_INFO_LOG("HCameraService publish OnStart sucess");
157 } else {
158 MEDIA_INFO_LOG("HCameraService publish OnStart failed");
159 }
160 CameraRoateParamManager::GetInstance().InitParam(); // 先初始化再监听
161 CameraRoateParamManager::GetInstance().SubscriberEvent();
162 MEDIA_INFO_LOG("HCameraService OnStart end");
163 }
164
OnDump()165 void HCameraService::OnDump()
166 {
167 MEDIA_INFO_LOG("HCameraService::OnDump called");
168 }
169
OnStop()170 void HCameraService::OnStop()
171 {
172 MEDIA_INFO_LOG("HCameraService::OnStop called");
173 cameraHostManager_->DeInit();
174 UnregisterFoldStatusListener();
175 }
176
GetMuteModeFromDataShareHelper(bool & muteMode)177 int32_t HCameraService::GetMuteModeFromDataShareHelper(bool &muteMode)
178 {
179 lock_guard<mutex> lock(g_dataShareHelperMutex);
180 CHECK_RETURN_RET_ELOG(cameraDataShareHelper_ == nullptr, CAMERA_INVALID_ARG,
181 "GetMuteModeFromDataShareHelper NULL");
182 std::string value = "";
183 auto ret = cameraDataShareHelper_->QueryOnce(PREDICATES_STRING, value);
184 MEDIA_INFO_LOG("GetMuteModeFromDataShareHelper Query ret = %{public}d, value = %{public}s", ret, value.c_str());
185 CHECK_RETURN_RET_ELOG(ret != CAMERA_OK, CAMERA_INVALID_ARG, "GetMuteModeFromDataShareHelper QueryOnce fail.");
186 value = (value == "0" || value == "1") ? value : "0";
187 int32_t muteModeVal = std::stoi(value);
188 CHECK_RETURN_RET_ELOG(muteModeVal != 0 && muteModeVal != 1, CAMERA_INVALID_ARG,
189 "GetMuteModeFromDataShareHelper Query MuteMode invald, value = %{public}d", muteModeVal);
190 muteMode = (muteModeVal == 1) ? true: false;
191 this->muteModeStored_ = muteMode;
192 return CAMERA_OK;
193 }
194
SetMuteModeFromDataShareHelper()195 bool HCameraService::SetMuteModeFromDataShareHelper()
196 {
197 CHECK_RETURN_RET(GetServiceStatus() == CameraServiceStatus::SERVICE_READY, true);
198 this->SetServiceStatus(CameraServiceStatus::SERVICE_READY);
199 bool muteMode = false;
200 int32_t ret = GetMuteModeFromDataShareHelper(muteMode);
201 CHECK_RETURN_RET_ELOG((ret != CAMERA_OK), false, "GetMuteModeFromDataShareHelper failed");
202 MuteCameraFunc(muteMode);
203 muteModeStored_ = muteMode;
204 MEDIA_INFO_LOG("SetMuteModeFromDataShareHelper Success, muteMode = %{public}d", muteMode);
205 return true;
206 }
207
OnReceiveEvent(const EventFwk::CommonEventData & data)208 void HCameraService::OnReceiveEvent(const EventFwk::CommonEventData &data)
209 {
210 auto const &want = data.GetWant();
211 std::string action = want.GetAction();
212 if (action == COMMON_EVENT_DATA_SHARE_READY) {
213 MEDIA_INFO_LOG("on receive datashare ready.");
214 SetMuteModeFromDataShareHelper();
215 }
216 #ifdef NOTIFICATION_ENABLE
217 if (action == EVENT_CAMERA_BEAUTY_NOTIFICATION) {
218 MEDIA_INFO_LOG("on receive camera beauty.");
219 OHOS::AAFwk::WantParams wantParams = data.GetWant().GetParams();
220 int32_t currentFlag = wantParams.GetIntParam(BEAUTY_NOTIFICATION_ACTION_PARAM, -1);
221 MEDIA_INFO_LOG("currentFlag: %{public}d", currentFlag);
222 int32_t beautyStatus = currentFlag == BEAUTY_STATUS_OFF ? BEAUTY_STATUS_ON : BEAUTY_STATUS_OFF;
223 CameraBeautyNotification::GetInstance()->SetBeautyStatusFromDataShareHelper(beautyStatus);
224 SetBeauty(beautyStatus);
225 CameraBeautyNotification::GetInstance()->SetBeautyStatus(beautyStatus);
226 CameraBeautyNotification::GetInstance()->PublishNotification(false);
227 }
228 #endif
229 if (action == COMMON_EVENT_SCREEN_LOCKED) {
230 MEDIA_DEBUG_LOG("on receive usual.event.SCREEN_LOCKED.");
231 CameraCommonEventManager::GetInstance()->SetScreenLocked(true);
232 }
233 if (action == COMMON_EVENT_SCREEN_UNLOCKED) {
234 MEDIA_DEBUG_LOG("on receive usual.event.SCREEN_UNLOCKED.");
235 CameraCommonEventManager::GetInstance()->SetScreenLocked(false);
236 }
237 if (action == COMMON_EVENT_RSS_MULTI_WINDOW_TYPE) {
238 MEDIA_DEBUG_LOG("on receive common.event.ressched.window.state.");
239 int32_t rssMultiWindowStatus = data.GetCode();
240 MEDIA_DEBUG_LOG("HCameraService::OnReceiveEvent rssMultiWindowStatus is %{public}d", rssMultiWindowStatus);
241 cameraHostManager_->NotifyDeviceStateChangeInfo(DeviceType::RSS_MULTI_WINDOW_TYPE, rssMultiWindowStatus);
242 }
243 if (action == EventFwk::CommonEventSupport::COMMON_EVENT_THERMAL_LEVEL_CHANGED) {
244 int32_t temperLevel = data.GetWant().GetIntParam("0", -1);
245 MEDIA_INFO_LOG("On receive thermal %{public}d ", temperLevel);
246
247 sptr<HCaptureSession> captureSession_ = nullptr;
248 auto &sessionManager = HCameraSessionManager::GetInstance();
249 captureSession_ = sessionManager.GetGroupDefaultSession(pressurePid_);
250 CHECK_RETURN_ELOG(captureSession_ == nullptr, "captureSession is null");
251 captureSession_->SetPressureStatus(TransferTemperToPressure(temperLevel));
252 }
253 }
254
TransferTemperToPressure(int32_t temperLevel)255 PressureStatus HCameraService::TransferTemperToPressure(int32_t temperLevel)
256 {
257 switch (temperLevel) {
258 case TEMPER_PRESSURE_COOL:
259 case TEMPER_PRESSURE_NORMAL:
260 return PressureStatus::SYSTEM_PRESSURE_NORMAL;
261 case TEMPER_PRESSURE_WARM:
262 return PressureStatus::SYSTEM_PRESSURE_MILD;
263 case TEMPER_PRESSURE_HOT:
264 case TEMPER_PRESSURE_OVERHEATED:
265 return PressureStatus::SYSTEM_PRESSURE_SEVERE;
266 case TEMPER_PRESSURE_WARNING:
267 case TEMPER_PRESSURE_EMERGENCY:
268 return PressureStatus::SYSTEM_PRESSURE_CRITICAL;
269 case TEMPER_PRESSURE_ESCAPE:
270 return PressureStatus::SYSTEM_PRESSURE_SHUTDOWN;
271 }
272 return PressureStatus::SYSTEM_PRESSURE_NORMAL;
273 }
274
275 #ifdef NOTIFICATION_ENABLE
SetBeauty(int32_t beautyStatus)276 int32_t HCameraService::SetBeauty(int32_t beautyStatus)
277 {
278 constexpr int32_t DEFAULT_ITEMS = 1;
279 constexpr int32_t DEFAULT_DATA_LENGTH = 1;
280 shared_ptr<OHOS::Camera::CameraMetadata> changedMetadata =
281 make_shared<OHOS::Camera::CameraMetadata>(DEFAULT_ITEMS, DEFAULT_DATA_LENGTH);
282 int32_t count = 1;
283 uint8_t beautyLevel = 0;
284 uint8_t beautyType = OHOS_CAMERA_BEAUTY_TYPE_OFF;
285 if (beautyStatus == BEAUTY_STATUS_ON) {
286 beautyLevel = BEAUTY_LEVEL;
287 beautyType = OHOS_CAMERA_BEAUTY_TYPE_AUTO;
288 }
289 MEDIA_INFO_LOG("HCameraService::SetBeauty beautyType: %{public}d, beautyLevel: %{public}d",
290 beautyType, beautyLevel);
291 AddOrUpdateMetadata(changedMetadata, OHOS_CONTROL_BEAUTY_TYPE, &beautyType, count);
292 AddOrUpdateMetadata(changedMetadata, OHOS_CONTROL_BEAUTY_AUTO_VALUE, &beautyLevel, count);
293 sptr<HCameraDeviceManager> deviceManager = HCameraDeviceManager::GetInstance();
294 std::vector<sptr<HCameraDeviceHolder>> deviceHolderVector = deviceManager->GetActiveCameraHolders();
295 for (sptr<HCameraDeviceHolder> activeDeviceHolder : deviceHolderVector) {
296 sptr<HCameraDevice> activeDevice = activeDeviceHolder->GetDevice();
297 if (activeDevice != nullptr && activeDevice->IsOpenedCameraDevice()) {
298 activeDevice->UpdateSetting(changedMetadata);
299 MEDIA_INFO_LOG("HCameraService::SetBeauty UpdateSetting");
300 }
301 }
302 return CAMERA_OK;
303 }
304 #endif
305
SetMuteModeByDataShareHelper(bool muteMode)306 int32_t HCameraService::SetMuteModeByDataShareHelper(bool muteMode)
307 {
308 MEDIA_INFO_LOG("SetMuteModeByDataShareHelper enter.");
309 lock_guard<mutex> lock(g_dataShareHelperMutex);
310 CHECK_RETURN_RET_ELOG(cameraDataShareHelper_ == nullptr, CAMERA_ALLOC_ERROR,
311 "GetMuteModeFromDataShareHelper NULL");
312 std::string unMuteModeStr = "0";
313 std::string muteModeStr = "1";
314 std::string value = muteMode? muteModeStr : unMuteModeStr;
315 auto ret = cameraDataShareHelper_->UpdateOnce(PREDICATES_STRING, value);
316 CHECK_RETURN_RET_ELOG(ret != CAMERA_OK, CAMERA_ALLOC_ERROR, "SetMuteModeByDataShareHelper UpdateOnce fail.");
317 return CAMERA_OK;
318 }
319
GetControlCenterStatusFromDataShareHelper(bool & status)320 int32_t HCameraService::GetControlCenterStatusFromDataShareHelper(bool &status)
321 {
322 MEDIA_INFO_LOG("HCameraService::GetControlCenterStatusFromDataShareHelper");
323 lock_guard<mutex> lock(g_dataShareHelperMutex);
324 CHECK_RETURN_RET_ELOG(cameraDataShareHelper_ == nullptr, CAMERA_INVALID_ARG,
325 "GetControlCenterStatusFromDataShareHelper NULL");
326
327 std::string value = "";
328 auto ret = cameraDataShareHelper_->QueryOnce(CONTROL_CENTER_DATA, value);
329 MEDIA_INFO_LOG("GetControlCenterStatusFromDataShareHelper Query ret = %{public}d, value = %{public}s",
330 ret, value.c_str());
331 if (ret != CAMERA_OK) {
332 status = false;
333 isControlCenterEnabled_ = false;
334 return CAMERA_OK;
335 }
336
337 std::string bundleName = videoSessionForControlCenter_->GetBundleForControlCenter();
338 std::map<std::string, std::array<float, CONTROL_CENTER_DATA_SIZE>> controlCenterMap
339 = StringToControlCenterMap(value);
340 if (controlCenterMap.find(bundleName) != controlCenterMap.end()) {
341 if (controlCenterMap[bundleName].size() >= CONTROL_CENTER_DATA_SIZE) {
342 int32_t statusVal = static_cast<int32_t>(controlCenterMap[bundleName][CONTROL_CENTER_STATUS_INDEX]);
343 MEDIA_INFO_LOG("GetControlCenterStatusFromDataShareHelper success value: %{public}d", statusVal);
344 status = (statusVal == 1) ? true: false;
345 }
346 } else {
347 MEDIA_ERR_LOG("GetControlCenterStatusFromDataShareHelper failed, no bundle.");
348 status = false;
349 return CAMERA_OK;
350 }
351 isControlCenterEnabled_ = status;
352 return CAMERA_OK;
353 }
354
UpdateControlCenterStatus(bool isStart)355 void HCameraService::UpdateControlCenterStatus(bool isStart)
356 {
357 bool controlCenterStatus = false;
358 CHECK_EXECUTE(isStart, GetControlCenterStatusFromDataShareHelper(controlCenterStatus));
359 MEDIA_INFO_LOG("HCameraService::UpdateControlCenterStatus, isStart: %{public}d, status: %{public}d",
360 isStart, controlCenterStatus);
361 EnableControlCenter(controlCenterStatus, false);
362 }
363
UpdateDataShareAndTag(bool status,bool needPersistEnable)364 int32_t HCameraService::UpdateDataShareAndTag(bool status, bool needPersistEnable)
365 {
366 MEDIA_INFO_LOG("HCameraService::UpdateDataShareAndTag");
367 lock_guard<mutex> lock(g_dataShareHelperMutex);
368 CHECK_RETURN_RET_ELOG(cameraDataShareHelper_ == nullptr, CAMERA_ALLOC_ERROR,
369 "GetMuteModeFromDataShareHelper NULL");
370
371 std::string bundleName = videoSessionForControlCenter_->GetBundleForControlCenter();
372 std::map<std::string, std::array<float, CONTROL_CENTER_DATA_SIZE>> controlCenterMap;
373 std::string value = "";
374 auto ret = cameraDataShareHelper_->QueryOnce(CONTROL_CENTER_DATA, value);
375 MEDIA_INFO_LOG("UpdateDataShareAndTag Query ret = %{public}d, value = %{public}s", ret, value.c_str());
376 if (ret != CAMERA_OK) {
377 CreateControlCenterDataShare(controlCenterMap, bundleName, status);
378 return ret;
379 }
380 controlCenterMap = StringToControlCenterMap(value);
381 if (controlCenterMap.find(bundleName) != controlCenterMap.end()) {
382 CHECK_RETURN_RET_ELOG(controlCenterMap[bundleName].size() < CONTROL_CENTER_DATA_SIZE, CAMERA_INVALID_ARG,
383 "Parse string failed.");
384 controlCenterMap[bundleName][CONTROL_CENTER_STATUS_INDEX] = status;
385 std::string controlCenterString = ControlCenterMapToString(controlCenterMap);
386 if (needPersistEnable) {
387 ret = cameraDataShareHelper_->UpdateOnce(CONTROL_CENTER_DATA, controlCenterString);
388 MEDIA_INFO_LOG("UpdateDataShareAndTag ret: %{public}d", ret);
389 }
390 if (status) {
391 videoSessionForControlCenter_->SetBeautyValue(
392 BeautyType::AUTO_TYPE, controlCenterMap[bundleName][CONTROL_CENTER_BEAUTY_INDEX], false);
393 videoSessionForControlCenter_->SetVirtualApertureValue(
394 controlCenterMap[bundleName][CONTROL_CENTER_APERTURE_INDEX], false);
395 } else if (needPersistEnable) {
396 videoSessionForControlCenter_->SetBeautyValue(BeautyType::AUTO_TYPE, 0, false);
397 videoSessionForControlCenter_->SetVirtualApertureValue(0, false);
398 }
399 } else {
400 MEDIA_INFO_LOG("UpdateDataShareAndTag no bundle, create info for new bundle.");
401 CreateControlCenterDataShare(controlCenterMap, bundleName, status);
402 }
403 return ret;
404 }
405
CreateControlCenterDataShare(std::map<std::string,std::array<float,CONTROL_CENTER_DATA_SIZE>> controlCenterMap,std::string bundleName,bool status)406 int32_t HCameraService::CreateControlCenterDataShare(std::map<std::string,
407 std::array<float, CONTROL_CENTER_DATA_SIZE>> controlCenterMap, std::string bundleName, bool status)
408 {
409 std::vector<float> virtualMetadata = {};
410 videoSessionForControlCenter_->GetVirtualApertureMetadate(virtualMetadata);
411 float biggestAperture = 0;
412 CHECK_EXECUTE(virtualMetadata.size() > 0, biggestAperture = virtualMetadata.back());
413
414 controlCenterMap[bundleName] = {status, 0, biggestAperture};
415 std::string controlCenterString = ControlCenterMapToString(controlCenterMap);
416 auto ret = cameraDataShareHelper_->UpdateOnce(CONTROL_CENTER_DATA, controlCenterString);
417 CHECK_RETURN_RET_ELOG(ret != CAMERA_OK, ret, "CreateControlCenterDataShare failed.");
418
419 videoSessionForControlCenter_->SetBeautyValue(BeautyType::AUTO_TYPE, 0, false);
420 if (status) {
421 videoSessionForControlCenter_->SetVirtualApertureValue(biggestAperture, false);
422 } else {
423 videoSessionForControlCenter_->SetVirtualApertureValue(0, false);
424 }
425 return ret;
426 }
427
OnAddSystemAbility(int32_t systemAbilityId,const std::string & deviceId)428 void HCameraService::OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId)
429 {
430 MEDIA_INFO_LOG("OnAddSystemAbility systemAbilityId:%{public}d", systemAbilityId);
431 switch (systemAbilityId) {
432 case DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID:
433 MEDIA_INFO_LOG("OnAddSystemAbility RegisterObserver start");
434 CameraCommonEventManager::GetInstance()->SubscribeCommonEvent(COMMON_EVENT_DATA_SHARE_READY,
435 std::bind(&HCameraService::OnReceiveEvent, this, std::placeholders::_1));
436 CHECK_EXECUTE(cameraDataShareHelper_->IsDataShareReady(), SetMuteModeFromDataShareHelper());
437 break;
438 case COMMON_EVENT_SERVICE_ID:
439 MEDIA_INFO_LOG("OnAddSystemAbility COMMON_EVENT_SERVICE");
440 #ifdef NOTIFICATION_ENABLE
441 CameraCommonEventManager::GetInstance()->SubscribeCommonEvent(EVENT_CAMERA_BEAUTY_NOTIFICATION,
442 std::bind(&HCameraService::OnReceiveEvent, this, std::placeholders::_1));
443 #endif
444 CameraCommonEventManager::GetInstance()->SubscribeCommonEvent(COMMON_EVENT_SCREEN_LOCKED,
445 std::bind(&HCameraService::OnReceiveEvent, this, std::placeholders::_1));
446 CameraCommonEventManager::GetInstance()->SubscribeCommonEvent(COMMON_EVENT_SCREEN_UNLOCKED,
447 std::bind(&HCameraService::OnReceiveEvent, this, std::placeholders::_1));
448 CameraCommonEventManager::GetInstance()->SubscribeCommonEvent(
449 EventFwk::CommonEventSupport::COMMON_EVENT_THERMAL_LEVEL_CHANGED,
450 std::bind(&HCameraService::OnReceiveEvent, this, std::placeholders::_1));
451 CameraCommonEventManager::GetInstance()->SubscribeCommonEvent(COMMON_EVENT_RSS_MULTI_WINDOW_TYPE,
452 std::bind(&HCameraService::OnReceiveEvent, this, std::placeholders::_1));
453 break;
454
455 default:
456 MEDIA_INFO_LOG("OnAddSystemAbility unhandled sysabilityId:%{public}d", systemAbilityId);
457 break;
458 }
459 MEDIA_INFO_LOG("OnAddSystemAbility done");
460 }
461
OnRemoveSystemAbility(int32_t systemAbilityId,const std::string & deviceId)462 void HCameraService::OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId)
463 {
464 MEDIA_DEBUG_LOG("HCameraService::OnRemoveSystemAbility systemAbilityId:%{public}d removed", systemAbilityId);
465 switch (systemAbilityId) {
466 case DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID:
467 CameraCommonEventManager::GetInstance()->UnSubscribeCommonEvent(COMMON_EVENT_DATA_SHARE_READY);
468 break;
469 default:
470 break;
471 }
472 MEDIA_DEBUG_LOG("HCameraService::OnRemoveSystemAbility done");
473 }
474
GetCameras(vector<string> & cameraIds,vector<shared_ptr<OHOS::Camera::CameraMetadata>> & cameraAbilityList)475 int32_t HCameraService::GetCameras(
476 vector<string>& cameraIds, vector<shared_ptr<OHOS::Camera::CameraMetadata>>& cameraAbilityList)
477 {
478 CAMERA_SYNC_TRACE;
479 isFoldable = isFoldableInit ? isFoldable : g_isFoldScreen;
480 isFoldableInit = true;
481 int32_t ret = cameraHostManager_->GetCameras(cameraIds);
482 CHECK_RETURN_RET_ELOG(ret != CAMERA_OK, ret, "HCameraService::GetCameras failed");
483 shared_ptr<OHOS::Camera::CameraMetadata> cameraAbility;
484 vector<shared_ptr<CameraMetaInfo>> cameraInfos;
485 for (auto id : cameraIds) {
486 ret = cameraHostManager_->GetCameraAbility(id, cameraAbility);
487 CHECK_RETURN_RET_ELOG(ret != CAMERA_OK || cameraAbility == nullptr, ret,
488 "HCameraService::GetCameraAbility failed");
489 auto cameraMetaInfo = GetCameraMetaInfo(id, cameraAbility);
490 if (cameraMetaInfo == nullptr) {
491 continue;
492 }
493 cameraInfos.emplace_back(cameraMetaInfo);
494 }
495 FillCameras(cameraInfos, cameraIds, cameraAbilityList);
496 return ret;
497 }
498
GetCameraMetaInfo(std::string & cameraId,shared_ptr<OHOS::Camera::CameraMetadata> cameraAbility)499 shared_ptr<CameraMetaInfo>HCameraService::GetCameraMetaInfo(std::string &cameraId,
500 shared_ptr<OHOS::Camera::CameraMetadata>cameraAbility)
501 {
502 camera_metadata_item_t item;
503 common_metadata_header_t* metadata = cameraAbility->get();
504 int32_t res = OHOS::Camera::FindCameraMetadataItem(metadata, OHOS_ABILITY_CAMERA_POSITION, &item);
505 uint8_t cameraPosition = (res == CAM_META_SUCCESS && item.count) ? item.data.u8[0] : OHOS_CAMERA_POSITION_OTHER;
506 res = OHOS::Camera::FindCameraMetadataItem(metadata, OHOS_ABILITY_CAMERA_FOLDSCREEN_TYPE, &item);
507 uint8_t foldType = (res == CAM_META_SUCCESS) ? item.data.u8[0] : OHOS_CAMERA_FOLDSCREEN_OTHER;
508 if (isFoldable && cameraPosition == OHOS_CAMERA_POSITION_FRONT && foldType == OHOS_CAMERA_FOLDSCREEN_OTHER &&
509 system::GetParameter("const.window.foldscreen.type", "")[0] == '1') {
510 return nullptr;
511 }
512 if (isFoldable && cameraPosition == OHOS_CAMERA_POSITION_FRONT && foldType == OHOS_CAMERA_FOLDSCREEN_INNER) {
513 cameraPosition = POSITION_FOLD_INNER;
514 }
515 res = OHOS::Camera::FindCameraMetadataItem(metadata, OHOS_ABILITY_CAMERA_TYPE, &item);
516 uint8_t cameraType = (res == CAM_META_SUCCESS && item.count) ? item.data.u8[0] : OHOS_CAMERA_TYPE_UNSPECIFIED;
517 res = OHOS::Camera::FindCameraMetadataItem(metadata, OHOS_ABILITY_CAMERA_CONNECTION_TYPE, &item);
518 uint8_t connectionType =
519 (res == CAM_META_SUCCESS && item.count) ? item.data.u8[0] : OHOS_CAMERA_CONNECTION_TYPE_BUILTIN;
520 res = OHOS::Camera::FindCameraMetadataItem(metadata, OHOS_CONTROL_CAPTURE_MIRROR_SUPPORTED, &item);
521 bool isMirrorSupported = res == CAM_META_SUCCESS && item.count;
522 res = OHOS::Camera::FindCameraMetadataItem(metadata, OHOS_ABILITY_CAMERA_FOLD_STATUS, &item);
523 uint8_t foldStatus =
524 (res == CAM_META_SUCCESS && item.count) ? item.data.u8[0] : OHOS_CAMERA_FOLD_STATUS_NONFOLDABLE;
525 res = OHOS::Camera::FindCameraMetadataItem(metadata, OHOS_ABILITY_CAMERA_MODES, &item);
526 std::vector<uint8_t> supportModes = {};
527 for (uint32_t i = 0; i < item.count; i++) {
528 supportModes.push_back(item.data.u8[i]);
529 }
530 CAMERA_SYSEVENT_STATISTIC(CreateMsg("CameraManager GetCameras camera ID:%s, Camera position:%d, "
531 "Camera Type:%d, Connection Type:%d, Mirror support:%d, Fold status %d",
532 cameraId.c_str(), cameraPosition, cameraType, connectionType, isMirrorSupported, foldStatus));
533 return make_shared<CameraMetaInfo>(cameraId, cameraType, cameraPosition, connectionType,
534 foldStatus, supportModes, cameraAbility);
535 }
536
FillCameras(vector<shared_ptr<CameraMetaInfo>> & cameraInfos,vector<string> & cameraIds,vector<shared_ptr<OHOS::Camera::CameraMetadata>> & cameraAbilityList)537 void HCameraService::FillCameras(vector<shared_ptr<CameraMetaInfo>>& cameraInfos,
538 vector<string>& cameraIds, vector<shared_ptr<OHOS::Camera::CameraMetadata>>& cameraAbilityList)
539 {
540 vector<shared_ptr<CameraMetaInfo>> choosedCameras = ChooseDeFaultCameras(cameraInfos);
541 cameraIds.clear();
542 cameraAbilityList.clear();
543 for (const auto& camera: choosedCameras) {
544 cameraIds.emplace_back(camera->cameraId);
545 cameraAbilityList.emplace_back(camera->cameraAbility);
546 }
547 int32_t uid = IPCSkeleton::GetCallingUid();
548 if (uid == ROOT_UID || uid == FACE_CLIENT_UID || uid == RSS_UID ||
549 OHOS::Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(IPCSkeleton::GetCallingFullTokenID())) {
550 vector<shared_ptr<CameraMetaInfo>> physicalCameras = ChoosePhysicalCameras(cameraInfos, choosedCameras);
551 for (const auto& camera: physicalCameras) {
552 cameraIds.emplace_back(camera->cameraId);
553 cameraAbilityList.emplace_back(camera->cameraAbility);
554 }
555 } else {
556 MEDIA_INFO_LOG("current token id not support physical camera");
557 }
558 }
559
ChoosePhysicalCameras(const vector<shared_ptr<CameraMetaInfo>> & cameraInfos,const vector<shared_ptr<CameraMetaInfo>> & choosedCameras)560 vector<shared_ptr<CameraMetaInfo>> HCameraService::ChoosePhysicalCameras(
561 const vector<shared_ptr<CameraMetaInfo>>& cameraInfos, const vector<shared_ptr<CameraMetaInfo>>& choosedCameras)
562 {
563 std::vector<OHOS::HDI::Camera::V1_3::OperationMode> supportedPhysicalCamerasModes = {
564 OHOS::HDI::Camera::V1_3::OperationMode::PROFESSIONAL_PHOTO,
565 OHOS::HDI::Camera::V1_3::OperationMode::PROFESSIONAL_VIDEO,
566 OHOS::HDI::Camera::V1_3::OperationMode::HIGH_RESOLUTION_PHOTO,
567 };
568 vector<shared_ptr<CameraMetaInfo>> physicalCameraInfos = {};
569 for (auto& camera : cameraInfos) {
570 if (std::any_of(choosedCameras.begin(), choosedCameras.end(), [camera](const auto& defaultCamera) {
571 return camera->cameraId == defaultCamera->cameraId;
572 })
573 ) {
574 MEDIA_INFO_LOG("ChoosePhysicalCameras alreadly has default camera: %{public}s", camera->cameraId.c_str());
575 } else {
576 physicalCameraInfos.push_back(camera);
577 }
578 }
579 vector<shared_ptr<CameraMetaInfo>> physicalCameras = {};
580 for (auto& camera : physicalCameraInfos) {
581 MEDIA_INFO_LOG("ChoosePhysicalCameras camera ID:%s, CameraType: %{public}d, Camera position:%{public}d, "
582 "Connection Type:%{public}d",
583 camera->cameraId.c_str(), camera->cameraType, camera->position, camera->connectionType);
584 bool isSupportPhysicalCamera = std::any_of(camera->supportModes.begin(), camera->supportModes.end(),
585 [&supportedPhysicalCamerasModes](auto mode) -> bool {
586 return any_of(supportedPhysicalCamerasModes.begin(), supportedPhysicalCamerasModes.end(),
587 [mode](auto it)-> bool { return it == mode; });
588 });
589 if (camera->cameraType != camera_type_enum_t::OHOS_CAMERA_TYPE_UNSPECIFIED && isSupportPhysicalCamera) {
590 physicalCameras.emplace_back(camera);
591 MEDIA_INFO_LOG("ChoosePhysicalCameras add camera ID:%{public}s", camera->cameraId.c_str());
592 }
593 }
594 return physicalCameras;
595 }
596
597
GetCameraIds(std::vector<std::string> & cameraIds)598 int32_t HCameraService::GetCameraIds(std::vector<std::string>& cameraIds)
599 {
600 CAMERA_SYNC_TRACE;
601 int32_t ret = CAMERA_OK;
602 MEDIA_DEBUG_LOG("HCameraService::GetCameraIds");
603 std::vector<std::shared_ptr<OHOS::Camera::CameraMetadata>> cameraAbilityList;
604 ret = GetCameras(cameraIds, cameraAbilityList);
605 CHECK_PRINT_ELOG(ret != CAMERA_OK, "HCameraService::GetCameraIds failed");
606 return ret;
607 }
608
GetCameraAbility(const std::string & cameraId,std::shared_ptr<OHOS::Camera::CameraMetadata> & cameraAbility)609 int32_t HCameraService::GetCameraAbility(const std::string& cameraId,
610 std::shared_ptr<OHOS::Camera::CameraMetadata>& cameraAbility)
611 {
612 CAMERA_SYNC_TRACE;
613 MEDIA_DEBUG_LOG("HCameraService::GetCameraAbility");
614 int32_t ret = cameraHostManager_->GetCameraAbility(cameraId, cameraAbility);
615 CHECK_RETURN_RET_ELOG(ret != CAMERA_OK, ret, "HCameraService::GetCameraAbility failed");
616 return ret;
617 }
618
ChooseDeFaultCameras(vector<shared_ptr<CameraMetaInfo>> cameraInfos)619 vector<shared_ptr<CameraMetaInfo>> HCameraService::ChooseDeFaultCameras(vector<shared_ptr<CameraMetaInfo>> cameraInfos)
620 {
621 vector<shared_ptr<CameraMetaInfo>> choosedCameras;
622 for (auto& camera : cameraInfos) {
623 MEDIA_DEBUG_LOG("ChooseDeFaultCameras camera ID:%s, Camera position:%{public}d, Connection Type:%{public}d",
624 camera->cameraId.c_str(), camera->position, camera->connectionType);
625 if (any_of(choosedCameras.begin(), choosedCameras.end(),
626 [camera](const auto& defaultCamera) {
627 return (camera->connectionType != OHOS_CAMERA_CONNECTION_TYPE_USB_PLUGIN &&
628 defaultCamera->position == camera->position &&
629 defaultCamera->connectionType == camera->connectionType &&
630 defaultCamera->foldStatus == camera->foldStatus);
631 })
632 ) {
633 MEDIA_DEBUG_LOG("ChooseDeFaultCameras alreadly has default camera");
634 } else {
635 choosedCameras.emplace_back(camera);
636 MEDIA_INFO_LOG("add camera ID:%{public}s", camera->cameraId.c_str());
637 }
638 }
639 return choosedCameras;
640 }
641
CreateCameraDevice(const string & cameraId,sptr<ICameraDeviceService> & device)642 int32_t HCameraService::CreateCameraDevice(const string& cameraId, sptr<ICameraDeviceService>& device)
643 {
644 CAMERA_SYNC_TRACE;
645 OHOS::Security::AccessToken::AccessTokenID callerToken = IPCSkeleton::GetCallingTokenID();
646 MEDIA_INFO_LOG("HCameraService::CreateCameraDevice prepare execute, cameraId:%{public}s", cameraId.c_str());
647
648 string permissionName = OHOS_PERMISSION_CAMERA;
649 int32_t ret = CheckPermission(permissionName, callerToken);
650 CHECK_RETURN_RET_ELOG(ret != CAMERA_OK, ret,
651 "HCameraService::CreateCameraDevice Check OHOS_PERMISSION_CAMERA fail %{public}d", ret);
652 // if callerToken is invalid, will not call IsAllowedUsingPermission
653 CHECK_RETURN_RET_ELOG(!IsInForeGround(callerToken), CAMERA_ALLOC_ERROR,
654 "HCameraService::CreateCameraDevice is not allowed!");
655 sptr<HCameraDevice> cameraDevice = new (nothrow) HCameraDevice(cameraHostManager_, cameraId, callerToken);
656 CHECK_RETURN_RET_ELOG(cameraDevice == nullptr, CAMERA_ALLOC_ERROR,
657 "HCameraService::CreateCameraDevice HCameraDevice allocation failed");
658 CHECK_RETURN_RET_ELOG(GetServiceStatus() != CameraServiceStatus::SERVICE_READY, CAMERA_INVALID_STATE,
659 "HCameraService::CreateCameraDevice CameraService not ready!");
660 {
661 lock_guard<mutex> lock(g_dataShareHelperMutex);
662 // when create camera device, update mute setting truely.
663 if (IsCameraMuteSupported(cameraId)) {
664 CHECK_PRINT_ELOG(UpdateMuteSetting(cameraDevice, muteModeStored_) != CAMERA_OK,
665 "UpdateMuteSetting Failed, cameraId: %{public}s", cameraId.c_str());
666 } else {
667 MEDIA_ERR_LOG("HCameraService::CreateCameraDevice MuteCamera not Supported");
668 }
669 device = cameraDevice;
670 cameraDevice->SetDeviceMuteMode(muteModeStored_);
671 cameraDevice->SetCameraRotateStrategyInfos(
672 CameraRoateParamManager::GetInstance().GetCameraRotateStrategyInfos());
673 }
674 CAMERA_SYSEVENT_STATISTIC(CreateMsg("CameraManager_CreateCameraInput CameraId:%s", cameraId.c_str()));
675 MEDIA_INFO_LOG("HCameraService::CreateCameraDevice execute success");
676 return CAMERA_OK;
677 }
678
CreateCaptureSession(sptr<ICaptureSession> & session,int32_t opMode)679 int32_t HCameraService::CreateCaptureSession(sptr<ICaptureSession>& session, int32_t opMode)
680 {
681 CAMERA_SYNC_TRACE;
682 std::lock_guard<std::mutex> lock(mutex_);
683 int32_t rc = CAMERA_OK;
684 MEDIA_INFO_LOG("HCameraService::CreateCaptureSession opMode_= %{public}d", opMode);
685
686 OHOS::Security::AccessToken::AccessTokenID callerToken = IPCSkeleton::GetCallingTokenID();
687 sptr<HCaptureSession> captureSession = nullptr;
688 rc = HCaptureSession::NewInstance(callerToken, opMode, captureSession);
689 if (rc != CAMERA_OK) { // LCOV_EXCL_LINE
690 MEDIA_ERR_LOG("HCameraService::CreateCaptureSession allocation failed");
691 CameraReportUtils::ReportCameraError(
692 "HCameraService::CreateCaptureSession", rc, false, CameraReportUtils::GetCallerInfo());
693 return rc;
694 }
695 session = captureSession;
696 if (opMode == SceneMode::VIDEO) {
697 videoSessionForControlCenter_ = captureSession;
698 videoSessionForControlCenter_->SetUpdateControlCenterCallback(
699 std::bind(&HCameraService::UpdateControlCenterStatus, this, std::placeholders::_1));
700 std::string bundleName = BmsAdapter::GetInstance()->GetBundleName(IPCSkeleton::GetCallingUid());
701 videoSessionForControlCenter_->SetBundleForControlCenter(bundleName);
702 MEDIA_INFO_LOG("Save videoSession for controlCenter");
703 } else {
704 videoSessionForControlCenter_ = nullptr;
705 MEDIA_INFO_LOG("Clear videoSession of controlCenter");
706 }
707
708 #ifdef HOOK_CAMERA_OPERATOR
709 std::string clientName = GetClientBundle(IPCSkeleton::GetCallingUid());
710 CameraRotatePlugin::GetInstance()->SetCaptureSession(clientName, captureSession);
711 #endif
712 int32_t uid = IPCSkeleton::GetCallingUid();
713 int32_t userId;
714 AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid, userId);
715 MEDIA_INFO_LOG("HCameraService::CreateCaptureSession userId= %{public}d", userId);
716 captureSession->SetUserId(userId);
717
718 auto &sessionManager = HCameraSessionManager::GetInstance();
719 auto mechSession = sessionManager.GetMechSession(userId);
720 if (mechSession != nullptr && mechSession->IsEnableMech()) {
721 captureSession->SetMechDeliveryState(MechDeliveryState::NEED_ENABLE);
722 }
723 return rc;
724 }
725
GetVideoSessionForControlCenter(sptr<ICaptureSession> & session)726 int32_t HCameraService::GetVideoSessionForControlCenter(sptr<ICaptureSession>& session)
727 {
728 std::lock_guard<std::mutex> lock(mutex_);
729 MEDIA_INFO_LOG("HCameraService::GetVideoSessionForControlCenter");
730 if (videoSessionForControlCenter_ == nullptr) {
731 MEDIA_ERR_LOG("GetVideoSessionForControlCenter failed, session == nullptr.");
732 return CAMERA_INVALID_ARG;
733 }
734 session = videoSessionForControlCenter_;
735 return CAMERA_OK;
736 }
737
CreateDeferredPhotoProcessingSession(int32_t userId,const sptr<DeferredProcessing::IDeferredPhotoProcessingSessionCallback> & callback,sptr<DeferredProcessing::IDeferredPhotoProcessingSession> & session)738 int32_t HCameraService::CreateDeferredPhotoProcessingSession(int32_t userId,
739 const sptr<DeferredProcessing::IDeferredPhotoProcessingSessionCallback>& callback,
740 sptr<DeferredProcessing::IDeferredPhotoProcessingSession>& session)
741 {
742 CAMERA_SYNC_TRACE;
743 CHECK_RETURN_RET_ELOG(!CheckSystemApp(), CAMERA_NO_PERMISSION, "HCameraService::CheckSystemApp fail");
744 CameraXCollie cameraXCollie = CameraXCollie("HCameraService::CreateDeferredPhotoProcessingSession");
745 MEDIA_INFO_LOG("HCameraService::CreateDeferredPhotoProcessingSession enter.");
746 sptr<DeferredProcessing::IDeferredPhotoProcessingSession> photoSession;
747 int32_t uid = IPCSkeleton::GetCallingUid();
748 AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid, userId);
749 MEDIA_INFO_LOG("CreateDeferredPhotoProcessingSession get uid:%{public}d userId:%{public}d", uid, userId);
750 photoSession =
751 DeferredProcessing::DeferredProcessingService::GetInstance().CreateDeferredPhotoProcessingSession(userId,
752 callback);
753 session = photoSession;
754 return CAMERA_OK;
755 }
756
CreateDeferredVideoProcessingSession(int32_t userId,const sptr<DeferredProcessing::IDeferredVideoProcessingSessionCallback> & callback,sptr<DeferredProcessing::IDeferredVideoProcessingSession> & session)757 int32_t HCameraService::CreateDeferredVideoProcessingSession(int32_t userId,
758 const sptr<DeferredProcessing::IDeferredVideoProcessingSessionCallback>& callback,
759 sptr<DeferredProcessing::IDeferredVideoProcessingSession>& session)
760 {
761 CAMERA_SYNC_TRACE;
762 MEDIA_INFO_LOG("HCameraService::CreateDeferredVideoProcessingSession enter.");
763 sptr<DeferredProcessing::IDeferredVideoProcessingSession> videoSession;
764 int32_t uid = IPCSkeleton::GetCallingUid();
765 AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid, userId);
766 MEDIA_INFO_LOG("CreateDeferredVideoProcessingSession get uid:%{public}d userId:%{public}d", uid, userId);
767 videoSession =
768 DeferredProcessing::DeferredProcessingService::GetInstance().CreateDeferredVideoProcessingSession(userId,
769 callback);
770 session = videoSession;
771 return CAMERA_OK;
772 }
773
CreateMechSession(int32_t userId,sptr<IMechSession> & session)774 int32_t HCameraService::CreateMechSession(int32_t userId, sptr<IMechSession>& session)
775 {
776 CAMERA_SYNC_TRACE;
777 MEDIA_INFO_LOG("HCameraService::CreateMechSession enter.");
778
779 OHOS::Security::AccessToken::AccessTokenID callerToken = IPCSkeleton::GetCallingTokenID();
780 string permissionName = OHOS_PERMISSION_CAMERA;
781 int32_t ret = CheckPermission(permissionName, callerToken);
782 CHECK_RETURN_RET_ELOG(ret != CAMERA_OK, ret,
783 "HCameraService::CreateMechSession failed permission is: %{public}s", permissionName.c_str());
784
785 auto &sessionManager = HCameraSessionManager::GetInstance();
786 auto mechSession = sessionManager.GetMechSession(userId);
787 if (mechSession != nullptr) {
788 session = mechSession;
789 return CAMERA_OK;
790 }
791
792 mechSession = new (std::nothrow) HMechSession(userId);
793 if (mechSession == nullptr) {
794 MEDIA_ERR_LOG("HMechSession::NewInstance mechSession is nullptr");
795 return CAMERA_ALLOC_ERROR;
796 }
797 session = mechSession;
798 sessionManager.AddMechSession(userId, mechSession);
799 return CAMERA_OK;
800 }
801
IsMechSupported(bool & isMechSupported)802 int32_t HCameraService::IsMechSupported(bool &isMechSupported)
803 {
804 CAMERA_SYNC_TRACE;
805 isMechSupported = false;
806 std::vector<std::string> cameraIds;
807 std::vector<std::shared_ptr<OHOS::Camera::CameraMetadata>> cameraAbilityList;
808 int32_t retCode = GetCameras(cameraIds, cameraAbilityList);
809 CHECK_RETURN_RET_ELOG(retCode != CAMERA_OK, retCode, "HCameraService::IsMechSupported failed");
810 for (auto& cameraAbility : cameraAbilityList) {
811 camera_metadata_item_t item;
812 int ret = OHOS::Camera::FindCameraMetadataItem(cameraAbility->get(),
813 OHOS_ABILITY_FOCUS_TRACKING_MECH_AVAILABLE, &item);
814 if (ret == CAM_META_SUCCESS && item.count > 0) {
815 MEDIA_DEBUG_LOG("IsMechSupported data is %{public}d", item.data.u8[0]);
816 if (item.data.u8[0] == OHOS_CAMERA_MECH_MODE_ON) {
817 isMechSupported = true;
818 break;
819 }
820 }
821 }
822 MEDIA_INFO_LOG("HCameraService::IsMechSupported success. isMechSupported: %{public}d", isMechSupported);
823 return retCode;
824 }
825
CreatePhotoOutput(const sptr<OHOS::IBufferProducer> & producer,int32_t format,int32_t width,int32_t height,sptr<IStreamCapture> & photoOutput)826 int32_t HCameraService::CreatePhotoOutput(const sptr<OHOS::IBufferProducer>& producer, int32_t format, int32_t width,
827 int32_t height, sptr<IStreamCapture>& photoOutput)
828 {
829 CAMERA_SYNC_TRACE;
830 int32_t rc = CAMERA_OK;
831 MEDIA_INFO_LOG("HCameraService::CreatePhotoOutput prepare execute");
832 if ((producer == nullptr) || (width == 0) || (height == 0)) {
833 rc = CAMERA_INVALID_ARG;
834 MEDIA_ERR_LOG("HCameraService::CreatePhotoOutput producer is null");
835 CameraReportUtils::ReportCameraError(
836 "HCameraService::CreatePhotoOutput", rc, false, CameraReportUtils::GetCallerInfo());
837 return rc;
838 }
839 sptr<HStreamCapture> streamCapture = new (nothrow) HStreamCapture(producer, format, width, height);
840 if (streamCapture == nullptr) {
841 rc = CAMERA_ALLOC_ERROR;
842 MEDIA_ERR_LOG("HCameraService::CreatePhotoOutput streamCapture is null");
843 CameraReportUtils::ReportCameraError(
844 "HCameraService::CreatePhotoOutput", rc, false, CameraReportUtils::GetCallerInfo());
845 return rc;
846 }
847
848 stringstream ss;
849 ss << "format=" << format << " width=" << width << " height=" << height;
850 CameraReportUtils::GetInstance().UpdateProfileInfo(ss.str());
851 photoOutput = streamCapture;
852 MEDIA_INFO_LOG("HCameraService::CreatePhotoOutput execute success");
853 return rc;
854 }
855
CreatePhotoOutput(int32_t format,int32_t width,int32_t height,sptr<IStreamCapture> & photoOutput)856 int32_t HCameraService::CreatePhotoOutput(
857 int32_t format, int32_t width, int32_t height, sptr<IStreamCapture> &photoOutput)
858 {
859 CAMERA_SYNC_TRACE;
860 int32_t rc = CAMERA_OK;
861 MEDIA_INFO_LOG("HCameraService::CreatePhotoOutput prepare execute");
862 sptr<HStreamCapture> streamCapture = new (nothrow) HStreamCapture(format, width, height);
863 if (streamCapture == nullptr) {
864 rc = CAMERA_ALLOC_ERROR;
865 MEDIA_ERR_LOG("HCameraService::CreatePhotoOutput streamCapture is null");
866 CameraReportUtils::ReportCameraError(
867 "HCameraService::CreatePhotoOutput", rc, false, CameraReportUtils::GetCallerInfo());
868 return rc;
869 }
870
871 stringstream ss;
872 ss << "format=" << format << " width=" << width << " height=" << height;
873 CameraReportUtils::GetInstance().UpdateProfileInfo(ss.str());
874 photoOutput = streamCapture;
875 MEDIA_INFO_LOG("HCameraService::CreatePhotoOutput execute success");
876 return rc;
877 }
878
CreateDeferredPreviewOutput(int32_t format,int32_t width,int32_t height,sptr<IStreamRepeat> & previewOutput)879 int32_t HCameraService::CreateDeferredPreviewOutput(
880 int32_t format, int32_t width, int32_t height, sptr<IStreamRepeat>& previewOutput)
881 {
882 CAMERA_SYNC_TRACE;
883 CHECK_RETURN_RET_ELOG(!CheckSystemApp(), CAMERA_NO_PERMISSION, "HCameraService::CheckSystemApp fail");
884 CameraXCollie cameraXCollie = CameraXCollie("HCameraService::CreateDeferredPreviewOutput");
885 sptr<HStreamRepeat> streamDeferredPreview;
886 MEDIA_INFO_LOG("HCameraService::CreateDeferredPreviewOutput prepare execute");
887 CHECK_RETURN_RET_ELOG((width == 0) || (height == 0), CAMERA_INVALID_ARG,
888 "HCameraService::CreateDeferredPreviewOutput producer is null!");
889 streamDeferredPreview = new (nothrow) HStreamRepeat(nullptr, format, width, height, RepeatStreamType::PREVIEW);
890 CHECK_RETURN_RET_ELOG(streamDeferredPreview == nullptr, CAMERA_ALLOC_ERROR,
891 "HCameraService::CreateDeferredPreviewOutput HStreamRepeat allocation failed");
892 previewOutput = streamDeferredPreview;
893 MEDIA_INFO_LOG("HCameraService::CreateDeferredPreviewOutput execute success");
894 return CAMERA_OK;
895 }
896
CreatePreviewOutput(const sptr<OHOS::IBufferProducer> & producer,int32_t format,int32_t width,int32_t height,sptr<IStreamRepeat> & previewOutput)897 int32_t HCameraService::CreatePreviewOutput(const sptr<OHOS::IBufferProducer>& producer, int32_t format, int32_t width,
898 int32_t height, sptr<IStreamRepeat>& previewOutput)
899 {
900 CAMERA_SYNC_TRACE;
901 sptr<HStreamRepeat> streamRepeatPreview;
902 int32_t rc = CAMERA_OK;
903 MEDIA_INFO_LOG("HCameraService::CreatePreviewOutput prepare execute");
904
905 if ((producer == nullptr) || (width == 0) || (height == 0)) {
906 rc = CAMERA_INVALID_ARG;
907 MEDIA_ERR_LOG("HCameraService::CreatePreviewOutput producer is null");
908 CameraReportUtils::ReportCameraError(
909 "HCameraService::CreatePreviewOutput", rc, false, CameraReportUtils::GetCallerInfo());
910 return rc;
911 }
912 #ifdef HOOK_CAMERA_OPERATOR
913 if (!CameraRotatePlugin::GetInstance()->
914 HookCreatePreviewFormat(GetClientBundle(IPCSkeleton::GetCallingUid()), format)) {
915 MEDIA_ERR_LOG("HCameraService::CreatePreviewOutput HookCreatePreviewFormat is failed");
916 }
917 #endif
918 streamRepeatPreview = new (nothrow) HStreamRepeat(producer, format, width, height, RepeatStreamType::PREVIEW);
919 if (streamRepeatPreview == nullptr) { // LCOV_EXCL_LINE
920 rc = CAMERA_ALLOC_ERROR;
921 MEDIA_ERR_LOG("HCameraService::CreatePreviewOutput HStreamRepeat allocation failed");
922 CameraReportUtils::ReportCameraError(
923 "HCameraService::CreatePreviewOutput", rc, false, CameraReportUtils::GetCallerInfo());
924 return rc;
925 }
926 previewOutput = streamRepeatPreview;
927 MEDIA_INFO_LOG("HCameraService::CreatePreviewOutput execute success");
928 return rc;
929 }
930
CreateDepthDataOutput(const sptr<OHOS::IBufferProducer> & producer,int32_t format,int32_t width,int32_t height,sptr<IStreamDepthData> & depthDataOutput)931 int32_t HCameraService::CreateDepthDataOutput(const sptr<OHOS::IBufferProducer>& producer, int32_t format,
932 int32_t width, int32_t height, sptr<IStreamDepthData>& depthDataOutput)
933 {
934 CAMERA_SYNC_TRACE;
935 CHECK_RETURN_RET_ELOG(
936 !CheckSystemApp(), CAMERA_NO_PERMISSION, "HCameraService::CreateDepthDataOutput:SystemApi is called");
937 sptr<HStreamDepthData> streamDepthData;
938 int32_t rc = CAMERA_OK;
939 MEDIA_INFO_LOG("HCameraService::CreateDepthDataOutput prepare execute");
940
941 if ((producer == nullptr) || (width == 0) || (height == 0)) {
942 rc = CAMERA_INVALID_ARG;
943 MEDIA_ERR_LOG("HCameraService::CreateDepthDataOutput producer is null");
944 CameraReportUtils::ReportCameraError(
945 "HCameraService::CreateDepthDataOutput", rc, false, CameraReportUtils::GetCallerInfo());
946 return rc;
947 }
948 streamDepthData = new (nothrow) HStreamDepthData(producer, format, width, height);
949 if (streamDepthData == nullptr) { // LCOV_EXCL_LINE
950 rc = CAMERA_ALLOC_ERROR;
951 MEDIA_ERR_LOG("HCameraService::CreateDepthDataOutput HStreamRepeat allocation failed");
952 CameraReportUtils::ReportCameraError(
953 "HCameraService::CreateDepthDataOutput", rc, false, CameraReportUtils::GetCallerInfo());
954 return rc;
955 }
956 depthDataOutput = streamDepthData;
957 MEDIA_INFO_LOG("HCameraService::CreateDepthDataOutput execute success");
958 return rc;
959 }
960
CreateMetadataOutput(const sptr<OHOS::IBufferProducer> & producer,int32_t format,const std::vector<int32_t> & metadataTypes,sptr<IStreamMetadata> & metadataOutput)961 int32_t HCameraService::CreateMetadataOutput(const sptr<OHOS::IBufferProducer>& producer, int32_t format,
962 const std::vector<int32_t>& metadataTypes, sptr<IStreamMetadata>& metadataOutput)
963 {
964 CAMERA_SYNC_TRACE;
965 sptr<HStreamMetadata> streamMetadata;
966 MEDIA_INFO_LOG("HCameraService::CreateMetadataOutput prepare execute");
967
968 CHECK_RETURN_RET_ELOG(producer == nullptr, CAMERA_INVALID_ARG,
969 "HCameraService::CreateMetadataOutput producer is null");
970 streamMetadata = new (nothrow) HStreamMetadata(producer, format, metadataTypes);
971 CHECK_RETURN_RET_ELOG(streamMetadata == nullptr, CAMERA_ALLOC_ERROR,
972 "HCameraService::CreateMetadataOutput HStreamMetadata allocation failed");
973
974 metadataOutput = streamMetadata;
975 MEDIA_INFO_LOG("HCameraService::CreateMetadataOutput execute success");
976 return CAMERA_OK;
977 }
978
CreateVideoOutput(const sptr<OHOS::IBufferProducer> & producer,int32_t format,int32_t width,int32_t height,sptr<IStreamRepeat> & videoOutput)979 int32_t HCameraService::CreateVideoOutput(const sptr<OHOS::IBufferProducer>& producer, int32_t format, int32_t width,
980 int32_t height, sptr<IStreamRepeat>& videoOutput)
981 {
982 CAMERA_SYNC_TRACE;
983 sptr<HStreamRepeat> streamRepeatVideo;
984 int32_t rc = CAMERA_OK;
985 MEDIA_INFO_LOG("HCameraService::CreateVideoOutput prepare execute");
986
987 if ((producer == nullptr) || (width == 0) || (height == 0)) {
988 rc = CAMERA_INVALID_ARG;
989 MEDIA_ERR_LOG("HCameraService::CreateVideoOutput producer is null");
990 CameraReportUtils::ReportCameraError(
991 "HCameraService::CreateVideoOutput", rc, false, CameraReportUtils::GetCallerInfo());
992 return rc;
993 }
994 streamRepeatVideo = new (nothrow) HStreamRepeat(producer, format, width, height, RepeatStreamType::VIDEO);
995 if (streamRepeatVideo == nullptr) { // LCOV_EXCL_LINE
996 rc = CAMERA_ALLOC_ERROR;
997 MEDIA_ERR_LOG("HCameraService::CreateVideoOutput HStreamRepeat allocation failed");
998 CameraReportUtils::ReportCameraError(
999 "HCameraService::CreateVideoOutput", rc, false, CameraReportUtils::GetCallerInfo());
1000 return rc;
1001 }
1002 stringstream ss;
1003 ss << "format=" << format << " width=" << width << " height=" << height;
1004 CameraReportUtils::GetInstance().UpdateProfileInfo(ss.str());
1005 videoOutput = streamRepeatVideo;
1006 MEDIA_INFO_LOG("HCameraService::CreateVideoOutput execute success");
1007 return rc;
1008 }
1009
ShouldSkipStatusUpdates(pid_t pid)1010 bool HCameraService::ShouldSkipStatusUpdates(pid_t pid)
1011 {
1012 std::lock_guard<std::mutex> lock(freezedPidListMutex_);
1013 CHECK_RETURN_RET(freezedPidList_.count(pid) == 0, false);
1014 MEDIA_INFO_LOG("ShouldSkipStatusUpdates pid = %{public}d", pid);
1015 return true;
1016 }
1017
CreateAndSaveTask(const string & cameraId,CameraStatus status,uint32_t pid)1018 void HCameraService::CreateAndSaveTask(const string& cameraId, CameraStatus status, uint32_t pid)
1019 {
1020 auto thisPtr = sptr<HCameraService>(this);
1021 CHECK_RETURN(!(status == CAMERA_STATUS_APPEAR || status == CAMERA_STATUS_DISAPPEAR));
1022 auto task = [cameraId, status, pid, thisPtr]() {
1023 auto itr = thisPtr->cameraServiceCallbacks_.find(pid);
1024 CHECK_RETURN(itr == thisPtr->cameraServiceCallbacks_.end() || !itr->second);
1025 MEDIA_INFO_LOG("trigger callback due to unfreeze pid: %{public}d", pid);
1026 itr->second->OnCameraStatusChanged(cameraId, status, "");
1027 };
1028 delayCbtaskMap_[pid][cameraId] = task;
1029 }
1030
OnCameraStatus(const string & cameraId,CameraStatus status,CallbackInvoker invoker)1031 void HCameraService::OnCameraStatus(const string& cameraId, CameraStatus status, CallbackInvoker invoker)
1032 {
1033 lock_guard<mutex> lock(cameraCbMutex_);
1034 std::string bundleName = "";
1035 if (invoker == CallbackInvoker::APPLICATION) {
1036 bundleName = GetClientBundle(IPCSkeleton::GetCallingUid());
1037 }
1038 MEDIA_INFO_LOG("HCameraService::OnCameraStatus callbacks.size = %{public}zu, cameraId = %{public}s, "
1039 "status = %{public}d, pid = %{public}d, bundleName = %{public}s",
1040 cameraServiceCallbacks_.size(), cameraId.c_str(), status, IPCSkeleton::GetCallingPid(), bundleName.c_str());
1041 for (auto it : cameraServiceCallbacks_) {
1042 if (it.second == nullptr) {
1043 MEDIA_ERR_LOG("HCameraService::OnCameraStatus pid:%{public}d cameraServiceCallback is null", it.first);
1044 continue;
1045 }
1046 uint32_t pid = it.first;
1047 if (ShouldSkipStatusUpdates(pid)) {
1048 CreateAndSaveTask(cameraId, status, pid);
1049 continue;
1050 }
1051 it.second->OnCameraStatusChanged(cameraId, status, bundleName);
1052 CacheCameraStatus(
1053 cameraId, std::make_shared<CameraStatusCallbacksInfo>(CameraStatusCallbacksInfo { status, bundleName }));
1054 CAMERA_SYSEVENT_BEHAVIOR(
1055 CreateMsg("OnCameraStatusChanged! for cameraId:%s, current Camera Status:%d", cameraId.c_str(), status));
1056 }
1057 }
1058
OnFlashlightStatus(const string & cameraId,FlashStatus status)1059 void HCameraService::OnFlashlightStatus(const string& cameraId, FlashStatus status)
1060 {
1061 lock_guard<mutex> lock(cameraCbMutex_);
1062 MEDIA_INFO_LOG("HCameraService::OnFlashlightStatus callbacks.size = %{public}zu, cameraId = %{public}s, "
1063 "status = %{public}d, pid = %{public}d",
1064 cameraServiceCallbacks_.size(), cameraId.c_str(), status, IPCSkeleton::GetCallingPid());
1065 for (auto it : cameraServiceCallbacks_) {
1066 if (it.second == nullptr) {
1067 MEDIA_ERR_LOG("HCameraService::OnCameraStatus pid:%{public}d cameraServiceCallback is null", it.first);
1068 continue;
1069 }
1070 uint32_t pid = it.first;
1071 if (ShouldSkipStatusUpdates(pid)) {
1072 continue;
1073 }
1074 it.second->OnFlashlightStatusChanged(cameraId, status);
1075 CacheFlashStatus(cameraId, status);
1076 }
1077 }
1078
OnMute(bool muteMode)1079 void HCameraService::OnMute(bool muteMode)
1080 {
1081 lock_guard<mutex> lock(muteCbMutex_);
1082 if (!cameraMuteServiceCallbacks_.empty()) {
1083 for (auto it : cameraMuteServiceCallbacks_) {
1084 if (it.second == nullptr) {
1085 MEDIA_ERR_LOG("HCameraService::OnMute pid:%{public}d cameraMuteServiceCallback is null", it.first);
1086 continue;
1087 }
1088 uint32_t pid = it.first;
1089 if (ShouldSkipStatusUpdates(pid)) {
1090 continue;
1091 }
1092 it.second->OnCameraMute(muteMode);
1093 CAMERA_SYSEVENT_BEHAVIOR(CreateMsg("OnCameraMute! current Camera muteMode:%d", muteMode));
1094 }
1095 }
1096 {
1097 std::lock_guard<std::mutex> peerLock(peerCallbackMutex_);
1098 if (peerCallback_ != nullptr) {
1099 MEDIA_INFO_LOG(
1100 "HCameraService::NotifyMuteCamera peerCallback current camera muteMode:%{public}d", muteMode);
1101 peerCallback_->NotifyMuteCamera(muteMode);
1102 }
1103 }
1104 }
1105
GetTorchStatus(int32_t & status)1106 int32_t HCameraService::GetTorchStatus(int32_t &status)
1107 {
1108 status = static_cast<int32_t>(torchStatus_);
1109 return CAMERA_OK;
1110 }
1111
OnTorchStatus(TorchStatus status)1112 void HCameraService::OnTorchStatus(TorchStatus status)
1113 {
1114 lock_guard<recursive_mutex> lock(torchCbMutex_);
1115 torchStatus_ = status;
1116 MEDIA_INFO_LOG("HCameraService::OnTorchtStatus callbacks.size = %{public}zu, status = %{public}d, pid = %{public}d",
1117 torchServiceCallbacks_.size(), status, IPCSkeleton::GetCallingPid());
1118 for (auto it : torchServiceCallbacks_) {
1119 if (it.second == nullptr) {
1120 MEDIA_ERR_LOG("HCameraService::OnTorchtStatus pid:%{public}d torchServiceCallback is null", it.first);
1121 continue;
1122 }
1123 uint32_t pid = it.first;
1124 if (ShouldSkipStatusUpdates(pid)) {
1125 continue;
1126 }
1127 it.second->OnTorchStatusChange(status);
1128 }
1129 }
1130
OnFoldStatusChanged(OHOS::Rosen::FoldStatus foldStatus)1131 void HCameraService::OnFoldStatusChanged(OHOS::Rosen::FoldStatus foldStatus)
1132 {
1133 MEDIA_INFO_LOG("OnFoldStatusChanged preFoldStatus = %{public}d, foldStatus = %{public}d, pid = %{public}d",
1134 preFoldStatus_, foldStatus, IPCSkeleton::GetCallingPid());
1135 auto curFoldStatus = (FoldStatus)foldStatus;
1136 if ((curFoldStatus == FoldStatus::HALF_FOLD && preFoldStatus_ == FoldStatus::EXPAND) ||
1137 (curFoldStatus == FoldStatus::EXPAND && preFoldStatus_ == FoldStatus::HALF_FOLD)) {
1138 preFoldStatus_ = curFoldStatus;
1139 return;
1140 }
1141 preFoldStatus_ = curFoldStatus;
1142 if (curFoldStatus == FoldStatus::HALF_FOLD) {
1143 curFoldStatus = FoldStatus::EXPAND;
1144 }
1145 lock_guard<recursive_mutex> lock(foldCbMutex_);
1146 CHECK_EXECUTE(innerFoldCallback_, innerFoldCallback_->OnFoldStatusChanged(curFoldStatus));
1147 CHECK_RETURN_ELOG(foldServiceCallbacks_.empty(), "OnFoldStatusChanged foldServiceCallbacks is empty");
1148 MEDIA_INFO_LOG("OnFoldStatusChanged foldStatusCallback size = %{public}zu", foldServiceCallbacks_.size());
1149 for (auto it : foldServiceCallbacks_) {
1150 if (it.second == nullptr) {
1151 MEDIA_ERR_LOG("OnFoldStatusChanged pid:%{public}d foldStatusCallbacks is null", it.first);
1152 continue;
1153 }
1154 uint32_t pid = it.first;
1155 if (ShouldSkipStatusUpdates(pid)) {
1156 continue;
1157 }
1158 it.second->OnFoldStatusChanged(curFoldStatus);
1159 }
1160 }
1161
CloseCameraForDestory(pid_t pid)1162 int32_t HCameraService::CloseCameraForDestory(pid_t pid)
1163 {
1164 MEDIA_INFO_LOG("HCameraService::CloseCameraForDestory enter");
1165 sptr<HCameraDeviceManager> deviceManager = HCameraDeviceManager::GetInstance();
1166 std::vector<sptr<HCameraDevice>> devicesNeedClose = deviceManager->GetCamerasByPid(pid);
1167 for (auto device : devicesNeedClose) {
1168 device->Close();
1169 }
1170
1171 std::vector<sptr<HStreamOperator>> streamOperatorToRelease =
1172 HStreamOperatorManager::GetInstance()->GetStreamOperatorByPid(pid);
1173 for (auto streamoperator : streamOperatorToRelease) {
1174 streamoperator->Release();
1175 }
1176 return CAMERA_OK;
1177 }
1178
ExecutePidSetCallback(const sptr<ICameraServiceCallback> & callback,std::vector<std::string> & cameraIds)1179 void HCameraService::ExecutePidSetCallback(const sptr<ICameraServiceCallback>& callback,
1180 std::vector<std::string>& cameraIds)
1181 {
1182 for (const auto& cameraId : cameraIds) {
1183 auto info = GetCachedCameraStatus(cameraId);
1184 auto flashStatus = GetCachedFlashStatus(cameraId);
1185 if (info != nullptr) {
1186 MEDIA_INFO_LOG("ExecutePidSetCallback cameraId = %{public}s, status = %{public}d, bundleName = %{public}s, "
1187 "flash status = %{public}d",
1188 cameraId.c_str(), info->status, info->bundleName.c_str(), flashStatus);
1189 callback->OnCameraStatusChanged(cameraId, info->status, info->bundleName);
1190 callback->OnFlashlightStatusChanged(cameraId, flashStatus);
1191 } else {
1192 MEDIA_INFO_LOG("ExecutePidSetCallback cameraId = %{public}s, status = 2", cameraId.c_str());
1193 callback->OnCameraStatusChanged(cameraId, static_cast<int32_t>(CameraStatus::CAMERA_STATUS_AVAILABLE), "");
1194 callback->OnFlashlightStatusChanged(cameraId, static_cast<int32_t>(FlashStatus::FLASH_STATUS_UNAVAILABLE));
1195 }
1196 }
1197 }
1198
SetCameraCallback(const sptr<ICameraServiceCallback> & callback)1199 int32_t HCameraService::SetCameraCallback(const sptr<ICameraServiceCallback>& callback)
1200 {
1201 std::vector<std::string> cameraIds;
1202 GetCameraIds(cameraIds);
1203 lock_guard<mutex> lock(cameraCbMutex_);
1204 pid_t pid = IPCSkeleton::GetCallingPid();
1205 MEDIA_INFO_LOG("HCameraService::SetCameraCallback pid = %{public}d", pid);
1206 CHECK_RETURN_RET_ELOG(callback == nullptr, CAMERA_INVALID_ARG,
1207 "HCameraService::SetCameraCallback callback is null");
1208 auto callbackItem = cameraServiceCallbacks_.find(pid);
1209 if (callbackItem != cameraServiceCallbacks_.end()) {
1210 callbackItem->second = nullptr;
1211 (void)cameraServiceCallbacks_.erase(callbackItem);
1212 }
1213 cameraServiceCallbacks_.insert(make_pair(pid, callback));
1214 ExecutePidSetCallback(callback, cameraIds);
1215 return CAMERA_OK;
1216 }
1217
UnSetCameraCallback()1218 int32_t HCameraService::UnSetCameraCallback()
1219 {
1220 pid_t pid = IPCSkeleton::GetCallingPid();
1221 return UnSetCameraCallback(pid);
1222 }
1223
SetMuteCallback(const sptr<ICameraMuteServiceCallback> & callback)1224 int32_t HCameraService::SetMuteCallback(const sptr<ICameraMuteServiceCallback>& callback)
1225 {
1226 CHECK_RETURN_RET_ELOG(!CheckSystemApp(), CAMERA_NO_PERMISSION, "HCameraService::CheckSystemApp fail");
1227 CameraXCollie cameraXCollie = CameraXCollie("HCameraService::SetMuteCallback");
1228 lock_guard<mutex> lock(muteCbMutex_);
1229 pid_t pid = IPCSkeleton::GetCallingPid();
1230 MEDIA_INFO_LOG("HCameraService::SetMuteCallback pid = %{public}d, muteMode:%{public}d", pid, muteModeStored_);
1231 CHECK_RETURN_RET_ELOG(callback == nullptr, CAMERA_INVALID_ARG,
1232 "HCameraService::SetMuteCallback callback is null");
1233 // If the callback set by the SA caller is later than the camera service is started,
1234 // the callback cannot be triggered to obtain the mute state. Therefore,
1235 // when the SA sets the callback, the callback is triggered immediately to return the mute state.
1236 callback->OnCameraMute(muteModeStored_);
1237 cameraMuteServiceCallbacks_.insert(make_pair(pid, callback));
1238 return CAMERA_OK;
1239 }
1240
UnSetMuteCallback()1241 int32_t HCameraService::UnSetMuteCallback()
1242 {
1243 pid_t pid = IPCSkeleton::GetCallingPid();
1244 return UnSetMuteCallback(pid);
1245 }
1246
SetControlCenterCallback(const sptr<IControlCenterStatusCallback> & callback)1247 int32_t HCameraService::SetControlCenterCallback(const sptr<IControlCenterStatusCallback>& callback)
1248 {
1249 lock_guard<recursive_mutex> lock(torchCbMutex_);
1250 pid_t pid = IPCSkeleton::GetCallingPid();
1251 MEDIA_INFO_LOG("HCameraService::SetControlCenterCallback pid = %{public}d", pid);
1252 CHECK_RETURN_RET_ELOG(callback == nullptr, CAMERA_INVALID_ARG,
1253 "HCameraService::SetControlCenterCallback callback is null");
1254 controlcenterCallbacks_.insert(make_pair(pid, callback));
1255 return CAMERA_OK;
1256 }
1257
UnSetControlCenterStatusCallback()1258 int32_t HCameraService::UnSetControlCenterStatusCallback()
1259 {
1260 pid_t pid = IPCSkeleton::GetCallingPid();
1261 return UnSetControlCenterStatusCallback(pid);
1262 }
1263
UnSetControlCenterStatusCallback(pid_t pid)1264 int32_t HCameraService::UnSetControlCenterStatusCallback(pid_t pid)
1265 {
1266 lock_guard<mutex> lock(controlCenterStatusMutex_);
1267 MEDIA_INFO_LOG("HCameraService::UnSetControlCenterStatusCallback pid = %{public}d, size = %{public}zu",
1268 pid, controlcenterCallbacks_.size());
1269 if (!controlcenterCallbacks_.empty()) {
1270 MEDIA_INFO_LOG("UnSetControlCenterStatusCallback controlcenterCallbacks_ is not empty, reset it");
1271 auto it = controlcenterCallbacks_.find(pid);
1272 bool isErasePid = (it != controlcenterCallbacks_.end()) && (it->second);
1273 if (isErasePid) {
1274 it->second = nullptr;
1275 controlcenterCallbacks_.erase(it);
1276 }
1277 }
1278 MEDIA_INFO_LOG("HCameraService::UnSetControlCenterStatusCallback after erase pid = %{public}d, size = %{public}zu",
1279 pid, controlcenterCallbacks_.size());
1280 return CAMERA_OK;
1281 }
1282
GetControlCenterStatus(bool & status)1283 int32_t HCameraService::GetControlCenterStatus(bool& status)
1284 {
1285 MEDIA_INFO_LOG("HCameraService::GetControlCenterStatus");
1286 CHECK_RETURN_RET_ELOG(!controlCenterPrecondition, CAMERA_OK,
1287 "HCameraService::GetControlCenterStatus precondition false.");
1288 status = isControlCenterEnabled_;
1289 return CAMERA_OK;
1290 }
1291
CheckControlCenterPermission()1292 int32_t HCameraService::CheckControlCenterPermission()
1293 {
1294 MEDIA_INFO_LOG("HCameraService::CheckControlCenterPermission");
1295 int32_t ret = CheckPermission(OHOS_PERMISSION_CAMERA_CONTROL, IPCSkeleton::GetCallingTokenID());
1296 CHECK_RETURN_RET_ELOG(ret != CAMERA_OK, ret, "CheckPermission argumentis failed!");
1297 return CAMERA_OK;
1298 }
1299
SetTorchCallback(const sptr<ITorchServiceCallback> & callback)1300 int32_t HCameraService::SetTorchCallback(const sptr<ITorchServiceCallback>& callback)
1301 {
1302 lock_guard<recursive_mutex> lock(torchCbMutex_);
1303 pid_t pid = IPCSkeleton::GetCallingPid();
1304 MEDIA_INFO_LOG("HCameraService::SetTorchCallback pid = %{public}d", pid);
1305 CHECK_RETURN_RET_ELOG(callback == nullptr, CAMERA_INVALID_ARG,
1306 "HCameraService::SetTorchCallback callback is null");
1307 torchServiceCallbacks_.insert(make_pair(pid, callback));
1308
1309 MEDIA_INFO_LOG("HCameraService::SetTorchCallback notify pid = %{public}d", pid);
1310 callback->OnTorchStatusChange(torchStatus_);
1311 return CAMERA_OK;
1312 }
1313
UnSetTorchCallback()1314 int32_t HCameraService::UnSetTorchCallback()
1315 {
1316 pid_t pid = IPCSkeleton::GetCallingPid();
1317 return UnSetTorchCallback(pid);
1318 }
1319
SetFoldStatusCallback(const sptr<IFoldServiceCallback> & callback,bool isInnerCallback)1320 int32_t HCameraService::SetFoldStatusCallback(const sptr<IFoldServiceCallback>& callback, bool isInnerCallback)
1321 {
1322 lock_guard<recursive_mutex> lock(foldCbMutex_);
1323 isFoldable = isFoldableInit ? isFoldable : g_isFoldScreen;
1324 CHECK_EXECUTE((isFoldable && !isFoldRegister), RegisterFoldStatusListener());
1325 if (isInnerCallback) {
1326 innerFoldCallback_ = callback;
1327 } else {
1328 pid_t pid = IPCSkeleton::GetCallingPid();
1329 MEDIA_INFO_LOG("HCameraService::SetFoldStatusCallback pid = %{public}d", pid);
1330 CHECK_RETURN_RET_ELOG(
1331 callback == nullptr, CAMERA_INVALID_ARG, "HCameraService::SetFoldStatusCallback callback is null");
1332 foldServiceCallbacks_.insert(make_pair(pid, callback));
1333 }
1334 return CAMERA_OK;
1335 }
1336
UnSetFoldStatusCallback()1337 int32_t HCameraService::UnSetFoldStatusCallback()
1338 {
1339 pid_t pid = IPCSkeleton::GetCallingPid();
1340 return UnSetFoldStatusCallback(pid);
1341 }
1342
UnSetCameraCallback(pid_t pid)1343 int32_t HCameraService::UnSetCameraCallback(pid_t pid)
1344 {
1345 lock_guard<mutex> lock(cameraCbMutex_);
1346 MEDIA_INFO_LOG("HCameraService::UnSetCameraCallback pid = %{public}d, size = %{public}zu",
1347 pid, cameraServiceCallbacks_.size());
1348 if (!cameraServiceCallbacks_.empty()) {
1349 MEDIA_INFO_LOG("HCameraService::UnSetCameraCallback cameraServiceCallbacks_ is not empty, reset it");
1350 auto it = cameraServiceCallbacks_.find(pid);
1351 if ((it != cameraServiceCallbacks_.end()) && (it->second != nullptr)) {
1352 it->second = nullptr;
1353 cameraServiceCallbacks_.erase(it);
1354 }
1355 }
1356 MEDIA_INFO_LOG("HCameraService::UnSetCameraCallback after erase pid = %{public}d, size = %{public}zu",
1357 pid, cameraServiceCallbacks_.size());
1358 return CAMERA_OK;
1359 }
1360
UnSetMuteCallback(pid_t pid)1361 int32_t HCameraService::UnSetMuteCallback(pid_t pid)
1362 {
1363 lock_guard<mutex> lock(muteCbMutex_);
1364 MEDIA_INFO_LOG("HCameraService::UnSetMuteCallback pid = %{public}d, size = %{public}zu",
1365 pid, cameraMuteServiceCallbacks_.size());
1366 if (!cameraMuteServiceCallbacks_.empty()) {
1367 MEDIA_INFO_LOG("HCameraService::UnSetMuteCallback cameraMuteServiceCallbacks_ is not empty, reset it");
1368 auto it = cameraMuteServiceCallbacks_.find(pid);
1369 if ((it != cameraMuteServiceCallbacks_.end()) && (it->second)) {
1370 it->second = nullptr;
1371 cameraMuteServiceCallbacks_.erase(it);
1372 }
1373 }
1374
1375 MEDIA_INFO_LOG("HCameraService::UnSetMuteCallback after erase pid = %{public}d, size = %{public}zu",
1376 pid, cameraMuteServiceCallbacks_.size());
1377 return CAMERA_OK;
1378 }
1379
UnSetTorchCallback(pid_t pid)1380 int32_t HCameraService::UnSetTorchCallback(pid_t pid)
1381 {
1382 lock_guard<recursive_mutex> lock(torchCbMutex_);
1383 MEDIA_INFO_LOG("HCameraService::UnSetTorchCallback pid = %{public}d, size = %{public}zu",
1384 pid, torchServiceCallbacks_.size());
1385 if (!torchServiceCallbacks_.empty()) {
1386 MEDIA_INFO_LOG("HCameraService::UnSetTorchCallback torchServiceCallbacks_ is not empty, reset it");
1387 auto it = torchServiceCallbacks_.find(pid);
1388 if ((it != torchServiceCallbacks_.end()) && (it->second)) {
1389 it->second = nullptr;
1390 torchServiceCallbacks_.erase(it);
1391 }
1392 }
1393
1394 MEDIA_INFO_LOG("HCameraService::UnSetTorchCallback after erase pid = %{public}d, size = %{public}zu",
1395 pid, torchServiceCallbacks_.size());
1396 return CAMERA_OK;
1397 }
1398
UnSetFoldStatusCallback(pid_t pid)1399 int32_t HCameraService::UnSetFoldStatusCallback(pid_t pid)
1400 {
1401 lock_guard<recursive_mutex> lock(foldCbMutex_);
1402 MEDIA_INFO_LOG("HCameraService::UnSetFoldStatusCallback pid = %{public}d, size = %{public}zu",
1403 pid, foldServiceCallbacks_.size());
1404 if (!foldServiceCallbacks_.empty()) {
1405 MEDIA_INFO_LOG("HCameraService::UnSetFoldStatusCallback foldServiceCallbacks_ is not empty, reset it");
1406 auto it = foldServiceCallbacks_.find(pid);
1407 if ((it != foldServiceCallbacks_.end()) && (it->second)) {
1408 it->second = nullptr;
1409 foldServiceCallbacks_.erase(it);
1410 }
1411 }
1412 MEDIA_INFO_LOG("HCameraService::UnSetFoldStatusCallback after erase pid = %{public}d, size = %{public}zu",
1413 pid, foldServiceCallbacks_.size());
1414 innerFoldCallback_ = nullptr;
1415 return CAMERA_OK;
1416 }
1417
RegisterFoldStatusListener()1418 void HCameraService::RegisterFoldStatusListener()
1419 {
1420 MEDIA_INFO_LOG("RegisterFoldStatusListener is called");
1421 preFoldStatus_ = (FoldStatus)OHOS::Rosen::DisplayManager::GetInstance().GetFoldStatus();
1422 auto ret = OHOS::Rosen::DisplayManager::GetInstance().RegisterFoldStatusListener(this);
1423 CHECK_RETURN_ELOG(ret != OHOS::Rosen::DMError::DM_OK, "RegisterFoldStatusListener failed");
1424 isFoldRegister = true;
1425 }
1426
UnregisterFoldStatusListener()1427 void HCameraService::UnregisterFoldStatusListener()
1428 {
1429 MEDIA_INFO_LOG("UnregisterFoldStatusListener is called");
1430 auto ret = OHOS::Rosen::DisplayManager::GetInstance().UnregisterFoldStatusListener(this);
1431 preFoldStatus_ = FoldStatus::UNKNOWN_FOLD;
1432 CHECK_PRINT_ELOG(ret != OHOS::Rosen::DMError::DM_OK, "UnregisterFoldStatusListener failed");
1433 isFoldRegister = false;
1434 }
1435
UnSetAllCallback(pid_t pid)1436 int32_t HCameraService::UnSetAllCallback(pid_t pid)
1437 {
1438 MEDIA_INFO_LOG("HCameraService::UnSetAllCallback enter");
1439 UnSetCameraCallback(pid);
1440 UnSetMuteCallback(pid);
1441 UnSetTorchCallback(pid);
1442 UnSetFoldStatusCallback(pid);
1443 return CAMERA_OK;
1444 }
1445
IsCameraMuteSupported(string cameraId)1446 bool HCameraService::IsCameraMuteSupported(string cameraId)
1447 {
1448 bool isMuteSupported = false;
1449 shared_ptr<OHOS::Camera::CameraMetadata> cameraAbility;
1450 int32_t ret = cameraHostManager_->GetCameraAbility(cameraId, cameraAbility);
1451 CHECK_RETURN_RET_ELOG(ret != CAMERA_OK, false, "HCameraService::IsCameraMuted GetCameraAbility failed");
1452 camera_metadata_item_t item;
1453 common_metadata_header_t* metadata = cameraAbility->get();
1454 ret = OHOS::Camera::FindCameraMetadataItem(metadata, OHOS_ABILITY_MUTE_MODES, &item);
1455 CHECK_RETURN_RET_ELOG(
1456 ret != CAM_META_SUCCESS, false, "HCameraService::IsCameraMuted not find MUTE ability, ret: %{public}d", ret);
1457 for (uint32_t i = 0; i < item.count; i++) {
1458 MEDIA_INFO_LOG("OHOS_ABILITY_MUTE_MODES %{public}d th is %{public}d", i, item.data.u8[i]);
1459 if (item.data.u8[i] == OHOS_CAMERA_MUTE_MODE_SOLID_COLOR_BLACK) {
1460 isMuteSupported = true;
1461 break;
1462 }
1463 }
1464 MEDIA_DEBUG_LOG("HCameraService::IsCameraMuted supported: %{public}d", isMuteSupported);
1465 return isMuteSupported;
1466 }
1467
UpdateMuteSetting(sptr<HCameraDevice> cameraDevice,bool muteMode)1468 int32_t HCameraService::UpdateMuteSetting(sptr<HCameraDevice> cameraDevice, bool muteMode)
1469 {
1470 constexpr int32_t DEFAULT_ITEMS = 1;
1471 constexpr int32_t DEFAULT_DATA_LENGTH = 1;
1472 shared_ptr<OHOS::Camera::CameraMetadata> changedMetadata =
1473 make_shared<OHOS::Camera::CameraMetadata>(DEFAULT_ITEMS, DEFAULT_DATA_LENGTH);
1474 int32_t count = 1;
1475 uint8_t mode = muteMode ? OHOS_CAMERA_MUTE_MODE_SOLID_COLOR_BLACK : OHOS_CAMERA_MUTE_MODE_OFF;
1476
1477 MEDIA_DEBUG_LOG("UpdateMuteSetting muteMode: %{public}d", muteMode);
1478
1479 bool status = AddOrUpdateMetadata(changedMetadata, OHOS_CONTROL_MUTE_MODE, &mode, count);
1480 int32_t ret = cameraDevice->UpdateSetting(changedMetadata);
1481 CHECK_RETURN_RET_ELOG(!status || ret != CAMERA_OK, CAMERA_UNKNOWN_ERROR, "UpdateMuteSetting muteMode Failed");
1482 return CAMERA_OK;
1483 }
1484
MuteCameraFunc(bool muteMode)1485 int32_t HCameraService::MuteCameraFunc(bool muteMode)
1486 {
1487 {
1488 lock_guard<mutex> lock(g_dataShareHelperMutex);
1489 cameraHostManager_->SetMuteMode(muteMode);
1490 }
1491 int32_t ret = CAMERA_OK;
1492 bool currentMuteMode = muteModeStored_;
1493 sptr<HCameraDeviceManager> deviceManager = HCameraDeviceManager::GetInstance();
1494 std::vector<sptr<HCameraDeviceHolder>> deviceHolderVector = deviceManager->GetActiveCameraHolders();
1495 if (deviceHolderVector.size() == 0) {
1496 OnMute(muteMode);
1497 int32_t retCode = SetMuteModeByDataShareHelper(muteMode);
1498 muteModeStored_ = muteMode;
1499 if (retCode != CAMERA_OK) {
1500 MEDIA_ERR_LOG("no activeClient, SetMuteModeByDataShareHelper: ret=%{public}d", retCode);
1501 muteModeStored_ = currentMuteMode;
1502 }
1503 return retCode;
1504 }
1505 for (sptr<HCameraDeviceHolder> activeDeviceHolder : deviceHolderVector) {
1506 sptr<HCameraDevice> activeDevice = activeDeviceHolder->GetDevice();
1507 if (activeDevice != nullptr) {
1508 string cameraId = activeDevice->GetCameraId();
1509 CHECK_RETURN_RET_ELOG(!IsCameraMuteSupported(cameraId), CAMERA_UNSUPPORTED,
1510 "Not Supported Mute,cameraId: %{public}s", cameraId.c_str());
1511 if (activeDevice != nullptr) {
1512 ret = UpdateMuteSetting(activeDevice, muteMode);
1513 }
1514 if (ret != CAMERA_OK) {
1515 MEDIA_ERR_LOG("UpdateMuteSetting Failed, cameraId: %{public}s", cameraId.c_str());
1516 muteModeStored_ = currentMuteMode;
1517 }
1518 }
1519 CHECK_EXECUTE(activeDevice != nullptr, activeDevice->SetDeviceMuteMode(muteMode));
1520 }
1521
1522 CHECK_EXECUTE(ret == CAMERA_OK, OnMute(muteMode));
1523 ret = SetMuteModeByDataShareHelper(muteMode);
1524 if (ret == CAMERA_OK) {
1525 muteModeStored_ = muteMode;
1526 }
1527 return ret;
1528 }
1529
EnableControlCenter(bool status,bool needPersistEnable)1530 int32_t HCameraService::EnableControlCenter(bool status, bool needPersistEnable)
1531 {
1532 MEDIA_INFO_LOG("HCameraService::EnableControlCenter");
1533 CHECK_RETURN_RET_ELOG(!controlCenterPrecondition, CAMERA_INVALID_STATE, "ControlCenterPrecondition false.");
1534 lock_guard<mutex> lock(controlCenterStatusMutex_);
1535
1536 auto ret = UpdateDataShareAndTag(status, needPersistEnable);
1537 CHECK_RETURN_RET_ELOG(ret != CAMERA_OK, ret, "UpdateDataShareAndTag failed.");
1538
1539 MEDIA_INFO_LOG("EnableControlCenter success.");
1540 isControlCenterEnabled_ = status;
1541 CHECK_RETURN_RET_ELOG(controlcenterCallbacks_.empty(), ret, "IControlCenterStatusCallback is empty.");
1542 for (auto it : controlcenterCallbacks_) {
1543 if (it.second == nullptr) {
1544 MEDIA_ERR_LOG("OnControlCenterStatusChanged pid:%{public}d Callbacks is null", it.first);
1545 continue;
1546 }
1547 uint32_t pid = it.first;
1548 if (ShouldSkipStatusUpdates(pid)) {
1549 continue;
1550 }
1551 it.second->OnControlCenterStatusChanged(status);
1552 }
1553 return ret;
1554 }
1555
SetControlCenterPrecondition(bool condition)1556 int32_t HCameraService::SetControlCenterPrecondition(bool condition)
1557 {
1558 std::lock_guard<std::mutex> lock(mutex_);
1559 MEDIA_INFO_LOG("HCameraService::SetControlCenterPrecondition %{public}d", condition);
1560 controlCenterPrecondition = condition;
1561 if (videoSessionForControlCenter_ != nullptr) {
1562 videoSessionForControlCenter_->SetControlCenterPrecondition(controlCenterPrecondition);
1563 } else {
1564 MEDIA_WARNING_LOG("");
1565 }
1566 CHECK_RETURN_RET_DLOG(controlCenterPrecondition || !isControlCenterEnabled_, CAMERA_OK,
1567 "SetControlCenterPrecondition success.");
1568 auto ret = EnableControlCenter(false, true);
1569 CHECK_RETURN_RET_ELOG(ret != CAMERA_OK, ret, "EnableControlCenter failed.");
1570 isControlCenterEnabled_ = false;
1571 for (auto it : controlcenterCallbacks_) {
1572 if (it.second == nullptr) {
1573 MEDIA_ERR_LOG("OnControlCenterStatusChanged pid:%{public}d Callbacks is null", it.first);
1574 continue;
1575 }
1576 uint32_t pid = it.first;
1577 if (ShouldSkipStatusUpdates(pid)) {
1578 continue;
1579 }
1580 it.second->OnControlCenterStatusChanged(false);
1581 }
1582 return CAMERA_OK;
1583 }
1584
SetDeviceControlCenterAbility(bool ability)1585 int32_t HCameraService::SetDeviceControlCenterAbility(bool ability)
1586 {
1587 std::lock_guard<std::mutex> lock(mutex_);
1588 deviceControlCenterAbility = ability;
1589 if (videoSessionForControlCenter_ != nullptr) {
1590 videoSessionForControlCenter_->SetDeviceControlCenterAbility(ability);
1591 }
1592 return CAMERA_OK;
1593 }
1594
CacheCameraStatus(const string & cameraId,std::shared_ptr<CameraStatusCallbacksInfo> info)1595 void HCameraService::CacheCameraStatus(const string& cameraId, std::shared_ptr<CameraStatusCallbacksInfo> info)
1596 {
1597 std::lock_guard<std::mutex> lock(cameraStatusCallbacksMutex_);
1598 cameraStatusCallbacks_[cameraId] = info;
1599 }
1600
GetCachedCameraStatus(const string & cameraId)1601 std::shared_ptr<CameraStatusCallbacksInfo> HCameraService::GetCachedCameraStatus(const string& cameraId)
1602 {
1603 std::lock_guard<std::mutex> lock(cameraStatusCallbacksMutex_);
1604 auto it = cameraStatusCallbacks_.find(cameraId);
1605 return it == cameraStatusCallbacks_.end() ? nullptr : it->second;
1606 }
1607
CacheFlashStatus(const string & cameraId,FlashStatus flashStatus)1608 void HCameraService::CacheFlashStatus(const string& cameraId, FlashStatus flashStatus)
1609 {
1610 std::lock_guard<std::mutex> lock(flashStatusCallbacksMutex_);
1611 flashStatusCallbacks_[cameraId] = flashStatus;
1612 }
1613
GetCachedFlashStatus(const string & cameraId)1614 FlashStatus HCameraService::GetCachedFlashStatus(const string& cameraId)
1615 {
1616 std::lock_guard<std::mutex> lock(flashStatusCallbacksMutex_);
1617 auto it = flashStatusCallbacks_.find(cameraId);
1618 return it == flashStatusCallbacks_.end() ? FlashStatus::FLASH_STATUS_UNAVAILABLE : it->second;
1619 }
1620
1621 static std::map<PolicyType, Security::AccessToken::PolicyType> g_policyTypeMap_ = {
1622 {PolicyType::EDM, Security::AccessToken::PolicyType::EDM},
1623 {PolicyType::PRIVACY, Security::AccessToken::PolicyType::PRIVACY},
1624 };
1625
MuteCamera(bool muteMode)1626 int32_t HCameraService::MuteCamera(bool muteMode)
1627 {
1628 CHECK_RETURN_RET_ELOG(!CheckSystemApp(), CAMERA_NO_PERMISSION, "HCameraService::CheckSystemApp fail");
1629 CameraXCollie cameraXCollie = CameraXCollie("HCameraService::MuteCamera");
1630 int32_t ret = CheckPermission(OHOS_PERMISSION_MANAGE_CAMERA_CONFIG, IPCSkeleton::GetCallingTokenID());
1631 CHECK_RETURN_RET_ELOG(ret != CAMERA_OK, ret, "CheckPermission argumentis failed!");
1632 CameraReportUtils::GetInstance().ReportUserBehavior(DFX_UB_MUTE_CAMERA,
1633 to_string(muteMode), CameraReportUtils::GetCallerInfo());
1634 return MuteCameraFunc(muteMode);
1635 }
1636
MuteCameraPersist(PolicyType policyType,bool isMute)1637 int32_t HCameraService::MuteCameraPersist(PolicyType policyType, bool isMute)
1638 {
1639 CHECK_RETURN_RET_ELOG(!CheckSystemApp(), CAMERA_NO_PERMISSION, "HCameraService::CheckSystemApp fail");
1640 CameraXCollie cameraXCollie = CameraXCollie("HCameraService::MuteCameraPersist");
1641 OHOS::Security::AccessToken::AccessTokenID callerToken = IPCSkeleton::GetCallingTokenID();
1642 int32_t ret = CheckPermission(OHOS_PERMISSION_CAMERA_CONTROL, callerToken);
1643 CHECK_RETURN_RET_ELOG(ret != CAMERA_OK, ret, "CheckPermission arguments failed!");
1644 CameraReportUtils::GetInstance().ReportUserBehavior(DFX_UB_MUTE_CAMERA,
1645 to_string(isMute), CameraReportUtils::GetCallerInfo());
1646 CHECK_RETURN_RET_ELOG(g_policyTypeMap_.count(policyType) == 0, CAMERA_INVALID_ARG,
1647 "MuteCameraPersist Failed, invalid param policyType = %{public}d", static_cast<int32_t>(policyType));
1648 bool targetMuteMode = isMute;
1649 const Security::AccessToken::PolicyType secPolicyType = g_policyTypeMap_[policyType];
1650 const Security::AccessToken::CallerType secCaller = Security::AccessToken::CallerType::CAMERA;
1651 ret = Security::AccessToken::PrivacyKit::SetMutePolicy(secPolicyType, secCaller, isMute, callerToken);
1652 // LCOV_EXCL_START
1653 if (ret != Security::AccessToken::RET_SUCCESS) {
1654 MEDIA_ERR_LOG("MuteCameraPersist SetMutePolicy return false, policyType = %{public}d, retCode = %{public}d",
1655 static_cast<int32_t>(policyType), static_cast<int32_t>(ret));
1656 targetMuteMode = muteModeStored_;
1657 }
1658 //LCOV_EXCL_STOP
1659 return MuteCameraFunc(targetMuteMode);
1660 }
1661
PrelaunchCamera(int32_t flag)1662 int32_t HCameraService::PrelaunchCamera(int32_t flag)
1663 {
1664 CAMERA_SYNC_TRACE;
1665 CHECK_RETURN_RET_ELOG(!CheckSystemApp(), CAMERA_NO_PERMISSION, "HCameraService::CheckSystemApp fail");
1666 CameraXCollie cameraXCollie = CameraXCollie("HCameraService::PrelaunchCamera");
1667 MEDIA_INFO_LOG("HCameraService::PrelaunchCamera");
1668 CHECK_RETURN_RET_ELOG(torchStatus_ == TorchStatus::TORCH_STATUS_ON,
1669 CAMERA_DEVICE_CONFLICT, "HCameraService::PrelaunchCamera torch is running, abort!");
1670 #ifdef MEMMGR_OVERRID
1671 PrelaunchRequireMemory(flag);
1672 #endif
1673 // only touch up and no flag enable prelaunch
1674 if ((flag != 1) && (flag != -1)) {
1675 return CAMERA_OK;
1676 }
1677 MEDIA_INFO_LOG("HCameraService::PrelaunchCamera E");
1678 CHECK_RETURN_RET_ELOG(HCameraDeviceManager::GetInstance()->GetCameraStateOfASide().Size() != 0,
1679 CAMERA_DEVICE_CONFLICT, "HCameraService::PrelaunchCamera there is a device active in A side, abort!");
1680 if (preCameraId_.empty()) {
1681 MEDIA_DEBUG_LOG("HCameraService::PrelaunchCamera firstBoot in");
1682 if (OHOS::Rosen::DisplayManager::GetInstance().IsFoldable()) { // LCOV_EXCL_LINE
1683 // foldable devices
1684 MEDIA_DEBUG_LOG("HCameraService::PrelaunchCamera firstBoot foldable");
1685 FoldStatus curFoldStatus = (FoldStatus)OHOS::Rosen::DisplayManager::GetInstance().GetFoldStatus();
1686 MEDIA_DEBUG_LOG("HCameraService::PrelaunchCamera curFoldStatus:%d", curFoldStatus);
1687 std::vector<std::string> cameraIds;
1688 std::vector<std::shared_ptr<OHOS::Camera::CameraMetadata>> cameraAbilityList;
1689 int32_t retCode = GetCameras(cameraIds, cameraAbilityList);
1690 CHECK_RETURN_RET_ELOG(retCode != CAMERA_OK, CAMERA_OK, "HCameraService::PrelaunchCamera exit");
1691 int8_t camIdx = ChooseFisrtBootFoldCamIdx(curFoldStatus, cameraAbilityList);
1692 CHECK_RETURN_RET_ELOG(camIdx == -1, CAMERA_OK, "HCameraService::PrelaunchCamera exit");
1693 preCameraId_ = cameraIds[camIdx];
1694 } else {
1695 // unfoldable devices
1696 MEDIA_DEBUG_LOG("HCameraService::PrelaunchCamera firstBoot unfoldable");
1697 vector<string> cameraIds_;
1698 cameraHostManager_->GetCameras(cameraIds_);
1699 CHECK_RETURN_RET_ELOG(cameraIds_.empty(), CAMERA_OK, "HCameraService::PrelaunchCamera exit");
1700 preCameraId_ = cameraIds_.front();
1701 }
1702 }
1703 MEDIA_INFO_LOG("HCameraService::PrelaunchCamera preCameraId_ is: %{public}s", preCameraId_.c_str());
1704 CAMERA_SYSEVENT_STATISTIC(CreateMsg("Camera Prelaunch CameraId:%s", preCameraId_.c_str()));
1705 CameraReportUtils::GetInstance().SetOpenCamPerfPreInfo(preCameraId_.c_str(), CameraReportUtils::GetCallerInfo());
1706 int32_t ret = cameraHostManager_->Prelaunch(preCameraId_, preCameraClient_);
1707 CHECK_PRINT_ELOG(ret != CAMERA_OK, "HCameraService::Prelaunch failed");
1708 return ret;
1709 }
1710
ResetRssPriority()1711 int32_t HCameraService::ResetRssPriority()
1712 {
1713 CHECK_RETURN_RET_ELOG(!CheckSystemApp(), CAMERA_NO_PERMISSION, "HCameraService::CheckSystemApp fail");
1714 CameraXCollie cameraXCollie = CameraXCollie("HCameraService::ResetRssPriority");
1715 MEDIA_INFO_LOG("HCameraService::ResetRssPriority");
1716 std::unordered_map<std::string, std::string> payload;
1717 OHOS::ResourceSchedule::ResSchedClient::GetInstance()
1718 .ReportData(ResourceSchedule::ResType::RES_TYPE_CAMERA_RESET_PRIORITY, 0, payload);
1719 return CAMERA_OK;
1720 }
1721
1722 // LCOV_EXCL_START
1723 /**
1724 camIdx select strategy:
1725 1. make sure curFoldStatus match foldStatusValue
1726 2. priority: BACK > FRONT > OTHER
1727 curFoldStatus 0: UNKNOWN_FOLD
1728 curFoldStatus 1: EXPAND
1729 curFoldStatus 2: FOLDED
1730 curFoldStatus 3: HALF_FOLD
1731 foldStatusValue 0: OHOS_CAMERA_FOLD_STATUS_NONFOLDABLE
1732 foldStatusValue 1: OHOS_CAMERA_FOLD_STATUS_EXPANDED
1733 foldStatusValue 2: OHOS_CAMERA_FOLD_STATUS_FOLDED
1734 foldStatusValue 3: OHOS_CAMERA_FOLD_STATUS_EXPANDED + OHOS_CAMERA_FOLD_STATUS_FOLDED
1735 positionValue 0: OHOS_CAMERA_POSITION_FRONT
1736 positionValue 1: OHOS_CAMERA_POSITION_BACK
1737 positionValue 2: OHOS_CAMERA_POSITION_OTHER
1738 */
ChooseFisrtBootFoldCamIdx(FoldStatus curFoldStatus,std::vector<std::shared_ptr<OHOS::Camera::CameraMetadata>> cameraAbilityList)1739 int8_t HCameraService::ChooseFisrtBootFoldCamIdx(
1740 FoldStatus curFoldStatus, std::vector<std::shared_ptr<OHOS::Camera::CameraMetadata>> cameraAbilityList)
1741 {
1742 int8_t camIdx = -1;
1743 uint8_t foldStatusValue = 0;
1744 uint8_t positionValue = 0;
1745 uint8_t EXPAND_SUPPORT = 1;
1746 uint8_t FOLD_SUPPORT = 2;
1747 uint8_t ALL_SUPPORT = 3;
1748 for (size_t i = 0; i < cameraAbilityList.size(); i++) {
1749 camera_metadata_item_t item;
1750 int ret =
1751 OHOS::Camera::FindCameraMetadataItem(cameraAbilityList[i]->get(), OHOS_ABILITY_CAMERA_FOLD_STATUS, &item);
1752 if (ret == CAM_META_SUCCESS && item.count > 0) {
1753 MEDIA_DEBUG_LOG("HCameraService::PrelaunchCamera device fold ablity is %{public}d", item.data.u8[0]);
1754 foldStatusValue = item.data.u8[0];
1755 } else {
1756 MEDIA_DEBUG_LOG("HCameraService::PrelaunchCamera device ablity not found");
1757 foldStatusValue = 0;
1758 }
1759 ret = OHOS::Camera::FindCameraMetadataItem(cameraAbilityList[i]->get(), OHOS_ABILITY_CAMERA_POSITION, &item);
1760 if (ret == CAM_META_SUCCESS && item.count > 0) {
1761 MEDIA_DEBUG_LOG("HCameraService::PrelaunchCamera device position is %{public}d", item.data.u8[0]);
1762 positionValue = item.data.u8[0];
1763 } else {
1764 MEDIA_DEBUG_LOG("HCameraService::PrelaunchCamera device position not found");
1765 positionValue = 0;
1766 }
1767 // check is fold supported
1768 bool isFoldSupported = false;
1769 if (curFoldStatus == FoldStatus::FOLDED) {
1770 isFoldSupported = (foldStatusValue == FOLD_SUPPORT || foldStatusValue == ALL_SUPPORT);
1771 } else if (curFoldStatus == FoldStatus::EXPAND || curFoldStatus == FoldStatus::HALF_FOLD) {
1772 isFoldSupported = (foldStatusValue == EXPAND_SUPPORT || foldStatusValue == ALL_SUPPORT);
1773 }
1774 // choose camIdx by priority
1775 if (isFoldSupported) {
1776 if (positionValue == OHOS_CAMERA_POSITION_BACK) {
1777 camIdx = i;
1778 break; // use BACK
1779 } else if (positionValue == OHOS_CAMERA_POSITION_FRONT && camIdx == -1) {
1780 camIdx = i; // record FRONT find BACK continue
1781 } else if (positionValue == OHOS_CAMERA_POSITION_OTHER && camIdx == -1) {
1782 camIdx = i; // record OTHER find BACK&FRONT continue
1783 }
1784 }
1785 }
1786 return camIdx;
1787 }
1788 // LCOV_EXCL_STOP
1789
PreSwitchCamera(const std::string & cameraId)1790 int32_t HCameraService::PreSwitchCamera(const std::string& cameraId)
1791 {
1792 CAMERA_SYNC_TRACE;
1793 CHECK_RETURN_RET_ELOG(!CheckSystemApp(), CAMERA_NO_PERMISSION, "HCameraService::CheckSystemApp fail");
1794 CameraXCollie cameraXCollie = CameraXCollie("HCameraService::PreSwitchCamera");
1795 MEDIA_INFO_LOG("HCameraService::PreSwitchCamera");
1796 CHECK_RETURN_RET(cameraId.empty() || cameraId.length() > PATH_MAX, CAMERA_INVALID_ARG);
1797 std::vector<std::string> cameraIds_;
1798 cameraHostManager_->GetCameras(cameraIds_);
1799 CHECK_RETURN_RET(cameraIds_.empty(), CAMERA_INVALID_STATE);
1800 auto it = std::find(cameraIds_.begin(), cameraIds_.end(), cameraId);
1801 CHECK_RETURN_RET(it == cameraIds_.end(), CAMERA_INVALID_ARG);
1802 MEDIA_INFO_LOG("HCameraService::PreSwitchCamera cameraId is: %{public}s", cameraId.c_str());
1803 CameraReportUtils::GetInstance().SetSwitchCamPerfStartInfo(CameraReportUtils::GetCallerInfo());
1804 int32_t ret = cameraHostManager_->PreSwitchCamera(cameraId);
1805 CHECK_PRINT_ELOG(ret != CAMERA_OK, "HCameraService::Prelaunch failed");
1806 return ret;
1807 }
1808
SetPrelaunchConfig(const string & cameraId,RestoreParamTypeOhos restoreParamType,int activeTime,const EffectParam & effectParam)1809 int32_t HCameraService::SetPrelaunchConfig(const string& cameraId, RestoreParamTypeOhos restoreParamType,
1810 int activeTime, const EffectParam& effectParam)
1811 {
1812 CAMERA_SYNC_TRACE;
1813 CHECK_RETURN_RET_ELOG(!CheckSystemApp(), CAMERA_NO_PERMISSION, "HCameraService::CheckSystemApp fail");
1814 CameraXCollie cameraXCollie = CameraXCollie("HCameraService::SetPrelaunchConfig");
1815 OHOS::Security::AccessToken::AccessTokenID callerToken = IPCSkeleton::GetCallingTokenID();
1816 string permissionName = OHOS_PERMISSION_CAMERA;
1817 int32_t ret = CheckPermission(permissionName, callerToken);
1818 CHECK_RETURN_RET_ELOG(ret != CAMERA_OK, ret,
1819 "HCameraService::SetPrelaunchConfig failed permission is: %{public}s", permissionName.c_str());
1820
1821 MEDIA_INFO_LOG("HCameraService::SetPrelaunchConfig cameraId %{public}s", (cameraId).c_str());
1822 vector<string> cameraIds_;
1823 cameraHostManager_->GetCameras(cameraIds_);
1824 if ((find(cameraIds_.begin(), cameraIds_.end(), cameraId) != cameraIds_.end()) && IsPrelaunchSupported(cameraId)) {
1825 preCameraId_ = cameraId;
1826 MEDIA_INFO_LOG("CameraHostInfo::SetPrelaunchConfig for cameraId %{public}s", (cameraId).c_str());
1827 sptr<HCaptureSession> captureSession_ = nullptr;
1828 pid_t pid = IPCSkeleton::GetCallingPid();
1829 auto &sessionManager = HCameraSessionManager::GetInstance();
1830 captureSession_ = sessionManager.GetGroupDefaultSession(pid);
1831 SaveCurrentParamForRestore(cameraId, static_cast<RestoreParamTypeOhos>(restoreParamType), activeTime,
1832 effectParam, captureSession_);
1833 } else {
1834 MEDIA_ERR_LOG("HCameraService::SetPrelaunchConfig illegal");
1835 ret = CAMERA_INVALID_ARG;
1836 }
1837 return ret;
1838 }
1839
SetTorchLevel(float level)1840 int32_t HCameraService::SetTorchLevel(float level)
1841 {
1842 int32_t ret = cameraHostManager_->SetTorchLevel(level);
1843 CHECK_PRINT_ELOG(ret != CAMERA_OK, "Failed to SetTorchLevel");
1844 return ret;
1845 }
1846
AllowOpenByOHSide(const std::string & cameraId,int32_t state,bool & canOpenCamera)1847 int32_t HCameraService::AllowOpenByOHSide(const std::string& cameraId, int32_t state, bool& canOpenCamera)
1848 {
1849 MEDIA_INFO_LOG("HCameraService::AllowOpenByOHSide start");
1850 std::vector<pid_t> activePids = HCameraDeviceManager::GetInstance()->GetActiveClient();
1851 if (activePids.size() == 0) {
1852 MEDIA_INFO_LOG("AllowOpenByOHSide::Open allow open camera");
1853 NotifyCameraState(cameraId, 0);
1854 canOpenCamera = true;
1855 return CAMERA_OK;
1856 }
1857 for (auto eachPid : activePids) {
1858 std::vector<sptr<HCameraDevice>> camerasNeedEvict =
1859 HCameraDeviceManager::GetInstance()->GetCamerasByPid(eachPid);
1860 for (auto device : camerasNeedEvict) {
1861 device->OnError(DEVICE_PREEMPT, 0);
1862 device->Close();
1863 NotifyCameraState(cameraId, 0);
1864 }
1865 }
1866 canOpenCamera = true;
1867 MEDIA_INFO_LOG("HCameraService::AllowOpenByOHSide end");
1868 return CAMERA_OK;
1869 }
1870
NotifyCameraState(const std::string & cameraId,int32_t state)1871 int32_t HCameraService::NotifyCameraState(const std::string& cameraId, int32_t state)
1872 {
1873 // 把cameraId和前后台状态刷新给device manager
1874 MEDIA_INFO_LOG(
1875 "HCameraService::NotifyCameraState SetStateOfACamera %{public}s:%{public}d", cameraId.c_str(), state);
1876 HCameraDeviceManager::GetInstance()->SetStateOfACamera(cameraId, state);
1877 return CAMERA_OK;
1878 }
1879
SetPeerCallback(const sptr<ICameraBroker> & callback)1880 int32_t HCameraService::SetPeerCallback(const sptr<ICameraBroker>& callback)
1881 {
1882 MEDIA_INFO_LOG("SetPeerCallback get callback");
1883 CHECK_RETURN_RET(callback == nullptr, CAMERA_INVALID_ARG);
1884 {
1885 std::lock_guard<std::mutex> lock(peerCallbackMutex_);
1886 peerCallback_ = callback;
1887 }
1888 MEDIA_INFO_LOG("HCameraService::SetPeerCallback current muteMode:%{public}d", muteModeStored_);
1889 callback->NotifyMuteCamera(muteModeStored_);
1890 HCameraDeviceManager::GetInstance()->SetPeerCallback(callback);
1891 return CAMERA_OK;
1892 }
1893
UnsetPeerCallback()1894 int32_t HCameraService::UnsetPeerCallback()
1895 {
1896 MEDIA_INFO_LOG("UnsetPeerCallback callback");
1897 {
1898 std::lock_guard<std::mutex> lock(peerCallbackMutex_);
1899 peerCallback_ = nullptr;
1900 }
1901 HCameraDeviceManager::GetInstance()->UnsetPeerCallback();
1902 return CAMERA_OK;
1903 }
1904
IsPrelaunchSupported(string cameraId)1905 bool HCameraService::IsPrelaunchSupported(string cameraId)
1906 {
1907 bool isPrelaunchSupported = false;
1908 shared_ptr<OHOS::Camera::CameraMetadata> cameraAbility;
1909 int32_t ret = cameraHostManager_->GetCameraAbility(cameraId, cameraAbility);
1910 CHECK_RETURN_RET_ELOG(ret != CAMERA_OK, isPrelaunchSupported,
1911 "HCameraService::IsCameraMuted GetCameraAbility failed");
1912 camera_metadata_item_t item;
1913 common_metadata_header_t* metadata = cameraAbility->get();
1914 ret = OHOS::Camera::FindCameraMetadataItem(metadata, OHOS_ABILITY_PRELAUNCH_AVAILABLE, &item);
1915 if (ret == 0) {
1916 MEDIA_INFO_LOG(
1917 "CameraManager::IsPrelaunchSupported() OHOS_ABILITY_PRELAUNCH_AVAILABLE is %{public}d", item.data.u8[0]);
1918 isPrelaunchSupported = (item.data.u8[0] == 1);
1919 } else {
1920 MEDIA_ERR_LOG("Failed to get OHOS_ABILITY_PRELAUNCH_AVAILABLE ret = %{public}d", ret);
1921 }
1922 return isPrelaunchSupported;
1923 }
1924
GetServiceStatus()1925 CameraServiceStatus HCameraService::GetServiceStatus()
1926 {
1927 lock_guard<mutex> lock(serviceStatusMutex_);
1928 return serviceStatus_;
1929 }
1930
SetServiceStatus(CameraServiceStatus serviceStatus)1931 void HCameraService::SetServiceStatus(CameraServiceStatus serviceStatus)
1932 {
1933 lock_guard<mutex> lock(serviceStatusMutex_);
1934 serviceStatus_ = serviceStatus;
1935 MEDIA_DEBUG_LOG("HCameraService::SetServiceStatus success. serviceStatus: %{public}d", serviceStatus);
1936 }
1937
IsTorchSupported(bool & isTorchSupported)1938 int32_t HCameraService::IsTorchSupported(bool &isTorchSupported)
1939 {
1940 isTorchSupported = false;
1941 std::vector<std::string> cameraIds;
1942 std::vector<std::shared_ptr<OHOS::Camera::CameraMetadata>> cameraAbilityList;
1943 int32_t retCode = GetCameras(cameraIds, cameraAbilityList);
1944 CHECK_RETURN_RET_ELOG(retCode != CAMERA_OK, retCode, "HCameraService::IsTorchSupported failed");
1945 for (auto& cameraAbility : cameraAbilityList) {
1946 camera_metadata_item_t item;
1947 int ret = OHOS::Camera::FindCameraMetadataItem(cameraAbility->get(), OHOS_ABILITY_FLASH_AVAILABLE, &item);
1948 if (ret == CAM_META_SUCCESS && item.count > 0) {
1949 MEDIA_DEBUG_LOG("OHOS_ABILITY_FLASH_AVAILABLE is %{public}d", item.data.u8[0]);
1950 if (item.data.u8[0] == 1) { // LCOV_EXCL_LINE
1951 isTorchSupported = true;
1952 break;
1953 }
1954 }
1955 }
1956 MEDIA_DEBUG_LOG("HCameraService::isTorchSupported success. isTorchSupported: %{public}d", isTorchSupported);
1957 return retCode;
1958 }
1959
IsCameraMuteSupported(bool & isCameraMuteSupported)1960 int32_t HCameraService::IsCameraMuteSupported(bool &isCameraMuteSupported)
1961 {
1962 CHECK_RETURN_RET_ELOG(
1963 !CheckSystemApp(), CAMERA_NO_PERMISSION, "HCameraService::IsCameraMuteSupported:SystemApi is called");
1964 std::vector<std::string> cameraIds;
1965 std::vector<std::shared_ptr<OHOS::Camera::CameraMetadata>> cameraAbilityList;
1966 int32_t retCode = GetCameras(cameraIds, cameraAbilityList);
1967 CHECK_RETURN_RET_ELOG(retCode != CAMERA_OK, retCode, "HCameraService::IsCameraMuteSupported failed");
1968 isCameraMuteSupported = std::any_of(
1969 cameraIds.begin(), cameraIds.end(), [&](auto& cameraId) { return IsCameraMuteSupported(cameraId); });
1970 return retCode;
1971 }
1972
IsCameraMuted(bool & muteMode)1973 int32_t HCameraService::IsCameraMuted(bool& muteMode)
1974 {
1975 CAMERA_SYNC_TRACE;
1976 lock_guard<mutex> lock(g_dataShareHelperMutex);
1977 CHECK_RETURN_RET(GetServiceStatus() != CameraServiceStatus::SERVICE_READY, CAMERA_INVALID_STATE);
1978 muteMode = muteModeStored_;
1979
1980 MEDIA_DEBUG_LOG("HCameraService::IsCameraMuted success. isMuted: %{public}d", muteMode);
1981 return CAMERA_OK;
1982 }
1983
DumpCameraSummary(vector<string> cameraIds,CameraInfoDumper & infoDumper)1984 void HCameraService::DumpCameraSummary(vector<string> cameraIds, CameraInfoDumper& infoDumper)
1985 {
1986 infoDumper.Tip("--------Dump Summary Begin-------");
1987 infoDumper.Title("Number of Cameras:[" + to_string(cameraIds.size()) + "]");
1988 infoDumper.Title(
1989 "Number of Active Cameras:[" + to_string(HCameraDeviceManager::GetInstance()->GetActiveCamerasCount()) + "]");
1990 infoDumper.Title("Current session summary:");
1991 HCaptureSession::DumpCameraSessionSummary(infoDumper);
1992 }
1993
DumpCameraInfo(CameraInfoDumper & infoDumper,std::vector<std::string> & cameraIds,std::vector<std::shared_ptr<OHOS::Camera::CameraMetadata>> & cameraAbilityList)1994 void HCameraService::DumpCameraInfo(CameraInfoDumper& infoDumper, std::vector<std::string>& cameraIds,
1995 std::vector<std::shared_ptr<OHOS::Camera::CameraMetadata>>& cameraAbilityList)
1996 {
1997 infoDumper.Tip("--------Dump CameraDevice Begin-------");
1998 int32_t capIdx = 0;
1999 for (auto& it : cameraIds) {
2000 auto metadata = cameraAbilityList[capIdx++];
2001 common_metadata_header_t* metadataEntry = metadata->get();
2002 infoDumper.Title("Camera ID:[" + it + "]:");
2003 infoDumper.Push();
2004 DumpCameraAbility(metadataEntry, infoDumper);
2005 DumpCameraStreamInfo(metadataEntry, infoDumper);
2006 DumpCameraZoom(metadataEntry, infoDumper);
2007 DumpCameraFlash(metadataEntry, infoDumper);
2008 DumpCameraCompensation(metadataEntry, infoDumper);
2009 DumpCameraColorSpace(metadataEntry, infoDumper);
2010 DumpCameraAF(metadataEntry, infoDumper);
2011 DumpCameraAE(metadataEntry, infoDumper);
2012 DumpCameraSensorInfo(metadataEntry, infoDumper);
2013 DumpCameraVideoStabilization(metadataEntry, infoDumper);
2014 DumpCameraVideoFrameRateRange(metadataEntry, infoDumper);
2015 DumpCameraPrelaunch(metadataEntry, infoDumper);
2016 DumpCameraThumbnail(metadataEntry, infoDumper);
2017 infoDumper.Pop();
2018 }
2019 }
2020
DumpCameraAbility(common_metadata_header_t * metadataEntry,CameraInfoDumper & infoDumper)2021 void HCameraService::DumpCameraAbility(common_metadata_header_t* metadataEntry, CameraInfoDumper& infoDumper)
2022 {
2023 camera_metadata_item_t item;
2024 int ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_CAMERA_POSITION, &item);
2025 if (ret == CAM_META_SUCCESS) {
2026 map<int, string>::const_iterator iter = g_cameraPos.find(item.data.u8[0]);
2027 CHECK_EXECUTE(iter != g_cameraPos.end(), infoDumper.Title("Camera Position:[" + iter->second + "]"));
2028 }
2029
2030 ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_CAMERA_TYPE, &item);
2031 if (ret == CAM_META_SUCCESS) {
2032 map<int, string>::const_iterator iter = g_cameraType.find(item.data.u8[0]);
2033 CHECK_EXECUTE(iter != g_cameraType.end(), infoDumper.Title("Camera Type:[" + iter->second + "]"));
2034 }
2035
2036 ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_CAMERA_CONNECTION_TYPE, &item);
2037 if (ret == CAM_META_SUCCESS) {
2038 map<int, string>::const_iterator iter = g_cameraConType.find(item.data.u8[0]);
2039 CHECK_EXECUTE(iter != g_cameraConType.end(),
2040 infoDumper.Title("Camera Connection Type:[" + iter->second + "]"));
2041 }
2042 }
2043
DumpCameraStreamInfo(common_metadata_header_t * metadataEntry,CameraInfoDumper & infoDumper)2044 void HCameraService::DumpCameraStreamInfo(common_metadata_header_t* metadataEntry, CameraInfoDumper& infoDumper)
2045 {
2046 camera_metadata_item_t item;
2047 int ret;
2048 constexpr uint32_t unitLen = 3;
2049 uint32_t widthOffset = 1;
2050 uint32_t heightOffset = 2;
2051 infoDumper.Title("Camera Available stream configuration List:");
2052 infoDumper.Push();
2053 ret =
2054 OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_STREAM_AVAILABLE_BASIC_CONFIGURATIONS, &item);
2055 if (ret == CAM_META_SUCCESS) {
2056 infoDumper.Title("Basic Stream Info Size: " + to_string(item.count / unitLen));
2057 for (uint32_t index = 0; index < item.count; index += unitLen) {
2058 map<int, string>::const_iterator iter = g_cameraFormat.find(item.data.i32[index]);
2059 if (iter != g_cameraFormat.end()) {
2060 infoDumper.Msg("Format:[" + iter->second + "] " +
2061 "Size:[Width:" + to_string(item.data.i32[index + widthOffset]) +
2062 " Height:" + to_string(item.data.i32[index + heightOffset]) + "]");
2063 } else {
2064 infoDumper.Msg("Format:[" + to_string(item.data.i32[index]) + "] " +
2065 "Size:[Width:" + to_string(item.data.i32[index + widthOffset]) +
2066 " Height:" + to_string(item.data.i32[index + heightOffset]) + "]");
2067 }
2068 }
2069 }
2070
2071 infoDumper.Pop();
2072 }
2073
DumpCameraZoom(common_metadata_header_t * metadataEntry,CameraInfoDumper & infoDumper)2074 void HCameraService::DumpCameraZoom(common_metadata_header_t* metadataEntry, CameraInfoDumper& infoDumper)
2075 {
2076 camera_metadata_item_t item;
2077 int ret;
2078 int32_t minIndex = 0;
2079 int32_t maxIndex = 1;
2080 uint32_t zoomRangeCount = 2;
2081 infoDumper.Title("Zoom Related Info:");
2082
2083 ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_ZOOM_CAP, &item);
2084 if (ret == CAM_META_SUCCESS) {
2085 infoDumper.Msg("OHOS_ABILITY_ZOOM_CAP data size:" + to_string(item.count));
2086 if (item.count == zoomRangeCount) {
2087 infoDumper.Msg("Available Zoom Capability:[" + to_string(item.data.i32[minIndex]) + " " +
2088 to_string(item.data.i32[maxIndex]) + "]");
2089 }
2090 }
2091
2092 ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_SCENE_ZOOM_CAP, &item);
2093 if (ret == CAM_META_SUCCESS) {
2094 infoDumper.Msg("OHOS_ABILITY_SCENE_ZOOM_CAP data size:" + to_string(item.count));
2095 string zoomAbilityString = "Available Zoom Modes:[ ";
2096 int reduce = 100;
2097 uint32_t size = 3;
2098 float range;
2099 int32_t val;
2100 for (uint32_t i = 0; i < item.count; i++) {
2101 val = item.data.i32[i];
2102 if (i % size != 0) {
2103 range = (float)val / reduce;
2104 zoomAbilityString.append(to_string(range) + " ");
2105 } else {
2106 zoomAbilityString.append(" mode: " + to_string(val) + " ");
2107 }
2108 }
2109 zoomAbilityString.append("]");
2110 infoDumper.Msg(zoomAbilityString);
2111 }
2112
2113 ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_ZOOM_RATIO_RANGE, &item);
2114 CHECK_RETURN(ret != CAM_META_SUCCESS);
2115 infoDumper.Msg("OHOS_ABILITY_ZOOM_RATIO_RANGE data size:" + to_string(item.count));
2116 if (item.count == zoomRangeCount) {
2117 infoDumper.Msg(
2118 "Available Zoom Ratio Range:[" + to_string(item.data.f[minIndex]) + to_string(item.data.f[maxIndex]) + "]");
2119 }
2120 }
2121
DumpCameraFlash(common_metadata_header_t * metadataEntry,CameraInfoDumper & infoDumper)2122 void HCameraService::DumpCameraFlash(common_metadata_header_t* metadataEntry, CameraInfoDumper& infoDumper)
2123 {
2124 camera_metadata_item_t item;
2125 int ret;
2126 infoDumper.Title("Flash Related Info:");
2127 ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_FLASH_MODES, &item);
2128 if (ret == CAM_META_SUCCESS) {
2129 string flashAbilityString = "Available Flash Modes:[ ";
2130 for (uint32_t i = 0; i < item.count; i++) {
2131 map<int, string>::const_iterator iter = g_cameraFlashMode.find(item.data.u8[i]);
2132 CHECK_EXECUTE(iter != g_cameraFlashMode.end(), flashAbilityString.append(iter->second + " "));
2133 }
2134 flashAbilityString.append("]");
2135 infoDumper.Msg(flashAbilityString);
2136 }
2137 }
2138
DumpCameraCompensation(common_metadata_header_t * metadataEntry,CameraInfoDumper & infoDumper)2139 void HCameraService::DumpCameraCompensation(common_metadata_header_t *metadataEntry, CameraInfoDumper &infoDumper)
2140 {
2141 camera_metadata_item_t item;
2142 int ret;
2143 infoDumper.Title("Compensation Related Info:");
2144 ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_AE_COMPENSATION_RANGE, &item);
2145 CHECK_RETURN(ret != CAM_META_SUCCESS);
2146 string compensationAbilityString = "Available Compensation Modes:[ ";
2147 for (uint32_t i = 0; i < item.count; i++) {
2148 int32_t val = item.data.i32[i];
2149 compensationAbilityString.append(to_string(val));
2150 }
2151 compensationAbilityString.append("]");
2152 infoDumper.Msg(compensationAbilityString);
2153 }
2154
DumpCameraColorSpace(common_metadata_header_t * metadataEntry,CameraInfoDumper & infoDumper)2155 void HCameraService::DumpCameraColorSpace(common_metadata_header_t *metadataEntry, CameraInfoDumper &infoDumper)
2156 {
2157 camera_metadata_item_t item;
2158 int ret;
2159 infoDumper.Title("Color Space Related Info:");
2160 ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_AVAILABLE_COLOR_SPACES, &item);
2161 CHECK_RETURN(ret != CAM_META_SUCCESS);
2162 string colorSpaceAbilityString = "Available Color Space Modes:[ ";
2163 for (uint32_t i = 0; i < item.count; i++) {
2164 int32_t val = item.data.i32[i];
2165 colorSpaceAbilityString.append(to_string(val));
2166 }
2167 colorSpaceAbilityString.append("]");
2168 infoDumper.Msg(colorSpaceAbilityString);
2169 }
2170
DumpCameraAF(common_metadata_header_t * metadataEntry,CameraInfoDumper & infoDumper)2171 void HCameraService::DumpCameraAF(common_metadata_header_t *metadataEntry, CameraInfoDumper &infoDumper)
2172 {
2173 camera_metadata_item_t item;
2174 int ret;
2175 infoDumper.Title("AF Related Info:");
2176 ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_FOCUS_MODES, &item);
2177 if (ret == CAM_META_SUCCESS) {
2178 string afAbilityString = "Available Focus Modes:[ ";
2179 for (uint32_t i = 0; i < item.count; i++) {
2180 map<int, string>::const_iterator iter = g_cameraFocusMode.find(item.data.u8[i]);
2181 CHECK_EXECUTE(iter != g_cameraFocusMode.end(), afAbilityString.append(iter->second + " "));
2182 }
2183 afAbilityString.append("]");
2184 infoDumper.Msg(afAbilityString);
2185 }
2186 }
2187
DumpCameraAE(common_metadata_header_t * metadataEntry,CameraInfoDumper & infoDumper)2188 void HCameraService::DumpCameraAE(common_metadata_header_t* metadataEntry, CameraInfoDumper& infoDumper)
2189 {
2190 camera_metadata_item_t item;
2191 int ret;
2192 infoDumper.Title("AE Related Info:");
2193 ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_EXPOSURE_MODES, &item);
2194 if (ret == CAM_META_SUCCESS) {
2195 string aeAbilityString = "Available Exposure Modes:[ ";
2196 for (uint32_t i = 0; i < item.count; i++) {
2197 map<int, string>::const_iterator iter = g_cameraExposureMode.find(item.data.u8[i]);
2198 CHECK_EXECUTE(iter != g_cameraExposureMode.end(), aeAbilityString.append(iter->second + " "));
2199 }
2200 aeAbilityString.append("]");
2201 infoDumper.Msg(aeAbilityString);
2202 }
2203 }
2204
DumpCameraSensorInfo(common_metadata_header_t * metadataEntry,CameraInfoDumper & infoDumper)2205 void HCameraService::DumpCameraSensorInfo(common_metadata_header_t* metadataEntry, CameraInfoDumper& infoDumper)
2206 {
2207 camera_metadata_item_t item;
2208 int ret;
2209 int32_t leftIndex = 0;
2210 int32_t topIndex = 1;
2211 int32_t rightIndex = 2;
2212 int32_t bottomIndex = 3;
2213 infoDumper.Title("Sensor Related Info:");
2214 ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_SENSOR_INFO_ACTIVE_ARRAY_SIZE, &item);
2215 CHECK_RETURN(ret != CAM_META_SUCCESS);
2216 infoDumper.Msg("Array:[" + to_string(item.data.i32[leftIndex]) + " " + to_string(item.data.i32[topIndex]) + " " +
2217 to_string(item.data.i32[rightIndex]) + " " + to_string(item.data.i32[bottomIndex]) + "]:\n");
2218 }
2219
DumpCameraVideoStabilization(common_metadata_header_t * metadataEntry,CameraInfoDumper & infoDumper)2220 void HCameraService::DumpCameraVideoStabilization(common_metadata_header_t* metadataEntry, CameraInfoDumper& infoDumper)
2221 {
2222 camera_metadata_item_t item;
2223 int ret;
2224 infoDumper.Title("Video Stabilization Related Info:");
2225 ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_VIDEO_STABILIZATION_MODES, &item);
2226 if (ret == CAM_META_SUCCESS) {
2227 std::string infoString = "Available Video Stabilization Modes:[ ";
2228 for (uint32_t i = 0; i < item.count; i++) {
2229 map<int, string>::const_iterator iter = g_cameraVideoStabilizationMode.find(item.data.u8[i]);
2230 CHECK_EXECUTE(iter != g_cameraVideoStabilizationMode.end(), infoString.append(iter->second + " "));
2231 }
2232 infoString.append("]:");
2233 infoDumper.Msg(infoString);
2234 }
2235 }
2236
DumpCameraVideoFrameRateRange(common_metadata_header_t * metadataEntry,CameraInfoDumper & infoDumper)2237 void HCameraService::DumpCameraVideoFrameRateRange(
2238 common_metadata_header_t* metadataEntry, CameraInfoDumper& infoDumper)
2239 {
2240 camera_metadata_item_t item;
2241 const int32_t FRAME_RATE_RANGE_STEP = 2;
2242 int ret;
2243 infoDumper.Title("Video FrameRateRange Related Info:");
2244 ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_FPS_RANGES, &item);
2245 if (ret == CAM_META_SUCCESS && item.count > 0) {
2246 infoDumper.Msg("Available FrameRateRange:");
2247 for (uint32_t i = 0; i < (item.count - 1); i += FRAME_RATE_RANGE_STEP) {
2248 infoDumper.Msg("[ " + to_string(item.data.i32[i]) + ", " + to_string(item.data.i32[i + 1]) + " ]");
2249 }
2250 }
2251 }
2252
DumpCameraPrelaunch(common_metadata_header_t * metadataEntry,CameraInfoDumper & infoDumper)2253 void HCameraService::DumpCameraPrelaunch(common_metadata_header_t* metadataEntry, CameraInfoDumper& infoDumper)
2254 {
2255 camera_metadata_item_t item;
2256 int ret;
2257 infoDumper.Title("Camera Prelaunch Related Info:");
2258 ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_PRELAUNCH_AVAILABLE, &item);
2259 CHECK_RETURN(ret != CAM_META_SUCCESS);
2260 map<int, string>::const_iterator iter = g_cameraPrelaunchAvailable.find(item.data.u8[0]);
2261 bool isSupport = false;
2262 if (iter != g_cameraPrelaunchAvailable.end()) {
2263 isSupport = true;
2264 }
2265 std::string infoString = "Available Prelaunch Info:[";
2266 infoString.append(isSupport ? "True" : "False");
2267 infoString.append("]");
2268 infoDumper.Msg(infoString);
2269 }
2270
DumpCameraThumbnail(common_metadata_header_t * metadataEntry,CameraInfoDumper & infoDumper)2271 void HCameraService::DumpCameraThumbnail(common_metadata_header_t* metadataEntry, CameraInfoDumper& infoDumper)
2272 {
2273 camera_metadata_item_t item;
2274 int ret;
2275 infoDumper.Title("Camera Thumbnail Related Info:");
2276 ret = OHOS::Camera::FindCameraMetadataItem(metadataEntry, OHOS_ABILITY_STREAM_QUICK_THUMBNAIL_AVAILABLE, &item);
2277 CHECK_RETURN(ret != CAM_META_SUCCESS);
2278 map<int, string>::const_iterator iter = g_cameraQuickThumbnailAvailable.find(item.data.u8[0]);
2279 bool isSupport = false;
2280 if (iter != g_cameraQuickThumbnailAvailable.end()) {
2281 isSupport = true;
2282 }
2283 std::string infoString = "Available Thumbnail Info:[";
2284 infoString.append(isSupport ? "True" : "False");
2285 infoString.append("]");
2286 infoDumper.Msg(infoString);
2287 }
2288
DumpCameraConcurrency(CameraInfoDumper & infoDumper,std::vector<std::shared_ptr<OHOS::Camera::CameraMetadata>> & cameraAbilityList)2289 void HCameraService::DumpCameraConcurrency(
2290 CameraInfoDumper &infoDumper, std::vector<std::shared_ptr<OHOS::Camera::CameraMetadata>> &cameraAbilityList)
2291 {
2292 infoDumper.Title("Concurrency Camera Info");
2293 HCameraDeviceManager *deviceManager = HCameraDeviceManager::GetInstance();
2294 std::vector<sptr<HCameraDeviceHolder>> cameraHolder = deviceManager->GetActiveCameraHolders();
2295 std::vector<std::string> cameraIds;
2296 std::vector<sptr<HCameraDevice>> cameraDevices;
2297 for (auto entry : cameraHolder) {
2298 cameraIds.push_back(entry->GetDevice()->GetCameraId());
2299 cameraDevices.push_back(entry->GetDevice());
2300 }
2301 size_t activeCamerasCount = deviceManager->GetActiveCamerasCount();
2302 infoDumper.Title("Number of Active Cameras:[" + to_string(activeCamerasCount) + "]");
2303 DumpCameraInfo(infoDumper, cameraIds, cameraAbilityList);
2304 HCaptureSession::DumpSessions(infoDumper);
2305 }
2306
Dump(int fd,const vector<u16string> & args)2307 int32_t HCameraService::Dump(int fd, const vector<u16string> &args)
2308 {
2309 unordered_set<u16string> argSets;
2310 for (decltype(args.size()) index = 0; index < args.size(); ++index) {
2311 argSets.insert(args[index]);
2312 }
2313 std::string dumpString;
2314 std::vector<std::string> cameraIds;
2315 std::vector<std::shared_ptr<OHOS::Camera::CameraMetadata>> cameraAbilityList;
2316 int ret = GetCameras(cameraIds, cameraAbilityList);
2317 CHECK_RETURN_RET((ret != CAMERA_OK) || cameraIds.empty() || cameraAbilityList.empty(), OHOS::UNKNOWN_ERROR);
2318 CameraInfoDumper infoDumper(fd);
2319 CHECK_EXECUTE(args.empty() || argSets.count(u16string(u"summary")), DumpCameraSummary(cameraIds, infoDumper));
2320 CHECK_EXECUTE(args.empty() || argSets.count(u16string(u"ability")),
2321 DumpCameraInfo(infoDumper, cameraIds, cameraAbilityList));
2322 if (args.empty() || argSets.count(u16string(u"preconfig"))) {
2323 infoDumper.Tip("--------Dump PreconfigInfo Begin-------");
2324 DumpPreconfigInfo(infoDumper, cameraHostManager_);
2325 }
2326 if (args.empty() || argSets.count(u16string(u"clientwiseinfo"))) {
2327 infoDumper.Tip("--------Dump Clientwise Info Begin-------");
2328 HCaptureSession::DumpSessions(infoDumper);
2329 }
2330 CHECK_EXECUTE(argSets.count(std::u16string(u"debugOn")), SetCameraDebugValue(true));
2331
2332 if (argSets.count(std::u16string(u"concurrency"))) {
2333 DumpCameraConcurrency(infoDumper, cameraAbilityList);
2334 }
2335 infoDumper.Print();
2336 return OHOS::NO_ERROR;
2337 }
2338
ClearCameraListenerByPid(pid_t pid)2339 void HCameraService::ClearCameraListenerByPid(pid_t pid)
2340 {
2341 sptr<IStandardCameraListener> cameraListenerTmp = nullptr;
2342 if (cameraListenerMap_.Find(pid, cameraListenerTmp)) {
2343 CHECK_EXECUTE(cameraListenerTmp != nullptr && cameraListenerTmp->AsObject() != nullptr,
2344 cameraListenerTmp->RemoveCameraDeathRecipient());
2345 cameraListenerMap_.Erase(pid);
2346 }
2347 }
2348
DestroyStubForPid(pid_t pid)2349 int HCameraService::DestroyStubForPid(pid_t pid)
2350 {
2351 UnSetAllCallback(pid);
2352 ClearCameraListenerByPid(pid);
2353 HCaptureSession::DestroyStubObjectForPid(pid);
2354 CloseCameraForDestory(pid);
2355
2356 return CAMERA_OK;
2357 }
2358
DestroyStubObj()2359 int HCameraService::DestroyStubObj()
2360 {
2361 pid_t pid = IPCSkeleton::GetCallingPid();
2362 MEDIA_DEBUG_LOG("DestroyStubObj client pid:%{public}d", pid);
2363 (void)DestroyStubForPid(pid);
2364
2365 return CAMERA_OK;
2366 }
2367
ClientDied(pid_t pid)2368 void HCameraService::ClientDied(pid_t pid)
2369 {
2370 DisableJeMalloc();
2371 MEDIA_ERR_LOG("client pid is dead, pid:%{public}d", pid);
2372 (void)DestroyStubForPid(pid);
2373 }
2374
SetListenerObject(const sptr<IRemoteObject> & object)2375 int HCameraService::SetListenerObject(const sptr<IRemoteObject>& object)
2376 {
2377 pid_t pid = IPCSkeleton::GetCallingPid();
2378 ClearCameraListenerByPid(pid); // Ensure cleanup before starting the listener if this is the second call
2379 CHECK_RETURN_RET_ELOG(object == nullptr, CAMERA_ALLOC_ERROR, "set listener object is nullptr");
2380
2381 sptr<IStandardCameraListener> cameraListener = iface_cast<IStandardCameraListener>(object);
2382 CHECK_RETURN_RET_ELOG(cameraListener == nullptr, CAMERA_ALLOC_ERROR,
2383 "failed to cast IStandardCameraListener");
2384
2385 sptr<CameraDeathRecipient> deathRecipient = new (std::nothrow) CameraDeathRecipient(pid);
2386 CHECK_RETURN_RET_ELOG(deathRecipient == nullptr, CAMERA_ALLOC_ERROR, "failed to new CameraDeathRecipient");
2387
2388 auto thisPtr = wptr<HCameraService>(this);
2389 deathRecipient->SetNotifyCb([thisPtr](pid_t pid) {
2390 auto hCameraServicePtr = thisPtr.promote();
2391 CHECK_EXECUTE(hCameraServicePtr != nullptr, hCameraServicePtr->ClientDied(pid));
2392 });
2393 cameraListener->AddCameraDeathRecipient(deathRecipient);
2394 cameraListenerMap_.EnsureInsert(pid, cameraListener);
2395
2396 return CAMERA_OK;
2397 }
2398
SaveCurrentParamForRestore(std::string cameraId,RestoreParamTypeOhos restoreParamType,int activeTime,EffectParam effectParam,sptr<HCaptureSession> captureSession)2399 int32_t HCameraService::SaveCurrentParamForRestore(std::string cameraId, RestoreParamTypeOhos restoreParamType,
2400 int activeTime, EffectParam effectParam, sptr<HCaptureSession> captureSession)
2401 {
2402 MEDIA_INFO_LOG("HCameraService::SaveCurrentParamForRestore enter");
2403 int32_t rc = CAMERA_OK;
2404 preCameraClient_ = GetClientBundle(IPCSkeleton::GetCallingUid());
2405 sptr<HCameraRestoreParam> cameraRestoreParam = new HCameraRestoreParam(
2406 preCameraClient_, cameraId);
2407 cameraRestoreParam->SetRestoreParamType(restoreParamType);
2408 cameraRestoreParam->SetStartActiveTime(activeTime);
2409 int foldStatus = static_cast<int>(OHOS::Rosen::DisplayManager::GetInstance().GetFoldStatus());
2410 cameraRestoreParam->SetFoldStatus(foldStatus);
2411 if (captureSession == nullptr || restoreParamType == RestoreParamTypeOhos::NO_NEED_RESTORE_PARAM_OHOS) {
2412 cameraHostManager_->SaveRestoreParam(cameraRestoreParam);
2413 return rc;
2414 }
2415
2416 sptr<HCameraDeviceManager> deviceManager = HCameraDeviceManager::GetInstance();
2417 std::vector<pid_t> pidOfActiveClients = deviceManager->GetActiveClient();
2418 CHECK_RETURN_RET_ELOG(pidOfActiveClients.size() == 0, CAMERA_OPERATION_NOT_ALLOWED,
2419 "HCaptureSession::SaveCurrentParamForRestore() Failed to save param cause no device is opening");
2420 CHECK_RETURN_RET_ELOG(pidOfActiveClients.size() > 1, CAMERA_OPERATION_NOT_ALLOWED,
2421 "HCaptureSession::SaveCurrentParamForRestore() not supported for Multi-Device is opening");
2422 std::vector<sptr<HCameraDevice>> activeDevices = deviceManager->GetCamerasByPid(pidOfActiveClients[0]);
2423 CHECK_RETURN_RET(activeDevices.empty(), CAMERA_OK);
2424 std::vector<StreamInfo_V1_1> allStreamInfos;
2425
2426 if (activeDevices.size() == 1) {
2427 std::shared_ptr<OHOS::Camera::CameraMetadata> defaultSettings
2428 = CreateDefaultSettingForRestore(activeDevices[0]);
2429 UpdateSkinSmoothSetting(defaultSettings, effectParam.skinSmoothLevel);
2430 UpdateFaceSlenderSetting(defaultSettings, effectParam.faceSlender);
2431 UpdateSkinToneSetting(defaultSettings, effectParam.skinTone);
2432 cameraRestoreParam->SetSetting(defaultSettings);
2433 }
2434 rc = captureSession->GetCurrentStreamInfos(allStreamInfos);
2435 CHECK_RETURN_RET_ELOG(rc != CAMERA_OK, rc,
2436 "HCaptureSession::SaveCurrentParamForRestore() Failed to get streams info, %{public}d", rc);
2437 int count = 0;
2438 for (auto& info : allStreamInfos) {
2439 MEDIA_INFO_LOG("HCameraService::SaveCurrentParamForRestore: streamId is:%{public}d", info.v1_0.streamId_);
2440 count += (info.v1_0.streamId_ == 0) ? 1: 0;
2441 }
2442 CaptureSessionState currentState;
2443 captureSession->GetSessionState(currentState);
2444 bool isCommitConfig = (currentState == CaptureSessionState::SESSION_CONFIG_COMMITTED)
2445 || (currentState == CaptureSessionState::SESSION_STARTED);
2446 CHECK_RETURN_RET_ELOG((!isCommitConfig || count > 1), CAMERA_INVALID_ARG,
2447 "HCameraService::SaveCurrentParamForRestore stream is not commit or streamId is all 0");
2448 cameraRestoreParam->SetStreamInfo(allStreamInfos);
2449 cameraRestoreParam->SetCameraOpMode(captureSession->GetopMode());
2450 cameraHostManager_->SaveRestoreParam(cameraRestoreParam);
2451 return rc;
2452 }
2453
CreateDefaultSettingForRestore(sptr<HCameraDevice> activeDevice)2454 std::shared_ptr<OHOS::Camera::CameraMetadata> HCameraService::CreateDefaultSettingForRestore(
2455 sptr<HCameraDevice> activeDevice)
2456 {
2457 constexpr int32_t DEFAULT_ITEMS = 1;
2458 constexpr int32_t DEFAULT_DATA_LENGTH = 1;
2459 auto defaultSettings = std::make_shared<OHOS::Camera::CameraMetadata>(DEFAULT_ITEMS, DEFAULT_DATA_LENGTH);
2460 float zoomRatio = 1.0f;
2461 int32_t count = 1;
2462 int32_t ret = 0;
2463 camera_metadata_item_t item;
2464 defaultSettings->addEntry(OHOS_CONTROL_ZOOM_RATIO, &zoomRatio, count);
2465 defaultSettings->addEntry(OHOS_CONTROL_TIME_LAPSE_RECORD_STATE, &ret, count);
2466 std::shared_ptr<OHOS::Camera::CameraMetadata> currentSetting = activeDevice->CloneCachedSettings();
2467 CHECK_RETURN_RET_ELOG(currentSetting == nullptr, defaultSettings,
2468 "HCameraService::CreateDefaultSettingForRestore:currentSetting is null");
2469 ret = OHOS::Camera::FindCameraMetadataItem(currentSetting->get(), OHOS_CONTROL_FPS_RANGES, &item);
2470 if (ret == CAM_META_SUCCESS) {
2471 uint32_t fpscount = item.count;
2472 std::vector<int32_t> fpsRange;
2473 for (uint32_t i = 0; i < fpscount; i++) {
2474 fpsRange.push_back(*(item.data.i32 + i));
2475 }
2476 defaultSettings->addEntry(OHOS_CONTROL_FPS_RANGES, fpsRange.data(), fpscount);
2477 }
2478
2479 ret = OHOS::Camera::FindCameraMetadataItem(currentSetting->get(), OHOS_CAMERA_USER_ID, &item);
2480 if (ret == CAM_META_SUCCESS) {
2481 int32_t userId = item.data.i32[0];
2482 defaultSettings->addEntry(OHOS_CAMERA_USER_ID, &userId, count);
2483 }
2484
2485 ret = OHOS::Camera::FindCameraMetadataItem(currentSetting->get(), OHOS_CONTROL_AE_EXPOSURE_COMPENSATION, &item);
2486 if (ret == CAM_META_SUCCESS) {
2487 int32_t exporseValue = item.data.i32[0];
2488 defaultSettings->addEntry(OHOS_CONTROL_AE_EXPOSURE_COMPENSATION, &exporseValue, count);
2489 }
2490
2491 uint8_t enableValue = true;
2492 defaultSettings->addEntry(OHOS_CONTROL_VIDEO_DEBUG_SWITCH, &enableValue, 1);
2493
2494 for (uint32_t metadataTag : restoreMetadataTag) { // item.type is uint8
2495 ret = OHOS::Camera::FindCameraMetadataItem(currentSetting->get(), metadataTag, &item);
2496 CHECK_EXECUTE(ret == 0 && item.count != 0,
2497 defaultSettings->addEntry(item.item, item.data.u8, item.count));
2498 }
2499 return defaultSettings;
2500 }
2501
UpdateSkinSmoothSetting(std::shared_ptr<OHOS::Camera::CameraMetadata> changedMetadata,int skinSmoothValue)2502 int32_t HCameraService::UpdateSkinSmoothSetting(std::shared_ptr<OHOS::Camera::CameraMetadata> changedMetadata,
2503 int skinSmoothValue)
2504 {
2505 CHECK_RETURN_RET(skinSmoothValue <= 0 || changedMetadata == nullptr, CAMERA_OK);
2506 bool status = false;
2507 int32_t count = 1;
2508 int ret;
2509 camera_metadata_item_t item;
2510
2511 MEDIA_DEBUG_LOG("UpdateBeautySetting skinsmooth: %{public}d", skinSmoothValue);
2512 uint8_t beauty = OHOS_CAMERA_BEAUTY_TYPE_SKIN_SMOOTH;
2513 ret = OHOS::Camera::FindCameraMetadataItem(changedMetadata->get(), OHOS_CONTROL_BEAUTY_TYPE, &item);
2514 if (ret == CAM_META_ITEM_NOT_FOUND) {
2515 status = changedMetadata->addEntry(OHOS_CONTROL_BEAUTY_TYPE, &beauty, count);
2516 } else if (ret == CAM_META_SUCCESS) {
2517 status = changedMetadata->updateEntry(OHOS_CONTROL_BEAUTY_TYPE, &beauty, count);
2518 }
2519
2520 ret = OHOS::Camera::FindCameraMetadataItem(changedMetadata->get(), OHOS_CONTROL_BEAUTY_SKIN_SMOOTH_VALUE, &item);
2521 if (ret == CAM_META_ITEM_NOT_FOUND) {
2522 status = changedMetadata->addEntry(OHOS_CONTROL_BEAUTY_SKIN_SMOOTH_VALUE, &skinSmoothValue, count);
2523 } else if (ret == CAM_META_SUCCESS) {
2524 status = changedMetadata->updateEntry(OHOS_CONTROL_BEAUTY_SKIN_SMOOTH_VALUE, &skinSmoothValue, count);
2525 }
2526 if (status) {
2527 MEDIA_INFO_LOG("UpdateBeautySetting status: %{public}d", status);
2528 }
2529
2530 return CAMERA_OK;
2531 }
2532
UpdateFaceSlenderSetting(std::shared_ptr<OHOS::Camera::CameraMetadata> changedMetadata,int faceSlenderValue)2533 int32_t HCameraService::UpdateFaceSlenderSetting(std::shared_ptr<OHOS::Camera::CameraMetadata> changedMetadata,
2534 int faceSlenderValue)
2535 {
2536 CHECK_RETURN_RET(faceSlenderValue <= 0 || changedMetadata == nullptr, CAMERA_OK);
2537 bool status = false;
2538 int32_t count = 1;
2539 int ret;
2540 camera_metadata_item_t item;
2541
2542 MEDIA_DEBUG_LOG("UpdateBeautySetting faceSlender: %{public}d", faceSlenderValue);
2543 uint8_t beauty = OHOS_CAMERA_BEAUTY_TYPE_FACE_SLENDER;
2544 ret = OHOS::Camera::FindCameraMetadataItem(changedMetadata->get(), OHOS_CONTROL_BEAUTY_TYPE, &item);
2545 if (ret == CAM_META_ITEM_NOT_FOUND) {
2546 status = changedMetadata->addEntry(OHOS_CONTROL_BEAUTY_TYPE, &beauty, count);
2547 } else if (ret == CAM_META_SUCCESS) {
2548 status = changedMetadata->updateEntry(OHOS_CONTROL_BEAUTY_TYPE, &beauty, count);
2549 }
2550
2551 ret = OHOS::Camera::FindCameraMetadataItem(changedMetadata->get(), OHOS_CONTROL_BEAUTY_FACE_SLENDER_VALUE, &item);
2552 if (ret == CAM_META_ITEM_NOT_FOUND) {
2553 status = changedMetadata->addEntry(OHOS_CONTROL_BEAUTY_FACE_SLENDER_VALUE, &faceSlenderValue, count);
2554 } else if (ret == CAM_META_SUCCESS) {
2555 status = changedMetadata->updateEntry(OHOS_CONTROL_BEAUTY_FACE_SLENDER_VALUE, &faceSlenderValue, count);
2556 }
2557 if (status) {
2558 MEDIA_INFO_LOG("UpdateBeautySetting status: %{public}d", status);
2559 }
2560
2561 return CAMERA_OK;
2562 }
2563
UpdateSkinToneSetting(std::shared_ptr<OHOS::Camera::CameraMetadata> changedMetadata,int skinToneValue)2564 int32_t HCameraService::UpdateSkinToneSetting(std::shared_ptr<OHOS::Camera::CameraMetadata> changedMetadata,
2565 int skinToneValue)
2566 {
2567 CHECK_RETURN_RET(skinToneValue <= 0 || changedMetadata == nullptr, CAMERA_OK);
2568 bool status = false;
2569 int32_t count = 1;
2570 int ret;
2571 camera_metadata_item_t item;
2572
2573 MEDIA_DEBUG_LOG("UpdateBeautySetting skinTone: %{public}d", skinToneValue);
2574 uint8_t beauty = OHOS_CAMERA_BEAUTY_TYPE_SKIN_TONE;
2575 ret = OHOS::Camera::FindCameraMetadataItem(changedMetadata->get(), OHOS_CONTROL_BEAUTY_TYPE, &item);
2576 if (ret == CAM_META_ITEM_NOT_FOUND) {
2577 status = changedMetadata->addEntry(OHOS_CONTROL_BEAUTY_TYPE, &beauty, count);
2578 } else if (ret == CAM_META_SUCCESS) {
2579 status = changedMetadata->updateEntry(OHOS_CONTROL_BEAUTY_TYPE, &beauty, count);
2580 }
2581
2582 ret = OHOS::Camera::FindCameraMetadataItem(changedMetadata->get(), OHOS_CONTROL_BEAUTY_SKIN_TONE_VALUE, &item);
2583 if (ret == CAM_META_ITEM_NOT_FOUND) {
2584 status = changedMetadata->addEntry(OHOS_CONTROL_BEAUTY_SKIN_TONE_VALUE, &skinToneValue, count);
2585 } else if (ret == CAM_META_SUCCESS) {
2586 status = changedMetadata->updateEntry(OHOS_CONTROL_BEAUTY_SKIN_TONE_VALUE, &skinToneValue, count);
2587 }
2588 if (status) {
2589 MEDIA_INFO_LOG("UpdateBeautySetting status: %{public}d", status);
2590 }
2591
2592 return CAMERA_OK;
2593 }
2594
g_toString(std::set<int32_t> & pidList)2595 std::string g_toString(std::set<int32_t>& pidList)
2596 {
2597 std::string ret = "[";
2598 for (const auto& pid : pidList) {
2599 ret += std::to_string(pid) + ",";
2600 }
2601 ret += "]";
2602 return ret;
2603 }
2604
ProxyForFreeze(const std::set<int32_t> & pidList,bool isProxy)2605 int32_t HCameraService::ProxyForFreeze(const std::set<int32_t>& pidList, bool isProxy)
2606 {
2607 constexpr int32_t maxSaUid = 10000;
2608 CHECK_RETURN_RET_ELOG(IPCSkeleton::GetCallingUid() >= maxSaUid, CAMERA_OPERATION_NOT_ALLOWED, "not allow");
2609 {
2610 std::lock_guard<std::mutex> lock(freezedPidListMutex_);
2611 if (isProxy) {
2612 freezedPidList_.insert(pidList.begin(), pidList.end());
2613 MEDIA_DEBUG_LOG("after freeze freezedPidList_:%{public}s", g_toString(freezedPidList_).c_str());
2614 return CAMERA_OK;
2615 } else {
2616 for (auto pid : pidList) {
2617 freezedPidList_.erase(pid);
2618 }
2619 MEDIA_DEBUG_LOG("after unfreeze freezedPidList_:%{public}s", g_toString(freezedPidList_).c_str());
2620 }
2621 }
2622
2623 {
2624 std::lock_guard<std::mutex> lock(cameraCbMutex_);
2625 std::for_each(pidList.begin(), pidList.end(), [this](auto pid) {
2626 auto pidIt = delayCbtaskMap_.find(pid);
2627 CHECK_RETURN(pidIt == delayCbtaskMap_.end());
2628 for (const auto &[cameraId, taskCallback] : pidIt->second) {
2629 CHECK_EXECUTE(taskCallback, taskCallback());
2630 }
2631 delayCbtaskMap_.erase(pidIt);
2632 });
2633 }
2634 return CAMERA_OK;
2635 }
2636
ResetAllFreezeStatus()2637 int32_t HCameraService::ResetAllFreezeStatus()
2638 {
2639 constexpr int32_t maxSaUid = 10000;
2640 CHECK_RETURN_RET_ELOG(IPCSkeleton::GetCallingUid() >= maxSaUid, CAMERA_OPERATION_NOT_ALLOWED, "not allow");
2641 std::lock_guard<std::mutex> lock(freezedPidListMutex_);
2642 freezedPidList_.clear();
2643 MEDIA_INFO_LOG("freezedPidList_ has been clear");
2644 return CAMERA_OK;
2645 }
2646
GetDmDeviceInfo(std::vector<std::string> & deviceInfos)2647 int32_t HCameraService::GetDmDeviceInfo(std::vector<std::string> &deviceInfos)
2648 {
2649 #ifdef DEVICE_MANAGER
2650 lock_guard<mutex> lock(g_dmDeviceInfoMutex);
2651 std::vector <DistributedHardware::DmDeviceInfo> deviceInfoList;
2652 auto &deviceManager = DistributedHardware::DeviceManager::GetInstance();
2653 std::shared_ptr<DistributedHardware::DmInitCallback> initCallback = std::make_shared<DeviceInitCallBack>();
2654 std::string pkgName = std::to_string(IPCSkeleton::GetCallingTokenID());
2655 const string extraInfo = "";
2656 deviceManager.InitDeviceManager(pkgName, initCallback);
2657 deviceManager.RegisterDevStateCallback(pkgName, extraInfo, NULL);
2658 deviceManager.GetTrustedDeviceList(pkgName, extraInfo, deviceInfoList);
2659 deviceManager.UnInitDeviceManager(pkgName);
2660 int size = static_cast<int>(deviceInfoList.size());
2661 MEDIA_INFO_LOG("HCameraService::GetDmDeviceInfo size=%{public}d", size);
2662 if (size > 0) { // LCOV_LINE_EXCL
2663 for (int i = 0; i < size; i++) {
2664 nlohmann::json deviceInfo;
2665 deviceInfo["deviceName"] = deviceInfoList[i].deviceName;
2666 deviceInfo["deviceTypeId"] = deviceInfoList[i].deviceTypeId;
2667 deviceInfo["networkId"] = deviceInfoList[i].networkId;
2668 std::string deviceInfoStr = deviceInfo.dump();
2669 MEDIA_INFO_LOG("HCameraService::GetDmDeviceInfo deviceInfo:%{public}s",
2670 OHOS::CameraStandard::Anonymization::AnonymizeString(deviceInfoStr).c_str());
2671 deviceInfos.emplace_back(deviceInfoStr);
2672 }
2673 }
2674 #endif
2675 return CAMERA_OK;
2676 }
2677
GetCameraOutputStatus(int32_t pid,int32_t & status)2678 int32_t HCameraService::GetCameraOutputStatus(int32_t pid, int32_t &status)
2679 {
2680 sptr<HCaptureSession> captureSession = nullptr;
2681 auto &sessionManager = HCameraSessionManager::GetInstance();
2682 captureSession = sessionManager.GetGroupDefaultSession(pid);
2683 if (captureSession) {
2684 captureSession->GetOutputStatus(status);
2685 } else {
2686 status = 0;
2687 }
2688 return CAMERA_OK;
2689 }
2690
RequireMemorySize(int32_t requiredMemSizeKB)2691 int32_t HCameraService::RequireMemorySize(int32_t requiredMemSizeKB)
2692 {
2693 #ifdef MEMMGR_OVERRID
2694 CameraXCollie cameraXCollie = CameraXCollie("HCameraService::RequireMemorySize");
2695 CHECK_RETURN_RET_ELOG(!CheckSystemApp(), CAMERA_NO_PERMISSION, "HCameraService::CheckSystemApp fail");
2696 int32_t pid = getpid();
2697 const std::string reason = "HW_CAMERA_TO_PHOTO";
2698 std::string clientName = SYSTEM_CAMERA;
2699 int32_t ret = Memory::MemMgrClient::GetInstance().RequireBigMem(pid, reason, requiredMemSizeKB, clientName);
2700 MEDIA_INFO_LOG("HCameraDevice::RequireMemory reason:%{public}s, clientName:%{public}s, ret:%{public}d",
2701 reason.c_str(), clientName.c_str(), ret);
2702 CHECK_RETURN_RET(ret == 0, CAMERA_OK);
2703 #endif
2704 return CAMERA_UNKNOWN_ERROR;
2705 }
2706
2707 #ifdef MEMMGR_OVERRID
PrelaunchRequireMemory(int32_t flag)2708 void HCameraService::PrelaunchRequireMemory(int32_t flag)
2709 {
2710 CAMERA_SYNC_TRACE;
2711 int32_t pid = getpid();
2712 int32_t requiredMemSizeKB = 0;
2713
2714 if (flag == TOUCH_DOWN) {
2715 // touch down
2716 MEDIA_INFO_LOG("PrelaunchRequireMemory touch down");
2717 Memory::MemMgrClient::GetInstance().RequireBigMem(
2718 pid, Memory::CAMERA_TOUCH_DOWN, requiredMemSizeKB, SYSTEM_CAMERA);
2719 } else if (flag == TOUCH_UP || flag == OLD_LAUNCH) {
2720 // touch up
2721 MEDIA_INFO_LOG("PrelaunchRequireMemory touch up");
2722 Memory::MemMgrClient::GetInstance().RequireBigMem(
2723 pid, Memory::CAMERA_PRELAUNCH, requiredMemSizeKB, SYSTEM_CAMERA);
2724 } else if (flag == TOUCH_CANCEL) {
2725 // touch cancel
2726 MEDIA_INFO_LOG("PrelaunchRequireMemory touch cancel");
2727 Memory::MemMgrClient::GetInstance().RequireBigMem(
2728 pid, Memory::CAMERA_LAUNCH_CANCEL, requiredMemSizeKB, SYSTEM_CAMERA);
2729 }
2730 }
2731 #endif
2732
GetIdforCameraConcurrentType(int32_t cameraPosition,std::string & cameraId)2733 int32_t HCameraService::GetIdforCameraConcurrentType(int32_t cameraPosition, std::string &cameraId)
2734 {
2735 std::string cameraIdnow;
2736 cameraHostManager_->GetPhysicCameraId(cameraPosition, cameraIdnow);
2737 cameraId = cameraIdnow;
2738 return CAMERA_OK;
2739 }
2740
GetConcurrentCameraAbility(const std::string & cameraId,std::shared_ptr<OHOS::Camera::CameraMetadata> & cameraAbility)2741 int32_t HCameraService::GetConcurrentCameraAbility(const std::string& cameraId,
2742 std::shared_ptr<OHOS::Camera::CameraMetadata>& cameraAbility)
2743 {
2744 MEDIA_DEBUG_LOG("HCameraService::GetConcurrentCameraAbility cameraId: %{public}s", cameraId.c_str());
2745 return cameraHostManager_->GetCameraAbility(cameraId, cameraAbility);
2746 }
2747
CheckWhiteList(bool & isInWhiteList)2748 int32_t HCameraService::CheckWhiteList(bool &isInWhiteList)
2749 {
2750 int32_t uid = IPCSkeleton::GetCallingUid();
2751 MEDIA_DEBUG_LOG("CheckWhitelist uid: %{public}d", uid);
2752 isInWhiteList = (uid == ROOT_UID || uid == FACE_CLIENT_UID || uid == RSS_UID ||
2753 OHOS::Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(IPCSkeleton::GetCallingFullTokenID()));
2754 return CAMERA_OK;
2755 }
2756
CallbackEnter(uint32_t code)2757 int32_t HCameraService::CallbackEnter([[maybe_unused]] uint32_t code)
2758 {
2759 MEDIA_DEBUG_LOG("start, code:%{public}u", code);
2760 DisableJeMalloc();
2761 return CAMERA_OK;
2762 }
CallbackExit(uint32_t code,int32_t result)2763 int32_t HCameraService::CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result)
2764 {
2765 MEDIA_DEBUG_LOG("leave, code:%{public}u, result:%{public}d", code, result);
2766 return CAMERA_OK;
2767 }
2768
GetCameraStorageSize(int64_t & size)2769 int32_t HCameraService::GetCameraStorageSize(int64_t& size)
2770 {
2771 CHECK_RETURN_RET_ELOG(
2772 !CheckSystemApp(), CAMERA_NO_PERMISSION, "HCameraService::GetCameraStorageSize:SystemApi is called");
2773 int32_t userId = 0;
2774 int32_t uid = IPCSkeleton::GetCallingUid();
2775 AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid, userId);
2776 cameraHostManager_->GetCameraStorageSize(userId, size);
2777 return CAMERA_OK;
2778 }
2779 } // namespace CameraStandard
2780 } // namespace OHOS
2781