Merge "Camera: Adjust VTS tests for zoom override latency" into udc-dev
diff --git a/automotive/audiocontrol/aidl/vts/VtsHalAudioControlTargetTest.cpp b/automotive/audiocontrol/aidl/vts/VtsHalAudioControlTargetTest.cpp
index f4e3b5a..4e7e963 100644
--- a/automotive/audiocontrol/aidl/vts/VtsHalAudioControlTargetTest.cpp
+++ b/automotive/audiocontrol/aidl/vts/VtsHalAudioControlTargetTest.cpp
@@ -53,17 +53,25 @@
 namespace audiohalcommon = android::hardware::audio::common;
 namespace audiomediacommon = android::media::audio::common;
 
+namespace {
+constexpr int32_t kAidlVersionThree = 3;
+}
+
 class AudioControlAidl : public testing::TestWithParam<std::string> {
   public:
     virtual void SetUp() override {
         audioControl = android::waitForDeclaredService<IAudioControl>(String16(GetParam().c_str()));
         ASSERT_NE(audioControl, nullptr);
+        aidlVersion = audioControl->getInterfaceVersion();
     }
 
     void TearDown() override { audioControl = nullptr; }
 
+    bool isAidlVersionAtleast(int version) const { return aidlVersion >= version; }
+
     sp<IAudioControl> audioControl;
     int32_t capabilities;
+    int32_t aidlVersion;
 };
 
 TEST_P(AudioControlAidl, OnSetFadeTowardsFront) {
@@ -250,6 +258,11 @@
 
 TEST_P(AudioControlAidl, RegisterModuleChangeCallbackTwiceThrowsException) {
     ALOGI("Register Module change callback test");
+    if (!isAidlVersionAtleast(kAidlVersionThree)) {
+        GTEST_SKIP() << "Device does not support the new APIs for module change callback";
+        return;
+    }
+
     // make sure no stale callbacks.
     audioControl->clearModuleChangeCallback();
 
@@ -269,6 +282,11 @@
 
 TEST_P(AudioControlAidl, RegisterModuleChangeNullCallbackThrowsException) {
     ALOGI("Register Module change callback with nullptr test");
+    if (!isAidlVersionAtleast(kAidlVersionThree)) {
+        GTEST_SKIP() << "Device does not support the new APIs for module change callback";
+        return;
+    }
+
     auto status = audioControl->setModuleChangeCallback(nullptr);
     EXPECT_THAT(status.exceptionCode(),
                 AnyOf(Eq(Status::EX_ILLEGAL_ARGUMENT), Eq(Status::EX_UNSUPPORTED_OPERATION)));
diff --git a/compatibility_matrices/compatibility_matrix.8.xml b/compatibility_matrices/compatibility_matrix.8.xml
index 4ac95f5..c04a499 100644
--- a/compatibility_matrices/compatibility_matrix.8.xml
+++ b/compatibility_matrices/compatibility_matrix.8.xml
@@ -345,6 +345,7 @@
             <name>IRemotelyProvisionedComponent</name>
             <instance>default</instance>
             <instance>strongbox</instance>
+            <instance>widevine</instance>
         </interface>
     </hal>
     <hal format="aidl" optional="true">
diff --git a/security/keymint/aidl/vts/functional/AttestKeyTest.cpp b/security/keymint/aidl/vts/functional/AttestKeyTest.cpp
index c035f19..a868c96 100644
--- a/security/keymint/aidl/vts/functional/AttestKeyTest.cpp
+++ b/security/keymint/aidl/vts/functional/AttestKeyTest.cpp
@@ -80,7 +80,13 @@
         return "";
     }
 
-    return ::android::base::Trim(out[0]);
+    string imei = ::android::base::Trim(out[0]);
+    if (imei.compare("null") == 0) {
+        LOG(ERROR) << "Error in getting IMEI from Telephony service: value is null. Cmd: " << cmd;
+        return "";
+    }
+
+    return imei;
 }
 
 }  // namespace
@@ -972,7 +978,7 @@
 
     // Skip the test if there is no second IMEI exists.
     string second_imei = get_imei(1);
