• 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 
GetFilesDir()62 std::string MockContextImpl::GetFilesDir()
63 {
64     return "/files";
65 }
66 
GetDistributedFilesDir()67 std::string MockContextImpl::GetDistributedFilesDir()
68 {
69     return "/mnt/hmdfs/device_view/local/data/bundleName";
70 }
71 
GetGroupDir(std::string groupId)72 std::string MockContextImpl::GetGroupDir(std::string groupId)
73 {
74     return "/group";
75 }
76 
GetSystemDatabaseDir(const std::string & groupId,bool checkExist,std::string & databaseDir)77 int32_t MockContextImpl::GetSystemDatabaseDir(const std::string &groupId, bool checkExist, std::string &databaseDir)
78 {
79     return 0;
80 }
81 
GetSystemPreferencesDir(const std::string & groupId,bool checkExist,std::string & preferencesDir)82 int32_t MockContextImpl::GetSystemPreferencesDir(const std::string &groupId, bool checkExist,
83     std::string &preferencesDir)
84 {
85     return 0;
86 }
87 
CreateModuleContext(const std::string & moduleName)88 std::shared_ptr<Context> MockContextImpl::CreateModuleContext(const std::string &moduleName)
89 {
90     std::shared_ptr<ContextImpl> appContext = std::make_shared<ContextImpl>();
91     return appContext;
92 }
93 
CreateModuleContext(const std::string & bundleName,const std::string & moduleName)94 std::shared_ptr<Context> MockContextImpl::CreateModuleContext(const std::string &bundleName, const std::string &moduleName)
95 {
96     std::shared_ptr<ContextImpl> appContext = std::make_shared<ContextImpl>();
97     return appContext;
98 }
99 
GetArea()100 int MockContextImpl::GetArea()
101 {
102     return 1;
103 }
104 
GetBaseDir() const105 std::string MockContextImpl::GetBaseDir() const
106 {
107     return "/data/app/base";
108 }
109 
CreateBundleContext(const std::string & bundleName)110 std::shared_ptr<Context> MockContextImpl::CreateBundleContext(const std::string &bundleName)
111 {
112     std::shared_ptr<ContextImpl> appContext = std::make_shared<ContextImpl>();
113     return appContext;
114 }
115 
GetBundleManager() const116 sptr<AppExecFwk::IBundleMgr> MockContextImpl::GetBundleManager() const
117 {
118     auto instance = OHOS::DelayedSingleton<AppExecFwk::SysMrgClient>::GetInstance();
119     if (instance == nullptr) {
120         return nullptr;
121     }
122     auto bundleObj = instance->GetSystemAbility(401);
123     if (bundleObj == nullptr) {
124         return nullptr;
125     }
126     sptr<AppExecFwk::IBundleMgr> bms = iface_cast<AppExecFwk::IBundleMgr>(bundleObj);
127     return bms;
128 }
129 
GetBundleCodePath() const130 std::string MockContextImpl::GetBundleCodePath() const
131 {
132     return "codePath";
133 }
134 
InitHapModuleInfo(const std::shared_ptr<AppExecFwk::AbilityInfo> & abilityInfo)135 void MockContextImpl::InitHapModuleInfo(const std::shared_ptr<AppExecFwk::AbilityInfo> &abilityInfo)
136 {}
137 
GetDeviceType() const138 Global::Resource::DeviceType MockContextImpl::GetDeviceType() const
139 {
140     return Global::Resource::DeviceType::DEVICE_NOT_SET;
141 }
142 
GetApplicationInfo() const143 std::shared_ptr<AppExecFwk::ApplicationInfo> MockContextImpl::GetApplicationInfo() const
144 {
145     std::shared_ptr<AppExecFwk::ApplicationInfo> info = std::make_shared<AppExecFwk::ApplicationInfo>();
146     info->name = "ContextTest";
147     return info;
148 }
149 
GetResourceManager() const150 std::shared_ptr<Global::Resource::ResourceManager> MockContextImpl::GetResourceManager() const
151 {
152     std::shared_ptr<Global::Resource::ResourceManager> resourceManager(Global::Resource::CreateResourceManager());
153     return resourceManager;
154 }
155 
GetConfiguration() const156 std::shared_ptr<AppExecFwk::Configuration> MockContextImpl::GetConfiguration() const
157 {
158     std::shared_ptr<AppExecFwk::Configuration> config = std::make_shared<AppExecFwk::Configuration>();
159     return config;
160 }
161 }  // namespace AbilityRuntime
162 }  // namespace OHOS
163