• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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 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     void HandleResetAllAOT() const;
45     ErrCode HandleCopyAp(const std::string &bundleName, bool isAllBundle, std::vector<std::string> &results) const;
46 private:
47     AOTHandler();
48     ~AOTHandler() = default;
49     DISALLOW_COPY_AND_MOVE(AOTHandler);
50 
51     ErrCode MkApDestDirIfNotExist() const;
52     void CopyApWithBundle(const std::string &bundleName, const BundleInfo &bundleInfo,
53         const int32_t userId, std::vector<std::string> &results) const;
54     std::string GetSouceAp(const std::string &mergedAp, const std::string &rtAp) const;
55     bool IsSupportARM64() const;
56     std::string FindArkProfilePath(const std::string &bundleName, const std::string &moduleName) const;
57     std::optional<AOTArgs> BuildAOTArgs(const InnerBundleInfo &info, const std::string &moduleName,
58         const std::string &compileMode, bool isEnableBaselinePgo = false) const;
59     void HandleInstallWithSingleHap(const InnerBundleInfo &info, const std::string &compileMode) const;
60     bool NeedCompile(const InnerBundleInfo &info, const std::string &moduleName) const;
61     ErrCode HandleCompileWithSingleHap(const InnerBundleInfo &info, const std::string &moduleName,
62         const std::string &compileMode, bool isEnableBaselinePgo = false) const;
63     EventInfo HandleCompileWithBundle(const std::string &bundleName, const std::string &compileMode,
64         std::shared_ptr<BundleDataMgr> dataMgr) const;
65     ErrCode HandleCompileBundles(const std::vector<std::string> &bundleNames, const std::string &compileMode,
66         std::shared_ptr<BundleDataMgr> &dataMgr, std::vector<std::string> &compileResults) const;
67     ErrCode HandleCompileModules(const std::vector<std::string> &moduleNames, const std::string &compileMode,
68         InnerBundleInfo &info, std::string &compileResult) const;
69     void ClearArkCacheDir() const;
70     void ResetAOTFlags() const;
71     void HandleIdleWithSingleSysComp(const std::string &abcPath) const;
72     void HandleIdleWithSingleHap(
73         const InnerBundleInfo &info, const std::string &moduleName, const std::string &compileMode) const;
74     bool CheckDeviceState() const;
75     ErrCode AOTInternal(const std::optional<AOTArgs> &aotArgs, uint32_t versionCode) const;
76     AOTCompileStatus ConvertToAOTCompileStatus(const ErrCode ret) const;
77     void HandleOTACompile();
78     void BeforeOTACompile();
79     void OTACompile() const;
80     void OTACompileInternal() const;
81     bool GetOTACompileList(std::vector<std::string> &bundleNames) const;
82     bool GetUserBehaviourAppList(std::vector<std::string> &bundleNames, int32_t size) const;
83     bool IsOTACompileSwitchOn() const;
84     void ReportSysEvent(const std::map<std::string, EventInfo> &sysEventMap) const;
85 
86     void DeleteArkAp(const BundleInfo &bundleInfo, const int32_t userId) const;
87     void ClearArkAp() const;
88     void HandleArkPathsChange() const;
89     void DelDeprecatedArkPaths() const;
90     void CreateArkProfilePaths() const;
91     std::vector<std::string> GetSysCompList() const;
92     void IdleForSysComp() const;
93     void IdleForHap(const std::string &compileMode) const;
94 private:
95     std::atomic<bool> OTACompileDeadline_ { false };
96     mutable std::mutex executeMutex_;
97     mutable std::mutex idleMutex_;
98     mutable std::mutex compileMutex_;
99     std::shared_ptr<SerialQueue> serialQueue_;
100 };
101 }  // namespace AppExecFwk
102 }  // namespace OHOS
103 #endif  // FOUNDATION_BUNDLE_FRAMEWORK_AOT_AOT_HANDLER
104