• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 
17 #include <satellite_call_control.h>
18 
19 #include "call_control_manager.h"
20 #include "call_dialog.h"
21 #include "call_object_manager.h"
22 #include "common_event.h"
23 #include "common_event_manager.h"
24 #include "common_event_support.h"
25 #include "notification_content.h"
26 #include "notification_helper.h"
27 #include "notification_normal_content.h"
28 #include "notification_request.h"
29 #include "settings_datashare_helper.h"
30 #include "telephony_errors.h"
31 #include "telephony_log_wrapper.h"
32 #include "telephony_permission.h"
33 #include "audio_control_manager.h"
34 
35 #include "want.h"
36 #include "uri.h"
37 #include "parameters.h"
38 
39 namespace OHOS {
40 namespace Telephony {
41 const int32_t DELAYED_TIME = 270000;
42 const int32_t COUNT_DOWN_TIME = 30000;
43 const int32_t SATELLITE_CONNECTED = 1;
44 const int32_t SATELLITE_MODE_ON = 1;
45 constexpr const char *SATELLITE_TYPE_DEFAULT_VALUE = "0";
46 constexpr const char *TEL_SATELLITE_SUPPORT_TYPE = "const.telephony.satellite.support_type";
47 
48 SatelliteCallControl::SatelliteCallControl() = default;
49 
50 SatelliteCallControl::~SatelliteCallControl() = default;
51 
SetSatcommTempLevel(int32_t level)52 void SatelliteCallControl::SetSatcommTempLevel(int32_t level)
53 {
54     if ((SatCommTempLevel)level == SatCommTempLevel_) {
55         return;
56     } else {
57         if ((SatCommTempLevel)level == SatCommTempLevel::TEMP_LEVEL_HIGH &&
58             CallObjectManager::HasSatelliteCallExist()) {
59             DelayedSingleton<CallDialog>::GetInstance()->DialogConnectExtension("SATELLITE_CALL_DISCONNECT");
60             SetShowDialog(true);
61         }
62         SatCommTempLevel_ = (SatCommTempLevel)level;
63     }
64 }
65 
IsAllowedSatelliteDialCall()66 int32_t SatelliteCallControl::IsAllowedSatelliteDialCall()
67 {
68     auto datashareHelper = SettingsDataShareHelper::GetInstance();
69     OHOS::Uri satelliteModeUri(SettingsDataShareHelper::SETTINGS_DATASHARE_URI);
70     std::string is_satellite_connected{"0"};
71     int32_t err = datashareHelper->Query(satelliteModeUri, SettingsDataShareHelper::QUERY_SATELLITE_CONNECTED_KEY,
72         is_satellite_connected);
73     int32_t satelliteConnected = std::atoi(is_satellite_connected.c_str());
74     if (err == TELEPHONY_SUCCESS && satelliteConnected == SATELLITE_CONNECTED) {
75         TELEPHONY_LOGI("satellite service is connected");
76         std::string tempLevel = OHOS::system::GetParameter("persist.thermal.log.satcomm", "-1");
77         if (tempLevel != "-1") {
78             int32_t temp = std::atoi(tempLevel.c_str());
79             SetSatcommTempLevel(temp);
80         }
81         TELEPHONY_LOGI("GetSatcommTempLevel = %{public}s", tempLevel.c_str());
82         if (GetSatcommTempLevel() >= SatCommTempLevel::TEMP_LEVEL_MIDDLE) {
83             DelayedSingleton<CallDialog>::GetInstance()->DialogConnectExtension("CANNOT_DIAL_SATELLITE_CALL");
84             return TELEPHONY_ERROR;
85         }
86         SetUsedModem();
87         return TELEPHONY_SUCCESS;
88     } else {
89         PublishSatelliteConnectEvent();
90     }
91     return TELEPHONY_ERROR;
92 }
93 
IsSatelliteSwitchEnable()94 int32_t SatelliteCallControl::IsSatelliteSwitchEnable()
95 {
96     auto datashareHelper = SettingsDataShareHelper::GetInstance();
97     OHOS::Uri satelliteModeUri(SettingsDataShareHelper::SETTINGS_DATASHARE_URI);
98     std::string is_satellite_mode_on{ "0" };
99     int32_t err = datashareHelper->Query(satelliteModeUri, SettingsDataShareHelper::QUERY_SATELLITE_MODE_KEY,
100         is_satellite_mode_on);
101     int32_t satelliteMode = std::atoi(is_satellite_mode_on.c_str());
102     if (err == TELEPHONY_SUCCESS && satelliteMode == SATELLITE_MODE_ON) {
103         TELEPHONY_LOGI("satellite mode on");
104         return TELEPHONY_SUCCESS;
105     }
106     return TELEPHONY_ERROR;
107 }
108 
GetSatcommTempLevel()109 SatCommTempLevel SatelliteCallControl::GetSatcommTempLevel()
110 {
111     return SatCommTempLevel_;
112 }
113 
SetUsedModem()114 void SatelliteCallControl::SetUsedModem()
115 {
116     char satelliteSupportType[SYSPARA_SIZE] = { 0 };
117     GetParameter(TEL_SATELLITE_SUPPORT_TYPE, SATELLITE_TYPE_DEFAULT_VALUE, satelliteSupportType, SYSPARA_SIZE);
118     int satelliteMode = static_cast<unsigned int>(std::atoi(satelliteSupportType));
119     TELEPHONY_LOGI("satellite satelliteMode = %{public}d.", satelliteMode);
120     if ((satelliteMode & 0b00000100) || (satelliteMode & 0b00010000)) {
121         std::vector<std::pair<std::string, std::string>> vec = {
122             std::pair<std::string, std::string>("USEDMODEM", "satemodem")
123         };
124         AudioStandard::AudioSystemManager::GetInstance()->SetExtraParameters("mmi",
125             vec);
126     }
127 }
128 
HandleSatelliteCallStateUpdate(sptr<CallBase> & call,TelCallState priorState,TelCallState nextState)129 void SatelliteCallControl::HandleSatelliteCallStateUpdate(sptr<CallBase> &call,
130     TelCallState priorState, TelCallState nextState)
131 {
132     bool isDisconnected = (nextState == TelCallState::CALL_STATUS_DISCONNECTED
133         || nextState == TelCallState::CALL_STATUS_DISCONNECTING) ? true : false;
134     if (isDisconnected && IsShowDialog()) {
135         RemoveCallCountDownEventHandlerTask();
136         SetShowDialog(false);
137     }
138     if (nextState == TelCallState::CALL_STATUS_INCOMING || nextState == TelCallState::CALL_STATUS_WAITING) {
139         SetUsedModem();
140     }
141     if (nextState == TelCallState::CALL_STATUS_ACTIVE) {
142         if (GetSatcommTempLevel() == SatCommTempLevel::TEMP_LEVEL_HIGH &&
143             CallObjectManager::HasSatelliteCallExist()) {
144             DelayedSingleton<CallDialog>::GetInstance()->DialogConnectExtension("SATELLITE_CALL_DISCONNECT");
145             SetShowDialog(true);
146         }
147     }
148     std::string model = OHOS::system::GetParameter("const.build.product", "0");
149     if (model != "") {
150         return;
151     }
152     if (nextState == TelCallState::CALL_STATUS_ACTIVE && !IsShowDialog()) {
153         SetSatelliteCallDurationProcessing();
154     }
155     if (isDisconnected) {
156         RemoveCallDurationEventHandlerTask();
157     }
158 }
159 
IsShowDialog()160 bool SatelliteCallControl::IsShowDialog()
161 {
162     return isShowingDialog_;
163 }
164 
SetShowDialog(bool isShowDialog)165 void SatelliteCallControl::SetShowDialog(bool isShowDialog)
166 {
167     isShowingDialog_ = isShowDialog;
168     if (isShowingDialog_) {
169         SetSatelliteCallCountDownProcessing();
170     }
171 }
172 
PublishSatelliteConnectEvent()173 void SatelliteCallControl::PublishSatelliteConnectEvent()
174 {
175     AAFwk::Want want;
176     want.SetAction("event.custom.satellite.ACTION_SATELLITE_CONNECT");
177     EventFwk::CommonEventData data;
178     data.SetWant(want);
179     EventFwk::CommonEventPublishInfo publishInfo;
180     std::vector<std::string> callPermissions;
181     callPermissions.emplace_back(Permission::SET_TELEPHONY_STATE);
182     publishInfo.SetSubscriberPermissions(callPermissions);
183     bool result = EventFwk::CommonEventManager::PublishCommonEvent(data, publishInfo, nullptr);
184     TELEPHONY_LOGI("publish satellite call event result : %{public}d.", result);
185 }
186 
SetSatelliteCallDurationProcessing()187 int32_t SatelliteCallControl::SetSatelliteCallDurationProcessing()
188 {
189     auto weak = weak_from_this();
190     TELEPHONY_LOGI("start satellite call duration task");
191     auto runner = AppExecFwk::EventRunner::Create("start_satellite_call_duration_dialog");
192     if (CallDurationLimitHandler_ == nullptr) {
193         CallDurationLimitHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
194     }
195     if (CallDurationLimitHandler_ == nullptr) {
196         TELEPHONY_LOGI("CallDurationLimitHandler_ is nullptr");
197         return TELEPHONY_ERROR;
198     }
199     auto task = [weak]() {
200         auto strong = weak.lock();
201         if (!strong) {
202             return;
203         }
204         if (!strong->IsShowDialog()) {
205             DelayedSingleton<CallDialog>::GetInstance()->DialogConnectExtension("SATELLITE_CALL_DURATION_LIMIT");
206             strong->SetShowDialog(true);
207         }
208     };
209     CallDurationLimitHandler_->RemoveTask("start_satellite_call_duration_dialog");
210     bool ret = CallDurationLimitHandler_->PostTask(task, "start_satellite_call_duration_dialog", DELAYED_TIME);
211     if (ret) {
212         TELEPHONY_LOGI("start satellite call duration task failed");
213         return TELEPHONY_ERROR;
214     }
215     return TELEPHONY_SUCCESS;
216 }
217 
SetSatelliteCallCountDownProcessing()218 int32_t SatelliteCallControl::SetSatelliteCallCountDownProcessing()
219 {
220         TELEPHONY_LOGI("start satellite call count down task");
221     auto runner = AppExecFwk::EventRunner::Create("satellite_call_count_down");
222     if (CallCountDownHandler_ == nullptr) {
223         CallCountDownHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
224     }
225     if (CallCountDownHandler_ == nullptr) {
226         TELEPHONY_LOGI("CallCountDownHandler_ is nullptr");
227         return TELEPHONY_ERROR;
228     }
229     auto task = []() {
230         std::list<int32_t> satelliteCallIdList;
231         int32_t ret = CallObjectManager::GetSatelliteCallList(satelliteCallIdList);
232         if (ret != TELEPHONY_SUCCESS) {
233             TELEPHONY_LOGI("GetSatelliteCallList failed");
234             return;
235         }
236         for (auto satelliteCallId : satelliteCallIdList) {
237             sptr<CallBase> satelliteCall = CallObjectManager::GetOneCallObject(satelliteCallId);
238             if (satelliteCall == nullptr) {
239                 TELEPHONY_LOGE("satelliteCall is nullptr");
240                 continue;
241             }
242             if (satelliteCall->GetTelCallState() == TelCallState::CALL_STATUS_INCOMING ||
243                 satelliteCall->GetTelCallState() == TelCallState::CALL_STATUS_WAITING) {
244                 DelayedSingleton<CallControlManager>::GetInstance()->RejectCall(satelliteCallId,
245                     true, u"satellitecalldurationlimit");
246             } else if (satelliteCall->GetTelCallState() == TelCallState::CALL_STATUS_ACTIVE) {
247                 DelayedSingleton<CallControlManager>::GetInstance()->HangUpCall(satelliteCallId);
248             }
249         }
250     };
251     CallCountDownHandler_->RemoveTask("satellite_call_count_down");
252     bool ret = CallCountDownHandler_->PostTask(task, "satellite_call_count_down", COUNT_DOWN_TIME);
253     if (ret) {
254         TELEPHONY_LOGI("start satellite call count down task failed");
255         return TELEPHONY_ERROR;
256     }
257     return TELEPHONY_SUCCESS;
258 }
259 
RemoveCallDurationEventHandlerTask()260 void SatelliteCallControl::RemoveCallDurationEventHandlerTask()
261 {
262     if (CallDurationLimitHandler_ != nullptr) {
263         CallDurationLimitHandler_->RemoveTask("start_satellite_call_duration_dialog");
264     }
265 }
266 
RemoveCallCountDownEventHandlerTask()267 void SatelliteCallControl::RemoveCallCountDownEventHandlerTask()
268 {
269     if (CallCountDownHandler_ != nullptr) {
270         CallCountDownHandler_->RemoveTask("satellite_call_count_down");
271     }
272 }
273 } // namespace Telephony
274 } // namespace OHOSss