Merge "Use hidl_pointer<native_handle_t>  in MQDescriptor"
diff --git a/base/include/hidl/HidlSupport.h b/base/include/hidl/HidlSupport.h
index 0e66ceb..61a8bea 100644
--- a/base/include/hidl/HidlSupport.h
+++ b/base/include/hidl/HidlSupport.h
@@ -423,7 +423,7 @@
     // copy from an array-like object, assuming my resources are freed.
     template <typename Array>
     void copyFrom(const Array &data, size_t size) {
-        mSize = size;
+        mSize = static_cast<uint32_t>(size);
         mOwnsBuffer = true;
         if (mSize > 0) {
             mBuffer = new T[size];
diff --git a/base/include/hidl/Status.h b/base/include/hidl/Status.h
index 1246ae0..06aa09c 100644
--- a/base/include/hidl/Status.h
+++ b/base/include/hidl/Status.h
@@ -149,21 +149,17 @@
     Return(T v) : mVal{v} {}
     Return(Status s) : mStatus(s) {}
 
-    T get() const {
+    bool isOk() const {
+        return mStatus.isOk();
+    }
+
+    operator T() const {
         if (!mStatus.isOk()) {
             logAlwaysFatal("Attempted to retrieve value from hidl service, "
                            "but there was a transport error.");
         }
         return mVal;
     }
-    bool isOk() const {
-        return mStatus.isOk();
-    }
-
-    // TODO(b/31348667) deprecate, remove all usage, remove function
-    // Can't mark as deprecated yet because of all the projects built with -Werror.
-    // [[deprecated("Replaced by get()")]]
-    operator T() const { return mVal; }
 
     const Status& getStatus() const {
         return mStatus;
diff --git a/transport/HidlBinderSupport.cpp b/transport/HidlBinderSupport.cpp
index f3e99e1..38e0640 100644
--- a/transport/HidlBinderSupport.cpp
+++ b/transport/HidlBinderSupport.cpp
@@ -25,8 +25,6 @@
 namespace android {
 namespace hardware {
 
-std::map<std::string, std::function<sp<IBinder>(void*)>> gBnConstructorMap{};
-
 const size_t hidl_memory::kOffsetOfHandle = offsetof(hidl_memory, mHandle);
 const size_t hidl_memory::kOffsetOfName = offsetof(hidl_memory, mName);
 
diff --git a/transport/Static.cpp b/transport/Static.cpp
index 3bd0285..ddda712 100644
--- a/transport/Static.cpp
+++ b/transport/Static.cpp
@@ -25,5 +25,7 @@
 Mutex gDefaultServiceManagerLock;
 sp<android::hidl::manager::V1_0::IServiceManager> gDefaultServiceManager;
 
+std::map<std::string, std::function<sp<IBinder>(void*)>> gBnConstructorMap{};
+
 }   // namespace hardware
 }   // namespace android
diff --git a/transport/include/hidl/HidlBinderSupport.h b/transport/include/hidl/HidlBinderSupport.h
index fb209c4..a596917 100644
--- a/transport/include/hidl/HidlBinderSupport.h
+++ b/transport/include/hidl/HidlBinderSupport.h
@@ -19,6 +19,7 @@
 
 #include <hidl/HidlSupport.h>
 #include <hidl/MQDescriptor.h>
+#include <hidl/Static.h>
 #include <hwbinder/IBinder.h>
 #include <hwbinder/Parcel.h>
 
@@ -280,8 +281,6 @@
 
 // ---------------------- support for casting interfaces
 
-extern std::map<std::string, std::function<sp<IBinder>(void*)>> gBnConstructorMap;
-
 // Construct a smallest possible binder from the given interface.
 // If it is remote, then its remote() will be retrieved.
 // Otherwise, the smallest possible BnChild is found where IChild is a subclass of IType
@@ -303,7 +302,7 @@
             }
         });
         if (myDescriptor.empty()) {
-            // interfaceChain fails || types.size() == 0
+            // interfaceChain fails
             return nullptr;
         }
         auto iter = gBnConstructorMap.find(myDescriptor);
@@ -372,7 +371,7 @@
                 [&success, &sm, &serviceName, &binderIface](const auto &chain) {         \
                     ::android::hardware::Return<bool> addRet =                           \
                             sm->add(chain, serviceName.c_str(), binderIface);            \
-                    success = addRet.isOk() && addRet.get();                             \
+                    success = addRet.isOk() && addRet;                                   \
                 });                                                                      \
         success = success && ret.getStatus().isOk();                                     \
         return success ? ::android::OK : ::android::UNKNOWN_ERROR;                       \
@@ -393,7 +392,7 @@
                 sm->registerForNotifications(PACKAGE "::I" #INTERFACE,                   \
                                              serviceName,                                \
                                              notification);                              \
-        return success.isOk() && success.get();                                          \
+        return success.isOk() && success;                                                \
     }
 
 
diff --git a/transport/include/hidl/HidlTransportSupport.h b/transport/include/hidl/HidlTransportSupport.h
index f8cae2e..1d22cb7 100644
--- a/transport/include/hidl/HidlTransportSupport.h
+++ b/transport/include/hidl/HidlTransportSupport.h
@@ -17,8 +17,8 @@
 #ifndef ANDROID_HIDL_TRANSPORT_SUPPORT_H
 #define ANDROID_HIDL_TRANSPORT_SUPPORT_H
 
-#include <hidl/HidlSupport.h>
 #include <hidl/HidlBinderSupport.h>
+#include <hidl/HidlSupport.h>
 
 namespace android {
 namespace hardware {
diff --git a/transport/include/hidl/Static.h b/transport/include/hidl/Static.h
index 00db8a7..2a40125 100644
--- a/transport/include/hidl/Static.h
+++ b/transport/include/hidl/Static.h
@@ -17,8 +17,10 @@
 // All static variables go here, to control initialization and
 // destruction order in the library.
 
-#include <utils/threads.h>
+#include <android/hidl/base/1.0/IBase.h>
 #include <android/hidl/manager/1.0/IServiceManager.h>
+#include <hwbinder/IBinder.h>
+#include <utils/threads.h>
 
 namespace android {
 namespace hardware {
@@ -27,5 +29,10 @@
 extern Mutex gDefaultServiceManagerLock;
 extern sp<android::hidl::manager::V1_0::IServiceManager> gDefaultServiceManager;
 
+// For HidlBinderSupport
+// value function receives reinterpret_cast<void *>(static_cast<IFoo *>(foo)),
+// returns sp<IBinder>
+extern std::map<std::string, std::function<sp<IBinder>(void*)>> gBnConstructorMap;
+
 }   // namespace hardware
 }   // namespace android