1 /* 2 * Copyright (c) 2022-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 #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, const std::string &appId, 78 const DisposedRule &DisposedRule, int32_t appIndex, int32_t userId); 79 80 ErrCode GetDisposedRule(const std::string &callerName, const std::string &appId, 81 DisposedRule &DisposedRule, int32_t appIndex, int32_t userId); 82 83 ErrCode DeleteDisposedRule(const std::string &callerName, const std::string &appId, 84 int32_t appIndex, int32_t userId); 85 86 ErrCode GetAbilityRunningControlRule(const std::string &bundleName, int32_t appIndex, int32_t userId, 87 std::vector<DisposedRule>& disposedRules); 88 89 ErrCode DeleteAllDisposedRuleByBundle(const InnerBundleInfo &bundleInfo, int32_t appIndex, int32_t userId); 90 91 void SetDisposedRuleOnlyForBms(const std::string &appId); 92 93 void DeleteDisposedRuleOnlyForBms(const std::string &appId); 94 95 ErrCode SetUninstallDisposedRule(const std::string &callerName, const std::string &appIdentifier, 96 const UninstallDisposedRule& rule, int32_t appIndex, int32_t userId); 97 98 ErrCode GetUninstallDisposedRule(const std::string &appIdentifier, int32_t appIndex, 99 int32_t userId, UninstallDisposedRule& rule); 100 101 ErrCode DeleteUninstallDisposedRule(const std::string &callerName, const std::string &appIdentifier, 102 int32_t appIndex, int32_t userId); 103 104 private: 105 void KillRunningApp(const std::vector<AppRunningControlRule> &rules, int32_t userId) const; 106 void DeleteAppRunningRuleCache(std::string &key); 107 bool GetAbilityRunningRuleCache(const std::string &key, std::vector<DisposedRule> &disposedRules); 108 void SetAbilityRunningRuleCache(const std::string &key, const std::vector<DisposedRule> &disposedRules); 109 void DeleteAbilityRunningRuleCache(const std::vector<std::string> &keyList); 110 bool GetDisposedRuleOnlyForBms(const std::string &appId, std::vector<DisposedRule> &disposedRules); 111 void DeleteAbilityRunningRuleBmsCache(const std::string &appId); 112 bool CheckCanDispose(const std::string &appId, int32_t userId); 113 void PrintDisposedRuleInfo(const std::vector<DisposedRule> &disposedRules, const std::string &key); 114 std::string GenerateAppRunningRuleCacheKey(const std::string &appId, int32_t userId, int32_t appIndex); 115 116 bool isAppInstallControlEnabled_ = false; 117 std::mutex appRunningControlMutex_; 118 std::mutex abilityRunningControlRuleMutex_; 119 std::shared_ptr<IAppControlManagerDb> appControlManagerDb_; 120 std::shared_ptr<IAppJumpInterceptorlManagerDb> appJumpInterceptorManagerDb_; 121 std::shared_ptr<BundleCommonEventMgr> commonEventMgr_; 122 std::unordered_map<std::string, AppRunningControlRuleResult> appRunningControlRuleResult_; 123 std::unordered_map<std::string, std::vector<DisposedRule>> abilityRunningControlRuleCache_; 124 std::unordered_map<std::string, DisposedRule> abilityRunningControlRuleCacheForBms_; 125 std::vector<std::string> noControllingList_; 126 }; 127 } // AppExecFwk 128 } // OHOS 129 #endif // FOUNDATION_BUNDLE_FRAMEWORK_SERVICE_INCLUDE_APP_CONTROL_MANAGER_H 130