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