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