• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "silence_update_strategy.h"
16 #include <fstream>
17 #include "securec.h"
18 #include "intell_voice_log.h"
19 #include "scope_guard.h"
20 #include "update_engine_utils.h"
21 #include "history_info_mgr.h"
22 #include "ability_manager_client.h"
23 #include "intell_voice_definitions.h"
24 
25 #define LOG_TAG "SilenceUpdateStrategy"
26 
27 using namespace OHOS::IntellVoiceUtils;
28 
29 namespace OHOS {
30 namespace IntellVoiceEngine {
31 static constexpr int32_t SILENCE_UPDATE_RETRY_TIMES = 5;
32 
SilenceUpdateStrategy(const std::string & param)33 SilenceUpdateStrategy::SilenceUpdateStrategy(const std::string &param): IUpdateStrategy(param)
34 {
35 }
36 
~SilenceUpdateStrategy()37 SilenceUpdateStrategy::~SilenceUpdateStrategy()
38 {
39 }
40 
UpdateRestrain()41 bool SilenceUpdateStrategy::UpdateRestrain()
42 {
43     return !UpdateEngineUtils::IsVersionUpdate();
44 }
45 
GetUpdatePriority()46 UpdatePriority SilenceUpdateStrategy::GetUpdatePriority()
47 {
48     return SILENCE_UPDATE_PRIORITY;
49 }
50 
GetRetryTimes()51 int SilenceUpdateStrategy::GetRetryTimes()
52 {
53     return SILENCE_UPDATE_RETRY_TIMES;
54 }
55 
NotifyUpdateFail()56 void SilenceUpdateStrategy::NotifyUpdateFail()
57 {
58     AAFwk::Want want;
59     HistoryInfoMgr &historyInfoMgr = HistoryInfoMgr::GetInstance();
60 
61     std::string bundleName = historyInfoMgr.GetStringKVPair(KEY_WAKEUP_ENGINE_BUNDLE_NAME);
62     std::string abilityName = historyInfoMgr.GetStringKVPair(KEY_WAKEUP_ENGINE_ABILITY_NAME);
63     INTELL_VOICE_LOG_INFO("bundleName:%{public}s, abilityName:%{public}s", bundleName.c_str(), abilityName.c_str());
64     if (bundleName.empty() || abilityName.empty()) {
65         INTELL_VOICE_LOG_ERROR("bundle name is empty or ability name is empty");
66         return;
67     }
68     want.SetElementName(bundleName, abilityName);
69     want.SetParam("serviceName", std::string("intell_voice"));
70     want.SetParam("servicePid", getpid());
71     want.SetParam("eventType", std::string("update_event"));
72     auto abilityManagerClient = AAFwk::AbilityManagerClient::GetInstance();
73     if (abilityManagerClient == nullptr) {
74         INTELL_VOICE_LOG_ERROR("abilityManagerClient is nullptr");
75         return;
76     }
77     abilityManagerClient->StartAbility(want);
78 }
79 
OnUpdateCompleteCallback(const int result,bool isLast)80 int SilenceUpdateStrategy::OnUpdateCompleteCallback(const int result, bool isLast)
81 {
82     if (!isLast || result == 0) {
83         return 0;
84     }
85 
86     INTELL_VOICE_LOG_INFO("notify silence update fail");
87     NotifyUpdateFail();
88     return  0;
89 }
90 }
91 }