From ac8e69620739891ddf53069c04d186cff03a32ea Mon Sep 17 00:00:00 2001 From: Hao Chen Date: Wed, 29 Mar 2023 11:20:56 -0700 Subject: [PATCH 1/2] Uprev the EVS AIDL NDK Version Bug: 262779341 Test: build Change-Id: I39d2e6b969db11b03d4e1fe929b19d65f75e72ff --- automotive/evs/aidl/impl/Android.bp | 2 +- automotive/evs/aidl/impl/default/Android.bp | 4 ++-- .../aidl/impl/default/include/EvsEnumerator.h | 3 +++ .../aidl/impl/default/src/EvsEnumerator.cpp | 20 +++++++++++++------ automotive/evs/aidl/vts/Android.bp | 9 ++++----- 5 files changed, 24 insertions(+), 14 deletions(-) diff --git a/automotive/evs/aidl/impl/Android.bp b/automotive/evs/aidl/impl/Android.bp index 0b51a0c1ff..fa44ebb4d9 100644 --- a/automotive/evs/aidl/impl/Android.bp +++ b/automotive/evs/aidl/impl/Android.bp @@ -22,7 +22,7 @@ cc_defaults { name: "EvsHalDefaults", defaults: ["android.hardware.graphics.common-ndk_static"], static_libs: [ - "android.hardware.automotive.evs-V1-ndk", + "android.hardware.automotive.evs-V2-ndk", "android.hardware.common-V2-ndk", ], shared_libs: [ diff --git a/automotive/evs/aidl/impl/default/Android.bp b/automotive/evs/aidl/impl/default/Android.bp index bf6c0be236..70c523b5fa 100644 --- a/automotive/evs/aidl/impl/default/Android.bp +++ b/automotive/evs/aidl/impl/default/Android.bp @@ -38,7 +38,7 @@ cc_binary { ], srcs: [ ":libgui_frame_event_aidl", - "src/*.cpp" + "src/*.cpp", ], shared_libs: [ "android.hardware.graphics.bufferqueue@1.0", @@ -61,7 +61,7 @@ cc_binary { ], static_libs: [ "android.frameworks.automotive.display-V1-ndk", - "android.hardware.automotive.evs-V1-ndk", + "android.hardware.automotive.evs-V2-ndk", "android.hardware.common-V2-ndk", "libaidlcommonsupport", "libcutils", diff --git a/automotive/evs/aidl/impl/default/include/EvsEnumerator.h b/automotive/evs/aidl/impl/default/include/EvsEnumerator.h index b11dd3ee80..259c266721 100644 --- a/automotive/evs/aidl/impl/default/include/EvsEnumerator.h +++ b/automotive/evs/aidl/impl/default/include/EvsEnumerator.h @@ -52,6 +52,7 @@ class EvsEnumerator final : public ::aidl::android::hardware::automotive::evs::B ndk::ScopedAStatus closeDisplay(const std::shared_ptr& obj) override; ndk::ScopedAStatus getDisplayIdList(std::vector* list) override; ndk::ScopedAStatus getDisplayState(evs::DisplayState* state) override; + ndk::ScopedAStatus getDisplayStateById(int32_t displayId, evs::DisplayState* state) override; ndk::ScopedAStatus registerStatusCallback( const std::shared_ptr& callback) override; ndk::ScopedAStatus openUltrasonicsArray( @@ -101,6 +102,8 @@ class EvsEnumerator final : public ::aidl::android::hardware::automotive::evs::B bool checkPermission(); void closeCamera_impl(const std::shared_ptr& pCamera, const std::string& cameraId); + ndk::ScopedAStatus getDisplayStateImpl(std::optional displayId, + evs::DisplayState* state); static bool qualifyCaptureDevice(const char* deviceName); static CameraRecord* findCameraById(const std::string& cameraId); diff --git a/automotive/evs/aidl/impl/default/src/EvsEnumerator.cpp b/automotive/evs/aidl/impl/default/src/EvsEnumerator.cpp index 6e2405deb5..5178958675 100644 --- a/automotive/evs/aidl/impl/default/src/EvsEnumerator.cpp +++ b/automotive/evs/aidl/impl/default/src/EvsEnumerator.cpp @@ -357,24 +357,32 @@ ScopedAStatus EvsEnumerator::closeDisplay(const std::shared_ptr& ob ScopedAStatus EvsEnumerator::getDisplayState(DisplayState* state) { LOG(DEBUG) << __FUNCTION__; + return getDisplayStateImpl(std::nullopt, state); +} + +ScopedAStatus EvsEnumerator::getDisplayStateById(int32_t displayId, DisplayState* state) { + LOG(DEBUG) << __FUNCTION__; + return getDisplayStateImpl(displayId, state); +} + +ScopedAStatus EvsEnumerator::getDisplayStateImpl(std::optional displayId, + DisplayState* state) { if (!checkPermission()) { *state = DisplayState::DEAD; return ScopedAStatus::fromServiceSpecificError( static_cast(EvsResult::PERMISSION_DENIED)); } - // TODO(b/262779341): For now we can just return the state of the 1st display. Need to update - // the API later. - const auto& all_displays = mutableActiveDisplays().getAllDisplays(); - // Do we still have a display object we think should be active? - if (all_displays.empty()) { + const auto display_search = displayId ? all_displays.find(*displayId) : all_displays.begin(); + + if (display_search == all_displays.end()) { *state = DisplayState::NOT_OPEN; return ScopedAStatus::fromServiceSpecificError(static_cast(EvsResult::OWNERSHIP_LOST)); } - std::shared_ptr pActiveDisplay = all_displays.begin()->second.displayWeak.lock(); + std::shared_ptr pActiveDisplay = display_search->second.displayWeak.lock(); if (pActiveDisplay) { return pActiveDisplay->getDisplayState(state); } else { diff --git a/automotive/evs/aidl/vts/Android.bp b/automotive/evs/aidl/vts/Android.bp index 5aa9501883..e50c913584 100644 --- a/automotive/evs/aidl/vts/Android.bp +++ b/automotive/evs/aidl/vts/Android.bp @@ -14,18 +14,17 @@ // limitations under the License. // -package{ +package { // See: http://go/android-license-faq // A large-scale-change added 'default_applicable_licenses' to import // all of the 'license_kinds' from "hardware_interfaces_license" // to get the below license kinds: // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses : ["hardware_interfaces_license"], + default_applicable_licenses: ["hardware_interfaces_license"], } cc_test { -name: - "VtsHalEvsTargetTest", + name: "VtsHalEvsTargetTest", srcs: [ "*.cpp", ], @@ -42,7 +41,7 @@ name: ], static_libs: [ "android.hardware.automotive.evs@common-default-lib", - "android.hardware.automotive.evs-V1-ndk", + "android.hardware.automotive.evs-V2-ndk", "android.hardware.common-V2-ndk", "libaidlcommonsupport", ], From be8193928534132838a0360a42259cafc8eb3aa5 Mon Sep 17 00:00:00 2001 From: Hao Chen Date: Wed, 29 Mar 2023 16:18:47 -0700 Subject: [PATCH 2/2] Add VTS testcases for getDisplayStateById Test: build Bug: 275626422 Change-Id: I27dfced8f0040e6604baeed37df7e12f5ec5d73d --- .../evs/aidl/vts/VtsHalEvsTargetTest.cpp | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/automotive/evs/aidl/vts/VtsHalEvsTargetTest.cpp b/automotive/evs/aidl/vts/VtsHalEvsTargetTest.cpp index 60adf93cdf..a6d99adae5 100644 --- a/automotive/evs/aidl/vts/VtsHalEvsTargetTest.cpp +++ b/automotive/evs/aidl/vts/VtsHalEvsTargetTest.cpp @@ -2273,6 +2273,10 @@ TEST_P(EvsAidlTest, DisplayStates) { DisplayState state; EXPECT_FALSE(mEnumerator->getDisplayState(&state).isOk()); } + for (const auto displayIdToQuery : displayIds) { + DisplayState state; + EXPECT_FALSE(mEnumerator->getDisplayStateById(displayIdToQuery, &state).isOk()); + } // Scope to limit the lifetime of the pDisplay pointer, and thus the IEvsDisplay object. { @@ -2285,6 +2289,15 @@ TEST_P(EvsAidlTest, DisplayStates) { EXPECT_TRUE(mEnumerator->getDisplayState(&state).isOk()); EXPECT_EQ(state, DisplayState::NOT_VISIBLE); } + for (const auto displayIdToQuery : displayIds) { + DisplayState state; + if (displayIdToQuery == displayId) { + EXPECT_TRUE(mEnumerator->getDisplayStateById(displayIdToQuery, &state).isOk()); + EXPECT_EQ(state, DisplayState::NOT_VISIBLE); + } else { + EXPECT_FALSE(mEnumerator->getDisplayStateById(displayIdToQuery, &state).isOk()); + } + } // Activate the display. EXPECT_TRUE(pDisplay->setDisplayState(DisplayState::VISIBLE_ON_NEXT_FRAME).isOk()); @@ -2298,6 +2311,15 @@ TEST_P(EvsAidlTest, DisplayStates) { EXPECT_TRUE(pDisplay->getDisplayState(&state).isOk()); EXPECT_EQ(state, DisplayState::VISIBLE_ON_NEXT_FRAME); } + for (const auto displayIdToQuery : displayIds) { + DisplayState state; + if (displayIdToQuery == displayId) { + EXPECT_TRUE(mEnumerator->getDisplayStateById(displayIdToQuery, &state).isOk()); + EXPECT_EQ(state, DisplayState::VISIBLE_ON_NEXT_FRAME); + } else { + EXPECT_FALSE(mEnumerator->getDisplayStateById(displayIdToQuery, &state).isOk()); + } + } // Get the output buffer we'd use to display the imagery. BufferDesc tgtBuffer; @@ -2319,6 +2341,15 @@ TEST_P(EvsAidlTest, DisplayStates) { EXPECT_TRUE(pDisplay->getDisplayState(&state).isOk()); EXPECT_EQ(state, DisplayState::VISIBLE); } + for (const auto displayIdToQuery : displayIds) { + DisplayState state; + if (displayIdToQuery == displayId) { + EXPECT_TRUE(mEnumerator->getDisplayStateById(displayIdToQuery, &state).isOk()); + EXPECT_EQ(state, DisplayState::VISIBLE); + } else { + EXPECT_FALSE(mEnumerator->getDisplayStateById(displayIdToQuery, &state).isOk()); + } + } // Turn off the display. EXPECT_TRUE(pDisplay->setDisplayState(DisplayState::NOT_VISIBLE).isOk()); @@ -2333,6 +2364,15 @@ TEST_P(EvsAidlTest, DisplayStates) { EXPECT_TRUE(pDisplay->getDisplayState(&state).isOk()); EXPECT_EQ(state, DisplayState::NOT_VISIBLE); } + for (const auto displayIdToQuery : displayIds) { + DisplayState state; + if (displayIdToQuery == displayId) { + EXPECT_TRUE(mEnumerator->getDisplayStateById(displayIdToQuery, &state).isOk()); + EXPECT_EQ(state, DisplayState::NOT_VISIBLE); + } else { + EXPECT_FALSE(mEnumerator->getDisplayStateById(displayIdToQuery, &state).isOk()); + } + } // Close the display. mEnumerator->closeDisplay(pDisplay); @@ -2348,6 +2388,10 @@ TEST_P(EvsAidlTest, DisplayStates) { DisplayState state; EXPECT_FALSE(mEnumerator->getDisplayState(&state).isOk()); } + for (const auto displayIdToQuery : displayIds) { + DisplayState state; + EXPECT_FALSE(mEnumerator->getDisplayStateById(displayIdToQuery, &state).isOk()); + } } }