1 /* 2 * Copyright (C) 2022 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 #ifndef SMS_STATE_OBSERVER_H 17 #define SMS_STATE_OBSERVER_H 18 19 #include "common_event_manager.h" 20 #include "common_event_subscriber.h" 21 #include "common_event_support.h" 22 #include "system_ability_status_change_stub.h" 23 24 namespace OHOS { 25 namespace Telephony { 26 using CommonEventSubscribeInfo = OHOS::EventFwk::CommonEventSubscribeInfo; 27 using CommonEventSubscriber = OHOS::EventFwk::CommonEventSubscriber; 28 29 enum SmsStateEventIntValue { 30 COMMON_EVENT_SMS_EMERGENCY_CB_RECEIVE_COMPLETED, 31 COMMON_EVENT_SMS_CB_RECEIVE_COMPLETED, 32 COMMON_EVENT_SMS_RECEIVE_COMPLETED, 33 COMMON_EVENT_SMS_WAPPUSH_RECEIVE_COMPLETED, 34 COMMON_EVENT_UNKNOWN, 35 }; 36 37 class SmsStateEventSubscriber : public CommonEventSubscriber { 38 public: SmsStateEventSubscriber(const CommonEventSubscribeInfo & info)39 explicit SmsStateEventSubscriber(const CommonEventSubscribeInfo &info) : CommonEventSubscriber(info) {} 40 ~SmsStateEventSubscriber() = default; 41 void OnReceiveEvent(const OHOS::EventFwk::CommonEventData &data) override; 42 void InitEventMap(); 43 44 private: 45 SmsStateEventIntValue GetSmsStateEventIntValue(std::string &event) const; 46 47 private: 48 std::map<std::string, SmsStateEventIntValue> smsStateEvenMapIntValues_; 49 }; 50 51 class SmsStateObserver { 52 public: 53 SmsStateObserver() = default; 54 ~SmsStateObserver() = default; 55 void StartEventSubscriber(); 56 void StopEventSubscriber(); 57 58 private: 59 std::shared_ptr<SmsStateEventSubscriber> smsSubscriber_; 60 sptr<ISystemAbilityStatusChange> smsStatusListener_ = nullptr; 61 62 private: 63 class SystemAbilityStatusChangeListener : public SystemAbilityStatusChangeStub { 64 public: 65 explicit SystemAbilityStatusChangeListener(std::shared_ptr<SmsStateEventSubscriber> &subscriber); 66 ~SystemAbilityStatusChangeListener() = default; 67 virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 68 virtual void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 69 70 private: 71 std::shared_ptr<SmsStateEventSubscriber> sub_ = nullptr; 72 }; 73 }; 74 } // namespace Telephony 75 } // namespace OHOS 76 #endif // SMS_STATE_OBSERVER_H 77