From 70df0abc5bf7ff1cff4d51e78853d7fa1addb9af Mon Sep 17 00:00:00 2001 From: cold_yixiu Date: Fri, 9 Sep 2022 18:00:17 +0800 Subject: [PATCH] refactor for camera frameworks and services Signed-off-by: cold_yixiu --- bundle.json | 23 ++++--- frameworks/native/camera/BUILD.gn | 10 ++-- .../native/camera/src/input/camera_input.cpp | 30 ---------- .../camera/src/input/camera_manager.cpp | 43 ------------- .../native/camera/src/output/photo_output.cpp | 2 - .../camera/src/output/preview_output.cpp | 1 - .../native/camera/src/output/video_output.cpp | 1 - .../camera/src/session/capture_session.cpp | 55 ----------------- services/camera_service/BUILD.gn | 9 +-- .../camera_service/include/hcamera_device.h | 2 + .../camera_service/src/hcamera_device.cpp | 60 ++++++++++++++++++- .../camera_service/src/hcamera_service.cpp | 45 ++++++++++++++ .../camera_service/src/hcapture_session.cpp | 50 ++++++++++++++++ .../camera_service/src/hstream_capture.cpp | 8 ++- .../camera_service/src/hstream_repeat.cpp | 7 ++- 15 files changed, 189 insertions(+), 157 deletions(-) diff --git a/bundle.json b/bundle.json index 983a91cb7..a2484f96a 100644 --- a/bundle.json +++ b/bundle.json @@ -33,14 +33,21 @@ ] }, "build": { - "sub_component": [ - "//foundation/multimedia/camera_framework/sa_profile:camera_service_sa_profile", - "//foundation/multimedia/camera_framework/services/etc:camera_service.rc", - "//foundation/multimedia/camera_framework/services/camera_service:camera_service", - "//foundation/multimedia/camera_framework/frameworks/native/camera:camera_framework", - "//foundation/multimedia/camera_framework/interfaces/kits/js/camera_napi:camera_napi", - "//foundation/multimedia/camera_framework/interfaces/kits/js/camera_napi:camera_js" - ], + "group_type": { + "base_group": [ + ], + "fwk_group": [ + "//foundation/multimedia/camera_framework/frameworks/native/camera:camera_framework", + "//foundation/multimedia/camera_framework/interfaces/kits/js/camera_napi:camera_napi", + "//foundation/multimedia/camera_framework/interfaces/kits/js/camera_napi:camera_js" + ], + "service_group": [ + "//foundation/multimedia/camera_framework/sa_profile:camera_service_sa_profile", + "//foundation/multimedia/camera_framework/services/etc:camera_service.rc", + "//foundation/multimedia/camera_framework/services/camera_service:camera_service" + ] + }, + "inner_kits": [ { "type": "none", diff --git a/frameworks/native/camera/BUILD.gn b/frameworks/native/camera/BUILD.gn index 4e7879aea..cd6943b4b 100644 --- a/frameworks/native/camera/BUILD.gn +++ b/frameworks/native/camera/BUILD.gn @@ -50,6 +50,12 @@ ohos_shared_library("camera_framework") { "//foundation/multimedia/camera_framework/services/camera_service/binder/client/src/hstream_capture_proxy.cpp", "//foundation/multimedia/camera_framework/services/camera_service/binder/client/src/hstream_metadata_proxy.cpp", "//foundation/multimedia/camera_framework/services/camera_service/binder/client/src/hstream_repeat_proxy.cpp", + "//foundation/multimedia/camera_framework/services/camera_service/binder/server/src/hcamera_device_callback_stub.cpp", + "//foundation/multimedia/camera_framework/services/camera_service/binder/server/src/hcamera_listener_stub.cpp", + "//foundation/multimedia/camera_framework/services/camera_service/binder/server/src/hcamera_service_callback_stub.cpp", + "//foundation/multimedia/camera_framework/services/camera_service/binder/server/src/hcapture_session_callback_stub.cpp", + "//foundation/multimedia/camera_framework/services/camera_service/binder/server/src/hstream_capture_callback_stub.cpp", + "//foundation/multimedia/camera_framework/services/camera_service/binder/server/src/hstream_repeat_callback_stub.cpp", "src/input/camera_info.cpp", "src/input/camera_input.cpp", "src/input/camera_manager.cpp", @@ -85,13 +91,9 @@ ohos_shared_library("camera_framework") { "//drivers/interface/camera/v1_0:libcamera_proxy_1.0", "//drivers/peripheral/camera/interfaces/metadata:metadata", "//foundation/graphic/graphic_2d:libsurface", - "//foundation/multimedia/camera_framework/services/camera_service:camera_service", ] external_deps = [ - "ability_base:want", - "bundle_framework:appexecfwk_base", - "bundle_framework:appexecfwk_core", "hisysevent_native:libhisysevent", "hitrace_native:hitrace_meter", "hiviewdfx_hilog_native:libhilog", diff --git a/frameworks/native/camera/src/input/camera_input.cpp b/frameworks/native/camera/src/input/camera_input.cpp index 352e38898..0a805e84e 100644 --- a/frameworks/native/camera/src/input/camera_input.cpp +++ b/frameworks/native/camera/src/input/camera_input.cpp @@ -20,7 +20,6 @@ #include "camera_device_ability_items.h" #include "camera_util.h" #include "hcamera_device_callback_stub.h" -#include "ipc_skeleton.h" #include "camera_log.h" #include "metadata_utils.h" @@ -51,8 +50,6 @@ public: MEDIA_ERR_LOG("CameraDeviceServiceCallback::OnError() is called!, errorType: %{public}d, errorMsg: %{public}d", errorType, errorMsg); if (camInput_ != nullptr && camInput_->GetErrorCallback() != nullptr) { - CAMERA_SYSEVENT_FAULT(CreateMsg("CameraDeviceServiceCallback::OnError() is called!, errorType: %d," - "errorMsg: %d", errorType, errorMsg)); camInput_->GetErrorCallback()->OnError(errorType, errorMsg); } else { MEDIA_INFO_LOG("CameraDeviceServiceCallback::ErrorCallback not set!, Discarding callback"); @@ -64,23 +61,6 @@ public: { MEDIA_INFO_LOG("CameraDeviceServiceCallback::OnResult() is called!, cameraId: %{public}s, timestamp: %{public}" PRIu64, camInput_->GetCameraDeviceInfo()->GetID().c_str(), timestamp); - camera_metadata_item_t item; - int ret = Camera::FindCameraMetadataItem(result->get(), OHOS_CONTROL_FLASH_STATE, &item); - if (ret == 0) { - MEDIA_INFO_LOG("CameraDeviceServiceCallback::OnResult() OHOS_CONTROL_FLASH_STATE is %{public}d", - item.data.u8[0]); - CAMERA_SYSEVENT_BEHAVIOR(CreateMsg("FlashStateChanged! current OHOS_CONTROL_FLASH_STATE is %d", - item.data.u8[0])); - POWERMGR_SYSEVENT_TORCH_STATE(IPCSkeleton::GetCallingPid(), - IPCSkeleton::GetCallingUid(), item.data.u8[0]); - } - ret = Camera::FindCameraMetadataItem(result->get(), OHOS_CONTROL_FLASH_MODE, &item); - if (ret == 0) { - MEDIA_INFO_LOG("CameraDeviceServiceCallback::OnResult() OHOS_CONTROL_FLASH_MODE is %{public}d", - item.data.u8[0]); - CAMERA_SYSEVENT_BEHAVIOR(CreateMsg("FlashModeChanged! current OHOS_CONTROL_FLASH_MODE is %d", - item.data.u8[0])); - } camInput_->ProcessAutoExposureUpdates(result); camInput_->ProcessAutoFocusUpdates(result); @@ -822,12 +802,6 @@ void CameraInput::SetFlashMode(camera_flash_mode_enum_t flashMode) MEDIA_ERR_LOG("CameraInput::SetFlashMode Failed to set flash mode"); return; } - - if (flashMode == OHOS_CAMERA_FLASH_MODE_CLOSE) { - POWERMGR_SYSEVENT_FLASH_OFF(); - } else { - POWERMGR_SYSEVENT_FLASH_ON(); - } } void CameraInput::SetErrorCallback(std::shared_ptr errorCallback) @@ -856,14 +830,10 @@ void CameraInput::ProcessAutoFocusUpdates(const std::shared_ptr(item.data.u8[0]); auto itr = mapFromMetadataFocus_.find(focusState); diff --git a/frameworks/native/camera/src/input/camera_manager.cpp b/frameworks/native/camera/src/input/camera_manager.cpp index 5cd0eb9a2..1dcabe1bf 100644 --- a/frameworks/native/camera/src/input/camera_manager.cpp +++ b/frameworks/native/camera/src/input/camera_manager.cpp @@ -70,9 +70,6 @@ public: CameraDeviceStatus deviceStatus; CameraStatusInfo cameraStatusInfo; - CAMERA_SYSEVENT_BEHAVIOR(CreateMsg("OnCameraStatusChanged! for cameraId:%s, current Camera Status:%d", - cameraId.c_str(), status)); - if (camMngr_ != nullptr && camMngr_->GetApplicationCallback() != nullptr) { switch (status) { case CAMERA_STATUS_UNAVAILABLE: @@ -103,12 +100,6 @@ public: int32_t OnFlashlightStatusChanged(const std::string& cameraId, const FlashStatus status) override { FlashlightStatus flashlightStatus; - - CAMERA_SYSEVENT_BEHAVIOR(CreateMsg("OnFlashlightStatusChanged! for cameraId:%s, current Flash Status:%d", - cameraId.c_str(), status)); - POWERMGR_SYSEVENT_TORCH_STATE(IPCSkeleton::GetCallingPid(), - IPCSkeleton::GetCallingUid(), status); - MEDIA_INFO_LOG("OnFlashlightStatusChanged: cameraId: %{public}s, status: %{public}d", cameraId.c_str(), status); if (camMngr_ != nullptr && camMngr_->GetApplicationCallback() != nullptr) { switch (status) { @@ -176,9 +167,6 @@ sptr CameraManager::CreatePhotoOutput(sptr &surface) result = new(std::nothrow) PhotoOutput(streamCapture); if (result == nullptr) { MEDIA_ERR_LOG("Failed to new PhotoOutput "); - } else { - POWERMGR_SYSEVENT_CAMERA_CONFIG(PHOTO, surface->GetDefaultWidth(), - surface->GetDefaultHeight()); } } else { MEDIA_ERR_LOG("Failed to get stream capture object from hcamera service!, %{public}d", retCode); @@ -202,10 +190,6 @@ sptr CameraManager::CreatePhotoOutput(const sptrGetDefaultWidth(), - producer->GetDefaultHeight()); } } else { MEDIA_ERR_LOG("Failed to get stream capture object from hcamera service!, %{public}d", retCode); @@ -230,10 +214,6 @@ sptr CameraManager::CreatePreviewOutput(sptr surface) result = new(std::nothrow) PreviewOutput(streamRepeat); if (result == nullptr) { MEDIA_ERR_LOG("Failed to new PreviewOutput"); - } else { - POWERMGR_SYSEVENT_CAMERA_CONFIG(PREVIEW, - surface->GetDefaultWidth(), - surface->GetDefaultHeight()); } } else { MEDIA_ERR_LOG("PreviewOutput: Failed to get stream repeat object from hcamera service!, %{public}d", retCode); @@ -257,10 +237,6 @@ sptr CameraManager::CreatePreviewOutput(const sptrGetDefaultWidth(), - producer->GetDefaultHeight()); } } else { MEDIA_ERR_LOG("PreviewOutput: Failed to get stream repeat object from hcamera service!, %{public}d", retCode); @@ -286,8 +262,6 @@ sptr CameraManager::CreateCustomPreviewOutput(sptr surfa result = new(std::nothrow) PreviewOutput(streamRepeat); if (result == nullptr) { MEDIA_ERR_LOG("Failed to new PreviewOutput"); - } else { - POWERMGR_SYSEVENT_CAMERA_CONFIG(PREVIEW, width, height); } } else { MEDIA_ERR_LOG("PreviewOutput: Failed to get stream repeat object from hcamera service!, %{public}d", retCode); @@ -312,8 +286,6 @@ sptr CameraManager::CreateCustomPreviewOutput(const sptr CameraManager::CreateMetadataOutput() MEDIA_ERR_LOG("CameraManager::CreateMetadataOutput Surface consumer listener registration failed"); return nullptr; } - POWERMGR_SYSEVENT_CAMERA_CONFIG(METADATA, width, height); return result; } @@ -386,10 +357,6 @@ sptr CameraManager::CreateVideoOutput(sptr &surface) result = new(std::nothrow) VideoOutput(streamRepeat); if (result == nullptr) { MEDIA_ERR_LOG("Failed to new VideoOutput"); - } else { - POWERMGR_SYSEVENT_CAMERA_CONFIG(VIDEO, - surface->GetDefaultWidth(), - surface->GetDefaultHeight()); } } else { MEDIA_ERR_LOG("VideoOutpout: Failed to get stream repeat object from hcamera service! %{public}d", retCode); @@ -413,10 +380,6 @@ sptr CameraManager::CreateVideoOutput(const sptrGetDefaultWidth(), - producer->GetDefaultHeight()); } } else { MEDIA_ERR_LOG("VideoOutpout: Failed to get stream repeat object from hcamera service! %{public}d", retCode); @@ -560,10 +523,6 @@ std::vector> CameraManager::GetCameras() MEDIA_ERR_LOG("CameraManager::GetCameras new CameraInfo failed for id={public}%s", it.c_str()); continue; } - CAMERA_SYSEVENT_STATISTIC(CreateMsg("CameraManager GetCameras camera ID:%s, Camera position:%d," - " Camera Type:%d, Connection Type:%d, Mirror support:%d", it.c_str(), - cameraObj->GetPosition(), cameraObj->GetCameraType(), - cameraObj->GetConnectionType(), cameraObj->IsMirrorSupported())); cameraObjList.emplace_back(cameraObj); } } else { @@ -592,8 +551,6 @@ sptr CameraManager::CreateCameraInput(sptr &camera) } else { MEDIA_ERR_LOG("CameraManager::CreateCameraInput: Camera object is null"); } - CAMERA_SYSEVENT_STATISTIC(CreateMsg("CameraManager_CreateCameraInput CameraId:%s", camera->GetID().c_str())); - return cameraInput; } diff --git a/frameworks/native/camera/src/output/photo_output.cpp b/frameworks/native/camera/src/output/photo_output.cpp index f3ed41248..398524728 100644 --- a/frameworks/native/camera/src/output/photo_output.cpp +++ b/frameworks/native/camera/src/output/photo_output.cpp @@ -206,8 +206,6 @@ public: int32_t OnCaptureError(const int32_t captureId, const int32_t errorCode) override { if (photoOutput_ != nullptr && photoOutput_->GetApplicationCallback() != nullptr) { - CAMERA_SYSEVENT_FAULT(CreateMsg("Photo OnCaptureError! captureId:%d & " - "errorCode:%{public}d", captureId, errorCode)); photoOutput_->GetApplicationCallback()->OnCaptureError(captureId, errorCode); } else { MEDIA_INFO_LOG("Discarding HStreamCaptureCallbackImpl::OnCaptureError callback"); diff --git a/frameworks/native/camera/src/output/preview_output.cpp b/frameworks/native/camera/src/output/preview_output.cpp index 0661efebc..155a3cfd4 100644 --- a/frameworks/native/camera/src/output/preview_output.cpp +++ b/frameworks/native/camera/src/output/preview_output.cpp @@ -72,7 +72,6 @@ public: int32_t OnFrameError(int32_t errorCode) override { if (previewOutput_ != nullptr && previewOutput_->GetApplicationCallback() != nullptr) { - CAMERA_SYSEVENT_FAULT(CreateMsg("Preview OnFrameError! errorCode:%d", errorCode)); previewOutput_->GetApplicationCallback()->OnError(errorCode); } else { MEDIA_INFO_LOG("Discarding HStreamRepeatCallbackImpl::OnFrameError callback in preview"); diff --git a/frameworks/native/camera/src/output/video_output.cpp b/frameworks/native/camera/src/output/video_output.cpp index afdb9670a..fc6d4132c 100644 --- a/frameworks/native/camera/src/output/video_output.cpp +++ b/frameworks/native/camera/src/output/video_output.cpp @@ -65,7 +65,6 @@ public: int32_t OnFrameError(const int32_t errorCode) override { if (videoOutput_ != nullptr && videoOutput_->GetApplicationCallback() != nullptr) { - CAMERA_SYSEVENT_FAULT(CreateMsg("Video OnFrameError! errorCode:%d", errorCode)); videoOutput_->GetApplicationCallback()->OnError(errorCode); } else { MEDIA_INFO_LOG("Discarding HStreamRepeatCallbackImpl::OnFrameError callback in video"); diff --git a/frameworks/native/camera/src/session/capture_session.cpp b/frameworks/native/camera/src/session/capture_session.cpp index 2c0371773..88f98daee 100644 --- a/frameworks/native/camera/src/session/capture_session.cpp +++ b/frameworks/native/camera/src/session/capture_session.cpp @@ -17,17 +17,10 @@ #include "camera_util.h" #include "hcapture_session_callback_stub.h" #include "input/camera_input.h" -#include "ipc_skeleton.h" #include "camera_log.h" #include "output/photo_output.h" #include "output/preview_output.h" #include "output/video_output.h" -#include "bundle_mgr_interface.h" -#include "iservice_registry.h" -#include "system_ability_definition.h" - -using namespace OHOS::AppExecFwk; -using namespace OHOS::AAFwk; namespace OHOS { namespace CameraStandard { @@ -50,7 +43,6 @@ public: MEDIA_INFO_LOG("CaptureSessionCallback::OnError() is called!, errorCode: %{public}d", errorCode); if (captureSession_ != nullptr && captureSession_->GetApplicationCallback() != nullptr) { - CAMERA_SYSEVENT_FAULT(CreateMsg("Session OnError! errorCode:%d", errorCode)); captureSession_->GetApplicationCallback()->OnError(errorCode); } else { MEDIA_INFO_LOG("CaptureSessionCallback::ApplicationCallback not set!, Discarding callback"); @@ -59,37 +51,6 @@ public: } }; -static std::string GetClientBundle(int uid) -{ - std::string bundleName = ""; - auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (samgr == nullptr) { - MEDIA_ERR_LOG("Get ability manager failed"); - return bundleName; - } - - sptr object = samgr->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); - if (object == nullptr) { - MEDIA_DEBUG_LOG("object is NULL."); - return bundleName; - } - - sptr bms = iface_cast(object); - if (bms == nullptr) { - MEDIA_DEBUG_LOG("bundle manager service is NULL."); - return bundleName; - } - - auto result = bms->GetBundleNameForUid(uid, bundleName); - if (!result) { - MEDIA_ERR_LOG("GetBundleNameForUid fail"); - return ""; - } - MEDIA_INFO_LOG("bundle name is %{public}s ", bundleName.c_str()); - - return bundleName; -} - CaptureSession::CaptureSession(sptr &captureSession) { captureSession_ = captureSession; @@ -112,14 +73,6 @@ int32_t CaptureSession::BeginConfig() int32_t CaptureSession::CommitConfig() { CAMERA_SYNC_TRACE; - if (inputDevice_ != nullptr) { - int32_t pid = IPCSkeleton::GetCallingPid(); - int32_t uid = IPCSkeleton::GetCallingUid(); - POWERMGR_SYSEVENT_CAMERA_CONNECT(pid, uid, - inputDevice_->GetCameraDeviceInfo()->GetID().c_str(), - GetClientBundle(uid)); - } - return captureSession_->CommitConfig(); } @@ -130,7 +83,6 @@ int32_t CaptureSession::AddInput(sptr &input) MEDIA_ERR_LOG("CaptureSession::AddInput input is null"); return CAMERA_INVALID_ARG; } - CAMERA_SYSEVENT_STATISTIC(CreateMsg("CaptureSession::AddInput")); inputDevice_ = input; return captureSession_->AddInput(((sptr &)input)->GetCameraDevice()); } @@ -142,7 +94,6 @@ int32_t CaptureSession::AddOutput(sptr &output) MEDIA_ERR_LOG("CaptureSession::AddOutput output is null"); return CAMERA_INVALID_ARG; } - CAMERA_SYSEVENT_STATISTIC(CreateMsg("CaptureSession::AddOutput with %s", output->GetOutputTypeString())); output->SetSession(this); return captureSession_->AddOutput(output->GetStreamType(), output->GetStream()); } @@ -154,7 +105,6 @@ int32_t CaptureSession::RemoveInput(sptr &input) MEDIA_ERR_LOG("CaptureSession::RemoveInput input is null"); return CAMERA_INVALID_ARG; } - CAMERA_SYSEVENT_STATISTIC(CreateMsg("CaptureSession::RemoveInput")); if (inputDevice_ != nullptr) { inputDevice_ = nullptr; } @@ -168,7 +118,6 @@ int32_t CaptureSession::RemoveOutput(sptr &output) MEDIA_ERR_LOG("CaptureSession::RemoveOutput output is null"); return CAMERA_INVALID_ARG; } - CAMERA_SYSEVENT_STATISTIC(CreateMsg("CaptureSession::RemoveOutput with %s", output->GetOutputTypeString())); output->SetSession(nullptr); return captureSession_->RemoveOutput(output->GetStreamType(), output->GetStream()); } @@ -300,10 +249,6 @@ std::shared_ptr CaptureSession::GetApplicationCallback() void CaptureSession::Release() { CAMERA_SYNC_TRACE; - if (inputDevice_ != nullptr) { - POWERMGR_SYSEVENT_CAMERA_DISCONNECT(inputDevice_->GetCameraDeviceInfo()->GetID().c_str()); - inputDevice_ = nullptr; - } int32_t errCode = captureSession_->Release(0); if (errCode != CAMERA_OK) { MEDIA_ERR_LOG("Failed to Release capture session!, %{public}d", errCode); diff --git a/services/camera_service/BUILD.gn b/services/camera_service/BUILD.gn index 7f5d820d5..e575fc100 100644 --- a/services/camera_service/BUILD.gn +++ b/services/camera_service/BUILD.gn @@ -22,17 +22,11 @@ ohos_shared_library("camera_service") { "binder/client/src/hcapture_session_callback_proxy.cpp", "binder/client/src/hstream_capture_callback_proxy.cpp", "binder/client/src/hstream_repeat_callback_proxy.cpp", - "binder/server/src/hcamera_device_callback_stub.cpp", "binder/server/src/hcamera_device_stub.cpp", - "binder/server/src/hcamera_listener_stub.cpp", - "binder/server/src/hcamera_service_callback_stub.cpp", "binder/server/src/hcamera_service_stub.cpp", - "binder/server/src/hcapture_session_callback_stub.cpp", "binder/server/src/hcapture_session_stub.cpp", - "binder/server/src/hstream_capture_callback_stub.cpp", "binder/server/src/hstream_capture_stub.cpp", "binder/server/src/hstream_metadata_stub.cpp", - "binder/server/src/hstream_repeat_callback_stub.cpp", "binder/server/src/hstream_repeat_stub.cpp", "src/camera_util.cpp", "src/hcamera_device.cpp", @@ -75,7 +69,10 @@ ohos_shared_library("camera_service") { ] external_deps = [ + "ability_base:want", "access_token:libaccesstoken_sdk", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", "hisysevent_native:libhisysevent", "hitrace_native:hitrace_meter", "hiviewdfx_hilog_native:libhilog", diff --git a/services/camera_service/include/hcamera_device.h b/services/camera_service/include/hcamera_device.h index 645f7384b..8a6d81494 100644 --- a/services/camera_service/include/hcamera_device.h +++ b/services/camera_service/include/hcamera_device.h @@ -63,6 +63,8 @@ private: std::shared_ptr updateSettings_; sptr streamOperator_; std::mutex deviceLock_; + + void ReportFlashEvent(const std::shared_ptr &settings); }; class CameraDeviceCallback : public ICameraDeviceCallback { diff --git a/services/camera_service/src/hcamera_device.cpp b/services/camera_service/src/hcamera_device.cpp index b75184a8c..b1fab6397 100644 --- a/services/camera_service/src/hcamera_device.cpp +++ b/services/camera_service/src/hcamera_device.cpp @@ -17,6 +17,7 @@ #include "camera_util.h" #include "camera_log.h" +#include "ipc_skeleton.h" #include "metadata_utils.h" namespace OHOS { @@ -177,12 +178,29 @@ int32_t HCameraDevice::UpdateSetting(const std::shared_ptr &settings) { + camera_metadata_item_t item; + camera_flash_mode_enum_t flashMode = OHOS_CAMERA_FLASH_MODE_ALWAYS_OPEN; + int ret = OHOS::Camera::FindCameraMetadataItem(settings->get(), OHOS_CONTROL_FLASH_MODE, &item); + if (ret != CAM_META_SUCCESS) { + MEDIA_ERR_LOG("CameraInput::GetFlashMode Failed with return code %{public}d", ret); + flashMode = static_cast(item.data.u8[0]); + } + + if (flashMode == OHOS_CAMERA_FLASH_MODE_CLOSE) { + POWERMGR_SYSEVENT_FLASH_OFF(); + } else { + POWERMGR_SYSEVENT_FLASH_ON(); + } +} + int32_t HCameraDevice::EnableResult(std::vector &results) { if (results.empty()) { @@ -264,13 +282,17 @@ sptr HCameraDevice::GetStreamOperator() int32_t HCameraDevice::OnError(const ErrorType type, const int32_t errorMsg) { if (deviceSvcCallback_ != nullptr) { + int32_t errorType; if (type == REQUEST_TIMEOUT) { - deviceSvcCallback_->OnError(CAMERA_DEVICE_REQUEST_TIMEOUT, errorMsg); + errorType = CAMERA_DEVICE_REQUEST_TIMEOUT; } else if (type == DEVICE_PREEMPT) { - deviceSvcCallback_->OnError(CAMERA_DEVICE_PREEMPTED, errorMsg); + errorType = CAMERA_DEVICE_PREEMPTED; } else { - deviceSvcCallback_->OnError(CAMERA_UNKNOWN_ERROR, errorMsg); + errorType = CAMERA_UNKNOWN_ERROR; } + deviceSvcCallback_->OnError(errorType, errorMsg); + CAMERA_SYSEVENT_FAULT(CreateMsg("CameraDeviceServiceCallback::OnError() is called!, errorType: %d," + "errorMsg: %d", errorType, errorMsg)); } return CAMERA_OK; } @@ -281,6 +303,38 @@ int32_t HCameraDevice::OnResult(const uint64_t timestamp, if (deviceSvcCallback_ != nullptr) { deviceSvcCallback_->OnResult(timestamp, result); } + camera_metadata_item_t item; + common_metadata_header_t *metadata = result->get(); + int ret = OHOS::Camera::FindCameraMetadataItem(metadata, OHOS_CONTROL_FLASH_MODE, &item); + if (ret == 0) { + MEDIA_INFO_LOG("CameraDeviceServiceCallback::OnResult() OHOS_CONTROL_FLASH_MODE is %{public}d", + item.data.u8[0]); + CAMERA_SYSEVENT_BEHAVIOR(CreateMsg("FlashModeChanged! current OHOS_CONTROL_FLASH_MODE is %d", + item.data.u8[0])); + } + ret = OHOS::Camera::FindCameraMetadataItem(metadata, OHOS_CONTROL_FLASH_STATE, &item); + if (ret == 0) { + MEDIA_INFO_LOG("CameraDeviceServiceCallback::OnResult() OHOS_CONTROL_FLASH_STATE is %{public}d", + item.data.u8[0]); + CAMERA_SYSEVENT_BEHAVIOR(CreateMsg("FlashStateChanged! current OHOS_CONTROL_FLASH_STATE is %d", + item.data.u8[0])); + POWERMGR_SYSEVENT_TORCH_STATE(IPCSkeleton::GetCallingPid(), + IPCSkeleton::GetCallingUid(), item.data.u8[0]); + } + + ret = OHOS::Camera::FindCameraMetadataItem(metadata, OHOS_CONTROL_FOCUS_MODE, &item); + if (ret == CAM_META_SUCCESS) { + MEDIA_DEBUG_LOG("Focus mode: %{public}d", item.data.u8[0]); + CAMERA_SYSEVENT_BEHAVIOR(CreateMsg("FocusModeChanged! current OHOS_CONTROL_FOCUS_MODE is %d", + item.data.u8[0])); + } + ret = OHOS::Camera::FindCameraMetadataItem(metadata, OHOS_CONTROL_FOCUS_STATE, &item); + if (ret == CAM_META_SUCCESS) { + MEDIA_INFO_LOG("Focus state: %{public}d", item.data.u8[0]); + CAMERA_SYSEVENT_BEHAVIOR(CreateMsg("FocusStateChanged! current OHOS_CONTROL_FOCUS_STATE is %d", + item.data.u8[0])); + } + return CAMERA_OK; } diff --git a/services/camera_service/src/hcamera_service.cpp b/services/camera_service/src/hcamera_service.cpp index d63e8e5f4..097f0c99a 100644 --- a/services/camera_service/src/hcamera_service.cpp +++ b/services/camera_service/src/hcamera_service.cpp @@ -92,6 +92,35 @@ int32_t HCameraService::GetCameras(std::vector &cameraIds, MEDIA_ERR_LOG("HCameraService::GetCameraAbility failed"); return ret; } + + camera_metadata_item_t item; + common_metadata_header_t *metadata = cameraAbility->get(); + camera_position_enum_t cameraPosition = OHOS_CAMERA_POSITION_OTHER; + int ret = OHOS::Camera::FindCameraMetadataItem(metadata, OHOS_ABILITY_CAMERA_POSITION, &item); + if (ret == CAM_META_SUCCESS) { + cameraPosition = static_cast(item.data.u8[0]); + } + + camera_type_enum_t cameraType = OHOS_CAMERA_TYPE_UNSPECIFIED; + ret = OHOS::Camera::FindCameraMetadataItem(metadata, OHOS_ABILITY_CAMERA_TYPE, &item); + if (ret == CAM_META_SUCCESS) { + cameraType = static_cast(item.data.u8[0]); + } + + camera_connection_type_t connectionType = OHOS_CAMERA_CONNECTION_TYPE_BUILTIN; + ret = OHOS::Camera::FindCameraMetadataItem(metadata, OHOS_ABILITY_CAMERA_CONNECTION_TYPE, &item); + if (ret == CAM_META_SUCCESS) { + connectionType = static_cast(item.data.u8[0]); + } + + bool isMirrorSupported = false; + ret = OHOS::Camera::FindCameraMetadataItem(metadata, OHOS_CONTROL_CAPTURE_MIRROR_SUPPORTED, &item); + if (ret == CAM_META_SUCCESS) { + isMirrorSupported = ((item.data.u8[0] == 1) || (item.data.u8[0] == 0)); + } + CAMERA_SYSEVENT_STATISTIC(CreateMsg("CameraManager GetCameras camera ID:%s, Camera position:%d," + " Camera Type:%d, Connection Type:%d, Mirror support:%d", id.c_str(), + cameraPosition, cameraType, connectionType, isMirrorSupported)); cameraAbilityList.emplace_back(cameraAbility); } @@ -132,6 +161,7 @@ int32_t HCameraService::CreateCameraDevice(std::string cameraId, sptr &pro MEDIA_ERR_LOG("HCameraService::CreatePhotoOutput HStreamCapture allocation failed"); return CAMERA_ALLOC_ERROR; } + POWERMGR_SYSEVENT_CAMERA_CONFIG(PHOTO, producer->GetDefaultWidth(), + producer->GetDefaultHeight()); photoOutput = streamCapture; return CAMERA_OK; } @@ -189,6 +221,8 @@ int32_t HCameraService::CreatePreviewOutput(const sptr &p MEDIA_ERR_LOG("HCameraService::CreatePreviewOutput HStreamRepeat allocation failed"); return CAMERA_ALLOC_ERROR; } + POWERMGR_SYSEVENT_CAMERA_CONFIG(PREVIEW, producer->GetDefaultWidth(), + producer->GetDefaultHeight()); previewOutput = streamRepeatPreview; return CAMERA_OK; } @@ -208,6 +242,7 @@ int32_t HCameraService::CreateCustomPreviewOutput(const sptr & MEDIA_ERR_LOG("HCameraService::CreateMetadataOutput HStreamMetadata allocation failed"); return CAMERA_ALLOC_ERROR; } + POWERMGR_SYSEVENT_CAMERA_CONFIG(METADATA, producer->GetDefaultWidth(), + producer->GetDefaultHeight()); metadataOutput = streamMetadata; return CAMERA_OK; } @@ -246,6 +283,8 @@ int32_t HCameraService::CreateVideoOutput(const sptr &pro MEDIA_ERR_LOG("HCameraService::CreateVideoOutput HStreamRepeat allocation failed"); return CAMERA_ALLOC_ERROR; } + POWERMGR_SYSEVENT_CAMERA_CONFIG(VIDEO, producer->GetDefaultWidth(), + producer->GetDefaultHeight()); videoOutput = streamRepeatVideo; return CAMERA_OK; } @@ -254,6 +293,8 @@ void HCameraService::OnCameraStatus(const std::string& cameraId, CameraStatus st { if (cameraServiceCallback_) { cameraServiceCallback_->OnCameraStatusChanged(cameraId, status); + CAMERA_SYSEVENT_BEHAVIOR(CreateMsg("OnCameraStatusChanged! for cameraId:%s, current Camera Status:%d", + cameraId.c_str(), status)); } } @@ -261,6 +302,10 @@ void HCameraService::OnFlashlightStatus(const std::string& cameraId, FlashStatus { if (cameraServiceCallback_) { cameraServiceCallback_->OnFlashlightStatusChanged(cameraId, status); + CAMERA_SYSEVENT_BEHAVIOR(CreateMsg("OnFlashlightStatusChanged! for cameraId:%s, current Flash Status:%d", + cameraId.c_str(), status)); + POWERMGR_SYSEVENT_TORCH_STATE(IPCSkeleton::GetCallingPid(), + IPCSkeleton::GetCallingUid(), status); } } diff --git a/services/camera_service/src/hcapture_session.cpp b/services/camera_service/src/hcapture_session.cpp index 34b962bc8..73bd8d402 100644 --- a/services/camera_service/src/hcapture_session.cpp +++ b/services/camera_service/src/hcapture_session.cpp @@ -20,11 +20,49 @@ #include "surface.h" #include "ipc_skeleton.h" #include "metadata_utils.h" +#include "bundle_mgr_interface.h" +#include "iservice_registry.h" +#include "system_ability_definition.h" + +using namespace OHOS::AppExecFwk; +using namespace OHOS::AAFwk; namespace OHOS { namespace CameraStandard { static std::map> session_; static std::mutex sessionLock_; + +static std::string GetClientBundle(int uid) +{ + std::string bundleName = ""; + auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (samgr == nullptr) { + MEDIA_ERR_LOG("Get ability manager failed"); + return bundleName; + } + + sptr object = samgr->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); + if (object == nullptr) { + MEDIA_DEBUG_LOG("object is NULL."); + return bundleName; + } + + sptr bms = iface_cast(object); + if (bms == nullptr) { + MEDIA_DEBUG_LOG("bundle manager service is NULL."); + return bundleName; + } + + auto result = bms->GetBundleNameForUid(uid, bundleName); + if (!result) { + MEDIA_ERR_LOG("GetBundleNameForUid fail"); + return ""; + } + MEDIA_INFO_LOG("bundle name is %{public}s ", bundleName.c_str()); + + return bundleName; +} + HCaptureSession::HCaptureSession(sptr cameraHostManager, sptr streamOperatorCb) : cameraHostManager_(cameraHostManager), streamOperatorCallback_(streamOperatorCb), @@ -102,6 +140,7 @@ int32_t HCaptureSession::AddInput(sptr cameraDevice) cameraDevice_->SetReleaseCameraDevice(false); } else { tempCameraDevices_.emplace_back(localCameraDevice); + CAMERA_SYSEVENT_STATISTIC(CreateMsg("CaptureSession::AddInput")); } return CAMERA_OK; } @@ -143,6 +182,7 @@ int32_t HCaptureSession::AddOutput(StreamType streamType, sptr st } else if (streamType == StreamType::METADATA) { rc = AddOutputStream(static_cast(stream.GetRefPtr())); } + CAMERA_SYSEVENT_STATISTIC(CreateMsg("CaptureSession::AddOutput with %d", streamType)); return rc; } @@ -168,6 +208,7 @@ int32_t HCaptureSession::RemoveInput(sptr cameraDevice) MEDIA_ERR_LOG("HCaptureSession::RemoveInput Invalid camera device"); return CAMERA_INVALID_SESSION_CFG; } + CAMERA_SYSEVENT_STATISTIC(CreateMsg("CaptureSession::RemoveInput")); return CAMERA_OK; } @@ -213,6 +254,7 @@ int32_t HCaptureSession::RemoveOutput(StreamType streamType, sptr } else if (streamType == StreamType::METADATA) { rc = RemoveOutputStream(static_cast(stream.GetRefPtr())); } + CAMERA_SYSEVENT_STATISTIC(CreateMsg("CaptureSession::RemoveOutput with %d", streamType)); return rc; } @@ -543,6 +585,13 @@ int32_t HCaptureSession::CommitConfig() RestorePreviousState(cameraDevice_, !deletedStreamIds_.empty()); return rc; } + if (device != nullptr) { + int32_t pid = IPCSkeleton::GetCallingPid(); + int32_t uid = IPCSkeleton::GetCallingUid(); + POWERMGR_SYSEVENT_CAMERA_CONNECT(pid, uid, device->GetCameraId().c_str(), + GetClientBundle(uid)); + } + if (cameraDevice_ != nullptr && device != cameraDevice_) { cameraDevice_->Close(); cameraDevice_ = nullptr; @@ -641,6 +690,7 @@ int32_t HCaptureSession::Release(pid_t pid) } if (cameraDevice_ != nullptr) { cameraDevice_->Close(); + POWERMGR_SYSEVENT_CAMERA_DISCONNECT(cameraDevice_->GetCameraId().c_str()); cameraDevice_ = nullptr; } ClearCaptureSession(pid); diff --git a/services/camera_service/src/hstream_capture.cpp b/services/camera_service/src/hstream_capture.cpp index 43254b503..67c9170a1 100644 --- a/services/camera_service/src/hstream_capture.cpp +++ b/services/camera_service/src/hstream_capture.cpp @@ -123,11 +123,15 @@ int32_t HStreamCapture::OnCaptureEnded(int32_t captureId, int32_t frameCount) int32_t HStreamCapture::OnCaptureError(int32_t captureId, int32_t errorCode) { if (streamCaptureCallback_ != nullptr) { + int32_t captureErrorCode; if (errorCode == BUFFER_LOST) { - streamCaptureCallback_->OnCaptureError(captureId, CAMERA_STREAM_BUFFER_LOST); + captureErrorCode = CAMERA_STREAM_BUFFER_LOST; } else { - streamCaptureCallback_->OnCaptureError(captureId, CAMERA_UNKNOWN_ERROR); + captureErrorCode = CAMERA_UNKNOWN_ERROR; } + CAMERA_SYSEVENT_FAULT(CreateMsg("Photo OnCaptureError! captureId:%d & " + "errorCode:%{public}d", captureId, captureErrorCode)); + streamCaptureCallback_->OnCaptureError(captureId, captureErrorCode); } return CAMERA_OK; } diff --git a/services/camera_service/src/hstream_repeat.cpp b/services/camera_service/src/hstream_repeat.cpp index 8a0a81deb..b85a3cc52 100644 --- a/services/camera_service/src/hstream_repeat.cpp +++ b/services/camera_service/src/hstream_repeat.cpp @@ -181,11 +181,14 @@ int32_t HStreamRepeat::OnFrameEnded(int32_t frameCount) int32_t HStreamRepeat::OnFrameError(int32_t errorType) { if (streamRepeatCallback_ != nullptr) { + int32_t repeatErrorCode; if (errorType == BUFFER_LOST) { - streamRepeatCallback_->OnFrameError(CAMERA_STREAM_BUFFER_LOST); + repeatErrorCode = CAMERA_STREAM_BUFFER_LOST; } else { - streamRepeatCallback_->OnFrameError(CAMERA_UNKNOWN_ERROR); + repeatErrorCode = CAMERA_UNKNOWN_ERROR; } + CAMERA_SYSEVENT_FAULT(CreateMsg("Preview OnFrameError! errorCode:%d", repeatErrorCode)); + streamRepeatCallback_->OnFrameError(repeatErrorCode); } return CAMERA_OK; } -- Gitee