1 /*
2 * Copyright (C) 2023 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 "voice_mail_constants.h"
17
18 #include <unistd.h>
19
20 #include "core_manager_inner.h"
21 #include "string_ex.h"
22 #include "telephony_ext_wrapper.h"
23
24 using namespace std;
25
26 namespace OHOS {
27 namespace Telephony {
VoiceMailConstants(int32_t slotId)28 VoiceMailConstants::VoiceMailConstants(int32_t slotId)
29 {
30 slotId_ = slotId;
31 if (TELEPHONY_EXT_WRAPPER.initVoiceMailManagerExt_ != nullptr) {
32 TELEPHONY_EXT_WRAPPER.initVoiceMailManagerExt_(slotId);
33 }
34 }
35
~VoiceMailConstants()36 VoiceMailConstants::~VoiceMailConstants()
37 {
38 if (TELEPHONY_EXT_WRAPPER.deinitVoiceMailManagerExt_ != nullptr) {
39 TELEPHONY_EXT_WRAPPER.deinitVoiceMailManagerExt_(slotId_);
40 }
41 }
42
GetStringValueFromCust(int32_t slotId,std::string key)43 std::string VoiceMailConstants::GetStringValueFromCust(int32_t slotId, std::string key)
44 {
45 OperatorConfig operatorConfig;
46 CoreManagerInner::GetInstance().GetOperatorConfigs(slotId, operatorConfig);
47 std::string value = "";
48 std::map<std::string, std::string>::iterator it = operatorConfig.stringValue.begin();
49 it = operatorConfig.stringValue.find(key);
50 if (it != operatorConfig.stringValue.end()) {
51 value = it->second;
52 }
53 return value;
54 }
55
ResetVoiceMailLoadedFlag()56 void VoiceMailConstants::ResetVoiceMailLoadedFlag()
57 {
58 if (TELEPHONY_EXT_WRAPPER.resetVoiceMailLoadedFlagExt_ != nullptr) {
59 TELEPHONY_LOGI("VoiceMailConstants::ResetVoiceMailLoadedFlag, resetVoiceMailLoadedFlagExt_");
60 TELEPHONY_EXT_WRAPPER.resetVoiceMailLoadedFlagExt_(slotId_);
61 return;
62 }
63 isVoiceMailFixed_ = false;
64 }
65
GetVoiceMailFixed(std::string carrier)66 bool VoiceMailConstants::GetVoiceMailFixed(std::string carrier)
67 {
68 if (TELEPHONY_EXT_WRAPPER.getVoiceMailFixedExt_ != nullptr) {
69 TELEPHONY_LOGI("VoiceMailConstants::GetVoiceMailFixed, getVoiceMailFixedExt_");
70 return TELEPHONY_EXT_WRAPPER.getVoiceMailFixedExt_(slotId_, carrier.c_str());
71 }
72 isVoiceMailFixed_ = true;
73 return isVoiceMailFixed_;
74 }
75
GetVoiceMailNumber(std::string carrier)76 std::string VoiceMailConstants::GetVoiceMailNumber(std::string carrier)
77 {
78 if (TELEPHONY_EXT_WRAPPER.getVoiceMailNumberExt_ != nullptr) {
79 TELEPHONY_LOGI("VoiceMailConstants::GetVoiceMailNumber, getVoiceMailNumberExt_");
80 std::string number = "";
81 TELEPHONY_EXT_WRAPPER.getVoiceMailNumberExt_(slotId_, carrier.c_str(), number);
82 return number;
83 }
84 return GetStringValueFromCust(slotId_, KEY_VOICE_MAIL_NUMBER_STRING);
85 }
86
GetVoiceMailTag(std::string carrier)87 std::string VoiceMailConstants::GetVoiceMailTag(std::string carrier)
88 {
89 if (TELEPHONY_EXT_WRAPPER.getVoiceMailTagExt_ != nullptr) {
90 TELEPHONY_LOGI("VoiceMailConstants::GetVoiceMailTag, getVoiceMailTagExt_");
91 std::string tag = "";
92 TELEPHONY_EXT_WRAPPER.getVoiceMailTagExt_(slotId_, carrier.c_str(), tag);
93 return tag;
94 }
95 return GetStringValueFromCust(slotId_, KEY_VOICE_MAIL_TAG_STRING);
96 }
97
LoadVoiceMailConfigFromCard(std::string configName,std::string carrier)98 std::string VoiceMailConstants::LoadVoiceMailConfigFromCard(std::string configName, std::string carrier)
99 {
100 if (carrier.empty()) {
101 return "";
102 }
103 return GetStringValueFromCust(slotId_, configName);
104 }
105
ContainsCarrier(std::string carrier)106 bool VoiceMailConstants::ContainsCarrier(std::string carrier)
107 {
108 std::string carrierName = LoadVoiceMailConfigFromCard(KEY_VOICE_MAIL_CARRIER_STRING, carrier);
109 return !carrierName.empty();
110 }
111 } // namespace Telephony
112 } // namespace OHOS
113