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