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 MOCK_BUNDLE_MANAGER_H 17 #define MOCK_BUNDLE_MANAGER_H 18 19 #include <vector> 20 #include <gmock/gmock.h> 21 #include "ability_info.h" 22 #include "application_info.h" 23 #include "bundlemgr/bundle_mgr_interface.h" 24 #include "iremote_proxy.h" 25 #include "iremote_stub.h" 26 #include "form_info.h" 27 #include "shortcut_info.h" 28 #include "want.h" 29 30 namespace OHOS { 31 namespace AppExecFwk { 32 namespace { 33 const std::string COM_IX_HIWORLD = "com.ix.hiworld"; 34 const std::string COM_IX_HIMUSIC = "com.ix.hiMusic"; 35 const std::string COM_IX_HIRADIO = "com.ix.hiRadio"; 36 const std::string COM_IX_HISERVICE = "com.ix.hiService"; 37 const std::string COM_IX_MUSICSERVICE = "com.ix.musicService"; 38 const std::string COM_IX_HIDATA = "com.ix.hiData"; 39 const std::string COM_IX_HIEXTENSION = "com.ix.hiExtension"; 40 const std::string COM_IX_HIACCOUNT = "com.ix.hiAccount"; 41 const std::string COM_IX_HIBACKGROUNDMUSIC = "com.ix.hiBackgroundMusic"; 42 const std::string COM_IX_HIBACKGROUNDDATA = "com.ix.hiBackgroundData"; 43 const std::string COM_IX_HISINGLEMUSIC = "com.ix.hiSingleMusicInfo"; 44 const std::string COM_IX_ACCOUNTSERVICE = "com.ix.accountService"; 45 const std::string COM_OHOS_TEST = "com.ohos.test"; 46 constexpr int32_t MAX_SYS_UID = 2899; 47 constexpr int32_t ROOT_UID = 0; 48 const int32_t BASE_USER_RANGE = 200000; 49 const int32_t APPLICATIONINFO_UID = 20000000; 50 } // namespace 51 52 class BundleMgrProxy : public IRemoteProxy<IBundleMgr> { 53 public: BundleMgrProxy(const sptr<IRemoteObject> & impl)54 explicit BundleMgrProxy(const sptr<IRemoteObject>& impl) : IRemoteProxy<IBundleMgr>(impl) 55 {} ~BundleMgrProxy()56 virtual ~BundleMgrProxy() 57 {} 58 int QueryWantAbility(const AAFwk::Want& want, std::vector<AbilityInfo>& abilityInfos); 59 60 bool QueryAbilityInfo(const AAFwk::Want& want, AbilityInfo& abilityInfo) override; 61 62 bool QueryAbilityInfoByUri(const std::string& uri, AbilityInfo& abilityInfo) override; 63 64 bool GetApplicationInfo( 65 const std::string& appName, const ApplicationFlag flag, const int userId, ApplicationInfo& appInfo) override; 66 67 bool GetBundleInfo( 68 const std::string& bundleName, const BundleFlag flag, BundleInfo& bundleInfo, int32_t userId) override; 69 70 virtual bool CheckIsSystemAppByUid(const int uid) override; 71 }; 72 73 class BundleMgrStub : public IRemoteStub<IBundleMgr> { 74 public: 75 virtual int OnRemoteRequest( 76 uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override; 77 }; 78 79 class BundleMgrService : public BundleMgrStub { 80 public: 81 BundleMgrService(); 82 ~BundleMgrService(); 83 84 bool QueryAbilityInfo(const AAFwk::Want& want, AbilityInfo& abilityInfo) override; 85 bool QueryAbilityInfo(const Want& want, int32_t flags, int32_t userId, AbilityInfo& abilityInfo) override; 86 bool QueryAbilityInfoByUri(const std::string& uri, AbilityInfo& abilityInfo) override; 87 bool GetApplicationInfo( 88 const std::string& appName, const ApplicationFlag flag, const int userId, ApplicationInfo& appInfo) override; 89 bool GetBundleInfo( 90 const std::string& bundleName, const BundleFlag flag, BundleInfo& bundleInfo, int32_t userId) override; 91 int GetUidByBundleName(const std::string& bundleName, const int userId) override; 92 virtual bool CheckIsSystemAppByUid(const int uid) override; 93 bool CheckWantEntity(const AAFwk::Want&, AbilityInfo&); 94 95 public: 96 using QueryAbilityInfoFunType = 97 std::function<bool(std::string bundleName, AbilityInfo& abilityInfo, ElementName& elementTemp)>; 98 std::map<std::string, QueryAbilityInfoFunType> abilityInfoMap_; 99 }; 100 } // namespace AppExecFwk 101 } // namespace OHOS 102 #endif // MOCK_BUNDLE_MANAGER_H 103