• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 FM_IMMS_PROJECT_PERUSERSETTING_H
17 #define FM_IMMS_PROJECT_PERUSERSETTING_H
18 
19 #include <map>
20 #include <string>
21 #include <vector>
22 #include "input_method_property.h"
23 #include "input_method_setting.h"
24 #include "global.h"
25 
26 namespace OHOS {
27 namespace MiscServices {
28     class PerUserSetting {
29     public:
30         explicit PerUserSetting(int32_t userId);
31 
32         ~PerUserSetting();
33 
34         void Initialize();
35         int32_t GetUserState();
36         InputMethodProperty *GetCurrentInputMethod();
37         InputMethodProperty *GetSecurityInputMethod();
38         InputMethodProperty *GetNextInputMethod();
39         InputMethodSetting *GetInputMethodSetting();
40         InputMethodProperty *GetInputMethodProperty(const std::u16string& imeId);
41 
42         int32_t OnPackageAdded(std::u16string& packageName, bool isSecurityIme);
43         int32_t OnPackageRemoved(std::u16string& packageName, bool isSecurityIme);
44         int32_t OnSettingChanged(const std::u16string& key, const std::u16string& value);
45         void OnAdvanceToNext();
46         void OnUserLocked();
47         void Dump(int32_t fd);
48 
49         int32_t ListInputMethodEnabled(std::vector<InputMethodProperty*> *properties);
50         int32_t ListInputMethod(std::vector<InputMethodProperty*> *properties);
51         int32_t ListKeyboardType(const std::u16string& imeId, std::vector<KeyboardType*> *types);
52 
53         static bool CheckIfSecurityIme(const InputMethodProperty& property);
54 
55     private:
56         int32_t userId_; // the id of the user to whom the object is linking
57         int32_t userState; // the state of the user to whom the object is linking
58         std::vector<InputMethodProperty*> inputMethodProperties; // a vector to save all IME installed for this user
59         std::u16string currentImeId; // the id of the default input method engine.
60         InputMethodSetting inputMethodSetting; // the object to manage the setting data for this user
61         int COMMON_COUNT_ONE_HUNDRED_THOUSAND = 100000;
62 
63         PerUserSetting(const PerUserSetting&);
64         PerUserSetting& operator =(const PerUserSetting&);
65         PerUserSetting(const PerUserSetting&&);
66         PerUserSetting& operator =(const PerUserSetting&&);
67         void InitInputMethodSetting();
68         void ResetCurrentInputMethod();
69         std::u16string GetKeyboardTypeLanguage(const InputMethodProperty *property, int32_t hashCode);
70         std::u16string GetImeId(const std::u16string& packageName);
71     };
72 }
73 }
74 #endif // FM_IMMS_PROJECT_PERUSERSETTING_H
75