1 /* 2 * Copyright (c) 2021-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_APPEXECFWK_STANDARD_TOOLS_TEST_MOCK_MOCK_BUNDLE_MGR_HOST_H 17 #define FOUNDATION_APPEXECFWK_STANDARD_TOOLS_TEST_MOCK_MOCK_BUNDLE_MGR_HOST_H 18 19 #include "gmock/gmock.h" 20 21 #include "app_log_wrapper.h" 22 #include "bundle_mgr_host.h" 23 24 namespace OHOS { 25 namespace AppExecFwk { 26 class MockBundleMgrHost : public BundleMgrHost { 27 public: 28 MOCK_METHOD4(GetApplicationInfo, 29 bool(const std::string &appName, const ApplicationFlag flag, const int userId, ApplicationInfo &appInfo)); 30 MOCK_METHOD3(GetApplicationInfos, 31 bool(const ApplicationFlag flag, const int userId, std::vector<ApplicationInfo> &appInfos)); 32 MOCK_METHOD4(GetBundleInfo, 33 bool(const std::string &bundleName, const BundleFlag flag, BundleInfo &bundleInfo, int32_t userId)); 34 MOCK_METHOD4(GetBundleInfo, 35 bool(const std::string &bundleName, int32_t flag, BundleInfo &bundleInfo, int32_t userId)); 36 MOCK_METHOD3(GetBundleInfos, 37 bool(const BundleFlag flag, std::vector<BundleInfo> &bundleInfos, int32_t userId)); 38 MOCK_METHOD3(GetBundleInfos, 39 bool(int32_t flag, std::vector<BundleInfo> &bundleInfos, int32_t userId)); 40 MOCK_METHOD2(GetUidByBundleName, int(const std::string &bundleName, const int userId)); 41 MOCK_METHOD2(GetAppIdByBundleName, std::string(const std::string &bundleName, const int userId)); 42 MOCK_METHOD2(GetBundleNameForUid, bool(const int uid, std::string &bundleName)); 43 MOCK_METHOD2(GetBundleGids, bool(const std::string &bundleName, std::vector<int> &gids)); 44 MOCK_METHOD1(GetAppType, std::string(const std::string &bundleName)); 45 MOCK_METHOD1(CheckIsSystemAppByUid, bool(const int uid)); 46 MOCK_METHOD2(GetBundleInfosByMetaData, bool(const std::string &metaData, std::vector<BundleInfo> &bundleInfos)); 47 MOCK_METHOD2(QueryAbilityInfo, bool(const Want &want, AbilityInfo &abilityInfo)); 48 MOCK_METHOD2(QueryAbilityInfos, bool(const Want &want, std::vector<AbilityInfo> &abilityInfos)); 49 MOCK_METHOD2(QueryAbilityInfosForClone, bool(const Want &want, std::vector<AbilityInfo> &abilityInfos)); 50 MOCK_METHOD2(QueryAbilityInfoByUri, bool(const std::string &abilityUri, AbilityInfo &abilityInfo)); 51 MOCK_METHOD1(QueryKeepAliveBundleInfos, bool(std::vector<BundleInfo> &bundleInfos)); 52 MOCK_METHOD2(GetAbilityLabel, std::string(const std::string &bundleName, const std::string &className)); 53 MOCK_METHOD3( 54 GetBundleArchiveInfo, bool(const std::string &hapFilePath, const BundleFlag flag, BundleInfo &bundleInfo)); 55 MOCK_METHOD2(GetHapModuleInfo, bool(const AbilityInfo &abilityInfo, HapModuleInfo &hapModuleInfo)); 56 MOCK_METHOD2(GetLaunchWantForBundle, bool(const std::string &bundleName, Want &want)); 57 MOCK_METHOD2(CheckPublicKeys, int(const std::string &firstBundleName, const std::string &secondBundleName)); 58 MOCK_METHOD2(CheckPermission, int(const std::string &bundleName, const std::string &permission)); 59 MOCK_METHOD2(GetPermissionDef, bool(const std::string &permissionName, PermissionDef &permissionDef)); 60 MOCK_METHOD1(GetAllPermissionGroupDefs, bool(std::vector<PermissionDef> &permissionDefs)); 61 MOCK_METHOD2(GetAppsGrantedPermissions, 62 bool(const std::vector<std::string> &permissions, std::vector<std::string> &appNames)); 63 MOCK_METHOD1(HasSystemCapability, bool(const std::string &capName)); 64 MOCK_METHOD1(GetSystemAvailableCapabilities, bool(std::vector<std::string> &systemCaps)); 65 MOCK_METHOD0(IsSafeMode, bool()); 66 67 bool CleanBundleCacheFiles(const std::string &bundleName, const sptr<ICleanCacheCallback> &cleanCacheCallback, 68 int32_t userId = Constants::UNSPECIFIED_USERID) override; 69 bool CleanBundleDataFiles(const std::string &bundleName, const int userId = 0); 70 71 MOCK_METHOD1(RegisterBundleStatusCallback, bool(const sptr<IBundleStatusCallback> &bundleStatusCallback)); 72 MOCK_METHOD1(ClearBundleStatusCallback, bool(const sptr<IBundleStatusCallback> &bundleStatusCallback)); 73 MOCK_METHOD0(UnregisterBundleStatusCallback, bool()); 74 75 bool DumpInfos( 76 const DumpFlag flag, const std::string &bundleName, int32_t userId, std::string &result); 77 78 MOCK_METHOD1(IsApplicationEnabled, bool(const std::string &bundleName)); 79 80 bool SetApplicationEnabled(const std::string &bundleName, bool isEnable, 81 int32_t userId = Constants::UNSPECIFIED_USERID) override; 82 bool SetAbilityEnabled(const AbilityInfo &abilityInfo, bool isEnable, 83 int32_t userId = Constants::UNSPECIFIED_USERID) override; 84 85 MOCK_METHOD0(GetBundleInstaller, sptr<IBundleInstaller>()); 86 MOCK_METHOD0(GetBundleUserMgr, sptr<IBundleUserMgr>()); 87 MOCK_METHOD3(CanRequestPermission, 88 bool(const std::string &bundleName, const std::string &permissionName, const int userId)); 89 MOCK_METHOD3(RequestPermissionFromUser, 90 bool(const std::string &bundleName, const std::string &permission, const int userId)); 91 MOCK_METHOD2(GetNameForUid, bool(const int uid, std::string &name)); 92 MOCK_METHOD2(GetBundlesForUid, bool(const int uid, std::vector<std::string> &)); 93 MOCK_METHOD1(IsAbilityEnabled, bool(const AbilityInfo &)); 94 MOCK_METHOD2(GetAbilityIcon, std::string(const std::string &bundleName, const std::string &className)); 95 MOCK_METHOD1(RegisterAllPermissionsChanged, bool(const sptr<OnPermissionChangedCallback> &callback)); 96 MOCK_METHOD2(RegisterPermissionsChanged, 97 bool(const std::vector<int> &uids, const sptr<OnPermissionChangedCallback> &callback)); 98 MOCK_METHOD1(UnregisterPermissionsChanged, bool(const sptr<OnPermissionChangedCallback> &callback)); 99 MOCK_METHOD1(GetAllFormsInfo, bool(std::vector<FormInfo> &formInfos)); 100 MOCK_METHOD2(GetFormsInfoByApp, bool(const std::string &bundleName, std::vector<FormInfo> &formInfos)); 101 MOCK_METHOD3(GetFormsInfoByModule, 102 bool(const std::string &bundleName, const std::string &moduleName, std::vector<FormInfo> &formInfos)); 103 MOCK_METHOD2(GetShortcutInfos, bool(const std::string &bundleName, std::vector<ShortcutInfo> &shortcutInfos)); 104 MOCK_METHOD2(GetAllCommonEventInfo, 105 bool(const std::string &eventKey, std::vector<CommonEventInfo> &commonEventInfos)); 106 MOCK_METHOD2(GetModuleUsageRecords, 107 bool(const int32_t number, std::vector<ModuleUsageRecord> &moduleUsageRecords)); 108 MOCK_METHOD4(NotifyAbilityLifeStatus, 109 bool(const std::string &bundleName, const std::string &abilityName, const int64_t launchTime, const int uid)); 110 MOCK_METHOD1(CheckBundleNameInAllowList, bool(const std::string &bundleName)); 111 MOCK_METHOD3(GetBundleGidsByUid, bool(const std::string &bundleName, const int &uid, std::vector<int> &gids)); 112 MOCK_METHOD2(RemoveClonedBundle, bool(const std::string &bundleName, const int32_t uid)); 113 MOCK_METHOD1(BundleClone, bool(const std::string &bundleName)); 114 MOCK_METHOD2(QueryAbilityInfosByUri, bool(const std::string &abilityUri, std::vector<AbilityInfo> &abilityInfos)); 115 MOCK_METHOD3(CheckPermissionByUid, 116 int(const std::string &bundleName, const std::string &permission, const int userId)); 117 MOCK_METHOD4(GetDistributedBundleInfo, bool(const std::string &networkId, int32_t userId, 118 const std::string &bundleName, DistributedBundleInfo &distributedBundleInfo)); 119 }; 120 } // namespace AppExecFwk 121 } // namespace OHOS 122 123 #endif // FOUNDATION_APPEXECFWK_STANDARD_TOOLS_TEST_MOCK_MOCK_BUNDLE_MGR_HOST_H 124