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
24 #define LOG_TAG "SilenceUpdateStrategy"
25
26 using namespace OHOS::IntellVoiceUtils;
27
28 namespace OHOS {
29 namespace IntellVoiceEngine {
30 static constexpr int32_t SILENCE_UPDATE_RETRY_TIMES = 5;
31
SilenceUpdateStrategy(const std::string & param)32 SilenceUpdateStrategy::SilenceUpdateStrategy(const std::string ¶m): IUpdateStrategy(param)
33 {
34 }
35
~SilenceUpdateStrategy()36 SilenceUpdateStrategy::~SilenceUpdateStrategy()
37 {
38 }
39
UpdateRestrain()40 bool SilenceUpdateStrategy::UpdateRestrain()
41 {
42 return !UpdateEngineUtils::IsVersionUpdate();
43 }
44
GetUpdatePriority()45 UpdatePriority SilenceUpdateStrategy::GetUpdatePriority()
46 {
47 return SILENCE_UPDATE_PRIORITY;
48 }
49
GetRetryTimes()50 int SilenceUpdateStrategy::GetRetryTimes()
51 {
52 return SILENCE_UPDATE_RETRY_TIMES;
53 }
54
NotifyUpdateFail()55 void SilenceUpdateStrategy::NotifyUpdateFail()
56 {
57 AAFwk::Want want;
58 HistoryInfoMgr &historyInfoMgr = HistoryInfoMgr::GetInstance();
59
60 std::string bundleName = historyInfoMgr.GetWakeupEngineBundleName();
61 std::string abilityName = historyInfoMgr.GetWakeupEngineAbilityName();
62 INTELL_VOICE_LOG_INFO("bundleName:%{public}s, abilityName:%{public}s", bundleName.c_str(), abilityName.c_str());
63 want.SetElementName(bundleName, abilityName);
64 want.SetParam("serviceName", std::string("intell_voice"));
65 want.SetParam("servicePid", getpid());
66 want.SetParam("eventType", std::string("update_event"));
67 AAFwk::AbilityManagerClient::GetInstance()->StartAbility(want);
68 }
69
OnUpdateCompleteCallback(const int result,bool isLast)70 int SilenceUpdateStrategy::OnUpdateCompleteCallback(const int result, bool isLast)
71 {
72 if (!isLast || result == 0) {
73 return 0;
74 }
75
76 INTELL_VOICE_LOG_INFO("notify silence update fail");
77 NotifyUpdateFail();
78 return 0;
79 }
80 }
81 }