diff options
Diffstat (limited to 'libs/binder/include/binder/BpBinder.h')
-rw-r--r-- | libs/binder/include/binder/BpBinder.h | 74 |
1 files changed, 60 insertions, 14 deletions
diff --git a/libs/binder/include/binder/BpBinder.h b/libs/binder/include/binder/BpBinder.h index 8e871b8214..61bf018e43 100644 --- a/libs/binder/include/binder/BpBinder.h +++ b/libs/binder/include/binder/BpBinder.h @@ -14,31 +14,41 @@ * limitations under the License. */ -#ifndef ANDROID_BPBINDER_H -#define ANDROID_BPBINDER_H +#pragma once #include <binder/IBinder.h> +#include <binder/RpcAddress.h> #include <utils/KeyedVector.h> #include <utils/Mutex.h> #include <utils/threads.h> #include <unordered_map> +#include <variant> // --------------------------------------------------------------------------- namespace android { +class RpcSession; +class RpcState; namespace internal { class Stability; -}; +} +class ProcessState; using binder_proxy_limit_callback = void(*)(int); class BpBinder : public IBinder { public: - static BpBinder* create(int32_t handle); + static sp<BpBinder> create(int32_t handle); + static sp<BpBinder> create(const sp<RpcSession>& session, const RpcAddress& address); - int32_t handle() const; + /** + * Return value: + * true - this is associated with a socket RpcSession + * false - (usual) binder over e.g. /dev/binder + */ + bool isRpcBinder() const; virtual const String16& getInterfaceDescriptor() const; virtual bool isBinderAlive() const; @@ -110,18 +120,57 @@ public: KeyedVector<const void*, entry_t> mObjects; }; -protected: - BpBinder(int32_t handle,int32_t trackedUid); + class PrivateAccessorForId { + private: + friend class BpBinder; + friend class ::android::Parcel; + friend class ::android::ProcessState; + friend class ::android::RpcState; + explicit PrivateAccessorForId(const BpBinder* binder) : mBinder(binder) {} + + // valid if !isRpcBinder + int32_t binderHandle() const { return mBinder->binderHandle(); } + + // valid if isRpcBinder + const RpcAddress& rpcAddress() const { return mBinder->rpcAddress(); } + const sp<RpcSession>& rpcSession() const { return mBinder->rpcSession(); } + + const BpBinder* mBinder; + }; + const PrivateAccessorForId getPrivateAccessorForId() const { + return PrivateAccessorForId(this); + } + +private: + friend PrivateAccessorForId; + friend class sp<BpBinder>; + + struct BinderHandle { + int32_t handle; + }; + struct RpcHandle { + sp<RpcSession> session; + RpcAddress address; + }; + using Handle = std::variant<BinderHandle, RpcHandle>; + + int32_t binderHandle() const; + const RpcAddress& rpcAddress() const; + const sp<RpcSession>& rpcSession() const; + + explicit BpBinder(Handle&& handle); + BpBinder(BinderHandle&& handle, int32_t trackedUid); + explicit BpBinder(RpcHandle&& handle); + virtual ~BpBinder(); virtual void onFirstRef(); virtual void onLastStrongRef(const void* id); virtual bool onIncStrongAttempted(uint32_t flags, const void* id); -private: - const int32_t mHandle; - friend ::android::internal::Stability; - int32_t mStability; + + int32_t mStability; + Handle mHandle; struct Obituary { wp<DeathRecipient> recipient; @@ -137,7 +186,6 @@ private: volatile int32_t mObitsSent; Vector<Obituary>* mObituaries; ObjectManager mObjects; - Parcel* mConstantData; mutable String16 mDescriptorCache; int32_t mTrackedUid; @@ -154,5 +202,3 @@ private: } // namespace android // --------------------------------------------------------------------------- - -#endif // ANDROID_BPBINDER_H |