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