Switch NFC to binderized HAL in angler_treble.

- Include hwservicemanager in angler_treble
- Use a custom kernel for angler_treble including hwbinder support
- Switch NFC HAL to nfc_hal_pn54x in angler_treble
- Add SEPolicy for angler_treble

Change-Id: Ib047365d1f62ae996edc40709106c295e7f38359
diff --git a/angler_treble/aosp_angler_treble.mk b/angler_treble/aosp_angler_treble.mk
index 817250c..da52ce4 100644
--- a/angler_treble/aosp_angler_treble.mk
+++ b/angler_treble/aosp_angler_treble.mk
@@ -19,3 +19,6 @@
 PRODUCT_NAME := aosp_angler_treble
 PRODUCT_DEVICE := angler_treble
 PRODUCT_MODEL := AOSP on angler_treble
+
+PRODUCT_PACKAGES += \
+    hwservicemanager
diff --git a/device.mk b/device.mk
index 2a9730e..2b49f12 100644
--- a/device.mk
+++ b/device.mk
@@ -23,7 +23,11 @@
 TARGET_USES_CHINOOK_SENSORHUB := false
 
 ifeq ($(TARGET_PREBUILT_KERNEL),)
-    LOCAL_KERNEL := device/huawei/angler-kernel/Image.gz-dtb
+    ifeq ($(TARGET_PRODUCT),angler_treble)
+      LOCAL_KERNEL := device/huawei/angler-kernel/Image_treble.gz-dtb
+    else
+      LOCAL_KERNEL := device/huawei/angler-kernel/Image.gz-dtb
+    endif
 else
   LOCAL_KERNEL := $(TARGET_PREBUILT_KERNEL)
 endif
@@ -263,10 +267,17 @@
 # NFC
 PRODUCT_PACKAGES += \
     libnfc-nci \
-    nfc_nci.angler \
     NfcNci \
     Tag
 
+ifeq ($(TARGET_PRODUCT), angler_treble)
+PRODUCT_PACKAGES += \
+    nfc_hal_pn54x
+else
+PRODUCT_PACKAGES += \
+    nfc_nci.angler
+endif
+
 # Power HAL
 PRODUCT_PACKAGES += \
     power.angler \
diff --git a/sepolicy/file_contexts b/sepolicy/file_contexts
index e563795..cee6202 100644
--- a/sepolicy/file_contexts
+++ b/sepolicy/file_contexts
@@ -174,3 +174,5 @@
 # Sysfs files used by nanoapp_cmd
 /sys/devices/virtual/nanohub/nanohub(/.*)? u:object_r:sysfs_nanoapp_cmd:s0
 
+# NFC hal
+/system/bin/hw/nfc_hal_pn54x    u:object_r:nfc_hal_pn54x_exec:s0
diff --git a/sepolicy/nfc.te b/sepolicy/nfc.te
new file mode 100644
index 0000000..90488a1
--- /dev/null
+++ b/sepolicy/nfc.te
@@ -0,0 +1,2 @@
+# allow NFC process to call into the NFC HAL
+binder_call(nfc, nfc_hal_pn54x)
diff --git a/sepolicy/nfc_hal_pn54x.te b/sepolicy/nfc_hal_pn54x.te
new file mode 100644
index 0000000..2830a71
--- /dev/null
+++ b/sepolicy/nfc_hal_pn54x.te
@@ -0,0 +1,30 @@
+# nfc subsystem
+type nfc_hal_pn54x, domain;
+type nfc_hal_pn54x_exec, exec_type, file_type;
+
+# may be started by init
+init_daemon_domain(nfc_hal_pn54x)
+
+allow nfc_hal_pn54x nfc_hal_pn54x_exec:file rx_file_perms;
+
+# hwbinder access
+hwbinder_use(nfc_hal_pn54x)
+
+# call into NFC process (callbacks)
+binder_call(nfc_hal_pn54x, nfc)
+
+# Set NFC properties
+set_prop(nfc_hal_pn54x, nfc_prop)
+
+# NFC device access.
+allow nfc_hal_pn54x nfc_device:chr_file rw_file_perms;
+
+# Data file accesses.
+allow nfc_hal_pn54x nfc_data_file:dir create_dir_perms;
+allow nfc_hal_pn54x nfc_data_file:notdevfile_class_set create_file_perms;
+
+allow nfc_hal_pn54x sysfs_nfc_power_writable:file rw_file_perms;
+allow nfc_hal_pn54x sysfs:file write;
+
+# TODO: added to match above sysfs rule. Remove me?
+allow nfc_hal_pn54x sysfs_usb:file write;