1 /* 2 * Copyright (c) 2024 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 #ifndef OHOS_GLOBAL_I18N_MULTI_USERS_H 16 #define OHOS_GLOBAL_I18N_MULTI_USERS_H 17 18 #include <string> 19 #include "i18n_types.h" 20 #include "preferences.h" 21 #include "preferences_helper.h" 22 23 namespace OHOS { 24 namespace Global { 25 namespace I18n { 26 class MultiUsers { 27 public: 28 static void InitMultiUser(); 29 static void SwitchUser(const std::string& curLocalId); 30 static void AddUser(const std::string& localId); 31 static void RemoveUser(const std::string& localId); 32 static I18nErrorCode SaveLanguage(const std::string& localId, const std::string& language); 33 static I18nErrorCode SaveLocale(const std::string& localId, const std::string& locale); 34 static I18nErrorCode SaveIs24Hour(const std::string& localId, const std::string& is24Hour); 35 36 private: 37 static I18nErrorCode SaveGlobalParam(const std::string& localId); 38 static I18nErrorCode LoadGlobalParam(const std::string& localId); 39 static I18nErrorCode GetForegroundLocalId(std::string& localId); 40 static I18nErrorCode RemoveGlobalParam(const std::string& localId); 41 static std::string ReadMultiUsersParameter(const std::string& paramKey, const std::string& localId); 42 static I18nErrorCode WriteMultiUsersParameter(const std::string& paramKey, const std::string& paramValue, 43 const std::string& localId, bool isDel); 44 static bool IsValidLocalId(const std::string& localId); 45 static void InitPreferences(); 46 static std::string GetParamFromPreferences(const std::string& paramKey); 47 static I18nErrorCode SetParamFromPreferences(const std::string& paramKey, const std::string& paramValue); 48 49 #ifdef SUPPORT_GRAPHICS 50 static void UpdateConfiguration(const std::string& locale, const std::string& is24Hour, int32_t userId); 51 static I18nErrorCode PublishCommonEvent(int32_t userId); 52 #endif 53 54 static const std::string MULTI_USERS_LANGUAGE_KEY; 55 static const std::string MULTI_USERS_LOCALE_KEY; 56 static const std::string MULTI_USERS_HOUR_KEY; 57 static const std::string INIT_KEY; 58 static const std::string PREFERENCE_PATH; 59 static const int32_t DEFAULT_LOCAL_ID; 60 static const int CONFIG_LEN; 61 static std::shared_ptr<NativePreferences::Preferences> preferences; 62 }; 63 } // namespace I18n 64 } // namespace Global 65 } // namespace OHOS 66 #endif