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