blob: 50c7053b13d3716f589391569ac3463dee4a5622 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
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
17#define LOG_TAG "BpBinder"
18//#define LOG_NDEBUG 0
19
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070020#include <binder/BpBinder.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080021
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070022#include <binder/IPCThreadState.h>
Dianne Hackborn23eb1e22015-10-07 17:35:27 -070023#include <binder/IResultReceiver.h>
Steven Moreland6e5a7752019-08-05 20:30:14 -070024#include <binder/Stability.h>
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -070025#include <cutils/compiler.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080026#include <utils/Log.h>
27
28#include <stdio.h>
29
Steve Block6807e592011-10-20 11:56:00 +010030//#undef ALOGV
31//#define ALOGV(...) fprintf(stderr, __VA_ARGS__)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080032
33namespace android {
34
35// ---------------------------------------------------------------------------
36
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -070037Mutex BpBinder::sTrackingLock;
38std::unordered_map<int32_t,uint32_t> BpBinder::sTrackingMap;
39int BpBinder::sNumTrackedUids = 0;
40std::atomic_bool BpBinder::sCountByUidEnabled(false);
41binder_proxy_limit_callback BpBinder::sLimitCallback;
42bool BpBinder::sBinderProxyThrottleCreate = false;
43
44// Arbitrarily high value that probably distinguishes a bad behaving app
45uint32_t BpBinder::sBinderProxyCountHighWatermark = 2500;
46// Another arbitrary value a binder count needs to drop below before another callback will be called
47uint32_t BpBinder::sBinderProxyCountLowWatermark = 2000;
48
49enum {
Michael Wachenschwanz74d967a2018-05-15 15:03:57 -070050 LIMIT_REACHED_MASK = 0x80000000, // A flag denoting that the limit has been reached
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -070051 COUNTING_VALUE_MASK = 0x7FFFFFFF, // A mask of the remaining bits for the count value
52};
53
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080054BpBinder::ObjectManager::ObjectManager()
55{
56}
57
58BpBinder::ObjectManager::~ObjectManager()
59{
60 kill();
61}
62
63void BpBinder::ObjectManager::attach(
64 const void* objectID, void* object, void* cleanupCookie,
65 IBinder::object_cleanup_func func)
66{
67 entry_t e;
68 e.object = object;
69 e.cleanupCookie = cleanupCookie;
70 e.func = func;
71
72 if (mObjects.indexOfKey(objectID) >= 0) {
Steve Blocke6f43dd2012-01-06 19:20:56 +000073 ALOGE("Trying to attach object ID %p to binder ObjectManager %p with object %p, but object ID already in use",
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080074 objectID, this, object);
75 return;
76 }
77
78 mObjects.add(objectID, e);
79}
80
81void* BpBinder::ObjectManager::find(const void* objectID) const
82{
83 const ssize_t i = mObjects.indexOfKey(objectID);
Yi Kongfdd8da92018-06-07 17:52:27 -070084 if (i < 0) return nullptr;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080085 return mObjects.valueAt(i).object;
86}
87
88void BpBinder::ObjectManager::detach(const void* objectID)
89{
90 mObjects.removeItem(objectID);
91}
92
93void BpBinder::ObjectManager::kill()
94{
95 const size_t N = mObjects.size();
Mark Salyzynd4ecccf2014-05-30 16:35:57 -070096 ALOGV("Killing %zu objects in manager %p", N, this);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080097 for (size_t i=0; i<N; i++) {
98 const entry_t& e = mObjects.valueAt(i);
Yi Kongfdd8da92018-06-07 17:52:27 -070099 if (e.func != nullptr) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800100 e.func(mObjects.keyAt(i), e.object, e.cleanupCookie);
101 }
102 }
103
104 mObjects.clear();
105}
106
107// ---------------------------------------------------------------------------
108
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700109
110BpBinder* BpBinder::create(int32_t handle) {
111 int32_t trackedUid = -1;
112 if (sCountByUidEnabled) {
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700113 trackedUid = IPCThreadState::self()->getCallingUid();
114 AutoMutex _l(sTrackingLock);
Michael Wachenschwanz74d967a2018-05-15 15:03:57 -0700115 uint32_t trackedValue = sTrackingMap[trackedUid];
116 if (CC_UNLIKELY(trackedValue & LIMIT_REACHED_MASK)) {
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700117 if (sBinderProxyThrottleCreate) {
Michael Wachenschwanz74d967a2018-05-15 15:03:57 -0700118 return nullptr;
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700119 }
120 } else {
Michael Wachenschwanz74d967a2018-05-15 15:03:57 -0700121 if ((trackedValue & COUNTING_VALUE_MASK) >= sBinderProxyCountHighWatermark) {
122 ALOGE("Too many binder proxy objects sent to uid %d from uid %d (%d proxies held)",
123 getuid(), trackedUid, trackedValue);
124 sTrackingMap[trackedUid] |= LIMIT_REACHED_MASK;
125 if (sLimitCallback) sLimitCallback(trackedUid);
126 if (sBinderProxyThrottleCreate) {
127 ALOGI("Throttling binder proxy creates from uid %d in uid %d until binder proxy"
128 " count drops below %d",
129 trackedUid, getuid(), sBinderProxyCountLowWatermark);
130 return nullptr;
131 }
132 }
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700133 }
Michael Wachenschwanz74d967a2018-05-15 15:03:57 -0700134 sTrackingMap[trackedUid]++;
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700135 }
Michael Wachenschwanz74d967a2018-05-15 15:03:57 -0700136 return new BpBinder(handle, trackedUid);
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700137}
138
139BpBinder::BpBinder(int32_t handle, int32_t trackedUid)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800140 : mHandle(handle)
141 , mAlive(1)
142 , mObitsSent(0)
Yi Kongfdd8da92018-06-07 17:52:27 -0700143 , mObituaries(nullptr)
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700144 , mTrackedUid(trackedUid)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800145{
Steve Block6807e592011-10-20 11:56:00 +0100146 ALOGV("Creating BpBinder %p handle %d\n", this, mHandle);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800147
148 extendObjectLifetime(OBJECT_LIFETIME_WEAK);
Martijn Coenen7c170bb2018-05-04 17:28:55 -0700149 IPCThreadState::self()->incWeakHandle(handle, this);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800150}
151
Steven Moreland85180c02019-07-16 14:24:20 -0700152int32_t BpBinder::handle() const {
153 return mHandle;
154}
155
Mathias Agopian83c04462009-05-22 19:00:22 -0700156bool BpBinder::isDescriptorCached() const {
157 Mutex::Autolock _l(mLock);
158 return mDescriptorCache.size() ? true : false;
159}
160
161const String16& BpBinder::getInterfaceDescriptor() const
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800162{
Mathias Agopian83c04462009-05-22 19:00:22 -0700163 if (isDescriptorCached() == false) {
164 Parcel send, reply;
165 // do the IPC without a lock held.
166 status_t err = const_cast<BpBinder*>(this)->transact(
167 INTERFACE_TRANSACTION, send, &reply);
168 if (err == NO_ERROR) {
169 String16 res(reply.readString16());
170 Mutex::Autolock _l(mLock);
171 // mDescriptorCache could have been assigned while the lock was
172 // released.
173 if (mDescriptorCache.size() == 0)
174 mDescriptorCache = res;
175 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800176 }
Mark Salyzynd4ecccf2014-05-30 16:35:57 -0700177
Mathias Agopian83c04462009-05-22 19:00:22 -0700178 // we're returning a reference to a non-static object here. Usually this
Mark Salyzynd4ecccf2014-05-30 16:35:57 -0700179 // is not something smart to do, however, with binder objects it is
Mathias Agopian83c04462009-05-22 19:00:22 -0700180 // (usually) safe because they are reference-counted.
Mark Salyzynd4ecccf2014-05-30 16:35:57 -0700181
Mathias Agopian83c04462009-05-22 19:00:22 -0700182 return mDescriptorCache;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800183}
184
185bool BpBinder::isBinderAlive() const
186{
187 return mAlive != 0;
188}
189
190status_t BpBinder::pingBinder()
191{
192 Parcel send;
193 Parcel reply;
Steven Moreland6e69d652019-07-10 14:17:55 -0700194 return transact(PING_TRANSACTION, send, &reply);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800195}
196
197status_t BpBinder::dump(int fd, const Vector<String16>& args)
198{
199 Parcel send;
200 Parcel reply;
201 send.writeFileDescriptor(fd);
202 const size_t numArgs = args.size();
203 send.writeInt32(numArgs);
204 for (size_t i = 0; i < numArgs; i++) {
205 send.writeString16(args[i]);
206 }
207 status_t err = transact(DUMP_TRANSACTION, send, &reply);
208 return err;
209}
210
Jiyong Parkb86c8662018-10-29 23:01:57 +0900211// NOLINTNEXTLINE(google-default-arguments)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800212status_t BpBinder::transact(
213 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
214{
215 // Once a binder has died, it will never come back to life.
216 if (mAlive) {
Steven Moreland6e5a7752019-08-05 20:30:14 -0700217 // user transactions require a given stability level
218 if (code >= FIRST_CALL_TRANSACTION && code <= LAST_CALL_TRANSACTION) {
219 using android::internal::Stability;
220
221 auto stability = Stability::get(this);
222
223 if (CC_UNLIKELY(!Stability::check(stability, Stability::kLocalStability))) {
Steven Moreland86a17f82019-09-10 10:18:00 -0700224 ALOGE("Cannot do a user transaction on a %s binder in a %s context.",
225 Stability::stabilityString(stability).c_str(),
226 Stability::stabilityString(Stability::kLocalStability).c_str());
Steven Moreland6e5a7752019-08-05 20:30:14 -0700227 return BAD_TYPE;
228 }
229 }
230
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800231 status_t status = IPCThreadState::self()->transact(
232 mHandle, code, data, reply, flags);
233 if (status == DEAD_OBJECT) mAlive = 0;
Steven Morelanda86a3562019-08-01 23:28:34 +0000234
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800235 return status;
236 }
237
238 return DEAD_OBJECT;
239}
240
Jiyong Parkb86c8662018-10-29 23:01:57 +0900241// NOLINTNEXTLINE(google-default-arguments)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800242status_t BpBinder::linkToDeath(
243 const sp<DeathRecipient>& recipient, void* cookie, uint32_t flags)
244{
245 Obituary ob;
246 ob.recipient = recipient;
247 ob.cookie = cookie;
248 ob.flags = flags;
249
Yi Kongfdd8da92018-06-07 17:52:27 -0700250 LOG_ALWAYS_FATAL_IF(recipient == nullptr,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800251 "linkToDeath(): recipient must be non-NULL");
252
253 {
254 AutoMutex _l(mLock);
255
256 if (!mObitsSent) {
257 if (!mObituaries) {
258 mObituaries = new Vector<Obituary>;
259 if (!mObituaries) {
260 return NO_MEMORY;
261 }
Steve Block6807e592011-10-20 11:56:00 +0100262 ALOGV("Requesting death notification: %p handle %d\n", this, mHandle);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800263 getWeakRefs()->incWeak(this);
264 IPCThreadState* self = IPCThreadState::self();
265 self->requestDeathNotification(mHandle, this);
266 self->flushCommands();
267 }
268 ssize_t res = mObituaries->add(ob);
269 return res >= (ssize_t)NO_ERROR ? (status_t)NO_ERROR : res;
270 }
271 }
272
273 return DEAD_OBJECT;
274}
275
Jiyong Parkb86c8662018-10-29 23:01:57 +0900276// NOLINTNEXTLINE(google-default-arguments)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800277status_t BpBinder::unlinkToDeath(
278 const wp<DeathRecipient>& recipient, void* cookie, uint32_t flags,
279 wp<DeathRecipient>* outRecipient)
280{
281 AutoMutex _l(mLock);
282
283 if (mObitsSent) {
284 return DEAD_OBJECT;
285 }
286
287 const size_t N = mObituaries ? mObituaries->size() : 0;
288 for (size_t i=0; i<N; i++) {
289 const Obituary& obit = mObituaries->itemAt(i);
290 if ((obit.recipient == recipient
Yi Kongfdd8da92018-06-07 17:52:27 -0700291 || (recipient == nullptr && obit.cookie == cookie))
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800292 && obit.flags == flags) {
Yi Kongfdd8da92018-06-07 17:52:27 -0700293 if (outRecipient != nullptr) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800294 *outRecipient = mObituaries->itemAt(i).recipient;
295 }
296 mObituaries->removeAt(i);
297 if (mObituaries->size() == 0) {
Steve Block6807e592011-10-20 11:56:00 +0100298 ALOGV("Clearing death notification: %p handle %d\n", this, mHandle);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800299 IPCThreadState* self = IPCThreadState::self();
300 self->clearDeathNotification(mHandle, this);
301 self->flushCommands();
302 delete mObituaries;
Yi Kongfdd8da92018-06-07 17:52:27 -0700303 mObituaries = nullptr;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800304 }
305 return NO_ERROR;
306 }
307 }
308
309 return NAME_NOT_FOUND;
310}
311
312void BpBinder::sendObituary()
313{
Steve Block6807e592011-10-20 11:56:00 +0100314 ALOGV("Sending obituary for proxy %p handle %d, mObitsSent=%s\n",
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800315 this, mHandle, mObitsSent ? "true" : "false");
316
317 mAlive = 0;
318 if (mObitsSent) return;
319
320 mLock.lock();
321 Vector<Obituary>* obits = mObituaries;
Yi Kongfdd8da92018-06-07 17:52:27 -0700322 if(obits != nullptr) {
Steve Block6807e592011-10-20 11:56:00 +0100323 ALOGV("Clearing sent death notification: %p handle %d\n", this, mHandle);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800324 IPCThreadState* self = IPCThreadState::self();
325 self->clearDeathNotification(mHandle, this);
326 self->flushCommands();
Yi Kongfdd8da92018-06-07 17:52:27 -0700327 mObituaries = nullptr;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800328 }
329 mObitsSent = 1;
330 mLock.unlock();
331
Mark Salyzynd4ecccf2014-05-30 16:35:57 -0700332 ALOGV("Reporting death of proxy %p for %zu recipients\n",
333 this, obits ? obits->size() : 0U);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800334
Yi Kongfdd8da92018-06-07 17:52:27 -0700335 if (obits != nullptr) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800336 const size_t N = obits->size();
337 for (size_t i=0; i<N; i++) {
338 reportOneDeath(obits->itemAt(i));
339 }
340
341 delete obits;
342 }
343}
344
345void BpBinder::reportOneDeath(const Obituary& obit)
346{
347 sp<DeathRecipient> recipient = obit.recipient.promote();
Steve Block6807e592011-10-20 11:56:00 +0100348 ALOGV("Reporting death to recipient: %p\n", recipient.get());
Yi Kongfdd8da92018-06-07 17:52:27 -0700349 if (recipient == nullptr) return;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800350
351 recipient->binderDied(this);
352}
353
354
355void BpBinder::attachObject(
356 const void* objectID, void* object, void* cleanupCookie,
357 object_cleanup_func func)
358{
359 AutoMutex _l(mLock);
Steve Block6807e592011-10-20 11:56:00 +0100360 ALOGV("Attaching object %p to binder %p (manager=%p)", object, this, &mObjects);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800361 mObjects.attach(objectID, object, cleanupCookie, func);
362}
363
364void* BpBinder::findObject(const void* objectID) const
365{
366 AutoMutex _l(mLock);
367 return mObjects.find(objectID);
368}
369
370void BpBinder::detachObject(const void* objectID)
371{
372 AutoMutex _l(mLock);
373 mObjects.detach(objectID);
374}
375
376BpBinder* BpBinder::remoteBinder()
377{
378 return this;
379}
380
381BpBinder::~BpBinder()
382{
Steve Block6807e592011-10-20 11:56:00 +0100383 ALOGV("Destroying BpBinder %p handle %d\n", this, mHandle);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800384
385 IPCThreadState* ipc = IPCThreadState::self();
386
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700387 if (mTrackedUid >= 0) {
388 AutoMutex _l(sTrackingLock);
Michael Wachenschwanz74d967a2018-05-15 15:03:57 -0700389 uint32_t trackedValue = sTrackingMap[mTrackedUid];
390 if (CC_UNLIKELY((trackedValue & COUNTING_VALUE_MASK) == 0)) {
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700391 ALOGE("Unexpected Binder Proxy tracking decrement in %p handle %d\n", this, mHandle);
392 } else {
393 if (CC_UNLIKELY(
Michael Wachenschwanz74d967a2018-05-15 15:03:57 -0700394 (trackedValue & LIMIT_REACHED_MASK) &&
395 ((trackedValue & COUNTING_VALUE_MASK) <= sBinderProxyCountLowWatermark)
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700396 )) {
Michael Wachenschwanz74d967a2018-05-15 15:03:57 -0700397 ALOGI("Limit reached bit reset for uid %d (fewer than %d proxies from uid %d held)",
398 getuid(), mTrackedUid, sBinderProxyCountLowWatermark);
399 sTrackingMap[mTrackedUid] &= ~LIMIT_REACHED_MASK;
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700400 }
401 if (--sTrackingMap[mTrackedUid] == 0) {
402 sTrackingMap.erase(mTrackedUid);
403 }
404 }
405 }
406
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800407 if (ipc) {
408 ipc->expungeHandle(mHandle, this);
409 ipc->decWeakHandle(mHandle);
410 }
411}
412
413void BpBinder::onFirstRef()
414{
Steve Block6807e592011-10-20 11:56:00 +0100415 ALOGV("onFirstRef BpBinder %p handle %d\n", this, mHandle);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800416 IPCThreadState* ipc = IPCThreadState::self();
Martijn Coenen7c170bb2018-05-04 17:28:55 -0700417 if (ipc) ipc->incStrongHandle(mHandle, this);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800418}
419
Colin Cross6f4f3ab2014-02-05 17:42:44 -0800420void BpBinder::onLastStrongRef(const void* /*id*/)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800421{
Steve Block6807e592011-10-20 11:56:00 +0100422 ALOGV("onLastStrongRef BpBinder %p handle %d\n", this, mHandle);
423 IF_ALOGV() {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800424 printRefs();
425 }
426 IPCThreadState* ipc = IPCThreadState::self();
427 if (ipc) ipc->decStrongHandle(mHandle);
Steven Moreland80d23932019-06-07 12:43:27 -0700428
429 mLock.lock();
430 Vector<Obituary>* obits = mObituaries;
431 if(obits != nullptr) {
432 if (!obits->isEmpty()) {
433 ALOGI("onLastStrongRef automatically unlinking death recipients");
434 }
435
436 if (ipc) ipc->clearDeathNotification(mHandle, this);
437 mObituaries = nullptr;
438 }
439 mLock.unlock();
440
441 if (obits != nullptr) {
442 // XXX Should we tell any remaining DeathRecipient
443 // objects that the last strong ref has gone away, so they
444 // are no longer linked?
445 delete obits;
446 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800447}
448
Colin Cross6f4f3ab2014-02-05 17:42:44 -0800449bool BpBinder::onIncStrongAttempted(uint32_t /*flags*/, const void* /*id*/)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800450{
Steve Block6807e592011-10-20 11:56:00 +0100451 ALOGV("onIncStrongAttempted BpBinder %p handle %d\n", this, mHandle);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800452 IPCThreadState* ipc = IPCThreadState::self();
453 return ipc ? ipc->attemptIncStrongHandle(mHandle) == NO_ERROR : false;
454}
455
Michael Wachenschwanzd296d0c2017-08-15 00:57:14 -0700456uint32_t BpBinder::getBinderProxyCount(uint32_t uid)
457{
458 AutoMutex _l(sTrackingLock);
459 auto it = sTrackingMap.find(uid);
460 if (it != sTrackingMap.end()) {
461 return it->second & COUNTING_VALUE_MASK;
462 }
463 return 0;
464}
465
466void BpBinder::getCountByUid(Vector<uint32_t>& uids, Vector<uint32_t>& counts)
467{
468 AutoMutex _l(sTrackingLock);
469 uids.setCapacity(sTrackingMap.size());
470 counts.setCapacity(sTrackingMap.size());
471 for (const auto& it : sTrackingMap) {
472 uids.push_back(it.first);
473 counts.push_back(it.second & COUNTING_VALUE_MASK);
474 }
475}
476
477void BpBinder::enableCountByUid() { sCountByUidEnabled.store(true); }
478void BpBinder::disableCountByUid() { sCountByUidEnabled.store(false); }
479void BpBinder::setCountByUidEnabled(bool enable) { sCountByUidEnabled.store(enable); }
480
481void BpBinder::setLimitCallback(binder_proxy_limit_callback cb) {
482 AutoMutex _l(sTrackingLock);
483 sLimitCallback = cb;
484}
485
486void BpBinder::setBinderProxyCountWatermarks(int high, int low) {
487 AutoMutex _l(sTrackingLock);
488 sBinderProxyCountHighWatermark = high;
489 sBinderProxyCountLowWatermark = low;
490}
491
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800492// ---------------------------------------------------------------------------
493
Steven Moreland61ff8492019-09-26 16:05:45 -0700494} // namespace android