1 /*
2 * Copyright (c) 2023-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 "events_info.h"
17
18 #include "basic_definitions.h"
19 #include "dp_log.h"
20 #ifdef CAMERA_USE_BATTERY
21 #include "battery_srv_client.h"
22 #include "battery_info.h"
23 #endif
24 #ifdef CAMERA_USE_THERMAL
25 #include "thermal_mgr_client.h"
26 #endif
27 #ifdef CAMERA_USE_POWER
28 #include "power_mgr_client.h"
29 #endif
30
31 namespace OHOS {
32 namespace CameraStandard {
33 namespace DeferredProcessing {
34 namespace {
35 constexpr int32_t BATTERY_THRESHOLD = 50;
36 }
37
EventsInfo()38 EventsInfo::EventsInfo()
39 {
40 DP_DEBUG_LOG("entered.");
41 }
42
~EventsInfo()43 EventsInfo::~EventsInfo()
44 {
45 DP_DEBUG_LOG("entered.");
46 }
47
Initialize()48 void EventsInfo::Initialize()
49 {
50 DP_DEBUG_LOG("Initialize enter.");
51 }
52
GetScreenState()53 ScreenStatus EventsInfo::GetScreenState()
54 {
55 #ifdef CAMERA_USE_POWER
56 auto& power = PowerMgr::PowerMgrClient::GetInstance();
57 if (power.IsScreenOn()) {
58 screenState_ = ScreenStatus::SCREEN_ON;
59 } else {
60 screenState_ = ScreenStatus::SCREEN_OFF;
61 }
62 #endif
63 return screenState_;
64 }
65
GetBatteryState()66 BatteryStatus EventsInfo::GetBatteryState()
67 {
68 #ifdef CAMERA_USE_BATTERY
69 auto& battery = PowerMgr::BatterySrvClient::GetInstance();
70 auto level = battery.GetCapacityLevel();
71 DP_INFO_LOG("GetBatteryState: %{public}d", level);
72 switch (level) {
73 case PowerMgr::BatteryCapacityLevel::LEVEL_NORMAL:
74 case PowerMgr::BatteryCapacityLevel::LEVEL_HIGH:
75 case PowerMgr::BatteryCapacityLevel::LEVEL_FULL:
76 batteryState_ = BatteryStatus::BATTERY_OKAY;
77 break;
78 default:
79 batteryState_ = BatteryStatus::BATTERY_LOW;
80 break;
81 }
82 #endif
83 return batteryState_;
84 }
85
GetChargingState()86 ChargingStatus EventsInfo::GetChargingState()
87 {
88 #ifdef CAMERA_USE_BATTERY
89 auto& battery = PowerMgr::BatterySrvClient::GetInstance();
90 auto status = battery.GetChargingStatus();
91 DP_INFO_LOG("GetChargingState: %{public}d", status);
92 switch (status) {
93 case PowerMgr::BatteryChargeState::CHARGE_STATE_ENABLE:
94 case PowerMgr::BatteryChargeState::CHARGE_STATE_FULL:
95 chargingState_ = ChargingStatus::CHARGING;
96 break;
97 default:
98 chargingState_ = ChargingStatus::DISCHARGING;
99 break;
100 }
101 #endif
102 return chargingState_;
103 }
104
GetBatteryLevel()105 BatteryLevel EventsInfo::GetBatteryLevel()
106 {
107 #ifdef CAMERA_USE_BATTERY
108 auto& battery = PowerMgr::BatterySrvClient::GetInstance();
109 auto capacity = battery.GetCapacity();
110 DP_INFO_LOG("GetBatteryLevel: %{public}d", capacity);
111 if (capacity <= BATTERY_THRESHOLD) {
112 batteryLevel_ = BatteryLevel::BATTERY_LEVEL_LOW;
113 } else {
114 batteryLevel_ = BatteryLevel::BATTERY_LEVEL_OKAY;
115 }
116 #endif
117 return batteryLevel_;
118 }
119
GetPhotoThermalLevel()120 SystemPressureLevel EventsInfo::GetPhotoThermalLevel()
121 {
122 #ifdef CAMERA_USE_THERMAL
123 auto& thermal = OHOS::PowerMgr::ThermalMgrClient::GetInstance();
124 auto level = thermal.GetThermalLevel();
125 photoThermalLevel_ = MapEventThermalLevel(static_cast<int32_t>(level));
126 DP_INFO_LOG("GetPhotoThermalLevel: %{public}d", photoThermalLevel_);
127 #endif
128 return photoThermalLevel_;
129 }
130
GetThermalLevel()131 ThermalLevel EventsInfo::GetThermalLevel()
132 {
133 #ifdef CAMERA_USE_THERMAL
134 auto& thermal = OHOS::PowerMgr::ThermalMgrClient::GetInstance();
135 thermalLevel_ = static_cast<ThermalLevel>(thermal.GetThermalLevel());
136 DP_INFO_LOG("GetThermalLevel: %{public}d", thermalLevel_);
137 #endif
138 return thermalLevel_;
139 }
140 } // namespace DeferredProcessing
141 } // namespace CameraStandard
142 } // namespace OHOS