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 #ifndef OHOS_ABILITY_RUNTIME_JS_WORKER_H 17 #define OHOS_ABILITY_RUNTIME_JS_WORKER_H 18 19 #include <string> 20 #include "bundle_mgr_proxy.h" 21 #include "js_environment_impl.h" 22 #include "native_engine/native_engine.h" 23 24 namespace OHOS { 25 namespace AbilityRuntime { 26 void InitWorkerFunc(NativeEngine* nativeEngine); 27 void OffWorkerFunc(NativeEngine* nativeEngine); 28 void ReleaseWorkerSafeMemFunc(void* mapper); 29 int32_t GetContainerId(); 30 void UpdateContainerScope(int32_t id); 31 void RestoreContainerScope(int32_t id); 32 void SetJsFramework(); 33 34 class AssetHelper final { 35 public: 36 explicit AssetHelper(std::shared_ptr<JsEnv::WorkerInfo> workerInfo); 37 38 virtual ~AssetHelper(); 39 40 void operator()(const std::string& uri, uint8_t** buff, size_t* buffSize, std::vector<uint8_t>& content, 41 std::string& ami, bool& useSecureMem, void** mapper, bool isRestricted = false); 42 43 private: 44 std::string NormalizedFileName(const std::string& fileName) const; 45 46 bool ReadAmiData(const std::string& ami, uint8_t** buff, size_t* buffSize, std::vector<uint8_t>& content, 47 bool& useSecureMem, bool isRestricted, void** mapper); 48 49 bool ReadFilePathData(const std::string& filePath, uint8_t** buff, size_t* buffSize, std::vector<uint8_t>& content, 50 bool& useSecureMem, bool isRestricted, void** mapper); 51 52 void GetAmi(std::string& ami, const std::string& filePath); 53 54 bool GetSafeData(const std::string& ami, uint8_t** buff, size_t* buffSize, void** mapper); 55 56 bool GetIsStageModel(); 57 58 std::shared_ptr<JsEnv::WorkerInfo> workerInfo_ = nullptr; 59 FILE *file_ = nullptr; 60 }; 61 62 } // namespace AbilityRuntime 63 } // namespace OHOS 64 65 #endif // OHOS_ABILITY_RUNTIME_JS_WORKER_H