1 /* 2 * Copyright (C) 2021 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 "call_broadcast_subscriber.h" 17 18 #include <string_ex.h> 19 20 #include "call_manager_errors.h" 21 #include "telephony_log_wrapper.h" 22 23 namespace OHOS { 24 namespace Telephony { 25 using namespace OHOS::EventFwk; CallBroadcastSubscriber(const OHOS::EventFwk::CommonEventSubscribeInfo & subscriberInfo)26CallBroadcastSubscriber::CallBroadcastSubscriber(const OHOS::EventFwk::CommonEventSubscribeInfo &subscriberInfo) 27 : CommonEventSubscriber(subscriberInfo) 28 { 29 memberFuncMap_[UNKNOWN_BROADCAST_EVENT] = &CallBroadcastSubscriber::UnknownBroadcast; 30 memberFuncMap_[SIM_STATE_BROADCAST_EVENT] = &CallBroadcastSubscriber::SimStateBroadcast; 31 } 32 OnReceiveEvent(const EventFwk::CommonEventData & data)33void CallBroadcastSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &data) 34 { 35 uint32_t code = UNKNOWN_BROADCAST_EVENT; 36 OHOS::EventFwk::Want want = data.GetWant(); 37 std::string action = data.GetWant().GetAction(); 38 TELEPHONY_LOGI("receive one broadcast:%{public}s", action.c_str()); 39 if (action == EventFwk::CommonEventSupport::COMMON_EVENT_SIM_STATE_CHANGED) { 40 code = SIM_STATE_BROADCAST_EVENT; 41 } else { 42 code = UNKNOWN_BROADCAST_EVENT; 43 } 44 auto itFunc = memberFuncMap_.find(code); 45 if (itFunc != memberFuncMap_.end()) { 46 auto memberFunc = itFunc->second; 47 if (memberFunc != nullptr) { 48 return (this->*memberFunc)(data); 49 } 50 } 51 } 52 UnknownBroadcast(const EventFwk::CommonEventData & data)53void CallBroadcastSubscriber::UnknownBroadcast(const EventFwk::CommonEventData &data) 54 { 55 TELEPHONY_LOGI("you receive one unknown broadcast!"); 56 } 57 SimStateBroadcast(const EventFwk::CommonEventData & data)58void CallBroadcastSubscriber::SimStateBroadcast(const EventFwk::CommonEventData &data) 59 { 60 TELEPHONY_LOGI("sim state broadcast code:%{public}d", data.GetCode()); 61 } 62 } // namespace Telephony 63 } // namespace OHOS 64