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