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> |
| 28 | #include <aidl/android/hardware/tv/input/TvStreamConfig.h> |
| 29 | |
| 30 | #include <log/log.h> |
| 31 | #include <utils/KeyedVector.h> |
| 32 | |
| 33 | using namespace aidl::android::hardware::tv::input; |
| 34 | using namespace std; |
| 35 | |
| 36 | using ::aidl::android::hardware::common::NativeHandle; |
| 37 | |
| 38 | #define WAIT_FOR_EVENT_TIMEOUT 5 |
| 39 | #define DEFAULT_ID INT32_MIN |
| 40 | |
| 41 | namespace VtsHalTvInputTargetTest { |
| 42 | |
| 43 | class TvInputAidlTest : public testing::TestWithParam<string> { |
| 44 | public: |
| 45 | class TvInputCallback : public BnTvInputCallback { |
| 46 | public: |
| 47 | TvInputCallback(shared_ptr<TvInputAidlTest> parent); |
| 48 | ::ndk::ScopedAStatus notify(const TvInputEvent& in_event) override; |
| 49 | |
| 50 | private: |
| 51 | shared_ptr<TvInputAidlTest> parent_; |
| 52 | }; |
| 53 | |
| 54 | virtual void SetUp() override; |
| 55 | virtual void TearDown() override; |
| 56 | |
| 57 | /* Called when a DEVICE_AVAILABLE event is received. */ |
| 58 | void onDeviceAvailable(const TvInputDeviceInfo& deviceInfo); |
| 59 | |
| 60 | /* Called when a DEVICE_UNAVAILABLE event is received. */ |
| 61 | void onDeviceUnavailable(int32_t deviceId); |
| 62 | |
| 63 | /* Called when a STREAM_CONFIGURATIONS_CHANGED event is received. */ |
| 64 | ::ndk::ScopedAStatus onStreamConfigurationsChanged(int32_t deviceId); |
| 65 | |
| 66 | /* Gets and updates the stream configurations for a device. */ |
| 67 | ::ndk::ScopedAStatus updateStreamConfigurations(int32_t deviceId); |
| 68 | |
| 69 | /* Gets and updates the stream configurations for all existing devices. */ |
| 70 | void updateAllStreamConfigurations(); |
| 71 | |
| 72 | /* Returns a list of indices of stream_config_ whose corresponding values are not empty. */ |
| 73 | vector<size_t> getConfigIndices(); |
| 74 | |
| 75 | /* |
| 76 | * Returns DEFAULT_ID if there is no missing integer in the range [0, the size of nums). |
| 77 | * Otherwise, returns the smallest missing non-negative integer. |
| 78 | */ |
| 79 | int32_t getNumNotIn(vector<int32_t>& nums); |
| 80 | |
| 81 | protected: |
| 82 | shared_ptr<ITvInput> tv_input_; |
| 83 | shared_ptr<TvInputCallback> tv_input_callback_; |
| 84 | android::KeyedVector<int32_t, TvInputDeviceInfo> device_info_; |
| 85 | android::KeyedVector<int32_t, vector<TvStreamConfig>> stream_config_; |
| 86 | mutex mutex_; |
| 87 | NativeHandle handle_; |
| 88 | }; |
| 89 | |
| 90 | } // namespace VtsHalTvInputTargetTest |