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() const22std::string MockContextImpl::GetBundleName() const 23 { 24 return "com.test.bundleName"; 25 } 26 GetBundleCodeDir()27std::string MockContextImpl::GetBundleCodeDir() 28 { 29 return "/code"; 30 } 31 GetCacheDir()32std::string MockContextImpl::GetCacheDir() 33 { 34 return "/cache"; 35 } 36 IsUpdatingConfigurations()37bool MockContextImpl::IsUpdatingConfigurations() 38 { 39 return true; 40 } 41 PrintDrawnCompleted()42bool MockContextImpl::PrintDrawnCompleted() 43 { 44 return true; 45 } 46 GetDatabaseDir()47std::string MockContextImpl::GetDatabaseDir() 48 { 49 return "/data/app/database"; 50 } 51 GetPreferencesDir()52std::string MockContextImpl::GetPreferencesDir() 53 { 54 return "/preferences"; 55 } 56 GetTempDir()57std::string MockContextImpl::GetTempDir() 58 { 59 return "/temp"; 60 } 61 GetFilesDir()62std::string MockContextImpl::GetFilesDir() 63 { 64 return "/files"; 65 } 66 GetDistributedFilesDir()67std::string MockContextImpl::GetDistributedFilesDir() 68 { 69 return "/mnt/hmdfs/device_view/local/data/bundleName"; 70 } 71 CreateModuleContext(const std::string & moduleName)72std::shared_ptr<Context> MockContextImpl::CreateModuleContext(const std::string &moduleName) 73 { 74 std::shared_ptr<ContextImpl> appContext = std::make_shared<ContextImpl>(); 75 return appContext; 76 } 77 CreateModuleContext(const std::string & bundleName,const std::string & moduleName)78std::shared_ptr<Context> MockContextImpl::CreateModuleContext(const std::string &bundleName, const std::string &moduleName) 79 { 80 std::shared_ptr<ContextImpl> appContext = std::make_shared<ContextImpl>(); 81 return appContext; 82 } 83 GetArea()84int MockContextImpl::GetArea() 85 { 86 return 1; 87 } 88 GetBaseDir() const89std::string MockContextImpl::GetBaseDir() const 90 { 91 return "/data/app/base"; 92 } 93 CreateBundleContext(const std::string & bundleName)94std::shared_ptr<Context> MockContextImpl::CreateBundleContext(const std::string &bundleName) 95 { 96 std::shared_ptr<ContextImpl> appContext = std::make_shared<ContextImpl>(); 97 return appContext; 98 } 99 GetBundleManager() const100sptr<AppExecFwk::IBundleMgr> MockContextImpl::GetBundleManager() const 101 { 102 auto instance = OHOS::DelayedSingleton<AppExecFwk::SysMrgClient>::GetInstance(); 103 if (instance == nullptr) { 104 return nullptr; 105 } 106 auto bundleObj = instance->GetSystemAbility(401); 107 if (bundleObj == nullptr) { 108 return nullptr; 109 } 110 sptr<AppExecFwk::IBundleMgr> bms = iface_cast<AppExecFwk::IBundleMgr>(bundleObj); 111 return bms; 112 } 113 GetBundleCodePath() const114std::string MockContextImpl::GetBundleCodePath() const 115 { 116 return "codePath"; 117 } 118 InitHapModuleInfo(const std::shared_ptr<AppExecFwk::AbilityInfo> & abilityInfo)119void MockContextImpl::InitHapModuleInfo(const std::shared_ptr<AppExecFwk::AbilityInfo> &abilityInfo) 120 {} 121 GetDeviceType() const122Global::Resource::DeviceType MockContextImpl::GetDeviceType() const 123 { 124 return Global::Resource::DeviceType::DEVICE_NOT_SET; 125 } 126 GetApplicationInfo() const127std::shared_ptr<AppExecFwk::ApplicationInfo> MockContextImpl::GetApplicationInfo() const 128 { 129 std::shared_ptr<AppExecFwk::ApplicationInfo> info = std::make_shared<AppExecFwk::ApplicationInfo>(); 130 info->name = "ContextTest"; 131 return info; 132 } 133 GetResourceManager() const134std::shared_ptr<Global::Resource::ResourceManager> MockContextImpl::GetResourceManager() const 135 { 136 std::shared_ptr<Global::Resource::ResourceManager> resourceManager(Global::Resource::CreateResourceManager()); 137 return resourceManager; 138 } 139 GetConfiguration() const140std::shared_ptr<AppExecFwk::Configuration> MockContextImpl::GetConfiguration() const 141 { 142 std::shared_ptr<AppExecFwk::Configuration> config = std::make_shared<AppExecFwk::Configuration>(); 143 return config; 144 } 145 } // namespace AbilityRuntime 146 } // namespace OHOS