Merge "Hal Manifest: remove obsolete TODO."
diff --git a/base/HidlSupport.cpp b/base/HidlSupport.cpp
index 547f7e7..e97797d 100644
--- a/base/HidlSupport.cpp
+++ b/base/HidlSupport.cpp
@@ -30,26 +30,13 @@
 
 vintf::Transport getTransportFromManifest(
         const FQName &fqName, const std::string &instanceName,
-        const std::string &manifestName,
         const vintf::HalManifest *vm) {
     if (vm == nullptr) {
-        LOG(WARNING) << "getTransportFromManifest: No " << manifestName << " manifest defined, "
-                     << "using default transport for " << fqName.string();
         return vintf::Transport::EMPTY;
     }
-    vintf::Transport tr = vm->getTransport(fqName.package(),
+    return vm->getTransport(fqName.package(),
             vintf::Version{fqName.getPackageMajorVersion(), fqName.getPackageMinorVersion()},
             fqName.name(), instanceName);
-    if (tr == vintf::Transport::EMPTY) {
-        LOG(WARNING) << "getTransportFromManifest: Cannot find entry "
-                     << fqName.string()
-                     << " in " << manifestName << " manifest, using default transport.";
-    } else {
-        LOG(DEBUG) << "getTransportFromManifest: " << fqName.string()
-                   << " declares transport method " << to_string(tr)
-                   << " in " << manifestName << " manifest";
-    }
-    return tr;
 }
 
 vintf::Transport getTransport(const std::string &interfaceName, const std::string &instanceName) {
@@ -68,13 +55,22 @@
                    << " does not specify an interface name. Using default transport.";
         return vintf::Transport::EMPTY;
     }
-    // TODO(b/34772739): modify the list if other packages are added to system/manifest.xml
-    if (fqName.inPackage("android.hidl")) {
-        return getTransportFromManifest(fqName, instanceName, "framework",
-                vintf::VintfObject::GetFrameworkHalManifest());
+
+    vintf::Transport tr = getTransportFromManifest(fqName, instanceName,
+            vintf::VintfObject::GetFrameworkHalManifest());
+    if (tr != vintf::Transport::EMPTY) {
+        return tr;
     }
-    return getTransportFromManifest(fqName, instanceName, "device",
+    tr = getTransportFromManifest(fqName, instanceName,
             vintf::VintfObject::GetDeviceHalManifest());
+    if (tr != vintf::Transport::EMPTY) {
+        return tr;
+    }
+
+    LOG(WARNING) << "getTransportFromManifest: Cannot find entry "
+                 << fqName.string()
+                 << " in either framework or device manifest, using default transport.";
+    return vintf::Transport::EMPTY;
 }
 
 namespace details {
diff --git a/base/include/hidl/HidlSupport.h b/base/include/hidl/HidlSupport.h
index 14afce3..f2e1265 100644
--- a/base/include/hidl/HidlSupport.h
+++ b/base/include/hidl/HidlSupport.h
@@ -818,7 +818,7 @@
 
 ///////////////////// toString functions
 
-namespace details {
+std::string toString(const void *t);
 
 // toString alias for numeric types
 template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
@@ -826,6 +826,8 @@
     return std::to_string(t);
 }
 
+namespace details {
+
 template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
 inline std::string toHexString(T t, bool prefix = true) {
     std::ostringstream os;
@@ -844,8 +846,48 @@
     return toHexString(static_cast<int32_t>(t), prefix);
 }
 
-inline std::string toString(const void *t, bool prefix = true) {
-    return toHexString(reinterpret_cast<uintptr_t>(t), prefix);
+template<typename Array>
+std::string arrayToString(const Array &a, size_t size);
+
+template<size_t SIZE1>
+std::string arraySizeToString() {
+    return std::string{"["} + toString(SIZE1) + "]";
+}
+
+template<size_t SIZE1, size_t SIZE2, size_t... SIZES>
+std::string arraySizeToString() {
+    return std::string{"["} + toString(SIZE1) + "]" + arraySizeToString<SIZE2, SIZES...>();
+}
+
+template<typename T, size_t SIZE1>
+std::string toString(details::const_accessor<T, SIZE1> a) {
+    return arrayToString(a, SIZE1);
+}
+
+template<typename Array>
+std::string arrayToString(const Array &a, size_t size) {
+    using android::hardware::toString;
+    std::string os;
+    os += "{";
+    for (size_t i = 0; i < size; ++i) {
+        if (i > 0) {
+            os += ", ";
+        }
+        os += toString(a[i]);
+    }
+    os += "}";
+    return os;
+}
+
+template<typename T, size_t SIZE1, size_t SIZE2, size_t... SIZES>
+std::string toString(details::const_accessor<T, SIZE1, SIZE2, SIZES...> a) {
+    return arrayToString(a, SIZE1);
+}
+
+}  //namespace details
+
+inline std::string toString(const void *t) {
+    return details::toHexString(reinterpret_cast<uintptr_t>(t));
 }
 
 // debug string dump. There will be quotes around the string!
@@ -868,68 +910,27 @@
     return std::string{"death_recipient@"} + toString(dr.get());
 }
 
-template<typename Array>
-std::string arrayToString(const Array &a, size_t size);
-
 // debug string dump, assuming that toString(T) is defined.
 template<typename T>
 std::string toString(const hidl_vec<T> &a) {
     std::string os;
     os += "[" + toString(a.size()) + "]";
-    os += arrayToString(a, a.size());
+    os += details::arrayToString(a, a.size());
     return os;
 }
 
-template<size_t SIZE1>
-std::string arraySizeToString() {
-    return std::string{"["} + toString(SIZE1) + "]";
-}
-
-template<typename T, size_t SIZE1>
-std::string toString(const_accessor<T, SIZE1> a) {
-    return arrayToString(a, SIZE1);
-}
-
 template<typename T, size_t SIZE1>
 std::string toString(const hidl_array<T, SIZE1> &a) {
-    return arraySizeToString<SIZE1>()
-            + toString(const_accessor<T, SIZE1>(a.data()));
-}
-
-template<size_t SIZE1, size_t SIZE2, size_t... SIZES>
-std::string arraySizeToString() {
-    return std::string{"["} + toString(SIZE1) + "]" + arraySizeToString<SIZE2, SIZES...>();
-}
-
-
-template<typename T, size_t SIZE1, size_t SIZE2, size_t... SIZES>
-std::string toString(const_accessor<T, SIZE1, SIZE2, SIZES...> a) {
-    return arrayToString(a, SIZE1);
+    return details::arraySizeToString<SIZE1>()
+            + details::toString(details::const_accessor<T, SIZE1>(a.data()));
 }
 
 template<typename T, size_t SIZE1, size_t SIZE2, size_t... SIZES>
 std::string toString(const hidl_array<T, SIZE1, SIZE2, SIZES...> &a) {
-    return arraySizeToString<SIZE1, SIZE2, SIZES...>()
-            + toString(const_accessor<T, SIZE1, SIZE2, SIZES...>(a.data()));
+    return details::arraySizeToString<SIZE1, SIZE2, SIZES...>()
+            + details::toString(details::const_accessor<T, SIZE1, SIZE2, SIZES...>(a.data()));
 }
 
-template<typename Array>
-std::string arrayToString(const Array &a, size_t size) {
-    std::string os;
-    os += "{";
-    for (size_t i = 0; i < size; ++i) {
-        if (i > 0) {
-            os += ", ";
-        }
-        os += toString(a[i]);
-    }
-    os += "}";
-    return os;
-}
-
-}  // namespace details
-
-
 }  // namespace hardware
 }  // namespace android
 
