• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 {
CallBroadcastSubscriber(const OHOS::EventFwk::CommonEventSubscribeInfo & subscriberInfo)25 CallBroadcastSubscriber::CallBroadcastSubscriber(const OHOS::EventFwk::CommonEventSubscribeInfo &subscriberInfo)
26     : CommonEventSubscriber(subscriberInfo)
27 {
28     memberFuncMap_[UNKNOWN_BROADCAST_EVENT] = &CallBroadcastSubscriber::UnknownBroadcast;
29     memberFuncMap_[SIM_STATE_BROADCAST_EVENT] = &CallBroadcastSubscriber::SimStateBroadcast;
30 }
31 
OnReceiveEvent(const EventFwk::CommonEventData & data)32 void CallBroadcastSubscriber::OnReceiveEvent(const EventFwk::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     TELEPHONY_LOGI("receive one broadcast:%{public}s", action.c_str());
38     if (action == SIM_STATE_UPDATE_ACTION) {
39         code = SIM_STATE_BROADCAST_EVENT;
40     } else {
41         code = UNKNOWN_BROADCAST_EVENT;
42     }
43     auto itFunc = memberFuncMap_.find(code);
44     if (itFunc != memberFuncMap_.end()) {
45         auto memberFunc = itFunc->second;
46         if (memberFunc != nullptr) {
47             return (this->*memberFunc)(data);
48         }
49     }
50 }
51 
UnknownBroadcast(const EventFwk::CommonEventData & data)52 void CallBroadcastSubscriber::UnknownBroadcast(const EventFwk::CommonEventData &data)
53 {
54     TELEPHONY_LOGI("you receive one unknown broadcast!");
55 }
56 
SimStateBroadcast(const EventFwk::CommonEventData & data)57 void CallBroadcastSubscriber::SimStateBroadcast(const EventFwk::CommonEventData &data)
58 {
59     TELEPHONY_LOGI("sim state broadcast code:%{public}d", data.GetCode());
60 }
61 } // namespace Telephony
62 } // namespace OHOS
63