• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 #include "ace_forward_compatibility.h"
17 
18 #include <unordered_set>
19 #include "hilog/log.h"
20 #ifdef OHOS_PLATFORM
21 #include "parameters.h"
22 #endif
23 
24 namespace OHOS {
25 namespace Ace {
26 namespace {
27     constexpr OHOS::HiviewDFX::HiLogLabel ACE_COMPATIBLITY_LABEL = { LOG_CORE, 0xD003900, "ACE_COMPATIBLITY" };
28     constexpr uint32_t ARKUI_NEW_PIPELINE_MIN_VERSION = 9;
29 #if defined(WINDOWS_PLATFORM)
30     constexpr char ARKUI_LIB_NAME_COMPATIBLE[] = "libace_compatible.dll";
31     constexpr char ARKUI_LIB_NAME[] = "libace.dll";
32 #elif defined(MAC_PLATFORM)
33     constexpr char ARKUI_LIB_NAME_COMPATIBLE[] = "libace_compatible.dylib";
34     constexpr char ARKUI_LIB_NAME[] = "libace.dylib";
35 #elif defined(LINUX_PLATFORM)
36     constexpr char ARKUI_LIB_NAME_COMPATIBLE[] = "libace_compatible.so";
37     constexpr char ARKUI_LIB_NAME[] = "libace.so";
38 #else
39     constexpr char ARKUI_LIB_NAME_COMPATIBLE[] = "libace_compatible.z.so";
40     constexpr char ARKUI_LIB_NAME[] = "libace.z.so";
41 #endif
42 
43 #define LOGD(fmt, ...)            \
44     (void)OHOS::HiviewDFX::HiLog::Debug(ACE_COMPATIBLITY_LABEL, "[%{public}d]" fmt, __LINE__, ##__VA_ARGS__)
45 
46 #define LOGI(fmt, ...)            \
47     (void)OHOS::HiviewDFX::HiLog::Info(ACE_COMPATIBLITY_LABEL, "[%{public}d]" fmt, __LINE__, ##__VA_ARGS__)
48 } // namespace
49 
Init(const std::string & bundleName,const uint32_t apiCompatibleVersion,bool deprecated)50 void AceForwardCompatibility::Init(const std::string& bundleName, const uint32_t apiCompatibleVersion, bool deprecated)
51 {
52 #ifdef OHOS_PLATFORM
53     isForceOldPipeline_ = OHOS::system::GetBoolParameter("persist.arkui.libace.og", true);
54 #else
55     isForceOldPipeline_ = true;
56 #endif
57 
58     isNewPipeline_ = (apiCompatibleVersion >= ARKUI_NEW_PIPELINE_MIN_VERSION) && !deprecated;
59     isInited_ = true;
60     LOGI("AceForwardCompatibility [%{public}s] force:%{public}d newpipe:%{public}d",
61          bundleName.c_str(), isForceOldPipeline_, isNewPipeline_);
62 }
63 
IsForceOldPipeline()64 bool AceForwardCompatibility::IsForceOldPipeline()
65 {
66     if (isInited_) {
67         return isForceOldPipeline_;
68     }
69 #ifdef OHOS_PLATFORM
70     return OHOS::system::GetBoolParameter("persist.arkui.libace.og", true);
71 #else
72     return true;
73 #endif
74 }
75 
IsNewPipeline()76 bool AceForwardCompatibility::IsNewPipeline()
77 {
78     if (isInited_) {
79         return isNewPipeline_ && !isForceOldPipeline_;
80     }
81     isNewAppspawn_ = !IsForceOldPipeline();
82     return !IsForceOldPipeline();
83 }
84 
IsUseNG()85 bool AceForwardCompatibility::IsUseNG()
86 {
87     return isNewPipeline_;
88 }
89 
GetAceLibName()90 const char* AceForwardCompatibility::GetAceLibName()
91 {
92     const char* libName;
93     if (IsNewPipeline()) {
94         libName = ARKUI_LIB_NAME;
95     } else {
96         libName = ARKUI_LIB_NAME_COMPATIBLE;
97     }
98     return libName;
99 }
100 
PipelineChanged()101 bool AceForwardCompatibility::PipelineChanged()
102 {
103     return (isNewPipeline_ && !isForceOldPipeline_) != isNewAppspawn_;
104 }
105 } // namespace Ace
106 } // namespace OHOS
107