• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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_HYBRID_JS_MODULE_READER_H
17 #define OHOS_ABILITY_RUNTIME_HYBRID_JS_MODULE_READER_H
18 
19 #include <sstream>
20 #include <string>
21 
22 #include "js_module_searcher.h"
23 #include "extractor.h"
24 
25 using Extractor = OHOS::AbilityBase::Extractor;
26 
27 namespace OHOS {
28 namespace AbilityRuntime {
29 class HybridJsModuleReader final : private JsModuleSearcher {
30 public:
31     static constexpr char ABS_CODE_PATH[] = "/data/storage/el1/";
32     static constexpr char ABS_DATA_CODE_PATH[] = "/data/app/el1/bundle/public/";
33     static constexpr char BUNDLE[] = "bundle/";
34     static constexpr char MERGE_ABC_PATH[] = "ets/modules.abc";
35     static constexpr char SYS_ABS_CODE_PATH[] = "/system/app/appServiceFwk/";
36     static constexpr char SHARED_FILE_SUFFIX[] = ".hsp";
37     static constexpr char ABILITY_FILE_SUFFIX[] = ".hap";
38     HybridJsModuleReader(const std::string& bundleName, const std::string& hapPath, bool isFormRender = false);
39     ~HybridJsModuleReader() = default;
40 
41     HybridJsModuleReader(const HybridJsModuleReader&) = default;
42     HybridJsModuleReader(HybridJsModuleReader&&) = default;
43     HybridJsModuleReader& operator=(const HybridJsModuleReader&) = default;
44     HybridJsModuleReader& operator=(HybridJsModuleReader&&) = default;
45 
46     bool operator()(const std::string& inputPath, uint8_t **buff, size_t *buffSize, std::string& errorMsg) const;
47     static std::string GetPresetAppHapPath(const std::string& inputPath, const std::string& bundleName);
48 
49 private:
50     std::string GetAppPath(const std::string& inputPath, const std::string& suffix) const;
51     std::string GetCommonAppPath(const std::string& inputPath, const std::string& suffix) const;
52     std::string GetFormAppPath(const std::string& inputPath, const std::string& suffix) const;
53     std::string GetModuleName(const std::string& inputPath) const;
54     std::string GetPluginHspPath(const std::string& inputPath) const;
55     std::shared_ptr<Extractor> GetExtractor(const std::string& inputPath, std::string& errorMsg) const;
56     static std::string GetOtherHspPath(const std::string& bundleName, const std::string& moduleName,
57         const std::string& inputPath);
58 
59     bool isSystemPath_ = false;
60     bool isFormRender_ = false;
61     static bool needFindPluginHsp_;
62 };
63 } // namespace AbilityRuntime
64 } // namespace OHOS
65 
66 #endif // OHOS_ABILITY_RUNTIME_HYBRID_JS_MODULE_READER_H
67