[keymaster] Fix race condition at bootup

Keymaster waits until all version and patchlevel properties have been
set before configuring the implementation.

Bug: 90406546
Change-Id: Ic7867955c9afef35f5be7830cbe0d9fcaadf5314
diff --git a/hals/keymaster/KeymasterDevice.cpp b/hals/keymaster/KeymasterDevice.cpp
index 635ede4..37da3f0 100644
--- a/hals/keymaster/KeymasterDevice.cpp
+++ b/hals/keymaster/KeymasterDevice.cpp
@@ -124,6 +124,7 @@
 
 // base
 using ::android::base::GetProperty;
+using ::android::base::WaitForPropertyCreation;
 
 // libhidl
 using ::android::hardware::Void;
@@ -251,6 +252,11 @@
 
 KeymasterDevice::KeymasterDevice(KeymasterClient& keymaster) :
         _keymaster{keymaster} {
+    // Block until all of the properties have been created
+    while (!(WaitForPropertyCreation(PROPERTY_OS_VERSION) &&
+             WaitForPropertyCreation(PROPERTY_OS_PATCHLEVEL) &&
+             WaitForPropertyCreation(PROPERTY_VENDOR_PATCHLEVEL))) {}
+
     _os_version = VersionToUint32(GetProperty(PROPERTY_OS_VERSION, ""));
     _os_patchlevel = DateCodeToUint32(GetProperty(PROPERTY_OS_PATCHLEVEL, ""),
                                      false /* include_day */);