-    if (second_imei.empty() || second_imei.compare("null") == 0) {
+    if (second_imei.empty()) {
         GTEST_SKIP() << "Test not applicable as there is no second IMEI";
     }
 
@@ -1050,13 +1056,13 @@
 
     // Skip the test if there is no first IMEI exists.
     string imei = get_imei(0);
-    if (imei.empty() || imei.compare("null") == 0) {
+    if (imei.empty()) {
         GTEST_SKIP() << "Test not applicable as there is no first IMEI";
     }
 
     // Skip the test if there is no second IMEI exists.
     string second_imei = get_imei(1);
-    if (second_imei.empty() || second_imei.compare("null") == 0) {
+    if (second_imei.empty()) {
         GTEST_SKIP() << "Test not applicable as there is no second IMEI";
     }
 
diff --git a/tv/input/aidl/android/hardware/tv/input/ITvInput.aidl b/tv/input/aidl/android/hardware/tv/input/ITvInput.aidl
index cbaf066..c63e0ac 100644
--- a/tv/input/aidl/android/hardware/tv/input/ITvInput.aidl
+++ b/tv/input/aidl/android/hardware/tv/input/ITvInput.aidl
@@ -98,6 +98,11 @@
      * detected from the stream based on whether or not they are enabled by
      * {@link #setTvMessageEnabled(int, int, TvMessageEventType, boolean)}.
      *
+     * This queue is expected to already contain the message data before calling
+     * {@link android.hardware.tv.input.ITvInputCallback#notifyTvMessageEvent}.
+     * The HAL implementation is expected to have already created the queue
+     * before the notification callback is called for the first time.
+     *
      * @param deviceId The ID of the device that contains the stream to get the queue for.
      * @param streamId THe ID of the stream to get the queue for.
      * @return The descriptor of the TV message queue.
diff --git a/tv/input/aidl/android/hardware/tv/input/ITvInputCallback.aidl b/tv/input/aidl/android/hardware/tv/input/ITvInputCallback.aidl
index 2c7e32f..a3afd41 100644
--- a/tv/input/aidl/android/hardware/tv/input/ITvInputCallback.aidl
+++ b/tv/input/aidl/android/hardware/tv/input/ITvInputCallback.aidl
@@ -39,6 +39,11 @@
      * the device that sent the message should be contained in
      * {@link android.hardware.tv.input.TvMessage#groupId}
      *
+     * Invoking this callback for the first time immediately triggers
+     * {@link android.hardware.tv.input.ITvInput#getTvMessageQueueDesc}. It is
+     * expected for the queue to be ready with
+     * the relevant messages for the event before this callback is called.
+     *
      * @param event Event passed to the client.
      */
     void notifyTvMessageEvent(in TvMessageEvent event);
diff --git a/tv/input/aidl/default/TvInput.cpp b/tv/input/aidl/default/TvInput.cpp
index c986ef1..2ee8bcf 100644
--- a/tv/input/aidl/default/TvInput.cpp
+++ b/tv/input/aidl/default/TvInput.cpp
@@ -68,7 +68,13 @@
 ::ndk::ScopedAStatus TvInput::setTvMessageEnabled(int32_t deviceId, int32_t streamId,
                                                   TvMessageEventType in_type, bool enabled) {
     ALOGV("%s", __FUNCTION__);
-    // TODO: Implement this
+
+    if (mStreamConfigs.count(deviceId) == 0) {
+        ALOGW("Device with id %d isn't available", deviceId);
+        return ::ndk::ScopedAStatus::fromServiceSpecificError(STATUS_INVALID_ARGUMENTS);
+    }
+
+    mTvMessageEventEnabled[deviceId][streamId][in_type] = enabled;
     return ::ndk::ScopedAStatus::ok();
 }
 
@@ -76,7 +82,10 @@
         MQDescriptor<int8_t, SynchronizedReadWrite>* out_queue, int32_t in_deviceId,
         int32_t in_streamId) {
     ALOGV("%s", __FUNCTION__);
-    // TODO: Implement this
+    if (mStreamConfigs.count(in_deviceId) == 0) {
+        ALOGW("Device with id %d isn't available", in_deviceId);
+        return ::ndk::ScopedAStatus::fromServiceSpecificError(STATUS_INVALID_ARGUMENTS);
+    }
     return ::ndk::ScopedAStatus::ok();
 }
 
diff --git a/tv/input/aidl/default/TvInput.h b/tv/input/aidl/default/TvInput.h
index 92e7d4c..5776961 100644
--- a/tv/input/aidl/default/TvInput.h
+++ b/tv/input/aidl/default/TvInput.h
@@ -22,6 +22,7 @@
 #include <aidl/android/hardware/tv/input/TvMessageEventType.h>
 #include <fmq/AidlMessageQueue.h>
 #include <map>
+#include <unordered_map>
 #include "TvInputDeviceInfoWrapper.h"
 #include "TvStreamConfigWrapper.h"
 
@@ -38,6 +39,9 @@
 namespace tv {
 namespace input {
 
+using TvMessageEnabledMap = std::unordered_map<
+        int32_t, std::unordered_map<int32_t, std::unordered_map<TvMessageEventType, bool>>>;
+
 class TvInput : public BnTvInput {
   public:
     TvInput();
@@ -53,7 +57,6 @@
     ::ndk::ScopedAStatus openStream(int32_t in_deviceId, int32_t in_streamId,
                                     NativeHandle* _aidl_return) override;
     ::ndk::ScopedAStatus closeStream(int32_t in_deviceId, int32_t in_streamId) override;
-
     void init();
 
   private:
@@ -62,6 +65,7 @@
     shared_ptr<ITvInputCallback> mCallback;
     map<int32_t, shared_ptr<TvInputDeviceInfoWrapper>> mDeviceInfos;
     map<int32_t, map<int32_t, shared_ptr<TvStreamConfigWrapper>>> mStreamConfigs;
+    TvMessageEnabledMap mTvMessageEventEnabled;
 };
 
 }  // namespace input
diff --git a/tv/input/aidl/vts/functional/VtsHalTvInputTargetTest.cpp b/tv/input/aidl/vts/functional/VtsHalTvInputTargetTest.cpp
index a2415b4..6433305 100644
--- a/tv/input/aidl/vts/functional/VtsHalTvInputTargetTest.cpp
+++ b/tv/input/aidl/vts/functional/VtsHalTvInputTargetTest.cpp
@@ -259,8 +259,11 @@
         return;
     }
     int32_t device_id = stream_config_.keyAt(indices[0]);
-    int32_t stream_id = stream_config_.valueAt(indices[0])[0].streamId;
-
+    vector<TvStreamConfig> streamConfigs = stream_config_.valueAt(indices[0]);
+    if (streamConfigs.empty()) {
+        return;
+    }
+    int32_t stream_id = streamConfigs[0].streamId;
     NativeHandle handle;
 
     ALOGD("OpenAnOpenedStreamsTest: open stream, device_id=%d, stream_id=%d", device_id, stream_id);
@@ -291,7 +294,11 @@
         return;
     }
     int32_t device_id = stream_config_.keyAt(indices[0]);
-    int32_t stream_id = stream_config_.valueAt(indices[0])[0].streamId;
+    vector<TvStreamConfig> streamConfigs = stream_config_.valueAt(indices[0]);
+    if (streamConfigs.empty()) {
+        return;
+    }
+    int32_t stream_id = streamConfigs[0].streamId;
 
     ALOGD("CloseStreamBeforeOpenTest: close stream, device_id=%d, stream_id=%d", device_id,
           stream_id);
@@ -299,6 +306,43 @@
                 ITvInput::STATUS_INVALID_STATE);
 }
 
+TEST_P(TvInputAidlTest, SetTvMessageEnabledTest) {
+    unique_lock<mutex> lock(mutex_);
+
+    updateAllStreamConfigurations();
+    vector<size_t> indices = getConfigIndices();
+    if (indices.empty()) {
+        return;
+    }
+    int32_t device_id = stream_config_.keyAt(indices[0]);
+    vector<TvStreamConfig> streamConfigs = stream_config_.valueAt(indices[0]);
+    if (streamConfigs.empty()) {
+        return;
+    }
+    int32_t stream_id = streamConfigs[0].streamId;
+    ALOGD("SetTvMessageEnabledTest: device_id=%d, stream_id=%d", device_id, stream_id);
+    tv_input_->setTvMessageEnabled(device_id, stream_id, TvMessageEventType::WATERMARK, true);
+}
+
+TEST_P(TvInputAidlTest, GetTvMessageQueueTest) {
+    unique_lock<mutex> lock(mutex_);
+
+    updateAllStreamConfigurations();
+    vector<size_t> indices = getConfigIndices();
+    if (indices.empty()) {
+        return;
+    }
+    int32_t device_id = stream_config_.keyAt(indices[0]);
+    vector<TvStreamConfig> streamConfigs = stream_config_.valueAt(indices[0]);
+    if (streamConfigs.empty()) {
+        return;
+    }
+    int32_t stream_id = streamConfigs[0].streamId;
+    ALOGD("GetTvMessageQueueTest: device_id=%d, stream_id=%d", device_id, stream_id);
+    MQDescriptor<int8_t, SynchronizedReadWrite> queue;
+    tv_input_->getTvMessageQueueDesc(&queue, device_id, stream_id);
+}
+
 INSTANTIATE_TEST_SUITE_P(PerInstance, TvInputAidlTest,
                          testing::ValuesIn(android::getAidlHalInstanceNames(ITvInput::descriptor)),
                          android::PrintInstanceNameToString);
diff --git a/tv/input/aidl/vts/functional/VtsHalTvInputTargetTest.h b/tv/input/aidl/vts/functional/VtsHalTvInputTargetTest.h
index 20d9227..832b27c 100644
--- a/tv/input/aidl/vts/functional/VtsHalTvInputTargetTest.h
+++ b/tv/input/aidl/vts/functional/VtsHalTvInputTargetTest.h
@@ -37,6 +37,7 @@
 using namespace std;
 using ::aidl::android::hardware::common::NativeHandle;
 using ::aidl::android::hardware::common::fmq::MQDescriptor;
+using ::aidl::android::hardware::common::fmq::SynchronizedReadWrite;
 using ::android::AidlMessageQueue;
 
 #define WAIT_FOR_EVENT_TIMEOUT 5
diff --git a/wifi/aidl/vts/functional/wifi_sta_iface_aidl_test.cpp b/wifi/aidl/vts/functional/wifi_sta_iface_aidl_test.cpp
index 288f20a..f12d873 100644
--- a/wifi/aidl/vts/functional/wifi_sta_iface_aidl_test.cpp
+++ b/wifi/aidl/vts/functional/wifi_sta_iface_aidl_test.cpp
@@ -24,6 +24,7 @@
 #include <android/binder_status.h>
 #include <binder/IServiceManager.h>
 #include <binder/ProcessState.h>
+#include <cutils/properties.h>
 
 #include "wifi_aidl_test_utils.h"
 
@@ -98,16 +99,23 @@
  */
 // @VsrTest = 5.3.12
 TEST_P(WifiStaIfaceAidlTest, CheckApfIsSupported) {
-    // It is not required to check the vendor API level is at least U here
-    // because the Wi-Fi AIDL interface is launched with Android U(VSR-14).
-    // TODO: Add wavier list to the chipsets that doesn't support APF.
-    EXPECT_TRUE(isFeatureSupported(IWifiStaIface::FeatureSetMask::APF));
-    StaApfPacketFilterCapabilities apf_caps = {};
-    EXPECT_TRUE(wifi_sta_iface_->getApfPacketFilterCapabilities(&apf_caps).isOk());
-    // The APF version must be 4 and the usable memory must be at least
-    // 1024 bytes.
-    EXPECT_EQ(apf_caps.version, 4);
-    EXPECT_GE(apf_caps.maxLength, 1024);
+    int vendor_api_level = property_get_int32("ro.vendor.api_level", 0);
+    // Before VSR 14, APF support is optional.
+    if (vendor_api_level < __ANDROID_API_U__) {
+        if (!isFeatureSupported(IWifiStaIface::FeatureSetMask::APF)) {
+            GTEST_SKIP() << "APF packet filter capabilities are not supported.";
+        }
+        StaApfPacketFilterCapabilities apf_caps = {};
+        EXPECT_TRUE(wifi_sta_iface_->getApfPacketFilterCapabilities(&apf_caps).isOk());
+    } else {
+        EXPECT_TRUE(isFeatureSupported(IWifiStaIface::FeatureSetMask::APF));
+        StaApfPacketFilterCapabilities apf_caps = {};
+        EXPECT_TRUE(wifi_sta_iface_->getApfPacketFilterCapabilities(&apf_caps).isOk());
+        // The APF version must be 4 and the usable memory must be at least
+        // 1024 bytes.
+        EXPECT_EQ(apf_caps.version, 4);
+        EXPECT_GE(apf_caps.maxLength, 1024);
+    }
 }
 
 /*