diff --git a/base/include/hidl/MQDescriptor.h b/base/include/hidl/MQDescriptor.h
index 90b30d1..48e59dd 100644
--- a/base/include/hidl/MQDescriptor.h
+++ b/base/include/hidl/MQDescriptor.h
@@ -246,7 +246,6 @@
 template<typename T, MQFlavor flavor>
 int32_t MQDescriptor<T, flavor>::getFlags() const { return mFlags; }
 
-namespace details {
 template<typename T, MQFlavor flavor>
 std::string toString(const MQDescriptor<T, flavor> &q) {
     std::string os;
@@ -263,7 +262,6 @@
        + ", .quantum = " + toString(q.getQuantum()) + "}";
     return os;
 }
-}  // namespace details
 
 }  // namespace hardware
 }  // namespace android
diff --git a/transport/HidlPassthroughSupport.cpp b/transport/HidlPassthroughSupport.cpp
index 43724f9..981a139 100644
--- a/transport/HidlPassthroughSupport.cpp
+++ b/transport/HidlPassthroughSupport.cpp
@@ -21,6 +21,7 @@
 
 namespace android {
 namespace hardware {
+namespace details {
 
 sp<::android::hidl::base::V1_0::IBase> wrapPassthrough(
         sp<::android::hidl::base::V1_0::IBase> iface) {
@@ -28,7 +29,7 @@
         // doesn't know how to handle it.
         return iface;
     }
-    std::string myDescriptor = details::getDescriptor(iface.get());
+    std::string myDescriptor = getDescriptor(iface.get());
     if (myDescriptor.empty()) {
         // interfaceDescriptor fails
         return nullptr;
@@ -40,6 +41,6 @@
     return func(reinterpret_cast<void *>(iface.get()));
 }
 
-
+}  // namespace details
 }  // namespace hardware
 }  // namespace android
