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 #include "ringtone_utils.h"
17
18 #include <securec.h>
19
20 #include "parameter.h"
21 #include "ringtone_type.h"
22
23 namespace OHOS {
24 namespace Media {
25 using namespace std;
26 static const int32_t SYSPARA_SIZE = 128;
27
ReplaceAll(std::string str,const std::string & oldValue,const std::string & newValue)28 std::string RingtoneUtils::ReplaceAll(std::string str, const std::string &oldValue, const std::string &newValue)
29 {
30 for (std::string::size_type pos(0); pos != std::string::npos; pos += newValue.length()) {
31 if ((pos = str.find(oldValue, pos)) != std::string::npos) {
32 str.replace(pos, oldValue.length(), newValue);
33 } else {
34 break;
35 }
36 }
37 return str;
38 }
39
GetDefaultSystemtoneInfo()40 std::map<int, std::string> RingtoneUtils::GetDefaultSystemtoneInfo()
41 {
42 map<int, string> defaultSystemtoneInfo;
43 char paramValue[SYSPARA_SIZE] = {0};
44 GetParameter(PARAM_RINGTONE_SETTING_RINGTONE, "", paramValue, SYSPARA_SIZE);
45 if (strcmp(paramValue, "")) {
46 defaultSystemtoneInfo.insert(make_pair(DEFAULT_RING_TYPE_SIM_CARD_1, string(paramValue)));
47 }
48
49 memset_s(paramValue, sizeof(paramValue), 0, sizeof(paramValue));
50 GetParameter(PARAM_RINGTONE_SETTING_RINGTONE2, "", paramValue, SYSPARA_SIZE);
51 if (strcmp(paramValue, "")) {
52 defaultSystemtoneInfo.insert(make_pair(DEFAULT_RING_TYPE_SIM_CARD_2, string(paramValue)));
53 }
54
55 memset_s(paramValue, sizeof(paramValue), 0, sizeof(paramValue));
56 GetParameter(PARAM_RINGTONE_SETTING_SHOT, "", paramValue, SYSPARA_SIZE);
57 if (strcmp(paramValue, "")) {
58 defaultSystemtoneInfo.insert(make_pair(DEFAULT_SHOT_TYPE_SIM_CARD_1, string(paramValue)));
59 }
60
61 memset_s(paramValue, sizeof(paramValue), 0, sizeof(paramValue));
62 GetParameter(PARAM_RINGTONE_SETTING_SHOT2, "", paramValue, SYSPARA_SIZE);
63 if (strcmp(paramValue, "")) {
64 defaultSystemtoneInfo.insert(make_pair(DEFAULT_SHOT_TYPE_SIM_CARD_2, string(paramValue)));
65 }
66
67 memset_s(paramValue, sizeof(paramValue), 0, sizeof(paramValue));
68 GetParameter(PARAM_RINGTONE_SETTING_NOTIFICATIONTONE, "", paramValue, SYSPARA_SIZE);
69 if (strcmp(paramValue, "")) {
70 defaultSystemtoneInfo.insert(make_pair(DEFAULT_NOTIFICATION_TYPE, string(paramValue)));
71 }
72
73 memset_s(paramValue, sizeof(paramValue), 0, sizeof(paramValue));
74 GetParameter(PARAM_RINGTONE_SETTING_ALARM, "", paramValue, SYSPARA_SIZE);
75 if (strcmp(paramValue, "")) {
76 defaultSystemtoneInfo.insert(make_pair(DEFAULT_ALARM_TYPE, string(paramValue)));
77 }
78 return defaultSystemtoneInfo;
79 }
80 } // namespace Media
81 } // namespace OHOS
82