• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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 #include "mock_bundle_manager.h"
17 
18 #include <fstream>
19 #include <sstream>
20 #include <string>
21 
22 #include "ability_config.h"
23 #include "ability_info.h"
24 #include "application_info.h"
25 #include "bundle_mgr_client.h"
26 
27 namespace OHOS {
28 namespace AppExecFwk {
29 using namespace std;
30 using namespace OHOS::AAFwk;
31 
GetBundleInfo(const string & bundleName,const BundleFlag flag,BundleInfo & bundleInfo,int32_t userId)32 bool BundleMgrProxy::GetBundleInfo(const string &bundleName,
33                                    const BundleFlag flag,
34                                    BundleInfo &bundleInfo,
35                                    int32_t userId)
36 {
37     GTEST_LOG_(INFO) << "BundleMgrProxy:GetBundleInfo is ok";
38     ExtensionAbilityInfo info;
39     info.type = AppExecFwk::ExtensionAbilityType::BACKUP;
40     info.name = "com.example.app2backup";
41     bundleInfo.extensionInfos.push_back(info);
42     return true;
43 }
44 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)45 int BundleMgrStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
46 {
47     return 0;
48 }
49 
GetBundleInfo(const string & bundleName,const BundleFlag flag,BundleInfo & bundleInfo,int32_t userId)50 bool BundleMgrStub::GetBundleInfo(const string &bundleName,
51                                   const BundleFlag flag,
52                                   BundleInfo &bundleInfo,
53                                   int32_t userId)
54 {
55     GTEST_LOG_(INFO) << "BundleMgrStub:GetBundleInfo is ok";
56     ExtensionAbilityInfo info;
57     info.type = AppExecFwk::ExtensionAbilityType::BACKUP;
58     info.name = "com.example.app2backup";
59     bundleInfo.extensionInfos.push_back(info);
60     return true;
61 }
62 
GetBundleInfo(const string & bundleName,int32_t flags,BundleInfo & bundleInfo,int32_t userId)63 bool BundleMgrStub::GetBundleInfo(const string &bundleName, int32_t flags, BundleInfo &bundleInfo, int32_t userId)
64 {
65     GTEST_LOG_(INFO) << "GetBundleInfo is ok";
66     ExtensionAbilityInfo info;
67     info.type = AppExecFwk::ExtensionAbilityType::BACKUP;
68     info.name = "com.example.app2backup";
69     bundleInfo.extensionInfos.push_back(info);
70     return true;
71 }
72 
GetApplicationInfos(const ApplicationFlag flag,int userId,vector<ApplicationInfo> & appInfos)73 bool BundleMgrStub::GetApplicationInfos(const ApplicationFlag flag, int userId, vector<ApplicationInfo> &appInfos)
74 {
75     GTEST_LOG_(INFO) << "GetApplicationInfos is ok";
76     ApplicationInfo appInfo {};
77     appInfo.bundleName = "com.example.app2backup";
78     appInfo.versionName = "1.0.0";
79     appInfos.push_back(appInfo);
80     return true;
81 }
82 
BundleMgrClient()83 BundleMgrClient::BundleMgrClient() {}
84 
~BundleMgrClient()85 BundleMgrClient::~BundleMgrClient() {}
86 
GetResConfigFile(const ExtensionAbilityInfo & extensionInfo,const string & metadataName,vector<string> & profileInfos) const87 bool BundleMgrClient::GetResConfigFile(const ExtensionAbilityInfo &extensionInfo,
88                                        const string &metadataName,
89                                        vector<string> &profileInfos) const
90 {
91     GTEST_LOG_(INFO) << "GetResConfigFile is ok";
92     string str = "{\"allowToBackupRestore\":true}";
93     profileInfos.push_back(str);
94     return true;
95 }
96 } // namespace AppExecFwk
97 } // namespace OHOS