Hongguang | 600a6ae | 2021-07-08 18:51:51 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2021 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 <gtest/gtest.h> |
| 20 | #include <log/log.h> |
| 21 | #include <utils/Condition.h> |
| 22 | #include <utils/Mutex.h> |
| 23 | #include <fstream> |
| 24 | #include <iostream> |
| 25 | #include <map> |
| 26 | |
| 27 | #include <android/hardware/cas/1.0/types.h> |
| 28 | #include <android/hardware/cas/1.2/ICas.h> |
| 29 | #include <android/hardware/cas/1.2/ICasListener.h> |
| 30 | #include <android/hardware/cas/1.2/IMediaCasService.h> |
| 31 | #include <android/hardware/cas/1.2/types.h> |
| 32 | |
| 33 | #include <aidl/android/hardware/tv/tuner/IDescrambler.h> |
| 34 | #include <aidl/android/hardware/tv/tuner/IDvr.h> |
| 35 | #include <aidl/android/hardware/tv/tuner/IDvrCallback.h> |
| 36 | #include <aidl/android/hardware/tv/tuner/ITuner.h> |
| 37 | |
| 38 | using android::Condition; |
| 39 | using android::Mutex; |
| 40 | using android::sp; |
| 41 | using android::hardware::hidl_string; |
| 42 | using android::hardware::hidl_vec; |
| 43 | using android::hardware::Return; |
| 44 | using android::hardware::Void; |
| 45 | using android::hardware::cas::V1_2::ICas; |
| 46 | using android::hardware::cas::V1_2::ICasListener; |
| 47 | using android::hardware::cas::V1_2::IMediaCasService; |
| 48 | using android::hardware::cas::V1_2::ScramblingMode; |
| 49 | using android::hardware::cas::V1_2::SessionIntent; |
| 50 | using android::hardware::cas::V1_2::Status; |
| 51 | using android::hardware::cas::V1_2::StatusEvent; |
| 52 | |
| 53 | using ::testing::AssertionResult; |
| 54 | |
| 55 | using namespace aidl::android::hardware::tv::tuner; |
| 56 | |
| 57 | class MediaCasListener : public ICasListener { |
| 58 | public: |
| 59 | virtual Return<void> onEvent(int32_t /*event*/, int32_t /*arg*/, |
| 60 | const hidl_vec<uint8_t>& /*data*/) override { |
| 61 | return Void(); |
| 62 | } |
| 63 | |
| 64 | virtual Return<void> onSessionEvent(const hidl_vec<uint8_t>& /*sessionId*/, int32_t /*event*/, |
| 65 | int32_t /*arg*/, |
| 66 | const hidl_vec<uint8_t>& /*data*/) override { |
| 67 | return Void(); |
| 68 | } |
| 69 | |
| 70 | virtual Return<void> onStatusUpdate(StatusEvent /*event*/, int32_t /*arg*/) override { |
| 71 | return Void(); |
| 72 | } |
| 73 | }; |
| 74 | |
| 75 | class DescramblerTests { |
| 76 | public: |
| 77 | void setService(std::shared_ptr<ITuner> tuner) { mService = tuner; } |
| 78 | void setCasService(sp<IMediaCasService> casService) { mMediaCasService = casService; } |
| 79 | |
| 80 | AssertionResult setKeyToken(std::vector<uint8_t>& token); |
| 81 | AssertionResult openDescrambler(int32_t demuxId); |
| 82 | AssertionResult addPid(DemuxPid pid, std::shared_ptr<IFilter> optionalSourceFilter); |
| 83 | AssertionResult removePid(DemuxPid pid, std::shared_ptr<IFilter> optionalSourceFilter); |
| 84 | AssertionResult closeDescrambler(); |
| 85 | AssertionResult getKeyToken(int32_t caSystemId, std::string& provisonStr, |
| 86 | std::vector<uint8_t>& hidlPvtData, std::vector<uint8_t>& token); |
| 87 | AssertionResult getDemuxPidFromFilterSettings(DemuxFilterType type, |
| 88 | const DemuxFilterSettings& settings, |
| 89 | DemuxPid& pid); |
| 90 | |
| 91 | protected: |
| 92 | static AssertionResult failure() { return ::testing::AssertionFailure(); } |
| 93 | |
| 94 | static AssertionResult success() { return ::testing::AssertionSuccess(); } |
| 95 | |
| 96 | std::shared_ptr<ITuner> mService; |
| 97 | std::shared_ptr<IDescrambler> mDescrambler; |
| 98 | android::sp<ICas> mCas; |
| 99 | android::sp<IMediaCasService> mMediaCasService; |
| 100 | android::sp<MediaCasListener> mCasListener; |
| 101 | |
| 102 | private: |
| 103 | AssertionResult openCasSession(std::vector<uint8_t>& sessionId, |
| 104 | std::vector<uint8_t>& hidlPvtData); |
| 105 | AssertionResult createCasPlugin(int32_t caSystemId); |
| 106 | }; |