1 /*
2 * Copyright (c) 2022 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 "app_control_manager.h"
17
18 #include "app_control_constants.h"
19 #include "app_control_manager_rdb.h"
20 #include "app_log_wrapper.h"
21 #include "appexecfwk_errors.h"
22 #include "application_info.h"
23 #include "bundle_constants.h"
24 #include "bundle_info.h"
25 #include "bundle_mgr_service.h"
26
27 namespace OHOS {
28 namespace AppExecFwk {
29 namespace {
30 const std::string APP_MARKET_CALLING = "app market";
31 }
32
AppControlManager()33 AppControlManager::AppControlManager()
34 {
35 appControlManagerDb_ = std::make_shared<AppControlManagerRdb>();
36 }
37
~AppControlManager()38 AppControlManager::~AppControlManager()
39 {
40 }
41
AddAppInstallControlRule(const std::string & callingName,const std::vector<std::string> & appIds,const std::string & controlRuleType,int32_t userId)42 ErrCode AppControlManager::AddAppInstallControlRule(const std::string &callingName,
43 const std::vector<std::string> &appIds, const std::string &controlRuleType, int32_t userId)
44 {
45 APP_LOGD("AddAppInstallControlRule");
46 return appControlManagerDb_->AddAppInstallControlRule(callingName, appIds, controlRuleType, userId);
47 }
48
DeleteAppInstallControlRule(const std::string & callingName,const std::string & controlRuleType,const std::vector<std::string> & appIds,int32_t userId)49 ErrCode AppControlManager::DeleteAppInstallControlRule(const std::string &callingName,
50 const std::string &controlRuleType, const std::vector<std::string> &appIds, int32_t userId)
51 {
52 APP_LOGD("DeleteAppInstallControlRule");
53 return appControlManagerDb_->DeleteAppInstallControlRule(callingName, controlRuleType, appIds, userId);
54 }
55
DeleteAppInstallControlRule(const std::string & callingName,const std::string & controlRuleType,int32_t userId)56 ErrCode AppControlManager::DeleteAppInstallControlRule(const std::string &callingName,
57 const std::string &controlRuleType, int32_t userId)
58 {
59 APP_LOGD("CleanInstallControlRule");
60 return appControlManagerDb_->DeleteAppInstallControlRule(callingName, controlRuleType, userId);
61 }
62
GetAppInstallControlRule(const std::string & callingName,const std::string & controlRuleType,int32_t userId,std::vector<std::string> & appIds)63 ErrCode AppControlManager::GetAppInstallControlRule(const std::string &callingName,
64 const std::string &controlRuleType, int32_t userId, std::vector<std::string> &appIds)
65 {
66 APP_LOGD("GetAppInstallControlRule");
67 return appControlManagerDb_->GetAppInstallControlRule(callingName, controlRuleType, userId, appIds);
68 }
69
AddAppRunningControlRule(const std::string & callingName,const std::vector<AppRunningControlRule> & controlRules,int32_t userId)70 ErrCode AppControlManager::AddAppRunningControlRule(const std::string &callingName,
71 const std::vector<AppRunningControlRule> &controlRules, int32_t userId)
72 {
73 APP_LOGD("AddAppRunningControlRule");
74 return appControlManagerDb_->AddAppRunningControlRule(callingName, controlRules, userId);
75 }
76
DeleteAppRunningControlRule(const std::string & callingName,const std::vector<AppRunningControlRule> & controlRules,int32_t userId)77 ErrCode AppControlManager::DeleteAppRunningControlRule(const std::string &callingName,
78 const std::vector<AppRunningControlRule> &controlRules, int32_t userId)
79 {
80 return appControlManagerDb_->DeleteAppRunningControlRule(callingName, controlRules, userId);
81 }
82
DeleteAppRunningControlRule(const std::string & callingName,int32_t userId)83 ErrCode AppControlManager::DeleteAppRunningControlRule(const std::string &callingName, int32_t userId)
84 {
85 return appControlManagerDb_->DeleteAppRunningControlRule(callingName, userId);
86 }
87
GetAppRunningControlRule(const std::string & callingName,int32_t userId,std::vector<std::string> & appIds)88 ErrCode AppControlManager::GetAppRunningControlRule(
89 const std::string &callingName, int32_t userId, std::vector<std::string> &appIds)
90 {
91 return appControlManagerDb_->GetAppRunningControlRule(callingName, userId, appIds);
92 }
93
SetDisposedStatus(const std::string & appId,const Want & want,int32_t userId)94 ErrCode AppControlManager::SetDisposedStatus(const std::string &appId, const Want& want, int32_t userId)
95 {
96 return appControlManagerDb_->SetDisposedStatus(
97 APP_MARKET_CALLING, appId, want, userId);
98 }
99
DeleteDisposedStatus(const std::string & appId,int32_t userId)100 ErrCode AppControlManager::DeleteDisposedStatus(const std::string &appId, int32_t userId)
101 {
102 return appControlManagerDb_->DeleteDisposedStatus(
103 APP_MARKET_CALLING, appId, userId);
104 }
105
GetDisposedStatus(const std::string & appId,Want & want,int32_t userId)106 ErrCode AppControlManager::GetDisposedStatus(const std::string &appId, Want& want, int32_t userId)
107 {
108 return appControlManagerDb_->GetDisposedStatus(
109 APP_MARKET_CALLING, appId, want, userId);
110 }
111
GetAppRunningControlRule(const std::string & bundleName,int32_t userId,AppRunningControlRuleResult & controlRuleResult)112 ErrCode AppControlManager::GetAppRunningControlRule(
113 const std::string &bundleName, int32_t userId, AppRunningControlRuleResult &controlRuleResult)
114 {
115 auto dataMgr = DelayedSingleton<BundleMgrService>::GetInstance()->GetDataMgr();
116 if (dataMgr == nullptr) {
117 APP_LOGE("DataMgr is nullptr");
118 return ERR_BUNDLE_MANAGER_INTERNAL_ERROR;
119 }
120 BundleInfo bundleInfo;
121 ErrCode ret = dataMgr->GetBundleInfoV9(bundleName,
122 static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_DISABLE), bundleInfo, userId);
123 if (ret != ERR_OK) {
124 APP_LOGE("DataMgr GetBundleInfoV9 failed");
125 return ret;
126 }
127 return appControlManagerDb_->GetAppRunningControlRule(bundleInfo.appId, userId, controlRuleResult);
128 }
129 }
130 }