From 633749ed913b217d7b87a684b1230b20c4031f0e Mon Sep 17 00:00:00 2001 From: cjj Date: Sat, 13 Sep 2025 18:22:55 +0800 Subject: [PATCH 1/3] fix review comment Signed-off-by: cjj --- .../moving_photo/src/moving_photo_adapter.cpp | 4 ++-- .../base/src/session/capture_session.cpp | 3 ++- .../session/include/night_session_unittest.h | 4 ++-- .../session/src/capture_session_unittest.cpp | 3 +++ .../session/src/night_session_unittest.cpp | 24 +++++++++---------- .../session/src/scan_session_unittest.cpp | 5 +++- .../src/camera_beauty_notification.cpp | 20 +++++++--------- .../src/camera_datashare_helper.cpp | 2 +- .../src/camera_fwk_metadata_utils.cpp | 2 ++ .../camera_service/src/camera_privacy.cpp | 8 +++++-- services/camera_service/src/camera_util.cpp | 3 ++- .../src/hcamera_device_manager.cpp | 13 +++++++--- .../src/hcamera_host_manager.cpp | 7 ++++++ .../camera_service/src/hcamera_preconfig.cpp | 2 ++ .../camera_service/src/hcamera_service.cpp | 2 ++ .../src/hcamera_session_manager.cpp | 2 +- 16 files changed, 66 insertions(+), 38 deletions(-) diff --git a/dynamic_libs/moving_photo/src/moving_photo_adapter.cpp b/dynamic_libs/moving_photo/src/moving_photo_adapter.cpp index d59972b70..6944ff288 100644 --- a/dynamic_libs/moving_photo/src/moving_photo_adapter.cpp +++ b/dynamic_libs/moving_photo/src/moving_photo_adapter.cpp @@ -218,8 +218,8 @@ void MovingPhotoVideoCacheAdapter::OnDrainFrameRecord(sptr frame) { MEDIA_DEBUG_LOG("OnDrainFrameRecord start"); CHECK_RETURN_ELOG(frame == nullptr, "FrameRecord is null"); - CHECK_RETURN_ELOG(videoCache_ == nullptr, "CreateMovingPhotoVideoCache failed"); auto videoCache = videoCache_.promote(); + CHECK_RETURN_ELOG(videoCache == nullptr, "CreateMovingPhotoVideoCache failed"); if (frame->IsIdle() && videoCache) { videoCache->CacheFrame(frame); } else if (frame->IsFinishCache() && videoCache) { @@ -235,8 +235,8 @@ void MovingPhotoVideoCacheAdapter::GetFrameCachedResult(std::vectorGetFrameCachedResult( frameRecords, diff --git a/frameworks/native/camera/base/src/session/capture_session.cpp b/frameworks/native/camera/base/src/session/capture_session.cpp index 0980e1030..af56a253f 100644 --- a/frameworks/native/camera/base/src/session/capture_session.cpp +++ b/frameworks/native/camera/base/src/session/capture_session.cpp @@ -2698,7 +2698,8 @@ int32_t CaptureSession::SetSmoothZoom(float targetZoomRatio, uint32_t smoothZoom } else { std::shared_ptr changedMetadata = std::make_shared(DEFAULT_ITEMS, DEFAULT_DATA_LENGTH); - changedMetadata->addEntry(OHOS_CONTROL_SMOOTH_ZOOM_RATIOS, &targetZoomRatio, 1); + bool addSmoothZoomOk = changedMetadata->addEntry(OHOS_CONTROL_SMOOTH_ZOOM_RATIOS, &targetZoomRatio, 1); + CHECK_PRINT_ELOG(!addSmoothZoomOk, "CaptureSession::SetSmoothZoom Failed to write smooth zoom ratios"); OnSettingUpdated(changedMetadata); auto abilityContainer = GetCameraAbilityContainer(); if (abilityContainer && supportSpecSearch_) { diff --git a/frameworks/native/camera/test/unittest/framework_native/session/include/night_session_unittest.h b/frameworks/native/camera/test/unittest/framework_native/session/include/night_session_unittest.h index 95eb44cb2..a7dcd645c 100644 --- a/frameworks/native/camera/test/unittest/framework_native/session/include/night_session_unittest.h +++ b/frameworks/native/camera/test/unittest/framework_native/session/include/night_session_unittest.h @@ -43,8 +43,8 @@ private: sptr cameraManager_ = nullptr; std::vector previewProfile_; std::vector photoProfile_; - bool preIsSupportedNighitmode_ = false; - bool phoIsSupportedNighitmode_ = false; + bool preIsSupportedNightmode_ = false; + bool phoIsSupportedNightmode_ = false; }; } diff --git a/frameworks/native/camera/test/unittest/framework_native/session/src/capture_session_unittest.cpp b/frameworks/native/camera/test/unittest/framework_native/session/src/capture_session_unittest.cpp index 8534f8eb4..f1385e200 100644 --- a/frameworks/native/camera/test/unittest/framework_native/session/src/capture_session_unittest.cpp +++ b/frameworks/native/camera/test/unittest/framework_native/session/src/capture_session_unittest.cpp @@ -47,6 +47,9 @@ struct TestObject {}; void CaptureSessionUnitTest::SessionControlParams(sptr session) { + if (session == nullptr) { + return; + } session->LockForControl(); std::vector zoomRatioRange = session->GetZoomRatioRange(); diff --git a/frameworks/native/camera/test/unittest/framework_native/session/src/night_session_unittest.cpp b/frameworks/native/camera/test/unittest/framework_native/session/src/night_session_unittest.cpp index a6e7fb6d5..94e0867b5 100644 --- a/frameworks/native/camera/test/unittest/framework_native/session/src/night_session_unittest.cpp +++ b/frameworks/native/camera/test/unittest/framework_native/session/src/night_session_unittest.cpp @@ -49,14 +49,14 @@ sptr CameraNightSessionUnit::CreatePreviewOutput() if (cameras.empty()) { return nullptr; } - preIsSupportedNighitmode_ = false; + preIsSupportedNightmode_ = false; for (sptr camDevice : cameras) { std::vector modes = cameraManager_->GetSupportedModes(camDevice); if (find(modes.begin(), modes.end(), SceneMode::NIGHT) != modes.end()) { - preIsSupportedNighitmode_ = true; + preIsSupportedNightmode_ = true; } - if (!preIsSupportedNighitmode_) { + if (!preIsSupportedNightmode_) { continue; } @@ -89,14 +89,14 @@ sptr CameraNightSessionUnit::CreatePhotoOutput() if (cameras.empty()) { return nullptr; } - phoIsSupportedNighitmode_ = false; + phoIsSupportedNightmode_ = false; for (sptr camDevice : cameras) { std::vector modes = cameraManager_->GetSupportedModes(camDevice); if (find(modes.begin(), modes.end(), SceneMode::NIGHT) != modes.end()) { - phoIsSupportedNighitmode_ = true; + phoIsSupportedNightmode_ = true; } - if (!phoIsSupportedNighitmode_) { + if (!phoIsSupportedNightmode_) { continue; } @@ -167,7 +167,7 @@ HWTEST_F(CameraNightSessionUnit, night_session_unittest_001, TestSize.Level1) sptr preview = CreatePreviewOutput(); sptr photo = CreatePhotoOutput(); - if (!preIsSupportedNighitmode_ || !phoIsSupportedNighitmode_) { + if (!preIsSupportedNightmode_ || !phoIsSupportedNightmode_) { input->Close(); GTEST_SKIP(); } @@ -227,13 +227,13 @@ HWTEST_F(CameraNightSessionUnit, night_session_unittest_002, TestSize.Level1) camInput->GetCameraDevice()->Open(); sptr preview = CreatePreviewOutput(); - if (!preIsSupportedNighitmode_) { + if (!preIsSupportedNightmode_) { input->Close(); GTEST_SKIP(); } ASSERT_NE(preview, nullptr); sptr photo = CreatePhotoOutput(); - if (!phoIsSupportedNighitmode_) { + if (!phoIsSupportedNightmode_) { input->Close(); GTEST_SKIP(); } @@ -292,7 +292,7 @@ HWTEST_F(CameraNightSessionUnit, night_session_unittest_003, TestSize.Level1) sptr preview = CreatePreviewOutput(); sptr photo = CreatePhotoOutput(); - if (!preIsSupportedNighitmode_ || !phoIsSupportedNighitmode_) { + if (!preIsSupportedNightmode_ || !phoIsSupportedNightmode_) { input->Close(); GTEST_SKIP(); } @@ -350,13 +350,13 @@ HWTEST_F(CameraNightSessionUnit, night_session_unittest_004, TestSize.Level0) camInput->GetCameraDevice()->Open(); sptr preview = CreatePreviewOutput(); - if (!preIsSupportedNighitmode_) { + if (!preIsSupportedNightmode_) { input->Close(); GTEST_SKIP(); } ASSERT_NE(preview, nullptr); sptr photo = CreatePhotoOutput(); - if (!phoIsSupportedNighitmode_) { + if (!phoIsSupportedNightmode_) { input->Close(); GTEST_SKIP(); } diff --git a/frameworks/native/camera/test/unittest/framework_native/session/src/scan_session_unittest.cpp b/frameworks/native/camera/test/unittest/framework_native/session/src/scan_session_unittest.cpp index 56a04681a..8bf38a3b9 100644 --- a/frameworks/native/camera/test/unittest/framework_native/session/src/scan_session_unittest.cpp +++ b/frameworks/native/camera/test/unittest/framework_native/session/src/scan_session_unittest.cpp @@ -47,8 +47,11 @@ using namespace OHOS::HDI::Camera::V1_1; sptr CameraScanSessionUnitTest::CreatePreviewOutput() { previewProfile_ = {}; + if (!cameraManager_) { + return nullptr; + } std::vector> cameras = cameraManager_->GetCameraDeviceListFromServer(); - if (!cameraManager_ || cameras.empty()) { + if (cameras.empty()) { return nullptr; } preIsSupportedScanmode_ = false; diff --git a/services/camera_service/src/camera_beauty_notification.cpp b/services/camera_service/src/camera_beauty_notification.cpp index 82d3a1c13..9da10667b 100644 --- a/services/camera_service/src/camera_beauty_notification.cpp +++ b/services/camera_service/src/camera_beauty_notification.cpp @@ -97,9 +97,8 @@ int32_t CameraBeautyNotification::GetBeautyTimes() int32_t CameraBeautyNotification::GetBeautyStatusFromDataShareHelper(int32_t &beautyStatus) { - if (cameraDataShareHelper_ == nullptr) { - cameraDataShareHelper_ = std::make_shared(); - } + CHECK_EXECUTE(cameraDataShareHelper_ == nullptr, + cameraDataShareHelper_ = std::make_shared()); std::string value = ""; auto ret = cameraDataShareHelper_->QueryOnce(PREDICATES_CAMERA_BEAUTY_STATUS, value); if (ret != CAMERA_OK) { @@ -118,9 +117,8 @@ int32_t CameraBeautyNotification::GetBeautyStatusFromDataShareHelper(int32_t &be int32_t CameraBeautyNotification::SetBeautyStatusFromDataShareHelper(int32_t beautyStatus) { - if (cameraDataShareHelper_ == nullptr) { - cameraDataShareHelper_ = std::make_shared(); - } + CHECK_EXECUTE(cameraDataShareHelper_ == nullptr, + cameraDataShareHelper_ = std::make_shared()); auto ret = cameraDataShareHelper_->UpdateOnce(PREDICATES_CAMERA_BEAUTY_STATUS, std::to_string(beautyStatus)); CHECK_RETURN_RET_ELOG(ret != CAMERA_OK, CAMERA_ALLOC_ERROR, "SetBeautyStatusFromDataShareHelper UpdateOnce fail."); return CAMERA_OK; @@ -128,9 +126,8 @@ int32_t CameraBeautyNotification::SetBeautyStatusFromDataShareHelper(int32_t bea int32_t CameraBeautyNotification::GetBeautyTimesFromDataShareHelper(int32_t ×) { - if (cameraDataShareHelper_ == nullptr) { - cameraDataShareHelper_ = std::make_shared(); - } + CHECK_EXECUTE(cameraDataShareHelper_ == nullptr, + cameraDataShareHelper_ = std::make_shared()); std::string value = ""; auto ret = cameraDataShareHelper_->QueryOnce(PREDICATES_CAMERA_BEAUTY_TIMES, value); if (ret != CAMERA_OK) { @@ -149,9 +146,8 @@ int32_t CameraBeautyNotification::GetBeautyTimesFromDataShareHelper(int32_t &tim int32_t CameraBeautyNotification::SetBeautyTimesFromDataShareHelper(int32_t times) { - if (cameraDataShareHelper_ == nullptr) { - cameraDataShareHelper_ = std::make_shared(); - } + CHECK_EXECUTE(cameraDataShareHelper_ == nullptr, + cameraDataShareHelper_ = std::make_shared()); auto ret = cameraDataShareHelper_->UpdateOnce(PREDICATES_CAMERA_BEAUTY_TIMES, std::to_string(times)); CHECK_RETURN_RET_ELOG(ret != CAMERA_OK, CAMERA_ALLOC_ERROR, "SetBeautyTimesFromDataShareHelper UpdateOnce fail."); return CAMERA_OK; diff --git a/services/camera_service/src/camera_datashare_helper.cpp b/services/camera_service/src/camera_datashare_helper.cpp index 6994ad736..8183c85bb 100644 --- a/services/camera_service/src/camera_datashare_helper.cpp +++ b/services/camera_service/src/camera_datashare_helper.cpp @@ -61,7 +61,7 @@ int32_t CameraDataShareHelper::QueryOnce(const std::string key, std::string &val resultSet->GetString(columnIndex, value); resultSet->Close(); dataShareHelper->Release(); - MEDIA_INFO_LOG("CameraDataShareHelper query success,value=%{public}s", value.c_str()); + MEDIA_INFO_LOG("CameraDataShareHelper query success,value=%{private}s", value.c_str()); return CAMERA_OK; } diff --git a/services/camera_service/src/camera_fwk_metadata_utils.cpp b/services/camera_service/src/camera_fwk_metadata_utils.cpp index d4e7c2a62..d4c913f78 100644 --- a/services/camera_service/src/camera_fwk_metadata_utils.cpp +++ b/services/camera_service/src/camera_fwk_metadata_utils.cpp @@ -99,6 +99,7 @@ std::shared_ptr CopyMetadata( { CHECK_RETURN_RET_ELOG(srcMetadata == nullptr, nullptr, "CopyMetadata fail, src is null"); auto metadataHeader = srcMetadata->get(); + CHECK_RETURN_RET_ELOG(metadataHeader == nullptr, nullptr, "CopyMetadata fail, metadataHeader is null"); auto newMetadata = std::make_shared(metadataHeader->item_capacity, metadataHeader->data_capacity); MergeMetadata(srcMetadata, newMetadata); @@ -124,6 +125,7 @@ void DumpMetadataInfo(const std::shared_ptr srcMet { CHECK_RETURN_ELOG(srcMetadata == nullptr, "DumpMetadataInfo srcMetadata is null"); auto metadataHeader = srcMetadata->get(); + CHECK_RETURN_ELOG(metadataHeader == nullptr, "DumpMetadataInfo metadataHeader is null"); uint32_t version = metadataHeader->version; uint32_t itemCount = metadataHeader->item_count; uint32_t dataCount = metadataHeader->data_count; diff --git a/services/camera_service/src/camera_privacy.cpp b/services/camera_service/src/camera_privacy.cpp index f17756260..7a558fbd4 100644 --- a/services/camera_service/src/camera_privacy.cpp +++ b/services/camera_service/src/camera_privacy.cpp @@ -42,6 +42,8 @@ void PermissionStatusChangeCb::PermStateChangeCallback(Security::AccessToken::Pe { MEDIA_INFO_LOG("enter CameraUseStateChangeNotify permStateChangeType:%{public}d" " permissionName:%{public}s", result.permStateChangeType, result.permissionName.c_str()); + CHECK_RETURN_ELOG(HCameraDeviceManager::GetInstance() == nullptr, + "PermissionStatusChangeCb::PermStateChangeCallback GetInstance is null"); std::vector> holders = HCameraDeviceManager::GetInstance()->GetActiveCameraHolders(); for (auto holder : holders) { if (holder->GetAccessTokenId() != result.tokenID) { @@ -65,6 +67,8 @@ void CameraUseStateChangeCb::StateChangeNotify(Security::AccessToken::AccessToke { MEDIA_INFO_LOG("CameraUseStateChangeCb::StateChangeNotify is called, isShowing: %{public}d", isShowing); std::vector> holders = HCameraDeviceManager::GetInstance()->GetActiveCameraHolders(); + CHECK_RETURN_ELOG(holders.empty(), + "CameraUseStateChangeCb::StateChangeNotify holders is null, skip."); for (auto holder : holders) { if (holder->GetAccessTokenId() != tokenId) { MEDIA_INFO_LOG("CameraUseStateChangeCb::StateChangeNotify not current tokenId, checking continue"); @@ -142,9 +146,9 @@ bool CameraPrivacy::AddCameraPermissionUsedRecord() { CAMERA_SYNC_TRACE; - int32_t successCout = 1; + int32_t successCount = 1; int32_t failCount = 0; - int32_t res = PrivacyKit::AddPermissionUsedRecord(callerToken_, OHOS_PERMISSION_CAMERA, successCout, failCount); + int32_t res = PrivacyKit::AddPermissionUsedRecord(callerToken_, OHOS_PERMISSION_CAMERA, successCount, failCount); MEDIA_INFO_LOG("CameraPrivacy::AddCameraPermissionUsedRecord res:%{public}d", res); CHECK_PRINT_ELOG(res != CAMERA_OK, "AddCameraPermissionUsedRecord failed."); return res == CAMERA_OK; diff --git a/services/camera_service/src/camera_util.cpp b/services/camera_service/src/camera_util.cpp index e25b7a8b3..041682eb9 100644 --- a/services/camera_service/src/camera_util.cpp +++ b/services/camera_service/src/camera_util.cpp @@ -257,6 +257,7 @@ bool IsValidMode(int32_t opMode, std::shared_ptr c return true; } camera_metadata_item_t item; + CHECK_RETURN_RET_ELOG(cameraAbility == nullptr, false, "cameraAbility is nullptr."); int ret = Camera::FindCameraMetadataItem(cameraAbility->get(), OHOS_ABILITY_CAMERA_MODES, &item); if (ret != CAM_META_SUCCESS || item.count == 0) { MEDIA_ERR_LOG("Failed to find stream extend configuration in camera ability with return code %{public}d", ret); @@ -301,7 +302,7 @@ void DumpMetadata(std::shared_ptr cameraSettings) } } else if (item.data_type == META_TYPE_UINT32) { for (size_t k = 0; k < item.count; k++) { - MEDIA_DEBUG_LOG("tag index:%d, name:%s, value:%d", item.index, name, (uint32_t)(item.data.ui32[k])); + MEDIA_DEBUG_LOG("tag index:%d, name:%s, value:%u", item.index, name, (uint32_t)(item.data.ui32[k])); } } else if (item.data_type == META_TYPE_FLOAT) { for (size_t k = 0; k < item.count; k++) { diff --git a/services/camera_service/src/hcamera_device_manager.cpp b/services/camera_service/src/hcamera_device_manager.cpp index 18a75785d..d87e32861 100644 --- a/services/camera_service/src/hcamera_device_manager.cpp +++ b/services/camera_service/src/hcamera_device_manager.cpp @@ -27,11 +27,11 @@ namespace OHOS { namespace CameraStandard { static const int32_t FOREGROUND_STATE_OF_PROCESS = 0; static const int32_t PIP_STATE_OF_PROCESS = 1; -static const int32_t BCAKGROUND_STATE_OF_PROCESS = 2; +static const int32_t BACKGROUND_STATE_OF_PROCESS = 2; static const int32_t UNKNOW_STATE_OF_PROCESS = 3; static const std::unordered_map APP_MGR_STATE_TO_CAMERA_STATE = { {2, FOREGROUND_STATE_OF_PROCESS}, - {4, BCAKGROUND_STATE_OF_PROCESS} + {4, BACKGROUND_STATE_OF_PROCESS} }; static const int32_t FOCUSED_STATE_OF_PROCESS = 1; static const int32_t UNFOCUSED_STATE_OF_PROCESS = 0; @@ -154,7 +154,7 @@ std::vector HCameraDeviceManager::GetActiveClient() std::lock_guard lock(mapMutex_); std::vector activeClientPids; if (!pidToCameras_.empty()) { - for (auto pair : pidToCameras_) { + for (auto& pair : pidToCameras_) { activeClientPids.emplace_back(pair.first); } } @@ -349,6 +349,8 @@ bool HCameraDeviceManager::HandleCameraEvictions(std::vector pidOfActiveClients = GetActiveClient(); pid_t pidOfOpenRequest = IPCSkeleton::GetCallingPid(); sptr amsClientInstance = CameraAppManagerClient::GetInstance(); + CHECK_RETURN_RET_ELOG(cameraRequestOpen == nullptr, false, + "HCameraDeviceManager::HandleCameraEvictions cameraRequestOpen is nullptr."); const std::string &cameraId = cameraRequestOpen->GetDevice()->GetCameraId(); int32_t requestState = amsClientInstance->GetProcessState(pidOfOpenRequest); for (auto eachClientPid : pidOfActiveClients) { @@ -518,6 +520,7 @@ void HCameraDeviceManager::GenerateEachProcessCameraState(int32_t& processState, void HCameraDeviceManager::PrintClientInfo(sptr activeCameraHolder, sptr requestCameraHolder) { + CHECK_RETURN_ELOG(activeCameraHolder->GetPriority() == nullptr, "GetPriority is nullptr"); MEDIA_INFO_LOG("activeInfo: uid: %{public}d, pid: %{public}d, processState: %{public}d, " "focusState: %{public}d, cameraId: %{public}s " "requestInfo: uid: %{public}d, pid: %{public}d, processState: %{public}d, " @@ -608,6 +611,7 @@ bool CameraConcurrentSelector::CanOpenCameraconcurrently(std::vector cameraIds; for (const auto& camera : reservedCameras) { + CHECK_CONTINUE_ELOG(camera->GetDevice() == nullptr, "CanOpenCameraconcurrently camera GetDevice is null."); cameraIds.push_back(GetCameraIdNumber(camera->GetDevice()->GetCameraId())); } for (const auto& group : concurrentCameraTable) { @@ -699,8 +703,11 @@ bool CameraConcurrentSelector::ConcurrentWithRetainedDevicesOrNot(sptr tempListToCheck; for (auto each : listOfCameraRetainable_) { + CHECK_CONTINUE_ELOG(each->GetDevice() == nullptr, "ConcurrentWithRetainedDevicesOrNot GetDevice is nullptr"); tempListToCheck.emplace_back(GetCameraIdNumber(each->GetDevice()->GetCameraId())); } + CHECK_RETURN_RET_ELOG(cameraIdNeedConfirm->GetDevice() == nullptr && requestCameraHolder_->GetDevice() == nullptr, + false, "ConcurrentWithRetainedDevicesOrNot GetDevice is nullptr."); tempListToCheck.emplace_back(GetCameraIdNumber(cameraIdNeedConfirm->GetDevice()->GetCameraId())); bool canOpenConcurrent = std::any_of( concurrentCameraTable_.begin(), concurrentCameraTable_.end(), [&](const std::vector &innerVec) { diff --git a/services/camera_service/src/hcamera_host_manager.cpp b/services/camera_service/src/hcamera_host_manager.cpp index 9b1aaaad4..eadcb6d86 100644 --- a/services/camera_service/src/hcamera_host_manager.cpp +++ b/services/camera_service/src/hcamera_host_manager.cpp @@ -482,6 +482,11 @@ int32_t HCameraHostManager::CameraHostInfo::PreCameraSwitch(const std::string& c void HCameraHostManager::CameraHostInfo::NotifyDeviceStateChangeInfo(int notifyType, int deviceState) { + if (notifyType < static_cast(DeviceType::FALLING_TYPE) || + notifyType > static_cast(DeviceType::RSS_MULTI_WINDOW_TYPE)) { + MEDIA_ERR_LOG("NotifyDeviceStateChangeInfo invalid notifyType: %{public}d", notifyType); + return; + } std::lock_guard lock(mutex_); CHECK_RETURN_ELOG(cameraHostProxy_ == nullptr, "CameraHostInfo::Prelaunch cameraHostProxy_ is null"); MEDIA_DEBUG_LOG("CameraHostInfo::NotifyDeviceStateChangeInfo notifyType = %{public}d, deviceState = %{public}d", @@ -1197,6 +1202,7 @@ void HCameraHostManager::RemoveCameraHost(const std::string& svcName) return; } std::vector cameraIds; + CHECK_RETURN_ELOG((*it) == nullptr, "*it is nullptr."); if ((*it)->GetCameras(cameraIds) == CAMERA_OK) { for (const auto& cameraId : cameraIds) { (*it)->OnCameraStatus(cameraId, UN_AVAILABLE); @@ -1214,6 +1220,7 @@ sptr HCameraHostManager::FindCameraHostInfo( { std::lock_guard lock(mutex_); for (const auto& cameraHostInfo : cameraHostInfos_) { + CHECK_CONTINUE_ELOG(cameraHostInfo == nullptr, "FindCameraHostInfo: cameraHostInfo is null, skip"); CHECK_RETURN_RET(cameraHostInfo->IsCameraSupported(cameraId), cameraHostInfo); } return nullptr; diff --git a/services/camera_service/src/hcamera_preconfig.cpp b/services/camera_service/src/hcamera_preconfig.cpp index c2227becf..18974bc0c 100644 --- a/services/camera_service/src/hcamera_preconfig.cpp +++ b/services/camera_service/src/hcamera_preconfig.cpp @@ -165,6 +165,7 @@ struct PreconfigProfile { std::string maxSizeInfo = ""; for (auto& cameraInfo : cameraInfos) { camera_metadata_item_t item; + CHECK_RETURN_RET(cameraInfo.ability == nullptr, "cameraInfo.ability is null"); int ret = OHOS::Camera::CameraMetadata::FindCameraMetadataItem( cameraInfo.ability->get(), OHOS_ABILITY_CAMERA_TYPE, &item); CHECK_RETURN_RET(ret != CAM_META_SUCCESS || item.count == 0, "device camera type info error"); @@ -377,6 +378,7 @@ void DumpPreconfigInfo(CameraInfoDumper& infoDumper, sptr& h { RATIO_16_9, "ratio 16:9" } }; std::vector cameraIds; std::vector cameraInfos; + CHECK_RETURN_ELOG(hostManager == nullptr, "DumpPreconfigInfo hostManager is nullptr."); hostManager->GetCameras(cameraIds); for (auto& cameraId : cameraIds) { CameraInfo cameraInfo { .cameraId = cameraId }; diff --git a/services/camera_service/src/hcamera_service.cpp b/services/camera_service/src/hcamera_service.cpp index 2d4638348..d0a3415aa 100644 --- a/services/camera_service/src/hcamera_service.cpp +++ b/services/camera_service/src/hcamera_service.cpp @@ -145,6 +145,7 @@ void HCameraService::DeviceInitCallBack::OnRemoteDied() void HCameraService::OnStart() { MEDIA_INFO_LOG("HCameraService OnStart begin"); + CHECK_RETURN_ELOG(cameraHostManager_ == nullptr, "HCameraService::OnStart failed cameraHostManager_ is nullptr"); CHECK_PRINT_ELOG(cameraHostManager_->Init() != CAMERA_OK, "HCameraService OnStart failed to init camera host manager."); // initialize deferred processing service. @@ -194,6 +195,7 @@ void HCameraService::OnDump() void HCameraService::OnStop() { MEDIA_INFO_LOG("HCameraService::OnStop called"); + CHECK_RETURN_ELOG(cameraHostManager_ == nullptr, "HCameraService::OnStop failed to cameraHostManager_ is nullptr"); cameraHostManager_->DeInit(); UnregisterFoldStatusListener(); } diff --git a/services/camera_service/src/hcamera_session_manager.cpp b/services/camera_service/src/hcamera_session_manager.cpp index 8ffdb01f4..6439b5825 100644 --- a/services/camera_service/src/hcamera_session_manager.cpp +++ b/services/camera_service/src/hcamera_session_manager.cpp @@ -158,7 +158,7 @@ void HCameraSessionManager::RemoveSession(sptr session) CHECK_RETURN(session == nullptr); std::lock_guard lock(totalSessionMapMutex_); auto mapIt = totalSessionMap_.find(session->GetPid()); - CHECK_RETURN(mapIt == totalSessionMap_.end()); + CHECK_RETURN_ELOG(mapIt == totalSessionMap_.end(), "RemoveSession failed: session with PID not found"); auto& list = mapIt->second; for (auto listIt = list.begin(); listIt != list.end(); listIt++) { if (session == *listIt) { -- Gitee From e40f23bd6e247b765c09aa04e3268e1a39f59faa Mon Sep 17 00:00:00 2001 From: cjj Date: Sat, 13 Sep 2025 10:41:53 +0000 Subject: [PATCH 2/3] update services/camera_service/src/camera_privacy.cpp. Signed-off-by: cjj --- services/camera_service/src/camera_privacy.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/camera_service/src/camera_privacy.cpp b/services/camera_service/src/camera_privacy.cpp index 7a558fbd4..0d1094bec 100644 --- a/services/camera_service/src/camera_privacy.cpp +++ b/services/camera_service/src/camera_privacy.cpp @@ -43,7 +43,7 @@ void PermissionStatusChangeCb::PermStateChangeCallback(Security::AccessToken::Pe MEDIA_INFO_LOG("enter CameraUseStateChangeNotify permStateChangeType:%{public}d" " permissionName:%{public}s", result.permStateChangeType, result.permissionName.c_str()); CHECK_RETURN_ELOG(HCameraDeviceManager::GetInstance() == nullptr, - "PermissionStatusChangeCb::PermStateChangeCallback GetInstance is null"); + "PermissionStatusChangeCb::PermStateChangeCallback GetInstance is null"); std::vector> holders = HCameraDeviceManager::GetInstance()->GetActiveCameraHolders(); for (auto holder : holders) { if (holder->GetAccessTokenId() != result.tokenID) { @@ -68,7 +68,7 @@ void CameraUseStateChangeCb::StateChangeNotify(Security::AccessToken::AccessToke MEDIA_INFO_LOG("CameraUseStateChangeCb::StateChangeNotify is called, isShowing: %{public}d", isShowing); std::vector> holders = HCameraDeviceManager::GetInstance()->GetActiveCameraHolders(); CHECK_RETURN_ELOG(holders.empty(), - "CameraUseStateChangeCb::StateChangeNotify holders is null, skip."); + "CameraUseStateChangeCb::StateChangeNotify holders is null, skip."); for (auto holder : holders) { if (holder->GetAccessTokenId() != tokenId) { MEDIA_INFO_LOG("CameraUseStateChangeCb::StateChangeNotify not current tokenId, checking continue"); -- Gitee From 431b0d3a21a271d57c7b7b449bb5b863c79593f4 Mon Sep 17 00:00:00 2001 From: cjj Date: Sat, 13 Sep 2025 10:43:01 +0000 Subject: [PATCH 3/3] update services/camera_service/src/hcamera_device_manager.cpp. Signed-off-by: cjj --- services/camera_service/src/hcamera_device_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/camera_service/src/hcamera_device_manager.cpp b/services/camera_service/src/hcamera_device_manager.cpp index d87e32861..79c788952 100644 --- a/services/camera_service/src/hcamera_device_manager.cpp +++ b/services/camera_service/src/hcamera_device_manager.cpp @@ -706,7 +706,7 @@ bool CameraConcurrentSelector::ConcurrentWithRetainedDevicesOrNot(sptrGetDevice() == nullptr, "ConcurrentWithRetainedDevicesOrNot GetDevice is nullptr"); tempListToCheck.emplace_back(GetCameraIdNumber(each->GetDevice()->GetCameraId())); } - CHECK_RETURN_RET_ELOG(cameraIdNeedConfirm->GetDevice() == nullptr && requestCameraHolder_->GetDevice() == nullptr, + CHECK_RETURN_RET_ELOG(cameraIdNeedConfirm->GetDevice() == nullptr && requestCameraHolder_->GetDevice() == nullptr, false, "ConcurrentWithRetainedDevicesOrNot GetDevice is nullptr."); tempListToCheck.emplace_back(GetCameraIdNumber(cameraIdNeedConfirm->GetDevice()->GetCameraId())); bool canOpenConcurrent = std::any_of( -- Gitee