• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef FOUNDATION_BUNDLE_FRAMEWORK_SERVICE_INCLUDE_APP_CONTROL_MANAGER_H
17 #define FOUNDATION_BUNDLE_FRAMEWORK_SERVICE_INCLUDE_APP_CONTROL_MANAGER_H
18 
19 #include <mutex>
20 #include <unordered_map>
21 
22 #include "app_control_manager_db_interface.h"
23 #include "app_jump_interceptor_manager_db_interface.h"
24 #include "bundle_common_event_mgr.h"
25 #include "singleton.h"
26 #include "want.h"
27 
28 namespace OHOS {
29 namespace AppExecFwk {
30 class AppControlManager : public DelayedSingleton<AppControlManager> {
31 public:
32     using Want = OHOS::AAFwk::Want;
33 
34     AppControlManager();
35     ~AppControlManager();
36 
37     ErrCode AddAppInstallControlRule(const std::string &callingName,
38         const std::vector<std::string> &appIds, const std::string &controlRuleType, int32_t userId);
39 
40     ErrCode DeleteAppInstallControlRule(const std::string &callingName, const std::string &controlRuleType,
41         const std::vector<std::string> &appIds, int32_t userId);
42 
43     ErrCode DeleteAppInstallControlRule(const std::string &callingName,
44         const std::string &controlRuleType, int32_t userId);
45 
46     ErrCode GetAppInstallControlRule(const std::string &callingName,
47         const std::string &controlRuleType, int32_t userId, std::vector<std::string> &appIds);
48 
49     ErrCode AddAppRunningControlRule(const std::string &callingName,
50         const std::vector<AppRunningControlRule> &controlRules, int32_t userId);
51     ErrCode DeleteAppRunningControlRule(const std::string &callingName,
52         const std::vector<AppRunningControlRule> &controlRules, int32_t userId);
53     ErrCode DeleteAppRunningControlRule(const std::string &callingName, int32_t userId);
54     ErrCode GetAppRunningControlRule(const std::string &callingName, int32_t userId, std::vector<std::string> &appIds);
55     ErrCode GetAppRunningControlRule(
56         const std::string &bundleName, int32_t userId, AppRunningControlRuleResult &controlRule);
57 
58     ErrCode ConfirmAppJumpControlRule(const std::string &callerBundleName, const std::string &targetBundleName,
59         int32_t userId);
60     ErrCode AddAppJumpControlRule(const std::vector<AppJumpControlRule> &controlRules, int32_t userId);
61     ErrCode DeleteAppJumpControlRule(const std::vector<AppJumpControlRule> &controlRules, int32_t userId);
62     ErrCode DeleteRuleByCallerBundleName(const std::string &callerBundleName, int32_t userId);
63     ErrCode DeleteRuleByTargetBundleName(const std::string &targetBundleName, int32_t userId);
64     ErrCode GetAppJumpControlRule(const std::string &callerBundleName, const std::string &targetBundleName,
65         int32_t userId, AppJumpControlRule &controlRule);
66 
67     ErrCode SetDisposedStatus(const std::string &appId, const Want& want, int32_t userId);
68 
69     ErrCode DeleteDisposedStatus(const std::string &appId, int32_t userId);
70 
71     ErrCode GetDisposedStatus(const std::string &appId, Want& want, int32_t userId);
72 
73     bool IsAppInstallControlEnabled() const;
74 
75     void SetAppInstallControlStatus();
76 
77     ErrCode SetDisposedRule(const std::string &callerName,
78         const std::string &appId, const DisposedRule &DisposedRule, int32_t userId);
79 
80     ErrCode GetDisposedRule(const std::string &callerName,
81         const std::string &appId, DisposedRule &DisposedRule, int32_t userId);
82 
83     ErrCode DeleteDisposedRule(const std::string &callerName, const std::string &appId, int32_t userId);
84 
85     ErrCode GetAbilityRunningControlRule(
86         const std::string &bundleName, int32_t userId, std::vector<DisposedRule>& disposedRules);
87 
88     ErrCode DeleteAllDisposedRuleByBundle(const std::string &appId, int32_t userId);
89 
90 private:
91     void KillRunningApp(const std::vector<AppRunningControlRule> &rules, int32_t userId) const;
92 
93     bool isAppInstallControlEnabled_ = false;
94     std::shared_ptr<IAppControlManagerDb> appControlManagerDb_;
95     std::shared_ptr<IAppJumpInterceptorlManagerDb> appJumpInterceptorManagerDb_;
96     std::unordered_map<std::string, AppRunningControlRuleResult> appRunningControlRuleResult_;
97     std::shared_ptr<BundleCommonEventMgr> commonEventMgr_;
98     std::mutex appRunningControlMutex_;
99     std::unordered_map<std::string, std::vector<DisposedRule>> abilityRunningControlRuleCache_;
100     std::mutex abilityRunningControlRuleMutex_;
101 };
102 } // AppExecFwk
103 } // OHOS
104 #endif // FOUNDATION_BUNDLE_FRAMEWORK_SERVICE_INCLUDE_APP_CONTROL_MANAGER_H
105