Diced: Implement HAL proxy node and initialize it in diced_main.

Still using sample artifacts if no HAL was found.

Test: diced_client_test
Bug: 198197213
Change-Id: I2d218f04cd53a6177dddd3e984879832287bd4dc
diff --git a/diced/src/diced_main.rs b/diced/src/diced_main.rs
index c6a5b68..c2cf02c 100644
--- a/diced/src/diced_main.rs
+++ b/diced/src/diced_main.rs
@@ -14,13 +14,15 @@
 
 //! Main entry point for diced, the friendly neighborhood DICE service.
 
-use diced::{DiceMaintenance, DiceNode, ResidentNode};
+use binder::get_interface;
+use diced::{DiceMaintenance, DiceNode, DiceNodeImpl, ProxyNodeHal, ResidentNode};
 use std::convert::TryInto;
 use std::panic;
 use std::sync::Arc;
 
 static DICE_NODE_SERVICE_NAME: &str = "android.security.dice.IDiceNode";
 static DICE_MAINTENANCE_SERVICE_NAME: &str = "android.security.dice.IDiceMaintenance";
+static DICE_HAL_SERVICE_NAME: &str = "android.hardware.security.dice.IDiceDevice/default";
 
 fn main() {
     android_logger::init_once(
@@ -34,17 +36,28 @@
     // Saying hi.
     log::info!("Diced, your friendly neighborhood DICE service, is starting.");
 
-    let (cdi_attest, cdi_seal, bcc) = diced_sample_inputs::make_sample_bcc_and_cdis()
-        .expect("Failed to create sample dice artifacts.");
-
-    let node_impl = Arc::new(
-        ResidentNode::new(
-            cdi_attest[..].try_into().expect("Failed to convert cdi_attest into array ref."),
-            cdi_seal[..].try_into().expect("Failed to convert cdi_seal into array ref."),
-            bcc,
-        )
-        .expect("Failed to construct a resident node."),
-    );
+    let node_impl: Arc<dyn DiceNodeImpl + Send + Sync> = match get_interface(DICE_HAL_SERVICE_NAME)
+    {
+        Ok(dice_device) => {
+            Arc::new(ProxyNodeHal::new(dice_device).expect("Failed to construct a proxy node."))
+        }
+        Err(e) => {
+            log::warn!("Failed to connect to DICE HAL: {:?}", e);
+            log::warn!("Using sample dice artifacts.");
+            let (cdi_attest, cdi_seal, bcc) = diced_sample_inputs::make_sample_bcc_and_cdis()
+                .expect("Failed to create sample dice artifacts.");
+            Arc::new(
+                ResidentNode::new(
+                    cdi_attest[..]
+                        .try_into()
+                        .expect("Failed to convert cdi_attest into array ref."),
+                    cdi_seal[..].try_into().expect("Failed to convert cdi_seal into array ref."),
+                    bcc,
+                )
+                .expect("Failed to construct a resident node."),
+            )
+        }
+    };
 
     let node = DiceNode::new_as_binder(node_impl.clone())
         .expect("Failed to create IDiceNode service instance.");