• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <gtest/gtest.h>
17 #include "mock_bundle_manager.h"
18 
19 #include "ability_info.h"
20 #include "application_info.h"
21 #include "form_info.h"
22 
23 namespace OHOS {
24 namespace AppExecFwk {
25 const std::string FORM_PROVIDER_BUNDLE_NAME = "com.form.provider.service";
26 const std::string PARAM_PROVIDER_PACKAGE_NAME = "com.form.provider.app.test.ability";
27 const std::string PARAM_PROVIDER_MODULE_NAME = "com.form.provider.app.test.ability";
28 const std::string FORM_PROVIDER_ABILITY_NAME = "com.form.provider.app.test.ability";
29 const std::string FORM_PROVIDER_MODULE_SOURCE_DIR = "";
30 const std::string FORM_JS_COMPONENT_NAME = "jsComponentName";
31 const std::string PARAM_FORM_NAME = "com.form.name.test";
32 const std::string DEVICE_ID = "ohos-phone1";
33 
34 bool BundleMgrService::IsSystemApp = false;
35 
GetUidByBundleName(const std::string & bundleName,const int userId)36 int BundleMgrService::GetUidByBundleName(const std::string &bundleName, const int userId)
37 {
38     if (bundleName.compare("com.form.host.app600") == 0) {
39         return APP_600;
40     }
41     return 0;
42 }
43 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)44 int BundleMgrStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
45 {
46     return 0;
47 }
48 
QueryAbilityInfo(const AAFwk::Want & want,AbilityInfo & abilityInfo)49 bool BundleMgrService::QueryAbilityInfo(const AAFwk::Want &want, AbilityInfo &abilityInfo)
50 {
51     return true;
52 }
53 
GetAppType(const std::string & bundleName)54 std::string BundleMgrService::GetAppType(const std::string &bundleName)
55 {
56     return "system";
57 }
58 
GetBundleInfo(const std::string & bundleName,const BundleFlag flag,BundleInfo & bundleInfo,int32_t userId)59 bool BundleMgrService::GetBundleInfo(
60     const std::string &bundleName, const BundleFlag flag, BundleInfo &bundleInfo, int32_t userId)
61 {
62     std::vector<AbilityInfo> abilityInfos;
63     ApplicationInfo applicationInfo;
64     ModuleInfo moduleInfo;
65 
66     moduleInfo.moduleSourceDir = FORM_PROVIDER_MODULE_SOURCE_DIR;
67     moduleInfo.moduleName = PARAM_PROVIDER_MODULE_NAME;
68     bundleInfo.name = bundleName;
69     applicationInfo.bundleName = bundleName;
70     applicationInfo.moduleInfos.emplace_back(moduleInfo);
71     bundleInfo.applicationInfo = applicationInfo;
72 
73     bundleInfo.moduleNames.emplace_back(PARAM_PROVIDER_MODULE_NAME);
74 
75     AbilityInfo abilityInfo;
76     abilityInfo.name = FORM_PROVIDER_ABILITY_NAME;
77     abilityInfo.package = PARAM_PROVIDER_PACKAGE_NAME;
78     abilityInfo.bundleName = bundleName;
79     abilityInfo.moduleName = PARAM_PROVIDER_MODULE_NAME;
80     abilityInfo.deviceId = DEVICE_ID;
81     bundleInfo.abilityInfos.emplace_back(abilityInfo);
82 
83     return true;
84 }
85 
GetFormsInfoByApp(const std::string & bundleName,std::vector<FormInfo> & formInfo)86 bool BundleMgrService::GetFormsInfoByApp(const std::string &bundleName, std::vector<FormInfo> &formInfo)
87 {
88     FormInfo form;
89     form.bundleName = bundleName;
90     form.abilityName = FORM_PROVIDER_ABILITY_NAME;
91     form.moduleName = PARAM_PROVIDER_MODULE_NAME;
92     form.name = PARAM_FORM_NAME;
93     form.updateEnabled = true;
94     form.updateDuration = 1;
95     form.scheduledUpdateTime = "06:06";
96     form.jsComponentName = FORM_JS_COMPONENT_NAME;
97     form.formVisibleNotify = true;
98     form.supportDimensions = {1, 2};
99     form.defaultDimension = 1;
100     formInfo.emplace_back(form);
101     return true;
102 }
GetFormsInfoByModule(const std::string & bundleName,const std::string & moduleName,std::vector<FormInfo> & formInfo)103 bool BundleMgrService::GetFormsInfoByModule(const std::string &bundleName, const std::string &moduleName,
104     std::vector<FormInfo> &formInfo)
105 {
106     FormInfo form;
107     form.bundleName = bundleName;
108     form.abilityName = FORM_PROVIDER_ABILITY_NAME;
109     form.moduleName = PARAM_PROVIDER_MODULE_NAME;
110     form.name = PARAM_FORM_NAME;
111     form.updateEnabled = true;
112     form.updateDuration = 1;
113     form.scheduledUpdateTime = "06:06";
114     form.jsComponentName = FORM_JS_COMPONENT_NAME;
115     form.formVisibleNotify = true;
116     form.supportDimensions = {1, 2};
117     form.defaultDimension = 1;
118     formInfo.emplace_back(form);
119     return true;
120 }
121 } // namespace AppExecFwk
122 } // namespace OHOS
123