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 "battery_level_strategy.h" 17 18 #ifdef CAMERA_USE_BATTERY 19 #endif 20 #include "events_monitor.h" 21 22 namespace OHOS { 23 namespace CameraStandard { 24 namespace DeferredProcessing { 25 namespace { 26 constexpr int32_t DEFAULT_CAPACITY = -1; 27 constexpr int32_t BATTERY_THRESHOLD = 50; 28 const std::string KEY_CAPACITY = "soc"; 29 } 30 BatteryLevelStrategy()31BatteryLevelStrategy::BatteryLevelStrategy() : preLevel_(BATTERY_LEVEL_LOW) 32 { 33 DP_DEBUG_LOG("entered."); 34 } 35 ~BatteryLevelStrategy()36BatteryLevelStrategy::~BatteryLevelStrategy() 37 { 38 DP_DEBUG_LOG("entered."); 39 } 40 handleEvent(const EventFwk::CommonEventData & data)41void BatteryLevelStrategy::handleEvent(const EventFwk::CommonEventData& data) 42 { 43 int32_t capacity = data.GetWant().GetIntParam(KEY_CAPACITY, DEFAULT_CAPACITY); 44 DP_CHECK_RETURN(capacity == DEFAULT_CAPACITY); 45 int32_t batteryLevel = BatteryLevel::BATTERY_LEVEL_LOW; 46 if (capacity >= BATTERY_THRESHOLD) { 47 batteryLevel = BatteryLevel::BATTERY_LEVEL_OKAY; 48 } 49 DP_CHECK_RETURN(batteryLevel == preLevel_); 50 51 preLevel_ = batteryLevel; 52 DP_INFO_LOG("DPS_EVENT: BatteryLevelChanged level: %{public}d", preLevel_); 53 EventsMonitor::GetInstance().NotifyBatteryLevel(preLevel_); 54 } 55 } // namespace DeferredProcessing 56 } // namespace CameraStandard 57 } // namespace OHOS