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