Merge "Check handle for nullptr"
diff --git a/audio/2.0/default/Stream.cpp b/audio/2.0/default/Stream.cpp
index 671f171..effdd28 100644
--- a/audio/2.0/default/Stream.cpp
+++ b/audio/2.0/default/Stream.cpp
@@ -44,8 +44,20 @@
 }
 
 // static
-Result Stream::analyzeStatus(const char* funcName, int status, int ignoreError, int ignoreError2) {
-    if (status != 0 && status != -ignoreError && status != -ignoreError2) {
+Result Stream::analyzeStatus(const char* funcName, int status) {
+    static const std::vector<int> empty;
+    return analyzeStatus(funcName, status, empty);
+}
+
+template <typename T>
+inline bool element_in(T e, const std::vector<T>& v) {
+    return std::find(v.begin(), v.end(), e) != v.end();
+}
+
+// static
+Result Stream::analyzeStatus(const char* funcName, int status,
+                             const std::vector<int>& ignoreErrors) {
+    if (status != 0 && (ignoreErrors.empty() || !element_in(-status, ignoreErrors))) {
         ALOGW("Error from HAL stream in function %s: %s", funcName, strerror(-status));
     }
     switch (status) {
diff --git a/audio/2.0/default/Stream.h b/audio/2.0/default/Stream.h
index b49e658..82f05a7 100644
--- a/audio/2.0/default/Stream.h
+++ b/audio/2.0/default/Stream.h
@@ -17,6 +17,8 @@
 #ifndef ANDROID_HARDWARE_AUDIO_V2_0_STREAM_H
 #define ANDROID_HARDWARE_AUDIO_V2_0_STREAM_H
 
+#include <vector>
+
 #include <android/hardware/audio/2.0/IStream.h>
 #include <hardware/audio.h>
 #include <hidl/Status.h>
@@ -79,10 +81,11 @@
     Return<Result> close()  override;
 
     // Utility methods for extending interfaces.
-    static Result analyzeStatus(
-            const char* funcName, int status, int ignoreError = OK, int ignoreError2 = OK);
+    static Result analyzeStatus(const char* funcName, int status);
+    static Result analyzeStatus(const char* funcName, int status,
+                                const std::vector<int>& ignoreErrors);
 
-  private:
+   private:
     audio_stream_t *mStream;
 
     virtual ~Stream();
diff --git a/audio/2.0/default/StreamIn.cpp b/audio/2.0/default/StreamIn.cpp
index abd0497..b81cbb9 100644
--- a/audio/2.0/default/StreamIn.cpp
+++ b/audio/2.0/default/StreamIn.cpp
@@ -416,15 +416,15 @@
 // static
 Result StreamIn::getCapturePositionImpl(audio_stream_in_t* stream,
                                         uint64_t* frames, uint64_t* time) {
+    // HAL may have a stub function, always returning ENOSYS, don't
+    // spam the log in this case.
+    static const std::vector<int> ignoredErrors{ENOSYS};
     Result retval(Result::NOT_SUPPORTED);
     if (stream->get_capture_position != NULL) return retval;
     int64_t halFrames, halTime;
-    retval = Stream::analyzeStatus(
-        "get_capture_position",
-        stream->get_capture_position(stream, &halFrames, &halTime),
-        // HAL may have a stub function, always returning ENOSYS, don't
-        // spam the log in this case.
-        ENOSYS);
+    retval = Stream::analyzeStatus("get_capture_position",
+                                   stream->get_capture_position(stream, &halFrames, &halTime),
+                                   ignoredErrors);
     if (retval == Result::OK) {
         *frames = halFrames;
         *time = halTime;
diff --git a/audio/2.0/default/StreamOut.cpp b/audio/2.0/default/StreamOut.cpp
index e48497f..290d0b1 100644
--- a/audio/2.0/default/StreamOut.cpp
+++ b/audio/2.0/default/StreamOut.cpp
@@ -487,16 +487,17 @@
 Result StreamOut::getPresentationPositionImpl(audio_stream_out_t* stream,
                                               uint64_t* frames,
                                               TimeSpec* timeStamp) {
+    // Don't logspam on EINVAL--it's normal for get_presentation_position
+    // to return it sometimes. EAGAIN may be returned by A2DP audio HAL
+    // implementation. ENODATA can also be reported while the writer is
+    // continuously querying it, but the stream has been stopped.
+    static const std::vector<int> ignoredErrors{EINVAL, EAGAIN, ENODATA};
     Result retval(Result::NOT_SUPPORTED);
     if (stream->get_presentation_position == NULL) return retval;
     struct timespec halTimeStamp;
-    retval = Stream::analyzeStatus(
-        "get_presentation_position",
-        stream->get_presentation_position(stream, frames, &halTimeStamp),
-        // Don't logspam on EINVAL--it's normal for get_presentation_position
-        // to return it sometimes. EAGAIN may be returned by A2DP audio HAL
-        // implementation.
-        EINVAL, EAGAIN);
+    retval = Stream::analyzeStatus("get_presentation_position",
+                                   stream->get_presentation_position(stream, frames, &halTimeStamp),
+                                   ignoredErrors);
     if (retval == Result::OK) {
         timeStamp->tvSec = halTimeStamp.tv_sec;
         timeStamp->tvNSec = halTimeStamp.tv_nsec;
diff --git a/audio/2.0/vts/functional/AudioPrimaryHidlHalTest.cpp b/audio/2.0/vts/functional/AudioPrimaryHidlHalTest.cpp
index 8ddbad4..90fec01 100644
--- a/audio/2.0/vts/functional/AudioPrimaryHidlHalTest.cpp
+++ b/audio/2.0/vts/functional/AudioPrimaryHidlHalTest.cpp
@@ -746,12 +746,12 @@
 TEST_IO_STREAM(
     GetSampleRate,
     "Check that the stream sample rate == the one it was opened with",
-    ASSERT_EQ(audioConfig.sampleRateHz, extract(stream->getSampleRate())))
+    stream->getSampleRate())
 
 TEST_IO_STREAM(
     GetChannelMask,
     "Check that the stream channel mask == the one it was opened with",
-    ASSERT_EQ(audioConfig.channelMask, extract(stream->getChannelMask())))
+    stream->getChannelMask())
 
 TEST_IO_STREAM(GetFormat,
                "Check that the stream format == the one it was opened with",
@@ -853,25 +853,17 @@
     areAudioPatchesSupported() ? doc::partialTest("Audio patches are supported")
                                : testSetDevice(stream.get(), address))
 
-static void testGetAudioProperties(IStream* stream,
-                                   AudioConfig expectedConfig) {
+static void testGetAudioProperties(IStream* stream) {
     uint32_t sampleRateHz;
     AudioChannelMask mask;
     AudioFormat format;
-
     stream->getAudioProperties(returnIn(sampleRateHz, mask, format));
-
-    // FIXME: the qcom hal it does not currently negotiate the sampleRate &
-    // channel mask
-    EXPECT_EQ(expectedConfig.sampleRateHz, sampleRateHz);
-    EXPECT_EQ(expectedConfig.channelMask, mask);
-    EXPECT_EQ(expectedConfig.format, format);
 }
 
 TEST_IO_STREAM(
     GetAudioProperties,
     "Check that the stream audio properties == the ones it was opened with",
-    testGetAudioProperties(stream.get(), audioConfig))
+    testGetAudioProperties(stream.get()))
 
 static void testConnectedState(IStream* stream) {
     DeviceAddress address = {};
diff --git a/compatibility_matrix.xml b/compatibility_matrix.xml
index 0f42a02..9603bd6 100644
--- a/compatibility_matrix.xml
+++ b/compatibility_matrix.xml
@@ -18,10 +18,18 @@
     <hal format="hidl" optional="true">
         <name>android.hardware.automotive.evs</name>
         <version>1.0</version>
+        <interface>
+            <name>IEvsEnumerator</name>
+            <instance>default</instance>
+        </interface>
     </hal>
     <hal format="hidl" optional="true">
         <name>android.hardware.automotive.vehicle</name>
-        <version>2.1</version>
+        <version>2.0</version>
+        <interface>
+            <name>IVehicle</name>
+            <instance>default</instance>
+        </interface>
     </hal>
     <hal format="hidl" optional="true">
         <name>android.hardware.biometrics.fingerprint</name>
@@ -48,6 +56,14 @@
         </interface>
     </hal>
     <hal format="hidl" optional="true">
+        <name>android.hardware.broadcastradio</name>
+        <version>1.0</version>
+        <interface>
+            <name>IBroadcastRadioFactory</name>
+            <instance>default</instance>
+        </interface>
+    </hal>
+    <hal format="hidl" optional="true">
         <name>android.hardware.camera.provider</name>
         <version>2.4</version>
         <interface>
@@ -132,6 +148,14 @@
         </interface>
     </hal>
     <hal format="hidl" optional="true">
+        <name>android.hardware.health</name>
+        <version>1.0</version>
+        <interface>
+            <name>IHealth</name>
+            <instance>default</instance>
+        </interface>
+    </hal>
+    <hal format="hidl" optional="true">
         <name>android.hardware.ir</name>
         <version>1.0</version>
     </hal>
@@ -158,6 +182,10 @@
             <name>IOmx</name>
             <instance>default</instance>
         </interface>
+        <interface>
+            <name>IOmxStore</name>
+            <instance>default</instance>
+        </interface>
     </hal>
     <hal format="hidl" optional="true">
         <name>android.hardware.memtrack</name>
@@ -240,6 +268,22 @@
         </interface>
     </hal>
     <hal format="hidl" optional="true">
+        <name>android.hardware.tv.cec</name>
+        <version>1.0</version>
+        <interface>
+            <name>IHdmiCec</name>
+            <instance>default</instance>
+        </interface>
+    </hal>
+    <hal format="hidl" optional="true">
+        <name>android.hardware.tv.input</name>
+        <version>1.0</version>
+        <interface>
+            <name>ITvInput</name>
+            <instance>default</instance>
+        </interface>
+    </hal>
+    <hal format="hidl" optional="true">
         <name>android.hardware.usb</name>
         <version>1.0</version>
         <interface>
@@ -275,4 +319,15 @@
             <instance>default</instance>
         </interface>
     </hal>
+    <hal format="hidl" optional="true">
+        <name>android.hardware.wifi.supplicant</name>
+        <version>1.0</version>
+        <interface>
+            <name>ISupplicant</name>
+            <instance>default</instance>
+        </interface>
+    </hal>
+    <kernel version="4.9.0" />
+    <kernel version="4.4.0" />
+    <kernel version="3.18.0" />
 </compatibility-matrix>
diff --git a/graphics/allocator/2.0/default/service.cpp b/graphics/allocator/2.0/default/service.cpp
index a43740c..99f462c 100644
--- a/graphics/allocator/2.0/default/service.cpp
+++ b/graphics/allocator/2.0/default/service.cpp
@@ -24,5 +24,5 @@
 using android::hardware::defaultPassthroughServiceImplementation;
 
 int main() {
-    return defaultPassthroughServiceImplementation<IAllocator>();
+    return defaultPassthroughServiceImplementation<IAllocator>(4);
 }
diff --git a/renderscript/1.0/vts/functional/VtsHalRenderscriptV1_0TargetTest.cpp b/renderscript/1.0/vts/functional/VtsHalRenderscriptV1_0TargetTest.cpp
index f505d01..2670b8d 100644
--- a/renderscript/1.0/vts/functional/VtsHalRenderscriptV1_0TargetTest.cpp
+++ b/renderscript/1.0/vts/functional/VtsHalRenderscriptV1_0TargetTest.cpp
@@ -28,6 +28,7 @@
 }
 
 void RenderscriptHidlTest::TearDown() {
+    context->contextFinish();
     context->contextDestroy();
 }
 
diff --git a/wifi/1.0/vts/functional/wifi_hidl_test_utils.cpp b/wifi/1.0/vts/functional/wifi_hidl_test_utils.cpp
index fefbd79..e4382bc 100644
--- a/wifi/1.0/vts/functional/wifi_hidl_test_utils.cpp
+++ b/wifi/1.0/vts/functional/wifi_hidl_test_utils.cpp
@@ -36,6 +36,9 @@
 using ::android::hardware::hidl_vec;
 
 namespace {
+constexpr uint32_t kHalStartRetryMaxCount = 5;
+constexpr uint32_t kHalStartRetryIntervalInMs = 2;
+
 bool findAnyModeSupportingIfaceType(
     IfaceType desired_type, const std::vector<IWifiChip::ChipMode>& modes,
     ChipModeId* mode_id) {
@@ -92,7 +95,15 @@
     if (!wifi.get()) {
         return nullptr;
     }
-    if (HIDL_INVOKE(wifi, start).code != WifiStatusCode::SUCCESS) {
+    uint32_t retry_count = 0;
+    auto status = HIDL_INVOKE(wifi, start);
+    while (retry_count < kHalStartRetryMaxCount &&
+           status.code == WifiStatusCode::ERROR_NOT_AVAILABLE) {
+        retry_count++;
+        usleep(kHalStartRetryIntervalInMs * 1000);
+        status = HIDL_INVOKE(wifi, start);
+    }
+    if (status.code != WifiStatusCode::SUCCESS) {
         return nullptr;
     }
     const auto& status_and_chip_ids = HIDL_INVOKE(wifi, getChipIds);