• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 INPUTMETHOD_IMF_AUTO_NUMBER_INPUT_APPS_MANAGER_H
17 #define INPUTMETHOD_IMF_AUTO_NUMBER_INPUT_APPS_MANAGER_H
18 
19 #include "settings_data_utils.h"
20 
21 namespace OHOS {
22 namespace MiscServices {
23 static constexpr int32_t BLOCK_MODE = 8;
24 struct NumkeyAPP : public Serializable {
25     std::string name;
26     bool numKey{ false };
UnmarshalNumkeyAPP27     bool Unmarshal(cJSON *node) override
28     {
29         GetValue(node, GET_NAME(name), name);
30         GetValue(node, GET_NAME(numKey), numKey);
31         return true;
32     }
33 };
34 
35 struct NumkeyAppListCfg : public Serializable {
36     std::vector<NumkeyAPP> numkeyApps;
UnmarshalNumkeyAppListCfg37     bool Unmarshal(cJSON *node) override
38     {
39         std::function<bool(NumkeyAPP)> filter = [](const NumkeyAPP &app) { return app.numKey; };
40         GetValues(node, numkeyApps, filter);
41         return true;
42     }
43 };
44 
45 struct UserBlockListCfg : public Serializable {
46     std::vector<std::string> blockApps;
UnmarshalUserBlockListCfg47     bool Unmarshal(cJSON *node) override
48     {
49         std::function<bool(int32_t)> filter = [](const int32_t &mode) { return mode == BLOCK_MODE; };
50         GetKeys(node, blockApps, filter);
51         return true;
52     }
53 };
54 
55 class NumkeyAppsManager {
56 public:
57     static NumkeyAppsManager &GetInstance();
58     int32_t Init(int32_t userId);
59     bool NeedAutoNumKeyInput(int32_t userId, const std::string &bundleName);
60     int32_t OnUserSwitched(int32_t userId);
61     int32_t OnUserRemoved(int32_t userId);
62     int32_t RegisterUserBlockListData(int32_t userId);
63     static constexpr const char *COMPATIBLE_SETTING_STRATEGY = "COMPATIBLE_SETTING_STRATEGY";
64     static constexpr const char *COMPATIBLE_APP_STRATEGY = "COMPATIBLE_APP_STRATEGY";
65 
66 private:
67     NumkeyAppsManager() = default;
68     ~NumkeyAppsManager();
69     NumkeyAppsManager(const NumkeyAppsManager &) = delete;
70     NumkeyAppsManager(NumkeyAppsManager &&) = delete;
71     NumkeyAppsManager &operator=(const NumkeyAppsManager &) = delete;
72     NumkeyAppsManager &operator=(NumkeyAppsManager &&) = delete;
73 
74     int32_t InitWhiteList();
75     int32_t UpdateUserBlockList(int32_t userId);
76     static int32_t ParseWhiteList(std::unordered_set<std::string> &list);
77     static int32_t ParseBlockList(int32_t userId, std::unordered_set<std::string> &list);
78     bool IsInNumKeyWhiteList(const std::string &bundleName);
79     bool IsInNumkeyBlockList(int32_t userId, const std::string &bundleName);
80 
81     bool isFeatureEnabled_{ false };
82     std::mutex appDeviceTypeLock_;
83     std::unordered_set<std::string> disableNumKeyAppDeviceTypes_;
84 
85     std::atomic<bool> isListInited_{ false };
86     std::mutex appListLock_;
87     std::unordered_set<std::string> numKeyAppList_;
88 
89     std::mutex blockListLock_;
90     std::map<int32_t, std::unordered_set<std::string>> usersBlockList_;
91     std::mutex observersLock_;
92     std::map<int32_t, sptr<SettingsDataObserver>> observers_;
93 };
94 } // namespace MiscServices
95 } // namespace OHOS
96 
97 #endif // INPUTMETHOD_IMF_AUTO_NUMBER_INPUT_APPS_MANAGER_H
98