Refactor headers to create explicit dependency

This makes explicit header dependencies between modules.

- Introduces cc_library_headers rather than indirectly specifying remote
include dirs with cc_defaults hack.
- Eliminates all includes starting with "..".
- Exports include directories correctly for libraries.

Bug: 65377115
Test: mma
Change-Id: I957b7df54b282d6c68443d3c2819b71f4b5fbbf6
diff --git a/apps/Android.bp b/apps/Android.bp
index 9e87adb..4407cf1 100644
--- a/apps/Android.bp
+++ b/apps/Android.bp
@@ -14,14 +14,23 @@
 // limitations under the License.
 //
 
+cc_library_headers {
+    name: "libese-app-headers",
+    host_supported: true,
+    proprietary: true,
+    export_include_dirs: ["include"],
+    visibility: ["//external/libese:__subpackages__"],
+}
+
 cc_defaults {
     name: "libese-app-defaults",
     proprietary: true,
     defaults: ["libese-defaults"],
 
+    header_libs: ["libese-app-headers"],
+    export_header_lib_headers: ["libese-app-headers"],
+
     // Ensure that only explicitly exported symbols are visible.
-    local_include_dirs: ["include"],
-    export_include_dirs: ["include"],
     cflags: ["-fvisibility=internal"],
 }
 
diff --git a/apps/boot/Android.bp b/apps/boot/Android.bp
index 3838966..17a65df 100644
--- a/apps/boot/Android.bp
+++ b/apps/boot/Android.bp
@@ -21,6 +21,7 @@
     cflags: ["-Wall", "-Werror"],
     host_supported: true,
     shared_libs: ["liblog", "libese", "libese-sysdeps"],
+    export_include_dirs: ["include"],
 }
 
 cc_library {
@@ -34,6 +35,7 @@
         "-Werror",
     ],
     shared_libs: ["liblog", "libese", "libese-sysdeps"],
+    export_include_dirs: ["include"],
 }
 
 
diff --git a/apps/boot/include/ese/app/boot.h b/apps/boot/include/ese/app/boot.h
index 09659a3..48714fa 100644
--- a/apps/boot/include/ese/app/boot.h
+++ b/apps/boot/include/ese/app/boot.h
@@ -19,11 +19,11 @@
 #ifndef ESE_APP_BOOT_H_
 #define ESE_APP_BOOT_H_ 1
 
-#include "../../../../../libese/include/ese/ese.h"
-#include "../../../../../libese/include/ese/log.h"
-#include "../../../../../libese-sysdeps/include/ese/sysdeps.h"
+#include <ese/ese.h>
+#include <ese/log.h>
+#include <ese/sysdeps.h>
 
-#include "../../../../include/ese/app/result.h"
+#include <ese/app/result.h>
 
 #ifdef __cplusplus
 extern "C" {
diff --git a/apps/weaver/Android.bp b/apps/weaver/Android.bp
index d4948a9..b3eb42e 100644
--- a/apps/weaver/Android.bp
+++ b/apps/weaver/Android.bp
@@ -24,6 +24,7 @@
         "-Wno-error=unused-variable",
     ],
     shared_libs: ["liblog", "libese", "libese-sysdeps"],
