• 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 
16 #ifndef INPUTMETHOD_IMF_FREEZE_MANAGER_H
17 #define INPUTMETHOD_IMF_FREEZE_MANAGER_H
18 
19 #include "event_handler.h"
20 
21 namespace OHOS {
22 namespace MiscServices {
23 enum class RequestType : int32_t { NORMAL = 0, START_INPUT, STOP_INPUT, REQUEST_SHOW, REQUEST_HIDE };
24 class FreezeManager {
25 public:
FreezeManager(pid_t pid)26     explicit FreezeManager(pid_t pid) : pid_(pid)
27     {
28     }
29     static void SetEventHandler(const std::shared_ptr<AppExecFwk::EventHandler> &eventHandler);
30     bool IsIpcNeeded(RequestType type);
31     void BeforeIpc(RequestType type);
32     void AfterIpc(RequestType type, bool isSuccess);
33     bool IsImeInUse();
34 
35 private:
36     static std::shared_ptr<AppExecFwk::EventHandler> eventHandler_;
37     void ControlIme(bool shouldFreeze);
38     static void ReportRss(bool shouldFreeze, pid_t pid);
39     std::mutex mutex_;
40     bool isImeInUse_{ false };
41     bool isFrozen_{ true };
42     pid_t pid_;
43 };
44 } // namespace MiscServices
45 } // namespace OHOS
46 #endif //INPUTMETHOD_IMF_FREEZE_MANAGER_H
47