/* * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef CLIENT_DEATH_HANDLER_H #define CLIENT_DEATH_HANDLER_H #include #include #include #include #include "iremote_object.h" #include "refbase.h" #include "nocopyable.h" #include "input_binder_client_death_recipient.h" namespace OHOS { namespace MMI { enum class CallBackType : int32_t { CALLBACK_TYPE_AUTHORIZE_HELPER, }; using ClientDeathCallback = std::function; class ClientDeathHandler final : RefBase { public: ClientDeathHandler(); ~ClientDeathHandler(); DISALLOW_COPY_AND_MOVE(ClientDeathHandler); bool RegisterClientDeathRecipient(const sptr &binderClientSrv, int32_t pid); bool AddClientDeathCallback(CallBackType type, ClientDeathCallback callback); bool UnregisterClientDeathRecipient(const wptr &remoteObj); void RemoveClientDeathCallback(CallBackType type); protected: bool RegisterClientDeathRecipient(const sptr &binderClientSrv); bool AddClientPid(const sptr &binderClientSrv, int32_t pid); void RemoveClientPid(int32_t pid); int32_t FindClientPid(const sptr &binderClientSrv); void NotifyDeath(int32_t pid); private: void OnDeath(const wptr &remoteObj); std::mutex mutexPidMap_; std::map> clientPidMap_; std::mutex mutexDeathRecipient_; sptr deathRecipient_ = nullptr; std::mutex mutexCallbacks_; std::map deathCallbacks_; }; } // namespace MMI } // namespace OHOS #endif // CLIENT_DEATH_HANDLER_H