• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     static std::string GetLanguageFromUserId(int32_t userId);
36     static std::string GetSystemLanguageFromUserId(int32_t userId);
37     static std::string GetSystemLocaleFromUserId(int32_t userId);
38 
39 private:
40     static I18nErrorCode SaveGlobalParam(const std::string& localId);
41     static I18nErrorCode LoadGlobalParam(const std::string& localId);
42     static I18nErrorCode GetForegroundLocalId(std::string& localId);
43     static I18nErrorCode RemoveGlobalParam(const std::string& localId);
44     static std::string ReadMultiUsersParameter(const std::string& paramKey, const std::string& localId);
45     static I18nErrorCode WriteMultiUsersParameter(const std::string& paramKey, const std::string& paramValue,
46         const std::string& localId, bool isDel);
47     static bool IsValidLocalId(const std::string& localId);
48     static void InitPreferences();
49     static std::string GetParamFromPreferences(const std::string& paramKey);
50     static I18nErrorCode SetParamFromPreferences(const std::string& paramKey, const std::string& paramValue);
51 
52 #ifdef SUPPORT_GRAPHICS
53     static void UpdateConfiguration(const std::string& locale, const std::string& language,
54         const std::string& is24Hour, int32_t userId);
55     static I18nErrorCode PublishCommonEvent(int32_t userId);
56 #endif
57 
58     static const std::string MULTI_USERS_LANGUAGE_KEY;
59     static const std::string MULTI_USERS_LOCALE_KEY;
60     static const std::string MULTI_USERS_HOUR_KEY;
61     static const std::string INIT_KEY;
62     static const std::string PREFERENCE_PATH;
63     static const int32_t DEFAULT_LOCAL_ID;
64     static const int CONFIG_LEN;
65     static std::shared_ptr<NativePreferences::Preferences> preferences;
66 };
67 } // namespace I18n
68 } // namespace Global
69 } // namespace OHOS
70 #endif