Add a.f.displayservice to manifest.xml.
am: 1ebb5233cf

Change-Id: I20a80aea1fbf0669db75750f12d60e15cc6a4c32
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..9b3f9d9
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,24 @@
+#
+# Copyright (C) 2017 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+BasedOnStyle: Google
+CommentPragmas: NOLINT:.*
+DerivePointerAlignment: false
+AllowShortFunctionsOnASingleLine: Inline
+ColumnLimit: 100
+TabWidth: 4
+UseTab: Never
+IndentWidth: 4
diff --git a/PREUPLOAD.cfg b/PREUPLOAD.cfg
new file mode 100644
index 0000000..213c93a
--- /dev/null
+++ b/PREUPLOAD.cfg
@@ -0,0 +1,5 @@
+[Options]
+ignore_merged_commits = true
+
+[Builtin Hooks]
+clang_format = true
diff --git a/base/Android.bp b/base/Android.bp
index 5ba464a..e4cf6cb 100644
--- a/base/Android.bp
+++ b/base/Android.bp
@@ -23,7 +23,6 @@
         "libutils",
     ],
     export_shared_lib_headers: [
-        "libbase",
         "libutils",
         "libcutils", // for native_handle.h
     ],
diff --git a/base/HidlSupport.cpp b/base/HidlSupport.cpp
index 8223599..4de7f7c 100644
--- a/base/HidlSupport.cpp
+++ b/base/HidlSupport.cpp
@@ -70,7 +70,7 @@
     if (other.mHandle != nullptr) {
         mHandle = native_handle_clone(other.mHandle);
         if (mHandle == nullptr) {
-            LOG(FATAL) << "Failed to clone native_handle in hidl_handle.";
+            PLOG(FATAL) << "Failed to clone native_handle in hidl_handle";
         }
         mOwnsHandle = true;
     } else {
@@ -218,7 +218,7 @@
     // assume my resources are freed.
 
     if (size > UINT32_MAX) {
-        LOG(FATAL) << "string size can't exceed 2^32 bytes.";
+        LOG(FATAL) << "string size can't exceed 2^32 bytes: " << size;
     }
     char *buf = (char *)malloc(size + 1);
     memcpy(buf, data, size);
@@ -252,7 +252,7 @@
 
 void hidl_string::setToExternal(const char *data, size_t size) {
     if (size > UINT32_MAX) {
-        LOG(FATAL) << "string size can't exceed 2^32 bytes.";
+        LOG(FATAL) << "string size can't exceed 2^32 bytes: " << size;
     }
     clear();
 
diff --git a/base/TaskRunner.cpp b/base/TaskRunner.cpp
index 33117e7..782b40b 100644
--- a/base/TaskRunner.cpp
+++ b/base/TaskRunner.cpp
@@ -43,6 +43,10 @@
     }
 }
 
+bool TaskRunner::push(const Task &t) {
+    return (mQueue != nullptr) && (!!t) && this->mQueue->push(t);
+}
+
 } // namespace details
 } // namespace hardware
 } // namespace android
diff --git a/base/include/hidl/MQDescriptor.h b/base/include/hidl/MQDescriptor.h
index abab212..23be971 100644
--- a/base/include/hidl/MQDescriptor.h
+++ b/base/include/hidl/MQDescriptor.h
@@ -17,7 +17,8 @@
 #ifndef _FMSGQ_DESCRIPTOR_H
 #define _FMSGQ_DESCRIPTOR_H
 
-#include <android-base/macros.h>
+#include <unistd.h>
+
 #include <cutils/native_handle.h>
 #include <hidl/HidlInternal.h>
 #include <hidl/HidlSupport.h>
diff --git a/base/include/hidl/Status.h b/base/include/hidl/Status.h
index a04cf77..7c716c7 100644
--- a/base/include/hidl/Status.h
+++ b/base/include/hidl/Status.h
@@ -20,7 +20,6 @@
 #include <cstdint>
 #include <sstream>
 
-#include <android-base/macros.h>
 #include <hidl/HidlInternal.h>
 #include <utils/Errors.h>
 #include <utils/StrongPointer.h>
@@ -195,6 +194,9 @@
         return mVal;
     }
 
+    T withDefault(T t) {
+        return isOk() ? mVal : t;
+    }
 };
 
 template<typename T> class Return<sp<T>> : public details::return_status {
@@ -220,6 +222,10 @@
         assertOk();
         return mVal;
     }
+
+    sp<T> withDefault(sp<T> t) {
+        return isOk() ? mVal : t;
+    }
 };
 
 
