1e5d0e473Sopenharmony_ci/* 2e5d0e473Sopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd. 3e5d0e473Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4e5d0e473Sopenharmony_ci * you may not use this file except in compliance with the License. 5e5d0e473Sopenharmony_ci * You may obtain a copy of the License at 6e5d0e473Sopenharmony_ci * 7e5d0e473Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8e5d0e473Sopenharmony_ci * 9e5d0e473Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10e5d0e473Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11e5d0e473Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12e5d0e473Sopenharmony_ci * See the License for the specific language governing permissions and 13e5d0e473Sopenharmony_ci * limitations under the License. 14e5d0e473Sopenharmony_ci */ 15e5d0e473Sopenharmony_ci 16e5d0e473Sopenharmony_ci#ifndef SMS_STATE_OBSERVER_H 17e5d0e473Sopenharmony_ci#define SMS_STATE_OBSERVER_H 18e5d0e473Sopenharmony_ci 19e5d0e473Sopenharmony_ci#include "common_event_manager.h" 20e5d0e473Sopenharmony_ci#include "common_event_subscriber.h" 21e5d0e473Sopenharmony_ci#include "common_event_support.h" 22e5d0e473Sopenharmony_ci#include "system_ability_status_change_stub.h" 23e5d0e473Sopenharmony_ci 24e5d0e473Sopenharmony_cinamespace OHOS { 25e5d0e473Sopenharmony_cinamespace Telephony { 26e5d0e473Sopenharmony_ciusing CommonEventSubscribeInfo = OHOS::EventFwk::CommonEventSubscribeInfo; 27e5d0e473Sopenharmony_ciusing CommonEventSubscriber = OHOS::EventFwk::CommonEventSubscriber; 28e5d0e473Sopenharmony_ci 29e5d0e473Sopenharmony_cienum SmsStateEventIntValue { 30e5d0e473Sopenharmony_ci COMMON_EVENT_SMS_EMERGENCY_CB_RECEIVE_COMPLETED, 31e5d0e473Sopenharmony_ci COMMON_EVENT_SMS_CB_RECEIVE_COMPLETED, 32e5d0e473Sopenharmony_ci COMMON_EVENT_SMS_RECEIVE_COMPLETED, 33e5d0e473Sopenharmony_ci COMMON_EVENT_SMS_WAPPUSH_RECEIVE_COMPLETED, 34e5d0e473Sopenharmony_ci COMMON_EVENT_UNKNOWN, 35e5d0e473Sopenharmony_ci}; 36e5d0e473Sopenharmony_ci 37e5d0e473Sopenharmony_ciclass SmsStateEventSubscriber : public CommonEventSubscriber { 38e5d0e473Sopenharmony_cipublic: 39e5d0e473Sopenharmony_ci explicit SmsStateEventSubscriber(const CommonEventSubscribeInfo &info) : CommonEventSubscriber(info) {} 40e5d0e473Sopenharmony_ci ~SmsStateEventSubscriber() = default; 41e5d0e473Sopenharmony_ci void OnReceiveEvent(const OHOS::EventFwk::CommonEventData &data) override; 42e5d0e473Sopenharmony_ci void InitEventMap(); 43e5d0e473Sopenharmony_ci 44e5d0e473Sopenharmony_ciprivate: 45e5d0e473Sopenharmony_ci SmsStateEventIntValue GetSmsStateEventIntValue(std::string &event) const; 46e5d0e473Sopenharmony_ci 47e5d0e473Sopenharmony_ciprivate: 48e5d0e473Sopenharmony_ci std::map<std::string, SmsStateEventIntValue> smsStateEvenMapIntValues_; 49e5d0e473Sopenharmony_ci}; 50e5d0e473Sopenharmony_ci 51e5d0e473Sopenharmony_ciclass SmsStateObserver { 52e5d0e473Sopenharmony_cipublic: 53e5d0e473Sopenharmony_ci SmsStateObserver() = default; 54e5d0e473Sopenharmony_ci ~SmsStateObserver() = default; 55e5d0e473Sopenharmony_ci void StartEventSubscriber(); 56e5d0e473Sopenharmony_ci void StopEventSubscriber(); 57e5d0e473Sopenharmony_ci 58e5d0e473Sopenharmony_ciprivate: 59e5d0e473Sopenharmony_ci std::shared_ptr<SmsStateEventSubscriber> smsSubscriber_; 60e5d0e473Sopenharmony_ci sptr<ISystemAbilityStatusChange> smsStatusListener_ = nullptr; 61e5d0e473Sopenharmony_ci 62e5d0e473Sopenharmony_ciprivate: 63e5d0e473Sopenharmony_ci class SystemAbilityStatusChangeListener : public SystemAbilityStatusChangeStub { 64e5d0e473Sopenharmony_ci public: 65e5d0e473Sopenharmony_ci explicit SystemAbilityStatusChangeListener(std::shared_ptr<SmsStateEventSubscriber> &subscriber); 66e5d0e473Sopenharmony_ci ~SystemAbilityStatusChangeListener() = default; 67e5d0e473Sopenharmony_ci virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 68e5d0e473Sopenharmony_ci virtual void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 69e5d0e473Sopenharmony_ci 70e5d0e473Sopenharmony_ci private: 71e5d0e473Sopenharmony_ci std::shared_ptr<SmsStateEventSubscriber> sub_ = nullptr; 72e5d0e473Sopenharmony_ci }; 73e5d0e473Sopenharmony_ci}; 74e5d0e473Sopenharmony_ci} // namespace Telephony 75e5d0e473Sopenharmony_ci} // namespace OHOS 76e5d0e473Sopenharmony_ci#endif // SMS_STATE_OBSERVER_H 77