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