1 /* 2 * Copyright (c) 2022-2025 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_HOST_IMPL_H 17 #define FOUNDATION_BUNDLE_FRAMEWORK_SERVICE_INCLUDE_APP_CONTROL_MANAGER_HOST_IMPL_H 18 19 #include "app_control_host.h" 20 #include "app_control_manager.h" 21 #include "bundle_data_mgr.h" 22 #include "event_report.h" 23 24 namespace OHOS { 25 namespace AppExecFwk { 26 class AppControlManagerHostImpl : public OHOS::AppExecFwk::AppControlHost { 27 public: 28 AppControlManagerHostImpl(); 29 virtual ~AppControlManagerHostImpl(); 30 31 virtual ErrCode AddAppInstallControlRule(const std::vector<std::string> &appIds, 32 const AppInstallControlRuleType controlRuleType, int32_t userId) override; 33 34 virtual ErrCode DeleteAppInstallControlRule(const AppInstallControlRuleType controlRuleType, 35 const std::vector<std::string> &appIds, int32_t userId) override; 36 37 virtual ErrCode DeleteAppInstallControlRule( 38 const AppInstallControlRuleType controlRuleType, int32_t userId) override; 39 40 virtual ErrCode GetAppInstallControlRule(const AppInstallControlRuleType controlRuleType, int32_t userId, 41 std::vector<std::string> &appIds) override; 42 43 // for app running control rule 44 virtual ErrCode AddAppRunningControlRule( 45 const std::vector<AppRunningControlRule> &controlRules, int32_t userId) override; 46 virtual ErrCode DeleteAppRunningControlRule( 47 const std::vector<AppRunningControlRule> &controlRules, int32_t userId) override; 48 virtual ErrCode DeleteAppRunningControlRule(int32_t userId) override; 49 virtual ErrCode GetAppRunningControlRule(int32_t userId, std::vector<std::string> &appIds) override; 50 virtual ErrCode GetAppRunningControlRule( 51 const std::string &bundleName, int32_t userId, AppRunningControlRuleResult &controlRule) override; 52 53 // for app jump control rule 54 virtual ErrCode ConfirmAppJumpControlRule(const std::string &callerBundleName, const std::string &targetBundleName, 55 int32_t userId) override; 56 virtual ErrCode AddAppJumpControlRule(const std::vector<AppJumpControlRule> &controlRules, int32_t userId) override; 57 virtual ErrCode DeleteAppJumpControlRule(const std::vector<AppJumpControlRule> &controlRules, 58 int32_t userId) override; 59 virtual ErrCode DeleteRuleByCallerBundleName(const std::string &callerBundleName, int32_t userId) override; 60 virtual ErrCode DeleteRuleByTargetBundleName(const std::string &targetBundleName, int32_t userId) override; 61 virtual ErrCode GetAppJumpControlRule(const std::string &callerBundleName, const std::string &targetBundleName, 62 int32_t userId, AppJumpControlRule &controlRule) override; 63 64 virtual ErrCode SetDisposedStatus( 65 const std::string &appId, const Want &want, int32_t userId) override; 66 67 virtual ErrCode DeleteDisposedStatus( 68 const std::string &appId, int32_t userId) override; 69 70 virtual ErrCode GetDisposedStatus( 71 const std::string &appId, Want &want, int32_t userId) override; 72 73 virtual ErrCode SetDisposedRule( 74 const std::string &appId, DisposedRule &DisposedRule, int32_t userId) override; 75 76 virtual ErrCode SetDisposedRules( 77 std::vector<DisposedRuleConfiguration> &disposedRuleConfigurations, int32_t userId) override; 78 79 virtual ErrCode GetDisposedRule( 80 const std::string &appId, DisposedRule &DisposedRule, int32_t userId) override; 81 82 virtual ErrCode GetAbilityRunningControlRule(const std::string &bundleName, int32_t userId, 83 std::vector<DisposedRule>& disposedRules, int32_t appIndex = Constants::MAIN_APP_INDEX) override; 84 85 virtual ErrCode SetDisposedRuleForCloneApp( 86 const std::string &appId, DisposedRule &DisposedRule, int32_t appIndex, int32_t userId) override; 87 88 virtual ErrCode GetDisposedRuleForCloneApp( 89 const std::string &appId, DisposedRule &DisposedRule, int32_t appIndex, int32_t userId) override; 90 91 virtual ErrCode DeleteDisposedRuleForCloneApp( 92 const std::string &appId, int32_t appIndex, int32_t userId) override; 93 94 virtual ErrCode GetUninstallDisposedRule(const std::string &appIdentifier, int32_t appIndex, 95 int32_t userId, UninstallDisposedRule &rule) override; 96 97 virtual ErrCode SetUninstallDisposedRule(const std::string &appIdentifier, const UninstallDisposedRule &rule, 98 int32_t appIndex, int32_t userId) override; 99 100 virtual ErrCode DeleteUninstallDisposedRule(const std::string &appIdentifier, int32_t appIndex, 101 int32_t userId) override; 102 103 private: 104 int32_t GetCallingUserId(); 105 std::string GetCallingName(); 106 std::string GetControlRuleType(const AppInstallControlRuleType controlRuleType); 107 void UpdateAppControlledInfo(int32_t userId, const std::vector<std::string> &modifyAppIds) const; 108 void GetCallerByUid(const int32_t uid, std::string &callerName); 109 void SendAppControlEvent(ControlActionType actionType, ControlOperationType operationType, 110 const std::string &callingName, int32_t userId, int32_t appIndex, const std::vector<std::string> &appIds, 111 const std::string &rule); 112 113 std::shared_ptr<AppControlManager> appControlManager_ = nullptr; 114 std::shared_ptr<BundleDataMgr> dataMgr_ = nullptr; 115 std::unordered_map<int32_t, std::string> callingNameMap_; 116 std::unordered_map<AppInstallControlRuleType, std::string> ruleTypeMap_; 117 }; 118 } 119 } 120 #endif // FOUNDATION_BUNDLE_FRAMEWORK_SERVICE_INCLUDE_APP_CONTROL_MANAGER_HOST_IMPL_H 121