Merge "Add VtsCan* to vts." into rvc-dev
diff --git a/automotive/audiocontrol/2.0/types.hal b/automotive/audiocontrol/2.0/types.hal
index 65b0988..80d9ee1 100644
--- a/automotive/audiocontrol/2.0/types.hal
+++ b/automotive/audiocontrol/2.0/types.hal
@@ -19,7 +19,7 @@
 /**
  * Changes in audio focus that can be experienced
  */
-enum AudioFocusChange : uint32_t {
+enum AudioFocusChange : int32_t {
     NONE = 0,
     GAIN = 1,
     GAIN_TRANSIENT = 2,
diff --git a/automotive/evs/1.1/IEvsCamera.hal b/automotive/evs/1.1/IEvsCamera.hal
index 38e6c42..3e7ac2b 100644
--- a/automotive/evs/1.1/IEvsCamera.hal
+++ b/automotive/evs/1.1/IEvsCamera.hal
@@ -215,4 +215,22 @@
      */
     setExtendedInfo_1_1(uint32_t opaqueIdentifier, vec<uint8_t> opaqueValue)
         generates (EvsResult result);
+
+    /**
+     * Import external buffers to capture frames
+     *
+     * This API must be called with a physical camera device identifier.
+     *
+     * @param  buffers  A list of buffers allocated by the caller.  EvsCamera
+     *                  will use these buffers to capture frames, in addition to
+     *                  other buffers already in its buffer pool.
+     * @return result   EvsResult::OK if it succeeds to import buffers.
+     *                  EvsResult::UNDERLYING_SERVICE_ERROR if this is called
+     *                  for logical camera devices or EVS fails to import
+     *                  buffers.
+     *         delta    The amount of buffer pool size changes after importing
+     *                  given buffers.
+     */
+    importExternalBuffers(vec<BufferDesc> buffers)
+        generates (EvsResult result, int32_t delta);
 };
diff --git a/automotive/evs/1.1/default/EvsCamera.cpp b/automotive/evs/1.1/default/EvsCamera.cpp
index 5196c95..0e69ed4 100644
--- a/automotive/evs/1.1/default/EvsCamera.cpp
+++ b/automotive/evs/1.1/default/EvsCamera.cpp
@@ -354,6 +354,14 @@
 }
 
 
