• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2025 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 #ifndef LOG_TAG
16 #define LOG_TAG "AudioToneManager"
17 #endif
18 
19 #include "audio_tone_manager.h"
20 #include <ability_manager_client.h>
21 #include "iservice_registry.h"
22 #include "parameter.h"
23 #include "parameters.h"
24 
25 #include "audio_policy_log.h"
26 #include "audio_inner_call.h"
27 #include "audio_tone_parser.h"
28 #include "media_monitor_manager.h"
29 
30 #include "audio_policy_utils.h"
31 
32 namespace OHOS {
33 namespace AudioStandard {
34 
35 #ifdef FEATURE_DTMF_TONE
LoadToneDtmfConfig()36 bool AudioToneManager::LoadToneDtmfConfig()
37 {
38     AUDIO_INFO_LOG("Enter");
39     std::unique_ptr<AudioToneParser> audioToneParser = std::make_unique<AudioToneParser>();
40     if (audioToneParser == nullptr) {
41         AudioPolicyUtils::GetInstance().WriteServiceStartupError("Audio Tone Load Configuration failed");
42     }
43     CHECK_AND_RETURN_RET_LOG(audioToneParser != nullptr, false, "Failed to create AudioToneParser");
44     if (audioToneParser->LoadNewConfig(AudioToneParser::AUDIO_TONE_CONFIG_FILE, toneDescriptorMap_,
45         customToneDescriptorMap_)) {
46         std::shared_ptr<Media::MediaMonitor::EventBean> bean = std::make_shared<Media::MediaMonitor::EventBean>(
47             Media::MediaMonitor::ModuleId::AUDIO, Media::MediaMonitor::EventId::LOAD_CONFIG_ERROR,
48             Media::MediaMonitor::EventType::FAULT_EVENT);
49         bean->Add("CATEGORY", Media::MediaMonitor::AUDIO_TONE_DTMF_CONFIG);
50         Media::MediaMonitor::MediaMonitorManager::GetInstance().WriteLogMsg(bean);
51         AudioPolicyUtils::GetInstance().WriteServiceStartupError("Audio Tone Load Configuration failed");
52         AUDIO_ERR_LOG("Audio Tone Load Configuration failed");
53         return false;
54     }
55     AUDIO_INFO_LOG("Done");
56     return true;
57 }
58 
GetSupportedTones(const std::string & countryCode)59 std::vector<int32_t> AudioToneManager::GetSupportedTones(const std::string &countryCode)
60 {
61     AUDIO_DEBUG_LOG("countryCode: %{public}s", countryCode.c_str());
62     std::set<int32_t> supportedToneList = {};
63     auto customToneDescriptorItem = customToneDescriptorMap_.find(countryCode);
64     if (customToneDescriptorItem != customToneDescriptorMap_.end()) {
65         for (auto &[number, toneInfo] : customToneDescriptorItem->second) {
66             supportedToneList.insert(number);
67         }
68     }
69 
70     for (auto &[number, toneInfo] : toneDescriptorMap_) {
71         supportedToneList.insert(number);
72     }
73 
74     return std::vector<int32_t>(supportedToneList.begin(), supportedToneList.end());
75 }
76 
GetToneConfig(int32_t ltonetype,const std::string & countryCode)77 std::shared_ptr<ToneInfo> AudioToneManager::GetToneConfig(int32_t ltonetype, const std::string &countryCode)
78 {
79     AUDIO_DEBUG_LOG("ltonetype: %{public}d, countryCode: %{public}s", ltonetype, countryCode.c_str());
80     auto customToneDescriptorItem = customToneDescriptorMap_.find(countryCode);
81     if (customToneDescriptorItem != customToneDescriptorMap_.end()) {
82         auto toneInfo = customToneDescriptorItem->second.find(ltonetype);
83         if (toneInfo != customToneDescriptorItem->second.end()) {
84             AUDIO_DEBUG_LOG("Get custom ToneConfig %{public}d", ltonetype);
85             return toneInfo->second;
86         }
87     }
88 
89     if (toneDescriptorMap_.find(ltonetype) != toneDescriptorMap_.end()) {
90         AUDIO_DEBUG_LOG("Get default ToneConfig %{public}d", ltonetype);
91         return toneDescriptorMap_[ltonetype];
92     }
93     AUDIO_DEBUG_LOG("Get ToneConfig %{public}d fail", ltonetype);
94     return nullptr;
95 }
96 #endif
97 
98 }
99 }