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 
16 #include "bundle_overlay_data_manager.h"
17 #include "bundle_overlay_manager.h"
18 
19 namespace OHOS {
20 namespace AppExecFwk {
IsExistedNonOverlayHap(const std::string & bundleName)21 bool BundleOverlayManager::IsExistedNonOverlayHap(const std::string &bundleName)
22 {
23     APP_LOGD("start");
24     if (bundleName.empty()) {
25         APP_LOGE("invalid bundleName");
26         return false;
27     }
28     return OverlayDataMgr::GetInstance()->IsExistedNonOverlayHap(bundleName);
29 }
30 
GetInnerBundleInfo(const std::string & bundleName,InnerBundleInfo & info)31 bool BundleOverlayManager::GetInnerBundleInfo(const std::string &bundleName, InnerBundleInfo &info)
32 {
33     APP_LOGD("start");
34     if (bundleName.empty()) {
35         APP_LOGE("invalid bundleName");
36         return false;
37     }
38 
39     return OverlayDataMgr::GetInstance()->QueryOverlayInnerBundleInfo(bundleName, info);
40 }
41 
GetAllOverlayModuleInfo(const std::string & bundleName,std::vector<OverlayModuleInfo> & overlayModuleInfo,int32_t userId)42 ErrCode BundleOverlayManager::GetAllOverlayModuleInfo(const std::string &bundleName,
43     std::vector<OverlayModuleInfo> &overlayModuleInfo, int32_t userId)
44 {
45     APP_LOGD("start");
46     if (bundleName.empty() || userId == Constants::INVALID_USERID) {
47         APP_LOGE("invalid bundleName or userId");
48         return ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR;
49     }
50 
51     return OverlayDataMgr::GetInstance()->GetAllOverlayModuleInfo(bundleName, overlayModuleInfo, userId);
52 }
53 
GetOverlayModuleInfo(const std::string & bundleName,const std::string & moduleName,OverlayModuleInfo & overlayModuleInfo,int32_t userId)54 ErrCode BundleOverlayManager::GetOverlayModuleInfo(const std::string &bundleName, const std::string &moduleName,
55     OverlayModuleInfo &overlayModuleInfo, int32_t userId)
56 {
57     APP_LOGD("start");
58     if (bundleName.empty() || moduleName.empty() || userId == Constants::INVALID_USERID) {
59         APP_LOGE("invalid bundleName、moduleName or userId");
60         return ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR;
61     }
62 
63     return OverlayDataMgr::GetInstance()->GetOverlayModuleInfo(bundleName, moduleName, overlayModuleInfo, userId);
64 }
65 
GetOverlayBundleInfoForTarget(const std::string & targetBundleName,std::vector<OverlayBundleInfo> & overlayBundleInfo,int32_t userId)66 ErrCode BundleOverlayManager::GetOverlayBundleInfoForTarget(const std::string &targetBundleName,
67     std::vector<OverlayBundleInfo> &overlayBundleInfo, int32_t userId)
68 {
69     APP_LOGD("start");
70     if (targetBundleName.empty() || userId == Constants::INVALID_USERID) {
71         APP_LOGE("invalid bundleName or userId");
72         return ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR;
73     }
74 
75     return OverlayDataMgr::GetInstance()->GetOverlayBundleInfoForTarget(targetBundleName, overlayBundleInfo, userId);
76 }
77 
GetOverlayModuleInfoForTarget(const std::string & targetBundleName,const std::string & targetModuleName,std::vector<OverlayModuleInfo> & overlayModuleInfo,int32_t userId)78 ErrCode BundleOverlayManager::GetOverlayModuleInfoForTarget(const std::string &targetBundleName,
79     const std::string &targetModuleName, std::vector<OverlayModuleInfo> &overlayModuleInfo, int32_t userId)
80 {
81     APP_LOGD("start");
82     if (targetBundleName.empty() || userId == Constants::INVALID_USERID) {
83         APP_LOGE("invalid bundleName or userId");
84         return ERR_BUNDLEMANAGER_OVERLAY_QUERY_FAILED_PARAM_ERROR;
85     }
86 
87     return OverlayDataMgr::GetInstance()->GetOverlayModuleInfoForTarget(targetBundleName, targetModuleName,
88         overlayModuleInfo, userId);
89 }
90 
SetOverlayEnabled(const std::string & bundleName,const std::string & moduleName,bool isEnabled,int32_t userId)91 ErrCode BundleOverlayManager::SetOverlayEnabled(const std::string &bundleName, const std::string &moduleName,
92     bool isEnabled, int32_t userId)
93 {
94     APP_LOGD("start");
95     if (bundleName.empty() || moduleName.empty() || userId == Constants::INVALID_USERID) {
96         APP_LOGE("invalid bundleName、moduleName or userId");
97         return ERR_BUNDLEMANAGER_OVERLAY_SET_OVERLAY_PARAM_ERROR;
98     }
99     return OverlayDataMgr::GetInstance()->SetOverlayEnabled(bundleName, moduleName, isEnabled, userId);
100 }
101 } // AppExecFwk
102 } // OHOS