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