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 FOUNDATION_ACE_ADAPTER_OHOS_CPP_ACE_NEWPIPE_JUDJEMENT_H
17 #define FOUNDATION_ACE_ADAPTER_OHOS_CPP_ACE_NEWPIPE_JUDJEMENT_H
18 
19 #include <set>
20 #include <string>
21 
22 namespace OHOS::Ace {
23 enum class AceNewPipeEnabledType {
24     ACE_NEW_PIPE_DISABLED = 0,
25     ACE_NEW_PIPE_ENABLED_FOR_ALL,
26     ACE_NEW_PIPE_PARTIALLY_ENABLED,
27 };
28 
29 class AceNewPipeJudgement final {
30 public:
31     ~AceNewPipeJudgement() = default;
32 
33     // Decide if it's a new framework
34     static bool QueryAceNewPipeEnabledFA(const std::string& packagename, uint32_t apiCompatibleVersion,
35         uint32_t apiTargetVersion, const std::string& apiReleaseType);
36     static bool QueryAceNewPipeEnabledStage(const std::string& packagename, uint32_t apiCompatibleVersion,
37         uint32_t apiTargetVersion, const std::string& apiReleaseType, bool closeArkTSPartialUpdate);
38     // Load acenewpipe.config
39     static void InitAceNewPipeConfig();
40 
41 private:
42     AceNewPipeJudgement() = default;
43 
44     // Dealing with Windows type end of line "\r"
45     static std::ifstream& SafeGetLine(std::ifstream& configFile, std::string& line);
46     static void InitAceNewPipeWithConfigFile();
47 
48     static inline AceNewPipeEnabledType aceNewPipeEnabledType_ = AceNewPipeEnabledType::ACE_NEW_PIPE_DISABLED;
49     static inline std::set<std::string> aceNewPipeEnabledList_ {};
50     static inline bool InitedAceNewPipeConfig_ = false;
51 };
52 } // namespace OHOS::Ace
53 #endif // FOUNDATION_ACE_ADAPTER_OHOS_CPP_ACE_NEWPIPE_JUDJEMENT_H
54