Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 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 | |
Martijn Coenen | f75a23d | 2016-08-01 11:55:17 +0200 | [diff] [blame] | 17 | #ifndef ANDROID_HARDWARE_BINDER_H |
| 18 | #define ANDROID_HARDWARE_BINDER_H |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 19 | |
Bailey Forrest | e20d6f4 | 2015-08-18 17:15:10 -0700 | [diff] [blame] | 20 | #include <atomic> |
Hans Boehm | 99c620a | 2014-08-12 22:56:00 +0000 | [diff] [blame] | 21 | #include <stdint.h> |
Martijn Coenen | 4080edc | 2016-05-04 14:17:02 +0200 | [diff] [blame] | 22 | #include <hwbinder/IBinder.h> |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 23 | |
Steven Moreland | b5f6e00 | 2021-02-26 01:51:20 +0000 | [diff] [blame] | 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 | |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 28 | // --------------------------------------------------------------------------- |
| 29 | namespace android { |
Martijn Coenen | f75a23d | 2016-08-01 11:55:17 +0200 | [diff] [blame] | 30 | namespace hardware { |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 31 | |
Yifan Hong | dde40f3 | 2017-01-12 14:22:45 -0800 | [diff] [blame] | 32 | class BHwBinder : public IBinder |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 33 | { |
| 34 | public: |
Yifan Hong | dde40f3 | 2017-01-12 14:22:45 -0800 | [diff] [blame] | 35 | BHwBinder(); |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 36 | |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 37 | virtual status_t transact( uint32_t code, |
| 38 | const Parcel& data, |
| 39 | Parcel* reply, |
Martijn Coenen | 79c2f4d | 2016-05-20 10:55:59 +0200 | [diff] [blame] | 40 | uint32_t flags = 0, |
| 41 | TransactCallback callback = nullptr); |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 42 | |
| 43 | virtual status_t linkToDeath(const sp<DeathRecipient>& recipient, |
Yi Kong | 55d4107 | 2018-07-23 14:55:39 -0700 | [diff] [blame] | 44 | void* cookie = nullptr, |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 45 | uint32_t flags = 0); |
| 46 | |
| 47 | virtual status_t unlinkToDeath( const wp<DeathRecipient>& recipient, |
Yi Kong | 55d4107 | 2018-07-23 14:55:39 -0700 | [diff] [blame] | 48 | void* cookie = nullptr, |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 49 | uint32_t flags = 0, |
Yi Kong | 55d4107 | 2018-07-23 14:55:39 -0700 | [diff] [blame] | 50 | wp<DeathRecipient>* outRecipient = nullptr); |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 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 | |
Yifan Hong | dde40f3 | 2017-01-12 14:22:45 -0800 | [diff] [blame] | 59 | virtual BHwBinder* localBinder(); |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 60 | |
Martijn Coenen | 3f18128 | 2017-05-03 13:45:32 -0700 | [diff] [blame] | 61 | int getMinSchedulingPolicy(); |
| 62 | int getMinSchedulingPriority(); |
Steven Moreland | 7375a87 | 2018-12-26 13:59:23 -0800 | [diff] [blame] | 63 | |
| 64 | bool isRequestingSid(); |
| 65 | |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 66 | protected: |
Yifan Hong | dde40f3 | 2017-01-12 14:22:45 -0800 | [diff] [blame] | 67 | virtual ~BHwBinder(); |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 68 | |
| 69 | virtual status_t onTransact( uint32_t code, |
| 70 | const Parcel& data, |
| 71 | Parcel* reply, |
Martijn Coenen | 79c2f4d | 2016-05-20 10:55:59 +0200 | [diff] [blame] | 72 | uint32_t flags = 0, |
| 73 | TransactCallback callback = nullptr); |
Steven Moreland | 7375a87 | 2018-12-26 13:59:23 -0800 | [diff] [blame] | 74 | |
| 75 | // This must be called before the object is sent to another process. Not thread safe. |
Steven Moreland | 8a3fd5a | 2020-07-07 23:03:12 +0000 | [diff] [blame] | 76 | // |
| 77 | // If this is called with true, and the kernel supports it, |
| 78 | // IPCThreadState::getCallingSid will return values for remote processes. |
Steven Moreland | 7375a87 | 2018-12-26 13:59:23 -0800 | [diff] [blame] | 79 | void setRequestingSid(bool requestSid); |
| 80 | |
Martijn Coenen | 3f18128 | 2017-05-03 13:45:32 -0700 | [diff] [blame] | 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; |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 84 | private: |
Yifan Hong | dde40f3 | 2017-01-12 14:22:45 -0800 | [diff] [blame] | 85 | BHwBinder(const BHwBinder& o); |
| 86 | BHwBinder& operator=(const BHwBinder& o); |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 87 | |
| 88 | class Extras; |
| 89 | |
Steven Moreland | 7375a87 | 2018-12-26 13:59:23 -0800 | [diff] [blame] | 90 | Extras* getOrCreateExtras(); |
| 91 | |
Bailey Forrest | e20d6f4 | 2015-08-18 17:15:10 -0700 | [diff] [blame] | 92 | std::atomic<Extras*> mExtras; |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 93 | void* mReserved0; |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | // --------------------------------------------------------------------------- |
| 97 | |
Yifan Hong | a2ce3b8 | 2017-01-12 14:49:26 -0800 | [diff] [blame] | 98 | class BpHwRefBase : public virtual RefBase |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 99 | { |
| 100 | protected: |
Chih-Hung Hsieh | 2ecdeaf | 2016-09-01 11:44:54 -0700 | [diff] [blame] | 101 | explicit BpHwRefBase(const sp<IBinder>& o); |
Yifan Hong | a2ce3b8 | 2017-01-12 14:49:26 -0800 | [diff] [blame] | 102 | virtual ~BpHwRefBase(); |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 103 | virtual void onFirstRef(); |
| 104 | virtual void onLastStrongRef(const void* id); |
| 105 | virtual bool onIncStrongAttempted(uint32_t flags, const void* id); |
| 106 | |
Steven Moreland | 81dbdee | 2018-09-27 10:56:35 -0700 | [diff] [blame] | 107 | public: |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 108 | inline IBinder* remote() const { return mRemote; } |
| 109 | |
| 110 | private: |
Yifan Hong | a2ce3b8 | 2017-01-12 14:49:26 -0800 | [diff] [blame] | 111 | BpHwRefBase(const BpHwRefBase& o); |
| 112 | BpHwRefBase& operator=(const BpHwRefBase& o); |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 113 | |
| 114 | IBinder* const mRemote; |
| 115 | RefBase::weakref_type* mRefs; |
Bailey Forrest | e20d6f4 | 2015-08-18 17:15:10 -0700 | [diff] [blame] | 116 | std::atomic<int32_t> mState; |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 117 | }; |
| 118 | |
Steven Moreland | 7173a4c | 2019-09-26 15:55:02 -0700 | [diff] [blame] | 119 | } // namespace hardware |
| 120 | } // namespace android |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 121 | |
| 122 | // --------------------------------------------------------------------------- |
| 123 | |
Martijn Coenen | f75a23d | 2016-08-01 11:55:17 +0200 | [diff] [blame] | 124 | #endif // ANDROID_HARDWARE_BINDER_H |