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