diff --git a/libwvdrmengine/cdm/core/test/license_holder.cpp b/libwvdrmengine/cdm/core/test/license_holder.cpp index 7535b14b..de131c62 100644 --- a/libwvdrmengine/cdm/core/test/license_holder.cpp +++ b/libwvdrmengine/cdm/core/test/license_holder.cpp @@ -7,6 +7,7 @@ #include "license_request.h" #include "message_dumper.h" #include "oec_device_features.h" +#include "properties.h" #include "test_base.h" namespace wvcdm { @@ -126,10 +127,27 @@ void LicenseHolder::GenerateAndPostReleaseRequest( const std::string init_data_string = MakePSSH(pssh); const InitializationData init_data(kCencMimeType, init_data_string); init_data.DumpToLogs(); - const CdmResponseType result = cdm_engine_->GenerateKeyRequest( - session_id_, key_set_id_, init_data, kLicenseTypeRelease, - empty_app_parameters, &request); + + CdmSessionId session_id; + CdmKeySetId key_set_id; + CdmResponseType result; + // For Android when key set IDs are used, the key set ID passed in should have + // a value and the session ID should be empty. + if (!Properties::AlwaysUseKeySetIds()) { + key_set_id = key_set_id_; + result = cdm_engine_->OpenKeySetSession(key_set_id_, nullptr, nullptr); + ASSERT_EQ(NO_ERROR, result) << "Failed for " << content_id(); + // For CE CDM, we only need the session ID to be valid. + } else { + session_id = session_id_; + } + result = cdm_engine_->GenerateKeyRequest(session_id, key_set_id, init_data, + kLicenseTypeRelease, + empty_app_parameters, &request); ASSERT_EQ(KEY_MESSAGE, result) << "Failed for " << content_id(); + if (!Properties::AlwaysUseKeySetIds()) { + cdm_engine_->CloseKeySetSession(key_set_id_); + } if (config_.dump_golden_data()) { // TODO (b/295956275) vickymin: write DumpReleaseRequest function // MessageDumper::DumpReleaseRequest(request); diff --git a/libwvdrmengine/cdm/core/test/policy_integration_test.cpp b/libwvdrmengine/cdm/core/test/policy_integration_test.cpp index 814b6d07..0249aafe 100644 --- a/libwvdrmengine/cdm/core/test/policy_integration_test.cpp +++ b/libwvdrmengine/cdm/core/test/policy_integration_test.cpp @@ -19,6 +19,7 @@ #include "license_holder.h" #include "log.h" #include "oec_device_features.h" +#include "properties.h" #include "provisioning_holder.h" #include "test_base.h" #include "test_printers.h" @@ -193,13 +194,24 @@ TEST_F(CorePIGTest, LicenseRelease1) { ASSERT_NO_FATAL_FAILURE(holder.FetchLicense()); ASSERT_NO_FATAL_FAILURE(holder.LoadLicense()); EXPECT_EQ(NO_ERROR, holder.Decrypt(key_id)); + // For Android where AlwaysUseKeySetIds() is false, the CDM engine generates + // a session separately. Thus, we close the session and only for CE CDM reopen + // it for the license release. + ASSERT_NO_FATAL_FAILURE(holder.CloseSession()); + if (Properties::AlwaysUseKeySetIds()) { + ASSERT_NO_FATAL_FAILURE(holder.OpenSession()); + ASSERT_NO_FATAL_FAILURE(holder.ReloadLicense()); + } ASSERT_NO_FATAL_FAILURE(holder.GenerateAndPostReleaseRequest( "CDM_UnlimitedStreaming_can_persist")); EXPECT_NE(NO_ERROR, holder.Decrypt(key_id)); ASSERT_NO_FATAL_FAILURE(holder.FetchRelease()); ASSERT_NO_FATAL_FAILURE(holder.LoadRelease()); EXPECT_NE(NO_ERROR, holder.Decrypt(key_id)); - ASSERT_NO_FATAL_FAILURE(holder.CloseSession()); + // For CE CDM, we can close the session after we have gotten the release. + if (Properties::AlwaysUseKeySetIds()) { + ASSERT_NO_FATAL_FAILURE(holder.CloseSession()); + } } /** @@ -219,11 +231,22 @@ TEST_F(CorePIGTest, LicenseRelease2) { ASSERT_NO_FATAL_FAILURE(holder.FetchLicense()); ASSERT_NO_FATAL_FAILURE(holder.LoadLicense()); wvutil::TestSleep::Sleep(10); + // For Android where AlwaysUseKeySetIds() is false, the CDM engine generates + // a session separately. Thus, we close the session and only for CE CDM reopen + // it for the license release. + ASSERT_NO_FATAL_FAILURE(holder.CloseSession()); + if (Properties::AlwaysUseKeySetIds()) { + ASSERT_NO_FATAL_FAILURE(holder.OpenSession()); + ASSERT_NO_FATAL_FAILURE(holder.ReloadLicense()); + } ASSERT_NO_FATAL_FAILURE(holder.GenerateAndPostReleaseRequest( "CDM_UnlimitedStreaming_can_persist")); ASSERT_NO_FATAL_FAILURE(holder.FetchRelease()); ASSERT_NO_FATAL_FAILURE(holder.LoadRelease()); - ASSERT_NO_FATAL_FAILURE(holder.CloseSession()); + // For CE CDM, we can close the session after we have gotten the release. + if (Properties::AlwaysUseKeySetIds()) { + ASSERT_NO_FATAL_FAILURE(holder.CloseSession()); + } } TEST_F(CorePIGTest, CastReceiverProvisioningUsingCdm) {