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_ARKCOMPILER_AOT_ARGS_HANDLER_H 17 #define OHOS_ARKCOMPILER_AOT_ARGS_HANDLER_H 18 19 #include <mutex> 20 #include <string> 21 #include <unordered_set> 22 #include <vector> 23 24 namespace OHOS::ArkCompiler { 25 struct HapArgs { 26 std::vector<std::string> argVector; 27 std::string fileName; 28 std::string signature; 29 int32_t bundleUid {0}; 30 int32_t bundleGid {0}; 31 }; 32 33 class AOTArgsParserBase; 34 35 class AOTArgsHandler { 36 public: 37 AOTArgsHandler(const std::unordered_map<std::string, std::string> &argsMap); 38 39 AOTArgsHandler() = default; 40 ~AOTArgsHandler() = default; 41 42 int32_t Handle(int32_t thermalLevel = 0); 43 44 std::vector<const char*> GetAotArgs() const; 45 46 void GetBundleId(int32_t &bundleUid, int32_t &bundleGid) const; 47 48 std::string GetFileName() const; 49 50 std::string GetCodeSignArgs() const; 51 52 private: 53 std::unique_ptr<AOTArgsParserBase> parser_; 54 const std::unordered_map<std::string, std::string> argsMap_; 55 HapArgs hapArgs_; 56 mutable std::mutex hapArgsMutex_; 57 }; 58 59 class AOTArgsParserBase { 60 public: 61 virtual ~AOTArgsParserBase() = default; 62 63 virtual int32_t Parse(const std::unordered_map<std::string, std::string> &argsMap, HapArgs &hapArgs, 64 int32_t thermalLevel) = 0; 65 66 static int32_t FindArgsIdxToInteger(const std::unordered_map<std::string, std::string> &argsMap, 67 const std::string &keyName, int32_t &bundleID); 68 69 static int32_t FindArgsIdxToString(const std::unordered_map<std::string, std::string> &argsMap, 70 const std::string &keyName, std::string &bundleArg); 71 #ifdef ENABLE_COMPILER_SERVICE_GET_PARAMETER 72 static bool IsEnableStaticCompiler(); 73 #endif 74 }; 75 76 class AOTArgsParser final : public AOTArgsParserBase { 77 public: 78 int32_t Parse(const std::unordered_map<std::string, std::string> &argsMap, HapArgs &hapArgs, 79 int32_t thermalLevel) override; 80 81 void AddExpandArgs(std::vector<std::string> &argVector, int32_t thermalLevel); 82 83 #ifdef ENABLE_COMPILER_SERVICE_GET_PARAMETER 84 void SetAnFileMaxSizeBySysParam(HapArgs &hapArgs); 85 void SetEnableCodeCommentBySysParam(HapArgs &hapArgs); 86 #endif 87 }; 88 89 class StaticAOTArgsParser : public AOTArgsParserBase { 90 public: 91 int32_t Parse(const std::unordered_map<std::string, std::string> &argsMap, HapArgs &hapArgs, 92 int32_t thermalLevel) override; 93 94 bool ParseBootPandaFiles(std::string &bootfiles); 95 96 std::string ParseLocation(std::string &anfilePath); 97 }; 98 99 class StaticFrameworkAOTArgsParser final : public StaticAOTArgsParser { 100 public: 101 int32_t Parse(const std::unordered_map<std::string, std::string> &argsMap, HapArgs &hapArgs, 102 int32_t thermalLevel) override; 103 104 std::string ParseFrameworkBootPandaFiles(const std::string &bootfiles, const std::string &paocPandaFiles); 105 106 bool IsFileExists(const std::string &fileName); 107 }; 108 109 class AOTArgsParserFactory { 110 public: 111 static std::optional<std::unique_ptr<AOTArgsParserBase>> GetParser(const std::unordered_map<std::string, 112 std::string> &argsMap); 113 }; 114 } // namespace OHOS::ArkCompiler 115 #endif // OHOS_ARKCOMPILER_AOT_ARGS_HANDLER_H 116