1 /* 2 * Copyright (C) 2021 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_IREMOTE_INVOKER_H 17 #define OHOS_IPC_IREMOTE_INVOKER_H 18 19 #include <unistd.h> 20 #include <sys/types.h> 21 #include "parcel.h" 22 #include "sys_binder.h" 23 #include "iremote_object.h" 24 #include "ipc_file_descriptor.h" 25 26 namespace OHOS { 27 #ifdef CONFIG_IPC_SINGLE 28 namespace IPC_SINGLE { 29 #endif 30 class IRemoteInvoker { 31 public: 32 enum { 33 IDLE_INVOKER, 34 ACTIVE_INVOKER, 35 }; 36 virtual ~IRemoteInvoker() = default; 37 virtual bool AcquireHandle(int32_t handle) = 0; 38 39 virtual bool ReleaseHandle(int32_t handle) = 0; 40 41 virtual bool PingService(int32_t handle) = 0; 42 43 virtual int SendReply(MessageParcel &reply, uint32_t flags, int32_t result) = 0; 44 45 virtual int SendRequest(int handle, uint32_t code, MessageParcel &data, MessageParcel &reply, 46 MessageOption &option) = 0; 47 48 virtual bool AddDeathRecipient(int32_t handle, void *cookie) = 0; 49 50 virtual bool RemoveDeathRecipient(int32_t handle, void *cookie) = 0; 51 52 virtual bool SetMaxWorkThread(int maxThreadNum) = 0; 53 54 virtual void JoinThread(bool initiative) = 0; 55 56 virtual void JoinProcessThread(bool initiative) = 0; 57 58 virtual void StopWorkThread() = 0; 59 60 virtual void FreeBuffer(void *data) = 0; 61 62 virtual bool SetRegistryObject(sptr<IRemoteObject> &object) = 0; 63 64 virtual std::string GetCallerSid() const = 0; 65 66 virtual pid_t GetCallerPid() const = 0; 67 68 virtual pid_t GetCallerRealPid() const = 0; 69 70 virtual uid_t GetCallerUid() const = 0; 71 72 virtual uint64_t GetCallerTokenID() const = 0; 73 74 virtual uint64_t GetFirstCallerTokenID() const = 0; 75 76 virtual uint64_t GetSelfTokenID() const = 0; 77 78 virtual uint64_t GetSelfFirstCallerTokenID() const = 0; 79 80 virtual uint32_t GetStatus() = 0; 81 82 virtual bool IsLocalCalling() = 0; 83 84 virtual std::string GetLocalDeviceID() = 0; 85 86 virtual std::string GetCallerDeviceID() const = 0; 87 88 virtual bool FlattenObject(Parcel &parcel, const IRemoteObject *object) const = 0; 89 90 virtual sptr<IRemoteObject> UnflattenObject(Parcel &parcel) = 0; 91 92 virtual int ReadFileDescriptor(Parcel &parcel) = 0; 93 94 virtual bool WriteFileDescriptor(Parcel &parcel, int fd, bool takeOwnership) = 0; 95 96 virtual int FlushCommands(IRemoteObject *object) = 0; 97 98 virtual std::string ResetCallingIdentity() = 0; 99 100 virtual bool SetCallingIdentity(std::string &identity, bool flag) = 0; 101 102 #ifndef CONFIG_IPC_SINGLE 103 virtual sptr<IRemoteObject> GetSAMgrObject() = 0; 104 105 virtual int TranslateIRemoteObject(int32_t cmd, const sptr<IRemoteObject> &obj) = 0; 106 107 #endif 108 }; 109 #ifdef CONFIG_IPC_SINGLE 110 } // namespace IPC_SINGLE 111 #endif 112 } // namespace OHOS 113 #endif // OHOS_IPC_IREMOTE_INVOKER_H 114