| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [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 | |
| 17 | #ifndef ANDROID_BINDER_H |
| 18 | #define ANDROID_BINDER_H |
| 19 | |
| Bailey Forrest | 6913c46 | 2015-08-18 17:15:10 -0700 | [diff] [blame] | 20 | #include <atomic> |
| Hans Boehm | 3effaba | 2014-08-12 22:56:00 +0000 | [diff] [blame] | 21 | #include <stdint.h> |
| Mathias Agopian | c5b2c0b | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 22 | #include <binder/IBinder.h> |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | |
| 24 | // --------------------------------------------------------------------------- |
| 25 | namespace android { |
| 26 | |
| Steven Moreland | a562a49 | 2020-02-26 16:02:08 -0800 | [diff] [blame] | 27 | namespace internal { |
| 28 | class Stability; |
| 29 | } |
| 30 | |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | class BBinder : public IBinder |
| 32 | { |
| 33 | public: |
| 34 | BBinder(); |
| 35 | |
| Mathias Agopian | 83c0446 | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 36 | virtual const String16& getInterfaceDescriptor() const; |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | virtual bool isBinderAlive() const; |
| 38 | virtual status_t pingBinder(); |
| 39 | virtual status_t dump(int fd, const Vector<String16>& args); |
| 40 | |
| Jiyong Park | b86c866 | 2018-10-29 23:01:57 +0900 | [diff] [blame] | 41 | // NOLINTNEXTLINE(google-default-arguments) |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | virtual status_t transact( uint32_t code, |
| 43 | const Parcel& data, |
| 44 | Parcel* reply, |
| Steven Moreland | 9f14ce6 | 2019-08-08 16:06:19 -0700 | [diff] [blame] | 45 | uint32_t flags = 0) final; |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | |
| Jiyong Park | b86c866 | 2018-10-29 23:01:57 +0900 | [diff] [blame] | 47 | // NOLINTNEXTLINE(google-default-arguments) |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | virtual status_t linkToDeath(const sp<DeathRecipient>& recipient, |
| Yi Kong | 87d465c | 2018-07-24 01:14:06 -0700 | [diff] [blame] | 49 | void* cookie = nullptr, |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | uint32_t flags = 0); |
| 51 | |
| Jiyong Park | b86c866 | 2018-10-29 23:01:57 +0900 | [diff] [blame] | 52 | // NOLINTNEXTLINE(google-default-arguments) |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | virtual status_t unlinkToDeath( const wp<DeathRecipient>& recipient, |
| Yi Kong | 87d465c | 2018-07-24 01:14:06 -0700 | [diff] [blame] | 54 | void* cookie = nullptr, |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | uint32_t flags = 0, |
| Yi Kong | 87d465c | 2018-07-24 01:14:06 -0700 | [diff] [blame] | 56 | wp<DeathRecipient>* outRecipient = nullptr); |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | |
| 58 | virtual void attachObject( const void* objectID, |
| 59 | void* object, |
| 60 | void* cleanupCookie, |
| Steven Moreland | b854651 | 2019-07-31 14:34:02 -0700 | [diff] [blame] | 61 | object_cleanup_func func) final; |
| 62 | virtual void* findObject(const void* objectID) const final; |
| 63 | virtual void detachObject(const void* objectID) final; |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | |
| 65 | virtual BBinder* localBinder(); |
| 66 | |
| Steven Moreland | 3085a47 | 2018-12-26 13:59:23 -0800 | [diff] [blame] | 67 | bool isRequestingSid(); |
| 68 | // This must be called before the object is sent to another process. Not thread safe. |
| 69 | void setRequestingSid(bool requestSid); |
| 70 | |
| Steven Moreland | b8ad08d | 2019-08-09 14:42:56 -0700 | [diff] [blame] | 71 | sp<IBinder> getExtension(); |
| 72 | // This must be called before the object is sent to another process. Not thread safe. |
| 73 | void setExtension(const sp<IBinder>& extension); |
| 74 | |
| Steven Moreland | b96ea77 | 2020-07-16 22:43:02 +0000 | [diff] [blame] | 75 | // This must be called before the object is sent to another process. Not thread safe. |
| 76 | // |
| 77 | // This function will abort if improper parameters are set. This is like |
| 78 | // sched_setscheduler. However, it sets the minimum scheduling policy |
| 79 | // only for the duration that this specific binder object is handling the |
| 80 | // call in a threadpool. By default, this API is set to SCHED_NORMAL/0. In |
| 81 | // this case, the scheduling priority will not actually be modified from |
| 82 | // binder defaults. See also IPCThreadState::disableBackgroundScheduling. |
| 83 | // |
| 84 | // Appropriate values are: |
| 85 | // SCHED_NORMAL: -20 <= priority <= 19 |
| 86 | // SCHED_RR/SCHED_FIFO: 1 <= priority <= 99 |
| 87 | __attribute__((weak)) |
| 88 | void setMinSchedulerPolicy(int policy, int priority); |
| 89 | __attribute__((weak)) |
| 90 | int getMinSchedulerPolicy(); |
| 91 | __attribute__((weak)) |
| 92 | int getMinSchedulerPriority(); |
| 93 | |
| Steven Moreland | 86080b8 | 2019-09-23 15:41:18 -0700 | [diff] [blame] | 94 | pid_t getDebugPid(); |
| 95 | |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | protected: |
| 97 | virtual ~BBinder(); |
| 98 | |
| Jiyong Park | b86c866 | 2018-10-29 23:01:57 +0900 | [diff] [blame] | 99 | // NOLINTNEXTLINE(google-default-arguments) |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 100 | virtual status_t onTransact( uint32_t code, |
| 101 | const Parcel& data, |
| 102 | Parcel* reply, |
| 103 | uint32_t flags = 0); |
| 104 | |
| 105 | private: |
| 106 | BBinder(const BBinder& o); |
| 107 | BBinder& operator=(const BBinder& o); |
| 108 | |
| 109 | class Extras; |
| 110 | |
| Steven Moreland | 3085a47 | 2018-12-26 13:59:23 -0800 | [diff] [blame] | 111 | Extras* getOrCreateExtras(); |
| 112 | |
| Bailey Forrest | 6913c46 | 2015-08-18 17:15:10 -0700 | [diff] [blame] | 113 | std::atomic<Extras*> mExtras; |
| Steven Moreland | a562a49 | 2020-02-26 16:02:08 -0800 | [diff] [blame] | 114 | |
| 115 | friend ::android::internal::Stability; |
| 116 | union { |
| 117 | int32_t mStability; |
| 118 | void* mReserved0; |
| 119 | }; |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 120 | }; |
| 121 | |
| 122 | // --------------------------------------------------------------------------- |
| 123 | |
| 124 | class BpRefBase : public virtual RefBase |
| 125 | { |
| 126 | protected: |
| Chih-Hung Hsieh | e3ab0e8 | 2016-09-01 11:44:54 -0700 | [diff] [blame] | 127 | explicit BpRefBase(const sp<IBinder>& o); |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 128 | virtual ~BpRefBase(); |
| 129 | virtual void onFirstRef(); |
| 130 | virtual void onLastStrongRef(const void* id); |
| 131 | virtual bool onIncStrongAttempted(uint32_t flags, const void* id); |
| 132 | |
| 133 | inline IBinder* remote() { return mRemote; } |
| 134 | inline IBinder* remote() const { return mRemote; } |
| 135 | |
| 136 | private: |
| 137 | BpRefBase(const BpRefBase& o); |
| 138 | BpRefBase& operator=(const BpRefBase& o); |
| 139 | |
| 140 | IBinder* const mRemote; |
| 141 | RefBase::weakref_type* mRefs; |
| Bailey Forrest | 6913c46 | 2015-08-18 17:15:10 -0700 | [diff] [blame] | 142 | std::atomic<int32_t> mState; |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 143 | }; |
| 144 | |
| Steven Moreland | 6511af5 | 2019-09-26 16:05:45 -0700 | [diff] [blame] | 145 | } // namespace android |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 146 | |
| 147 | // --------------------------------------------------------------------------- |
| 148 | |
| 149 | #endif // ANDROID_BINDER_H |