diff --git a/base/include/hidl/TaskRunner.h b/base/include/hidl/TaskRunner.h
index 8ecceca..28ea01c 100644
--- a/base/include/hidl/TaskRunner.h
+++ b/base/include/hidl/TaskRunner.h
@@ -52,9 +52,7 @@
      * Add a task. Return true if successful, false if
      * the queue's size exceeds limit or t doesn't contain a callable target.
      */
-    inline bool push(const Task &t) {
-        return (mQueue != nullptr) && (!!t) && this->mQueue->push(t);
-    }
+    bool push(const Task &t);
 
 private:
     std::shared_ptr<SynchronizedQueue<Task>> mQueue;
diff --git a/test_main.cpp b/test_main.cpp
index 4be2eb9..bce9294 100644
--- a/test_main.cpp
+++ b/test_main.cpp
@@ -363,6 +363,29 @@
     ret.isOk();
 }
 
+TEST_F(LibHidlTest, ReturnTest) {
+    using ::android::DEAD_OBJECT;
+    using ::android::hardware::Return;
+    using ::android::hardware::Status;
+    using ::android::hardware::hidl_string;
+
+    EXPECT_FALSE(Return<void>(Status::fromStatusT(DEAD_OBJECT)).isOk());
+    EXPECT_TRUE(Return<void>(Status::ok()).isOk());
+
+    hidl_string one = "1";
+    hidl_string two = "2";
+    Return<hidl_string> ret = Return<hidl_string>(Status::fromStatusT(DEAD_OBJECT));
+
+    EXPECT_EQ(one, Return<hidl_string>(one).withDefault(two));
+    EXPECT_EQ(two, ret.withDefault(two));
+
+    hidl_string&& moved = ret.withDefault(std::move(two));
+    EXPECT_EQ("2", moved);
+
+    const hidl_string three = "3";
+    EXPECT_EQ(three, ret.withDefault(three));
+}
+
 std::string toString(const ::android::hardware::Status &s) {
     using ::android::hardware::operator<<;
     std::ostringstream oss;
diff --git a/transport/Android.bp b/transport/Android.bp
index 47a4de3..4e424be 100644
--- a/transport/Android.bp
+++ b/transport/Android.bp
@@ -59,6 +59,7 @@
     srcs: [
         "HidlBinderSupport.cpp",
         "HidlTransportSupport.cpp",
+        "HidlTransportUtils.cpp",
         "ServiceManagement.cpp",
         "Static.cpp"
     ],
diff --git a/transport/HidlBinderSupport.cpp b/transport/HidlBinderSupport.cpp
index f421953..d293542 100644
--- a/transport/HidlBinderSupport.cpp
+++ b/transport/HidlBinderSupport.cpp
@@ -28,6 +28,22 @@
 namespace android {
 namespace hardware {
 
+hidl_binder_death_recipient::hidl_binder_death_recipient(const sp<hidl_death_recipient> &recipient,
+        uint64_t cookie, const sp<::android::hidl::base::V1_0::IBase> &base) :
+    mRecipient(recipient), mCookie(cookie), mBase(base) {
+}
+
+void hidl_binder_death_recipient::binderDied(const wp<IBinder>& /*who*/) {
+    sp<hidl_death_recipient> recipient = mRecipient.promote();
+    if (recipient != nullptr) {
+        recipient->serviceDied(mCookie, mBase);
+    }
+}
+
+wp<hidl_death_recipient> hidl_binder_death_recipient::getRecipient() {
+    return mRecipient;
+}
+
 const size_t hidl_memory::kOffsetOfHandle = offsetof(hidl_memory, mHandle);
 const size_t hidl_memory::kOffsetOfName = offsetof(hidl_memory, mName);
 static_assert(hidl_memory::kOffsetOfHandle == 0, "wrong offset");
@@ -69,7 +85,6 @@
 
     return _hidl_err;
 }
-// static
 const size_t hidl_string::kOffsetOfBuffer = offsetof(hidl_string, mBuffer);
 static_assert(hidl_string::kOffsetOfBuffer == 0, "wrong offset");
 
diff --git a/transport/HidlTransportUtils.cpp b/transport/HidlTransportUtils.cpp
new file mode 100644
index 0000000..eda9b8a
--- /dev/null
+++ b/transport/HidlTransportUtils.cpp
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <hidl/HidlTransportUtils.h>
+
+namespace android {
+namespace hardware {
+namespace details {
+
+Return<bool> canCastInterface(::android::hidl::base::V1_0::IBase* interface,
+        const char* castTo, bool emitError) {
+    if (interface == nullptr) {
+        return false;
+    }
+
+    bool canCast = false;
+    auto chainRet = interface->interfaceChain([&](const hidl_vec<hidl_string> &types) {
+        for (size_t i = 0; i < types.size(); i++) {
+            if (types[i] == castTo) {
+                canCast = true;
+                break;
+            }
+        }
+    });
+
+    if (!chainRet.isOk()) {
+        // call fails, propagate the error if emitError
+        return emitError
+                ? details::StatusOf<void, bool>(chainRet)
+                : Return<bool>(false);
+    }
+
+    return canCast;
+}
+
+std::string getDescriptor(::android::hidl::base::V1_0::IBase* interface) {
+    std::string myDescriptor{};
+    auto ret = interface->interfaceDescriptor([&](const hidl_string &types) {
+        myDescriptor = types.c_str();
+    });
+    ret.isOk(); // ignored, return empty string if not isOk()
+    return myDescriptor;
+}
+
+}  // namespace details
+}  // namespace hardware
+}  // namespace android
diff --git a/transport/allocator/1.0/Android.bp b/transport/allocator/1.0/Android.bp
index 03e8a56..e6aa698 100644
--- a/transport/allocator/1.0/Android.bp
+++ b/transport/allocator/1.0/Android.bp
@@ -48,13 +48,11 @@
         "liblog",
         "libutils",
         "libcutils",
-        "android.hidl.base@1.0",
     ],
     export_shared_lib_headers: [
         "libhidlbase",
         "libhidltransport",
         "libhwbinder",
         "libutils",
-        "android.hidl.base@1.0",
     ],
 }
