1 /* 2 * Copyright (c) 2023-2023 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 NAP_PROCESS_H 17 #define NAP_PROCESS_H 18 19 #include "uds_server.h" 20 21 namespace OHOS { 22 namespace MMI { 23 class NapProcess final { 24 public: 25 26 virtual ~NapProcess() = default; 27 28 static NapProcess *GetInstance(); 29 30 struct NapStatusData { 31 int32_t pid; 32 int32_t uid; 33 std::string bundleName; 34 bool operator==(const NapStatusData b) const 35 { 36 return pid == b.pid && uid == b.uid && bundleName == b.bundleName; 37 } 38 bool operator<(const NapStatusData b) const 39 { 40 if (pid != b.pid) return pid < b.pid; 41 if (uid != b.uid) return uid < b.uid; 42 return bundleName < b.bundleName; 43 } 44 }; 45 std::map<NapStatusData, int32_t> napMap_; 46 int32_t NotifyBundleName(NapStatusData napData, int32_t syncState); 47 int32_t SetNapStatus(int32_t pid, int32_t uid, std::string bundleName, int32_t napState); 48 int32_t NotifyNapOnline(); 49 int32_t GetAllMmiSubscribedEvents(std::map<std::tuple<int32_t, int32_t, std::string>, int32_t> &datas); 50 int32_t RemoveInputEventObserver(); 51 int32_t AddMmiSubscribedEventData(const NapStatusData& napData, int32_t syncState); 52 int32_t RemoveMmiSubscribedEventData(const NapStatusData& napData); 53 int32_t GetNapClientPid(); 54 bool IsNeedNotify(const NapStatusData& napData); 55 void Init(UDSServer& udsServer); 56 int32_t napClientPid_ { -1 }; 57 58 private: 59 UDSServer* udsServer_ { nullptr }; 60 NapProcess() = default; 61 DISALLOW_COPY_AND_MOVE(NapProcess); 62 static NapProcess *instance_; 63 std::mutex mapMtx_; 64 }; 65 } // namespace MMI 66 } // namespace OHOS 67 #endif // NAP_PROCESS_H 68