diff --git a/transport/include/hidl/HidlPassthroughSupport.h b/transport/include/hidl/HidlPassthroughSupport.h
index 2b2f86b..0a8f15b 100644
--- a/transport/include/hidl/HidlPassthroughSupport.h
+++ b/transport/include/hidl/HidlPassthroughSupport.h
@@ -21,6 +21,7 @@
 
 namespace android {
 namespace hardware {
+namespace details {
 
 /*
  * Wrap the given interface with the smallest BsChild possible. Will return the
@@ -29,6 +30,7 @@
 sp<::android::hidl::base::V1_0::IBase> wrapPassthrough(
         sp<::android::hidl::base::V1_0::IBase> iface);
 
+}  // namespace details
 }  // namespace hardware
 }  // namespace android
 
diff --git a/transport/include/hidl/HidlTransportSupport.h b/transport/include/hidl/HidlTransportSupport.h
index 8476f47..8a2a70a 100644
--- a/transport/include/hidl/HidlTransportSupport.h
+++ b/transport/include/hidl/HidlTransportSupport.h
@@ -47,6 +47,8 @@
  */
 void joinRpcThreadpool();
 
+namespace details {
+
 // cast the interface IParent to IChild.
 // Return nullptr if parent is null or any failure.
 template<typename IChild, typename IParent, typename BpChild, typename BpParent>
@@ -69,6 +71,8 @@
     return sp<IChild>(static_cast<IChild *>(parent.get()));
 }
 
+}  // namespace details
+
 }  // namespace hardware
 }  // namespace android
 
diff --git a/transport/memory/1.0/IMemory.hal b/transport/memory/1.0/IMemory.hal
index 66f37b3..14dcfb1 100644
--- a/transport/memory/1.0/IMemory.hal
+++ b/transport/memory/1.0/IMemory.hal
@@ -34,7 +34,20 @@
     updateRange(uint64_t start, uint64_t length);
 
     /**
-     * Notify that you are done modifying this memory.
+     * Notify that you are about to start reading all of this memory.
+     */
+    read();
+
+    /**
+     * Notify that you are about to read the specific range.
+     *
+     * @param start Offset from start of buffer about to be read.
+     * @param length Number of bytes to be read.
+     */
+    readRange(uint64_t start, uint64_t length);
+
+    /**
+     * Notify that you are done reading and/or writing this memory.
      *
      * Must commit all previous update's and updateAll's.
      */
diff --git a/transport/memory/1.0/default/AshmemMemory.cpp b/transport/memory/1.0/default/AshmemMemory.cpp
index 912b724..0729608 100644
--- a/transport/memory/1.0/default/AshmemMemory.cpp
+++ b/transport/memory/1.0/default/AshmemMemory.cpp
@@ -46,6 +46,16 @@
     return Void();
 }
 
+Return<void> AshmemMemory::read() {
+    // NOOP (since non-remoted memory)
+    return Void();
+}
+
+Return<void> AshmemMemory::readRange(uint64_t /* start */, uint64_t /* length */) {
+    // NOOP (since non-remoted memory)
+    return Void();
+}
+
 Return<void> AshmemMemory::commit() {
     // NOOP (since non-remoted memory)
     return Void();
diff --git a/transport/memory/1.0/default/AshmemMemory.h b/transport/memory/1.0/default/AshmemMemory.h
index 825d74e..cf2d543 100644
--- a/transport/memory/1.0/default/AshmemMemory.h
+++ b/transport/memory/1.0/default/AshmemMemory.h
@@ -44,6 +44,8 @@
     // Methods from ::android::hidl::memory::V1_0::IMemory follow.
     Return<void> update() override;
     Return<void> updateRange(uint64_t start, uint64_t length) override;
+    Return<void> read() override;
+    Return<void> readRange(uint64_t start, uint64_t length) override;
     Return<void> commit() override;
     Return<void*> getPointer() override;
     Return<uint64_t> getSize() override;