Merge "Only convert valid SharedMemInfo"
diff --git a/audio/2.0/default/Device.cpp b/audio/2.0/default/Device.cpp
index b696d94..da79238 100644
--- a/audio/2.0/default/Device.cpp
+++ b/audio/2.0/default/Device.cpp
@@ -17,9 +17,11 @@
 #define LOG_TAG "DeviceHAL"
 //#define LOG_NDEBUG 0
 
-#include <algorithm>
 #include <memory.h>
 #include <string.h>
+#include <algorithm>
+#include <mutex>
+#include <vector>
 
 #include <android/log.h>
 
@@ -35,8 +37,57 @@
 namespace V2_0 {
 namespace implementation {
 
-Device::Device(audio_hw_device_t* device)
-        : mDevice(device) {
+namespace {
+
+class Diagnostics {
+   public:
+    static Diagnostics& getInstance() {
+        std::lock_guard<std::mutex> _(mLock);
+        if (mInstance == nullptr) {
+            mInstance = new Diagnostics;
+        }
+        return *mInstance;
+    }
+
+    void registerDevice(Device* dev) {
+        std::lock_guard<std::mutex> _(mLock);
+        mDevices.push_back(wp<Device>(dev));
+    }
+
+    void checkForErasedHalCblk(const Device* dev) {
+        if (dev->version() != 0) return;  // all OK
+
+        std::ostringstream ss;
+        ss << "Zero HAL CB for " << dev->type() << ":" << std::hex
+           << dev->device() << "; Others: ";
+        {
+            std::lock_guard<std::mutex> _(mLock);
+            for (auto wp : mDevices) {
+                sp<Device> other{wp.promote()};
+                if (other.get() == nullptr || other.get() == dev) continue;
+                ss << other->type() << ":" << other->version() << ":"
+                   << std::hex << other->device() << "; ";
+            }
+        }
+        ALOGE("%s", ss.str().c_str());
+    }
+
+   private:
+    Diagnostics() {}
+
+    static std::mutex mLock;
+    static Diagnostics* mInstance;
+    std::vector<wp<Device>> mDevices;
+};
+
+std::mutex Diagnostics::mLock;
+Diagnostics* Diagnostics::mInstance{nullptr};
+
+}  // namespace
+
+Device::Device(audio_hw_device_t* device, const char* type)
+    : mDevice{device}, mType{type} {
+    Diagnostics::getInstance().registerDevice(this);
 }
 
 Device::~Device() {
@@ -68,10 +119,12 @@
 }
 
 char* Device::halGetParameters(const char* keys) {
+    Diagnostics::getInstance().checkForErasedHalCblk(this);
     return mDevice->get_parameters(mDevice, keys);
 }
 
 int Device::halSetParameters(const char* keysAndValues) {
+    Diagnostics::getInstance().checkForErasedHalCblk(this);
     return mDevice->set_parameters(mDevice, keysAndValues);
 }
 
diff --git a/audio/2.0/default/Device.h b/audio/2.0/default/Device.h
index 7738361..55bd0ab 100644
--- a/audio/2.0/default/Device.h
+++ b/audio/2.0/default/Device.h
@@ -56,7 +56,7 @@
 using ::android::sp;
 
 struct Device : public IDevice, public ParametersUtil {
-    explicit Device(audio_hw_device_t* device);
+    Device(audio_hw_device_t* device, const char* type);
 
     // Methods from ::android::hardware::audio::V2_0::IDevice follow.
     Return<Result> initCheck()  override;
@@ -101,17 +101,18 @@
     void closeInputStream(audio_stream_in_t* stream);
     void closeOutputStream(audio_stream_out_t* stream);
     audio_hw_device_t* device() const { return mDevice; }
+    const char* type() const { return mType; }
+    uint32_t version() const { return mDevice->common.version; }
 
-  private:
+   private:
     audio_hw_device_t *mDevice;
+    const char* mType;
 
     virtual ~Device();
 
     // Methods from ParametersUtil.
     char* halGetParameters(const char* keys) override;
     int halSetParameters(const char* keysAndValues) override;
-
-    uint32_t version() const { return mDevice->common.version; }
 };
 
 }  // namespace implementation
diff --git a/audio/2.0/default/DevicesFactory.cpp b/audio/2.0/default/DevicesFactory.cpp
index b913bc7..b344968 100644
--- a/audio/2.0/default/DevicesFactory.cpp
+++ b/audio/2.0/default/DevicesFactory.cpp
@@ -86,7 +86,7 @@
                 result = new PrimaryDevice(halDevice);
             } else {
                 result = new ::android::hardware::audio::V2_0::implementation::
-                    Device(halDevice);
+                    Device(halDevice, moduleName);
             }
             retval = Result::OK;
         } else if (halStatus == -EINVAL) {
diff --git a/audio/2.0/default/PrimaryDevice.cpp b/audio/2.0/default/PrimaryDevice.cpp
index 905203b..af0b249 100644
--- a/audio/2.0/default/PrimaryDevice.cpp
+++ b/audio/2.0/default/PrimaryDevice.cpp
@@ -25,8 +25,7 @@
 namespace implementation {
 
 PrimaryDevice::PrimaryDevice(audio_hw_device_t* device)
-        : mDevice(new Device(device)) {
-}
+    : mDevice{new Device(device, AUDIO_HARDWARE_MODULE_ID_PRIMARY)} {}
 
 PrimaryDevice::~PrimaryDevice() {}
 
diff --git a/compatibility_matrix.xml b/compatibility_matrix.xml
index cd3904e..8ef91b9 100644
--- a/compatibility_matrix.xml
+++ b/compatibility_matrix.xml
@@ -1,4 +1,16 @@
 <compatibility-matrix version="1.0" type="framework">
+    <hal format="hidl" optional="false">
+        <name>android.hardware.audio</name>
+        <version>2.0</version>
+    </hal>
+    <hal format="hidl" optional="false">
+        <name>android.hardware.audio.effect</name>
+        <version>2.0</version>
+    </hal>
+    <hal format="hidl" optional="true">
+        <name>android.hardware.biometrics.fingerprint</name>
+        <version>2.1</version>
+    </hal>
     <hal format="hidl" optional="true">
         <name>android.hardware.bluetooth</name>
         <version>1.0</version>
@@ -8,18 +20,76 @@
         <version>1.0</version>
     </hal>
     <hal format="hidl" optional="true">
+        <name>android.hardware.camera.provider</name>
+        <version>2.4</version>
+    </hal>
+    <!-- TODO(b/35356977): configstore is required. -->
+    <hal format="hidl" optional="true">
         <name>android.hardware.configstore</name>
+        <version>1.0-1</version>
+    </hal>
+    <hal format="hidl" optional="true">
+        <name>android.hardware.contexthub</name>
         <version>1.0</version>
     </hal>
+    <hal format="hidl" optional="false">
+        <name>android.hardware.drm</name>
+        <version>1.0</version>
+    </hal>
+    <hal format="hidl" optional="true">
+        <name>android.hardware.dumpstate</name>
+        <version>1.0</version>
+    </hal>
+    <hal format="hidl" optional="false">
+        <name>android.hardware.gatekeeper</name>
+        <version>1.0</version>
+    </hal>
+    <hal format="hidl" optional="true">
+        <name>android.hardware.gnss</name>
+        <version>1.0</version>
+    </hal>
+    <hal format="hidl" optional="false">
+        <name>android.hardware.graphics.allocator</name>
+        <version>2.0</version>
+    </hal>
+    <hal format="hidl" optional="false">
+        <name>android.hardware.graphics.composer</name>
+        <version>2.1</version>
+    </hal>
+    <hal format="hidl" optional="false">
+        <name>android.hardware.graphics.mapper</name>
+        <version>2.0</version>
+    </hal>
     <hal format="hidl" optional="true">
         <name>android.hardware.ir</name>
         <version>1.0</version>
     </hal>
+    <hal format="hidl" optional="false">
+        <name>android.hardware.keymaster</name>
+        <version>3.0</version>
+    </hal>
+    <hal format="hidl" optional="true">
+        <name>android.hardware.light</name>
+        <version>2.0</version>
+    </hal>
+    <!-- TODO(b/36097717): omx is required. -->
+    <hal format="hidl" optional="true">
+        <name>android.hardware.media.omx</name>
+        <version>1.0</version>
+    </hal>
+    <hal format="hidl" optional="true">
+        <name>android.hardware.memtrack</name>
+        <version>1.0</version>
+    </hal>
     <hal format="hidl" optional="true">
         <name>android.hardware.nfc</name>
         <version>1.0</version>
     </hal>
     <hal format="hidl" optional="true">
+        <name>android.hardware.power</name>
+        <version>1.0</version>
+    </hal>
+    <hal format="hidl" optional="true">
         <name>android.hardware.radio</name>
         <version>1.0</version>
     </hal>
@@ -28,6 +98,30 @@
         <version>1.0</version>
     </hal>
     <hal format="hidl" optional="true">
+        <name>android.hardware.sensors</name>
+        <version>1.0</version>
+    </hal>
+    <hal format="hidl" optional="true">
+        <name>android.hardware.soundtrigger</name>
+        <version>2.0</version>
+    </hal>
+    <hal format="hidl" optional="true">
+        <name>android.hardware.thermal</name>
+        <version>1.0</version>
+    </hal>
+    <hal format="hidl" optional="true">
+        <name>android.hardware.usb</name>
+        <version>1.0</version>
+    </hal>
+    <hal format="hidl" optional="true">
+        <name>android.hardware.vibrator</name>
+        <version>1.0</version>
+    </hal>
+    <hal format="hidl" optional="true">
+        <name>android.hardware.vr</name>
+        <version>1.0</version>
+    </hal>
+    <hal format="hidl" optional="true">
         <name>android.hardware.wifi</name>
         <version>1.0</version>
     </hal>
diff --git a/keymaster/3.0/default/Android.mk b/keymaster/3.0/default/Android.mk
index 9df5bf8..87ad245 100644
--- a/keymaster/3.0/default/Android.mk
+++ b/keymaster/3.0/default/Android.mk
@@ -11,7 +11,8 @@
     liblog \
     libsoftkeymasterdevice \
     libcrypto \
-    libkeymaster1 \
+    libkeymaster_portable \
+    libkeymaster_staging \
     libhidlbase \
     libhidltransport \
     libutils \
diff --git a/keymaster/3.0/default/KeymasterDevice.cpp b/keymaster/3.0/default/KeymasterDevice.cpp
index fcdd329..d83963f 100644
--- a/keymaster/3.0/default/KeymasterDevice.cpp
+++ b/keymaster/3.0/default/KeymasterDevice.cpp
@@ -64,7 +64,7 @@
     assert(mod->module_api_version < KEYMASTER_MODULE_API_VERSION_1_0);
     ALOGI("Found keymaster0 module %s, version %x", mod->name, mod->module_api_version);
 
-    UniquePtr<SoftKeymasterDevice> soft_keymaster(new SoftKeymasterDevice);
+    std::unique_ptr<SoftKeymasterDevice> soft_keymaster(new SoftKeymasterDevice);
     keymaster0_device_t* km0_device = NULL;
     keymaster_error_t error = KM_ERROR_OK;
 
@@ -107,7 +107,7 @@
     assert(mod->module_api_version >= KEYMASTER_MODULE_API_VERSION_1_0);
     ALOGI("Found keymaster1 module %s, version %x", mod->name, mod->module_api_version);
 
-    UniquePtr<SoftKeymasterDevice> soft_keymaster(new SoftKeymasterDevice);
+    std::unique_ptr<SoftKeymasterDevice> soft_keymaster(new SoftKeymasterDevice);
     keymaster1_device_t* km1_device = nullptr;
     keymaster_error_t error = KM_ERROR_OK;
 
diff --git a/keymaster/3.0/vts/functional/keymaster_hidl_hal_test.cpp b/keymaster/3.0/vts/functional/keymaster_hidl_hal_test.cpp
index 3448398..fcd4dec 100644
--- a/keymaster/3.0/vts/functional/keymaster_hidl_hal_test.cpp
+++ b/keymaster/3.0/vts/functional/keymaster_hidl_hal_test.cpp
@@ -3932,17 +3932,21 @@
  * Verifies that attesting to AES keys fails in the expected way.
  */
 TEST_F(AttestationTest, AesAttestation) {
-    ASSERT_EQ(ErrorCode::OK, GenerateKey(AuthorizationSetBuilder()
-                                             .Authorization(TAG_NO_AUTH_REQUIRED)
-                                             .AesEncryptionKey(128)
-                                             .EcbMode()
-                                             .Padding(PaddingMode::PKCS7)));
+    ASSERT_EQ(ErrorCode::OK,
+              GenerateKey(AuthorizationSetBuilder()
+                              .Authorization(TAG_NO_AUTH_REQUIRED)
+                              .AesEncryptionKey(128)
+                              .EcbMode()
+                              .Padding(PaddingMode::PKCS7)));
 
     hidl_vec<hidl_vec<uint8_t>> cert_chain;
-    EXPECT_EQ(ErrorCode::INCOMPATIBLE_ALGORITHM,
-              AttestKey(AuthorizationSetBuilder().Authorization(TAG_ATTESTATION_CHALLENGE,
-                                                                HidlBuf("challenge")),
-                        &cert_chain));
+    EXPECT_EQ(
+        ErrorCode::INCOMPATIBLE_ALGORITHM,
+        AttestKey(
+            AuthorizationSetBuilder()
+                .Authorization(TAG_ATTESTATION_CHALLENGE, HidlBuf("challenge"))
+                .Authorization(TAG_ATTESTATION_APPLICATION_ID, HidlBuf("foo")),
+            &cert_chain));
 }
 
 /*
@@ -3951,18 +3955,22 @@
  * Verifies that attesting to HMAC keys fails in the expected way.
  */
 TEST_F(AttestationTest, HmacAttestation) {
-    ASSERT_EQ(ErrorCode::OK, GenerateKey(AuthorizationSetBuilder()
-                                             .Authorization(TAG_NO_AUTH_REQUIRED)
-                                             .HmacKey(128)
-                                             .EcbMode()
-                                             .Digest(Digest::SHA_2_256)
-                                             .Authorization(TAG_MIN_MAC_LENGTH, 128)));
+    ASSERT_EQ(ErrorCode::OK,
+              GenerateKey(AuthorizationSetBuilder()
+                              .Authorization(TAG_NO_AUTH_REQUIRED)
+                              .HmacKey(128)
+                              .EcbMode()
+                              .Digest(Digest::SHA_2_256)
+                              .Authorization(TAG_MIN_MAC_LENGTH, 128)));
 
     hidl_vec<hidl_vec<uint8_t>> cert_chain;
-    EXPECT_EQ(ErrorCode::INCOMPATIBLE_ALGORITHM,
-              AttestKey(AuthorizationSetBuilder().Authorization(TAG_ATTESTATION_CHALLENGE,
-                                                                HidlBuf("challenge")),
-                        &cert_chain));
+    EXPECT_EQ(
+        ErrorCode::INCOMPATIBLE_ALGORITHM,
+        AttestKey(
+            AuthorizationSetBuilder()
+                .Authorization(TAG_ATTESTATION_CHALLENGE, HidlBuf("challenge"))
+                .Authorization(TAG_ATTESTATION_APPLICATION_ID, HidlBuf("foo")),
+            &cert_chain));
 }
 
 typedef KeymasterHidlTest KeyDeletionTest;
diff --git a/wifi/supplicant/1.0/vts/functional/supplicant_sta_iface_hidl_test.cpp b/wifi/supplicant/1.0/vts/functional/supplicant_sta_iface_hidl_test.cpp
index c0e62d1..ec102d5 100644
--- a/wifi/supplicant/1.0/vts/functional/supplicant_sta_iface_hidl_test.cpp
+++ b/wifi/supplicant/1.0/vts/functional/supplicant_sta_iface_hidl_test.cpp
@@ -261,9 +261,7 @@
 TEST_F(SupplicantStaIfaceHidlTest, InitiateTdlsDiscover) {
     sta_iface_->initiateTdlsDiscover(
         mac_addr_, [](const SupplicantStatus& status) {
-            // These requests will fail unless the MAC address mentioned is
-            // actually around.
-            EXPECT_EQ(SupplicantStatusCode::FAILURE_UNKNOWN, status.code);
+            EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
         });
 }
 
@@ -273,9 +271,7 @@
 TEST_F(SupplicantStaIfaceHidlTest, InitiateTdlsSetup) {
     sta_iface_->initiateTdlsSetup(
         mac_addr_, [](const SupplicantStatus& status) {
-            // These requests will fail unless the MAC address mentioned is
-            // actually around.
-            EXPECT_EQ(SupplicantStatusCode::FAILURE_UNKNOWN, status.code);
+            EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
         });
 }
 
@@ -285,9 +281,7 @@
 TEST_F(SupplicantStaIfaceHidlTest, InitiateTdlsTeardown) {
     sta_iface_->initiateTdlsTeardown(
         mac_addr_, [](const SupplicantStatus& status) {
-            // These requests will fail unless the MAC address mentioned is
-            // actually around.
-            EXPECT_EQ(SupplicantStatusCode::FAILURE_UNKNOWN, status.code);
+            EXPECT_EQ(SupplicantStatusCode::SUCCESS, status.code);
         });
 }