split android.hidl.memory

Split android.hidl.memory into android.hidl.memory and
android.hidl.allocator. This must be done because IAllocator is served
over hwbinder transport and IMapper/IMemory are always going to be
passthrough hals.

Test: hidl_test, device boots with allocator
Bug: 35327976
Change-Id: Ib135b5e101fadadbbf16126a98f90181f76a253b
diff --git a/CleanSpec.mk b/CleanSpec.mk
new file mode 100644
index 0000000..7d4e281
--- /dev/null
+++ b/CleanSpec.mk
@@ -0,0 +1,48 @@
+# Copyright 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.
+#
+
+# If you don't need to do a full clean build but would like to touch
+# a file or delete some intermediate files, add a clean step to the end
+# of the list.  These steps will only be run once, if they haven't been
+# run before.
+#
+# E.g.:
+#     $(call add-clean-step, touch -c external/sqlite/sqlite3.h)
+#     $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libz_intermediates)
+#
+# Always use "touch -c" and "rm -f" or "rm -rf" to gracefully deal with
+# files that are missing or have been moved.
+#
+# Use $(PRODUCT_OUT) to get to the "out/target/product/blah/" directory.
+# Use $(OUT_DIR) to refer to the "out" directory.
+#
+# If you need to re-do something that's already mentioned, just copy
+# the command and add it to the bottom of the list.  E.g., if a change
+# that you made last week required touching a file and a change you
+# made today requires touching the same file, just copy the old
+# touch step and add it to the end of the list.
+#
+# ************************************************
+# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
+# ************************************************
+
+# For example:
+#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/AndroidTests_intermediates)
+#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/core_intermediates)
+#$(call add-clean-step, find $(OUT_DIR) -type f -name "IGTalkSession*" -print0 | xargs -0 rm -f)
+#$(call add-clean-step, rm -rf $(PRODUCT_OUT)/data/*)
+
+$(call add-clean-step, rm -f $(PRODUCT_OUT)/system/bin/hw/android.hidl.memory@1.0-service)
+$(call add-clean-step, rm -f $(PRODUCT_OUT)/system/etc/init/android.hidl.memory@1.0-service.rc)
diff --git a/base/HidlSupport.cpp b/base/HidlSupport.cpp
index b359f1d..595a928 100644
--- a/base/HidlSupport.cpp
+++ b/base/HidlSupport.cpp
@@ -28,10 +28,10 @@
 namespace android {
 namespace hardware {
 vintf::Transport getTransportForFrameworkPackages(const std::string &name) {
-    // TODO(b/34772739): check with VNDK team to see if this should be in an XML.
+    // TODO(b/34772739): move to framework vintf
     const static std::unordered_map<std::string, vintf::Transport> sTransports {
         {"android.hidl.manager@1.0::IServiceManager", vintf::Transport::HWBINDER},
-        {"android.hidl.memory@1.0::IAllocator"      , vintf::Transport::HWBINDER},
+        {"android.hidl.allocator@1.0::IAllocator"   , vintf::Transport::HWBINDER},
         {"android.hidl.memory@1.0::IMapper"         , vintf::Transport::PASSTHROUGH},
         {"android.hidl.memory@1.0::IMemory"         , vintf::Transport::PASSTHROUGH},
     };
diff --git a/transport/Android.bp b/transport/Android.bp
index 9dc54b4..0c32653 100644
--- a/transport/Android.bp
+++ b/transport/Android.bp
@@ -13,6 +13,8 @@
 // limitations under the License.
 
 subdirs = [
+    "allocator/1.0",
+    "allocator/1.0/default",
     "base/1.0",
     "manager/1.0",
     "memory/1.0",
diff --git a/transport/allocator/1.0/Android.bp b/transport/allocator/1.0/Android.bp
new file mode 100644
index 0000000..b610db4
--- /dev/null
+++ b/transport/allocator/1.0/Android.bp
@@ -0,0 +1,59 @@
+// This file is autogenerated by hidl-gen. Do not edit manually.
+
+filegroup {
+    name: "android.hidl.allocator@1.0_hal",
+    srcs: [
+        "IAllocator.hal",
+    ],
+}
+
+genrule {
+    name: "android.hidl.allocator@1.0_genc++",
+    tools: ["hidl-gen"],
+    cmd: "$(location hidl-gen) -o $(genDir) -Lc++ -randroid.hidl:system/libhidl/transport android.hidl.allocator@1.0",
+    srcs: [
+        ":android.hidl.allocator@1.0_hal",
+    ],
+    out: [
+        "android/hidl/allocator/1.0/AllocatorAll.cpp",
+    ],
+}
+
+genrule {
+    name: "android.hidl.allocator@1.0_genc++_headers",
+    tools: ["hidl-gen"],
+    cmd: "$(location hidl-gen) -o $(genDir) -Lc++ -randroid.hidl:system/libhidl/transport android.hidl.allocator@1.0",
+    srcs: [
+        ":android.hidl.allocator@1.0_hal",
+    ],
+    out: [
+        "android/hidl/allocator/1.0/IAllocator.h",
+        "android/hidl/allocator/1.0/IHwAllocator.h",
+        "android/hidl/allocator/1.0/BnHwAllocator.h",
+        "android/hidl/allocator/1.0/BpHwAllocator.h",
+        "android/hidl/allocator/1.0/BsAllocator.h",
+    ],
+}
+
+cc_library_shared {
+    name: "android.hidl.allocator@1.0",
+    generated_sources: ["android.hidl.allocator@1.0_genc++"],
+    generated_headers: ["android.hidl.allocator@1.0_genc++_headers"],
+    export_generated_headers: ["android.hidl.allocator@1.0_genc++_headers"],
+    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",
+    ],
+}
diff --git a/transport/memory/1.0/IAllocator.hal b/transport/allocator/1.0/IAllocator.hal
similarity index 96%
rename from transport/memory/1.0/IAllocator.hal
rename to transport/allocator/1.0/IAllocator.hal
index 7f540aa..814c69d 100644
--- a/transport/memory/1.0/IAllocator.hal
+++ b/transport/allocator/1.0/IAllocator.hal
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package android.hidl.memory@1.0;
+package android.hidl.allocator@1.0;
 
 /**
  * Interface which allocates the required memory.
diff --git a/transport/allocator/1.0/default/Android.bp b/transport/allocator/1.0/default/Android.bp
new file mode 100644
index 0000000..914fc8d
--- /dev/null
+++ b/transport/allocator/1.0/default/Android.bp
@@ -0,0 +1,35 @@
+// 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.
+
+cc_binary {
+    name: "android.hidl.allocator@1.0-service",
+    relative_install_path: "hw",
+    srcs: [
+        "AshmemAllocator.cpp",
+        "service.cpp"
+    ],
+    init_rc: ["android.hidl.allocator@1.0-service.rc"],
+
+    shared_libs: [
+        "android.hidl.base@1.0",
+        "android.hidl.allocator@1.0",
+        "libhidlbase",
+        "libhidltransport",
+        "libhwbinder",
+        "libbase",
+        "liblog",
+        "libutils",
+        "libcutils",
+    ],
+}
diff --git a/transport/memory/1.0/default/AshmemAllocator.cpp b/transport/allocator/1.0/default/AshmemAllocator.cpp
similarity index 91%
rename from transport/memory/1.0/default/AshmemAllocator.cpp
rename to transport/allocator/1.0/default/AshmemAllocator.cpp
index 667c46e..ce6dbf7 100644
--- a/transport/memory/1.0/default/AshmemAllocator.cpp
+++ b/transport/allocator/1.0/default/AshmemAllocator.cpp
@@ -20,11 +20,11 @@
 
 namespace android {
 namespace hidl {
-namespace memory {
+namespace allocator {
 namespace V1_0 {
 namespace implementation {
 
-// Methods from ::android::hidl::memory::V1_0::IAllocator follow.
+// Methods from ::android::hidl::allocator::V1_0::IAllocator follow.
 Return<void> AshmemAllocator::allocate(uint64_t size, allocate_cb _hidl_cb) {
     int fd = ashmem_create_region("AshmemAllocator_hidl", size);
     if (fd < 0) {
@@ -44,6 +44,6 @@
 
 }  // namespace implementation
 }  // namespace V1_0
-}  // namespace memory
+}  // namespace allocator
 }  // namespace hidl
 }  // namespace android
diff --git a/transport/memory/1.0/default/AshmemAllocator.h b/transport/allocator/1.0/default/AshmemAllocator.h
similarity index 75%
rename from transport/memory/1.0/default/AshmemAllocator.h
rename to transport/allocator/1.0/default/AshmemAllocator.h
index 35ad420..307cb5a 100644
--- a/transport/memory/1.0/default/AshmemAllocator.h
+++ b/transport/allocator/1.0/default/AshmemAllocator.h
@@ -14,20 +14,20 @@
  * limitations under the License.
  */
 
-#ifndef ANDROID_HIDL_ASHMEM_MEMORY_V1_0_ALLOCATOR_H
-#define ANDROID_HIDL_ASHMEM_MEMORY_V1_0_ALLOCATOR_H
+#ifndef ANDROID_HIDL_ASHMEM_ALLOCATOR_V1_0_ALLOCATOR_H
+#define ANDROID_HIDL_ASHMEM_ALLOCATOR_V1_0_ALLOCATOR_H
 
-#include <android/hidl/memory/1.0/IAllocator.h>
+#include <android/hidl/allocator/1.0/IAllocator.h>
 #include <hidl/MQDescriptor.h>
 #include <hidl/Status.h>
 
 namespace android {
 namespace hidl {
-namespace memory {
+namespace allocator {
 namespace V1_0 {
 namespace implementation {
 
-using ::android::hidl::memory::V1_0::IAllocator;
+using ::android::hidl::allocator::V1_0::IAllocator;
 using ::android::hardware::hidl_array;
 using ::android::hardware::hidl_memory;
 using ::android::hardware::hidl_string;
@@ -37,15 +37,15 @@
 using ::android::sp;
 
 struct AshmemAllocator : public IAllocator {
-    // Methods from ::android::hidl::memory::V1_0::IAllocator follow.
+    // Methods from ::android::hidl::allocator::V1_0::IAllocator follow.
     Return<void> allocate(uint64_t size, allocate_cb _hidl_cb) override;
 
 };
 
 }  // namespace implementation
 }  // namespace V1_0
-}  // namespace memory
+}  // namespace allocator
 }  // namespace hidl
 }  // namespace android
 
-#endif  // ANDROID_HIDL_ASHMEM_MEMORY_V1_0_ALLOCATOR_H
+#endif  // ANDROID_HIDL_ASHMEM_ALLOCATOR_V1_0_ALLOCATOR_H
diff --git a/transport/allocator/1.0/default/android.hidl.allocator@1.0-service.rc b/transport/allocator/1.0/default/android.hidl.allocator@1.0-service.rc
new file mode 100644
index 0000000..4f05523
--- /dev/null
+++ b/transport/allocator/1.0/default/android.hidl.allocator@1.0-service.rc
@@ -0,0 +1,4 @@
+service hidl_memory /system/bin/hw/android.hidl.allocator@1.0-service
+    class hal
+    user system
+    group system
diff --git a/transport/memory/1.0/default/service.cpp b/transport/allocator/1.0/default/service.cpp
similarity index 72%
rename from transport/memory/1.0/default/service.cpp
rename to transport/allocator/1.0/default/service.cpp
index 0302e51..63babd3 100644
--- a/transport/memory/1.0/default/service.cpp
+++ b/transport/allocator/1.0/default/service.cpp
@@ -1,15 +1,15 @@
-#define LOG_TAG "android.hidl.memory@1.0-service"
+#define LOG_TAG "android.hidl.allocator@1.0-service"
 
 #include "AshmemAllocator.h"
 
 #include <android-base/logging.h>
-#include <android/hidl/memory/1.0/IAllocator.h>
+#include <android/hidl/allocator/1.0/IAllocator.h>
 #include <hidl/HidlTransportSupport.h>
 
 using android::hardware::configureRpcThreadpool;
 using android::hardware::joinRpcThreadpool;
-using android::hidl::memory::V1_0::IAllocator;
-using android::hidl::memory::V1_0::implementation::AshmemAllocator;
+using android::hidl::allocator::V1_0::IAllocator;
+using android::hidl::allocator::V1_0::implementation::AshmemAllocator;
 using android::sp;
 using android::status_t;
 
diff --git a/transport/base/1.0/Android.bp b/transport/base/1.0/Android.bp
index eb6b88f..c595bb2 100644
--- a/transport/base/1.0/Android.bp
+++ b/transport/base/1.0/Android.bp
@@ -13,8 +13,7 @@
     tools: ["hidl-gen"],
     cmd: "$(location hidl-gen) -o $(genDir) -Lc++ -randroid.hidl:system/libhidl/transport android.hidl.base@1.0",
     srcs: [
-        "types.hal",
-        "IBase.hal",
+        ":android.hidl.base@1.0_hal",
     ],
     out: [
         "android/hidl/base/1.0/types.cpp",
@@ -27,8 +26,7 @@
     tools: ["hidl-gen"],
     cmd: "$(location hidl-gen) -o $(genDir) -Lc++ -randroid.hidl:system/libhidl/transport android.hidl.base@1.0",
     srcs: [
-        "types.hal",
-        "IBase.hal",
+        ":android.hidl.base@1.0_hal",
     ],
     out: [
         "android/hidl/base/1.0/types.h",
diff --git a/transport/manager/1.0/Android.bp b/transport/manager/1.0/Android.bp
index 499b560..0e5766f 100644
--- a/transport/manager/1.0/Android.bp
+++ b/transport/manager/1.0/Android.bp
@@ -13,8 +13,7 @@
     tools: ["hidl-gen"],
     cmd: "$(location hidl-gen) -o $(genDir) -Lc++ -randroid.hidl:system/libhidl/transport android.hidl.manager@1.0",
     srcs: [
-        "IServiceManager.hal",
-        "IServiceNotification.hal",
+        ":android.hidl.manager@1.0_hal",
     ],
     out: [
         "android/hidl/manager/1.0/ServiceManagerAll.cpp",
@@ -27,8 +26,7 @@
     tools: ["hidl-gen"],
     cmd: "$(location hidl-gen) -o $(genDir) -Lc++ -randroid.hidl:system/libhidl/transport android.hidl.manager@1.0",
     srcs: [
-        "IServiceManager.hal",
-        "IServiceNotification.hal",
+        ":android.hidl.manager@1.0_hal",
     ],
     out: [
         "android/hidl/manager/1.0/IServiceManager.h",
diff --git a/transport/memory/1.0/Android.bp b/transport/memory/1.0/Android.bp
index 0a7b88f..4ec0191 100644
--- a/transport/memory/1.0/Android.bp
+++ b/transport/memory/1.0/Android.bp
@@ -3,7 +3,6 @@
 filegroup {
     name: "android.hidl.memory@1.0_hal",
     srcs: [
-        "IAllocator.hal",
         "IMapper.hal",
         "IMemory.hal",
     ],
@@ -14,12 +13,9 @@
     tools: ["hidl-gen"],
     cmd: "$(location hidl-gen) -o $(genDir) -Lc++ -randroid.hidl:system/libhidl/transport android.hidl.memory@1.0",
     srcs: [
-        "IAllocator.hal",
-        "IMapper.hal",
-        "IMemory.hal",
+        ":android.hidl.memory@1.0_hal",
     ],
     out: [
-        "android/hidl/memory/1.0/AllocatorAll.cpp",
         "android/hidl/memory/1.0/MapperAll.cpp",
         "android/hidl/memory/1.0/MemoryAll.cpp",
     ],
@@ -30,16 +26,9 @@
     tools: ["hidl-gen"],
     cmd: "$(location hidl-gen) -o $(genDir) -Lc++ -randroid.hidl:system/libhidl/transport android.hidl.memory@1.0",
     srcs: [
-        "IAllocator.hal",
-        "IMapper.hal",
-        "IMemory.hal",
+        ":android.hidl.memory@1.0_hal",
     ],
     out: [
-        "android/hidl/memory/1.0/IAllocator.h",
-        "android/hidl/memory/1.0/IHwAllocator.h",
-        "android/hidl/memory/1.0/BnHwAllocator.h",
-        "android/hidl/memory/1.0/BpHwAllocator.h",
-        "android/hidl/memory/1.0/BsAllocator.h",
         "android/hidl/memory/1.0/IMapper.h",
         "android/hidl/memory/1.0/IHwMapper.h",
         "android/hidl/memory/1.0/BnHwMapper.h",
diff --git a/transport/memory/1.0/default/Android.bp b/transport/memory/1.0/default/Android.bp
index 62fb556..e3a05c3 100644
--- a/transport/memory/1.0/default/Android.bp
+++ b/transport/memory/1.0/default/Android.bp
@@ -35,25 +35,3 @@
         "android.hidl.memory@1.0",
     ],
 }
-
-cc_binary {
-    name: "android.hidl.memory@1.0-service",
-    relative_install_path: "hw",
-    srcs: [
-        "AshmemAllocator.cpp",
-        "service.cpp"
-    ],
-    init_rc: ["android.hidl.memory@1.0-service.rc"],
-
-    shared_libs: [
-        "android.hidl.base@1.0",
-        "android.hidl.memory@1.0",
-        "libhidlbase",
-        "libhidltransport",
-        "libhwbinder",
-        "libbase",
-        "liblog",
-        "libutils",
-        "libcutils",
-    ],
-}
diff --git a/transport/memory/1.0/default/HidlFetch.cpp b/transport/memory/1.0/default/HidlFetch.cpp
index adb55d3..d47cf97 100644
--- a/transport/memory/1.0/default/HidlFetch.cpp
+++ b/transport/memory/1.0/default/HidlFetch.cpp
@@ -16,7 +16,6 @@
 
 #include "HidlFetch.h"
 
-#include "AshmemAllocator.h"
 #include "AshmemMapper.h"
 
 static std::string kAshmemMemoryName = "ashmem";
diff --git a/transport/memory/1.0/default/HidlFetch.h b/transport/memory/1.0/default/HidlFetch.h
index 389ca30..b220be4 100644
--- a/transport/memory/1.0/default/HidlFetch.h
+++ b/transport/memory/1.0/default/HidlFetch.h
@@ -17,7 +17,6 @@
 #ifndef HIDL_FETCH_H
 #define HIDL_FETCH_H
 
-#include <android/hidl/memory/1.0/IAllocator.h>
 #include <android/hidl/memory/1.0/IMapper.h>
 
 namespace android {
@@ -34,4 +33,4 @@
 }  // namespace hidl
 }  // namespace android
 
-#endif  // HIDL_FETCH_H
\ No newline at end of file
+#endif  // HIDL_FETCH_H
diff --git a/transport/memory/1.0/default/android.hidl.memory@1.0-service.rc b/transport/memory/1.0/default/android.hidl.memory@1.0-service.rc
deleted file mode 100644
index 1caaae9..0000000
--- a/transport/memory/1.0/default/android.hidl.memory@1.0-service.rc
+++ /dev/null
@@ -1,4 +0,0 @@
-service hidl_memory /system/bin/hw/android.hidl.memory@1.0-service
-    class hal
-    user system
-    group system
diff --git a/transport/token/1.0/Android.bp b/transport/token/1.0/Android.bp
index ffa1c18..5f90cb7 100644
--- a/transport/token/1.0/Android.bp
+++ b/transport/token/1.0/Android.bp
@@ -12,7 +12,7 @@
     tools: ["hidl-gen"],
     cmd: "$(location hidl-gen) -o $(genDir) -Lc++ -randroid.hidl:system/libhidl/transport android.hidl.token@1.0",
     srcs: [
-        "ITokenManager.hal",
+        ":android.hidl.token@1.0_hal",
     ],
     out: [
         "android/hidl/token/1.0/TokenManagerAll.cpp",
@@ -24,7 +24,7 @@
     tools: ["hidl-gen"],
     cmd: "$(location hidl-gen) -o $(genDir) -Lc++ -randroid.hidl:system/libhidl/transport android.hidl.token@1.0",
     srcs: [
-        "ITokenManager.hal",
+        ":android.hidl.token@1.0_hal",
     ],
     out: [
         "android/hidl/token/1.0/ITokenManager.h",
diff --git a/update-makefiles.sh b/update-makefiles.sh
index 3cd1cd2..7f43031 100755
--- a/update-makefiles.sh
+++ b/update-makefiles.sh
@@ -7,6 +7,7 @@
 fi
 
 packages=(
+    android.hidl.allocator@1.0
     android.hidl.base@1.0
     android.hidl.manager@1.0
     android.hidl.memory@1.0