• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 
16 #include "mock_context_impl.h"
17 #include "sys_mgr_client.h"
18 #include "configuration.h"
19 
20 namespace OHOS {
21 namespace AbilityRuntime {
22 
GetBundleName() const23 std::string MockContextImpl::GetBundleName() const
24 {
25     return "com.test.bundleName";
26 }
27 
GetBundleCodeDir()28 std::string MockContextImpl::GetBundleCodeDir()
29 {
30     return "/code";
31 }
32 
GetCacheDir()33 std::string MockContextImpl::GetCacheDir()
34 {
35     return "/cache";
36 }
37 
IsUpdatingConfigurations()38 bool MockContextImpl::IsUpdatingConfigurations()
39 {
40     return true;
41 }
42 
PrintDrawnCompleted()43 bool MockContextImpl::PrintDrawnCompleted()
44 {
45     return true;
46 }
47 
GetDatabaseDir()48 std::string MockContextImpl::GetDatabaseDir()
49 {
50     return "/data/app/database";
51 }
52 
GetPreferencesDir()53 std::string MockContextImpl::GetPreferencesDir()
54 {
55     return "/preferences";
56 }
57 
GetTempDir()58 std::string MockContextImpl::GetTempDir()
59 {
60     return "/temp";
61 }
62 
GetResourceDir(const std::string & moduleName)63 std::string MockContextImpl::GetResourceDir(const std::string &moduleName)
64 {
65     return "/resfile";
66 }
67 
GetFilesDir()68 std::string MockContextImpl::GetFilesDir()
69 {
70     return "/files";
71 }
72 
GetDistributedFilesDir()73 std::string MockContextImpl::GetDistributedFilesDir()
74 {
75     return "/mnt/hmdfs/device_view/local/data/bundleName";
76 }
77 
GetCloudFileDir()78 std::string MockContextImpl::GetCloudFileDir()
79 {
80     return "/cloud";
81 }
82 
GetGroupDir(std::string groupId)83 std::string MockContextImpl::GetGroupDir(std::string groupId)
84 {
85     return "/group";
86 }
87 
GetSystemDatabaseDir(const std::string & groupId,bool checkExist,std::string & databaseDir)88 int32_t MockContextImpl::GetSystemDatabaseDir(const std::string &groupId, bool checkExist, std::string &databaseDir)
89 {
90     return 0;
91 }
92 
GetSystemPreferencesDir(const std::string & groupId,bool checkExist,std::string & preferencesDir)93 int32_t MockContextImpl::GetSystemPreferencesDir(const std::string &groupId, bool checkExist,
94     std::string &preferencesDir)
95 {
96     return 0;
97 }
98 
CreateModuleContext(const std::string & moduleName)99 std::shared_ptr<Context> MockContextImpl::CreateModuleContext(const std::string &moduleName)
100 {
101     std::shared_ptr<ContextImpl> appContext = std::make_shared<ContextImpl>();
102     return appContext;
103 }
104 
CreateModuleContext(const std::string & bundleName,const std::string & moduleName)105 std::shared_ptr<Context> MockContextImpl::CreateModuleContext(const std::string &bundleName,
106     const std::string &moduleName)
107 {
108     std::shared_ptr<ContextImpl> appContext = std::make_shared<ContextImpl>();
109     return appContext;
110 }
111 
CreateSystemHspModuleResourceManager(const std::string & bundleName,const std::string & moduleName,std::shared_ptr<Global::Resource::ResourceManager> & resourceManager)112 int32_t MockContextImpl::CreateSystemHspModuleResourceManager(const std::string &bundleName,
113     const std::string &moduleName, std::shared_ptr<Global::Resource::ResourceManager> &resourceManager)
114 {
115     return 0;
116 }
117 
CreateModuleResourceManager(const std::string & bundleName,const std::string & moduleName)118 std::shared_ptr<Global::Resource::ResourceManager> MockContextImpl::CreateModuleResourceManager(
119     const std::string &bundleName, const std::string &moduleName)
120 {
121     return nullptr;
122 }
123 
GetArea()124 int MockContextImpl::GetArea()
125 {
126     return 1;
127 }
128 
GetBaseDir() const129 std::string MockContextImpl::GetBaseDir() const
130 {
131     return "/data/app/base";
132 }
133 
CreateBundleContext(const std::string & bundleName)134 std::shared_ptr<Context> MockContextImpl::CreateBundleContext(const std::string &bundleName)
135 {
136     std::shared_ptr<ContextImpl> appContext = std::make_shared<ContextImpl>();
137     return appContext;
138 }
139 
GetBundleManager() const140 sptr<AppExecFwk::IBundleMgr> MockContextImpl::GetBundleManager() const
141 {
142     auto instance = OHOS::DelayedSingleton<AppExecFwk::SysMrgClient>::GetInstance();
143     if (instance == nullptr) {
144         return nullptr;
145     }
146     auto bundleObj = instance->GetSystemAbility(401);
147     if (bundleObj == nullptr) {
148         return nullptr;
149     }
150     sptr<AppExecFwk::IBundleMgr> bms = iface_cast<AppExecFwk::IBundleMgr>(bundleObj);
151     return bms;
152 }
153 
GetBundleCodePath() const154 std::string MockContextImpl::GetBundleCodePath() const
155 {
156     return "codePath";
157 }
158 
InitHapModuleInfo(const std::shared_ptr<AppExecFwk::AbilityInfo> & abilityInfo)159 void MockContextImpl::InitHapModuleInfo(const std::shared_ptr<AppExecFwk::AbilityInfo> &abilityInfo)
160 {}
161 
GetDeviceType() const162 Global::Resource::DeviceType MockContextImpl::GetDeviceType() const
163 {
164     return Global::Resource::DeviceType::DEVICE_NOT_SET;
165 }
166 
GetApplicationInfo() const167 std::shared_ptr<AppExecFwk::ApplicationInfo> MockContextImpl::GetApplicationInfo() const
168 {
169     std::shared_ptr<AppExecFwk::ApplicationInfo> info = std::make_shared<AppExecFwk::ApplicationInfo>();
170     info->name = "ContextTest";
171     return info;
172 }
173 
GetResourceManager() const174 std::shared_ptr<Global::Resource::ResourceManager> MockContextImpl::GetResourceManager() const
175 {
176     std::shared_ptr<Global::Resource::ResourceManager> resourceManager(Global::Resource::CreateResourceManager());
177     return resourceManager;
178 }
179 
GetConfiguration() const180 std::shared_ptr<AppExecFwk::Configuration> MockContextImpl::GetConfiguration() const
181 {
182     std::shared_ptr<AppExecFwk::Configuration> config = std::make_shared<AppExecFwk::Configuration>();
183     return config;
184 }
185 
GetProcessName()186 std::string MockContextImpl::GetProcessName()
187 {
188     return "processName";
189 }
190 
CreateAreaModeContext(int areaMode)191 std::shared_ptr<Context> MockContextImpl::CreateAreaModeContext(int areaMode)
192 {
193     return nullptr;
194 }
195 
196 #ifdef SUPPORT_GRAPHICS
CreateDisplayContext(uint64_t displayId)197 std::shared_ptr<Context> MockContextImpl::CreateDisplayContext(uint64_t displayId)
198 {
199     return nullptr;
200 }
201 #endif
202 }  // namespace AbilityRuntime
203 }  // namespace OHOS
204