From 08c9891c9c850db7d7fdfcd77d694bcefe836884 Mon Sep 17 00:00:00 2001 From: Alex Vakulenko Date: Mon, 4 Jan 2016 12:22:05 -0800 Subject: libbinderwrapper: Add BinderWrapper::GetOrCreateInstance() In libraries relying on binder it is useful to be able to obtain an existing copy of BinderWrapper or create one if it doesn't exist. This allows to abstract the actual RPC (binder) from clients who have no other dependencies on this RPC. BUG: 23782171 Change-Id: Ie775d3d8ab83d75e38abc7e1385eb39a363555ef --- include/binderwrapper/binder_wrapper.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'include') diff --git a/include/binderwrapper/binder_wrapper.h b/include/binderwrapper/binder_wrapper.h index 921c4ed19..ccda825b3 100644 --- a/include/binderwrapper/binder_wrapper.h +++ b/include/binderwrapper/binder_wrapper.h @@ -30,6 +30,7 @@ class BBinder; class IBinder; // Wraps libbinder to make it testable. +// NOTE: Static methods of this class are not thread-safe. class BinderWrapper { public: virtual ~BinderWrapper() {} @@ -50,6 +51,10 @@ class BinderWrapper { // InitForTesting(). static BinderWrapper* Get(); + // Returns the singleton instance if it was previously created by Create() or + // set by InitForTesting(), or creates a new one by calling Create(). + static BinderWrapper* GetOrCreateInstance(); + // Gets the binder for communicating with the service identified by // |service_name|, returning null immediately if it doesn't exist. virtual sp GetService(const std::string& service_name) = 0; -- cgit v1.2.3