Add CAS AIDL/HIDL support for Tuner Descrambler Tests
Bug: 266968335 Test: VtsHalTvTunerTargetTest Change-Id: I55074360587735256c4f0efa8228d28f57b21592 Merged-In: I55074360587735256c4f0efa8228d28f57b21592
This commit is contained in:
parent
fb54986369
commit
d4a66cb3d0
5 changed files with 156 additions and 58 deletions
|
@ -1,3 +1,5 @@
|
|||
# Bug component: 136752
|
||||
|
||||
hgchen@google.com
|
||||
shubang@google.com
|
||||
quxiangfang@google.com
|
||||
|
|
|
@ -51,6 +51,7 @@ cc_test {
|
|||
"android.hardware.cas@1.0",
|
||||
"android.hardware.cas@1.1",
|
||||
"android.hardware.cas@1.2",
|
||||
"android.hardware.cas-V1-ndk",
|
||||
"android.hardware.common-V2-ndk",
|
||||
"android.hardware.common.fmq-V1-ndk",
|
||||
"android.hardware.tv.tuner-V1-ndk",
|
||||
|
|
|
@ -19,71 +19,115 @@
|
|||
using namespace std;
|
||||
|
||||
AssertionResult DescramblerTests::createCasPlugin(int32_t caSystemId) {
|
||||
auto status = mMediaCasService->isSystemIdSupported(caSystemId);
|
||||
if (!status.isOk() || !status) {
|
||||
ALOGW("[vts] Failed to check isSystemIdSupported.");
|
||||
return failure();
|
||||
mCasListener = ::ndk::SharedRefBase::make<MediaCasListener>();
|
||||
|
||||
if (mMediaCasServiceAidl != nullptr) {
|
||||
bool rst = false;
|
||||
ScopedAStatus status = mMediaCasServiceAidl->isSystemIdSupported(caSystemId, &rst);
|
||||
if (!status.isOk() || !rst) {
|
||||
ALOGW("[vts] Failed to check isSystemIdSupported for AIDL service.");
|
||||
return failure();
|
||||
}
|
||||
status = mMediaCasServiceAidl->createPlugin(caSystemId, mCasListener, &mCasAidl);
|
||||
if (!status.isOk()) {
|
||||
ALOGW("[vts] Failed to createPlugin for AIDL service.");
|
||||
return failure();
|
||||
}
|
||||
} else {
|
||||
auto status = mMediaCasServiceHidl->isSystemIdSupported(caSystemId);
|
||||
if (!status.isOk() || !status) {
|
||||
ALOGW("[vts] Failed to check isSystemIdSupported for HIDL service.");
|
||||
return failure();
|
||||
}
|
||||
auto pluginStatus = mMediaCasServiceHidl->createPluginExt(
|
||||
caSystemId, sp<ICasListenerHidl>(mCasListener.get()));
|
||||
if (!pluginStatus.isOk()) {
|
||||
ALOGW("[vts] Failed to createPluginExt for HIDL service.");
|
||||
return failure();
|
||||
}
|
||||
mCasHidl = ICasHidl::castFrom(pluginStatus);
|
||||
if (mCasHidl == nullptr) {
|
||||
ALOGW("[vts] Failed to get ICas for HIDL service.");
|
||||
return failure();
|
||||
}
|
||||
}
|
||||
|
||||
mCasListener = new MediaCasListener();
|
||||
auto pluginStatus = mMediaCasService->createPluginExt(caSystemId, mCasListener);
|
||||
if (!pluginStatus.isOk()) {
|
||||
ALOGW("[vts] Failed to createPluginExt.");
|
||||
return failure();
|
||||
}
|
||||
mCas = ICas::castFrom(pluginStatus);
|
||||
if (mCas == nullptr) {
|
||||
ALOGW("[vts] Failed to get ICas.");
|
||||
return failure();
|
||||
}
|
||||
return success();
|
||||
}
|
||||
|
||||
AssertionResult DescramblerTests::openCasSession(vector<uint8_t>& sessionId,
|
||||
vector<uint8_t>& hidlPvtData) {
|
||||
Status sessionStatus;
|
||||
SessionIntent intent = SessionIntent::LIVE;
|
||||
ScramblingMode mode = ScramblingMode::RESERVED;
|
||||
auto returnVoid =
|
||||
mCas->openSession_1_2(intent, mode, [&](Status status, const hidl_vec<uint8_t>& id) {
|
||||
sessionStatus = status;
|
||||
sessionId = id;
|
||||
});
|
||||
if (!returnVoid.isOk() || (sessionStatus != Status::OK)) {
|
||||
ALOGW("[vts] Failed to open cas session.");
|
||||
mCas->closeSession(sessionId);
|
||||
return failure();
|
||||
}
|
||||
|
||||
if (hidlPvtData.size() > 0) {
|
||||
auto status = mCas->setSessionPrivateData(sessionId, hidlPvtData);
|
||||
if (status != android::hardware::cas::V1_0::Status::OK) {
|
||||
ALOGW("[vts] Failed to set session private data");
|
||||
mCas->closeSession(sessionId);
|
||||
vector<uint8_t>& pvtData) {
|
||||
if (mMediaCasServiceAidl != nullptr) {
|
||||
SessionIntentAidl intent = SessionIntentAidl::LIVE;
|
||||
ScramblingModeAidl mode = ScramblingModeAidl::RESERVED;
|
||||
std::vector<uint8_t> sessionId;
|
||||
ScopedAStatus status = mCasAidl->openSession(intent, mode, &sessionId);
|
||||
if (!status.isOk()) {
|
||||
ALOGW("[vts] Failed to open cas session for AIDL service.");
|
||||
mCasAidl->closeSession(sessionId);
|
||||
return failure();
|
||||
}
|
||||
|
||||
if (pvtData.size() > 0) {
|
||||
ScopedAStatus status = mCasAidl->setSessionPrivateData(sessionId, pvtData);
|
||||
if (!status.isOk()) {
|
||||
ALOGW("[vts] Failed to set session private data for AIDL service.");
|
||||
mCasAidl->closeSession(sessionId);
|
||||
return failure();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Status sessionStatus;
|
||||
SessionIntentHidl intent = SessionIntentHidl::LIVE;
|
||||
ScramblingModeHidl mode = ScramblingModeHidl::RESERVED;
|
||||
auto returnVoid = mCasHidl->openSession_1_2(
|
||||
intent, mode, [&](Status status, const hidl_vec<uint8_t>& id) {
|
||||
sessionStatus = status;
|
||||
sessionId = id;
|
||||
});
|
||||
if (!returnVoid.isOk() || (sessionStatus != Status::OK)) {
|
||||
ALOGW("[vts] Failed to open cas session for HIDL service.");
|
||||
mCasHidl->closeSession(sessionId);
|
||||
return failure();
|
||||
}
|
||||
|
||||
if (pvtData.size() > 0) {
|
||||
auto status = mCasHidl->setSessionPrivateData(sessionId, pvtData);
|
||||
if (status != android::hardware::cas::V1_0::Status::OK) {
|
||||
ALOGW("[vts] Failed to set session private data for HIDL service.");
|
||||
mCasHidl->closeSession(sessionId);
|
||||
return failure();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return success();
|
||||
}
|
||||
|
||||
AssertionResult DescramblerTests::getKeyToken(int32_t caSystemId, string& provisonStr,
|
||||
vector<uint8_t>& hidlPvtData,
|
||||
vector<uint8_t>& token) {
|
||||
vector<uint8_t>& pvtData, vector<uint8_t>& token) {
|
||||
if (createCasPlugin(caSystemId) != success()) {
|
||||
ALOGW("[vts] createCasPlugin failed.");
|
||||
return failure();
|
||||
}
|
||||
|
||||
if (provisonStr.size() > 0) {
|
||||
auto returnStatus = mCas->provision(hidl_string(provisonStr));
|
||||
if (returnStatus != android::hardware::cas::V1_0::Status::OK) {
|
||||
ALOGW("[vts] provision failed.");
|
||||
return failure();
|
||||
if (mMediaCasServiceAidl != nullptr) {
|
||||
ScopedAStatus status = mCasAidl->provision(provisonStr);
|
||||
if (!status.isOk()) {
|
||||
ALOGW("[vts] provision failed for AIDL service.");
|
||||
return failure();
|
||||
}
|
||||
} else {
|
||||
auto returnStatus = mCasHidl->provision(hidl_string(provisonStr));
|
||||
if (returnStatus != android::hardware::cas::V1_0::Status::OK) {
|
||||
ALOGW("[vts] provision failed for HIDL service.");
|
||||
return failure();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return openCasSession(token, hidlPvtData);
|
||||
return openCasSession(token, pvtData);
|
||||
}
|
||||
|
||||
AssertionResult DescramblerTests::openDescrambler(int32_t demuxId) {
|
||||
|
|
|
@ -30,11 +30,17 @@
|
|||
#include <android/hardware/cas/1.2/IMediaCasService.h>
|
||||
#include <android/hardware/cas/1.2/types.h>
|
||||
|
||||
#include <aidl/android/hardware/cas/BnCasListener.h>
|
||||
#include <aidl/android/hardware/cas/ICas.h>
|
||||
#include <aidl/android/hardware/cas/IMediaCasService.h>
|
||||
#include <aidl/android/hardware/cas/ScramblingMode.h>
|
||||
#include <aidl/android/hardware/cas/SessionIntent.h>
|
||||
#include <aidl/android/hardware/tv/tuner/IDescrambler.h>
|
||||
#include <aidl/android/hardware/tv/tuner/IDvr.h>
|
||||
#include <aidl/android/hardware/tv/tuner/IDvrCallback.h>
|
||||
#include <aidl/android/hardware/tv/tuner/ITuner.h>
|
||||
|
||||
using ::aidl::android::hardware::cas::BnCasListener;
|
||||
using android::Condition;
|
||||
using android::Mutex;
|
||||
using android::sp;
|
||||
|
@ -42,19 +48,26 @@ using android::hardware::hidl_string;
|
|||
using android::hardware::hidl_vec;
|
||||
using android::hardware::Return;
|
||||
using android::hardware::Void;
|
||||
using android::hardware::cas::V1_2::ICas;
|
||||
using android::hardware::cas::V1_2::ICasListener;
|
||||
using android::hardware::cas::V1_2::IMediaCasService;
|
||||
using android::hardware::cas::V1_2::ScramblingMode;
|
||||
using android::hardware::cas::V1_2::SessionIntent;
|
||||
using android::hardware::cas::V1_2::Status;
|
||||
using android::hardware::cas::V1_2::StatusEvent;
|
||||
using ICasAidl = ::aidl::android::hardware::cas::ICas;
|
||||
using ICasHidl = android::hardware::cas::V1_2::ICas;
|
||||
using ICasListenerHidl = android::hardware::cas::V1_2::ICasListener;
|
||||
using IMediaCasServiceAidl = ::aidl::android::hardware::cas::IMediaCasService;
|
||||
using IMediaCasServiceHidl = android::hardware::cas::V1_2::IMediaCasService;
|
||||
using ScramblingModeAidl = ::aidl::android::hardware::cas::ScramblingMode;
|
||||
using ScramblingModeHidl = android::hardware::cas::V1_2::ScramblingMode;
|
||||
using SessionIntentAidl = ::aidl::android::hardware::cas::SessionIntent;
|
||||
using SessionIntentHidl = android::hardware::cas::V1_2::SessionIntent;
|
||||
|
||||
using ::ndk::ScopedAStatus;
|
||||
using ::testing::AssertionResult;
|
||||
|
||||
using namespace aidl::android::hardware::tv::tuner;
|
||||
|
||||
class MediaCasListener : public ICasListener {
|
||||
const std::string MEDIA_CAS_AIDL_SERVICE_NAME = "android.hardware.cas.IMediaCasService/default";
|
||||
|
||||
class MediaCasListener : public ICasListenerHidl, public BnCasListener {
|
||||
public:
|
||||
virtual Return<void> onEvent(int32_t /*event*/, int32_t /*arg*/,
|
||||
const hidl_vec<uint8_t>& /*data*/) override {
|
||||
|
@ -70,12 +83,33 @@ class MediaCasListener : public ICasListener {
|
|||
virtual Return<void> onStatusUpdate(StatusEvent /*event*/, int32_t /*arg*/) override {
|
||||
return Void();
|
||||
}
|
||||
|
||||
ScopedAStatus onEvent(int32_t /*in_event*/, int32_t /*in_arg*/,
|
||||
const std::vector<uint8_t>& /*in_data*/) override {
|
||||
return ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ScopedAStatus onSessionEvent(const std::vector<uint8_t>& /*in_sessionId*/, int32_t /*in_event*/,
|
||||
int32_t /*in_arg*/,
|
||||
const std::vector<uint8_t>& /*in_data*/) override {
|
||||
return ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ScopedAStatus onStatusUpdate(::aidl::android::hardware::cas::StatusEvent /*in_event*/,
|
||||
int32_t /*in_number*/) override {
|
||||
return ScopedAStatus::ok();
|
||||
}
|
||||
};
|
||||
|
||||
class DescramblerTests {
|
||||
public:
|
||||
void setService(std::shared_ptr<ITuner> tuner) { mService = tuner; }
|
||||
void setCasService(sp<IMediaCasService> casService) { mMediaCasService = casService; }
|
||||
void setCasServiceHidl(sp<IMediaCasServiceHidl> casService) {
|
||||
mMediaCasServiceHidl = casService;
|
||||
}
|
||||
void setCasServiceAidl(std::shared_ptr<IMediaCasServiceAidl> casService) {
|
||||
mMediaCasServiceAidl = casService;
|
||||
}
|
||||
|
||||
AssertionResult setKeyToken(std::vector<uint8_t>& token);
|
||||
AssertionResult openDescrambler(int32_t demuxId);
|
||||
|
@ -95,12 +129,13 @@ class DescramblerTests {
|
|||
|
||||
std::shared_ptr<ITuner> mService;
|
||||
std::shared_ptr<IDescrambler> mDescrambler;
|
||||
android::sp<ICas> mCas;
|
||||
android::sp<IMediaCasService> mMediaCasService;
|
||||
android::sp<MediaCasListener> mCasListener;
|
||||
std::shared_ptr<ICasAidl> mCasAidl;
|
||||
android::sp<ICasHidl> mCasHidl;
|
||||
std::shared_ptr<IMediaCasServiceAidl> mMediaCasServiceAidl;
|
||||
android::sp<IMediaCasServiceHidl> mMediaCasServiceHidl;
|
||||
std::shared_ptr<MediaCasListener> mCasListener;
|
||||
|
||||
private:
|
||||
AssertionResult openCasSession(std::vector<uint8_t>& sessionId,
|
||||
std::vector<uint8_t>& hidlPvtData);
|
||||
AssertionResult openCasSession(std::vector<uint8_t>& sessionId, std::vector<uint8_t>& pvtData);
|
||||
AssertionResult createCasPlugin(int32_t caSystemId);
|
||||
};
|
||||
|
|
|
@ -338,16 +338,31 @@ class TunerDescramblerAidlTest : public testing::TestWithParam<std::string> {
|
|||
} else {
|
||||
mService = nullptr;
|
||||
}
|
||||
mCasService = IMediaCasService::getService();
|
||||
ASSERT_NE(mService, nullptr);
|
||||
ASSERT_NE(mCasService, nullptr);
|
||||
|
||||
// Get IMediaCasService. Try getting AIDL service first, if AIDL does not exist, try HIDL.
|
||||
if (AServiceManager_isDeclared(MEDIA_CAS_AIDL_SERVICE_NAME.c_str())) {
|
||||
::ndk::SpAIBinder binder(
|
||||
AServiceManager_waitForService(MEDIA_CAS_AIDL_SERVICE_NAME.c_str()));
|
||||
mCasServiceAidl = IMediaCasServiceAidl::fromBinder(binder);
|
||||
} else {
|
||||
mCasServiceAidl = nullptr;
|
||||
}
|
||||
if (mCasServiceAidl == nullptr) {
|
||||
mCasServiceHidl = IMediaCasServiceHidl::getService();
|
||||
}
|
||||
ASSERT_TRUE(mCasServiceAidl != nullptr || mCasServiceHidl != nullptr);
|
||||
ASSERT_TRUE(initConfiguration());
|
||||
|
||||
mFrontendTests.setService(mService);
|
||||
mDemuxTests.setService(mService);
|
||||
mDvrTests.setService(mService);
|
||||
mDescramblerTests.setService(mService);
|
||||
mDescramblerTests.setCasService(mCasService);
|
||||
if (mCasServiceAidl != nullptr) {
|
||||
mDescramblerTests.setCasServiceAidl(mCasServiceAidl);
|
||||
} else {
|
||||
mDescramblerTests.setCasServiceHidl(mCasServiceHidl);
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
|
@ -360,7 +375,8 @@ class TunerDescramblerAidlTest : public testing::TestWithParam<std::string> {
|
|||
AssertionResult filterDataOutputTest();
|
||||
|
||||
std::shared_ptr<ITuner> mService;
|
||||
android::sp<IMediaCasService> mCasService;
|
||||
sp<IMediaCasServiceHidl> mCasServiceHidl;
|
||||
std::shared_ptr<IMediaCasServiceAidl> mCasServiceAidl;
|
||||
FrontendTests mFrontendTests;
|
||||
DemuxTests mDemuxTests;
|
||||
FilterTests mFilterTests;
|
||||
|
|
Loading…
Reference in a new issue