• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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_FRAMEWORKS_CORE_COMMON_ACE_APPLICATION_INFO_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_ACE_APPLICATION_INFO_H
18 
19 #include <chrono>
20 #include <cstdint>
21 #include <mutex>
22 #include <set>
23 #include <shared_mutex>
24 #include <string>
25 #include <vector>
26 
27 #include "base/json/json_util.h"
28 #include "base/utils/macros.h"
29 #include "base/utils/noncopyable.h"
30 #include "base/utils/string_utils.h"
31 #include "interfaces/inner_api/ace/ace_forward_compatibility.h"
32 
33 namespace OHOS::Ace {
34 
35 enum class PlatformVersion {
36     VERSION_FIVE = 5,
37     VERSION_SIX,
38     VERSION_SEVEN,
39     VERSION_EIGHT,
40     VERSION_NINE,
41     VERSION_TEN,
42     VERSION_ELEVEN,
43     VERSION_TWELVE,
44     VERSION_THIRTEEN,
45     VERSION_FOURTEEN,
46     VERSION_FIFTEEN
47 };
48 struct AceBundleInfo {
49     uint32_t versionCode = 0;
50     std::string versionName;
51 };
52 
53 class ACE_FORCE_EXPORT AceApplicationInfo : public NonCopyable {
54 public:
55     ACE_EXPORT static AceApplicationInfo& GetInstance();
56 
57     virtual void SetLocale(const std::string& language, const std::string& countryOrRegion, const std::string& script,
58         const std::string& keywordsAndValues) = 0;
59     virtual void ChangeLocale(const std::string& language, const std::string& countryOrRegion) = 0;
60     virtual void SetDebug(bool isDebugVersion, bool needDebugBreakpoint) = 0;
61 
SetUserId(int userId)62     void SetUserId(int userId)
63     {
64         userId_ = userId;
65     }
66 
GetUserId()67     int GetUserId() const
68     {
69         return userId_;
70     }
71 
72     void SetPackageName(const std::string& packageName);
73     const std::string& GetPackageName() const;
74 
75     void SetUid(int32_t uid);
76     int32_t GetUid() const;
77 
78     void SetProcessName(const std::string& processName);
79     const std::string& GetProcessName() const;
80 
81     void SetAbilityName(const std::string& abilityName_);
82     const std::string& GetAbilityName() const;
83 
SetDataFileDirPath(const std::string & dataDirFilePath)84     void SetDataFileDirPath(const std::string& dataDirFilePath)
85     {
86         dataDirFilePath_ = dataDirFilePath;
87     }
GetDataFileDirPath()88     const std::string& GetDataFileDirPath() const
89     {
90         return dataDirFilePath_;
91     }
92 
SetApiTargetVersion(int32_t apiVersion)93     void SetApiTargetVersion(int32_t apiVersion)
94     {
95         apiVersion_ = apiVersion;
96     }
GetApiTargetVersion()97     int32_t GetApiTargetVersion() const
98     {
99         return apiVersion_;
100     }
101 
GreatOrEqualTargetAPIVersion(PlatformVersion version)102     bool GreatOrEqualTargetAPIVersion(PlatformVersion version)
103     {
104         return (apiVersion_ % 1000) >= static_cast<int32_t>(version);
105     }
106 
SetAppVersionName(const std::string & versionName)107     void SetAppVersionName(const std::string& versionName)
108     {
109         versionName_ = versionName;
110     }
111 
GetAppVersionName()112     const std::string& GetAppVersionName() const
113     {
114         return versionName_;
115     }
116 
SetAppVersionCode(uint32_t versionCode)117     void SetAppVersionCode(uint32_t versionCode)
118     {
119         versionCode_ = versionCode;
120     }
121 
GetAppVersionCode()122     uint32_t GetAppVersionCode() const
123     {
124         return versionCode_;
125     }
126 
127     virtual bool GetBundleInfo(const std::string& packageName, AceBundleInfo& bundleInfo) = 0;
128     virtual double GetLifeTime() const = 0;
129 
130     virtual std::string GetJsEngineParam(const std::string& key) const = 0;
131 
GetCountryOrRegion()132     const std::string& GetCountryOrRegion() const
133     {
134         return countryOrRegion_;
135     }
136 
GetLanguage()137     const std::string& GetLanguage() const
138     {
139         return language_;
140     }
141 
GetScript()142     const std::string& GetScript() const
143     {
144         return script_;
145     }
146 
GetLocaleTag()147     const std::string& GetLocaleTag() const
148     {
149         return localeTag_;
150     }
151 
152     std::string GetUnicodeSetting() const;
153 
IsRightToLeft()154     bool IsRightToLeft() const
155     {
156         return isRightToLeft_;
157     }
158 
IsDebugVersion()159     bool IsDebugVersion() const
160     {
161         return isDebugVersion_;
162     }
163 
IsNeedDebugBreakPoint()164     bool IsNeedDebugBreakPoint() const
165     {
166         return needDebugBreakpoint_;
167     }
168 
SetNeedDebugBreakPoint(const bool needDebugBreakpoint)169     void SetNeedDebugBreakPoint(const bool needDebugBreakpoint)
170     {
171         needDebugBreakpoint_ = needDebugBreakpoint;
172     }
173 
SetCardType()174     void SetCardType()
175     {
176         isCardType_ = true;
177     }
178 
GetIsCardType()179     bool GetIsCardType() const
180     {
181         return isCardType_;
182     }
SetBarrierfreeDuration(int32_t duration)183     void SetBarrierfreeDuration(int32_t duration)
184     {
185         barrierfreeDuration_ = duration;
186     }
GetBarrierfreeDuration()187     int32_t GetBarrierfreeDuration() const
188     {
189         return barrierfreeDuration_;
190     }
SetAccessibilityEnabled(bool isEnabled)191     void SetAccessibilityEnabled(bool isEnabled)
192     {
193         isAccessibilityEnabled_ = isEnabled;
194     }
IsAccessibilityEnabled()195     bool IsAccessibilityEnabled() const
196     {
197         return isAccessibilityEnabled_;
198     }
SetPid(int32_t pid)199     void SetPid(int32_t pid)
200     {
201         pid_ = pid;
202     }
GetPid()203     int32_t GetPid() const
204     {
205         return pid_;
206     }
207 
SetMissionId(int32_t missionId)208     void SetMissionId(int32_t missionId)
209     {
210         missionId_ = missionId;
211     }
GetMissionId()212     int32_t GetMissionId() const
213     {
214         return missionId_;
215     }
216 
IsUseNewPipeline()217     bool IsUseNewPipeline()
218     {
219         return useNewPipeline_.value_or(AceForwardCompatibility::IsUseNG());
220     }
221 
SetIsUseNewPipeline(bool useNewPipeline)222     void SetIsUseNewPipeline(bool useNewPipeline)
223     {
224         useNewPipeline_.emplace(useNewPipeline);
225     }
226 
SetTouchEventsPassThroughMode(bool isTouchEventsPassThrough)227     void SetTouchEventsPassThroughMode(bool isTouchEventsPassThrough)
228     {
229         std::unique_lock<std::shared_mutex> lock(eventsPassThroughMutex_);
230         isTouchEventsPassThrough_ = isTouchEventsPassThrough;
231     }
232 
IsTouchEventsPassThrough()233     bool IsTouchEventsPassThrough() const
234     {
235         std::shared_lock<std::shared_mutex> lock(eventsPassThroughMutex_);
236         return isTouchEventsPassThrough_;
237     }
238 
SetReusedNodeSkipMeasure(bool reusedNodeSkipMeasure)239     void SetReusedNodeSkipMeasure(bool reusedNodeSkipMeasure)
240     {
241         reusedNodeSkipMeasure_= reusedNodeSkipMeasure;
242     }
243 
IsReusedNodeSkipMeasure()244     bool IsReusedNodeSkipMeasure() const
245     {
246         return reusedNodeSkipMeasure_;
247     }
248 
249 protected:
250     std::string countryOrRegion_;
251     std::string language_;
252     std::string script_;
253     std::string localeTag_;
254     std::string keywordsAndValues_;
255 
256     std::string packageName_;
257     std::string processName_;
258     std::string dataDirFilePath_;
259     std::string abilityName_;
260     int32_t pid_ = 0;
261     int32_t uid_ = 0;
262     int32_t barrierfreeDuration_ = 0;
263 
264     bool isRightToLeft_ = false;
265     bool isDebugVersion_ = false;
266     bool needDebugBreakpoint_ = false;
267     std::optional<bool> useNewPipeline_;
268 
269     bool isCardType_ = false;
270 
271     int userId_ = 0;
272     bool isAccessibilityEnabled_ = false;
273 
274     int32_t apiVersion_ = 0;
275     std::string versionName_;
276     uint32_t versionCode_ = 0;
277     int32_t missionId_ = -1;
278     mutable std::shared_mutex eventsPassThroughMutex_;
279     bool isTouchEventsPassThrough_ = false;
280     bool reusedNodeSkipMeasure_ = false;
281 };
282 
283 } // namespace OHOS::Ace
284 
285 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_ACE_APPLICATION_INFO_H
286