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_ = { 28 { POWER_BROADCAST_EVENT, [this] (const CommonEventData &data) { PowerBroadcast(data); } }, 29 }; 30 } 31 OnReceiveEvent(const CommonEventData & data)32void PowerSubscriber::OnReceiveEvent(const CommonEventData &data) 33 { 34 uint32_t code = UNKNOWN_BROADCAST_EVENT; 35 OHOS::EventFwk::Want want = data.GetWant(); 36 std::string action = data.GetWant().GetAction(); 37 TIME_HILOGD(TIME_MODULE_SERVICE, "receive one broadcast:%{public}s", action.c_str()); 38 if (action == CommonEventSupport::COMMON_EVENT_SCREEN_ON) { 39 code = POWER_BROADCAST_EVENT; 40 } 41 auto itFunc = memberFuncMap_.find(code); 42 if (itFunc != memberFuncMap_.end()) { 43 auto memberFunc = itFunc->second; 44 if (memberFunc != nullptr) { 45 return memberFunc(data); 46 } 47 } 48 } 49 PowerBroadcast(const CommonEventData & data)50void PowerSubscriber::PowerBroadcast(const CommonEventData &data) 51 { 52 TimeTickNotify::GetInstance().Callback(); 53 } 54 } // namespace MiscServices 55 } // namespace OHOS