+    export_include_dirs: ["include"],
 }
 
 cc_test {
diff --git a/apps/weaver/include/ese/app/weaver.h b/apps/weaver/include/ese/app/weaver.h
index 7c8adad..40af18a 100644
--- a/apps/weaver/include/ese/app/weaver.h
+++ b/apps/weaver/include/ese/app/weaver.h
@@ -17,11 +17,11 @@
 #ifndef ESE_APP_WEAVER_H_
 #define ESE_APP_WEAVER_H_ 1
 
-#include "../../../../../libese/include/ese/ese.h"
-#include "../../../../../libese/include/ese/log.h"
-#include "../../../../../libese-sysdeps/include/ese/sysdeps.h"
+#include <ese/ese.h>
+#include <ese/log.h>
+#include <ese/sysdeps.h>
 
-#include "../../../../include/ese/app/result.h"
+#include <ese/app/result.h>
 
 #ifdef __cplusplus
 extern "C" {
diff --git a/esed/OemLock.cpp b/esed/OemLock.cpp
index 4a7974d..a59c3cb 100644
--- a/esed/OemLock.cpp
+++ b/esed/OemLock.cpp
@@ -19,7 +19,7 @@
 #include <vector>
 
 #include <android-base/logging.h>
-#include "../apps/boot/include/ese/app/boot.h"
+#include <ese/app/boot.h>
 #include "ScopedEseConnection.h"
 
 namespace android {
diff --git a/esed/Weaver.cpp b/esed/Weaver.cpp
index 1101551..da17fc4 100644
--- a/esed/Weaver.cpp
+++ b/esed/Weaver.cpp
@@ -21,7 +21,7 @@
 
 #include <android-base/logging.h>
 
-#include "../apps/weaver/include/ese/app/weaver.h"
+#include <ese/app/weaver.h>
 #include "ScopedEseConnection.h"
 
 namespace android {
diff --git a/libese-hw/nxp/Android.bp b/libese-hw/nxp/Android.bp
index 0ec4ea6..5dab88f 100644
--- a/libese-hw/nxp/Android.bp
+++ b/libese-hw/nxp/Android.bp
@@ -25,7 +25,6 @@
         "libese-teq1",
         "libese-sysdeps",
     ],
-    local_include_dirs: ["include"],
     export_include_dirs: ["include"],
     cflags: [
         "-Wall",
@@ -65,6 +64,7 @@
     cflags: [
         "-Wno-format",
     ],
+    export_include_dirs: ["include"],
 }
 
 cc_library {
@@ -77,4 +77,5 @@
         "-Wno-error=unused-variable",
         "-Wno-format",
     ],
+    export_include_dirs: ["include"],
 }
diff --git a/libese-hw/nxp/include/ese/hw/nxp/pn80t/common.h b/libese-hw/nxp/include/ese/hw/nxp/pn80t/common.h
index 839983f..99f5114 100644
--- a/libese-hw/nxp/include/ese/hw/nxp/pn80t/common.h
+++ b/libese-hw/nxp/include/ese/hw/nxp/pn80t/common.h
@@ -17,9 +17,9 @@
 #ifndef ESE_HW_NXP_PN80T_COMMON_H_
 #define ESE_HW_NXP_PN80T_COMMON_H_ 1
 
-#include "../../libese-teq1/include/ese/teq1.h"
-#include "../../libese/include/ese/ese.h"
-#include "../../libese/include/ese/log.h"
+#include <ese/teq1.h>
+#include <ese/ese.h>
+#include <ese/log.h>
 #include "platform.h"
 
 /* Card state is _required_ to be at the front of eSE pad. */
diff --git a/libese-sysdeps/Android.bp b/libese-sysdeps/Android.bp
index 95dba4e..2e2fa1d 100644
--- a/libese-sysdeps/Android.bp
+++ b/libese-sysdeps/Android.bp
@@ -19,9 +19,6 @@
     proprietary: true,
     host_supported: true,
     srcs: [],
-    local_include_dirs: [
-        "include",
-    ],
     cflags: [
         "-std=c99",
         "-Wall",
diff --git a/libese-teq1/Android.bp b/libese-teq1/Android.bp
index 888ddc5..2e13a71 100644
--- a/libese-teq1/Android.bp
+++ b/libese-teq1/Android.bp
@@ -21,6 +21,7 @@
     srcs: ["teq1.c"],
     cflags: ["-Wall", "-Werror"],
     shared_libs: ["liblog", "libese", "libese-sysdeps"],
+    export_include_dirs: ["include"],
 }
 
 cc_library {
@@ -35,6 +36,7 @@
     // Ensure that only explicitly exported symbols are visible.
     shared_libs: ["liblog", "libese", "libese-sysdeps"],
     export_include_dirs: [".", "include"],
+    visibility: ["//external/libese:__subpackages__"],
 }
 
 subdirs = ["tests"]
diff --git a/libese-teq1/include/ese/teq1.h b/libese-teq1/include/ese/teq1.h
index d5d6ce9..0c4a6fa 100644
--- a/libese-teq1/include/ese/teq1.h
+++ b/libese-teq1/include/ese/teq1.h
@@ -21,8 +21,8 @@
 extern "C" {
 #endif
 
-#include "../../../libese/include/ese/ese.h"
-#include "../../../libese/include/ese/bit_spec.h"
+#include <ese/ese.h>
+#include <ese/bit_spec.h>
 
 /* Reserved codes for T=1 devices in EseOperation­>errors. */
 enum Teq1Error {
diff --git a/libese/Android.bp b/libese/Android.bp
index 38f0a7c..8e2296c 100644
--- a/libese/Android.bp
+++ b/libese/Android.bp
@@ -32,13 +32,22 @@
     },
 }
 
+cc_library_headers {
+    name: "libese-api-headers",
+    host_supported: true,
+    proprietary: true,
+    export_include_dirs: ["include"],
+    visibility: ["//external/libese:__subpackages__"],
+}
+
 cc_defaults {
     name: "libese-api-defaults",
     defaults: ["libese-defaults"],
 
+    header_libs: ["libese-api-headers"],
+    export_header_lib_headers: ["libese-api-headers"],
+
     // Ensure that only explicitly exported symbols are visible.
-    local_include_dirs: ["include"],
-    export_include_dirs: ["include"],
     cflags: ["-fvisibility=internal"],
 }
 
@@ -52,10 +61,8 @@
         "ese_sg.c",
     ],
 
-    export_include_dirs: ["include"],
-
     shared_libs: ["libese-sysdeps", "liblog"],
-    export_shared_lib_headers: ["liblog"],
+    export_shared_lib_headers: ["libese-sysdeps", "liblog"],
 }
 
 subdirs = ["tests"]
diff --git a/libese/include/ese/ese.h b/libese/include/ese/ese.h
index 69a84ef..17beb05 100644
--- a/libese/include/ese/ese.h
+++ b/libese/include/ese/ese.h
@@ -19,7 +19,7 @@
 
 #include "ese_sg.h"
 #include "ese_hw_api.h"
-#include "../../../libese-sysdeps/include/ese/sysdeps.h"
+#include <ese/sysdeps.h>
 
 #ifdef __cplusplus
 extern "C" {
diff --git a/libese/include/ese/ese_hw_api.h b/libese/include/ese/ese_hw_api.h
index 92fd671..759365a 100644
--- a/libese/include/ese/ese_hw_api.h
+++ b/libese/include/ese/ese_hw_api.h
@@ -18,7 +18,7 @@
 #define ESE_HW_API_H_ 1
 
 #include "ese_sg.h"
-#include "../../../libese-sysdeps/include/ese/sysdeps.h"
+#include <ese/sysdeps.h>
 
 #ifdef __cplusplus
 extern "C" {
diff --git a/libese/include/ese/ese_sg.h b/libese/include/ese/ese_sg.h
index 025520c..51b144c 100644
--- a/libese/include/ese/ese_sg.h
+++ b/libese/include/ese/ese_sg.h
@@ -17,7 +17,7 @@
 #ifndef ESE_SG_H_
 #define ESE_SG_H_ 1
 
-#include "../../../libese-sysdeps/include/ese/sysdeps.h"
+#include <ese/sysdeps.h>
 
 #ifdef __cplusplus
 extern "C" {