/* * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #define MLOG_TAG "Subscribe" #include "ringtone_subscriber.h" #include "common_event_support.h" #include "ringtone_log.h" namespace OHOS { namespace Media { using namespace OHOS::AAFwk; const std::vector RingtoneSubscriber::events_ = { EventFwk::CommonEventSupport::COMMON_EVENT_CHARGING, EventFwk::CommonEventSupport::COMMON_EVENT_DISCHARGING, EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_OFF, EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_ON, EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED, EventFwk::CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED }; RingtoneSubscriber::RingtoneSubscriber(const EventFwk::CommonEventSubscribeInfo &subscriberInfo) : EventFwk::CommonEventSubscriber(subscriberInfo) { } bool RingtoneSubscriber::Subscribe(void) { EventFwk::MatchingSkills matchingSkills; for (auto event : events_) { matchingSkills.AddEvent(event); } EventFwk::CommonEventSubscribeInfo subscribeInfo(matchingSkills); std::shared_ptr subscriber = std::make_shared(subscribeInfo); return EventFwk::CommonEventManager::SubscribeCommonEvent(subscriber); } void RingtoneSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &eventData) { const AAFwk::Want &want = eventData.GetWant(); std::string action = want.GetAction(); RINGTONE_INFO_LOG("OnReceiveEvent action:%{public}s.", action.c_str()); if (action.compare(EventFwk::CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED) == 0) { RINGTONE_INFO_LOG("recieve boot complete event."); } } } // namespace Media } // namespace OHOS