1 /* 2 * Copyright (C) 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 "power_subscriber.h" 17 #include "time_common.h" 18 #include "time_tick_notify.h" 19 20 namespace OHOS { 21 namespace MiscServices { 22 using namespace OHOS::EventFwk; 23 using namespace OHOS::AAFwk; PowerSubscriber(const OHOS::EventFwk::CommonEventSubscribeInfo & subscriberInfo)24PowerSubscriber::PowerSubscriber(const OHOS::EventFwk::CommonEventSubscribeInfo &subscriberInfo) 25 : CommonEventSubscriber(subscriberInfo) 26 { 27 memberFuncMap_[POWER_BROADCAST_EVENT] = &PowerSubscriber::PowerBroadcast; 28 } 29 OnReceiveEvent(const CommonEventData & data)30void PowerSubscriber::OnReceiveEvent(const CommonEventData &data) 31 { 32 uint32_t code = UNKNOWN_BROADCAST_EVENT; 33 OHOS::EventFwk::Want want = data.GetWant(); 34 std::string action = data.GetWant().GetAction(); 35 TIME_HILOGD(TIME_MODULE_SERVICE, "receive one broadcast:%{public}s", action.c_str()); 36 if (action == CommonEventSupport::COMMON_EVENT_SCREEN_ON) { 37 code = POWER_BROADCAST_EVENT; 38 } 39 auto itFunc = memberFuncMap_.find(code); 40 if (itFunc != memberFuncMap_.end()) { 41 auto memberFunc = itFunc->second; 42 if (memberFunc != nullptr) { 43 return (this->*memberFunc)(data); 44 } 45 } 46 } 47 PowerBroadcast(const CommonEventData & data)48void PowerSubscriber::PowerBroadcast(const CommonEventData &data) 49 { 50 TimeTickNotify::GetInstance().PowerCallback(); 51 } 52 } // namespace MiscServices 53 } // namespace OHOS