• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ANDROID_HARDWARE_BINDER_H
18 #define ANDROID_HARDWARE_BINDER_H
19 
20 #include <atomic>
21 #include <stdint.h>
22 #include <hwbinder/IBinder.h>
23 
24 // WARNING: this code is part of libhwbinder, a fork of libbinder. Generally,
25 // this means that it is only relevant to HIDL. Any AIDL- or libbinder-specific
26 // code should not try to use these things.
27 
28 // ---------------------------------------------------------------------------
29 namespace android {
30 namespace hardware {
31 
32 class BHwBinder : public IBinder
33 {
34 public:
35                         BHwBinder();
36 
37     virtual status_t    transact(   uint32_t code,
38                                     const Parcel& data,
39                                     Parcel* reply,
40                                     uint32_t flags = 0,
41                                     TransactCallback callback = nullptr);
42 
43     virtual status_t    linkToDeath(const sp<DeathRecipient>& recipient,
44                                     void* cookie = nullptr,
45                                     uint32_t flags = 0);
46 
47     virtual status_t    unlinkToDeath(  const wp<DeathRecipient>& recipient,
48                                         void* cookie = nullptr,
49                                         uint32_t flags = 0,
50                                         wp<DeathRecipient>* outRecipient = nullptr);
51 
52     virtual void        attachObject(   const void* objectID,
53                                         void* object,
54                                         void* cleanupCookie,
55                                         object_cleanup_func func);
56     virtual void*       findObject(const void* objectID) const;
57     virtual void        detachObject(const void* objectID);
58 
59     virtual BHwBinder*    localBinder();
60 
61     int                 getMinSchedulingPolicy();
62     int                 getMinSchedulingPriority();
63 
64     bool                isRequestingSid();
65 
66 protected:
67     virtual             ~BHwBinder();
68 
69     virtual status_t    onTransact( uint32_t code,
70                                     const Parcel& data,
71                                     Parcel* reply,
72                                     uint32_t flags = 0,
73                                     TransactCallback callback = nullptr);
74 
75     // This must be called before the object is sent to another process. Not thread safe.
76     //
77     // If this is called with true, and the kernel supports it,
78     // IPCThreadState::getCallingSid will return values for remote processes.
79     void                setRequestingSid(bool requestSid);
80 
81     int                 mSchedPolicy; // policy to run transaction from this node at
82     // priority [-20..19] for SCHED_NORMAL, [1..99] for SCHED_FIFO/RT
83     int                 mSchedPriority;
84 private:
85                         BHwBinder(const BHwBinder& o);
86             BHwBinder&    operator=(const BHwBinder& o);
87 
88     class Extras;
89 
90     Extras*             getOrCreateExtras();
91 
92     std::atomic<Extras*> mExtras;
93             void*       mReserved0;
94 };
95 
96 // ---------------------------------------------------------------------------
97 
98 class BpHwRefBase : public virtual RefBase
99 {
100 protected:
101     explicit                BpHwRefBase(const sp<IBinder>& o);
102     virtual                 ~BpHwRefBase();
103     virtual void            onFirstRef();
104     virtual void            onLastStrongRef(const void* id);
105     virtual bool            onIncStrongAttempted(uint32_t flags, const void* id);
106 
107 public:
remote()108     inline  IBinder*        remote() const          { return mRemote; }
109 
110 private:
111                             BpHwRefBase(const BpHwRefBase& o);
112     BpHwRefBase&              operator=(const BpHwRefBase& o);
113 
114     IBinder* const          mRemote;
115     RefBase::weakref_type*  mRefs;
116     std::atomic<int32_t>    mState;
117 };
118 
119 } // namespace hardware
120 } // namespace android
121 
122 // ---------------------------------------------------------------------------
123 
124 #endif // ANDROID_HARDWARE_BINDER_H
125