1 /*
2  * Copyright (C) 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 <gmock/gmock.h>
20 #include <vector>
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 "want.h"
27 
28 namespace OHOS {
29 namespace AppExecFwk {
30 const std::string COM_IX_HIWORLD = "com.ix.hiworld";
31 const std::string COM_IX_HIMUSIC = "com.ix.hiMusic";
32 const std::string COM_IX_HIRADIO = "com.ix.hiRadio";
33 const std::string COM_IX_HISERVICE = "com.ix.hiService";
34 const std::string COM_IX_MUSICSERVICE = "com.ix.musicService";
35 const std::string COM_IX_HIDATA = "com.ix.hiData";
36 
37 class BundleMgrStub : public IRemoteStub<IBundleMgr> {
38 public:
39     DECLARE_INTERFACE_DESCRIPTOR(u"IBundleMgr");
40     int OnRemoteRequest(
41         uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override;
42 };
43 
44 class BundleMgrService : public BundleMgrStub {
45 public:
46     bool QueryAbilityInfo(const AAFwk::Want& want, AbilityInfo& abilityInfo) override;
47     bool GetApplicationInfo(
48         const std::string& appName, const ApplicationFlag flag, const int userId, ApplicationInfo& appInfo) override;
49 
50     bool GetBundleInfo(const std::string& bundleName, const BundleFlag flag, BundleInfo& bundleInfo,
51         int32_t userId = Constants::UNSPECIFIED_USERID) override;
52 
53     BundleMgrService();
54 
~BundleMgrService()55     virtual ~BundleMgrService()
56     {}
57 
58     bool CheckWantEntity(const AAFwk::Want&, AbilityInfo&);
59 
60 public:
61     using QueryAbilityInfoFunType =
62         std::function<bool(std::string bundleName, AbilityInfo& abilityInfo, ElementName& elementTemp)>;
63     std::map<std::string, QueryAbilityInfoFunType> abilityInfoMap_;
64 };
65 } // namespace AppExecFwk
66 } // namespace OHOS
67 #endif // MOCK_BUNDLE_MANAGER_H
68