The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2005 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 | |
Mathias Agopian | c5b2c0b | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 17 | #include <binder/Binder.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18 | |
Bailey Forrest | 6913c46 | 2015-08-18 17:15:10 -0700 | [diff] [blame] | 19 | #include <atomic> |
Steven Moreland | d138798 | 2019-07-24 00:12:19 +0000 | [diff] [blame] | 20 | #include <utils/misc.h> |
Mathias Agopian | c5b2c0b | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 21 | #include <binder/BpBinder.h> |
| 22 | #include <binder/IInterface.h> |
Dianne Hackborn | 23eb1e2 | 2015-10-07 17:35:27 -0700 | [diff] [blame] | 23 | #include <binder/IResultReceiver.h> |
Dianne Hackborn | 1941a40 | 2016-08-29 12:30:43 -0700 | [diff] [blame] | 24 | #include <binder/IShellCallback.h> |
Mathias Agopian | c5b2c0b | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 25 | #include <binder/Parcel.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | |
Steven Moreland | bf1915b | 2020-07-16 22:43:02 +0000 | [diff] [blame^] | 27 | #include <linux/sched.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | #include <stdio.h> |
| 29 | |
| 30 | namespace android { |
| 31 | |
| 32 | // --------------------------------------------------------------------------- |
| 33 | |
Mathias Agopian | 83c0446 | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 34 | IBinder::IBinder() |
| 35 | : RefBase() |
| 36 | { |
| 37 | } |
| 38 | |
| 39 | IBinder::~IBinder() |
| 40 | { |
| 41 | } |
| 42 | |
| 43 | // --------------------------------------------------------------------------- |
| 44 | |
Colin Cross | 6f4f3ab | 2014-02-05 17:42:44 -0800 | [diff] [blame] | 45 | sp<IInterface> IBinder::queryLocalInterface(const String16& /*descriptor*/) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | { |
Yi Kong | fdd8da9 | 2018-06-07 17:52:27 -0700 | [diff] [blame] | 47 | return nullptr; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | BBinder* IBinder::localBinder() |
| 51 | { |
Yi Kong | fdd8da9 | 2018-06-07 17:52:27 -0700 | [diff] [blame] | 52 | return nullptr; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | BpBinder* IBinder::remoteBinder() |
| 56 | { |
Yi Kong | fdd8da9 | 2018-06-07 17:52:27 -0700 | [diff] [blame] | 57 | return nullptr; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | bool IBinder::checkSubclass(const void* /*subclassID*/) const |
| 61 | { |
| 62 | return false; |
| 63 | } |
| 64 | |
Dianne Hackborn | 23eb1e2 | 2015-10-07 17:35:27 -0700 | [diff] [blame] | 65 | |
Dianne Hackborn | f2bf93b | 2015-10-14 15:13:02 -0700 | [diff] [blame] | 66 | status_t IBinder::shellCommand(const sp<IBinder>& target, int in, int out, int err, |
Dianne Hackborn | 1941a40 | 2016-08-29 12:30:43 -0700 | [diff] [blame] | 67 | Vector<String16>& args, const sp<IShellCallback>& callback, |
| 68 | const sp<IResultReceiver>& resultReceiver) |
Dianne Hackborn | 23eb1e2 | 2015-10-07 17:35:27 -0700 | [diff] [blame] | 69 | { |
Dianne Hackborn | f2bf93b | 2015-10-14 15:13:02 -0700 | [diff] [blame] | 70 | Parcel send; |
| 71 | Parcel reply; |
| 72 | send.writeFileDescriptor(in); |
| 73 | send.writeFileDescriptor(out); |
| 74 | send.writeFileDescriptor(err); |
| 75 | const size_t numArgs = args.size(); |
| 76 | send.writeInt32(numArgs); |
| 77 | for (size_t i = 0; i < numArgs; i++) { |
| 78 | send.writeString16(args[i]); |
Dianne Hackborn | 23eb1e2 | 2015-10-07 17:35:27 -0700 | [diff] [blame] | 79 | } |
Yi Kong | fdd8da9 | 2018-06-07 17:52:27 -0700 | [diff] [blame] | 80 | send.writeStrongBinder(callback != nullptr ? IInterface::asBinder(callback) : nullptr); |
| 81 | send.writeStrongBinder(resultReceiver != nullptr ? IInterface::asBinder(resultReceiver) : nullptr); |
Dianne Hackborn | f2bf93b | 2015-10-14 15:13:02 -0700 | [diff] [blame] | 82 | return target->transact(SHELL_COMMAND_TRANSACTION, send, &reply); |
Dianne Hackborn | 23eb1e2 | 2015-10-07 17:35:27 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Steven Moreland | b8ad08d | 2019-08-09 14:42:56 -0700 | [diff] [blame] | 85 | status_t IBinder::getExtension(sp<IBinder>* out) { |
| 86 | BBinder* local = this->localBinder(); |
| 87 | if (local != nullptr) { |
| 88 | *out = local->getExtension(); |
| 89 | return OK; |
| 90 | } |
| 91 | |
| 92 | BpBinder* proxy = this->remoteBinder(); |
| 93 | LOG_ALWAYS_FATAL_IF(proxy == nullptr); |
| 94 | |
| 95 | Parcel data; |
| 96 | Parcel reply; |
| 97 | status_t status = transact(EXTENSION_TRANSACTION, data, &reply); |
| 98 | if (status != OK) return status; |
| 99 | |
| 100 | return reply.readNullableStrongBinder(out); |
| 101 | } |
| 102 | |
Steven Moreland | 86080b8 | 2019-09-23 15:41:18 -0700 | [diff] [blame] | 103 | status_t IBinder::getDebugPid(pid_t* out) { |
| 104 | BBinder* local = this->localBinder(); |
| 105 | if (local != nullptr) { |
| 106 | *out = local->getDebugPid(); |
| 107 | return OK; |
| 108 | } |
| 109 | |
| 110 | BpBinder* proxy = this->remoteBinder(); |
| 111 | LOG_ALWAYS_FATAL_IF(proxy == nullptr); |
| 112 | |
| 113 | Parcel data; |
| 114 | Parcel reply; |
| 115 | status_t status = transact(DEBUG_PID_TRANSACTION, data, &reply); |
| 116 | if (status != OK) return status; |
| 117 | |
| 118 | int32_t pid; |
| 119 | status = reply.readInt32(&pid); |
| 120 | if (status != OK) return status; |
| 121 | |
| 122 | if (pid < 0 || pid > std::numeric_limits<pid_t>::max()) { |
| 123 | return BAD_VALUE; |
| 124 | } |
| 125 | *out = pid; |
| 126 | return OK; |
| 127 | } |
| 128 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 129 | // --------------------------------------------------------------------------- |
| 130 | |
| 131 | class BBinder::Extras |
| 132 | { |
| 133 | public: |
Steven Moreland | f021200 | 2018-12-26 13:59:23 -0800 | [diff] [blame] | 134 | // unlocked objects |
| 135 | bool mRequestingSid = false; |
Steven Moreland | b8ad08d | 2019-08-09 14:42:56 -0700 | [diff] [blame] | 136 | sp<IBinder> mExtension; |
Steven Moreland | bf1915b | 2020-07-16 22:43:02 +0000 | [diff] [blame^] | 137 | int mPolicy = SCHED_NORMAL; |
| 138 | int mPriority = 0; |
Steven Moreland | f021200 | 2018-12-26 13:59:23 -0800 | [diff] [blame] | 139 | |
| 140 | // for below objects |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 141 | Mutex mLock; |
| 142 | BpBinder::ObjectManager mObjects; |
| 143 | }; |
| 144 | |
| 145 | // --------------------------------------------------------------------------- |
| 146 | |
Steven Moreland | a7fb018 | 2020-02-26 16:02:08 -0800 | [diff] [blame] | 147 | BBinder::BBinder() : mExtras(nullptr), mStability(0) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 148 | { |
| 149 | } |
| 150 | |
| 151 | bool BBinder::isBinderAlive() const |
| 152 | { |
| 153 | return true; |
| 154 | } |
| 155 | |
| 156 | status_t BBinder::pingBinder() |
| 157 | { |
| 158 | return NO_ERROR; |
| 159 | } |
| 160 | |
Mathias Agopian | 83c0446 | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 161 | const String16& BBinder::getInterfaceDescriptor() const |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 162 | { |
Dan Egnor | 386a332 | 2010-05-06 00:55:09 -0700 | [diff] [blame] | 163 | // This is a local static rather than a global static, |
| 164 | // to avoid static initializer ordering issues. |
| 165 | static String16 sEmptyDescriptor; |
Steve Block | 32397c1 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 166 | ALOGW("reached BBinder::getInterfaceDescriptor (this=%p)", this); |
Mathias Agopian | 83c0446 | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 167 | return sEmptyDescriptor; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 168 | } |
| 169 | |
Jiyong Park | b86c866 | 2018-10-29 23:01:57 +0900 | [diff] [blame] | 170 | // NOLINTNEXTLINE(google-default-arguments) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 171 | status_t BBinder::transact( |
| 172 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 173 | { |
| 174 | data.setDataPosition(0); |
| 175 | |
| 176 | status_t err = NO_ERROR; |
| 177 | switch (code) { |
| 178 | case PING_TRANSACTION: |
Steven Moreland | 6e69d65 | 2019-07-10 14:17:55 -0700 | [diff] [blame] | 179 | err = pingBinder(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 180 | break; |
Steven Moreland | b8ad08d | 2019-08-09 14:42:56 -0700 | [diff] [blame] | 181 | case EXTENSION_TRANSACTION: |
| 182 | err = reply->writeStrongBinder(getExtension()); |
| 183 | break; |
Steven Moreland | 86080b8 | 2019-09-23 15:41:18 -0700 | [diff] [blame] | 184 | case DEBUG_PID_TRANSACTION: |
| 185 | err = reply->writeInt32(getDebugPid()); |
| 186 | break; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 187 | default: |
| 188 | err = onTransact(code, data, reply, flags); |
| 189 | break; |
| 190 | } |
| 191 | |
Steven Moreland | a86a356 | 2019-08-01 23:28:34 +0000 | [diff] [blame] | 192 | // In case this is being transacted on in the same process. |
Yi Kong | fdd8da9 | 2018-06-07 17:52:27 -0700 | [diff] [blame] | 193 | if (reply != nullptr) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 194 | reply->setDataPosition(0); |
| 195 | } |
| 196 | |
| 197 | return err; |
| 198 | } |
| 199 | |
Jiyong Park | b86c866 | 2018-10-29 23:01:57 +0900 | [diff] [blame] | 200 | // NOLINTNEXTLINE(google-default-arguments) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 201 | status_t BBinder::linkToDeath( |
Colin Cross | 6f4f3ab | 2014-02-05 17:42:44 -0800 | [diff] [blame] | 202 | const sp<DeathRecipient>& /*recipient*/, void* /*cookie*/, |
| 203 | uint32_t /*flags*/) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 204 | { |
| 205 | return INVALID_OPERATION; |
| 206 | } |
| 207 | |
Jiyong Park | b86c866 | 2018-10-29 23:01:57 +0900 | [diff] [blame] | 208 | // NOLINTNEXTLINE(google-default-arguments) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 209 | status_t BBinder::unlinkToDeath( |
Colin Cross | 6f4f3ab | 2014-02-05 17:42:44 -0800 | [diff] [blame] | 210 | const wp<DeathRecipient>& /*recipient*/, void* /*cookie*/, |
| 211 | uint32_t /*flags*/, wp<DeathRecipient>* /*outRecipient*/) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 212 | { |
| 213 | return INVALID_OPERATION; |
| 214 | } |
| 215 | |
Dianne Hackborn | 23eb1e2 | 2015-10-07 17:35:27 -0700 | [diff] [blame] | 216 | status_t BBinder::dump(int /*fd*/, const Vector<String16>& /*args*/) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 217 | { |
| 218 | return NO_ERROR; |
| 219 | } |
| 220 | |
| 221 | void BBinder::attachObject( |
| 222 | const void* objectID, void* object, void* cleanupCookie, |
| 223 | object_cleanup_func func) |
| 224 | { |
Steven Moreland | f021200 | 2018-12-26 13:59:23 -0800 | [diff] [blame] | 225 | Extras* e = getOrCreateExtras(); |
| 226 | if (!e) return; // out of memory |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 227 | |
| 228 | AutoMutex _l(e->mLock); |
| 229 | e->mObjects.attach(objectID, object, cleanupCookie, func); |
| 230 | } |
| 231 | |
| 232 | void* BBinder::findObject(const void* objectID) const |
| 233 | { |
Bailey Forrest | 6913c46 | 2015-08-18 17:15:10 -0700 | [diff] [blame] | 234 | Extras* e = mExtras.load(std::memory_order_acquire); |
Yi Kong | fdd8da9 | 2018-06-07 17:52:27 -0700 | [diff] [blame] | 235 | if (!e) return nullptr; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 236 | |
| 237 | AutoMutex _l(e->mLock); |
| 238 | return e->mObjects.find(objectID); |
| 239 | } |
| 240 | |
| 241 | void BBinder::detachObject(const void* objectID) |
| 242 | { |
Bailey Forrest | 6913c46 | 2015-08-18 17:15:10 -0700 | [diff] [blame] | 243 | Extras* e = mExtras.load(std::memory_order_acquire); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 244 | if (!e) return; |
| 245 | |
| 246 | AutoMutex _l(e->mLock); |
| 247 | e->mObjects.detach(objectID); |
| 248 | } |
| 249 | |
| 250 | BBinder* BBinder::localBinder() |
| 251 | { |
| 252 | return this; |
| 253 | } |
| 254 | |
Steven Moreland | f021200 | 2018-12-26 13:59:23 -0800 | [diff] [blame] | 255 | bool BBinder::isRequestingSid() |
| 256 | { |
| 257 | Extras* e = mExtras.load(std::memory_order_acquire); |
| 258 | |
| 259 | return e && e->mRequestingSid; |
| 260 | } |
| 261 | |
| 262 | void BBinder::setRequestingSid(bool requestingSid) |
| 263 | { |
| 264 | Extras* e = mExtras.load(std::memory_order_acquire); |
| 265 | |
| 266 | if (!e) { |
| 267 | // default is false. Most things don't need sids, so avoiding allocations when possible. |
| 268 | if (!requestingSid) { |
| 269 | return; |
| 270 | } |
| 271 | |
| 272 | e = getOrCreateExtras(); |
| 273 | if (!e) return; // out of memory |
| 274 | } |
| 275 | |
Steven Moreland | 3668be6 | 2019-02-08 17:56:55 -0800 | [diff] [blame] | 276 | e->mRequestingSid = requestingSid; |
Steven Moreland | f021200 | 2018-12-26 13:59:23 -0800 | [diff] [blame] | 277 | } |
| 278 | |
Steven Moreland | b8ad08d | 2019-08-09 14:42:56 -0700 | [diff] [blame] | 279 | sp<IBinder> BBinder::getExtension() { |
| 280 | Extras* e = mExtras.load(std::memory_order_acquire); |
| 281 | if (e == nullptr) return nullptr; |
| 282 | return e->mExtension; |
| 283 | } |
| 284 | |
Steven Moreland | bf1915b | 2020-07-16 22:43:02 +0000 | [diff] [blame^] | 285 | void BBinder::setMinSchedulerPolicy(int policy, int priority) { |
| 286 | switch (policy) { |
| 287 | case SCHED_NORMAL: |
| 288 | LOG_ALWAYS_FATAL_IF(priority < -20 || priority > 19, "Invalid priority for SCHED_NORMAL: %d", priority); |
| 289 | break; |
| 290 | case SCHED_RR: |
| 291 | case SCHED_FIFO: |
| 292 | LOG_ALWAYS_FATAL_IF(priority < 1 || priority > 99, "Invalid priority for sched %d: %d", policy, priority); |
| 293 | break; |
| 294 | default: |
| 295 | LOG_ALWAYS_FATAL("Unrecognized scheduling policy: %d", policy); |
| 296 | } |
| 297 | |
| 298 | Extras* e = mExtras.load(std::memory_order_acquire); |
| 299 | |
| 300 | if (e == nullptr) { |
| 301 | // Avoid allocations if called with default. |
| 302 | if (policy == SCHED_NORMAL && priority == 0) { |
| 303 | return; |
| 304 | } |
| 305 | |
| 306 | e = getOrCreateExtras(); |
| 307 | if (!e) return; // out of memory |
| 308 | } |
| 309 | |
| 310 | e->mPolicy = policy; |
| 311 | e->mPriority = priority; |
| 312 | } |
| 313 | |
| 314 | int BBinder::getMinSchedulerPolicy() { |
| 315 | Extras* e = mExtras.load(std::memory_order_acquire); |
| 316 | if (e == nullptr) return SCHED_NORMAL; |
| 317 | return e->mPolicy; |
| 318 | } |
| 319 | |
| 320 | int BBinder::getMinSchedulerPriority() { |
| 321 | Extras* e = mExtras.load(std::memory_order_acquire); |
| 322 | if (e == nullptr) return 0; |
| 323 | return e->mPriority; |
| 324 | } |
| 325 | |
Steven Moreland | 86080b8 | 2019-09-23 15:41:18 -0700 | [diff] [blame] | 326 | pid_t BBinder::getDebugPid() { |
| 327 | return getpid(); |
| 328 | } |
| 329 | |
Steven Moreland | b8ad08d | 2019-08-09 14:42:56 -0700 | [diff] [blame] | 330 | void BBinder::setExtension(const sp<IBinder>& extension) { |
| 331 | Extras* e = getOrCreateExtras(); |
| 332 | e->mExtension = extension; |
| 333 | } |
| 334 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 335 | BBinder::~BBinder() |
| 336 | { |
Bailey Forrest | 6913c46 | 2015-08-18 17:15:10 -0700 | [diff] [blame] | 337 | Extras* e = mExtras.load(std::memory_order_relaxed); |
Hans Boehm | 3effaba | 2014-08-12 22:56:00 +0000 | [diff] [blame] | 338 | if (e) delete e; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | |
Jiyong Park | b86c866 | 2018-10-29 23:01:57 +0900 | [diff] [blame] | 342 | // NOLINTNEXTLINE(google-default-arguments) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 343 | status_t BBinder::onTransact( |
Colin Cross | 6f4f3ab | 2014-02-05 17:42:44 -0800 | [diff] [blame] | 344 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t /*flags*/) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 345 | { |
| 346 | switch (code) { |
| 347 | case INTERFACE_TRANSACTION: |
| 348 | reply->writeString16(getInterfaceDescriptor()); |
| 349 | return NO_ERROR; |
| 350 | |
| 351 | case DUMP_TRANSACTION: { |
| 352 | int fd = data.readFileDescriptor(); |
| 353 | int argc = data.readInt32(); |
| 354 | Vector<String16> args; |
| 355 | for (int i = 0; i < argc && data.dataAvail() > 0; i++) { |
| 356 | args.add(data.readString16()); |
| 357 | } |
| 358 | return dump(fd, args); |
| 359 | } |
Dianne Hackborn | 555f89d | 2012-05-08 18:54:22 -0700 | [diff] [blame] | 360 | |
Dianne Hackborn | 23eb1e2 | 2015-10-07 17:35:27 -0700 | [diff] [blame] | 361 | case SHELL_COMMAND_TRANSACTION: { |
| 362 | int in = data.readFileDescriptor(); |
| 363 | int out = data.readFileDescriptor(); |
| 364 | int err = data.readFileDescriptor(); |
| 365 | int argc = data.readInt32(); |
| 366 | Vector<String16> args; |
| 367 | for (int i = 0; i < argc && data.dataAvail() > 0; i++) { |
| 368 | args.add(data.readString16()); |
| 369 | } |
Dianne Hackborn | 1941a40 | 2016-08-29 12:30:43 -0700 | [diff] [blame] | 370 | sp<IShellCallback> shellCallback = IShellCallback::asInterface( |
| 371 | data.readStrongBinder()); |
Dianne Hackborn | 23eb1e2 | 2015-10-07 17:35:27 -0700 | [diff] [blame] | 372 | sp<IResultReceiver> resultReceiver = IResultReceiver::asInterface( |
| 373 | data.readStrongBinder()); |
| 374 | |
Dianne Hackborn | f2bf93b | 2015-10-14 15:13:02 -0700 | [diff] [blame] | 375 | // XXX can't add virtuals until binaries are updated. |
| 376 | //return shellCommand(in, out, err, args, resultReceiver); |
Christopher Wiley | 0a9a1c1 | 2016-07-20 08:28:14 -0700 | [diff] [blame] | 377 | (void)in; |
| 378 | (void)out; |
| 379 | (void)err; |
| 380 | |
Yi Kong | fdd8da9 | 2018-06-07 17:52:27 -0700 | [diff] [blame] | 381 | if (resultReceiver != nullptr) { |
Dianne Hackborn | f2bf93b | 2015-10-14 15:13:02 -0700 | [diff] [blame] | 382 | resultReceiver->send(INVALID_OPERATION); |
| 383 | } |
Martijn Coenen | aa6ee99 | 2017-08-17 15:38:08 +0200 | [diff] [blame] | 384 | |
| 385 | return NO_ERROR; |
Dianne Hackborn | 23eb1e2 | 2015-10-07 17:35:27 -0700 | [diff] [blame] | 386 | } |
| 387 | |
Dianne Hackborn | 555f89d | 2012-05-08 18:54:22 -0700 | [diff] [blame] | 388 | case SYSPROPS_TRANSACTION: { |
| 389 | report_sysprop_change(); |
| 390 | return NO_ERROR; |
| 391 | } |
| 392 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 393 | default: |
| 394 | return UNKNOWN_TRANSACTION; |
| 395 | } |
| 396 | } |
| 397 | |
Steven Moreland | f021200 | 2018-12-26 13:59:23 -0800 | [diff] [blame] | 398 | BBinder::Extras* BBinder::getOrCreateExtras() |
| 399 | { |
| 400 | Extras* e = mExtras.load(std::memory_order_acquire); |
| 401 | |
| 402 | if (!e) { |
| 403 | e = new Extras; |
| 404 | Extras* expected = nullptr; |
| 405 | if (!mExtras.compare_exchange_strong(expected, e, |
| 406 | std::memory_order_release, |
| 407 | std::memory_order_acquire)) { |
| 408 | delete e; |
| 409 | e = expected; // Filled in by CAS |
| 410 | } |
| 411 | if (e == nullptr) return nullptr; // out of memory |
| 412 | } |
| 413 | |
| 414 | return e; |
| 415 | } |
| 416 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 417 | // --------------------------------------------------------------------------- |
| 418 | |
| 419 | enum { |
| 420 | // This is used to transfer ownership of the remote binder from |
| 421 | // the BpRefBase object holding it (when it is constructed), to the |
| 422 | // owner of the BpRefBase object when it first acquires that BpRefBase. |
| 423 | kRemoteAcquired = 0x00000001 |
| 424 | }; |
| 425 | |
| 426 | BpRefBase::BpRefBase(const sp<IBinder>& o) |
Yi Kong | fdd8da9 | 2018-06-07 17:52:27 -0700 | [diff] [blame] | 427 | : mRemote(o.get()), mRefs(nullptr), mState(0) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 428 | { |
| 429 | extendObjectLifetime(OBJECT_LIFETIME_WEAK); |
| 430 | |
| 431 | if (mRemote) { |
| 432 | mRemote->incStrong(this); // Removed on first IncStrong(). |
| 433 | mRefs = mRemote->createWeak(this); // Held for our entire lifetime. |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | BpRefBase::~BpRefBase() |
| 438 | { |
| 439 | if (mRemote) { |
Bailey Forrest | 6913c46 | 2015-08-18 17:15:10 -0700 | [diff] [blame] | 440 | if (!(mState.load(std::memory_order_relaxed)&kRemoteAcquired)) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 441 | mRemote->decStrong(this); |
| 442 | } |
| 443 | mRefs->decWeak(this); |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | void BpRefBase::onFirstRef() |
| 448 | { |
Bailey Forrest | 6913c46 | 2015-08-18 17:15:10 -0700 | [diff] [blame] | 449 | mState.fetch_or(kRemoteAcquired, std::memory_order_relaxed); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 450 | } |
| 451 | |
Colin Cross | 6f4f3ab | 2014-02-05 17:42:44 -0800 | [diff] [blame] | 452 | void BpRefBase::onLastStrongRef(const void* /*id*/) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 453 | { |
| 454 | if (mRemote) { |
| 455 | mRemote->decStrong(this); |
| 456 | } |
| 457 | } |
| 458 | |
Colin Cross | 6f4f3ab | 2014-02-05 17:42:44 -0800 | [diff] [blame] | 459 | bool BpRefBase::onIncStrongAttempted(uint32_t /*flags*/, const void* /*id*/) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 460 | { |
| 461 | return mRemote ? mRefs->attemptIncStrong(this) : false; |
| 462 | } |
| 463 | |
| 464 | // --------------------------------------------------------------------------- |
| 465 | |
Steven Moreland | 61ff849 | 2019-09-26 16:05:45 -0700 | [diff] [blame] | 466 | } // namespace android |