• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "camera_strategy.h"
17 
18 #include "dps_event_report.h"
19 #include "events_info.h"
20 #include "events_monitor.h"
21 
22 namespace OHOS {
23 namespace CameraStandard {
24 namespace DeferredProcessing {
25 namespace {
26     const std::string COMMON_CAMERA_ID = "cameraId";
27     const std::string COMMON_CAMERA_STATE = "cameraState";
28     const std::string COMMON_IS_SYSTEM_CAMERA = "isSystemCamera";
29 }
30 enum CameraType {
31     SYSTEM = 0,
32     OTHER
33 };
34 
35 enum CameraStatus {
36     CAMERA_OPEN = 0,
37     CAMERA_CLOSE
38 };
39 
CameraStrategy()40 CameraStrategy::CameraStrategy()
41 {
42     DP_DEBUG_LOG("entered.");
43 }
44 
~CameraStrategy()45 CameraStrategy::~CameraStrategy()
46 {
47     DP_DEBUG_LOG("entered.");
48 }
49 
handleEvent(const EventFwk::CommonEventData & data)50 void CameraStrategy::handleEvent(const EventFwk::CommonEventData& data)
51 {
52     auto want = data.GetWant();
53     std::string cameraId = want.GetStringParam(COMMON_CAMERA_ID);
54     int32_t state = want.GetIntParam(COMMON_CAMERA_STATE, CameraStatus::CAMERA_CLOSE);
55     int32_t cameraType = want.GetIntParam(COMMON_IS_SYSTEM_CAMERA, CameraType::SYSTEM);
56     bool isSystemCamera = cameraType == CameraType::SYSTEM;
57     CameraSessionStatus cameraSessionStatus;
58     if (state == CameraStatus::CAMERA_OPEN) {
59         numActiveSessions_++;
60         cameraSessionStatus = isSystemCamera ?
61             CameraSessionStatus::SYSTEM_CAMERA_OPEN : CameraSessionStatus::NORMAL_CAMERA_OPEN;
62     } else if (state == CameraStatus::CAMERA_CLOSE) {
63         numActiveSessions_--;
64         cameraSessionStatus = isSystemCamera ?
65             CameraSessionStatus::SYSTEM_CAMERA_CLOSED : CameraSessionStatus::NORMAL_CAMERA_CLOSED;
66     } else {
67         return;
68     }
69     DP_INFO_LOG("DPS_EVENT: CameraStatusChanged state: %{public}d, cameraId: %{public}s, numActive: %{public}d",
70         cameraSessionStatus, cameraId.c_str(), numActiveSessions_.load());
71     EventsInfo::GetInstance().SetCameraState(cameraSessionStatus);
72     EventsMonitor::GetInstance().NotifyCameraSessionStatus(cameraSessionStatus);
73 }
74 } // namespace DeferredProcessing
75 } // namespace CameraStandard
76 } // namespace OHOS