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 struct AceBundleInfo { 33 uint32_t versionCode = 0; 34 std::string versionName; 35 }; 36 37 class ACE_FORCE_EXPORT_WITH_PREVIEW AceApplicationInfo : public NonCopyable { 38 public: 39 ACE_EXPORT static AceApplicationInfo& GetInstance(); 40 41 virtual void SetLocale(const std::string& language, const std::string& countryOrRegion, const std::string& script, 42 const std::string& keywordsAndValues) = 0; 43 virtual void ChangeLocale(const std::string& language, const std::string& countryOrRegion) = 0; 44 virtual void SetDebug(bool isDebugVersion, bool needDebugBreakpoint) = 0; 45 SetUserId(int userId)46 void SetUserId(int userId) 47 { 48 userId_ = userId; 49 } 50 GetUserId()51 int GetUserId() const 52 { 53 return userId_; 54 } 55 56 void SetPackageName(const std::string& packageName); 57 const std::string& GetPackageName() const; 58 59 void SetUid(int32_t uid); 60 int32_t GetUid() const; 61 62 void SetProcessName(const std::string& processName); 63 const std::string& GetProcessName() const; 64 65 void SetAbilityName(const std::string& abilityName_); 66 const std::string& GetAbilityName() const; 67 SetDataFileDirPath(const std::string & dataDirFilePath)68 void SetDataFileDirPath(const std::string& dataDirFilePath) 69 { 70 dataDirFilePath_ = dataDirFilePath; 71 } GetDataFileDirPath()72 const std::string& GetDataFileDirPath() const 73 { 74 return dataDirFilePath_; 75 } 76 77 virtual bool GetBundleInfo(const std::string& packageName, AceBundleInfo& bundleInfo) = 0; 78 virtual double GetLifeTime() const = 0; 79 80 virtual std::string GetJsEngineParam(const std::string& key) const = 0; 81 GetCountryOrRegion()82 const std::string& GetCountryOrRegion() const 83 { 84 return countryOrRegion_; 85 } 86 GetLanguage()87 const std::string& GetLanguage() const 88 { 89 return language_; 90 } 91 GetScript()92 const std::string& GetScript() const 93 { 94 return script_; 95 } 96 GetLocaleTag()97 const std::string& GetLocaleTag() const 98 { 99 return localeTag_; 100 } 101 102 std::string GetUnicodeSetting() const; 103 IsRightToLeft()104 bool IsRightToLeft() const 105 { 106 return isRightToLeft_; 107 } 108 IsDebugVersion()109 bool IsDebugVersion() const 110 { 111 return isDebugVersion_; 112 } 113 IsNeedDebugBreakPoint()114 bool IsNeedDebugBreakPoint() const 115 { 116 return needDebugBreakpoint_; 117 } 118 SetNeedDebugBreakPoint(const bool needDebugBreakpoint)119 void SetNeedDebugBreakPoint(const bool needDebugBreakpoint) 120 { 121 needDebugBreakpoint_ = needDebugBreakpoint; 122 } 123 SetCardType()124 void SetCardType() 125 { 126 isCardType_ = true; 127 } 128 GetIsCardType()129 bool GetIsCardType() const 130 { 131 return isCardType_; 132 } SetBarrierfreeDuration(int32_t duration)133 void SetBarrierfreeDuration(int32_t duration) 134 { 135 barrierfreeDuration_ = duration; 136 } GetBarrierfreeDuration()137 int32_t GetBarrierfreeDuration() const 138 { 139 return barrierfreeDuration_; 140 } SetAccessibilityEnabled(bool isEnabled)141 void SetAccessibilityEnabled(bool isEnabled) 142 { 143 isAccessibilityEnabled_ = isEnabled; 144 } IsAccessibilityEnabled()145 bool IsAccessibilityEnabled() const 146 { 147 return isAccessibilityEnabled_; 148 } SetPid(int32_t pid)149 void SetPid(int32_t pid) 150 { 151 pid_ = pid; 152 } GetPid()153 int32_t GetPid() const 154 { 155 return pid_; 156 } 157 158 protected: 159 std::string countryOrRegion_; 160 std::string language_; 161 std::string script_; 162 std::string localeTag_; 163 std::string keywordsAndValues_; 164 165 std::string packageName_; 166 std::string processName_; 167 std::string dataDirFilePath_; 168 std::string abilityName_; 169 int32_t pid_ = 0; 170 int32_t uid_ = 0; 171 int32_t barrierfreeDuration_ = 0; 172 173 bool isRightToLeft_ = false; 174 bool isDebugVersion_ = false; 175 bool needDebugBreakpoint_ = false; 176 177 bool isCardType_ = false; 178 179 int userId_ = 0; 180 bool isAccessibilityEnabled_ = false; 181 }; 182 183 } // namespace OHOS::Ace 184 185 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_ACE_APPLICATION_INFO_H 186