1 /*
2 * Copyright (c) 2022-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 "js_worker.h"
17
18 #include <cerrno>
19 #include <climits>
20 #include <cstdlib>
21 #include <fstream>
22 #include <unistd.h>
23 #include <vector>
24
25 #include "bundle_mgr_helper.h"
26 #include "connect_server_manager.h"
27 #include "commonlibrary/c_utils/base/include/refbase.h"
28 #ifdef SUPPORT_GRAPHICS
29 #include "core/common/container_scope.h"
30 #endif
31 #include "declarative_module_preloader.h"
32
33 #include "extractor.h"
34 #include "file_mapper.h"
35 #include "foundation/bundlemanager/bundle_framework/interfaces/inner_api/appexecfwk_base/include/bundle_info.h"
36 #include "foundation/bundlemanager/bundle_framework/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_proxy.h"
37 #include "foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy/include/iservice_registry.h"
38 #include "foundation/communication/ipc/interfaces/innerkits/ipc_core/include/iremote_object.h"
39 #include "singleton.h"
40 #include "system_ability_definition.h"
41 #include "hilog_tag_wrapper.h"
42 #include "js_runtime_utils.h"
43 #include "native_engine/impl/ark/ark_native_engine.h"
44 #include "commonlibrary/ets_utils/js_sys_module/console/console.h"
45 #include "syscap_ts.h"
46 #ifdef SUPPORT_GRAPHICS
47 using OHOS::Ace::ContainerScope;
48 #endif
49
50 namespace OHOS {
51 namespace AbilityRuntime {
52 namespace {
53 constexpr int64_t ASSET_FILE_MAX_SIZE = 32 * 1024 * 1024;
54 constexpr int32_t API8 = 8;
55 constexpr int32_t API12 = 12;
56 const std::string BUNDLE_NAME_FLAG = "@bundle:";
57 const std::string CACHE_DIRECTORY = "el2";
58 const std::string RESTRICTED_PREFIX_PATH = "abcs/";
59 const int PATH_THREE = 3;
60 #ifdef APP_USE_ARM
61 constexpr char ARK_DEBUGGER_LIB_PATH[] = "/system/lib/platformsdk/libark_inspector.z.so";
62 #elif defined(APP_USE_X86_64)
63 constexpr char ARK_DEBUGGER_LIB_PATH[] = "/system/lib64/platformsdk/libark_inspector.z.so";
64 #else
65 constexpr char ARK_DEBUGGER_LIB_PATH[] = "/system/lib64/platformsdk/libark_inspector.z.so";
66 #endif
67
68 bool g_debugMode = false;
69 bool g_debugApp = false;
70 bool g_jsFramework = false;
71 bool g_nativeStart = false;
72 std::mutex g_mutex;
73 }
74
InitWorkerFunc(NativeEngine * nativeEngine)75 void InitWorkerFunc(NativeEngine* nativeEngine)
76 {
77 TAG_LOGD(AAFwkTag::JSRUNTIME, "called");
78 if (nativeEngine == nullptr) {
79 TAG_LOGE(AAFwkTag::JSRUNTIME, "null nativeEngine");
80 return;
81 }
82
83 napi_value globalObj = nullptr;
84 napi_get_global(reinterpret_cast<napi_env>(nativeEngine), &globalObj);
85 if (globalObj == nullptr) {
86 TAG_LOGE(AAFwkTag::JSRUNTIME, "Failed to get global object");
87 return;
88 }
89
90 InitSyscapModule(reinterpret_cast<napi_env>(nativeEngine));
91 OHOS::JsSysModule::Console::InitConsoleModule(reinterpret_cast<napi_env>(nativeEngine));
92 OHOS::Ace::DeclarativeModulePreloader::PreloadWorker(*nativeEngine);
93
94 auto arkNativeEngine = static_cast<ArkNativeEngine*>(nativeEngine);
95 // load jsfwk
96 if (g_jsFramework && !arkNativeEngine->ExecuteJsBin("/system/etc/strip.native.min.abc")) {
97 TAG_LOGE(AAFwkTag::JSRUNTIME, "load jsframework failed");
98 }
99
100 if (g_debugMode) {
101 auto instanceId = DFXJSNApi::GetCurrentThreadId();
102 std::string instanceName = "workerThread_" + std::to_string(instanceId);
103 bool needBreakPoint = ConnectServerManager::Get().AddInstance(instanceId, instanceId, instanceName);
104 if (g_nativeStart) {
105 TAG_LOGE(AAFwkTag::JSRUNTIME, "native: true, set needBreakPoint: false");
106 needBreakPoint = false;
107 }
108 auto workerPostTask = [nativeEngine](std::function<void()>&& callback) {
109 nativeEngine->CallDebuggerPostTaskFunc(std::move(callback));
110 };
111 panda::JSNApi::DebugOption debugOption = {ARK_DEBUGGER_LIB_PATH, needBreakPoint};
112 auto vm = const_cast<EcmaVM*>(arkNativeEngine->GetEcmaVm());
113 ConnectServerManager::Get().StoreDebuggerInfo(
114 instanceId, reinterpret_cast<void*>(vm), debugOption, workerPostTask, g_debugApp);
115
116 panda::JSNApi::NotifyDebugMode(instanceId, vm, debugOption, instanceId, workerPostTask, g_debugApp);
117 }
118 }
119
OffWorkerFunc(NativeEngine * nativeEngine)120 void OffWorkerFunc(NativeEngine* nativeEngine)
121 {
122 TAG_LOGD(AAFwkTag::JSRUNTIME, "called");
123 if (nativeEngine == nullptr) {
124 TAG_LOGE(AAFwkTag::JSRUNTIME, "null nativeEngine");
125 return;
126 }
127
128 if (g_debugMode) {
129 auto instanceId = DFXJSNApi::GetCurrentThreadId();
130 ConnectServerManager::Get().RemoveInstance(instanceId);
131 auto arkNativeEngine = static_cast<ArkNativeEngine*>(nativeEngine);
132 auto vm = const_cast<EcmaVM*>(arkNativeEngine->GetEcmaVm());
133 panda::JSNApi::StopDebugger(vm);
134 }
135 }
136
137
138 using Extractor = AbilityBase::Extractor;
139 using ExtractorUtil = AbilityBase::ExtractorUtil;
140 using FileMapper = AbilityBase::FileMapper;
141 using FileMapperType = AbilityBase::FileMapperType;
142 using IBundleMgr = AppExecFwk::IBundleMgr;
143
NormalizedFileName(const std::string & fileName) const144 std::string AssetHelper::NormalizedFileName(const std::string& fileName) const
145 {
146 std::string normalizedFilePath;
147 size_t index = 0;
148 index = fileName.find_last_of(".");
149 // 1.1 end with file name
150 // 1.2 end with file name and file type
151 if (index == std::string::npos) {
152 TAG_LOGD(AAFwkTag::JSRUNTIME, "uri end without file type");
153 normalizedFilePath = fileName + ".abc";
154 } else {
155 TAG_LOGD(AAFwkTag::JSRUNTIME, "uri end with file type");
156 normalizedFilePath = fileName.substr(0, index) + ".abc";
157 }
158 return normalizedFilePath;
159 }
160
~AssetHelper()161 AssetHelper::~AssetHelper()
162 {
163 TAG_LOGD(AAFwkTag::JSRUNTIME, "destroyed");
164 if (fd_ != -1) {
165 close(fd_);
166 fd_ = -1;
167 }
168 }
169
operator ()(const std::string & uri,uint8_t ** buff,size_t * buffSize,std::vector<uint8_t> & content,std::string & ami,bool & useSecureMem,bool isRestricted)170 void AssetHelper::operator()(const std::string& uri, uint8_t** buff, size_t* buffSize, std::vector<uint8_t>& content,
171 std::string& ami, bool& useSecureMem, bool isRestricted)
172 {
173 if (uri.empty() || buff == nullptr || buffSize == nullptr || workerInfo_ == nullptr) {
174 TAG_LOGE(AAFwkTag::JSRUNTIME, "Input params invalid");
175 return;
176 }
177
178 TAG_LOGD(AAFwkTag::JSRUNTIME, "RegisterAssetFunc called, uri: %{private}s", uri.c_str());
179 std::string realPath;
180 std::string filePath;
181 useSecureMem = false;
182
183 // 1. compilemode is jsbundle
184 // 2. compilemode is esmodule
185 if (workerInfo_->isBundle) {
186 // the @bundle:bundlename/modulename only exist in esmodule.
187 // 1.1 start with /modulename
188 // 1.2 start with ../
189 // 1.3 start with @namespace [not support]
190 // 1.4 start with modulename
191 TAG_LOGD(AAFwkTag::JSRUNTIME, "esmodule mode");
192 if (uri.find_first_of("/") == 0) {
193 TAG_LOGD(AAFwkTag::JSRUNTIME, "uri start with /modulename");
194 realPath = uri.substr(1);
195 } else if (uri.find("../") == 0 && !GetIsStageModel()) {
196 TAG_LOGD(AAFwkTag::JSRUNTIME, "uri start with ../");
197 realPath = uri.substr(PATH_THREE);
198 } else if (uri.find_first_of("@") == 0) {
199 TAG_LOGD(AAFwkTag::JSRUNTIME, "uri start with @namespace");
200 realPath = uri.substr(uri.find_first_of("/") + 1);
201 } else {
202 TAG_LOGD(AAFwkTag::JSRUNTIME, "uri start with modulename");
203 realPath = uri;
204 }
205
206 filePath = NormalizedFileName(realPath);
207 TAG_LOGI(AAFwkTag::JSRUNTIME, "filePath %{private}s", filePath.c_str());
208
209 if (!GetIsStageModel()) {
210 GetAmi(ami, filePath);
211 } else {
212 ami = (workerInfo_->codePath).GetOriginString() + filePath;
213 }
214
215 TAG_LOGD(AAFwkTag::JSRUNTIME, "Get asset, ami: %{private}s", ami.c_str());
216 if (ami.find(CACHE_DIRECTORY) != std::string::npos) {
217 if (!ReadAmiData(ami, buff, buffSize, content, useSecureMem, isRestricted)) {
218 TAG_LOGE(AAFwkTag::JSRUNTIME, "Get buffer by ami failed");
219 }
220 } else if (!ReadFilePathData(filePath, buff, buffSize, content, useSecureMem, isRestricted)) {
221 TAG_LOGE(AAFwkTag::JSRUNTIME, "Get buffer by filepath failed");
222 }
223 } else {
224 // 2.1 start with @bundle:bundlename/modulename
225 // 2.2 start with /modulename
226 // 2.3 start with @namespace
227 // 2.4 start with modulename
228 TAG_LOGD(AAFwkTag::JSRUNTIME, "esmodule mode");
229 if (uri.find(BUNDLE_NAME_FLAG) == 0) {
230 TAG_LOGD(AAFwkTag::JSRUNTIME, "uri start with @bundle:");
231 size_t fileNamePos = uri.find_last_of("/");
232 realPath = uri.substr(fileNamePos + 1);
233 if (realPath.find_last_of(".") != std::string::npos) {
234 ami = NormalizedFileName(uri);
235 } else {
236 ami = uri;
237 }
238 TAG_LOGD(AAFwkTag::JSRUNTIME, "Get asset, ami: %{private}s", ami.c_str());
239 return;
240 } else if (uri.find_first_of("/") == 0) {
241 TAG_LOGD(AAFwkTag::JSRUNTIME, "uri start with /modulename");
242 realPath = uri.substr(1);
243 } else if (uri.find_first_of("@") == 0) {
244 TAG_LOGD(AAFwkTag::JSRUNTIME, "uri start with @namespace");
245 realPath = workerInfo_->moduleName + uri;
246 } else {
247 TAG_LOGD(AAFwkTag::JSRUNTIME, "uri start with modulename");
248 realPath = uri;
249 }
250
251 filePath = NormalizedFileName(realPath);
252 // for safe reason, filePath must starts with 'abcs/' in restricted env
253 if (isRestricted && filePath.find(RESTRICTED_PREFIX_PATH)
254 && (static_cast<int32_t>(workerInfo_->apiTargetVersion.GetOriginPointer())) >= API12) {
255 filePath = RESTRICTED_PREFIX_PATH + filePath;
256 }
257 ami = (workerInfo_->codePath).GetOriginString() + filePath;
258 TAG_LOGD(AAFwkTag::JSRUNTIME, "Get asset, ami: %{private}s", ami.c_str());
259 if (ami.find(CACHE_DIRECTORY) != std::string::npos) {
260 if (!ReadAmiData(ami, buff, buffSize, content, useSecureMem, isRestricted)) {
261 TAG_LOGE(AAFwkTag::JSRUNTIME, "Get buffer by ami failed");
262 }
263 } else if (!ReadFilePathData(filePath, buff, buffSize, content, useSecureMem, isRestricted)) {
264 TAG_LOGE(AAFwkTag::JSRUNTIME, "Get buffer by filepath failed");
265 }
266 }
267 }
268
GetSafeData(const std::string & ami,uint8_t ** buff,size_t * buffSize)269 bool AssetHelper::GetSafeData(const std::string& ami, uint8_t** buff, size_t* buffSize)
270 {
271 TAG_LOGD(AAFwkTag::JSRUNTIME, "called");
272 std::string resolvedPath;
273 resolvedPath.reserve(PATH_MAX);
274 resolvedPath.resize(PATH_MAX - 1);
275 if (realpath(ami.c_str(), &(resolvedPath[0])) == nullptr) {
276 TAG_LOGE(AAFwkTag::JSRUNTIME, "Realpath file %{private}s caught error: %{public}d", ami.c_str(), errno);
277 return false;
278 }
279
280 int fd = open(resolvedPath.c_str(), O_RDONLY);
281 if (fd < 0) {
282 TAG_LOGE(AAFwkTag::JSRUNTIME, "Open file %{private}s caught error: %{public}d", resolvedPath.c_str(), errno);
283 return false;
284 }
285
286 struct stat statbuf;
287 if (fstat(fd, &statbuf) < 0) {
288 TAG_LOGE(AAFwkTag::JSRUNTIME, "Get fstat of file %{private}s caught error: %{public}d", resolvedPath.c_str(),
289 errno);
290 close(fd);
291 return false;
292 }
293
294 std::unique_ptr<FileMapper> fileMapper = std::make_unique<FileMapper>();
295 if (fileMapper == nullptr) {
296 TAG_LOGE(AAFwkTag::JSRUNTIME, "Create file mapper failed");
297 close(fd);
298 return false;
299 }
300
301 auto result = fileMapper->CreateFileMapper(resolvedPath, false, fd, 0, statbuf.st_size, FileMapperType::SAFE_ABC);
302 if (!result) {
303 TAG_LOGE(AAFwkTag::JSRUNTIME, "Create file %{private}s mapper failed", resolvedPath.c_str());
304 close(fd);
305 return false;
306 }
307
308 *buff = fileMapper->GetDataPtr();
309 *buffSize = fileMapper->GetDataLen();
310 fd_ = fd;
311 return true;
312 }
313
ReadAmiData(const std::string & ami,uint8_t ** buff,size_t * buffSize,std::vector<uint8_t> & content,bool & useSecureMem,bool isRestricted)314 bool AssetHelper::ReadAmiData(const std::string& ami, uint8_t** buff, size_t* buffSize, std::vector<uint8_t>& content,
315 bool& useSecureMem, bool isRestricted)
316 {
317 // Current function is a private, validity of workerInfo_ has been checked by caller.
318 int32_t apiTargetVersion = static_cast<int32_t>(workerInfo_->apiTargetVersion.GetOriginPointer());
319 bool apiSatisfy = apiTargetVersion == 0 || apiTargetVersion > API8;
320 if (GetIsStageModel() && !isRestricted && apiSatisfy) {
321 if (apiTargetVersion >= API12) {
322 useSecureMem = true;
323 return GetSafeData(ami, buff, buffSize);
324 } else if (GetSafeData(ami, buff, buffSize)) {
325 useSecureMem = true;
326 return true;
327 } else {
328 // If api version less than 12 and get secure mem failed, try get normal mem.
329 TAG_LOGW(AAFwkTag::JSRUNTIME, "Get secure mem failed, file %{private}s", ami.c_str());
330 }
331 }
332
333 char path[PATH_MAX];
334 if (realpath(ami.c_str(), path) == nullptr) {
335 TAG_LOGE(AAFwkTag::JSRUNTIME, "Realpath file %{private}s caught error: %{public}d", ami.c_str(), errno);
336 return false;
337 }
338
339 std::ifstream stream(path, std::ios::binary | std::ios::ate);
340 if (!stream.is_open()) {
341 TAG_LOGE(AAFwkTag::JSRUNTIME, "Failed to open file %{private}s", ami.c_str());
342 return false;
343 }
344
345 auto fileLen = stream.tellg();
346 if (!workerInfo_->isDebugVersion && fileLen > ASSET_FILE_MAX_SIZE) {
347 TAG_LOGE(AAFwkTag::JSRUNTIME, "File too large");
348 return false;
349 }
350
351 if (fileLen <= 0) {
352 TAG_LOGE(AAFwkTag::JSRUNTIME, "Invalid file length");
353 return false;
354 }
355
356 content.resize(fileLen);
357 stream.seekg(0);
358 stream.read(reinterpret_cast<char*>(content.data()), content.size());
359 return true;
360 }
361
ReadFilePathData(const std::string & filePath,uint8_t ** buff,size_t * buffSize,std::vector<uint8_t> & content,bool & useSecureMem,bool isRestricted)362 bool AssetHelper::ReadFilePathData(const std::string& filePath, uint8_t** buff, size_t* buffSize,
363 std::vector<uint8_t>& content, bool& useSecureMem, bool isRestricted)
364 {
365 auto bundleMgrHelper = DelayedSingleton<AppExecFwk::BundleMgrHelper>::GetInstance();
366 if (bundleMgrHelper == nullptr) {
367 TAG_LOGE(AAFwkTag::JSRUNTIME, "null bundleMgrHelper");
368 return false;
369 }
370
371 AppExecFwk::BundleInfo bundleInfo;
372 auto getInfoResult = bundleMgrHelper->GetBundleInfoForSelf(
373 static_cast<int32_t>(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE), bundleInfo);
374 if (getInfoResult != 0) {
375 TAG_LOGE(AAFwkTag::JSRUNTIME, "GetBundleInfoForSelf failed");
376 return false;
377 }
378 if (bundleInfo.hapModuleInfos.size() == 0) {
379 TAG_LOGE(AAFwkTag::JSRUNTIME, "Get hapModuleInfo of bundleInfo failed");
380 return false;
381 }
382
383 std::string newHapPath;
384 size_t pos = filePath.find('/');
385 if (!GetIsStageModel()) {
386 newHapPath = (workerInfo_->hapPath).GetOriginString();
387 } else {
388 for (auto hapModuleInfo : bundleInfo.hapModuleInfos) {
389 if (hapModuleInfo.moduleName == filePath.substr(0, pos)) {
390 newHapPath = hapModuleInfo.hapPath;
391 break;
392 }
393 }
394 }
395 TAG_LOGD(AAFwkTag::JSRUNTIME, "HapPath: %{private}s", newHapPath.c_str());
396 bool newCreate = false;
397 std::string loadPath = ExtractorUtil::GetLoadFilePath(newHapPath);
398 std::shared_ptr<Extractor> extractor = ExtractorUtil::GetExtractor(loadPath, newCreate);
399 if (extractor == nullptr) {
400 TAG_LOGE(AAFwkTag::JSRUNTIME, "LoadPath %{private}s GetExtractor failed", loadPath.c_str());
401 return false;
402 }
403 std::unique_ptr<uint8_t[]> dataPtr = nullptr;
404 std::string realfilePath;
405 size_t fileLen = 0;
406 if (!GetIsStageModel()) {
407 bool flag = false;
408 for (const auto& basePath : workerInfo_->assetBasePathStr) {
409 realfilePath = basePath + filePath;
410 TAG_LOGD(AAFwkTag::JSRUNTIME, "realfilePath: %{private}s", realfilePath.c_str());
411 if (extractor->ExtractToBufByName(realfilePath, dataPtr, fileLen)) {
412 flag = true;
413 break;
414 }
415 }
416 if (!flag) {
417 TAG_LOGE(AAFwkTag::JSRUNTIME, "ExtractToBufByName error");
418 return flag;
419 }
420 } else {
421 realfilePath = filePath.substr(pos + 1);
422 TAG_LOGD(AAFwkTag::JSRUNTIME, "realfilePath: %{private}s", realfilePath.c_str());
423 int32_t apiTargetVersion = static_cast<int32_t>(workerInfo_->apiTargetVersion.GetOriginPointer());
424 bool apiSatisfy = apiTargetVersion == 0 || apiTargetVersion > API8;
425 if (GetIsStageModel() && !isRestricted && apiSatisfy && !extractor->IsHapCompress(realfilePath)) {
426 TAG_LOGD(AAFwkTag::JSRUNTIME, "Use secure mem.");
427 auto safeData = extractor->GetSafeData(realfilePath);
428 if (apiTargetVersion >= API12) {
429 useSecureMem = true;
430 if (safeData == nullptr) {
431 TAG_LOGE(AAFwkTag::JSRUNTIME, "Get secure mem failed, file %{private}s", filePath.c_str());
432 return false;
433 }
434 *buff = safeData->GetDataPtr();
435 *buffSize = safeData->GetDataLen();
436 return true;
437 } else if (safeData != nullptr) {
438 useSecureMem = true;
439 *buff = safeData->GetDataPtr();
440 *buffSize = safeData->GetDataLen();
441 return true;
442 } else {
443 // If api version less than 12 and get secure mem failed, try get normal mem.
444 TAG_LOGW(AAFwkTag::JSRUNTIME, "Get secure mem failed, file %{private}s", filePath.c_str());
445 }
446 }
447 if (!extractor->ExtractToBufByName(realfilePath, dataPtr, fileLen)) {
448 TAG_LOGE(AAFwkTag::JSRUNTIME, "get mergeAbc fileBuffer failed");
449 return false;
450 }
451 }
452
453 if (!workerInfo_->isDebugVersion && fileLen > ASSET_FILE_MAX_SIZE) {
454 TAG_LOGE(AAFwkTag::JSRUNTIME, "ReadFilePathData failed, file is too large");
455 return false;
456 }
457
458 content.assign(dataPtr.get(), dataPtr.get() + fileLen);
459 return true;
460 }
461
GetAmi(std::string & ami,const std::string & filePath)462 void AssetHelper::GetAmi(std::string& ami, const std::string& filePath)
463 {
464 size_t slashPos = filePath.find_last_of("/");
465 std::string fileName = filePath.substr(slashPos + 1);
466 std::string path = filePath.substr(0, slashPos + 1);
467
468 std::string loadPath = ExtractorUtil::GetLoadFilePath((workerInfo_->hapPath).GetOriginString());
469 bool newCreate = false;
470 std::shared_ptr<Extractor> extractor = ExtractorUtil::GetExtractor(loadPath, newCreate);
471 if (extractor == nullptr) {
472 TAG_LOGE(AAFwkTag::JSRUNTIME, "loadPath %{private}s GetExtractor failed", loadPath.c_str());
473 return;
474 }
475 std::vector<std::string> files;
476 for (const auto& basePath : workerInfo_->assetBasePathStr) {
477 std::string assetPath = basePath + path;
478 TAG_LOGI(AAFwkTag::JSRUNTIME, "assetPath: %{private}s", assetPath.c_str());
479 bool res = extractor->IsDirExist(assetPath);
480 if (!res) {
481 continue;
482 }
483 res = extractor->GetFileList(assetPath, files);
484 if (!res) {
485 continue;
486 }
487 }
488
489 std::string targetFilePath;
490 bool flag = false;
491 for (const auto& file : files) {
492 size_t filePos = file.find_last_of("/");
493 if (filePos != std::string::npos) {
494 if (file.substr(filePos + 1) == fileName) {
495 targetFilePath = path + fileName;
496 flag = true;
497 break;
498 }
499 }
500 }
501
502 TAG_LOGD(AAFwkTag::JSRUNTIME, "targetFilePath %{private}s", targetFilePath.c_str());
503
504 if (!flag) {
505 TAG_LOGE(AAFwkTag::JSRUNTIME, "get targetFilePath failed");
506 return;
507 }
508
509 for (const auto& basePath : workerInfo_->assetBasePathStr) {
510 std::string filePathName = basePath + targetFilePath;
511 bool hasFile = extractor->HasEntry(filePathName);
512 if (hasFile) {
513 ami = (workerInfo_->hapPath).GetOriginString() + "/" + filePathName;
514 return;
515 }
516 }
517 }
518
GetIsStageModel()519 bool AssetHelper::GetIsStageModel()
520 {
521 bool stageModule = workerInfo_->isStageModel.GetBool();
522 TAG_LOGI(AAFwkTag::JSRUNTIME, "stagemodule: %{public}d", stageModule);
523 return stageModule;
524 }
525
GetContainerId()526 int32_t GetContainerId()
527 {
528 #ifdef SUPPORT_GRAPHICS
529 int32_t scopeId = ContainerScope::CurrentId();
530 return scopeId;
531 #else
532 constexpr int32_t containerScopeDefaultId = 0;
533 return containerScopeDefaultId;
534 #endif
535 }
UpdateContainerScope(int32_t id)536 void UpdateContainerScope(int32_t id)
537 {
538 #ifdef SUPPORT_GRAPHICS
539 ContainerScope::UpdateCurrent(id);
540 #endif
541 }
RestoreContainerScope(int32_t id)542 void RestoreContainerScope(int32_t id)
543 {
544 #ifdef SUPPORT_GRAPHICS
545 ContainerScope::UpdateCurrent(-1);
546 #endif
547 }
548
StartDebuggerInWorkerModule(bool isDebugApp,bool isNativeStart)549 void StartDebuggerInWorkerModule(bool isDebugApp, bool isNativeStart)
550 {
551 g_debugMode = true;
552 g_debugApp = isDebugApp;
553 g_nativeStart = isNativeStart;
554 }
555
SetJsFramework()556 void SetJsFramework()
557 {
558 g_jsFramework = true;
559 }
560 } // namespace AbilityRuntime
561 } // namespace OHOS
562