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