Haofan Wang | e02b809 | 2024-10-28 21:47:27 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2024 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Haofan Wang | b97b3f3 | 2024-10-31 15:33:17 -0700 | [diff] [blame] | 16 | #define LOG_TAG "ambient_backlight_aidl_hal_test" |
Haofan Wang | e02b809 | 2024-10-28 21:47:27 +0000 | [diff] [blame] | 17 | |
| 18 | #include <aidl/Gtest.h> |
| 19 | #include <aidl/Vintf.h> |
Haofan Wang | b97b3f3 | 2024-10-31 15:33:17 -0700 | [diff] [blame] | 20 | #include <aidl/android/hardware/tv/mediaquality/AmbientBacklightEvent.h> |
| 21 | #include <aidl/android/hardware/tv/mediaquality/AmbientBacklightSettings.h> |
| 22 | #include <aidl/android/hardware/tv/mediaquality/BnMediaQualityCallback.h> |
Haofan Wang | 58d25d2 | 2024-11-18 17:47:57 -0800 | [diff] [blame] | 23 | #include <aidl/android/hardware/tv/mediaquality/BnPictureProfileAdjustmentListener.h> |
| 24 | #include <aidl/android/hardware/tv/mediaquality/BnSoundProfileAdjustmentListener.h> |
Haofan Wang | b97b3f3 | 2024-10-31 15:33:17 -0700 | [diff] [blame] | 25 | #include <aidl/android/hardware/tv/mediaquality/IMediaQuality.h> |
Haofan Wang | 58d25d2 | 2024-11-18 17:47:57 -0800 | [diff] [blame] | 26 | #include <aidl/android/hardware/tv/mediaquality/PictureParameters.h> |
| 27 | #include <aidl/android/hardware/tv/mediaquality/PictureProfile.h> |
| 28 | #include <aidl/android/hardware/tv/mediaquality/SoundParameters.h> |
| 29 | #include <aidl/android/hardware/tv/mediaquality/SoundProfile.h> |
| 30 | |
Haofan Wang | b97b3f3 | 2024-10-31 15:33:17 -0700 | [diff] [blame] | 31 | #include <android/binder_auto_utils.h> |
| 32 | #include <android/binder_manager.h> |
Haofan Wang | e02b809 | 2024-10-28 21:47:27 +0000 | [diff] [blame] | 33 | #include <binder/IServiceManager.h> |
| 34 | #include <binder/ProcessState.h> |
Haofan Wang | b97b3f3 | 2024-10-31 15:33:17 -0700 | [diff] [blame] | 35 | #include <future> |
Haofan Wang | e02b809 | 2024-10-28 21:47:27 +0000 | [diff] [blame] | 36 | |
Haofan Wang | b97b3f3 | 2024-10-31 15:33:17 -0700 | [diff] [blame] | 37 | using aidl::android::hardware::graphics::common::PixelFormat; |
| 38 | using aidl::android::hardware::tv::mediaquality::AmbientBacklightEvent; |
| 39 | using aidl::android::hardware::tv::mediaquality::AmbientBacklightSettings; |
| 40 | using aidl::android::hardware::tv::mediaquality::AmbientBacklightSource; |
| 41 | using aidl::android::hardware::tv::mediaquality::BnMediaQualityCallback; |
Haofan Wang | 58d25d2 | 2024-11-18 17:47:57 -0800 | [diff] [blame] | 42 | using aidl::android::hardware::tv::mediaquality::BnPictureProfileAdjustmentListener; |
| 43 | using aidl::android::hardware::tv::mediaquality::BnSoundProfileAdjustmentListener; |
Haofan Wang | b97b3f3 | 2024-10-31 15:33:17 -0700 | [diff] [blame] | 44 | using aidl::android::hardware::tv::mediaquality::IMediaQuality; |
Haofan Wang | 58d25d2 | 2024-11-18 17:47:57 -0800 | [diff] [blame] | 45 | using aidl::android::hardware::tv::mediaquality::PictureParameters; |
| 46 | using aidl::android::hardware::tv::mediaquality::PictureProfile; |
| 47 | using aidl::android::hardware::tv::mediaquality::SoundParameters; |
| 48 | using aidl::android::hardware::tv::mediaquality::SoundProfile; |
Haofan Wang | e02b809 | 2024-10-28 21:47:27 +0000 | [diff] [blame] | 49 | using android::ProcessState; |
Haofan Wang | e02b809 | 2024-10-28 21:47:27 +0000 | [diff] [blame] | 50 | using android::String16; |
Haofan Wang | b97b3f3 | 2024-10-31 15:33:17 -0700 | [diff] [blame] | 51 | using ndk::ScopedAStatus; |
| 52 | using ndk::SpAIBinder; |
Haofan Wang | e02b809 | 2024-10-28 21:47:27 +0000 | [diff] [blame] | 53 | |
| 54 | #define ASSERT_OK(ret) ASSERT_TRUE(ret.isOk()) |
| 55 | #define EXPECT_OK(ret) EXPECT_TRUE(ret.isOk()) |
| 56 | |
Haofan Wang | b97b3f3 | 2024-10-31 15:33:17 -0700 | [diff] [blame] | 57 | class MediaQualityCallback : public BnMediaQualityCallback { |
Haofan Wang | e02b809 | 2024-10-28 21:47:27 +0000 | [diff] [blame] | 58 | public: |
Haofan Wang | b97b3f3 | 2024-10-31 15:33:17 -0700 | [diff] [blame] | 59 | explicit MediaQualityCallback( |
| 60 | const std::function<void(const AmbientBacklightEvent& event)>& on_hal_event_cb) |
| 61 | : on_hal_event_cb_(on_hal_event_cb) {} |
| 62 | ScopedAStatus notifyAmbientBacklightEvent(const AmbientBacklightEvent& event) override { |
| 63 | on_hal_event_cb_(event); |
| 64 | return ScopedAStatus::ok(); |
Haofan Wang | e02b809 | 2024-10-28 21:47:27 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Haofan Wang | b97b3f3 | 2024-10-31 15:33:17 -0700 | [diff] [blame] | 67 | private: |
| 68 | std::function<void(const AmbientBacklightEvent& event)> on_hal_event_cb_; |
Haofan Wang | e02b809 | 2024-10-28 21:47:27 +0000 | [diff] [blame] | 69 | }; |
| 70 | |
Haofan Wang | 58d25d2 | 2024-11-18 17:47:57 -0800 | [diff] [blame] | 71 | class PictureProfileAdjustmentListener : public BnPictureProfileAdjustmentListener { |
| 72 | public: |
| 73 | explicit PictureProfileAdjustmentListener( |
| 74 | const std::function<void(const PictureProfile& pictureProfile)>& |
| 75 | on_hal_picture_profile_adjust) |
| 76 | : on_hal_picture_profile_adjust_(on_hal_picture_profile_adjust) {} |
| 77 | ScopedAStatus onPictureProfileAdjusted(const PictureProfile& pictureProfile) override { |
| 78 | on_hal_picture_profile_adjust_(pictureProfile); |
| 79 | return ScopedAStatus::ok(); |
| 80 | } |
| 81 | |
| 82 | private: |
| 83 | std::function<void(const PictureProfile& pictureProfile)> on_hal_picture_profile_adjust_; |
| 84 | }; |
| 85 | |
| 86 | class SoundProfileAdjustmentListener : public BnSoundProfileAdjustmentListener { |
| 87 | public: |
| 88 | explicit SoundProfileAdjustmentListener( |
| 89 | const std::function<void(const SoundProfile& soundProfile)>& |
| 90 | on_hal_sound_profile_adjust) |
| 91 | : on_hal_sound_profile_adjust_(on_hal_sound_profile_adjust) {} |
| 92 | ScopedAStatus onSoundProfileAdjusted(const SoundProfile& soundProfile) override { |
| 93 | on_hal_sound_profile_adjust_(soundProfile); |
| 94 | return ScopedAStatus::ok(); |
| 95 | } |
| 96 | |
| 97 | private: |
| 98 | std::function<void(const SoundProfile& soundProfile)> on_hal_sound_profile_adjust_; |
| 99 | }; |
| 100 | |
Haofan Wang | b97b3f3 | 2024-10-31 15:33:17 -0700 | [diff] [blame] | 101 | class MediaQualityAidl : public testing::TestWithParam<std::string> { |
| 102 | public: |
| 103 | virtual void SetUp() override { |
| 104 | mediaquality = IMediaQuality::fromBinder( |
| 105 | SpAIBinder(AServiceManager_waitForService(GetParam().c_str()))); |
| 106 | ASSERT_NE(mediaquality, nullptr); |
| 107 | } |
| 108 | std::shared_ptr<IMediaQuality> mediaquality; |
| 109 | }; |
| 110 | |
| 111 | TEST_P(MediaQualityAidl, TestSetAmbientBacklightDetectionEnabled) { |
| 112 | std::promise<void> open_cb_promise; |
| 113 | std::future<void> open_cb_future{open_cb_promise.get_future()}; |
| 114 | std::shared_ptr<MediaQualityCallback> callback = |
| 115 | ndk::SharedRefBase::make<MediaQualityCallback>([&open_cb_promise](auto event) { |
| 116 | EXPECT_EQ(event.getTag(), AmbientBacklightEvent::Tag::enabled); |
| 117 | EXPECT_EQ(event.template get<AmbientBacklightEvent::Tag::enabled>(), true); |
| 118 | open_cb_promise.set_value(); |
| 119 | return ScopedAStatus::ok(); |
| 120 | }); |
| 121 | ASSERT_OK(mediaquality->setCallback(callback)); |
| 122 | ASSERT_OK(mediaquality->setAmbientBacklightDetectionEnabled(true)); |
| 123 | std::chrono::milliseconds timeout{10000}; |
| 124 | EXPECT_EQ(open_cb_future.wait_for(timeout), std::future_status::ready); |
Haofan Wang | e02b809 | 2024-10-28 21:47:27 +0000 | [diff] [blame] | 125 | } |
| 126 | |
Haofan Wang | b97b3f3 | 2024-10-31 15:33:17 -0700 | [diff] [blame] | 127 | TEST_P(MediaQualityAidl, TestGetAmbientBacklightDetectionEnabled) { |
Haofan Wang | e02b809 | 2024-10-28 21:47:27 +0000 | [diff] [blame] | 128 | bool enabled; |
Haofan Wang | b97b3f3 | 2024-10-31 15:33:17 -0700 | [diff] [blame] | 129 | ASSERT_OK(mediaquality->getAmbientBacklightDetectionEnabled(&enabled)); |
| 130 | } |
| 131 | |
| 132 | TEST_P(MediaQualityAidl, TestSetMediaQualityCallback) { |
| 133 | std::shared_ptr<MediaQualityCallback> callback = ndk::SharedRefBase::make<MediaQualityCallback>( |
| 134 | [](auto /* event */) { return ScopedAStatus::ok(); }); |
| 135 | ASSERT_OK(mediaquality->setCallback(callback)); |
| 136 | } |
| 137 | |
Haofan Wang | 58d25d2 | 2024-11-18 17:47:57 -0800 | [diff] [blame] | 138 | TEST_P(MediaQualityAidl, TestSetPictureProfileAdjustmentListener) { |
| 139 | std::shared_ptr<PictureProfileAdjustmentListener> listener = |
| 140 | ndk::SharedRefBase::make<PictureProfileAdjustmentListener>( |
| 141 | [](auto /*picture profile*/) { return ScopedAStatus::ok(); }); |
| 142 | ASSERT_OK(mediaquality->setPictureProfileAdjustmentListener(listener)); |
| 143 | } |
| 144 | |
| 145 | TEST_P(MediaQualityAidl, TestGetPictureParameters) { |
| 146 | PictureParameters pictureParams; |
| 147 | auto result = mediaquality->getPictureParameters(1, &pictureParams); |
| 148 | ASSERT_TRUE(result.isOk()); |
| 149 | ASSERT_EQ(pictureParams.pictureParameters.size(), 2); |
| 150 | } |
| 151 | |
| 152 | TEST_P(MediaQualityAidl, TestSetSoundProfileAdjustmentListener) { |
| 153 | std::shared_ptr<SoundProfileAdjustmentListener> listener = |
| 154 | ndk::SharedRefBase::make<SoundProfileAdjustmentListener>( |
| 155 | [](auto /*sound profile*/) { return ScopedAStatus::ok(); }); |
| 156 | ASSERT_OK(mediaquality->setSoundProfileAdjustmentListener(listener)); |
| 157 | } |
| 158 | |
| 159 | TEST_P(MediaQualityAidl, TestGetSoundParameters) { |
| 160 | SoundParameters soundParams; |
| 161 | auto result = mediaquality->getSoundParameters(1, &soundParams); |
| 162 | ASSERT_TRUE(result.isOk()); |
| 163 | ASSERT_EQ(soundParams.soundParameters.size(), 2); |
| 164 | } |
| 165 | |
Haofan Wang | b97b3f3 | 2024-10-31 15:33:17 -0700 | [diff] [blame] | 166 | TEST_P(MediaQualityAidl, TestSetAmbientBacklightDetector) { |
| 167 | AmbientBacklightSettings in_settings = { |
| 168 | .packageName = "com.android.mediaquality", |
| 169 | .source = AmbientBacklightSource::VIDEO, |
| 170 | .colorFormat = PixelFormat::RGB_888, |
| 171 | .hZonesNumber = 32, |
| 172 | .vZonesNumber = 20, |
| 173 | .hasLetterbox = true, |
| 174 | .threshold = 0, |
| 175 | }; |
| 176 | ASSERT_OK(mediaquality->setAmbientBacklightDetector(in_settings)); |
Haofan Wang | e02b809 | 2024-10-28 21:47:27 +0000 | [diff] [blame] | 177 | } |
| 178 | |
Haofan Wang | ee9629f | 2024-11-22 13:34:17 -0800 | [diff] [blame^] | 179 | TEST_P(MediaQualityAidl, TestIsAutoPqSupported) { |
| 180 | bool supported; |
| 181 | ASSERT_OK(mediaquality->isAutoPqSupported(&supported)); |
| 182 | } |
| 183 | |
| 184 | TEST_P(MediaQualityAidl, TestGetAutoPqEnabled) { |
| 185 | bool enabled; |
| 186 | ASSERT_OK(mediaquality->getAutoPqEnabled(&enabled)); |
| 187 | } |
| 188 | |
| 189 | TEST_P(MediaQualityAidl, TestSetAutoPqEnabled) { |
| 190 | ASSERT_OK(mediaquality->setAutoPqEnabled(true)); |
| 191 | } |
| 192 | |
| 193 | TEST_P(MediaQualityAidl, TestIsAutoSrSupported) { |
| 194 | bool supported; |
| 195 | ASSERT_OK(mediaquality->isAutoSrSupported(&supported)); |
| 196 | } |
| 197 | |
| 198 | TEST_P(MediaQualityAidl, TestGetAutoSrEnabled) { |
| 199 | bool enabled; |
| 200 | ASSERT_OK(mediaquality->getAutoSrEnabled(&enabled)); |
| 201 | } |
| 202 | |
| 203 | TEST_P(MediaQualityAidl, TestSetAutoSrEnabled) { |
| 204 | ASSERT_OK(mediaquality->setAutoSrEnabled(true)); |
| 205 | } |
| 206 | |
| 207 | TEST_P(MediaQualityAidl, TestIsAutoAqSupported) { |
| 208 | bool supported; |
| 209 | ASSERT_OK(mediaquality->isAutoAqSupported(&supported)); |
| 210 | } |
| 211 | |
| 212 | TEST_P(MediaQualityAidl, TestGetAutoAqEnabled) { |
| 213 | bool enabled; |
| 214 | ASSERT_OK(mediaquality->getAutoAqEnabled(&enabled)); |
| 215 | } |
| 216 | |
| 217 | TEST_P(MediaQualityAidl, TestSetAutoAqEnabled) { |
| 218 | ASSERT_OK(mediaquality->setAutoAqEnabled(true)); |
| 219 | } |
| 220 | |
Haofan Wang | e02b809 | 2024-10-28 21:47:27 +0000 | [diff] [blame] | 221 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(MediaQualityAidl); |
| 222 | |
| 223 | INSTANTIATE_TEST_SUITE_P( |
| 224 | PerInstance, MediaQualityAidl, |
| 225 | testing::ValuesIn(android::getAidlHalInstanceNames(IMediaQuality::descriptor)), |
| 226 | android::PrintInstanceNameToString); |
| 227 | |
| 228 | int main(int argc, char** argv) { |
| 229 | ::testing::InitGoogleTest(&argc, argv); |
| 230 | ProcessState::self()->setThreadPoolMaxThreadCount(1); |
| 231 | ProcessState::self()->startThreadPool(); |
| 232 | return RUN_ALL_TESTS(); |
| 233 | } |