Yixiao Luo | ce50133 | 2022-08-12 11:18:18 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2022 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 | */ |
| 16 | |
| 17 | #pragma once |
| 18 | |
| 19 | #include <android/binder_manager.h> |
| 20 | |
| 21 | #include <aidl/Gtest.h> |
| 22 | #include <aidl/Vintf.h> |
| 23 | |
| 24 | #include <aidl/android/hardware/tv/input/BnTvInputCallback.h> |
| 25 | #include <aidl/android/hardware/tv/input/ITvInput.h> |
| 26 | #include <aidl/android/hardware/tv/input/TvInputDeviceInfo.h> |
| 27 | #include <aidl/android/hardware/tv/input/TvInputEvent.h> |
David Zhao | 6bdbc5e | 2023-01-12 16:51:03 -0800 | [diff] [blame] | 28 | #include <aidl/android/hardware/tv/input/TvMessageEvent.h> |
| 29 | #include <aidl/android/hardware/tv/input/TvMessageEventType.h> |
Yixiao Luo | ce50133 | 2022-08-12 11:18:18 -0700 | [diff] [blame] | 30 | #include <aidl/android/hardware/tv/input/TvStreamConfig.h> |
David Zhao | 6bdbc5e | 2023-01-12 16:51:03 -0800 | [diff] [blame] | 31 | #include <fmq/AidlMessageQueue.h> |
Yixiao Luo | ce50133 | 2022-08-12 11:18:18 -0700 | [diff] [blame] | 32 | |
| 33 | #include <log/log.h> |
| 34 | #include <utils/KeyedVector.h> |
| 35 | |
| 36 | using namespace aidl::android::hardware::tv::input; |
| 37 | using namespace std; |
Yixiao Luo | ce50133 | 2022-08-12 11:18:18 -0700 | [diff] [blame] | 38 | using ::aidl::android::hardware::common::NativeHandle; |
David Zhao | 6bdbc5e | 2023-01-12 16:51:03 -0800 | [diff] [blame] | 39 | using ::aidl::android::hardware::common::fmq::MQDescriptor; |
| 40 | using ::android::AidlMessageQueue; |
Yixiao Luo | ce50133 | 2022-08-12 11:18:18 -0700 | [diff] [blame] | 41 | |
| 42 | #define WAIT_FOR_EVENT_TIMEOUT 5 |
| 43 | #define DEFAULT_ID INT32_MIN |
| 44 | |
| 45 | namespace VtsHalTvInputTargetTest { |
| 46 | |
| 47 | class TvInputAidlTest : public testing::TestWithParam<string> { |
| 48 | public: |
| 49 | class TvInputCallback : public BnTvInputCallback { |
| 50 | public: |
| 51 | TvInputCallback(shared_ptr<TvInputAidlTest> parent); |
| 52 | ::ndk::ScopedAStatus notify(const TvInputEvent& in_event) override; |
David Zhao | 6bdbc5e | 2023-01-12 16:51:03 -0800 | [diff] [blame] | 53 | ::ndk::ScopedAStatus notifyTvMessageEvent(const TvMessageEvent& in_event) override; |
Yixiao Luo | ce50133 | 2022-08-12 11:18:18 -0700 | [diff] [blame] | 54 | |
| 55 | private: |
| 56 | shared_ptr<TvInputAidlTest> parent_; |
| 57 | }; |
| 58 | |
| 59 | virtual void SetUp() override; |
| 60 | virtual void TearDown() override; |
| 61 | |
| 62 | /* Called when a DEVICE_AVAILABLE event is received. */ |
| 63 | void onDeviceAvailable(const TvInputDeviceInfo& deviceInfo); |
| 64 | |
| 65 | /* Called when a DEVICE_UNAVAILABLE event is received. */ |
| 66 | void onDeviceUnavailable(int32_t deviceId); |
| 67 | |
| 68 | /* Called when a STREAM_CONFIGURATIONS_CHANGED event is received. */ |
| 69 | ::ndk::ScopedAStatus onStreamConfigurationsChanged(int32_t deviceId); |
| 70 | |
| 71 | /* Gets and updates the stream configurations for a device. */ |
| 72 | ::ndk::ScopedAStatus updateStreamConfigurations(int32_t deviceId); |
| 73 | |
| 74 | /* Gets and updates the stream configurations for all existing devices. */ |
| 75 | void updateAllStreamConfigurations(); |
| 76 | |
| 77 | /* Returns a list of indices of stream_config_ whose corresponding values are not empty. */ |
| 78 | vector<size_t> getConfigIndices(); |
| 79 | |
| 80 | /* |
| 81 | * Returns DEFAULT_ID if there is no missing integer in the range [0, the size of nums). |
| 82 | * Otherwise, returns the smallest missing non-negative integer. |
| 83 | */ |
| 84 | int32_t getNumNotIn(vector<int32_t>& nums); |
| 85 | |
| 86 | protected: |
| 87 | shared_ptr<ITvInput> tv_input_; |
| 88 | shared_ptr<TvInputCallback> tv_input_callback_; |
| 89 | android::KeyedVector<int32_t, TvInputDeviceInfo> device_info_; |
| 90 | android::KeyedVector<int32_t, vector<TvStreamConfig>> stream_config_; |
| 91 | mutex mutex_; |
Yixiao Luo | ce50133 | 2022-08-12 11:18:18 -0700 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | } // namespace VtsHalTvInputTargetTest |