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