Merge "Revert "Set omx and configstore as optional."" into oc-dev
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 8825107..b344968 100644
--- a/audio/2.0/default/DevicesFactory.cpp
+++ b/audio/2.0/default/DevicesFactory.cpp
@@ -39,6 +39,7 @@
         case IDevicesFactory::Device::R_SUBMIX: return AUDIO_HARDWARE_MODULE_ID_REMOTE_SUBMIX;
         case IDevicesFactory::Device::STUB: return AUDIO_HARDWARE_MODULE_ID_STUB;
     }
+    return nullptr;
 }
 
 // static
@@ -75,19 +76,22 @@
 // Methods from ::android::hardware::audio::V2_0::IDevicesFactory follow.
 Return<void> DevicesFactory::openDevice(IDevicesFactory::Device device, openDevice_cb _hidl_cb)  {
     audio_hw_device_t *halDevice;
-    int halStatus = loadAudioInterface(deviceToString(device), &halDevice);
-    Result retval(Result::OK);
+    Result retval(Result::INVALID_ARGUMENTS);
     sp<IDevice> result;
-    if (halStatus == OK) {
-        if (device == IDevicesFactory::Device::PRIMARY) {
-            result = new PrimaryDevice(halDevice);
-        } else {
-            result = new ::android::hardware::audio::V2_0::implementation::Device(halDevice);
+    const char* moduleName = deviceToString(device);
+    if (moduleName != nullptr) {
+        int halStatus = loadAudioInterface(moduleName, &halDevice);
+        if (halStatus == OK) {
+            if (device == IDevicesFactory::Device::PRIMARY) {
+                result = new PrimaryDevice(halDevice);
+            } else {
+                result = new ::android::hardware::audio::V2_0::implementation::
+                    Device(halDevice, moduleName);
+            }
+            retval = Result::OK;
+        } else if (halStatus == -EINVAL) {
+            retval = Result::NOT_INITIALIZED;
         }
-    } else if (halStatus == -EINVAL) {
-        retval = Result::NOT_INITIALIZED;
-    } else {
-        retval = Result::INVALID_ARGUMENTS;
     }
     _hidl_cb(retval, result);
     return Void();
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/audio/2.0/vts/functional/AudioPrimaryHidlHalTest.cpp b/audio/2.0/vts/functional/AudioPrimaryHidlHalTest.cpp
index 711a8d9..074903f 100644
--- a/audio/2.0/vts/functional/AudioPrimaryHidlHalTest.cpp
+++ b/audio/2.0/vts/functional/AudioPrimaryHidlHalTest.cpp
@@ -155,6 +155,16 @@
     doc::test("test the getService (called in SetUp)");
 }
 
+TEST_F(AudioHidlTest, OpenDeviceInvalidParameter) {
+    doc::test("test passing an invalid parameter to openDevice");
+    IDevicesFactory::Result result;
+    sp<IDevice> device;
+    ASSERT_OK(devicesFactory->openDevice(IDevicesFactory::Device(-1),
+                                         returnIn(result, device)));
+    ASSERT_EQ(IDevicesFactory::Result::INVALID_ARGUMENTS, result);
+    ASSERT_TRUE(device == nullptr);
+}
+
 //////////////////////////////////////////////////////////////////////////////
 /////////////////////////////// openDevice primary ///////////////////////////
 //////////////////////////////////////////////////////////////////////////////
diff --git a/current.txt b/current.txt
index 089f128..82a1626 100644
--- a/current.txt
+++ b/current.txt
@@ -87,9 +87,9 @@
 e6dd0c8416e523ab9cbd14d56ab6f016481a8aef3bc8a750051122d31075f6c7 android.hardware.gnss@1.0::IGnssGeofenceCallback
 f90e4ddc652706299d8e3d8ba18e0745c3bae9bf4d1be6bd06d9c1f50ec8d28a android.hardware.gnss@1.0::IGnssGeofencing
 9ea8987bb1089c8c5d7b67866575b866ef516045021d9efcc37c6352bce072a3 android.hardware.gnss@1.0::IGnssMeasurement
-d6a00007b30f0e3ed196df677f311b3e25b15082c5e82756f392677d3b66ec0a android.hardware.gnss@1.0::IGnssMeasurementCallback
+cf20492673d6a423e4c2e87fdfb5a4c4a602431721978db852e246f258e25edb android.hardware.gnss@1.0::IGnssMeasurementCallback
 af85aa0f48ae99a39f4688c344e4419304f681f9af818a5c8d759286fc4418de android.hardware.gnss@1.0::IGnssNavigationMessage
-649b1b0fb98bdd3a1ace84f4e08bfa2df813afdd4862856693f107c281a929ba android.hardware.gnss@1.0::IGnssNavigationMessageCallback
+76b0874ea4c06b29f66418c59820f4286b3be9629cd872923d0dfbb602cd432d android.hardware.gnss@1.0::IGnssNavigationMessageCallback
 248bcf51da4273d64f367bf6877baef2feeaca365459842fd3c214a2dc6e0224 android.hardware.gnss@1.0::IGnssNi
 c781b7b125f68be5db8a8c3d412d526acdbdf77dcc592a4c0ed70b8ce4fe6c49 android.hardware.gnss@1.0::IGnssNiCallback
 c1142657de16fdb292a502372fe938614d65270ab8359217d6e13604fe4dbca4 android.hardware.gnss@1.0::IGnssXtra
diff --git a/gnss/1.0/IGnssMeasurementCallback.hal b/gnss/1.0/IGnssMeasurementCallback.hal
index 467bf19..4031664 100644
--- a/gnss/1.0/IGnssMeasurementCallback.hal
+++ b/gnss/1.0/IGnssMeasurementCallback.hal
@@ -556,7 +556,7 @@
 
         /**
          * Signal-to-noise ratio at correlator output in dB.
-         * If the data is available, gnssClockFlags must contain MEASUREMENT_HAS_SNR.
+         * If the data is available, GnssMeasurementFlags must contain HAS_SNR.
          * This is the power ratio of the "correlation peak height above the
          * observed noise floor" to "the noise RMS".
          */
diff --git a/gnss/1.0/IGnssNavigationMessageCallback.hal b/gnss/1.0/IGnssNavigationMessageCallback.hal
index e18f7e2..3fdae9f 100644
--- a/gnss/1.0/IGnssNavigationMessageCallback.hal
+++ b/gnss/1.0/IGnssNavigationMessageCallback.hal
@@ -28,14 +28,14 @@
     @export(name="", value_prefix="GNSS_NAVIGATION_MESSAGE_TYPE_")
     enum GnssNavigationMessageType : int16_t {
         UNKNOWN    = 0,
-        /** GNSS L1 C/A message contained in the structure.  */
-        GNSS_L1CA       = 0x0101,
-        /** GNSS L2-CNAV message contained in the structure. */
-        GNSS_L2CNAV     = 0x0102,
-        /** GNSS L5-CNAV message contained in the structure. */
-        GNSS_L5CNAV     = 0x0103,
-        /** GNSS CNAV-2 message contained in the structure. */
-        GNSS_CNAV2      = 0x0104,
+        /** GPS L1 C/A message contained in the structure.  */
+        GPS_L1CA       = 0x0101,
+        /** GPS L2-CNAV message contained in the structure. */
+        GPS_L2CNAV     = 0x0102,
+        /** GPS L5-CNAV message contained in the structure. */
+        GPS_L5CNAV     = 0x0103,
+        /** GPS CNAV-2 message contained in the structure. */
+        GPS_CNAV2      = 0x0104,
         /** Glonass L1 CA message contained in the structure. */
         GLO_L1CA        = 0x0301,
         /** Beidou D1 message contained in the structure. */
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/radio/1.0/vts/functional/radio_hidl_hal_misc.cpp b/radio/1.0/vts/functional/radio_hidl_hal_misc.cpp
index d6ac9d6..65b055c 100644
--- a/radio/1.0/vts/functional/radio_hidl_hal_misc.cpp
+++ b/radio/1.0/vts/functional/radio_hidl_hal_misc.cpp
@@ -556,7 +556,7 @@
 TEST_F(RadioHidlTest, nvResetConfig) {
   int serial = 1;
 
-  radio->nvResetConfig(++serial, ResetNvType::RELOAD);
+  radio->nvResetConfig(++serial, ResetNvType::ERASE);
   EXPECT_EQ(std::cv_status::no_timeout, wait());
   EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
   EXPECT_EQ(serial, radioRsp->rspInfo.serial);
@@ -733,6 +733,8 @@
 TEST_F(RadioHidlTest, setAllowedCarriers) {
   int serial = 1;
   CarrierRestrictions carriers;
+
+  /* Carrier restriction with one carrier */
   memset(&carriers, 0, sizeof(carriers));
   carriers.allowedCarriers.resize(1);
   carriers.excludedCarriers.resize(0);
@@ -749,6 +751,20 @@
   if (cardStatus.cardState == CardState::ABSENT) {
     ASSERT_TRUE(radioRsp->rspInfo.error == RadioError::NONE);
   }
+
+  /* Reset back to no carrier restriction */
+  memset(&carriers, 0, sizeof(carriers));
+  carriers.allowedCarriers.resize(0);
+  carriers.excludedCarriers.resize(0);
+
+  radio->setAllowedCarriers(++serial, true, carriers);
+  EXPECT_EQ(std::cv_status::no_timeout, wait());
+  EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp->rspInfo.type);
+  EXPECT_EQ(serial, radioRsp->rspInfo.serial);
+
+  if (cardStatus.cardState == CardState::ABSENT) {
+      ASSERT_TRUE(radioRsp->rspInfo.error == RadioError::NONE);
+  }
 }
 
 /*
@@ -816,4 +832,4 @@
     ASSERT_TRUE(radioRsp->rspInfo.error == RadioError::NONE
         || radioRsp->rspInfo.error == RadioError::REQUEST_NOT_SUPPORTED);
   }
-}
\ No newline at end of file
+}
diff --git a/radio/1.0/vts/functional/sap_hidl_hal_api.cpp b/radio/1.0/vts/functional/sap_hidl_hal_api.cpp
index 682230c..e166209 100644
--- a/radio/1.0/vts/functional/sap_hidl_hal_api.cpp
+++ b/radio/1.0/vts/functional/sap_hidl_hal_api.cpp
@@ -66,7 +66,8 @@
   EXPECT_EQ(std::cv_status::no_timeout, wait());
   EXPECT_EQ(sapCb->sapResponseToken, token);
 
-  ASSERT_TRUE(SapResultCode::DATA_NOT_AVAILABLE == sapCb->sapResultCode ||
+  ASSERT_TRUE(SapResultCode::GENERIC_FAILURE == sapCb->sapResultCode ||
+              SapResultCode::DATA_NOT_AVAILABLE == sapCb->sapResultCode ||
               SapResultCode::CARD_ALREADY_POWERED_OFF == sapCb->sapResultCode ||
               SapResultCode::CARD_REMOVED == sapCb->sapResultCode);
 }
@@ -82,7 +83,8 @@
   EXPECT_EQ(std::cv_status::no_timeout, wait());
   EXPECT_EQ(sapCb->sapResponseToken, token);
 
-  ASSERT_TRUE(SapResultCode::CARD_NOT_ACCESSSIBLE == sapCb->sapResultCode ||
+  ASSERT_TRUE(SapResultCode::GENERIC_FAILURE == sapCb->sapResultCode ||
+              SapResultCode::CARD_NOT_ACCESSSIBLE == sapCb->sapResultCode ||
               SapResultCode::CARD_ALREADY_POWERED_OFF == sapCb->sapResultCode ||
               SapResultCode::CARD_REMOVED == sapCb->sapResultCode ||
               SapResultCode::CARD_ALREADY_POWERED_ON == sapCb->sapResultCode);
@@ -98,7 +100,8 @@
   EXPECT_EQ(std::cv_status::no_timeout, wait());
   EXPECT_EQ(sapCb->sapResponseToken, token);
 
-  ASSERT_TRUE(SapResultCode::CARD_NOT_ACCESSSIBLE == sapCb->sapResultCode ||
+  ASSERT_TRUE(SapResultCode::GENERIC_FAILURE == sapCb->sapResultCode ||
+              SapResultCode::CARD_NOT_ACCESSSIBLE == sapCb->sapResultCode ||
               SapResultCode::CARD_ALREADY_POWERED_OFF == sapCb->sapResultCode ||
               SapResultCode::CARD_REMOVED == sapCb->sapResultCode);
 }
@@ -113,7 +116,8 @@
   EXPECT_EQ(std::cv_status::no_timeout, wait());
   EXPECT_EQ(sapCb->sapResponseToken, token);
 
-  EXPECT_EQ(SapResultCode::DATA_NOT_AVAILABLE, sapCb->sapResultCode);
+  ASSERT_TRUE(SapResultCode::GENERIC_FAILURE == sapCb->sapResultCode ||
+              SapResultCode::DATA_NOT_AVAILABLE == sapCb->sapResultCode);
 }
 
 /*
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);
         });
 }