• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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_MODULE_READER_H
17 #define OHOS_ABILITY_RUNTIME_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 JsModuleReader 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 SHARED_FILE_SUFFIX[] = ".hsp";
36     JsModuleReader(const std::string& bundleName, const std::string& hapPath, bool isFormRender = false);
37     ~JsModuleReader() = default;
38 
39     JsModuleReader(const JsModuleReader&) = default;
40     JsModuleReader(JsModuleReader&&) = default;
41     JsModuleReader& operator=(const JsModuleReader&) = default;
42     JsModuleReader& operator=(JsModuleReader&&) = default;
43 
44     bool operator()(const std::string& inputPath, uint8_t **buff, size_t *buffSize) const;
45     std::string GetPresetAppHapPath(const std::string& inputPath) const;
46 
47 private:
48     std::string GetAppHspPath(const std::string& inputPath) const;
49     std::string GetCommonAppHspPath(const std::string& inputPath) const;
50     std::string GetFormAppHspPath(const std::string& inputPath) const;
51     std::string GetModuleName(const std::string& inputPath) const;
52 
53     bool isSystemPath_ = false;
54     bool isFormRender_ = false;
55 };
56 } // namespace AbilityRuntime
57 } // namespace OHOS
58 
59 #endif // OHOS_ABILITY_RUNTIME_JS_MODULE_READER_H
60