diff --git a/transport/allocator/1.0/default/Android.bp b/transport/allocator/1.0/default/Android.bp
index d15d7c2..7d5fd8b 100644
--- a/transport/allocator/1.0/default/Android.bp
+++ b/transport/allocator/1.0/default/Android.bp
@@ -23,7 +23,6 @@
     init_rc: ["android.hidl.allocator@1.0-service.rc"],
 
     shared_libs: [
-        "android.hidl.base@1.0",
         "android.hidl.allocator@1.0",
         "libhidlbase",
         "libhidltransport",
diff --git a/transport/base/1.0/Android.bp b/transport/base/1.0/Android.bp
index a137f78..8382824 100644
--- a/transport/base/1.0/Android.bp
+++ b/transport/base/1.0/Android.bp
@@ -39,24 +39,4 @@
     ],
 }
 
-cc_library_shared {
-    name: "android.hidl.base@1.0",
-    generated_sources: ["android.hidl.base@1.0_genc++"],
-    generated_headers: ["android.hidl.base@1.0_genc++_headers"],
-    export_generated_headers: ["android.hidl.base@1.0_genc++_headers"],
-    vendor_available: true,
-    shared_libs: [
-        "libhidlbase",
-        "libhidltransport",
-        "libhwbinder",
-        "liblog",
-        "libutils",
-        "libcutils",
-    ],
-    export_shared_lib_headers: [
-        "libhidlbase",
-        "libhidltransport",
-        "libhwbinder",
-        "libutils",
-    ],
-}
+// android.hidl.base@1.0 is exported from libhidltransport
diff --git a/transport/include/hidl/HidlBinderSupport.h b/transport/include/hidl/HidlBinderSupport.h
index a82f977..6f82dbc 100644
--- a/transport/include/hidl/HidlBinderSupport.h
+++ b/transport/include/hidl/HidlBinderSupport.h
@@ -40,18 +40,9 @@
 // DeathRecipient interface.
 struct hidl_binder_death_recipient : IBinder::DeathRecipient {
     hidl_binder_death_recipient(const sp<hidl_death_recipient> &recipient,
-            uint64_t cookie, const sp<::android::hidl::base::V1_0::IBase> &base) :
-        mRecipient(recipient), mCookie(cookie), mBase(base) {
-    }
-    virtual void binderDied(const wp<IBinder>& /*who*/) {
-        sp<hidl_death_recipient> recipient = mRecipient.promote();
-        if (recipient != nullptr) {
-            recipient->serviceDied(mCookie, mBase);
-        }
-    }
-    wp<hidl_death_recipient> getRecipient() {
-        return mRecipient;
-    }
+            uint64_t cookie, const sp<::android::hidl::base::V1_0::IBase> &base);
+    virtual void binderDied(const wp<IBinder>& /*who*/);
+    wp<hidl_death_recipient> getRecipient();
 private:
     wp<hidl_death_recipient> mRecipient;
     uint64_t mCookie;
diff --git a/transport/include/hidl/HidlTransportUtils.h b/transport/include/hidl/HidlTransportUtils.h
index fbd6516..5afb9a6 100644
--- a/transport/include/hidl/HidlTransportUtils.h
+++ b/transport/include/hidl/HidlTransportUtils.h
@@ -28,40 +28,10 @@
  * @param emitError if emitError is false, return Return<bool>{false} on error; if emitError
  * is true, the Return<bool> object contains the actual error.
  */