+Return<void>
+EvsCamera::importExternalBuffers(const hidl_vec<BufferDesc_1_1>& /* buffers */,
+                                 importExternalBuffers_cb _hidl_cb) {
+    ALOGW("%s is not implemented yet.", __FUNCTION__);
+    _hidl_cb(EvsResult::UNDERLYING_SERVICE_ERROR, 0);
+    return {};
+}
+
 
 bool EvsCamera::setAvailableFrames_Locked(unsigned bufferCount) {
     if (bufferCount < 1) {
diff --git a/automotive/evs/1.1/default/EvsCamera.h b/automotive/evs/1.1/default/EvsCamera.h
index 0fa83b4..6163a34 100644
--- a/automotive/evs/1.1/default/EvsCamera.h
+++ b/automotive/evs/1.1/default/EvsCamera.h
@@ -82,6 +82,8 @@
                                           const hidl_vec<uint8_t>& opaqueValue) override;
     Return<void>      getExtendedInfo_1_1(uint32_t opaqueIdentifier,
                                           getExtendedInfo_1_1_cb _hidl_cb) override;
+    Return<void>      importExternalBuffers(const hidl_vec<BufferDesc_1_1>& buffers,
+                                            importExternalBuffers_cb _hidl_cb) override;
 
     static sp<EvsCamera> Create(const char *deviceName);
     static sp<EvsCamera> Create(const char *deviceName,
diff --git a/automotive/evs/1.1/types.hal b/automotive/evs/1.1/types.hal
index b34e7e7..1f69f09 100644
--- a/automotive/evs/1.1/types.hal
+++ b/automotive/evs/1.1/types.hal
@@ -70,6 +70,9 @@
      */
     int64_t timestamp;
 
+    /**
+     * Frame metadata.  This is opaque to EVS manager.
+     */
     vec<uint8_t> metadata;
 };
 
diff --git a/automotive/evs/1.1/vts/functional/VtsHalEvsV1_1TargetTest.cpp b/automotive/evs/1.1/vts/functional/VtsHalEvsV1_1TargetTest.cpp
index 368a6d4..6a386c3 100644
--- a/automotive/evs/1.1/vts/functional/VtsHalEvsV1_1TargetTest.cpp
+++ b/automotive/evs/1.1/vts/functional/VtsHalEvsV1_1TargetTest.cpp
@@ -50,6 +50,8 @@
 #include <system/camera_metadata.h>
 #include <ui/DisplayConfig.h>
 #include <ui/DisplayState.h>
+#include <ui/GraphicBuffer.h>
+#include <ui/GraphicBufferAllocator.h>
 
 #include <gtest/gtest.h>
 #include <hidl/GtestPrinter.h>
@@ -66,6 +68,7 @@
 using ::android::sp;
 using ::android::wp;
 using ::android::hardware::camera::device::V3_2::Stream;
+using ::android::hardware::automotive::evs::V1_1::BufferDesc;
 using ::android::hardware::automotive::evs::V1_0::DisplayDesc;
 using ::android::hardware::automotive::evs::V1_0::DisplayState;
 using ::android::hardware::graphics::common::V1_0::PixelFormat;
@@ -2231,6 +2234,140 @@
 
 
 /*
+ * CameraStreamExternalBuffering:
+ * This is same with CameraStreamBuffering except frame buffers are allocated by
+ * the test client and then imported by EVS framework.
+ */
+TEST_P(EvsHidlTest, CameraStreamExternalBuffering) {
+    LOG(INFO) << "Starting CameraStreamExternalBuffering test";
+
+    // Arbitrary constant (should be > 1 and less than crazy)
+    static const unsigned int kBuffersToHold = 6;
+
+    // Get the camera list
+    loadCameraList();
+
+    // Using null stream configuration makes EVS uses the default resolution and
+    // output format.
+    Stream nullCfg = {};
+
+    // Acquire the graphics buffer allocator
+    android::GraphicBufferAllocator& alloc(android::GraphicBufferAllocator::get());
+    const auto usage = GRALLOC_USAGE_HW_TEXTURE |
+                       GRALLOC_USAGE_SW_READ_RARELY |
+                       GRALLOC_USAGE_SW_WRITE_OFTEN;
+    const auto format = HAL_PIXEL_FORMAT_RGBA_8888;
+    const auto width = 640;
+    const auto height = 360;
+
+    // Allocate buffers to use
+    hidl_vec<BufferDesc> buffers;
+    for (auto i = 0; i < kBuffersToHold; ++i) {
+        unsigned pixelsPerLine;
+        buffer_handle_t memHandle = nullptr;
+        android::status_t result = alloc.allocate(width,
+                                                  height,
+                                                  format,
+                                                  1,
+                                                  usage,
+                                                  &memHandle,
+                                                  &pixelsPerLine,
+                                                  0,
+                                                  "EvsApp");
+        if (result != android::NO_ERROR) {
+            LOG(ERROR) << __FUNCTION__ << " failed to allocate memory.";
+        } else {
+            BufferDesc buf;
+            AHardwareBuffer_Desc* pDesc =
+                reinterpret_cast<AHardwareBuffer_Desc *>(&buf.buffer.description);
+            pDesc->width = width;
+            pDesc->height = height;
+            pDesc->layers = 1;
+            pDesc->format = format;
+            pDesc->usage = usage;
+            pDesc->stride = pixelsPerLine;
+            buf.buffer.nativeHandle = memHandle;
+            buf.bufferId = i;   // Unique number to identify this buffer
+            buffers[i] = buf;
+        }
+    }
+
+    // Test each reported camera
+    for (auto&& cam: cameraInfo) {
+        bool isLogicalCam = false;
+        getPhysicalCameraIds(cam.v1.cameraId, isLogicalCam);
+
+        sp<IEvsCamera_1_1> pCam =
+            IEvsCamera_1_1::castFrom(pEnumerator->openCamera_1_1(cam.v1.cameraId, nullCfg))
+            .withDefault(nullptr);
+        ASSERT_NE(pCam, nullptr);
+
+        // Store a camera handle for a clean-up
+        activeCameras.push_back(pCam);
+
+        // Request to import buffers
+        EvsResult result = EvsResult::OK;
+        int delta = 0;
+        pCam->importExternalBuffers(buffers,
+                                    [&] (auto _result, auto _delta) {
+                                        result = _result;
+                                        delta = _delta;
+                                    });
+        if (isLogicalCam) {
+            EXPECT_EQ(result, EvsResult::UNDERLYING_SERVICE_ERROR);
+            continue;
+        }
+
+        EXPECT_EQ(result, EvsResult::OK);
+        EXPECT_GE(delta, 0);
+
+        // Set up a frame receiver object which will fire up its own thread.
+        sp<FrameHandler> frameHandler = new FrameHandler(pCam, cam,
+                                                         nullptr,
+                                                         FrameHandler::eNoAutoReturn);
+
+        // Start the camera's video stream
+        bool startResult = frameHandler->startStream();
+        ASSERT_TRUE(startResult);
+
+        // Check that the video stream stalls once we've gotten exactly the number of buffers
+        // we requested since we told the frameHandler not to return them.
+        sleep(1);   // 1 second should be enough for at least 5 frames to be delivered worst case
+        unsigned framesReceived = 0;
+        frameHandler->getFramesCounters(&framesReceived, nullptr);
+        ASSERT_EQ(kBuffersToHold, framesReceived) << "Stream didn't stall at expected buffer limit";
+
+
+        // Give back one buffer
+        bool didReturnBuffer = frameHandler->returnHeldBuffer();
+        EXPECT_TRUE(didReturnBuffer);
+
+        // Once we return a buffer, it shouldn't take more than 1/10 second to get a new one
+        // filled since we require 10fps minimum -- but give a 10% allowance just in case.
+        usleep(110 * kMillisecondsToMicroseconds);
+        frameHandler->getFramesCounters(&framesReceived, nullptr);
+        EXPECT_EQ(kBuffersToHold+1, framesReceived) << "Stream should've resumed";
+
+        // Even when the camera pointer goes out of scope, the FrameHandler object will
+        // keep the stream alive unless we tell it to shutdown.
+        // Also note that the FrameHandle and the Camera have a mutual circular reference, so
+        // we have to break that cycle in order for either of them to get cleaned up.
+        frameHandler->shutdown();
+
+        // Explicitly release the camera
+        pEnumerator->closeCamera(pCam);
+        activeCameras.clear();
+    }
+
+    // Release buffers
+    for (auto& b : buffers) {
+        alloc.free(b.buffer.nativeHandle);
+    }
+    buffers.resize(0);
+}
+
+
+/*
  * UltrasonicsArrayOpenClean:
  * Opens each ultrasonics arrays reported by the enumerator and then explicitly closes it via a
  * call to closeUltrasonicsArray. Then repeats the test to ensure all ultrasonics arrays
diff --git a/boot/1.1/vts/functional/Android.bp b/boot/1.1/vts/functional/Android.bp
index 49ea09a..9f0c74a 100644
--- a/boot/1.1/vts/functional/Android.bp
+++ b/boot/1.1/vts/functional/Android.bp
@@ -23,6 +23,8 @@
         "android.hardware.boot@1.1",
         "libgmock",
     ],
-    test_suites: ["device-tests"],
+    test_suites: [
+        "device-tests",
+        "vts",
+    ],
 }
-
diff --git a/current.txt b/current.txt
index 183d006..2677eb1 100644
--- a/current.txt
+++ b/current.txt
@@ -635,20 +635,20 @@
 4bc4e8087f5c389f013370ed68bc8a1a29cb2f203237937697f35e005a5ad0b4 android.hardware.automotive.audiocontrol@2.0::IAudioControl
 37ef585d6687cb31e35c67ab456140d70edba9c4333ce5a6ddd70e636e985773 android.hardware.automotive.audiocontrol@2.0::ICloseHandle
 3cf3e5e48ba2642052bbccc1aa4e8bb142933ac960ff40eeedd16e4fe452e7a5 android.hardware.automotive.audiocontrol@2.0::IFocusListener
-d06fc14b325beeef06bd39de8f178f490d9e9095255626866071aab42be1fc40 android.hardware.automotive.audiocontrol@2.0::types
+44c03f3341939524b5f5acb6680f8a91924d02e335a32840d56597616db7f1ea android.hardware.automotive.audiocontrol@2.0::types
 949a2582c9efa3f6f631f56120eae3f02313f251dbf9246c327e419cdf0652a2 android.hardware.automotive.can@1.0::ICanBus
 43cddb1907a30343bced68946884416ea25ab14ae2df4709357528b2bedba84c android.hardware.automotive.can@1.0::ICanController
 272e826492b27b0dbdeda408e84a41ae43e98f29e57995b6452ded270aae4eee android.hardware.automotive.can@1.0::ICanErrorListener
 07e387bd8bc0e4df5f372515ed960a0b1ae74ea7231d4490a0bb09b07046e4f1 android.hardware.automotive.can@1.0::ICanMessageListener
 2166132d6c247630a193217b4338074f634d6691b1ed6796cb26b3812e90b46e android.hardware.automotive.can@1.0::ICloseHandle
 83355471a3b6d7f777d3f129714585ffb77d9b6f8a3d0365741969631efb81b2 android.hardware.automotive.can@1.0::types
-8afd93d525cf17818e3d46e72f30debeaacc6fb166a59a8e25272f2baeb0ef7a android.hardware.automotive.evs@1.1::IEvsCamera
+50bfbeef15d7451bd07e4ad460fbcb7ff80521b89bb8049035c0d458b4125ae4 android.hardware.automotive.evs@1.1::IEvsCamera
 89ff5ab18b3069f21a57f559b290caa50670f0ae1b74178f630183aef39b496b android.hardware.automotive.evs@1.1::IEvsCameraStream
 4c67f768067a0aceac74381f6f62e778ab3b6a18f47db3c9b98c58190ef5619d android.hardware.automotive.evs@1.1::IEvsDisplay
 87958d728d7c0ee9b9391ab4a072b097914921a7b38f7dc3df427f933a5b528e android.hardware.automotive.evs@1.1::IEvsEnumerator
 f53b4e8de6209c6d0fa9036005671b34a2f98328b51423d3a5137a43bf42c84d android.hardware.automotive.evs@1.1::IEvsUltrasonicsArray
 0460bacbde906a846a3d71b2b7b33d6927cac3ff072e523ffac7853577464406 android.hardware.automotive.evs@1.1::IEvsUltrasonicsArrayStream
-8a156203892de3cfa47baaccabef3c45b3315cae93b332357598d60896b1ac7f android.hardware.automotive.evs@1.1::types
+3e374b5c4777f959f62a320abb3b9edca8874e24e383dbb19c66d224f151b363 android.hardware.automotive.evs@1.1::types
 4e4904c4067dadae974ddf90351f362331dcd04bba1d890d313cc8ba91f68c15 android.hardware.automotive.sv@1.0::ISurroundView2dSession
 63336e9d03f545020ff2982ff76d9d8c44fa76ad476293b5ef6732cbbd71e61b android.hardware.automotive.sv@1.0::ISurroundView3dSession
 b7015428cd52ce8192d13bfcbf2c4455cda3727d57f2aac80d65a1747104f5ac android.hardware.automotive.sv@1.0::ISurroundViewService
diff --git a/graphics/composer/2.2/default/android.hardware.graphics.composer@2.2-service.rc b/graphics/composer/2.2/default/android.hardware.graphics.composer@2.2-service.rc
index 0d7e86f..efe6dad 100644
--- a/graphics/composer/2.2/default/android.hardware.graphics.composer@2.2-service.rc
+++ b/graphics/composer/2.2/default/android.hardware.graphics.composer@2.2-service.rc
@@ -1,6 +1,4 @@
 service vendor.hwcomposer-2-2 /vendor/bin/hw/android.hardware.graphics.composer@2.2-service
-    interface android.hardware.graphics.composer@2.1::IComposer default
-    interface android.hardware.graphics.composer@2.2::IComposer default
     class hal animation
     user system
     group graphics drmrpc
diff --git a/radio/1.3/vts/functional/radio_hidl_hal_api.cpp b/radio/1.3/vts/functional/radio_hidl_hal_api.cpp
index ca64305..1a01b28 100644
--- a/radio/1.3/vts/functional/radio_hidl_hal_api.cpp
+++ b/radio/1.3/vts/functional/radio_hidl_hal_api.cpp
@@ -16,6 +16,7 @@
 
 #include <radio_hidl_hal_utils_v1_3.h>
 #include <vector>
+#include "VtsCoreUtil.h"
 
 #define ASSERT_OK(ret) ASSERT_TRUE(ret.isOk())
 
@@ -25,6 +26,15 @@
 TEST_P(RadioHidlTest_v1_3, enableModem) {
     serial = GetRandomSerialNumber();
 
+    bool isMultiSimEnabled =
+            testing::checkSubstringInCommandOutput("getprop persist.radio.multisim.config",
+                                                   "dsds") ||
+            testing::checkSubstringInCommandOutput("getprop persist.radio.multisim.config", "tsts");
+    if (!isMultiSimEnabled) {
+        ALOGI("enableModem, no need to test in single SIM mode");
+        return;
+    }
+
     bool responseToggle = radioRsp_v1_3->enableModemResponseToggle;
     Return<void> res = radio_v1_3->enableModem(serial, true);
     ASSERT_OK(res);