1 /* 2 * Copyright (c) 2024 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 DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_FAST_APP_PACKAGER_H 17 #define DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_FAST_APP_PACKAGER_H 18 19 #include <iostream> 20 #include <list> 21 #include <map> 22 #include <set> 23 #include <string> 24 25 #include "packager.h" 26 #include "zip_wrapper.h" 27 28 namespace OHOS { 29 namespace AppPackingTool { 30 class FastAppPackager : public Packager { 31 public: 32 FastAppPackager(const std::map<std::string, std::string> ¶meterMap, std::string &resultReceiver); ~FastAppPackager()33 ~FastAppPackager() override {} 34 bool IsVerifyValidInFastAppMode(); 35 bool FormatPath(); 36 bool IsVerifyValid(); 37 bool IsFormatPathValid(const std::string &inputPath, std::list<std::string> &formattedPathList); 38 bool IsHapPathValid(const std::list<std::string> &formatPathList); 39 bool IsHspPathValid(const std::list<std::string> &formatPathList, const std::string &hspSuffix); 40 bool ModuleJsonAndPackInfoExists(const std::list<std::string> &hapPathList, 41 const std::list<std::string> &hspPathList); 42 bool CheckBundleTypeConsistency(const std::list<std::string> &hapPathList, 43 const std::list<std::string> &hspPathList); 44 bool IsPackInfoValid(const fs::path &packInfo, const std::list<std::string> &hapPathList, 45 const std::list<std::string> &hspPathList); 46 bool IsPackInfoPathListValid(const std::list<std::string> &pathList, std::set<std::string> &packages, 47 const std::set<std::string> &allPackageSet); 48 bool GetPackageNameFromPath(const fs::path &path, std::list<std::string> &packageNameList); 49 bool CompressFastAppMode(); 50 bool CheckHapAndPackFastApp(std::list<std::string> &fileList, const fs::path &tmpDir); 51 bool Pack(const std::string &tmpDir, std::list<std::string> &fileList); 52 bool Pack(const fs::path &inputPath, const fs::path &appPackInfo, const fs::path &outPath, fs::path &path); 53 bool PackDir(const fs::path &inputPath, const fs::path &appPackInfo, const fs::path &outPath, fs::path &path); 54 bool RepackHsp(const fs::path &inputPath, const fs::path &appPackInfo, const fs::path &outPath, fs::path &path); 55 bool PackFastApp(const std::list<std::string> &fileList); 56 bool AddHapListToApp(const std::list<std::string> &fileList); 57 bool AddSignatureAndCertificateToApp(); 58 bool packSingleThread(const fs::path &inputPath, const fs::path &appPackInfo, 59 const fs::path &outHap, fs::path &path); 60 bool AddOtherFileToZip(const fs::path &inputPath); 61 bool packMultiThread(const fs::path &inputPath, const fs::path &appPackInfo, 62 const fs::path &outHap, fs::path &path); 63 void GenBuildHash(const fs::path &inputPath, std::string &jsonString); 64 std::string GetBundleTypeFromPath(const std::string &filePath); 65 std::string GetModuleJsonContentFromPath(const fs::path &path); 66 std::string ReadFileToString(const fs::path &path); 67 std::string GetBundleTypeFromModuleJson(const std::string &moduleJsonContent); 68 std::string GetPackInfoContentFromPath(const fs::path &path); 69 std::string UzipHspAndRemovePackInfo(const std::string& hspPath, const std::string& unzipPathString); 70 71 protected: 72 int32_t InitAllowedParam() override; 73 int32_t PreProcess() override; 74 int32_t Process() override; 75 int32_t PostProcess() override; 76 77 private: 78 bool isSharedApp_ = false; 79 bool compressNativeLibs_ = false; 80 bool isGenerateBuildHash_ = false; 81 std::string packInfoPath_; 82 std::list<std::string> formattedEntryCardPathList_; 83 std::list<std::string> formattedHapPathList_; 84 std::list<std::string> formattedHspPathList_; 85 ZipWrapper zipWrapper_; 86 }; 87 } // namespace AppExecFwk 88 } // namespace OHOS 89 #endif // DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_FAST_APP_PACKAGER_H