-inline Return<bool> canCastInterface(::android::hidl::base::V1_0::IBase* interface,
-        const char* castTo, bool emitError = false) {
-    if (interface == nullptr) {
-        return false;
-    }
+Return<bool> canCastInterface(::android::hidl::base::V1_0::IBase* interface,
+        const char* castTo, bool emitError = false);
 
-    bool canCast = false;
-    auto chainRet = interface->interfaceChain([&](const hidl_vec<hidl_string> &types) {
-        for (size_t i = 0; i < types.size(); i++) {
-            if (types[i] == castTo) {
-                canCast = true;
-                break;
-            }
-        }
-    });
-
-    if (!chainRet.isOk()) {
-        // call fails, propagate the error if emitError
-        return emitError
-                ? details::StatusOf<void, bool>(chainRet)
-                : Return<bool>(false);
-    }
-
-    return canCast;
-}
-
-inline std::string getDescriptor(::android::hidl::base::V1_0::IBase* interface) {
-    std::string myDescriptor{};
-    auto ret = interface->interfaceDescriptor([&](const hidl_string &types) {
-        myDescriptor = types.c_str();
-    });
-    ret.isOk(); // ignored, return empty string if not isOk()
-    return myDescriptor;
-}
+std::string getDescriptor(::android::hidl::base::V1_0::IBase* interface);
 
 }   // namespace details
 }   // namespace hardware
diff --git a/transport/manager/1.0/Android.bp b/transport/manager/1.0/Android.bp
index bb712e1..8bdbfa5 100644
--- a/transport/manager/1.0/Android.bp
+++ b/transport/manager/1.0/Android.bp
@@ -42,26 +42,4 @@
     ],
 }
 
-cc_library_shared {
-    name: "android.hidl.manager@1.0",
-    generated_sources: ["android.hidl.manager@1.0_genc++"],
-    generated_headers: ["android.hidl.manager@1.0_genc++_headers"],
-    export_generated_headers: ["android.hidl.manager@1.0_genc++_headers"],
-    vendor_available: true,
-    shared_libs: [
-        "libhidlbase",
-        "libhidltransport",
-        "libhwbinder",
-        "liblog",
-        "libutils",
-        "libcutils",
-        "android.hidl.base@1.0",
-    ],
-    export_shared_lib_headers: [
-        "libhidlbase",
-        "libhidltransport",
-        "libhwbinder",
-        "libutils",
-        "android.hidl.base@1.0",
-    ],
-}
+// android.hidl.manager@1.0 is exported from libhidltransport
diff --git a/transport/memory/1.0/Android.bp b/transport/memory/1.0/Android.bp
index 615c083..01a80ed 100644
--- a/transport/memory/1.0/Android.bp
+++ b/transport/memory/1.0/Android.bp
@@ -55,13 +55,11 @@
         "liblog",
         "libutils",
         "libcutils",
-        "android.hidl.base@1.0",
     ],
     export_shared_lib_headers: [
         "libhidlbase",
         "libhidltransport",
         "libhwbinder",
         "libutils",
-        "android.hidl.base@1.0",
     ],
 }
diff --git a/transport/memory/1.0/default/Android.bp b/transport/memory/1.0/default/Android.bp
index 3b1b7da..b0c601a 100644
--- a/transport/memory/1.0/default/Android.bp
+++ b/transport/memory/1.0/default/Android.bp
@@ -32,7 +32,6 @@
         "libutils",
         "libhidlbase",
         "libhidltransport",
-        "android.hidl.base@1.0",
         "android.hidl.memory@1.0",
     ],
 }
diff --git a/transport/token/1.0/Android.bp b/transport/token/1.0/Android.bp
index 2fccbb6..4f7e6f4 100644
--- a/transport/token/1.0/Android.bp
+++ b/transport/token/1.0/Android.bp
@@ -48,13 +48,11 @@
         "liblog",
         "libutils",
         "libcutils",
-        "android.hidl.base@1.0",
     ],
     export_shared_lib_headers: [
         "libhidlbase",
         "libhidltransport",
         "libhwbinder",
         "libutils",
-        "android.hidl.base@1.0",
     ],
 }
diff --git a/update-makefiles.sh b/update-makefiles.sh
index 7f43031..e82d24c 100755
--- a/update-makefiles.sh
+++ b/update-makefiles.sh
@@ -1,11 +1,5 @@
 #!/bin/bash
 
-# TODO(b/33276472)
-if [ ! -d system/libhidl/transport ] ; then
-  echo "Where is system/libhidl/transport?";
-  exit 1;
-fi
-
 packages=(
     android.hidl.allocator@1.0
     android.hidl.base@1.0