• 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 #ifndef IME_MIRROR_MANAGER_H
16 #define IME_MIRROR_MANAGER_H
17 #include <atomic>
18 #include <functional>
19 #include <mutex>
20 #include <unordered_map>
21 
22 #include "iservice_registry.h"
23 #include "system_ability_status_change_stub.h"
24 
25 namespace OHOS {
26 namespace MiscServices {
27 class ImeMirrorManager {
28 public:
29     bool IsImeMirrorEnable();
30     void SetImeMirrorEnable(bool isRegistered);
31     bool SubscribeSaStart(std::function<void()> handler, int32_t saId);
32     bool UnSubscribeSaStart(int32_t saId);
33 
34 private:
35     class SaMgrListener : public SystemAbilityStatusChangeStub {
36     public:
SaMgrListener(std::function<void ()> handler)37         explicit SaMgrListener(std::function<void()> handler) : func_(handler) {};
38         ~SaMgrListener() = default;
39         void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
OnRemoveSystemAbility(int32_t systemAbilityId,const std::string & deviceId)40         void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override { }
41 
42     private:
43         std::function<void()> func_;
44     };
45     std::atomic<bool> isEnable_ = false;
46 
47     std::mutex listenerMapMutex_;
48     std::unordered_map<int32_t, sptr<ISystemAbilityStatusChange>> saMgrListenerMap_; // saId -> listener
49 };
50 }
51 }
52 #endif // IME_MIRROR_MANAGER_H