1 /*
2  * Copyright (C) 2021-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 CELLULAR_CALL_CONFIG_H
17 #define CELLULAR_CALL_CONFIG_H
18 
19 #include <map>
20 #include <mutex>
21 
22 #include "config_request.h"
23 #include "global_params_data.h"
24 #include "operator_config_types.h"
25 #include "sim_state_type.h"
26 #include "telephony_log_wrapper.h"
27 
28 namespace OHOS {
29 namespace Telephony {
30 constexpr const char *KEY_CONST_TELEPHONY_READ_THIRD_PARTY_LIB = "const.telephony.read_third_party_lib";
31 class CellularCallConfig {
32 public:
33     /**
34      * CellularCallConfig constructor
35      *
36      */
37     CellularCallConfig();
38 
39     /**
40      * Set Domain Preference Mode
41      *
42      * 3GPP TS 27.007 V17.3.0 (2021-09) 10.1.35	UE's voice domain preference E-UTRAN +CEVDP
43      * 3GPP TS 24.167 V17.1.0 (2020-12) 5.27 /<X>/Voice_Domain_Preference_E_UTRAN
44      *
45      * @param mode
46      * @param slotId
47      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
48      */
49     int32_t SetDomainPreferenceMode(int32_t slotId, int32_t mode);
50 
51     /**
52      * Get Domain Preference Mode
53      *
54      * 3GPP TS 27.007 V17.3.0 (2021-09) 10.1.35	UE's voice domain preference E-UTRAN +CEVDP
55      * 3GPP TS 24.167 V17.1.0 (2020-12) 5.27 /<X>/Voice_Domain_Preference_E_UTRAN
56      *
57      * @param slotId
58      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
59      */
60     int32_t GetDomainPreferenceMode(int32_t slotId);
61 
62     /**
63      * Set Lte Ims Switch Status
64      *
65      * 3GPP TS 24.167 V17.1.0 (2020-12) 5.31 /<X>/Mobility_Management_IMS_Voice_Termination
66      *
67      * @param slotId
68      * @param active
69      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
70      */
71     int32_t SetImsSwitchStatus(int32_t slotId, bool active);
72 
73     /**
74      * Get Lte Ims Switch Status
75      *
76      * 3GPP TS 24.167 V17.1.0 (2020-12) 5.31 /<X>/Mobility_Management_IMS_Voice_Termination
77      *
78      * @param slotId
79      * @param enabled
80      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
81      */
82     int32_t GetImsSwitchStatus(int32_t slotId, bool &enabled);
83 
84     /**
85      * Set VoNR Switch Status
86      *
87      * @param slotId
88      * @param state
89      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
90      */
91     int32_t SetVoNRSwitchStatus(int32_t slotId, int32_t state);
92 
93     /**
94      * Get VoNR Switch Status
95      *
96      * @param slotId
97      * @param state
98      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
99      */
100     int32_t GetVoNRSwitchStatus(int32_t slotId, int32_t &state);
101 
102     /**
103      * Get Domain Preference Mode Response
104      *
105      * @param slotId
106      * @param mode
107      */
108     void GetDomainPreferenceModeResponse(int32_t slotId, int32_t mode);
109 
110     /**
111      * Get Lte Ims Switch Status Response
112      *
113      * @param slotId
114      * @param active
115      */
116     void GetImsSwitchStatusResponse(int32_t slotId, int32_t active);
117 
118     /**
119      * Get Preference Mode
120      *
121      * @param slotId
122      * @return mode
123      */
124     int32_t GetPreferenceMode(int32_t slotId) const;
125 
126     /**
127      * Set Ims Config
128      *
129      * @param ImsConfigItem
130      * @param value
131      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
132      */
133     int32_t SetImsConfig(ImsConfigItem item, const std::string &value);
134 
135     /**
136      * Set Ims Config
137      *
138      * @param ImsConfigItem
139      * @param value
140      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
141      */
142     int32_t SetImsConfig(ImsConfigItem item, int32_t value);
143 
144     /**
145      * Get Ims Config
146      *
147      * @param ImsConfigItem
148      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
149      */
150     int32_t GetImsConfig(ImsConfigItem item);
151 
152     /**
153      * Set Ims Feature Value
154      *
155      * @param FeatureType
156      * @param value
157      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
158      */
159     int32_t SetImsFeatureValue(FeatureType type, int32_t value);
160 
161     /**
162      * Get Ims Feature Value
163      *
164      * @param FeatureType
165      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
166      */
167     int32_t GetImsFeatureValue(FeatureType type);
168 
169     /**
170      * SetMute
171      *
172      * @param slotId
173      * @param mute
174      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
175      */
176     int32_t SetMute(int32_t slotId, int32_t mute);
177 
178     /**
179      * GetMute
180      *
181      * @param slotId
182      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
183      */
184     int32_t GetMute(int32_t slotId);
185 
186     /**
187      * GetEmergencyCallList
188      *
189      * @param slotId
190      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
191      */
192     int32_t GetEmergencyCallList(int32_t slotId);
193 
194     /**
195      * SetEmergencyCallList
196      *
197      * @param slotId
198      * @param eccVec
199      * @return Returns TELEPHONY_SUCCESS on success, others on failure.
200      */
201     int32_t SetEmergencyCallList(int32_t slotId, std::vector<EmergencyCall> &eccVec);
202 
203     /**
204      * SetTempMode
205      *
206      * @param slotId
207      */
208     void SetTempMode(int32_t slotId);
209 
210     /**
211      * Init mode and active
212      */
213     void InitModeActive();
214 
215     /**
216      * Get Emergency Call List Response
217      *
218      * @param slotId
219      * @param EmergencyInfoList
220      */
221     void UpdateEmergencyCallFromRadio(int32_t slotId, const EmergencyInfoList &eccList);
222 
223     /**
224      * HandleSimStateChanged
225      *
226      * @param slotId
227      */
228     void HandleSimStateChanged(int32_t slotId);
229 
230     /**
231      * HandleFactoryReset
232      *
233      * @param slotId
234      */
235     void HandleFactoryReset(int32_t slotId);
236 
237     /**
238      * HandleSetLteImsSwitchResult
239      *
240      * @param slotId
241      * @param result
242      */
243     void HandleSetLteImsSwitchResult(int32_t slotId, ErrType result);
244 
245     /**
246      * HandleSetVoNRSwitchResult
247      *
248      * @param slotId
249      * @param result
250      */
251     void HandleSetVoNRSwitchResult(int32_t slotId, ErrType result);
252 
253     /**
254      * HandleSimRecordsLoaded
255      *
256      * @param slotId
257      */
258     void HandleSimRecordsLoaded(int32_t slotId);
259 
260     void HandleResidentNetworkChange(int32_t slotId, std::string plmn);
261 
262     void HandleNetworkStateChange(int32_t slotId);
263 
264     /**
265      * HandleSimAccountLoaded
266      *
267      * @param slotId
268      */
269     void HandleSimAccountLoaded(int32_t slotId);
270 
271     /**
272      * Handle when operator config change.
273      *
274      * @param slotId
275      */
276     void HandleOperatorConfigChanged(int32_t slotId);
277 
278     /**
279      * Get Ecc Call List
280      *
281      * @param slotId
282      * @return std::vector<EmergencyCall>
283      */
284     std::vector<EmergencyCall> GetEccCallList(int32_t slotId);
285 
286     std::string GetMcc(int32_t slotId_);
287 
288     /**
289      * Change bool value to Ims switch value.
290      *
291      * @param value
292      * @return std::int32_t
293      */
294     std::int32_t BooleanToImsSwitchValue(bool value);
295 
296     /**
297      * The IF used to get the value of operator config
298      * {@link OperatorConfig#KEY_IMS_SWITCH_ON_BY_DEFAULT_BOOL}
299      *
300      * @param slotId
301      * @return bool
302      */
303     bool GetImsSwitchOnByDefaultConfig(int32_t slotId);
304 
305     /**
306      * The IF used to get the value of operator config
307      * {@link OperatorConfig#KEY_HIDE_IMS_SWITCH_BOOL}
308      *
309      * @param slotId
310      * @return bool
311      */
312     bool GethideImsSwitchConfig(int32_t slotId);
313 
314     /**
315      * The IF used to get the value of operator config
316      * {@link OperatorConfig#KEY_VOLTE_SUPPORTED_BOOL}
317      *
318      * @param slotId
319      * @return bool
320      */
321     bool GetvolteSupportedConfig(int32_t slotId);
322 
323     /**
324      * The IF used to get the value of operator config
325      * {@link OperatorConfig#KEY_NR_MODE_SUPPORTED_LIST_INT_ARRAY}
326      *
327      * @param slotId
328      * @return std::vector<int32_t>
329      */
330     std::vector<int32_t> GetNrModeSupportedListConfig(int32_t slotId);
331 
332     /**
333      * The IF used to get the value of operator config
334      * {@link OperatorConfig#KEY_VOLTE_PROVISIONING_SUPPORTED_BOOL}
335      *
336      * @param slotId
337      * @return bool
338      */
339     bool GetVolteProvisioningSupportedConfig(int32_t slotId);
340 
341     /**
342      * The IF used to get the value of operator config
343      * {@link OperatorConfig#KEY_SS_OVER_UT_SUPPORTED_BOOL}
344      *
345      * @param slotId
346      * @return bool
347      */
348     bool GetSsOverUtSupportedConfig(int32_t slotId);
349 
350     /**
351      * The IF used to get the value of operator config
352      * {@link OperatorConfig#KEY_IMS_GBA_REQUIRED_BOOL}
353      *
354      * @param slotId
355      * @return bool
356      */
357     bool GetImsGbaRequiredConfig(int32_t slotId);
358 
359     /**
360      * The IF used to get the value of operator config
361      * {@link OperatorConfig#KEY_UT_PROVISIONING_SUPPORTED_BOOL}
362      *
363      * @param slotId
364      * @return bool
365      */
366     bool GetUtProvisioningSupportedConfig(int32_t slotId);
367 
368     /**
369      * The IF used to get the value of operator config
370      * {@link OperatorConfig#KEY_IMS_PREFER_FOR_EMERGENCY_BOOL}
371      *
372      * @param slotId
373      * @return bool
374      */
375     bool GetImsPreferForEmergencyConfig(int32_t slotId);
376 
377     /**
378      * The IF used to get the value of operator config
379      * {@link OperatorConfig#KEY_CALL_WAITING_SERVICE_CLASS_INT}
380      *
381      * @param slotId
382      * @return std::int32_t
383      */
384     std::int32_t GetCallWaitingServiceClassConfig(int32_t slotId);
385 
386     /**
387      * The IF used to get the value of operator config
388      * {@link OperatorConfig#KEY_IMS_CALL_DISCONNECT_REASONINFO_MAPPING_STRING_ARRAY}
389      *
390      * @param slotId
391      * @return std::vector<std::string>
392      */
393     std::vector<std::string> GetImsCallDisconnectResoninfoMappingConfig(int32_t slotId);
394 
395     /**
396      * The IF used to get the value of operator config
397      * {@link OperatorConfig#KEY_FORCE_VOLTE_SWITCH_ON_BOOL}
398      *
399      * @param slotId
400      * @return bool
401      */
402     bool GetForceVolteSwitchOnConfig(int32_t slotId);
403 
404     /**
405      * Is Valid Slot Id
406      *
407      * @param slotId
408      * @return bool
409      */
410     bool IsValidSlotId(int32_t slotId);
411 
412     void SetReadyToCall(int32_t slotId, bool isReadyToCall);
413 
414     bool IsReadyToCall(int32_t slotId);
415 
416     /**
417      * update ims capability to modem.
418      *
419      * @param slotId
420      * @param needUpdateUtCapability update ut capability or not
421      */
422     void UpdateImsCapabilities(int32_t slotId, bool needUpdateUtCapability);
423 
424     bool NeedReadThirdParyLib();
425 
426 private:
427     static void InitDefaultOperatorConfig();
428     EmergencyCall BuildDefaultEmergencyCall(const std::string &number, SimpresentType simType);
429     EmergencyCall BuildEmergencyCall(int32_t slotId, const EmergencyInfo &from);
430     void UniqueEccCallList(int32_t slotId, std::vector<EmergencyCall> &eccList);
431     void MergeEccCallList(int32_t slotId);
432     bool CheckAndUpdateSimState(int32_t slotId);
433     int32_t ParseAndCacheOperatorConfigs(int32_t slotId, OperatorConfig &poc);
434     void ParseBoolOperatorConfigs(
435         int32_t slotId, std::map<int32_t, bool> &config, OperatorConfig &poc, std::string configName);
436     void ResetImsSwitch(int32_t slotId);
437     void UpdateImsUtCapabilities(int32_t slotId, bool isGbaValid, ImsCapabilityList &imsCapabilityList);
438     void UpdateImsVoiceCapabilities(int32_t slotId, bool isGbaValid, ImsCapabilityList &imsCapabilityList);
439     bool IsGbaValid(int32_t slotId);
440     bool IsVolteProvisioned(int32_t slotId);
441     bool IsVonrSupported(int32_t slotId, bool isGbaValid);
442     bool IsUtProvisioned(int32_t slotId);
443     bool IsNeedTurnOnIms(const ImsCapabilityList &imsCapabilityList);
444     bool IsSimChanged(int32_t slotId, std::string iccid);
445     bool ChangeImsSwitchWithOperatorConfig(int32_t slotId, bool active);
446     int32_t SaveImsSwitch(int32_t slotId, int32_t imsSwitchValue);
447     int32_t GetSwitchStatus(int32_t slotId);
448     void saveImsSwitchStatusToLocalForPowerOn(int32_t slotId);
449     void saveImsSwitchStatusToLocal(int32_t slotId, int32_t imsSwitchStatus);
450     void SaveVoNRState(int32_t slotId, int32_t state);
451     int32_t ObtainVoNRState(int32_t slotId);
452     void UpdateEccNumberList(int32_t slotId);
453     void GetEccListFromResult(const std::vector<EccNum> &eccVec,
454         std::vector<std::string> &callListWithCard, std::vector<std::string> &callListNoCard);
455     int32_t CheckHomeAndPresentState(int32_t slotId, bool &isHoamAndPresent);
456     bool GetRoamingState(int32_t slotId);
457 
458 private:
459     static std::map<int32_t, int32_t> modeTempMap_;
460     static std::map<int32_t, int32_t> modeMap_;
461     static std::map<int32_t, std::vector<EmergencyCall>> eccListRadioMap_;
462     static std::vector<EmergencyCall> eccList3gppHasSim_;
463     static std::vector<EmergencyCall> eccList3gppNoSim_;
464     static std::map<int32_t, std::vector<EmergencyCall>> allEccList_;
465     static std::map<int32_t, int32_t> simState_;
466     static std::map<int32_t, std::string> curPlmn_;
467     std::mutex mutex_;
468     std::mutex simStateLock_;
469     static std::mutex operatorMutex_;
470     ConfigRequest configRequest_;
471     static std::map<int32_t, bool> imsSwitchOnByDefault_;
472     static std::map<int32_t, bool> hideImsSwitch_;
473     static std::map<int32_t, bool> volteSupported_;
474     static std::map<int32_t, std::vector<int32_t>> nrModeSupportedList_;
475     static std::map<int32_t, bool> volteProvisioningSupported_;
476     static std::map<int32_t, bool> ssOverUtSupported_;
477     static std::map<int32_t, bool> imsGbaRequired_;
478     static std::map<int32_t, bool> utProvisioningSupported_;
479     static std::map<int32_t, bool> imsPreferForEmergency_;
480     static std::map<int32_t, int32_t> callWaitingServiceClass_;
481     static std::map<int32_t, std::vector<std::string>> imsCallDisconnectResoninfoMapping_;
482     static std::map<int32_t, bool> forceVolteSwitchOn_;
483     static std::map<int32_t, bool> readyToCall_;
484     static std::map<int32_t, int32_t> vonrSwithStatus_;
485     static std::map<int32_t, int32_t> nrModeSupported_;
486     static bool isOperatorConfigInit_;
487     struct cellularNetworkState {
488         bool isInService_ = false;
489         bool isRoaming_ = false;
490     };
491     static std::map<int32_t, cellularNetworkState> networkServiceState_;
492 };
493 } // namespace Telephony
494 } // namespace OHOS
495 #endif // CELLULAR_CALL_CONFIG_H
496