1 /*
2 * Copyright (c) 2023-2024 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_tag_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 TAG_LOGD(AAFwkTag::ABILITY_SIM, "bundleName:%{public}s", options.bundleName.c_str());
58 TAG_LOGD(AAFwkTag::ABILITY_SIM, "moduleName:%{public}s", options.moduleName.c_str());
59 TAG_LOGD(AAFwkTag::ABILITY_SIM, "modulePath:%{public}s", options.modulePath.c_str());
60 TAG_LOGD(AAFwkTag::ABILITY_SIM, "resourcePath:%{public}s", options.resourcePath.c_str());
61 TAG_LOGD(AAFwkTag::ABILITY_SIM, "debugPort:%{public}d", options.debugPort);
62 TAG_LOGD(AAFwkTag::ABILITY_SIM, "assetPath:%{public}s", options.assetPath.c_str());
63 TAG_LOGD(AAFwkTag::ABILITY_SIM, "systemResourcePath:%{public}s", options.systemResourcePath.c_str());
64 TAG_LOGD(AAFwkTag::ABILITY_SIM, "appResourcePath:%{public}s", options.appResourcePath.c_str());
65 TAG_LOGD(AAFwkTag::ABILITY_SIM, "containerSdkPath:%{public}s", options.containerSdkPath.c_str());
66 TAG_LOGD(AAFwkTag::ABILITY_SIM, "url:%{public}s", options.url.c_str());
67 TAG_LOGD(AAFwkTag::ABILITY_SIM, "language:%{public}s", options.language.c_str());
68 TAG_LOGD(AAFwkTag::ABILITY_SIM, "region:%{public}s", options.region.c_str());
69 TAG_LOGD(AAFwkTag::ABILITY_SIM, "script:%{public}s", options.script.c_str());
70 TAG_LOGD(AAFwkTag::ABILITY_SIM, "themeId:%{public}d", options.themeId);
71 TAG_LOGD(AAFwkTag::ABILITY_SIM, "deviceWidth:%{public}d", options.deviceWidth);
72 TAG_LOGD(AAFwkTag::ABILITY_SIM, "deviceHeight:%{public}d", options.deviceHeight);
73 TAG_LOGD(AAFwkTag::ABILITY_SIM, "isRound:%{public}d", options.isRound);
74 TAG_LOGD(AAFwkTag::ABILITY_SIM, "compatibleVersion:%{public}d", options.compatibleVersion);
75 TAG_LOGD(AAFwkTag::ABILITY_SIM, "installationFree:%{public}d", options.installationFree);
76 TAG_LOGD(AAFwkTag::ABILITY_SIM, "labelId:%{public}d", options.labelId);
77 TAG_LOGD(AAFwkTag::ABILITY_SIM, "compileMode:%{public}s", options.compileMode.c_str());
78 TAG_LOGD(AAFwkTag::ABILITY_SIM, "pageProfile:%{public}s", options.pageProfile.c_str());
79 TAG_LOGD(AAFwkTag::ABILITY_SIM, "targetVersion:%{public}d", options.targetVersion);
80 TAG_LOGD(AAFwkTag::ABILITY_SIM, "releaseType:%{public}s", options.releaseType.c_str());
81 TAG_LOGD(AAFwkTag::ABILITY_SIM, "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
GetCloudFileDir()134 std::string AbilityContext::GetCloudFileDir()
135 {
136 return stageContext_ ? stageContext_->GetCloudFileDir() : "";
137 }
138
SwitchArea(int mode)139 void AbilityContext::SwitchArea(int mode)
140 {
141 if (stageContext_) {
142 stageContext_->SwitchArea(mode);
143 }
144 }
145
GetArea()146 int AbilityContext::GetArea()
147 {
148 return stageContext_ ? stageContext_->GetArea() : EL_DEFAULT;
149 }
150
GetBaseDir()151 std::string AbilityContext::GetBaseDir()
152 {
153 return stageContext_ ? stageContext_->GetBaseDir() : "";
154 }
155
GetResourceManager() const156 std::shared_ptr<Global::Resource::ResourceManager> AbilityContext::GetResourceManager() const
157 {
158 return resourceMgr_;
159 }
160
SetResourceManager(const std::shared_ptr<Global::Resource::ResourceManager> & resMgr)161 void AbilityContext::SetResourceManager(const std::shared_ptr<Global::Resource::ResourceManager> &resMgr)
162 {
163 resourceMgr_ = resMgr;
164 }
165
SetAbilityStageContext(const std::shared_ptr<AbilityStageContext> & stageContext)166 void AbilityContext::SetAbilityStageContext(const std::shared_ptr<AbilityStageContext> &stageContext)
167 {
168 stageContext_ = stageContext;
169 }
170
IsTerminating()171 bool AbilityContext::IsTerminating()
172 {
173 return isTerminating_;
174 }
175
SetTerminating(const bool & state)176 void AbilityContext::SetTerminating(const bool &state)
177 {
178 isTerminating_ = state;
179 }
180
TerminateSelf()181 int32_t AbilityContext::TerminateSelf()
182 {
183 if (simulator_ != nullptr) {
184 simulator_->TerminateAbility(0);
185 }
186 return 0;
187 }
188
SetSimulator(Simulator * simulator)189 void AbilityContext::SetSimulator(Simulator *simulator)
190 {
191 simulator_ = simulator;
192 }
193 } // namespace AbilityRuntime
194 } // namespace OHOS
195