1 /* 2 * Copyright (c) 2023-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 FOUNDATION_BUNDLE_FRAMEWORK_AOT_AOT_HANDLER 17 #define FOUNDATION_BUNDLE_FRAMEWORK_AOT_AOT_HANDLER 18 19 #include <mutex> 20 #include <optional> 21 #include <string> 22 #include <unordered_map> 23 24 #include "aot/aot_args.h" 25 #include "bundle_mgr_service.h" 26 #include "event_report.h" 27 #include "inner_bundle_info.h" 28 #include "nocopyable.h" 29 #include "serial_queue.h" 30 31 namespace OHOS { 32 namespace AppExecFwk { 33 class AOTHandler final { 34 public: 35 static AOTHandler& GetInstance(); 36 static std::string BuildArkProfilePath( 37 const int32_t userId, const std::string &bundleName = "", const std::string &moduleName = ""); 38 void HandleInstall(const std::unordered_map<std::string, InnerBundleInfo> &infos) const; 39 void HandleOTA(); 40 void HandleIdle() const; 41 ErrCode HandleCompile(const std::string &bundleName, const std::string &compileMode, bool isAllBundle, 42 std::vector<std::string> &compileResults) const; 43 void HandleResetAOT(const std::string &bundleName, bool isAllBundle) const; 44 ErrCode HandleCopyAp(const std::string &bundleName, bool isAllBundle, std::vector<std::string> &results) const; 45 private: 46 AOTHandler(); 47 ~AOTHandler() = default; 48 DISALLOW_COPY_AND_MOVE(AOTHandler); 49 50 ErrCode MkApDestDirIfNotExist() const; 51 void CopyApWithBundle(const std::string &bundleName, const BundleInfo &bundleInfo, 52 const int32_t userId, std::vector<std::string> &results) const; 53 std::string GetSouceAp(const std::string &mergedAp, const std::string &rtAp) const; 54 bool IsSupportARM64() const; 55 std::string FindArkProfilePath(const std::string &bundleName, const std::string &moduleName) const; 56 std::optional<AOTArgs> BuildAOTArgs(const InnerBundleInfo &info, const std::string &moduleName, 57 const std::string &compileMode, bool isEnableBaselinePgo = false) const; 58 void HandleInstallWithSingleHap(const InnerBundleInfo &info, const std::string &compileMode) const; 59 bool NeedCompile(const InnerBundleInfo &info, const std::string &moduleName) const; 60 ErrCode HandleCompileWithSingleHap(const InnerBundleInfo &info, const std::string &moduleName, 61 const std::string &compileMode, bool isEnableBaselinePgo = false) const; 62 EventInfo HandleCompileWithBundle(const std::string &bundleName, const std::string &compileMode, 63 std::shared_ptr<BundleDataMgr> dataMgr) const; 64 ErrCode HandleCompileBundles(const std::vector<std::string> &bundleNames, const std::string &compileMode, 65 std::shared_ptr<BundleDataMgr> &dataMgr, std::vector<std::string> &compileResults) const; 66 ErrCode HandleCompileModules(const std::vector<std::string> &moduleNames, const std::string &compileMode, 67 InnerBundleInfo &info, std::string &compileResult) const; 68 void ClearArkCacheDir() const; 69 void ResetAOTFlags() const; 70 void HandleIdleWithSingleHap( 71 const InnerBundleInfo &info, const std::string &moduleName, const std::string &compileMode) const; 72 bool CheckDeviceState() const; 73 ErrCode AOTInternal(const std::optional<AOTArgs> &aotArgs, uint32_t versionCode) const; 74 AOTCompileStatus ConvertToAOTCompileStatus(const ErrCode ret) const; 75 void HandleOTACompile(); 76 void BeforeOTACompile(); 77 void OTACompile() const; 78 void OTACompileInternal() const; 79 bool GetOTACompileList(std::vector<std::string> &bundleNames) const; 80 bool GetUserBehaviourAppList(std::vector<std::string> &bundleNames, int32_t size) const; 81 bool IsOTACompileSwitchOn() const; 82 void ReportSysEvent(const std::map<std::string, EventInfo> &sysEventMap) const; 83 84 void DeleteArkAp(const BundleInfo &bundleInfo, const int32_t userId) const; 85 void ClearArkAp(const std::string &oldAOTVersion, const std::string &curAOTVersion) const; 86 std::string GetCurAOTVersion() const; 87 bool GetOldAOTVersion(std::string &oldAOTVersion) const; 88 void SaveAOTVersion(const std::string &curAOTVersion) const; 89 void HandleArkPathsChange() const; 90 void DelDeprecatedArkPaths() const; 91 void CreateArkProfilePaths() const; 92 private: 93 std::atomic<bool> OTACompileDeadline_ { false }; 94 mutable std::mutex executeMutex_; 95 mutable std::mutex idleMutex_; 96 mutable std::mutex compileMutex_; 97 std::shared_ptr<SerialQueue> serialQueue_; 98 }; 99 } // namespace AppExecFwk 100 } // namespace OHOS 101 #endif // FOUNDATION_BUNDLE_FRAMEWORK_AOT_AOT_HANDLER 102