1 /* 2 * Copyright (c) 2022 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 #ifdef DEVICE_USAGES_STATISTICS_POWERMANGER_ENABLE 16 #include "bundle_active_log.h" 17 #include "bundle_active_power_state_callback_service.h" 18 #include "power_state_machine_info.h" 19 20 namespace OHOS { 21 namespace DeviceUsageStats { 22 using OHOS::PowerMgr::PowerState; BundleActivePowerStateCallbackService(std::shared_ptr<BundleActiveCore> bundleActiveCore)23BundleActivePowerStateCallbackService::BundleActivePowerStateCallbackService( 24 std::shared_ptr<BundleActiveCore> bundleActiveCore) 25 { 26 if (bundleActiveCore != nullptr) { 27 bundleActiveCore_ = bundleActiveCore; 28 } 29 } 30 OnPowerStateChanged(PowerState state)31void BundleActivePowerStateCallbackService::OnPowerStateChanged(PowerState state) 32 { 33 int32_t eventId; 34 BUNDLE_ACTIVE_LOGD("BundleActDvePowerStateCallbackService::OnPowerStateChanged power state is %{public}u", state); 35 if (state == PowerState::AWAKE) { 36 eventId = BundleActiveEvent::SYSTEM_WAKEUP; 37 } else if (state == PowerState::SLEEP) { 38 eventId = BundleActiveEvent::SYSTEM_SLEEP; 39 } else { 40 return; 41 } 42 bundleActiveCore_->PreservePowerStateInfo(eventId); 43 } 44 } // namespace DeviceUsageStats 45 } // namespace OHOS 46 #endif 47 48