1 /* 2 * Copyright (C) 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 #ifndef OHOS_DISTRIBUTED_BUNDLE_MANANGER_INTERNAL_MOCK_H 16 #define OHOS_DISTRIBUTED_BUNDLE_MANANGER_INTERNAL_MOCK_H 17 18 #include <gmock/gmock.h> 19 20 #include "bundle/bundle_manager_internal.h" 21 22 namespace OHOS { 23 namespace DistributedSchedule { 24 class IBundleManagerInternal { 25 public: 26 virtual ~IBundleManagerInternal() = default; 27 virtual bool GetCallerAppIdFromBms(int32_t callingUid, std::string& appId) = 0; 28 virtual bool GetCallerAppIdFromBms(const std::string& bundleName, std::string& appId); 29 virtual bool GetSpecifyBundleNameFromBms(int32_t callingUid, std::string& bundleName) = 0; 30 virtual bool GetBundleNameListFromBms(int32_t callingUid, std::vector<std::string>& bundleNameList) = 0; 31 virtual bool GetBundleNameListFromBms(int32_t callingUid, std::vector<std::u16string>& u16BundleNameList) = 0; 32 virtual bool QueryAbilityInfo(const AAFwk::Want& want, AppExecFwk::AbilityInfo& abilityInfo) = 0; 33 virtual bool QueryExtensionAbilityInfo(const AAFwk::Want& want, 34 AppExecFwk::ExtensionAbilityInfo& extensionInfo) = 0; 35 virtual void InitAbilityInfoFromExtension(const AppExecFwk::ExtensionAbilityInfo &extensionAbilityInfo, 36 AppExecFwk::AbilityInfo &abilityInfo) = 0; 37 virtual bool IsSameAppId(const std::string& callerAppId, const std::string& targetBundleName) = 0; 38 virtual bool IsSameDeveloperId(const std::string &bundleNameInCurrentSide, 39 const std::string &developerId4OtherSide) = 0; 40 virtual int32_t GetLocalBundleInfo(const std::string& bundleName, AppExecFwk::BundleInfo &localBundleInfo) = 0; 41 virtual int32_t GetLocalBundleInfoV9(const std::string& bundleName, AppExecFwk::BundleInfo &bundleInfo) = 0; 42 virtual int32_t GetLocalAbilityInfo(const std::string& bundleName, 43 const std::string& moduleName, const std::string& abilityName, AppExecFwk::AbilityInfo &abilityInfo) = 0; 44 virtual bool GetContinueBundle4Src(const std::string& srcBundleName, 45 std::vector<std::string>& bundleNameList) = 0; 46 virtual bool GetAppProvisionInfo4CurrentUser(const std::string& bundleName, 47 AppExecFwk::AppProvisionInfo& appProvisionInfo) = 0; 48 virtual int32_t CheckRemoteBundleInfoForContinuation(const std::string& dstDeviceId, 49 const std::string& bundleName, AppExecFwk::DistributedBundleInfo& remoteBundleInfo) = 0; 50 virtual sptr<AppExecFwk::IBundleMgr> GetBundleManager() = 0; 51 virtual sptr<AppExecFwk::IDistributedBms> GetDistributedBundleManager() = 0; 52 virtual int32_t GetUidFromBms(const std::string& bundleName) = 0; 53 virtual bool CheckIfRemoteCanInstall(const AAFwk::Want& want, int32_t missionId) = 0; 54 virtual int32_t GetBundleNameId(const std::string& bundleName, uint16_t& bundleNameId) = 0; 55 virtual std::string GetContinueType(const std::string &networkId, 56 std::string &bundleName, uint8_t continueTypeId) = 0; 57 virtual int32_t GetContinueTypeId(const std::string &bundleName, 58 const std::string &abilityName, uint8_t &continueTypeId) = 0; 59 virtual std::string GetAbilityName(const std::string &, std::string &, std::string &) = 0; 60 virtual int32_t GetBundleNameById(const std::string& networkId, 61 const uint16_t& bundleNameId, std::string& bundleName) = 0; 62 virtual int32_t GetApplicationInfoFromBms(const std::string& bundleName, const AppExecFwk::BundleFlag flag, 63 const int32_t userId, AppExecFwk::ApplicationInfo &appInfo) = 0; 64 virtual ErrCode QueryOsAccount(int32_t& activeAccountId) = 0; 65 public: 66 static inline std::shared_ptr<IBundleManagerInternal> bundleMgrMock = nullptr; 67 }; 68 69 class BundleManagerInternalMock : public IBundleManagerInternal { 70 public: 71 MOCK_METHOD2(GetCallerAppIdFromBms, bool(int32_t callingUid, std::string& appId)); 72 MOCK_METHOD2(GetCallerAppIdFromBms, bool(const std::string& bundleName, std::string& appId)); 73 MOCK_METHOD2(GetSpecifyBundleNameFromBms, bool(int32_t callingUid, std::string& bundleName)); 74 MOCK_METHOD2(GetBundleNameListFromBms, bool(int32_t callingUid, std::vector<std::string>& bundleNameList)); 75 MOCK_METHOD2(GetBundleNameListFromBms, bool(int32_t callingUid, std::vector<std::u16string>& u16BundleNameList)); 76 MOCK_METHOD2(QueryAbilityInfo, bool(const AAFwk::Want& want, AppExecFwk::AbilityInfo& abilityInfo)); 77 MOCK_METHOD2(QueryExtensionAbilityInfo, bool(const AAFwk::Want& want, 78 AppExecFwk::ExtensionAbilityInfo& extensionInfo)); 79 MOCK_METHOD2(InitAbilityInfoFromExtension, void(const AppExecFwk::ExtensionAbilityInfo &extensionAbilityInfo, 80 AppExecFwk::AbilityInfo &abilityInfo)); 81 MOCK_METHOD2(IsSameAppId, bool(const std::string& callerAppId, const std::string& targetBundleName)); 82 MOCK_METHOD2(IsSameDeveloperId, bool(const std::string &bundleNameInCurrentSide, 83 const std::string &developerId4OtherSide)); 84 MOCK_METHOD2(GetLocalBundleInfo, int32_t(const std::string& bundleName, AppExecFwk::BundleInfo &localBundleInfo)); 85 MOCK_METHOD2(GetLocalBundleInfoV9, int32_t(const std::string& bundleName, AppExecFwk::BundleInfo &bundleInfo)); 86 MOCK_METHOD4(GetLocalAbilityInfo, int32_t(const std::string& bundleName, 87 const std::string& moduleName, const std::string& abilityName, AppExecFwk::AbilityInfo &abilityInfo)); 88 MOCK_METHOD2(GetContinueBundle4Src, bool(const std::string& srcBundleName, 89 std::vector<std::string>& bundleNameList)); 90 MOCK_METHOD2(GetAppProvisionInfo4CurrentUser, bool(const std::string& bundleName, 91 AppExecFwk::AppProvisionInfo& appProvisionInfo)); 92 MOCK_METHOD3(CheckRemoteBundleInfoForContinuation, int32_t(const std::string& dstDeviceId, 93 const std::string& bundleName, AppExecFwk::DistributedBundleInfo& remoteBundleInfo)); 94 MOCK_METHOD0(GetBundleManager, sptr<AppExecFwk::IBundleMgr>()); 95 MOCK_METHOD0(GetDistributedBundleManager, sptr<AppExecFwk::IDistributedBms>()); 96 MOCK_METHOD1(GetUidFromBms, int32_t(const std::string& bundleName)); 97 MOCK_METHOD2(CheckIfRemoteCanInstall, bool(const AAFwk::Want& want, int32_t missionId)); 98 MOCK_METHOD2(GetBundleNameId, int32_t(const std::string& bundleName, uint16_t& bundleNameId)); 99 MOCK_METHOD3(GetContinueType, std::string(const std::string &networkId, 100 std::string &bundleName, uint8_t continueTypeId)); 101 MOCK_METHOD3(GetContinueTypeId, int32_t(const std::string &bundleName, 102 const std::string &abilityName, uint8_t &continueTypeId)); 103 MOCK_METHOD3(GetAbilityName, std::string(const std::string &networkId, std::string &bundleName, 104 std::string &continueType)); 105 MOCK_METHOD3(GetBundleNameById, int32_t(const std::string& networkId, 106 const uint16_t& bundleNameId, std::string& bundleName)); 107 MOCK_METHOD4(GetApplicationInfoFromBms, int32_t(const std::string& bundleName, const AppExecFwk::BundleFlag flag, 108 const int32_t userId, AppExecFwk::ApplicationInfo &appInfo)); 109 MOCK_METHOD1(QueryOsAccount, ErrCode(int32_t& activeAccountId)); 110 }; 111 } 112 } 113 #endif