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