1 /* 2 * Copyright (C) 2021-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 OHOS_IPC_BINDER_CONNECTOR_H 17 #define OHOS_IPC_BINDER_CONNECTOR_H 18 19 #include <string> 20 #include <mutex> 21 22 namespace OHOS { 23 class BinderConnector { 24 public: 25 static BinderConnector *GetInstance(); 26 BinderConnector(const std::string &deviceName); 27 ~BinderConnector(); 28 29 int WriteBinder(unsigned long request, void *value); 30 void ExitCurrentThread(unsigned long request); 31 bool IsDriverAlive(); 32 bool IsAccessTokenSupported(); 33 bool IsRealPidSupported(); 34 uint64_t GetSelfTokenID(); 35 uint64_t GetSelfFirstCallerTokenID(); 36 void CloseDriverFd(); 37 private: 38 static BinderConnector *instance_; 39 static std::mutex skeletonMutex; 40 static constexpr size_t CLOSE_WAIT_TIME_MS = 15; 41 bool OpenDriver(); 42 bool MapMemory(uint64_t featureSet); 43 std::atomic_int driverFD_; 44 void *vmAddr_; 45 const std::string deviceName_; 46 int32_t version_; 47 uint64_t featureSet_; 48 uint64_t selfTokenID_; 49 }; 50 } // namespace OHOS 51 #endif // OHOS_IPC_BINDER_CONNECTOR_H 52