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 #include "history_info_mgr.h"
16 
17 #include "string_util.h"
18 
19 #define LOG_TAG "HistoryInfoMgr"
20 
21 using namespace OHOS::IntellVoiceUtils;
22 
23 namespace OHOS {
24 namespace IntellVoiceEngine {
25 constexpr int DECIMAL_NOTATION = 10;
26 const std::string KEY_ENROLL_ENGINE_UID = "EnrollEngineUid";
27 const std::string KEY_SENSIBILITY = "Sensibility";
28 const std::string KEY_WAKEUP_DSP_FEATURE = "WakeupDspFeature";
29 
HistoryInfoMgr()30 HistoryInfoMgr::HistoryInfoMgr()
31     : ServiceDbHelper("intell_voice_service_manager", "local_intell_voice_history_mgr_storeId")
32 {
33 }
34 
SetEnrollEngineUid(int32_t uid)35 void HistoryInfoMgr::SetEnrollEngineUid(int32_t uid)
36 {
37     SetValue(KEY_ENROLL_ENGINE_UID, StringUtil::Int2String(uid));
38 }
39 
GetEnrollEngineUid()40 int32_t HistoryInfoMgr::GetEnrollEngineUid()
41 {
42     std::string value = GetValue(KEY_ENROLL_ENGINE_UID);
43     return static_cast<int32_t>(strtol(value.c_str(), nullptr, DECIMAL_NOTATION));
44 }
45 
SetWakeupEngineBundleName(const std::string & bundleName)46 void HistoryInfoMgr::SetWakeupEngineBundleName(const std::string &bundleName)
47 {
48     SetValue(KEY_WAKEUP_ENGINE_BUNDLE_NAME, bundleName);
49 }
50 
GetWakeupEngineBundleName()51 std::string HistoryInfoMgr::GetWakeupEngineBundleName()
52 {
53     return GetValue(KEY_WAKEUP_ENGINE_BUNDLE_NAME);
54 }
55 
SetWakeupEngineAbilityName(const std::string & abilityName)56 void HistoryInfoMgr::SetWakeupEngineAbilityName(const std::string &abilityName)
57 {
58     SetValue(KEY_WAKEUP_ENGINE_ABILITY_NAME, abilityName);
59 }
60 
GetWakeupEngineAbilityName()61 std::string HistoryInfoMgr::GetWakeupEngineAbilityName()
62 {
63     return GetValue(KEY_WAKEUP_ENGINE_ABILITY_NAME);
64 }
65 
SetWakeupVesion(const std::string & wakeupVesion)66 void HistoryInfoMgr::SetWakeupVesion(const std::string &wakeupVesion)
67 {
68     SetValue(KEY_WAKEUP_VESRION, wakeupVesion);
69 }
70 
GetWakeupVesion()71 std::string HistoryInfoMgr::GetWakeupVesion()
72 {
73     return GetValue(KEY_WAKEUP_VESRION);
74 }
75 
SetLanguage(const std::string & language)76 void HistoryInfoMgr::SetLanguage(const std::string &language)
77 {
78     SetValue(KEY_LANGUAGE, language);
79 }
80 
GetLanguage()81 std::string HistoryInfoMgr::GetLanguage()
82 {
83     return GetValue(KEY_LANGUAGE);
84 }
85 
SetArea(const std::string & area)86 void HistoryInfoMgr::SetArea(const std::string &area)
87 {
88     SetValue(KEY_AREA, area);
89 }
90 
GetArea()91 std::string HistoryInfoMgr::GetArea()
92 {
93     return GetValue(KEY_AREA);
94 }
95 
SetSensibility(const std::string & sensibility)96 void HistoryInfoMgr::SetSensibility(const std::string &sensibility)
97 {
98     SetValue(KEY_SENSIBILITY, sensibility);
99 }
100 
GetSensibility()101 std::string HistoryInfoMgr::GetSensibility()
102 {
103     return GetValue(KEY_SENSIBILITY);
104 }
105 
SetWakeupPhrase(const std::string & wakeupPhrase)106 void HistoryInfoMgr::SetWakeupPhrase(const std::string &wakeupPhrase)
107 {
108     SetValue(KEY_WAKEUP_PHRASE, wakeupPhrase);
109 }
110 
GetWakeupPhrase()111 std::string HistoryInfoMgr::GetWakeupPhrase()
112 {
113     return GetValue(KEY_WAKEUP_PHRASE);
114 }
115 
SetWakeupDspFeature(const std::string & wakeupDspFeature)116 void HistoryInfoMgr::SetWakeupDspFeature(const std::string &wakeupDspFeature)
117 {
118     SetValue(KEY_WAKEUP_DSP_FEATURE, wakeupDspFeature);
119 }
120 
GetWakeupDspFeature()121 std::string HistoryInfoMgr::GetWakeupDspFeature()
122 {
123     return GetValue(KEY_WAKEUP_DSP_FEATURE);
124 }
125 
DeleteKey(const std::vector<std::string> & keyList)126 void HistoryInfoMgr::DeleteKey(const std::vector<std::string> &keyList)
127 {
128     for (auto key : keyList) {
129         Delete(key);
130     }
131 }
132 }
133 }