Implement power manager requirement events

Signed-off-by: Veeresh Kadasani <veeresh.kadasani@huawei.com>
This commit is contained in:
Veeresh Kadasani
2022-06-09 23:46:13 +05:30
parent 010d0d1a7d
commit c271d61b55
7 changed files with 172 additions and 3 deletions
+3
View File
@@ -60,6 +60,9 @@ ohos_shared_library("camera_framework") {
]
external_deps = [
"ability_base:want",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"hisysevent_native:libhisysevent",
"hitrace_native:hitrace_meter",
"hiviewdfx_hilog_native:libhilog",
@@ -21,6 +21,7 @@
#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"
@@ -70,6 +71,8 @@ public:
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) {
@@ -829,8 +832,14 @@ void CameraInput::SetFlashMode(camera_flash_mode_enum_t flashMode)
if (!status) {
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();
}
return;
}
void CameraInput::SetErrorCallback(std::shared_ptr<ErrorCallback> errorCallback)
@@ -105,6 +105,8 @@ public:
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) {
@@ -173,6 +175,9 @@ sptr<PhotoOutput> CameraManager::CreatePhotoOutput(sptr<Surface> &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);
@@ -196,6 +201,10 @@ sptr<PhotoOutput> CameraManager::CreatePhotoOutput(const sptr<OHOS::IBufferProdu
result = new(std::nothrow) PhotoOutput(streamCapture);
if (result == nullptr) {
MEDIA_ERR_LOG("Failed to new PhotoOutput");
} else {
POWERMGR_SYSEVENT_CAMERA_CONFIG(PHOTO,
producer->GetDefaultWidth(),
producer->GetDefaultHeight());
}
} else {
MEDIA_ERR_LOG("Failed to get stream capture object from hcamera service!, %{public}d", retCode);
@@ -220,6 +229,10 @@ sptr<PreviewOutput> CameraManager::CreatePreviewOutput(sptr<Surface> 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);
@@ -243,6 +256,10 @@ sptr<PreviewOutput> CameraManager::CreatePreviewOutput(const sptr<OHOS::IBufferP
result = new(std::nothrow) PreviewOutput(streamRepeat);
if (result == nullptr) {
MEDIA_ERR_LOG("Failed to new PreviewOutput");
} else {
POWERMGR_SYSEVENT_CAMERA_CONFIG(PREVIEW,
producer->GetDefaultWidth(),
producer->GetDefaultHeight());
}
} else {
MEDIA_ERR_LOG("PreviewOutput: Failed to get stream repeat object from hcamera service!, %{public}d", retCode);
@@ -268,6 +285,8 @@ sptr<PreviewOutput> CameraManager::CreateCustomPreviewOutput(sptr<Surface> 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);
@@ -292,6 +311,8 @@ sptr<PreviewOutput> CameraManager::CreateCustomPreviewOutput(const sptr<OHOS::IB
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);
@@ -316,6 +337,10 @@ sptr<VideoOutput> CameraManager::CreateVideoOutput(sptr<Surface> &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);
@@ -339,6 +364,10 @@ sptr<VideoOutput> CameraManager::CreateVideoOutput(const sptr<OHOS::IBufferProdu
result = new(std::nothrow) VideoOutput(streamRepeat);
if (result == nullptr) {
MEDIA_ERR_LOG("Failed to new VideoOutput");
} else {
POWERMGR_SYSEVENT_CAMERA_CONFIG(VIDEO,
producer->GetDefaultWidth(),
producer->GetDefaultHeight());
}
} else {
MEDIA_ERR_LOG("VideoOutpout: Failed to get stream repeat object from hcamera service! %{public}d", retCode);
@@ -17,12 +17,18 @@
#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 std;
using namespace OHOS::AppExecFwk;
using namespace OHOS::AAFwk;
namespace OHOS {
namespace CameraStandard {
@@ -54,12 +60,50 @@ 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<IRemoteObject> object = samgr->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
if (object == nullptr) {
MEDIA_DEBUG_LOG("object is NULL.");
return bundleName;
}
sptr<AppExecFwk::IBundleMgr> bms = iface_cast<AppExecFwk::IBundleMgr>(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<ICaptureSession> &captureSession)
{
captureSession_ = captureSession;
inputDevice_ = nullptr;
}
CaptureSession::~CaptureSession()
{
if (inputDevice_ != nullptr) {
inputDevice_ = nullptr;
}
}
int32_t CaptureSession::BeginConfig()
{
CAMERA_SYNC_TRACE;
@@ -69,6 +113,14 @@ 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();
}
@@ -104,6 +156,9 @@ int32_t CaptureSession::RemoveInput(sptr<CaptureInput> &input)
return CAMERA_INVALID_ARG;
}
CAMERA_SYSEVENT_STATISTIC(CreateMsg("CaptureSession::RemoveInput"));
if (inputDevice_ != nullptr) {
inputDevice_ = nullptr;
}
return captureSession_->RemoveInput(((sptr<CameraInput> &)input)->GetCameraDevice());
}
@@ -161,11 +216,14 @@ std::shared_ptr<SessionCallback> 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);
}
return;
}
} // CameraStandard
} // OHOS
+29
View File
@@ -24,3 +24,32 @@ CAMERA_STATE:
CAMERA_STATISTIC:
__BASE: {type: STATISTIC, level: MINOR, desc: camera stats}
MSG: {type: STRING, desc: message}
CAMERA_CONNECT:
__BASE: {type: STATISTIC, level: MINOR, tag: PowerStats, desc: camera connect}
PID: {type: INT32, desc: pid}
UID: {type: INT32, desc: uid}
ID: {type: STRING, desc: camera id}
NAME: {type: STRING, desc: package name}
CAMERA_DISCONNECT:
__BASE: {type: STATISTIC, level: MINOR, tag: PowerStats, desc: camera disconnect}
ID: {type: STRING, desc: camera id}
TORCH_STATE:
__BASE: {type: STATISTIC, level: MINOR, tag: PowerStats, desc: torch state}
PID: {type: INT32, desc: pid}
UID: {type: INT32, desc: uid}
STATE: {type: INT32, desc: status}
CAMERA_CONFIG:
__BASE: {type: STATISTIC, level: MINOR, tag: PowerStats, desc: camera config}
TYPE: {type: STRING, desc: stream type}
WIDTH: {type: INT32, desc: image width}
HEIGHT: {type: INT32, desc: image height}
FLASHLIGHT_ON:
__BASE: {type: STATISTIC, level: MINOR, tag: PowerStats, desc: flashlight on}
FLASHLIGHT_OFF:
__BASE: {type: STATISTIC, level: MINOR, tag: PowerStats, desc: flashlight off}
@@ -41,7 +41,7 @@ class CaptureSession : public RefBase {
public:
sptr<CaptureInput> inputDevice_;
explicit CaptureSession(sptr<ICaptureSession> &captureSession);
~CaptureSession() {}
~CaptureSession();
/**
* @brief Begin the capture session config.
@@ -102,6 +102,47 @@
"MSG", str); \
} while (0)
#define POWERMGR_SYSEVENT_CAMERA_CONNECT(pid, uid, camid, name) \
do { \
HiviewDFX::HiSysEvent::Write("CAMERA", "CAMERA_CONNECT", \
HiviewDFX::HiSysEvent::EventType::STATISTIC, \
"PID", pid, "UID", uid, "ID", camid, \
"NAME", name); \
} while (0)
#define POWERMGR_SYSEVENT_CAMERA_DISCONNECT(camid) \
do { \
HiviewDFX::HiSysEvent::Write("CAMERA", "CAMERA_DISCONNECT", \
HiviewDFX::HiSysEvent::EventType::STATISTIC, \
"ID", camid); \
} while (0)
#define POWERMGR_SYSEVENT_TORCH_STATE(pid, uid, status) \
do { \
HiviewDFX::HiSysEvent::Write("CAMERA", "TORCH_STATE", \
HiviewDFX::HiSysEvent::EventType::STATISTIC, \
"PID", pid, "UID", uid, "STATE", status); \
} while (0)
#define POWERMGR_SYSEVENT_CAMERA_CONFIG(type, width, height) \
do { \
HiviewDFX::HiSysEvent::Write("CAMERA", "CAMERA_CONFIG", \
HiviewDFX::HiSysEvent::EventType::STATISTIC, \
"TYPE", #type, "WIDTH", width, "HEIGHT", height); \
} while (0)
#define POWERMGR_SYSEVENT_FLASH_ON() \
do { \
HiviewDFX::HiSysEvent::Write("CAMERA", "FLASHLIGHT_ON", \
HiviewDFX::HiSysEvent::EventType::STATISTIC); \
} while (0)
#define POWERMGR_SYSEVENT_FLASH_OFF() \
do { \
HiviewDFX::HiSysEvent::Write("CAMERA", "FLASHLIGHT_OFF", \
HiviewDFX::HiSysEvent::EventType::STATISTIC); \
} while (0)
#define CAMERA_START_ASYNC_TRACE(str, taskId) \
do { \
StartAsyncTrace(HITRACE_TAG_ZCAMERA, str, taskId, -1); \