• 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 "singleton.h"
25 #include "want.h"
26 
27 namespace OHOS {
28 namespace AppExecFwk {
29 class AppControlManager : public DelayedSingleton<AppControlManager> {
30 public:
31     using Want = OHOS::AAFwk::Want;
32 
33     AppControlManager();
34     ~AppControlManager();
35 
36     ErrCode AddAppInstallControlRule(const std::string &callingName,
37         const std::vector<std::string> &appIds, const std::string &controlRuleType, int32_t userId);
38 
39     ErrCode DeleteAppInstallControlRule(const std::string &callingName, const std::string &controlRuleType,
40         const std::vector<std::string> &appIds, int32_t userId);
41 
42     ErrCode DeleteAppInstallControlRule(const std::string &callingName,
43         const std::string &controlRuleType, int32_t userId);
44 
45     ErrCode GetAppInstallControlRule(const std::string &callingName,
46         const std::string &controlRuleType, int32_t userId, std::vector<std::string> &appIds);
47 
48     ErrCode AddAppRunningControlRule(const std::string &callingName,
49         const std::vector<AppRunningControlRule> &controlRules, int32_t userId);
50     ErrCode DeleteAppRunningControlRule(const std::string &callingName,
51         const std::vector<AppRunningControlRule> &controlRules, int32_t userId);
52     ErrCode DeleteAppRunningControlRule(const std::string &callingName, int32_t userId);
53     ErrCode GetAppRunningControlRule(const std::string &callingName, int32_t userId, std::vector<std::string> &appIds);
54     ErrCode GetAppRunningControlRule(
55         const std::string &bundleName, int32_t userId, AppRunningControlRuleResult &controlRule);
56 
57     ErrCode ConfirmAppJumpControlRule(const std::string &callerBundleName, const std::string &targetBundleName,
58         int32_t userId);
59     ErrCode AddAppJumpControlRule(const std::vector<AppJumpControlRule> &controlRules, int32_t userId);
60     ErrCode DeleteAppJumpControlRule(const std::vector<AppJumpControlRule> &controlRules, int32_t userId);
61     ErrCode DeleteRuleByCallerBundleName(const std::string &callerBundleName, int32_t userId);
62     ErrCode DeleteRuleByTargetBundleName(const std::string &targetBundleName, int32_t userId);
63     ErrCode GetAppJumpControlRule(const std::string &callerBundleName, const std::string &targetBundleName,
64         int32_t userId, AppJumpControlRule &controlRule);
65 
66     ErrCode SetDisposedStatus(const std::string &appId, const Want& want, int32_t userId);
67 
68     ErrCode DeleteDisposedStatus(const std::string &appId, int32_t userId);
69 
70     ErrCode GetDisposedStatus(const std::string &appId, Want& want, int32_t userId);
71 
72     bool IsAppInstallControlEnabled() const;
73 
74     void SetAppInstallControlStatus();
75 
76 private:
77     void KillRunningApp(const std::vector<AppRunningControlRule> &rules, int32_t userId) const;
78 
79     bool isAppInstallControlEnabled_ = false;
80     std::shared_ptr<IAppControlManagerDb> appControlManagerDb_;
81     std::shared_ptr<IAppJumpInterceptorlManagerDb> appJumpInterceptorManagerDb_;
82     std::unordered_map<std::string, AppRunningControlRuleResult> appRunningControlRuleResult_;
83     std::mutex appRunningControlMutex_;
84 };
85 } // AppExecFwk
86 } // OHOS
87 #endif // FOUNDATION_BUNDLE_FRAMEWORK_SERVICE_INCLUDE_APP_CONTROL_MANAGER_H
88