• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "mock_context_impl.h"
17 #include "sys_mgr_client.h"
18 
19 namespace OHOS {
20 namespace AbilityRuntime {
21 
GetBundleName() const22 std::string MockContextImpl::GetBundleName() const
23 {
24     return "com.test.bundleName";
25 }
26 
GetBundleCodeDir()27 std::string MockContextImpl::GetBundleCodeDir()
28 {
29     return "/code";
30 }
31 
GetCacheDir()32 std::string MockContextImpl::GetCacheDir()
33 {
34     return "/cache";
35 }
36 
IsUpdatingConfigurations()37 bool MockContextImpl::IsUpdatingConfigurations()
38 {
39     return true;
40 }
41 
PrintDrawnCompleted()42 bool MockContextImpl::PrintDrawnCompleted()
43 {
44     return true;
45 }
46 
GetDatabaseDir()47 std::string MockContextImpl::GetDatabaseDir()
48 {
49     return "/data/app/database";
50 }
51 
GetPreferencesDir()52 std::string MockContextImpl::GetPreferencesDir()
53 {
54     return "/preferences";
55 }
56 
GetTempDir()57 std::string MockContextImpl::GetTempDir()
58 {
59     return "/temp";
60 }
61 
GetResourceDir()62 std::string MockContextImpl::GetResourceDir()
63 {
64     return "/resfile";
65 }
66 
GetFilesDir()67 std::string MockContextImpl::GetFilesDir()
68 {
69     return "/files";
70 }
71 
GetDistributedFilesDir()72 std::string MockContextImpl::GetDistributedFilesDir()
73 {
74     return "/mnt/hmdfs/device_view/local/data/bundleName";
75 }
76 
GetGroupDir(std::string groupId)77 std::string MockContextImpl::GetGroupDir(std::string groupId)
78 {
79     return "/group";
80 }
81 
GetSystemDatabaseDir(const std::string & groupId,bool checkExist,std::string & databaseDir)82 int32_t MockContextImpl::GetSystemDatabaseDir(const std::string &groupId, bool checkExist, std::string &databaseDir)
83 {
84     return 0;
85 }
86 
GetSystemPreferencesDir(const std::string & groupId,bool checkExist,std::string & preferencesDir)87 int32_t MockContextImpl::GetSystemPreferencesDir(const std::string &groupId, bool checkExist,
88     std::string &preferencesDir)
89 {
90     return 0;
91 }
92 
CreateModuleContext(const std::string & moduleName)93 std::shared_ptr<Context> MockContextImpl::CreateModuleContext(const std::string &moduleName)
94 {
95     std::shared_ptr<ContextImpl> appContext = std::make_shared<ContextImpl>();
96     return appContext;
97 }
98 
CreateModuleContext(const std::string & bundleName,const std::string & moduleName)99 std::shared_ptr<Context> MockContextImpl::CreateModuleContext(const std::string &bundleName,
100     const std::string &moduleName)
101 {
102     std::shared_ptr<ContextImpl> appContext = std::make_shared<ContextImpl>();
103     return appContext;
104 }
105 
CreateModuleResourceManager(const std::string & bundleName,const std::string & moduleName)106 std::shared_ptr<Global::Resource::ResourceManager> MockContextImpl::CreateModuleResourceManager(
107     const std::string &bundleName, const std::string &moduleName)
108 {
109     return nullptr;
110 }
111 
GetArea()112 int MockContextImpl::GetArea()
113 {
114     return 1;
115 }
116 
GetBaseDir() const117 std::string MockContextImpl::GetBaseDir() const
118 {
119     return "/data/app/base";
120 }
121 
CreateBundleContext(const std::string & bundleName)122 std::shared_ptr<Context> MockContextImpl::CreateBundleContext(const std::string &bundleName)
123 {
124     std::shared_ptr<ContextImpl> appContext = std::make_shared<ContextImpl>();
125     return appContext;
126 }
127 
GetBundleManager() const128 sptr<AppExecFwk::IBundleMgr> MockContextImpl::GetBundleManager() const
129 {
130     auto instance = OHOS::DelayedSingleton<AppExecFwk::SysMrgClient>::GetInstance();
131     if (instance == nullptr) {
132         return nullptr;
133     }
134     auto bundleObj = instance->GetSystemAbility(401);
135     if (bundleObj == nullptr) {
136         return nullptr;
137     }
138     sptr<AppExecFwk::IBundleMgr> bms = iface_cast<AppExecFwk::IBundleMgr>(bundleObj);
139     return bms;
140 }
141 
GetBundleCodePath() const142 std::string MockContextImpl::GetBundleCodePath() const
143 {
144     return "codePath";
145 }
146 
InitHapModuleInfo(const std::shared_ptr<AppExecFwk::AbilityInfo> & abilityInfo)147 void MockContextImpl::InitHapModuleInfo(const std::shared_ptr<AppExecFwk::AbilityInfo> &abilityInfo)
148 {}
149 
GetDeviceType() const150 Global::Resource::DeviceType MockContextImpl::GetDeviceType() const
151 {
152     return Global::Resource::DeviceType::DEVICE_NOT_SET;
153 }
154 
GetApplicationInfo() const155 std::shared_ptr<AppExecFwk::ApplicationInfo> MockContextImpl::GetApplicationInfo() const
156 {
157     std::shared_ptr<AppExecFwk::ApplicationInfo> info = std::make_shared<AppExecFwk::ApplicationInfo>();
158     info->name = "ContextTest";
159     return info;
160 }
161 
GetResourceManager() const162 std::shared_ptr<Global::Resource::ResourceManager> MockContextImpl::GetResourceManager() const
163 {
164     std::shared_ptr<Global::Resource::ResourceManager> resourceManager(Global::Resource::CreateResourceManager());
165     return resourceManager;
166 }
167 
GetConfiguration() const168 std::shared_ptr<AppExecFwk::Configuration> MockContextImpl::GetConfiguration() const
169 {
170     std::shared_ptr<AppExecFwk::Configuration> config = std::make_shared<AppExecFwk::Configuration>();
171     return config;
172 }
173 }  // namespace AbilityRuntime
174 }  // namespace OHOS
175