1 /* 2 * Copyright (C) 2021-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 OHOS_IPC_BINDER_CONNECTOR_H 17 #define OHOS_IPC_BINDER_CONNECTOR_H 18 19 #include <string> 20 #include <mutex> 21 22 namespace OHOS { 23 #ifdef CONFIG_ACTV_BINDER 24 class ActvBinderConnector { 25 public: 26 ActvBinderConnector(); 27 28 int InitActvBinder(int fd); 29 void InitActvBinderConfig(uint64_t featureSet); 30 31 bool isActvMgr_; 32 }; 33 #endif 34 35 class BinderConnector { 36 public: 37 static BinderConnector *GetInstance(); 38 BinderConnector(const std::string &deviceName); 39 ~BinderConnector(); 40 41 int WriteBinder(unsigned long request, void *value); 42 void ExitCurrentThread(unsigned long request); 43 bool IsDriverAlive(); 44 bool IsAccessTokenSupported(); 45 bool IsRealPidSupported(); 46 uint64_t GetSelfTokenID(); 47 uint64_t GetSelfFirstCallerTokenID(); 48 void CloseDriverFd(); 49 #ifdef CONFIG_ACTV_BINDER 50 bool IsActvBinderSupported(); 51 bool IsActvBinderService(); 52 #endif 53 private: 54 static BinderConnector *instance_; 55 static std::mutex skeletonMutex; 56 bool OpenDriver(); 57 bool MapMemory(uint64_t featureSet); 58 int driverFD_; 59 void *vmAddr_; 60 const std::string deviceName_; 61 int32_t version_; 62 uint64_t featureSet_; 63 uint64_t selfTokenID_; 64 #ifdef CONFIG_ACTV_BINDER 65 ActvBinderConnector actvBinder_; 66 #endif 67 }; 68 } // namespace OHOS 69 #endif // OHOS_IPC_BINDER_CONNECTOR_H 70