blob: 832b27ce44010159de3854aeb8058ffff4cd8ab1 [file] [log] [blame]
Yixiao Luoce501332022-08-12 11:18:18 -07001/*
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 Zhao6bdbc5e2023-01-12 16:51:03 -080028#include <aidl/android/hardware/tv/input/TvMessageEvent.h>
29#include <aidl/android/hardware/tv/input/TvMessageEventType.h>
Yixiao Luoce501332022-08-12 11:18:18 -070030#include <aidl/android/hardware/tv/input/TvStreamConfig.h>
David Zhao6bdbc5e2023-01-12 16:51:03 -080031#include <fmq/AidlMessageQueue.h>
Yixiao Luoce501332022-08-12 11:18:18 -070032
33#include <log/log.h>
34#include <utils/KeyedVector.h>
35
36using namespace aidl::android::hardware::tv::input;
37using namespace std;
Yixiao Luoce501332022-08-12 11:18:18 -070038using ::aidl::android::hardware::common::NativeHandle;
David Zhao6bdbc5e2023-01-12 16:51:03 -080039using ::aidl::android::hardware::common::fmq::MQDescriptor;
David Zhao17a91902023-05-17 16:36:38 -070040using ::aidl::android::hardware::common::fmq::SynchronizedReadWrite;
David Zhao6bdbc5e2023-01-12 16:51:03 -080041using ::android::AidlMessageQueue;
Yixiao Luoce501332022-08-12 11:18:18 -070042
43#define WAIT_FOR_EVENT_TIMEOUT 5
44#define DEFAULT_ID INT32_MIN
45
46namespace VtsHalTvInputTargetTest {
47
48class TvInputAidlTest : public testing::TestWithParam<string> {
49 public:
50 class TvInputCallback : public BnTvInputCallback {
51 public:
52 TvInputCallback(shared_ptr<TvInputAidlTest> parent);
53 ::ndk::ScopedAStatus notify(const TvInputEvent& in_event) override;
David Zhao6bdbc5e2023-01-12 16:51:03 -080054 ::ndk::ScopedAStatus notifyTvMessageEvent(const TvMessageEvent& in_event) override;
Yixiao Luoce501332022-08-12 11:18:18 -070055
56 private:
57 shared_ptr<TvInputAidlTest> parent_;
58 };
59
60 virtual void SetUp() override;
61 virtual void TearDown() override;
62
63 /* Called when a DEVICE_AVAILABLE event is received. */
64 void onDeviceAvailable(const TvInputDeviceInfo& deviceInfo);
65
66 /* Called when a DEVICE_UNAVAILABLE event is received. */
67 void onDeviceUnavailable(int32_t deviceId);
68
69 /* Called when a STREAM_CONFIGURATIONS_CHANGED event is received. */
70 ::ndk::ScopedAStatus onStreamConfigurationsChanged(int32_t deviceId);
71
72 /* Gets and updates the stream configurations for a device. */
73 ::ndk::ScopedAStatus updateStreamConfigurations(int32_t deviceId);
74
75 /* Gets and updates the stream configurations for all existing devices. */
76 void updateAllStreamConfigurations();
77
78 /* Returns a list of indices of stream_config_ whose corresponding values are not empty. */
79 vector<size_t> getConfigIndices();
80
81 /*
82 * Returns DEFAULT_ID if there is no missing integer in the range [0, the size of nums).
83 * Otherwise, returns the smallest missing non-negative integer.
84 */
85 int32_t getNumNotIn(vector<int32_t>& nums);
86
87 protected:
88 shared_ptr<ITvInput> tv_input_;
89 shared_ptr<TvInputCallback> tv_input_callback_;
90 android::KeyedVector<int32_t, TvInputDeviceInfo> device_info_;
91 android::KeyedVector<int32_t, vector<TvStreamConfig>> stream_config_;
92 mutex mutex_;
Yixiao Luoce501332022-08-12 11:18:18 -070093};
94
95} // namespace VtsHalTvInputTargetTest