libbinder: add IBinder::withLock

BpBinder (and BBinder, once its mExtra allocation is made) have very
nice and shiny locks which they keep all for themselves! Stop it,
IBinder! Share that lock!

This provides convenient access to IBinder's lock, in order to avoid
needing additional locks elsewhere.

Bug: 192023359
Test: N/A
Change-Id: Id3485a2ac66d19379dcad2f0b41d6cb7a8a96725
diff --git a/libs/binder/BpBinder.cpp b/libs/binder/BpBinder.cpp
index 1f67825..3099296 100644
--- a/libs/binder/BpBinder.cpp
+++ b/libs/binder/BpBinder.cpp
@@ -427,6 +427,11 @@
     return mObjects.detach(objectID);
 }
 
+void BpBinder::withLock(const std::function<void()>& doWithLock) {
+    AutoMutex _l(mLock);
+    doWithLock();
+}
+
 BpBinder* BpBinder::remoteBinder()
 {
     return this;