• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 "ability_context.h"
17 
18 #include <cstring>
19 #include "hilog_wrapper.h"
20 
21 namespace OHOS {
22 namespace AbilityRuntime {
GetConfiguration()23 std::shared_ptr<AppExecFwk::Configuration> AbilityContext::GetConfiguration()
24 {
25     return stageContext_ ? stageContext_->GetConfiguration() : nullptr;
26 }
27 
GetApplicationInfo() const28 std::shared_ptr<AppExecFwk::ApplicationInfo> AbilityContext::GetApplicationInfo() const
29 {
30     return stageContext_ ? stageContext_->GetApplicationInfo() : nullptr;
31 }
32 
GetHapModuleInfo() const33 std::shared_ptr<AppExecFwk::HapModuleInfo> AbilityContext::GetHapModuleInfo() const
34 {
35     return stageContext_ ? stageContext_->GetHapModuleInfo() : nullptr;
36 }
37 
GetAbilityInfo() const38 std::shared_ptr<AppExecFwk::AbilityInfo> AbilityContext::GetAbilityInfo() const
39 {
40     return abilityInfo_;
41 }
42 
SetAbilityInfo(const std::shared_ptr<AppExecFwk::AbilityInfo> & info)43 void AbilityContext::SetAbilityInfo(const std::shared_ptr<AppExecFwk::AbilityInfo> &info)
44 {
45     abilityInfo_ = info;
46 }
47 
GetOptions()48 Options AbilityContext::GetOptions()
49 {
50     return options_;
51 }
52 
SetOptions(const Options & options)53 void AbilityContext::SetOptions(const Options &options)
54 {
55     options_ = options;
56 
57     HILOG_DEBUG("Options.bundleName: %{public}s", options.bundleName.c_str());
58     HILOG_DEBUG("Options.moduleName: %{public}s", options.moduleName.c_str());
59     HILOG_DEBUG("Options.modulePath: %{public}s", options.modulePath.c_str());
60     HILOG_DEBUG("Options.resourcePath: %{public}s", options.resourcePath.c_str());
61     HILOG_DEBUG("Options.debugPort: %{public}d", options.debugPort);
62     HILOG_DEBUG("Options.assetPath: %{public}s", options.assetPath.c_str());
63     HILOG_DEBUG("Options.systemResourcePath: %{public}s", options.systemResourcePath.c_str());
64     HILOG_DEBUG("Options.appResourcePath: %{public}s", options.appResourcePath.c_str());
65     HILOG_DEBUG("Options.containerSdkPath: %{public}s", options.containerSdkPath.c_str());
66     HILOG_DEBUG("Options.url: %{public}s", options.url.c_str());
67     HILOG_DEBUG("Options.language: %{public}s", options.language.c_str());
68     HILOG_DEBUG("Options.region: %{public}s", options.region.c_str());
69     HILOG_DEBUG("Options.script: %{public}s", options.script.c_str());
70     HILOG_DEBUG("Options.themeId: %{public}d", options.themeId);
71     HILOG_DEBUG("Options.deviceWidth: %{public}d", options.deviceWidth);
72     HILOG_DEBUG("Options.deviceHeight: %{public}d", options.deviceHeight);
73     HILOG_DEBUG("Options.isRound: %{public}d", options.themeId);
74     HILOG_DEBUG("Options.compatibleVersion: %{public}d", options.compatibleVersion);
75     HILOG_DEBUG("Options.installationFree: %{public}d", options.installationFree);
76     HILOG_DEBUG("Options.labelId: %{public}d", options.labelId);
77     HILOG_DEBUG("Options.compileMode: %{public}s", options.compileMode.c_str());
78     HILOG_DEBUG("Options.pageProfile: %{public}s", options.pageProfile.c_str());
79     HILOG_DEBUG("Options.targetVersion: %{public}d", options.targetVersion);
80     HILOG_DEBUG("Options.releaseType: %{public}s", options.releaseType.c_str());
81     HILOG_DEBUG("Options.enablePartialUpdate: %{public}d", options.enablePartialUpdate);
82 }
83 
GetBundleName()84 std::string AbilityContext::GetBundleName()
85 {
86     return stageContext_ ? stageContext_->GetBundleName() : "";
87 }
88 
GetBundleCodePath()89 std::string AbilityContext::GetBundleCodePath()
90 {
91     return stageContext_ ? stageContext_->GetBundleCodePath() : "";
92 }
93 
GetBundleCodeDir()94 std::string AbilityContext::GetBundleCodeDir()
95 {
96     return stageContext_ ? stageContext_->GetBundleCodeDir() : "";
97 }
98 
GetCacheDir()99 std::string AbilityContext::GetCacheDir()
100 {
101     return stageContext_ ? stageContext_->GetCacheDir() : "";
102 }
103 
GetTempDir()104 std::string AbilityContext::GetTempDir()
105 {
106     return stageContext_ ? stageContext_->GetTempDir() : "";
107 }
108 
GetResourceDir()109 std::string AbilityContext::GetResourceDir()
110 {
111     return stageContext_ ? stageContext_->GetResourceDir() : "";
112 }
113 
GetFilesDir()114 std::string AbilityContext::GetFilesDir()
115 {
116     return stageContext_ ? stageContext_->GetFilesDir() : "";
117 }
118 
GetDatabaseDir()119 std::string AbilityContext::GetDatabaseDir()
120 {
121     return stageContext_ ? stageContext_->GetDatabaseDir() : "";
122 }
123 
GetPreferencesDir()124 std::string AbilityContext::GetPreferencesDir()
125 {
126     return stageContext_ ? stageContext_->GetPreferencesDir() : "";
127 }
128 
GetDistributedFilesDir()129 std::string AbilityContext::GetDistributedFilesDir()
130 {
131     return stageContext_ ? stageContext_->GetDistributedFilesDir() : "";
132 }
133 
SwitchArea(int mode)134 void AbilityContext::SwitchArea(int mode)
135 {
136     if (stageContext_) {
137         stageContext_->SwitchArea(mode);
138     }
139 }
140 
GetArea()141 int AbilityContext::GetArea()
142 {
143     return stageContext_ ? stageContext_->GetArea() : EL_DEFAULT;
144 }
145 
GetBaseDir()146 std::string AbilityContext::GetBaseDir()
147 {
148     return stageContext_ ? stageContext_->GetBaseDir() : "";
149 }
150 
GetResourceManager() const151 std::shared_ptr<Global::Resource::ResourceManager> AbilityContext::GetResourceManager() const
152 {
153     return resourceMgr_;
154 }
155 
SetResourceManager(const std::shared_ptr<Global::Resource::ResourceManager> & resMgr)156 void AbilityContext::SetResourceManager(const std::shared_ptr<Global::Resource::ResourceManager> &resMgr)
157 {
158     resourceMgr_ = resMgr;
159 }
160 
SetAbilityStageContext(const std::shared_ptr<AbilityStageContext> & stageContext)161 void AbilityContext::SetAbilityStageContext(const std::shared_ptr<AbilityStageContext> &stageContext)
162 {
163     stageContext_ = stageContext;
164 }
165 
IsTerminating()166 bool AbilityContext::IsTerminating()
167 {
168     return isTerminating_;
169 }
170 
SetTerminating(const bool & state)171 void AbilityContext::SetTerminating(const bool &state)
172 {
173     isTerminating_ = state;
174 }
175 
TerminateSelf()176 int32_t AbilityContext::TerminateSelf()
177 {
178     if (simulator_ != nullptr) {
179         simulator_->TerminateAbility(0);
180     }
181     return 0;
182 }
183 
SetSimulator(Simulator * simulator)184 void AbilityContext::SetSimulator(Simulator *simulator)
185 {
186     simulator_ = simulator;
187 }
188 } // namespace AbilityRuntime
189 } // namespace OHOS
190