1 /* 2 * Copyright (c) 2021 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 <set> 21 #include <string> 22 #include <vector> 23 24 #include "base/json/json_util.h" 25 #include "base/utils/macros.h" 26 #include "base/utils/noncopyable.h" 27 #include "base/utils/string_utils.h" 28 29 namespace OHOS::Ace { 30 31 struct AceBundleInfo { 32 uint32_t versionCode = 0; 33 std::string versionName; 34 }; 35 36 class ACE_FORCE_EXPORT_WITH_PREVIEW AceApplicationInfo : public NonCopyable { 37 public: 38 ACE_EXPORT static AceApplicationInfo& GetInstance(); 39 40 virtual void SetLocale(const std::string& language, const std::string& countryOrRegion, const std::string& script, 41 const std::string& keywordsAndValues) = 0; 42 virtual void ChangeLocale(const std::string& language, const std::string& countryOrRegion) = 0; 43 virtual void SetDebug(bool isDebugVersion, bool needDebugBreakpoint) = 0; 44 SetUserId(int userId)45 void SetUserId(int userId) 46 { 47 userId_ = userId; 48 } 49 GetUserId()50 int GetUserId() const 51 { 52 return userId_; 53 } 54 55 void SetPackageName(const std::string& packageName); 56 const std::string& GetPackageName() const; 57 58 void SetUid(int32_t uid); 59 int32_t GetUid() const; 60 61 void SetProcessName(const std::string& processName); 62 const std::string& GetProcessName() const; 63 64 SetDataFileDirPath(const std::string & dataDirFilePath)65 void SetDataFileDirPath(const std::string& dataDirFilePath) 66 { 67 dataDirFilePath_ = dataDirFilePath; 68 } GetDataFileDirPath()69 const std::string& GetDataFileDirPath() const 70 { 71 return dataDirFilePath_; 72 } 73 74 virtual bool GetBundleInfo(const std::string& packageName, AceBundleInfo& bundleInfo) = 0; 75 virtual double GetLifeTime() const = 0; 76 77 // TODO: move to AceSettings 78 virtual std::string GetJsEngineParam(const std::string& key) const = 0; 79 GetCountryOrRegion()80 const std::string& GetCountryOrRegion() const 81 { 82 return countryOrRegion_; 83 } 84 GetLanguage()85 const std::string& GetLanguage() const 86 { 87 return language_; 88 } 89 GetScript()90 const std::string& GetScript() const 91 { 92 return script_; 93 } 94 GetLocaleTag()95 const std::string& GetLocaleTag() const 96 { 97 return localeTag_; 98 } 99 100 std::string GetUnicodeSetting() const; 101 IsRightToLeft()102 bool IsRightToLeft() const 103 { 104 return isRightToLeft_; 105 } 106 IsDebugVersion()107 bool IsDebugVersion() const 108 { 109 return isDebugVersion_; 110 } 111 IsNeedDebugBreakPoint()112 bool IsNeedDebugBreakPoint() const 113 { 114 return needDebugBreakpoint_; 115 } 116 SetNeedDebugBreakPoint(const bool needDebugBreakpoint)117 void SetNeedDebugBreakPoint(const bool needDebugBreakpoint) 118 { 119 needDebugBreakpoint_ = needDebugBreakpoint; 120 } 121 SetCardType()122 void SetCardType() 123 { 124 isCardType_ = true; 125 } 126 GetIsCardType()127 bool GetIsCardType() const 128 { 129 return isCardType_; 130 } 131 SetAccessibilityEnabled(bool isEnabled)132 void SetAccessibilityEnabled(bool isEnabled) 133 { 134 isAccessibilityEnabled_ = isEnabled; 135 } IsAccessibilityEnabled()136 bool IsAccessibilityEnabled() const 137 { 138 return isAccessibilityEnabled_; 139 } 140 141 protected: 142 std::string countryOrRegion_; 143 std::string language_; 144 std::string script_; 145 std::string localeTag_; 146 std::string keywordsAndValues_; 147 148 std::string packageName_; 149 std::string processName_; 150 std::string dataDirFilePath_; 151 int32_t uid_; 152 153 bool isRightToLeft_ = false; 154 bool isDebugVersion_ = false; 155 bool needDebugBreakpoint_ = false; 156 157 // TODO: move to container 158 bool isCardType_ = false; 159 160 int userId_ = 0; 161 bool isAccessibilityEnabled_ = false; 162 }; 163 164 } // namespace OHOS::Ace 165 166 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_ACE_APPLICATION_INFO_H 167