• 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 "audio_device_manager.h"
21 #include "call_manager_errors.h"
22 #include "telephony_log_wrapper.h"
23 #include "call_control_manager.h"
24 #include "satellite_call_control.h"
25 #include "call_superprivacy_control_manager.h"
26 #include "call_connect_ability.h"
27 #include "call_ability_connect_callback.h"
28 
29 namespace OHOS {
30 namespace Telephony {
31 using namespace OHOS::EventFwk;
CallBroadcastSubscriber(const OHOS::EventFwk::CommonEventSubscribeInfo & subscriberInfo)32 CallBroadcastSubscriber::CallBroadcastSubscriber(const OHOS::EventFwk::CommonEventSubscribeInfo &subscriberInfo)
33     : CommonEventSubscriber(subscriberInfo)
34 {
35     memberFuncMap_[UNKNOWN_BROADCAST_EVENT] =
36         [this](const EventFwk::CommonEventData &data) { UnknownBroadcast(data); };
37     memberFuncMap_[SIM_STATE_BROADCAST_EVENT] =
38         [this](const EventFwk::CommonEventData &data) { SimStateBroadcast(data); };
39     memberFuncMap_[CONNECT_CALLUI_SERVICE] =
40         [this](const EventFwk::CommonEventData &data) { ConnectCallUiServiceBroadcast(data); };
41     memberFuncMap_[HIGH_TEMP_LEVEL_CHANGED] =
42         [this](const EventFwk::CommonEventData &data) { HighTempLevelChangedBroadcast(data); };
43     memberFuncMap_[SUPER_PRIVACY_MODE] =
44         [this](const EventFwk::CommonEventData &data) { ConnectCallUiSuperPrivacyModeBroadcast(data); };
45     memberFuncMap_[BLUETOOTH_REMOTEDEVICE_NAME_UPDATE] =
46         [this](const EventFwk::CommonEventData &data) { UpdateBluetoothDeviceName(data); };
47     memberFuncMap_[USER_SWITCHED] =
48         [this](const EventFwk::CommonEventData &data) { ConnectCallUiUserSwitchedBroadcast(data); };
49 }
50 
OnReceiveEvent(const EventFwk::CommonEventData & data)51 void CallBroadcastSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &data)
52 {
53     uint32_t code = UNKNOWN_BROADCAST_EVENT;
54     OHOS::EventFwk::Want want = data.GetWant();
55     std::string action = data.GetWant().GetAction();
56     TELEPHONY_LOGI("receive one broadcast:%{public}s", action.c_str());
57     if (action == EventFwk::CommonEventSupport::COMMON_EVENT_SIM_STATE_CHANGED) {
58         code = SIM_STATE_BROADCAST_EVENT;
59     } else if (action == "event.custom.contacts.PAGE_STATE_CHANGE") {
60         code = CONNECT_CALLUI_SERVICE;
61     } else if (action == "usual.event.thermal.satcomm.HIGH_TEMP_LEVEL") {
62         code = HIGH_TEMP_LEVEL_CHANGED;
63     } else if (action == "usual.event.SUPER_PRIVACY_MODE") {
64         code = SUPER_PRIVACY_MODE;
65     } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_NAME_UPDATE) {
66         code = BLUETOOTH_REMOTEDEVICE_NAME_UPDATE;
67     } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED) {
68         code = USER_SWITCHED;
69     } else {
70         code = UNKNOWN_BROADCAST_EVENT;
71     }
72     auto itFunc = memberFuncMap_.find(code);
73     if (itFunc != memberFuncMap_.end()) {
74         auto memberFunc = itFunc->second;
75         if (memberFunc != nullptr) {
76             return memberFunc(data);
77         }
78     }
79 }
80 
UnknownBroadcast(const EventFwk::CommonEventData & data)81 void CallBroadcastSubscriber::UnknownBroadcast(const EventFwk::CommonEventData &data)
82 {
83     TELEPHONY_LOGI("you receive one unknown broadcast!");
84 }
85 
SimStateBroadcast(const EventFwk::CommonEventData & data)86 void CallBroadcastSubscriber::SimStateBroadcast(const EventFwk::CommonEventData &data)
87 {
88     TELEPHONY_LOGI("sim state broadcast code:%{public}d", data.GetCode());
89 }
90 
ConnectCallUiServiceBroadcast(const EventFwk::CommonEventData & data)91 void CallBroadcastSubscriber::ConnectCallUiServiceBroadcast(const EventFwk::CommonEventData &data)
92 {
93     bool isConnectService = data.GetWant().GetBoolParam("isShouldConnect", false);
94     TELEPHONY_LOGI("isConnectService:%{public}d", isConnectService);
95     DelayedSingleton<CallControlManager>::GetInstance()->ConnectCallUiService(isConnectService);
96 }
97 
HighTempLevelChangedBroadcast(const EventFwk::CommonEventData & data)98 void CallBroadcastSubscriber::HighTempLevelChangedBroadcast(const EventFwk::CommonEventData &data)
99 {
100     int32_t satcommHighTempLevel = data.GetWant().GetIntParam("satcomm_high_temp_level", -1);
101     TELEPHONY_LOGI("satcommHighTempLevel:%{public}d", satcommHighTempLevel);
102     DelayedSingleton<SatelliteCallControl>::GetInstance()->SetSatcommTempLevel(satcommHighTempLevel);
103 }
104 
ConnectCallUiSuperPrivacyModeBroadcast(const EventFwk::CommonEventData & data)105 void CallBroadcastSubscriber::ConnectCallUiSuperPrivacyModeBroadcast(const EventFwk::CommonEventData &data)
106 {
107     int32_t videoState = data.GetWant().GetIntParam("videoState", -1);
108     bool isAnswer = data.GetWant().GetBoolParam("isAnswer", false);
109     DelayedSingleton<CallSuperPrivacyControlManager>::GetInstance()->SetOldSuperPrivacyMode();
110     DelayedSingleton<CallSuperPrivacyControlManager>::GetInstance()->SetIsChangeSuperPrivacyMode(true);
111     TELEPHONY_LOGI("CallUiSuperPrivacyModeBroadcast isAnswer:%{public}d", isAnswer);
112     if (isAnswer) {
113         int32_t callId = data.GetWant().GetIntParam("callId", -1);
114         TELEPHONY_LOGI("CallUiSuperPrivacyModeBroadcast_Answer callId:%{public}d", callId);
115         DelayedSingleton<CallSuperPrivacyControlManager>::GetInstance()->
116             CloseAnswerSuperPrivacyMode(callId, videoState);
117     } else {
118         std::string phoneNumber = data.GetWant().GetStringParam("phoneNumber");
119         std::u16string phNumber = Str8ToStr16(phoneNumber);
120         int32_t accountId = data.GetWant().GetIntParam("accountId", -1);
121         TELEPHONY_LOGI("CallUiSuperPrivacyModeBroadcast_Answer accountId:%{public}d", accountId);
122         int32_t dialScene = data.GetWant().GetIntParam("dialScene", -1);
123         int32_t dialType = data.GetWant().GetIntParam("dialType", -1);
124         int32_t callType = data.GetWant().GetIntParam("callType", -1);
125         DelayedSingleton<CallSuperPrivacyControlManager>::GetInstance()->CloseCallSuperPrivacyMode(
126             phNumber, accountId, videoState, dialScene, dialType, callType);
127     }
128 }
129 
UpdateBluetoothDeviceName(const EventFwk::CommonEventData & data)130 void CallBroadcastSubscriber::UpdateBluetoothDeviceName(const EventFwk::CommonEventData &data)
131 {
132     std::string macAddress = data.GetWant().GetStringParam("deviceAddr");
133     std::string deviceName = data.GetWant().GetStringParam("remoteName");
134     DelayedSingleton<AudioDeviceManager>::GetInstance()->UpdateBluetoothDeviceName(macAddress, deviceName);
135 }
136 
ConnectCallUiUserSwitchedBroadcast(const EventFwk::CommonEventData & data)137 void CallBroadcastSubscriber::ConnectCallUiUserSwitchedBroadcast(const EventFwk::CommonEventData &data)
138 {
139     if (!DelayedSingleton<CallConnectAbility>::GetInstance()->GetConnectFlag()) {
140         TELEPHONY_LOGE("is not connected");
141         return;
142     }
143     TELEPHONY_LOGI("User switched, need reconnect ability");
144     DelayedSingleton<CallConnectAbility>::GetInstance()->DisconnectAbility();
145     sptr<CallAbilityConnectCallback> connectCallback_ = new CallAbilityConnectCallback();
146     connectCallback_->ReConnectAbility();
147 }
148 } // namespace Telephony
149 } // namespace OHOS
150