1 /*
2 * Copyright (c) 2024-2025 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 "keep_alive_utils.h"
17
18 #include "ability_resident_process_rdb.h"
19 #include "keep_alive_process_manager.h"
20 #include "main_element_utils.h"
21
22 namespace OHOS {
23 namespace AAFwk {
NotifyDisableKeepAliveProcesses(const std::vector<AppExecFwk::BundleInfo> & bundleInfos,int32_t userId)24 void KeepAliveUtils::NotifyDisableKeepAliveProcesses(
25 const std::vector<AppExecFwk::BundleInfo> &bundleInfos, int32_t userId)
26 {
27 for (size_t i = 0; i < bundleInfos.size(); i++) {
28 std::string processName = bundleInfos[i].applicationInfo.process;
29 for (const auto &hapModuleInfo : bundleInfos[i].hapModuleInfos) {
30 std::string mainElement;
31 bool isDataAbility = false;
32 std::string uriStr;
33 if (!MainElementUtils::CheckMainElement(hapModuleInfo,
34 processName, mainElement, isDataAbility, uriStr, userId)) {
35 continue;
36 }
37 MainElementUtils::UpdateMainElement(hapModuleInfo.bundleName,
38 hapModuleInfo.name, mainElement, false, userId);
39 }
40 }
41 }
42
IsKeepAliveBundle(const AppExecFwk::BundleInfo & bundleInfo,int32_t userId,KeepAliveType & type)43 bool KeepAliveUtils::IsKeepAliveBundle(const AppExecFwk::BundleInfo &bundleInfo, int32_t userId, KeepAliveType &type)
44 {
45 if (KeepAliveProcessManager::GetInstance().IsKeepAliveBundle(bundleInfo.name, userId)) {
46 type = KeepAliveType::THIRD_PARTY;
47 return true;
48 }
49
50 bool keepAliveEnable = bundleInfo.isKeepAlive;
51 if (keepAliveEnable) {
52 AbilityRuntime::AmsResidentProcessRdb::GetInstance().GetResidentProcessEnable(bundleInfo.name, keepAliveEnable);
53 }
54 if (keepAliveEnable) {
55 type = KeepAliveType::RESIDENT_PROCESS;
56 }
57 return keepAliveEnable;
58 }
59 } // namespace AAFwk
60 } // namespace OHOS
61