diff --git a/libwvdrmengine/cdm/core/include/cdm_engine.h b/libwvdrmengine/cdm/core/include/cdm_engine.h index e9efaa04..5c6c767f 100644 --- a/libwvdrmengine/cdm/core/include/cdm_engine.h +++ b/libwvdrmengine/cdm/core/include/cdm_engine.h @@ -32,11 +32,13 @@ class CdmEngine { // Session related methods virtual CdmResponseType OpenSession(const CdmKeySystem& key_system, const CdmClientPropertySet* property_set, + WvCdmEventListener* event_listener, CdmSessionId* session_id); virtual CdmResponseType CloseSession(const CdmSessionId& session_id); virtual CdmResponseType OpenKeySetSession( - const CdmKeySetId& key_set_id, const CdmClientPropertySet* property_set); + const CdmKeySetId& key_set_id, const CdmClientPropertySet* property_set, + WvCdmEventListener* event_listener); virtual CdmResponseType CloseKeySetSession(const CdmKeySetId& key_set_id); // License related methods @@ -138,25 +140,17 @@ class CdmEngine { virtual bool IsKeyLoaded(const KeyId& key_id); virtual bool FindSessionForKey(const KeyId& key_id, CdmSessionId* sessionId); - // Event listener related methods. - - // We assume that the WvCdmEventListener is asynchronous -- i.e. an event - // should be dispatched to another thread which actually does the work. In - // particular, if a synchronous listener calls OpenSession or CloseSession, - // the thread will dead lock. - // Returns false if listener already attached. - virtual bool AttachEventListener(const CdmSessionId& session_id, - WvCdmEventListener* listener); - // Returns true if listener was detached. - virtual bool DetachEventListener(const CdmSessionId& session_id, - WvCdmEventListener* listener); - // Used for notifying the Max-Res Engine of resolution changes virtual void NotifyResolution(const CdmSessionId& session_id, uint32_t width, uint32_t height); // Timer expiration method. This method is not re-entrant -- there can be // only one timer. + // This method triggers appropriate event callbacks from |event_listener_|, + // which is assumed to be asynchronous -- i.e. an event should be dispatched + // to another thread which does the actual work. In particular, if a + // synchronous listener calls OpenSession or CloseSession, the thread will + // dead lock. virtual void OnTimerEvent(); private: diff --git a/libwvdrmengine/cdm/core/include/cdm_session.h b/libwvdrmengine/cdm/core/include/cdm_session.h index 3b2ca841..64e60a67 100644 --- a/libwvdrmengine/cdm/core/include/cdm_session.h +++ b/libwvdrmengine/cdm/core/include/cdm_session.h @@ -21,7 +21,8 @@ class WvCdmEventListener; class CdmSession { public: - explicit CdmSession(const CdmClientPropertySet* cdm_client_property_set); + CdmSession(const CdmClientPropertySet* cdm_client_property_set, + WvCdmEventListener* event_listener); virtual ~CdmSession(); virtual CdmResponseType Init(); @@ -74,10 +75,6 @@ class CdmSession { virtual bool IsKeyLoaded(const KeyId& key_id); - // See comments for CdmEngine::AttachEventListener/DetachEventListener. - virtual bool AttachEventListener(WvCdmEventListener* listener); - virtual bool DetachEventListener(WvCdmEventListener* listener); - // Used for notifying the Policy Engine of resolution changes virtual void NotifyResolution(uint32_t width, uint32_t height); @@ -112,10 +109,7 @@ class CdmSession { bool DeleteLicense(); private: - // Internal constructor - void Create(CdmLicense* license_parser, CryptoSession* crypto_session, - PolicyEngine* policy_engine, DeviceFiles* file_handle, - const CdmClientPropertySet* cdm_client_property_set); + friend class CdmSessionTest; // Generate unique ID for each new session. CdmSessionId GenerateSessionId(); @@ -123,9 +117,17 @@ class CdmSession { CdmResponseType StoreLicense(); bool StoreLicense(DeviceFiles::LicenseState state); + + // These setters are for testing only. Takes ownership of the pointers. + void set_license_parser(CdmLicense* license_parser); + void set_crypto_session(CryptoSession* crypto_session); + void set_policy_engine(PolicyEngine* policy_engine); + void set_file_handle(DeviceFiles* file_handle); + // instance variables bool initialized_; CdmSessionId session_id_; + WvCdmEventListener* event_listener_; scoped_ptr license_parser_; scoped_ptr crypto_session_; scoped_ptr policy_engine_; @@ -156,18 +158,6 @@ class CdmSession { // license type release and offline related information CdmKeySetId key_set_id_; - std::set listeners_; - - // For testing only - // Takes ownership of license_parser, crypto_session, policy_engine - // and device_files - CdmSession(CdmLicense* license_parser, CryptoSession* crypto_session, - PolicyEngine* policy_engine, DeviceFiles* file_handle, - const CdmClientPropertySet* cdm_client_property_set); -#if defined(UNIT_TEST) - friend class CdmSessionTest; -#endif - CORE_DISALLOW_COPY_AND_ASSIGN(CdmSession); }; diff --git a/libwvdrmengine/cdm/core/include/policy_engine.h b/libwvdrmengine/cdm/core/include/policy_engine.h index 1df84f80..6ee93e91 100644 --- a/libwvdrmengine/cdm/core/include/policy_engine.h +++ b/libwvdrmengine/cdm/core/include/policy_engine.h @@ -7,6 +7,7 @@ #include "license_protocol.pb.h" #include "max_res_engine.h" +#include "scoped_ptr.h" #include "wv_cdm_types.h" namespace wvcdm { @@ -15,7 +16,6 @@ using video_widevine_server::sdk::LicenseIdentification; class Clock; class CryptoSession; -class PolicyEngineTest; // This acts as an oracle that basically says "Yes(true) you may still decrypt // or no(false) you may not decrypt this data anymore." @@ -78,6 +78,8 @@ class PolicyEngine { bool IsLicenseForFuture() { return license_state_ == kLicenseStatePending; } private: + friend class PolicyEngineTest; + typedef enum { kLicenseStateInitial, kLicenseStatePending, // if license is issued for sometime in the future @@ -87,8 +89,6 @@ class PolicyEngine { kLicenseStateExpired } LicenseState; - void Init(Clock* clock); - int64_t GetLicenseDurationRemaining(int64_t current_time); int64_t GetPlaybackDurationRemaining(int64_t current_time); @@ -98,6 +98,9 @@ class PolicyEngine { void UpdateRenewalRequest(int64_t current_time); + // These setters are for testing only. Takes ownership of the pointers. + void set_clock(Clock* clock); + LicenseState license_state_; bool can_decrypt_; @@ -124,11 +127,7 @@ class PolicyEngine { int64_t policy_max_duration_seconds_; MaxResEngine max_res_engine_; - Clock* clock_; - - // For testing - friend class PolicyEngineTest; - PolicyEngine(CryptoSession* crypto_session, Clock* clock); + scoped_ptr clock_; CORE_DISALLOW_COPY_AND_ASSIGN(PolicyEngine); }; diff --git a/libwvdrmengine/cdm/core/include/wv_cdm_event_listener.h b/libwvdrmengine/cdm/core/include/wv_cdm_event_listener.h index 35fca737..d01231fd 100644 --- a/libwvdrmengine/cdm/core/include/wv_cdm_event_listener.h +++ b/libwvdrmengine/cdm/core/include/wv_cdm_event_listener.h @@ -8,9 +8,6 @@ namespace wvcdm { // Listener for events from the Content Decryption Module. -// The caller of the CDM API must provide an implementation for OnEvent -// and signal its intent by using the Attach/DetachEventListener methods -// in the WvContentDecryptionModule class. class WvCdmEventListener { public: WvCdmEventListener() {} diff --git a/libwvdrmengine/cdm/core/src/cdm_engine.cpp b/libwvdrmengine/cdm/core/src/cdm_engine.cpp index f2b74e29..1e21f4b6 100644 --- a/libwvdrmengine/cdm/core/src/cdm_engine.cpp +++ b/libwvdrmengine/cdm/core/src/cdm_engine.cpp @@ -76,6 +76,7 @@ CdmEngine::~CdmEngine() { CdmResponseType CdmEngine::OpenSession(const CdmKeySystem& key_system, const CdmClientPropertySet* property_set, + WvCdmEventListener* event_listener, CdmSessionId* session_id) { LOGI("CdmEngine::OpenSession"); @@ -89,7 +90,8 @@ CdmResponseType CdmEngine::OpenSession(const CdmKeySystem& key_system, return KEY_ERROR; } - scoped_ptr new_session(new CdmSession(property_set)); + scoped_ptr new_session( + new CdmSession(property_set, event_listener)); if (new_session->session_id().empty()) { LOGE("CdmEngine::OpenSession: failure to generate session ID"); return UNKNOWN_ERROR; @@ -112,7 +114,8 @@ CdmResponseType CdmEngine::OpenSession(const CdmKeySystem& key_system, } CdmResponseType CdmEngine::OpenKeySetSession( - const CdmKeySetId& key_set_id, const CdmClientPropertySet* property_set) { + const CdmKeySetId& key_set_id, const CdmClientPropertySet* property_set, + WvCdmEventListener* event_listener) { LOGI("CdmEngine::OpenKeySetSession"); if (key_set_id.empty()) { @@ -121,7 +124,8 @@ CdmResponseType CdmEngine::OpenKeySetSession( } CdmSessionId session_id; - CdmResponseType sts = OpenSession(KEY_SYSTEM, property_set, &session_id); + CdmResponseType sts = + OpenSession(KEY_SYSTEM, property_set, event_listener, &session_id); if (sts != NO_ERROR) return sts; @@ -587,7 +591,7 @@ CdmResponseType CdmEngine::GetUsageInfo(const std::string& app_id, } usage_property_set_->set_security_level(kLevelDefault); usage_property_set_->set_app_id(app_id); - usage_session_.reset(new CdmSession(usage_property_set_.get())); + usage_session_.reset(new CdmSession(usage_property_set_.get(), NULL)); CdmResponseType status = usage_session_->Init(); if (NO_ERROR != status) { LOGE("CdmEngine::GetUsageInfo: session init error"); @@ -605,7 +609,7 @@ CdmResponseType CdmEngine::GetUsageInfo(const std::string& app_id, &license_response)) { usage_property_set_->set_security_level(kLevel3); usage_property_set_->set_app_id(app_id); - usage_session_.reset(new CdmSession(usage_property_set_.get())); + usage_session_.reset(new CdmSession(usage_property_set_.get(), NULL)); status = usage_session_->Init(); if (NO_ERROR != status) { LOGE("CdmEngine::GetUsageInfo: session init error"); @@ -673,7 +677,7 @@ CdmResponseType CdmEngine::GetUsageInfo(const std::string& app_id, usage_property_set_->set_security_level(requested_security_level); usage_property_set_->set_app_id(app_id); - usage_session_.reset(new CdmSession(usage_property_set_.get())); + usage_session_.reset(new CdmSession(usage_property_set_.get(), NULL)); CdmResponseType status = usage_session_->Init(); if (NO_ERROR != status) { @@ -856,26 +860,6 @@ bool CdmEngine::FindSessionForKey(const KeyId& key_id, return false; } -bool CdmEngine::AttachEventListener(const CdmSessionId& session_id, - WvCdmEventListener* listener) { - CdmSessionMap::iterator iter = sessions_.find(session_id); - if (iter == sessions_.end()) { - return false; - } - - return iter->second->AttachEventListener(listener); -} - -bool CdmEngine::DetachEventListener(const CdmSessionId& session_id, - WvCdmEventListener* listener) { - CdmSessionMap::iterator iter = sessions_.find(session_id); - if (iter == sessions_.end()) { - return false; - } - - return iter->second->DetachEventListener(listener); -} - void CdmEngine::NotifyResolution(const CdmSessionId& session_id, uint32_t width, uint32_t height) { CdmSessionMap::iterator iter = sessions_.find(session_id); diff --git a/libwvdrmengine/cdm/core/src/cdm_session.cpp b/libwvdrmengine/cdm/core/src/cdm_session.cpp index e3ff2e36..016e7a97 100644 --- a/libwvdrmengine/cdm/core/src/cdm_session.cpp +++ b/libwvdrmengine/cdm/core/src/cdm_session.cpp @@ -23,68 +23,32 @@ const size_t kKeySetIdLength = 14; namespace wvcdm { -typedef std::set::iterator CdmEventListenerIter; - -CdmSession::CdmSession(const CdmClientPropertySet* cdm_client_property_set) { - CryptoSession* crypto_session = new CryptoSession(); - Create(new CdmLicense(), crypto_session, new PolicyEngine(crypto_session), - new DeviceFiles(), cdm_client_property_set); -} - -CdmSession::CdmSession(CdmLicense* license_parser, - CryptoSession* crypto_session, - PolicyEngine* policy_engine, DeviceFiles* file_handle, - const CdmClientPropertySet* cdm_client_property_set) { - Create(license_parser, crypto_session, policy_engine, file_handle, - cdm_client_property_set); -} - -void CdmSession::Create(CdmLicense* license_parser, - CryptoSession* crypto_session, - PolicyEngine* policy_engine, DeviceFiles* file_handle, - const CdmClientPropertySet* cdm_client_property_set) { - // Just return on failures. Failures will be signaled in Init. - if (NULL == license_parser) { - LOGE("CdmSession::Create: License parser not provided"); - return; - } - if (NULL == crypto_session) { - LOGE("CdmSession::Create: Crypto session not provided"); - return; - } - if (NULL == policy_engine) { - LOGE("CdmSession::Create: Policy engine not provided"); - return; - } - if (NULL == file_handle) { - LOGE("CdmSession::Create: Device files not provided"); - return; - } - initialized_ = false; - session_id_ = GenerateSessionId(); - license_parser_.reset(license_parser); - crypto_session_.reset(crypto_session); - file_handle_.reset(file_handle); - policy_engine_.reset(policy_engine); - license_received_ = false; - is_offline_ = false; - is_release_ = false; - is_initial_usage_update_ = true; - is_usage_update_needed_ = false; - is_initial_decryption_ = true; - has_decrypted_since_last_report_ = false; - requested_security_level_ = kLevelDefault; - if (NULL != cdm_client_property_set) { - if (QUERY_VALUE_SECURITY_LEVEL_L3.compare( - cdm_client_property_set->security_level()) == 0) { +CdmSession::CdmSession(const CdmClientPropertySet* cdm_client_property_set, + WvCdmEventListener* event_listener) + : initialized_(false), + session_id_(GenerateSessionId()), + event_listener_(event_listener), + license_parser_(new CdmLicense), + crypto_session_(new CryptoSession), + policy_engine_(new PolicyEngine(crypto_session_.get())), + file_handle_(new DeviceFiles), + license_received_(false), + is_offline_(false), + is_release_(false), + security_level_(kSecurityLevelUninitialized), + requested_security_level_(kLevelDefault), + is_initial_decryption_(true), + has_decrypted_since_last_report_(false), + is_initial_usage_update_(true), + is_usage_update_needed_(false) { + if (cdm_client_property_set) { + if (cdm_client_property_set->security_level() == + QUERY_VALUE_SECURITY_LEVEL_L3) { requested_security_level_ = kLevel3; + security_level_ = kSecurityLevelL3; } Properties::AddSessionPropertySet(session_id_, cdm_client_property_set); } - security_level_ = - GetRequestedSecurityLevel() == kLevel3 ? kSecurityLevelL3 - : kSecurityLevelUninitialized; - app_id_.clear(); } CdmSession::~CdmSession() { Properties::RemoveSessionPropertySet(session_id_); } @@ -546,15 +510,6 @@ bool CdmSession::DeleteLicense() { } } -bool CdmSession::AttachEventListener(WvCdmEventListener* listener) { - std::pair result = listeners_.insert(listener); - return result.second; -} - -bool CdmSession::DetachEventListener(WvCdmEventListener* listener) { - return (listeners_.erase(listener) == 1); -} - void CdmSession::NotifyResolution(uint32_t width, uint32_t height) { policy_engine_->NotifyResolution(width, height); } @@ -573,19 +528,14 @@ void CdmSession::OnTimerEvent(bool update_usage) { policy_engine_->OnTimerEvent(&event_occurred, &event); if (event_occurred) { - for (CdmEventListenerIter iter = listeners_.begin(); - iter != listeners_.end(); ++iter) { - (*iter)->OnEvent(session_id_, event); - } + if (event_listener_) event_listener_->OnEvent(session_id_, event); } } void CdmSession::OnKeyReleaseEvent(const CdmKeySetId& key_set_id) { if (key_set_id_ == key_set_id) { - for (CdmEventListenerIter iter = listeners_.begin(); - iter != listeners_.end(); ++iter) { - (*iter)->OnEvent(session_id_, LICENSE_EXPIRED_EVENT); - } + if (event_listener_) + event_listener_->OnEvent(session_id_, LICENSE_EXPIRED_EVENT); } } @@ -610,4 +560,20 @@ CdmResponseType CdmSession::ReleaseCrypto() { return NO_ERROR; } +void CdmSession::set_license_parser(CdmLicense* license_parser) { + license_parser_.reset(license_parser); +} + +void CdmSession::set_crypto_session(CryptoSession* crypto_session) { + crypto_session_.reset(crypto_session); +} + +void CdmSession::set_policy_engine(PolicyEngine* policy_engine) { + policy_engine_.reset(policy_engine); +} + +void CdmSession::set_file_handle(DeviceFiles* file_handle) { + file_handle_.reset(file_handle); +} + } // namespace wvcdm diff --git a/libwvdrmengine/cdm/core/src/policy_engine.cpp b/libwvdrmengine/cdm/core/src/policy_engine.cpp index 15ad9c9e..0916d559 100644 --- a/libwvdrmengine/cdm/core/src/policy_engine.cpp +++ b/libwvdrmengine/cdm/core/src/policy_engine.cpp @@ -17,29 +17,17 @@ namespace wvcdm { PolicyEngine::PolicyEngine(CryptoSession* crypto_session) - : max_res_engine_(crypto_session) { - Init(new Clock()); -} + : license_state_(kLicenseStateInitial), + can_decrypt_(false), + license_start_time_(0), + playback_start_time_(0), + last_playback_time_(0), + next_renewal_time_(0), + policy_max_duration_seconds_(0), + max_res_engine_(crypto_session), + clock_(new Clock) {} -PolicyEngine::PolicyEngine(CryptoSession* crypto_session, Clock* clock) - : max_res_engine_(crypto_session) { - Init(clock); -} - -PolicyEngine::~PolicyEngine() { - if (clock_) delete clock_; -} - -void PolicyEngine::Init(Clock* clock) { - license_state_ = kLicenseStateInitial; - can_decrypt_ = false; - license_start_time_ = 0; - playback_start_time_ = 0; - last_playback_time_ = 0; - next_renewal_time_ = 0; - policy_max_duration_seconds_ = 0; - clock_ = clock; -} +PolicyEngine::~PolicyEngine() {} bool PolicyEngine::CanDecrypt(const KeyId& key_id) { return can_decrypt_ && max_res_engine_.CanDecrypt(key_id); @@ -316,4 +304,6 @@ bool PolicyEngine::IsRenewalRetryIntervalExpired(int64_t current_time) { next_renewal_time_ <= current_time; } +void PolicyEngine::set_clock(Clock* clock) { clock_.reset(clock); } + } // wvcdm diff --git a/libwvdrmengine/cdm/core/test/cdm_engine_test.cpp b/libwvdrmengine/cdm/core/test/cdm_engine_test.cpp index c967c6f6..0ba413e1 100644 --- a/libwvdrmengine/cdm/core/test/cdm_engine_test.cpp +++ b/libwvdrmengine/cdm/core/test/cdm_engine_test.cpp @@ -47,10 +47,10 @@ class WvCdmEngineTest : public testing::Test { public: virtual void SetUp() { CdmResponseType status = - cdm_engine_.OpenSession(g_key_system, NULL, &session_id_); + cdm_engine_.OpenSession(g_key_system, NULL, NULL, &session_id_); if (status == NEED_PROVISIONING) { Provision(); - status = cdm_engine_.OpenSession(g_key_system, NULL, &session_id_); + status = cdm_engine_.OpenSession(g_key_system, NULL, NULL, &session_id_); } ASSERT_EQ(NO_ERROR, status); ASSERT_NE("", session_id_) << "Could not open CDM session."; diff --git a/libwvdrmengine/cdm/core/test/cdm_session_unittest.cpp b/libwvdrmengine/cdm/core/test/cdm_session_unittest.cpp index 3dbffe1c..675feb50 100644 --- a/libwvdrmengine/cdm/core/test/cdm_session_unittest.cpp +++ b/libwvdrmengine/cdm/core/test/cdm_session_unittest.cpp @@ -5,6 +5,7 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" #include "properties.h" +#include "scoped_ptr.h" #include "string_conversions.h" #include "test_printers.h" @@ -126,25 +127,19 @@ class MockCdmLicense : public CdmLicense { class CdmSessionTest : public ::testing::Test { protected: virtual void SetUp() { + cdm_session_.reset(new CdmSession(NULL, NULL)); + // Inject testing mocks. license_parser_ = new MockCdmLicense(); + cdm_session_->set_license_parser(license_parser_); crypto_session_ = new MockCryptoSession(); + cdm_session_->set_crypto_session(crypto_session_); policy_engine_ = new MockPolicyEngine(); + cdm_session_->set_policy_engine(policy_engine_); file_handle_ = new MockDeviceFiles(); + cdm_session_->set_file_handle(file_handle_); } - virtual void TearDown() { - if (cdm_session_) delete cdm_session_; - } - - void CreateSession() { CreateSession(NULL); } - - void CreateSession(const CdmClientPropertySet* cdm_client_property_set) { - cdm_session_ = - new CdmSession(license_parser_, crypto_session_, policy_engine_, - file_handle_, cdm_client_property_set); - } - - CdmSession* cdm_session_; + scoped_ptr cdm_session_; MockCdmLicense* license_parser_; MockCryptoSession* crypto_session_; MockPolicyEngine* policy_engine_; @@ -173,7 +168,6 @@ TEST_F(CdmSessionTest, InitWithCertificate) { Properties::set_use_certificates_as_identification(true); - CreateSession(); ASSERT_EQ(NO_ERROR, cdm_session_->Init()); } @@ -195,7 +189,6 @@ TEST_F(CdmSessionTest, InitWithKeybox) { Properties::set_use_certificates_as_identification(false); - CreateSession(); ASSERT_EQ(NO_ERROR, cdm_session_->Init()); } @@ -221,7 +214,6 @@ TEST_F(CdmSessionTest, ReInitFail) { Properties::set_use_certificates_as_identification(true); - CreateSession(); ASSERT_EQ(NO_ERROR, cdm_session_->Init()); ASSERT_EQ(UNKNOWN_ERROR, cdm_session_->Init()); } @@ -233,7 +225,6 @@ TEST_F(CdmSessionTest, InitFailCryptoError) { Properties::set_use_certificates_as_identification(true); - CreateSession(); ASSERT_EQ(UNKNOWN_ERROR, cdm_session_->Init()); } @@ -252,7 +243,6 @@ TEST_F(CdmSessionTest, InitNeedsProvisioning) { Properties::set_use_certificates_as_identification(true); - CreateSession(); ASSERT_EQ(NEED_PROVISIONING, cdm_session_->Init()); } diff --git a/libwvdrmengine/cdm/core/test/policy_engine_unittest.cpp b/libwvdrmengine/cdm/core/test/policy_engine_unittest.cpp index 33cdf773..73282dee 100644 --- a/libwvdrmengine/cdm/core/test/policy_engine_unittest.cpp +++ b/libwvdrmengine/cdm/core/test/policy_engine_unittest.cpp @@ -10,6 +10,7 @@ #include "license.h" #include "mock_clock.h" #include "policy_engine.h" +#include "scoped_ptr.h" #include "test_printers.h" #include "wv_cdm_constants.h" @@ -58,8 +59,10 @@ using ::testing::AtLeast; class PolicyEngineTest : public ::testing::Test { protected: virtual void SetUp() { + policy_engine_.reset(new PolicyEngine(NULL)); + // Inject testing clock. mock_clock_ = new MockClock(); - policy_engine_ = new PolicyEngine(NULL, mock_clock_); + policy_engine_->set_clock(mock_clock_); license_.set_license_start_time(kLicenseStartTime); @@ -85,13 +88,6 @@ class PolicyEngineTest : public ::testing::Test { policy->set_renew_with_usage(false); } - virtual void TearDown() { - delete policy_engine_; - // Done by policy engine: delete mock_clock_; - policy_engine_ = NULL; - mock_clock_ = NULL; - } - int64_t GetMinOfRentalPlaybackLicenseDurations() { const License_Policy& policy = license_.policy(); int64_t rental_duration = policy.rental_duration_seconds(); @@ -105,7 +101,7 @@ class PolicyEngineTest : public ::testing::Test { } MockClock* mock_clock_; - PolicyEngine* policy_engine_; + scoped_ptr policy_engine_; License license_; }; diff --git a/libwvdrmengine/cdm/include/wv_content_decryption_module.h b/libwvdrmengine/cdm/include/wv_content_decryption_module.h index aaf1558b..1b0bfe1d 100644 --- a/libwvdrmengine/cdm/include/wv_content_decryption_module.h +++ b/libwvdrmengine/cdm/include/wv_content_decryption_module.h @@ -26,10 +26,10 @@ class WvContentDecryptionModule : public TimerHandler { static bool IsWebm(const std::string& init_data_type); // Session related methods - virtual CdmResponseType OpenSession( - const CdmKeySystem& key_system, - CdmClientPropertySet* property_set, - CdmSessionId* session_id); + virtual CdmResponseType OpenSession(const CdmKeySystem& key_system, + CdmClientPropertySet* property_set, + WvCdmEventListener* event_listener, + CdmSessionId* session_id); virtual CdmResponseType CloseSession(const CdmSessionId& session_id); // Construct a valid license request. @@ -103,12 +103,6 @@ class WvContentDecryptionModule : public TimerHandler { bool validate_key_id, const CdmDecryptionParameters& parameters); - // Event listener related methods - virtual bool AttachEventListener(const CdmSessionId& session_id, - WvCdmEventListener* listener); - virtual bool DetachEventListener(const CdmSessionId& session_id, - WvCdmEventListener* listener); - virtual void NotifyResolution(const CdmSessionId& session_id, uint32_t width, uint32_t height); diff --git a/libwvdrmengine/cdm/src/wv_content_decryption_module.cpp b/libwvdrmengine/cdm/src/wv_content_decryption_module.cpp index e247b823..58b09c28 100644 --- a/libwvdrmengine/cdm/src/wv_content_decryption_module.cpp +++ b/libwvdrmengine/cdm/src/wv_content_decryption_module.cpp @@ -38,16 +38,16 @@ bool WvContentDecryptionModule::IsWebm(const std::string& init_data_type) { } CdmResponseType WvContentDecryptionModule::OpenSession( - const CdmKeySystem& key_system, - CdmClientPropertySet* property_set, - CdmSessionId* session_id) { + const CdmKeySystem& key_system, CdmClientPropertySet* property_set, + WvCdmEventListener* event_listener, CdmSessionId* session_id) { if (property_set && property_set->is_session_sharing_enabled()) { AutoLock auto_lock(session_sharing_id_generation_lock_); if (property_set->session_sharing_id() == 0) property_set->set_session_sharing_id(GenerateSessionSharingId()); } - return cdm_engine_->OpenSession(key_system, property_set, session_id); + return cdm_engine_->OpenSession(key_system, property_set, event_listener, + session_id); } CdmResponseType WvContentDecryptionModule::CloseSession( @@ -69,9 +69,8 @@ CdmResponseType WvContentDecryptionModule::GenerateKeyRequest( std::string* server_url) { CdmResponseType sts; if (license_type == kLicenseTypeRelease) { - sts = cdm_engine_->OpenKeySetSession(key_set_id, property_set); - if (sts != NO_ERROR) - return sts; + sts = cdm_engine_->OpenKeySetSession(key_set_id, property_set, NULL); + if (sts != NO_ERROR) return sts; } InitializationData initialization_data(init_data_type, init_data); sts = cdm_engine_->GenerateKeyRequest(session_id, key_set_id, @@ -195,16 +194,6 @@ CdmResponseType WvContentDecryptionModule::Decrypt( return cdm_engine_->Decrypt(local_session_id, parameters); } -bool WvContentDecryptionModule::AttachEventListener( - const CdmSessionId& session_id, WvCdmEventListener* listener) { - return cdm_engine_->AttachEventListener(session_id, listener); -} - -bool WvContentDecryptionModule::DetachEventListener( - const CdmSessionId& session_id, WvCdmEventListener* listener) { - return cdm_engine_->DetachEventListener(session_id, listener); -} - void WvContentDecryptionModule::NotifyResolution(const CdmSessionId& session_id, uint32_t width, uint32_t height) { diff --git a/libwvdrmengine/cdm/test/cdm_extended_duration_test.cpp b/libwvdrmengine/cdm/test/cdm_extended_duration_test.cpp index 4ba1dd9f..8956131b 100644 --- a/libwvdrmengine/cdm/test/cdm_extended_duration_test.cpp +++ b/libwvdrmengine/cdm/test/cdm_extended_duration_test.cpp @@ -406,7 +406,7 @@ class WvCdmExtendedDurationTest : public testing::Test { void Provision() { CdmResponseType status = - decryptor_.OpenSession(g_key_system, NULL, &session_id_); + decryptor_.OpenSession(g_key_system, NULL, NULL, &session_id_); switch (status) { case NO_ERROR: decryptor_.CloseSession(session_id_); @@ -654,7 +654,7 @@ class WvCdmExtendedDurationTest : public testing::Test { } std::string GetSecurityLevel(TestWvCdmClientPropertySet* property_set) { - decryptor_.OpenSession(g_key_system, property_set, &session_id_); + decryptor_.OpenSession(g_key_system, property_set, NULL, &session_id_); CdmQueryMap query_info; EXPECT_EQ(wvcdm::NO_ERROR, decryptor_.QuerySessionStatus(session_id_, &query_info)); @@ -688,7 +688,7 @@ class WvCdmExtendedDurationTest : public testing::Test { TEST_F(WvCdmExtendedDurationTest, VerifyLicenseRequestTest) { Provision(); - decryptor_.OpenSession(g_key_system, NULL, &session_id_); + decryptor_.OpenSession(g_key_system, NULL, NULL, &session_id_); GenerateKeyRequest(g_key_id, kLicenseTypeStreaming); EXPECT_TRUE(!key_msg_.empty()); @@ -756,7 +756,7 @@ TEST_F(WvCdmExtendedDurationTest, VerifyLicenseRequestTest) { TEST_F(WvCdmExtendedDurationTest, VerifyLicenseRenewalTest) { Provision(); - decryptor_.OpenSession(g_key_system, NULL, &session_id_); + decryptor_.OpenSession(g_key_system, NULL, NULL, &session_id_); GenerateKeyRequest(g_key_id, kLicenseTypeStreaming); VerifyKeyRequestResponse(g_license_server, g_client_auth, false); @@ -848,7 +848,7 @@ TEST_F(WvCdmExtendedDurationTest, UsageOverflowTest) { EXPECT_TRUE(handle.DeleteAllUsageInfoForApp("", &provider_session_tokens)); for (size_t i = 0; i < kMaxUsageTableSize + 100; ++i) { - decryptor_.OpenSession(g_key_system, property_set, &session_id_); + decryptor_.OpenSession(g_key_system, property_set, NULL, &session_id_); std::string key_id = a2bs_hex( "000000427073736800000000" // blob size and pssh "EDEF8BA979D64ACEA3C827DCD51D21ED00000022" // Widevine system id @@ -888,7 +888,7 @@ TEST_P(WvCdmStreamingNoPstTest, UsageTest) { Unprovision(); Provision(); - decryptor_.OpenSession(g_key_system, NULL, &session_id_); + decryptor_.OpenSession(g_key_system, NULL, NULL, &session_id_); GenerateKeyRequest(g_key_id, kLicenseTypeStreaming); VerifyKeyRequestResponse(g_license_server, g_client_auth, false); @@ -967,7 +967,7 @@ TEST_P(WvCdmStreamingPstTest, UsageTest) { Unprovision(); Provision(); - decryptor_.OpenSession(g_key_system, NULL, &session_id_); + decryptor_.OpenSession(g_key_system, NULL, NULL, &session_id_); GenerateKeyRequest(kStreamingClip1PstInitData, kLicenseTypeStreaming); VerifyKeyRequestResponse(g_license_server, g_client_auth, false); @@ -1046,7 +1046,7 @@ TEST_P(WvCdmStreamingUsageReportTest, UsageTest) { Unprovision(); Provision(); - decryptor_.OpenSession(g_key_system, NULL, &session_id_); + decryptor_.OpenSession(g_key_system, NULL, NULL, &session_id_); GenerateKeyRequest(kStreamingClip1PstInitData, kLicenseTypeStreaming); VerifyKeyRequestResponse(g_license_server, g_client_auth, false); @@ -1147,7 +1147,7 @@ TEST_P(WvCdmOfflineUsageReportTest, UsageTest) { Unprovision(); Provision(); - decryptor_.OpenSession(g_key_system, NULL, &session_id_); + decryptor_.OpenSession(g_key_system, NULL, NULL, &session_id_); GenerateKeyRequest(kOfflineClip2PstInitData, kLicenseTypeOffline); VerifyKeyRequestResponse(g_license_server, g_client_auth, false); @@ -1170,7 +1170,7 @@ TEST_P(WvCdmOfflineUsageReportTest, UsageTest) { for (size_t i = 0; i < GetParam(); ++i) { session_id_.clear(); - decryptor_.OpenSession(g_key_system, NULL, &session_id_); + decryptor_.OpenSession(g_key_system, NULL, NULL, &session_id_); EXPECT_EQ(wvcdm::KEY_ADDED, decryptor_.RestoreKey(session_id_, key_set_id)); // Query and validate usage information @@ -1217,7 +1217,7 @@ TEST_P(WvCdmOfflineUsageReportTest, UsageTest) { } session_id_.clear(); - decryptor_.OpenSession(g_key_system, NULL, &session_id_); + decryptor_.OpenSession(g_key_system, NULL, NULL, &session_id_); EXPECT_EQ(wvcdm::KEY_ADDED, decryptor_.RestoreKey(session_id_, key_set_id)); // Query and validate usage information diff --git a/libwvdrmengine/cdm/test/request_license_test.cpp b/libwvdrmengine/cdm/test/request_license_test.cpp index e4009093..494f670d 100644 --- a/libwvdrmengine/cdm/test/request_license_test.cpp +++ b/libwvdrmengine/cdm/test/request_license_test.cpp @@ -636,7 +636,7 @@ class WvCdmRequestLicenseTest : public testing::Test { } CdmResponseType status = - decryptor_.OpenSession(g_key_system, property_set, &session_id_); + decryptor_.OpenSession(g_key_system, property_set, NULL, &session_id_); switch (status) { case NO_ERROR: decryptor_.CloseSession(session_id_); @@ -670,8 +670,8 @@ class WvCdmRequestLicenseTest : public testing::Test { } std::string GetSecurityLevel(TestWvCdmClientPropertySet* property_set) { - EXPECT_EQ(NO_ERROR, - decryptor_.OpenSession(g_key_system, property_set, &session_id_)); + EXPECT_EQ(NO_ERROR, decryptor_.OpenSession(g_key_system, property_set, NULL, + &session_id_)); CdmQueryMap query_info; EXPECT_EQ(wvcdm::NO_ERROR, decryptor_.QuerySessionStatus(session_id_, &query_info)); @@ -707,7 +707,7 @@ class WvCdmRequestLicenseTest : public testing::Test { }; TEST_F(WvCdmRequestLicenseTest, ProvisioningTest) { - decryptor_.OpenSession(g_key_system, NULL, &session_id_); + decryptor_.OpenSession(g_key_system, NULL, NULL, &session_id_); std::string provisioning_server_url; CdmCertificateType cert_type = kCertificateWidevine; std::string cert_authority, cert, wrapped_key; @@ -742,7 +742,7 @@ TEST_F(WvCdmRequestLicenseTest, UnprovisionTest) { } TEST_F(WvCdmRequestLicenseTest, ProvisioningRetryTest) { - decryptor_.OpenSession(g_key_system, NULL, &session_id_); + decryptor_.OpenSession(g_key_system, NULL, NULL, &session_id_); std::string provisioning_server_url; CdmCertificateType cert_type = kCertificateWidevine; std::string cert_authority, cert, wrapped_key; @@ -776,7 +776,7 @@ TEST_F(WvCdmRequestLicenseTest, ProvisioningRetryTest) { } TEST_F(WvCdmRequestLicenseTest, DISABLED_X509ProvisioningTest) { - decryptor_.OpenSession(g_key_system, NULL, &session_id_); + decryptor_.OpenSession(g_key_system, NULL, NULL, &session_id_); std::string provisioning_server_url; CdmCertificateType cert_type = kCertificateX509; // TODO(rfrias): insert appropriate CA here @@ -808,12 +808,12 @@ TEST_F(WvCdmRequestLicenseTest, PropertySetTest) { property_set_L1.set_security_level(QUERY_VALUE_SECURITY_LEVEL_L1); property_set_L1.set_use_privacy_mode(true); - decryptor_.OpenSession(g_key_system, &property_set_L1, &session_id_L1); + decryptor_.OpenSession(g_key_system, &property_set_L1, NULL, &session_id_L1); property_set_L3.set_security_level(QUERY_VALUE_SECURITY_LEVEL_L3); property_set_L3.set_use_privacy_mode(false); - CdmResponseType sts = - decryptor_.OpenSession(g_key_system, &property_set_L3, &session_id_L3); + CdmResponseType sts = decryptor_.OpenSession(g_key_system, &property_set_L3, + NULL, &session_id_L3); if (NEED_PROVISIONING == sts) { std::string provisioning_server_url; @@ -829,13 +829,13 @@ TEST_F(WvCdmRequestLicenseTest, PropertySetTest) { EXPECT_EQ(NO_ERROR, decryptor_.HandleProvisioningResponse(response, &cert, &wrapped_key)); EXPECT_EQ(NO_ERROR, decryptor_.OpenSession(g_key_system, &property_set_L3, - &session_id_L3)); + NULL, &session_id_L3)); } else { EXPECT_EQ(NO_ERROR, sts); } property_set_Ln.set_security_level(""); - decryptor_.OpenSession(g_key_system, &property_set_Ln, &session_id_Ln); + decryptor_.OpenSession(g_key_system, &property_set_Ln, NULL, &session_id_Ln); std::string security_level; EXPECT_TRUE(Properties::GetSecurityLevel(session_id_L1, &security_level)); @@ -874,8 +874,9 @@ TEST_F(WvCdmRequestLicenseTest, ForceL3Test) { handle.SetTestFile(&file); EXPECT_TRUE(handle.DeleteAllFiles()); - EXPECT_EQ(NEED_PROVISIONING, - decryptor_.OpenSession(g_key_system, &property_set, &session_id_)); + EXPECT_EQ( + NEED_PROVISIONING, + decryptor_.OpenSession(g_key_system, &property_set, NULL, &session_id_)); std::string provisioning_server_url; CdmCertificateType cert_type = kCertificateWidevine; std::string cert_authority, cert, wrapped_key; @@ -889,8 +890,8 @@ TEST_F(WvCdmRequestLicenseTest, ForceL3Test) { EXPECT_EQ(NO_ERROR, decryptor_.HandleProvisioningResponse(response, &cert, &wrapped_key)); - EXPECT_EQ(NO_ERROR, - decryptor_.OpenSession(g_key_system, &property_set, &session_id_)); + EXPECT_EQ(NO_ERROR, decryptor_.OpenSession(g_key_system, &property_set, NULL, + &session_id_)); GenerateKeyRequest(g_key_id, kLicenseTypeStreaming); VerifyKeyRequestResponse(g_license_server, g_client_auth, false); decryptor_.CloseSession(session_id_); @@ -900,7 +901,7 @@ TEST_F(WvCdmRequestLicenseTest, PrivacyModeTest) { TestWvCdmClientPropertySet property_set; property_set.set_use_privacy_mode(true); - decryptor_.OpenSession(g_key_system, &property_set, &session_id_); + decryptor_.OpenSession(g_key_system, &property_set, NULL, &session_id_); GenerateKeyRequest(g_key_id, kLicenseTypeStreaming); std::string resp = GetKeyRequestResponse(g_license_server, g_client_auth); @@ -916,21 +917,21 @@ TEST_F(WvCdmRequestLicenseTest, PrivacyModeWithServiceCertificateTest) { property_set.set_use_privacy_mode(true); property_set.set_service_certificate(a2bs_hex(kServiceCertificate)); - decryptor_.OpenSession(g_key_system, &property_set, &session_id_); + decryptor_.OpenSession(g_key_system, &property_set, NULL, &session_id_); GenerateKeyRequest(g_key_id, kLicenseTypeStreaming); VerifyKeyRequestResponse(g_license_server, g_client_auth, false); decryptor_.CloseSession(session_id_); } TEST_F(WvCdmRequestLicenseTest, BaseMessageTest) { - decryptor_.OpenSession(g_key_system, NULL, &session_id_); + decryptor_.OpenSession(g_key_system, NULL, NULL, &session_id_); GenerateKeyRequest(g_key_id, kLicenseTypeStreaming); GetKeyRequestResponse(g_license_server, g_client_auth); decryptor_.CloseSession(session_id_); } TEST_F(WvCdmRequestLicenseTest, WrongMessageTest) { - decryptor_.OpenSession(g_key_system, NULL, &session_id_); + decryptor_.OpenSession(g_key_system, NULL, NULL, &session_id_); std::string wrong_message = wvcdm::a2bs_hex(g_wrong_key_id); GenerateKeyRequest(wrong_message, kLicenseTypeStreaming); @@ -958,7 +959,7 @@ TEST_F(WvCdmRequestLicenseTest, WrongMessageTest) { } TEST_F(WvCdmRequestLicenseTest, AddStreamingKeyTest) { - decryptor_.OpenSession(g_key_system, NULL, &session_id_); + decryptor_.OpenSession(g_key_system, NULL, NULL, &session_id_); GenerateKeyRequest(g_key_id, kLicenseTypeStreaming); VerifyKeyRequestResponse(g_license_server, g_client_auth, false); decryptor_.CloseSession(session_id_); @@ -973,7 +974,7 @@ TEST_F(WvCdmRequestLicenseTest, AddKeyOfflineTest) { std::string client_auth; GetOfflineConfiguration(&key_id, &client_auth); - decryptor_.OpenSession(g_key_system, NULL, &session_id_); + decryptor_.OpenSession(g_key_system, NULL, NULL, &session_id_); GenerateKeyRequest(key_id, kLicenseTypeOffline); VerifyKeyRequestResponse(g_license_server, client_auth, false); decryptor_.CloseSession(session_id_); @@ -988,7 +989,7 @@ TEST_F(WvCdmRequestLicenseTest, RestoreOfflineKeyTest) { std::string client_auth; GetOfflineConfiguration(&key_id, &client_auth); - decryptor_.OpenSession(g_key_system, NULL, &session_id_); + decryptor_.OpenSession(g_key_system, NULL, NULL, &session_id_); GenerateKeyRequest(key_id, kLicenseTypeOffline); VerifyKeyRequestResponse(g_license_server, client_auth, false); @@ -997,7 +998,7 @@ TEST_F(WvCdmRequestLicenseTest, RestoreOfflineKeyTest) { decryptor_.CloseSession(session_id_); session_id_.clear(); - decryptor_.OpenSession(g_key_system, NULL, &session_id_); + decryptor_.OpenSession(g_key_system, NULL, NULL, &session_id_); EXPECT_EQ(wvcdm::KEY_ADDED, decryptor_.RestoreKey(session_id_, key_set_id)); decryptor_.CloseSession(session_id_); } @@ -1011,7 +1012,7 @@ TEST_F(WvCdmRequestLicenseTest, ReleaseOfflineKeyTest) { std::string client_auth; GetOfflineConfiguration(&key_id, &client_auth); - decryptor_.OpenSession(g_key_system, NULL, &session_id_); + decryptor_.OpenSession(g_key_system, NULL, NULL, &session_id_); GenerateKeyRequest(key_id, kLicenseTypeOffline); VerifyKeyRequestResponse(g_license_server, client_auth, false); @@ -1021,7 +1022,7 @@ TEST_F(WvCdmRequestLicenseTest, ReleaseOfflineKeyTest) { session_id_.clear(); key_set_id_.clear(); - decryptor_.OpenSession(g_key_system, NULL, &session_id_); + decryptor_.OpenSession(g_key_system, NULL, NULL, &session_id_); EXPECT_EQ(wvcdm::KEY_ADDED, decryptor_.RestoreKey(session_id_, key_set_id)); decryptor_.CloseSession(session_id_); @@ -1041,7 +1042,7 @@ TEST_F(WvCdmRequestLicenseTest, ReleaseRetryOfflineKeyTest) { std::string client_auth; GetOfflineConfiguration(&key_id, &client_auth); - decryptor_.OpenSession(g_key_system, NULL, &session_id_); + decryptor_.OpenSession(g_key_system, NULL, NULL, &session_id_); GenerateKeyRequest(key_id, kLicenseTypeOffline); VerifyKeyRequestResponse(g_license_server, client_auth, false); @@ -1051,7 +1052,7 @@ TEST_F(WvCdmRequestLicenseTest, ReleaseRetryOfflineKeyTest) { session_id_.clear(); key_set_id_.clear(); - decryptor_.OpenSession(g_key_system, NULL, &session_id_); + decryptor_.OpenSession(g_key_system, NULL, NULL, &session_id_); EXPECT_EQ(wvcdm::KEY_ADDED, decryptor_.RestoreKey(session_id_, key_set_id)); decryptor_.CloseSession(session_id_); @@ -1060,7 +1061,7 @@ TEST_F(WvCdmRequestLicenseTest, ReleaseRetryOfflineKeyTest) { GenerateKeyRelease(key_set_id); session_id_.clear(); - decryptor_.OpenSession(g_key_system, NULL, &session_id_); + decryptor_.OpenSession(g_key_system, NULL, NULL, &session_id_); EXPECT_EQ(wvcdm::UNKNOWN_ERROR, decryptor_.RestoreKey(session_id_, key_set_id)); decryptor_.CloseSession(session_id_); @@ -1083,7 +1084,7 @@ TEST_F(WvCdmRequestLicenseTest, ReleaseRetryL3OfflineKeyTest) { GetOfflineConfiguration(&key_id, &client_auth); CdmResponseType sts = - decryptor_.OpenSession(g_key_system, &property_set, &session_id_); + decryptor_.OpenSession(g_key_system, &property_set, NULL, &session_id_); if (NEED_PROVISIONING == sts) { std::string provisioning_server_url; @@ -1099,12 +1100,12 @@ TEST_F(WvCdmRequestLicenseTest, ReleaseRetryL3OfflineKeyTest) { EXPECT_EQ(NO_ERROR, decryptor_.HandleProvisioningResponse(response, &cert, &wrapped_key)); EXPECT_EQ(NO_ERROR, decryptor_.OpenSession(g_key_system, &property_set, - &session_id_)); + NULL, &session_id_)); } else { EXPECT_EQ(NO_ERROR, sts); } - decryptor_.OpenSession(g_key_system, &property_set, &session_id_); + decryptor_.OpenSession(g_key_system, &property_set, NULL, &session_id_); GenerateKeyRequest(key_id, kLicenseTypeOffline, &property_set); VerifyKeyRequestResponse(g_license_server, client_auth, false); @@ -1114,7 +1115,7 @@ TEST_F(WvCdmRequestLicenseTest, ReleaseRetryL3OfflineKeyTest) { session_id_.clear(); key_set_id_.clear(); - decryptor_.OpenSession(g_key_system, &property_set, &session_id_); + decryptor_.OpenSession(g_key_system, &property_set, NULL, &session_id_); EXPECT_EQ(wvcdm::KEY_ADDED, decryptor_.RestoreKey(session_id_, key_set_id)); decryptor_.CloseSession(session_id_); @@ -1123,7 +1124,7 @@ TEST_F(WvCdmRequestLicenseTest, ReleaseRetryL3OfflineKeyTest) { GenerateKeyRelease(key_set_id, &property_set); session_id_.clear(); - decryptor_.OpenSession(g_key_system, &property_set, &session_id_); + decryptor_.OpenSession(g_key_system, &property_set, NULL, &session_id_); EXPECT_EQ( wvcdm::UNKNOWN_ERROR, decryptor_.RestoreKey(session_id_, key_set_id)); decryptor_.CloseSession(session_id_); @@ -1144,7 +1145,7 @@ TEST_F(WvCdmRequestLicenseTest, ExpiryOnReleaseOfflineKeyTest) { std::string client_auth; GetOfflineConfiguration(&key_id, &client_auth); - decryptor_.OpenSession(g_key_system, NULL, &session_id_); + decryptor_.OpenSession(g_key_system, NULL, NULL, &session_id_); GenerateKeyRequest(key_id, kLicenseTypeOffline); VerifyKeyRequestResponse(g_license_server, client_auth, false); @@ -1154,10 +1155,9 @@ TEST_F(WvCdmRequestLicenseTest, ExpiryOnReleaseOfflineKeyTest) { session_id_.clear(); key_set_id_.clear(); - decryptor_.OpenSession(g_key_system, NULL, &session_id_); - CdmSessionId restore_session_id = session_id_; TestWvCdmEventListener listener; - EXPECT_TRUE(decryptor_.AttachEventListener(restore_session_id, &listener)); + decryptor_.OpenSession(g_key_system, NULL, &listener, &session_id_); + CdmSessionId restore_session_id = session_id_; EXPECT_EQ(wvcdm::KEY_ADDED, decryptor_.RestoreKey(restore_session_id, key_set_id)); @@ -1174,7 +1174,7 @@ TEST_F(WvCdmRequestLicenseTest, ExpiryOnReleaseOfflineKeyTest) { } TEST_F(WvCdmRequestLicenseTest, StreamingLicenseRenewal) { - decryptor_.OpenSession(g_key_system, NULL, &session_id_); + decryptor_.OpenSession(g_key_system, NULL, NULL, &session_id_); GenerateKeyRequest(g_key_id, kLicenseTypeStreaming); VerifyKeyRequestResponse(g_license_server, g_client_auth, false); @@ -1191,7 +1191,7 @@ TEST_F(WvCdmRequestLicenseTest, OfflineLicenseRenewal) { std::string client_auth; GetOfflineConfiguration(&key_id, &client_auth); - decryptor_.OpenSession(g_key_system, NULL, &session_id_); + decryptor_.OpenSession(g_key_system, NULL, NULL, &session_id_); GenerateKeyRequest(key_id, kLicenseTypeOffline); VerifyKeyRequestResponse(g_license_server, client_auth, false); @@ -1203,7 +1203,8 @@ TEST_F(WvCdmRequestLicenseTest, OfflineLicenseRenewal) { } TEST_F(WvCdmRequestLicenseTest, RemoveKeys) { - ASSERT_EQ(NO_ERROR, decryptor_.OpenSession(g_key_system, NULL, &session_id_)); + ASSERT_EQ(NO_ERROR, + decryptor_.OpenSession(g_key_system, NULL, NULL, &session_id_)); GenerateKeyRequest(g_key_id, kLicenseTypeStreaming); VerifyKeyRequestResponse(g_license_server, g_client_auth, false); ASSERT_EQ(NO_ERROR, decryptor_.RemoveKeys(session_id_)); @@ -1224,7 +1225,7 @@ TEST_F(WvCdmRequestLicenseTest, UsageInfoRetryTest) { EXPECT_TRUE(handle.DeleteAllUsageInfoForApp(app_id, &psts)); SubSampleInfo* data = &usage_info_sub_samples_icp[0]; - decryptor_.OpenSession(g_key_system, NULL, &session_id_); + decryptor_.OpenSession(g_key_system, NULL, NULL, &session_id_); std::string key_id = a2bs_hex( "000000427073736800000000" // blob size and pssh "EDEF8BA979D64ACEA3C827DCD51D21ED00000022" // Widevine system id @@ -1302,7 +1303,7 @@ TEST_P(WvCdmUsageInfoTest, UsageInfo) { for (size_t i = 0; i < usage_info_data->usage_info; ++i) { SubSampleInfo* data = usage_info_data->sub_sample + i; - decryptor_.OpenSession(g_key_system, property_set, &session_id_); + decryptor_.OpenSession(g_key_system, property_set, NULL, &session_id_); std::string key_id = a2bs_hex( "000000427073736800000000" // blob size and pssh "EDEF8BA979D64ACEA3C827DCD51D21ED00000022" // Widevine system id @@ -1378,7 +1379,7 @@ TEST_F(WvCdmRequestLicenseTest, QueryModifiedSessionStatus) { } TEST_F(WvCdmRequestLicenseTest, QueryKeyStatus) { - decryptor_.OpenSession(g_key_system, NULL, &session_id_); + decryptor_.OpenSession(g_key_system, NULL, NULL, &session_id_); GenerateKeyRequest(g_key_id, kLicenseTypeStreaming); VerifyKeyRequestResponse(g_license_server, g_client_auth, false); @@ -1448,7 +1449,7 @@ TEST_F(WvCdmRequestLicenseTest, QueryStatus) { } TEST_F(WvCdmRequestLicenseTest, QueryKeyControlInfo) { - decryptor_.OpenSession(g_key_system, NULL, &session_id_); + decryptor_.OpenSession(g_key_system, NULL, NULL, &session_id_); GenerateKeyRequest(g_key_id, kLicenseTypeStreaming); VerifyKeyRequestResponse(g_license_server, g_client_auth, false); @@ -1510,7 +1511,7 @@ TEST_F(WvCdmRequestLicenseTest, SecurityLevelPathBackwardCompatibility) { file.Remove(path); } - decryptor_.OpenSession(g_key_system, NULL, &session_id_); + decryptor_.OpenSession(g_key_system, NULL, NULL, &session_id_); std::string provisioning_server_url; CdmCertificateType cert_type = kCertificateWidevine; std::string cert_authority, cert, wrapped_key; @@ -1529,7 +1530,7 @@ TEST_F(WvCdmRequestLicenseTest, SecurityLevelPathBackwardCompatibility) { EXPECT_TRUE(file.List(base_path, &files)); size_t number_of_files = files.size(); - decryptor_.OpenSession(g_key_system, NULL, &session_id_); + decryptor_.OpenSession(g_key_system, NULL, NULL, &session_id_); GenerateKeyRequest(key_id, kLicenseTypeOffline); VerifyKeyRequestResponse(g_license_server, client_auth, false); CdmKeySetId key_set_id = key_set_id_; @@ -1555,11 +1556,11 @@ TEST_F(WvCdmRequestLicenseTest, SecurityLevelPathBackwardCompatibility) { // Setup complete to earlier version (non-security level based) path. // Restore persistent license, retrieve L1, L3 streaming licenses to verify session_id_.clear(); - decryptor_.OpenSession(g_key_system, NULL, &session_id_); + decryptor_.OpenSession(g_key_system, NULL, NULL, &session_id_); EXPECT_EQ(wvcdm::KEY_ADDED, decryptor_.RestoreKey(session_id_, key_set_id)); decryptor_.CloseSession(session_id_); - decryptor_.OpenSession(g_key_system, NULL, &session_id_); + decryptor_.OpenSession(g_key_system, NULL, NULL, &session_id_); GenerateKeyRequest(g_key_id, kLicenseTypeStreaming); VerifyKeyRequestResponse(g_license_server, client_auth, false); decryptor_.CloseSession(session_id_); @@ -1569,8 +1570,8 @@ TEST_F(WvCdmRequestLicenseTest, SecurityLevelPathBackwardCompatibility) { TestWvCdmClientPropertySet property_set; property_set.set_security_level(QUERY_VALUE_SECURITY_LEVEL_L3); - EXPECT_EQ(NO_ERROR, - decryptor_.OpenSession(g_key_system, &property_set, &session_id_)); + EXPECT_EQ(NO_ERROR, decryptor_.OpenSession(g_key_system, &property_set, NULL, + &session_id_)); wvcdm::CdmAppParameterMap app_parameters; std::string server_url; @@ -1589,15 +1590,15 @@ TEST_F(WvCdmRequestLicenseTest, SecurityLevelPathBackwardCompatibility) { EXPECT_EQ(NO_ERROR, decryptor_.HandleProvisioningResponse(response, &cert, &wrapped_key)); - EXPECT_EQ(NO_ERROR, - decryptor_.OpenSession(g_key_system, &property_set, &session_id_)); + EXPECT_EQ(NO_ERROR, decryptor_.OpenSession(g_key_system, &property_set, NULL, + &session_id_)); GenerateKeyRequest(g_key_id, kLicenseTypeStreaming); VerifyKeyRequestResponse(g_license_server, client_auth, false); decryptor_.CloseSession(session_id_); } TEST_F(WvCdmRequestLicenseTest, DISABLED_OfflineLicenseDecryptionTest) { - decryptor_.OpenSession(g_key_system, NULL, &session_id_); + decryptor_.OpenSession(g_key_system, NULL, NULL, &session_id_); GenerateKeyRequest(g_key_id, kLicenseTypeOffline); VerifyKeyRequestResponse(g_license_server, g_client_auth, false); @@ -1650,7 +1651,7 @@ TEST_F(WvCdmRequestLicenseTest, DISABLED_OfflineLicenseDecryptionTest) { } TEST_F(WvCdmRequestLicenseTest, DISABLED_RestoreOfflineLicenseDecryptionTest) { - decryptor_.OpenSession(g_key_system, NULL, &session_id_); + decryptor_.OpenSession(g_key_system, NULL, NULL, &session_id_); GenerateKeyRequest(g_key_id, kLicenseTypeOffline); VerifyKeyRequestResponse(g_license_server, g_client_auth, false); CdmKeySetId key_set_id = key_set_id_; @@ -1658,7 +1659,7 @@ TEST_F(WvCdmRequestLicenseTest, DISABLED_RestoreOfflineLicenseDecryptionTest) { decryptor_.CloseSession(session_id_); session_id_.clear(); - decryptor_.OpenSession(g_key_system, NULL, &session_id_); + decryptor_.OpenSession(g_key_system, NULL, NULL, &session_id_); EXPECT_EQ(wvcdm::KEY_ADDED, decryptor_.RestoreKey(session_id_, key_set_id)); /* // key 1, encrypted, 256b @@ -1775,7 +1776,7 @@ TEST_P(WvCdmSessionSharingTest, SessionSharingTest) { property_set.set_session_sharing_mode( session_sharing_info->session_sharing_enabled); - decryptor_.OpenSession(g_key_system, &property_set, &session_id_); + decryptor_.OpenSession(g_key_system, &property_set, NULL, &session_id_); CdmSessionId gp_session_id_1 = session_id_; GenerateKeyRequest(g_key_id, kLicenseTypeStreaming); VerifyKeyRequestResponse(g_license_server, g_client_auth, false); @@ -1788,7 +1789,7 @@ TEST_P(WvCdmSessionSharingTest, SessionSharingTest) { "edef8ba979d64acea3c827dcd51d21ed00000014" // Widevine system id "08011210bdf1cb4fffc6506b8b7945b0bd2917fb"); // pssh data - decryptor_.OpenSession(g_key_system, &property_set, &session_id_); + decryptor_.OpenSession(g_key_system, &property_set, NULL, &session_id_); CdmSessionId gp_session_id_2 = session_id_; GenerateKeyRequest(gp_key_id2, kLicenseTypeStreaming); VerifyKeyRequestResponse(g_license_server, gp_client_auth2, false); @@ -1823,7 +1824,7 @@ TEST_F(WvCdmRequestLicenseTest, DecryptionKeyExpiredTest) { "EDEF8BA979D64ACEA3C827DCD51D21ED00000014" // Widevine system id "0801121030313233343536373839616263646566"); // pssh data SubSampleInfo* data = &single_encrypted_sub_sample_short_expiry; - decryptor_.OpenSession(g_key_system, NULL, &session_id_); + decryptor_.OpenSession(g_key_system, NULL, NULL, &session_id_); if (data->retrieve_key) { GenerateKeyRequest(kCpKeyId, kLicenseTypeStreaming); VerifyKeyRequestResponse(g_license_server, g_client_auth, false); @@ -1853,7 +1854,7 @@ class WvCdmDecryptionTest TEST_P(WvCdmDecryptionTest, DecryptionTest) { SubSampleInfo* data = GetParam(); - decryptor_.OpenSession(g_key_system, NULL, &session_id_); + decryptor_.OpenSession(g_key_system, NULL, NULL, &session_id_); if (data->retrieve_key) { GenerateKeyRequest(g_key_id, kLicenseTypeStreaming); VerifyKeyRequestResponse(g_license_server, g_client_auth, false); diff --git a/libwvdrmengine/mediadrm/src/WVDrmPlugin.cpp b/libwvdrmengine/mediadrm/src/WVDrmPlugin.cpp index 6be7bb4b..5d50664a 100644 --- a/libwvdrmengine/mediadrm/src/WVDrmPlugin.cpp +++ b/libwvdrmengine/mediadrm/src/WVDrmPlugin.cpp @@ -42,13 +42,6 @@ WVDrmPlugin::~WVDrmPlugin() { for (mapIterator iter = mCryptoSessions.begin(); iter != mCryptoSessions.end(); ++iter) { - bool bRes = mCDM->DetachEventListener(iter->first, this); - - if (!bRes) { - ALOGE("Received failure when trying to detach WVDrmPlugin as an event " - "listener."); - } - CdmResponseType res = mCDM->CloseSession(iter->first); if (!isCdmResponseTypeSuccess(res)) { ALOGE("Failed to close session while destroying WVDrmPlugin"); @@ -59,8 +52,8 @@ WVDrmPlugin::~WVDrmPlugin() { status_t WVDrmPlugin::openSession(Vector& sessionId) { CdmSessionId cdmSessionId; - CdmResponseType res = mCDM->OpenSession("com.widevine", &mPropertySet, - &cdmSessionId); + CdmResponseType res = + mCDM->OpenSession("com.widevine", &mPropertySet, this, &cdmSessionId); if (!isCdmResponseTypeSuccess(res)) { return mapAndNotifyOfCdmResponseType(sessionId, res); @@ -68,32 +61,23 @@ status_t WVDrmPlugin::openSession(Vector& sessionId) { bool success = false; - // Register for events - bool listenerAttached = mCDM->AttachEventListener(cdmSessionId, this); + // Construct a CryptoSession + CdmQueryMap info; + res = mCDM->QueryKeyControlInfo(cdmSessionId, &info); - if (listenerAttached) { - // Construct a CryptoSession - CdmQueryMap info; + if (isCdmResponseTypeSuccess(res) && + info.count(QUERY_KEY_OEMCRYPTO_SESSION_ID)) { + OEMCrypto_SESSION oecSessionId; + istringstream(info[QUERY_KEY_OEMCRYPTO_SESSION_ID]) >> oecSessionId; - res = mCDM->QueryKeyControlInfo(cdmSessionId, &info); - - if (isCdmResponseTypeSuccess(res) && - info.count(QUERY_KEY_OEMCRYPTO_SESSION_ID)) { - OEMCrypto_SESSION oecSessionId; - istringstream(info[QUERY_KEY_OEMCRYPTO_SESSION_ID]) >> oecSessionId; - - { - Mutex::Autolock lock(mCryptoSessionsMutex); - mCryptoSessions[cdmSessionId] = CryptoSession(oecSessionId); - } - - success = true; - } else { - ALOGE("Unable to query key control info."); + { + Mutex::Autolock lock(mCryptoSessionsMutex); + mCryptoSessions[cdmSessionId] = CryptoSession(oecSessionId); } + + success = true; } else { - ALOGE("Received failure when trying to attach WVDrmPlugin as an event" - "listener."); + ALOGE("Unable to query key control info."); } if (success) { @@ -104,10 +88,6 @@ status_t WVDrmPlugin::openSession(Vector& sessionId) { return android::OK; } else { - if (listenerAttached) { - mCDM->DetachEventListener(cdmSessionId, this); - } - mCDM->CloseSession(cdmSessionId); if (!isCdmResponseTypeSuccess(res)) { diff --git a/libwvdrmengine/mediadrm/test/WVDrmPlugin_test.cpp b/libwvdrmengine/mediadrm/test/WVDrmPlugin_test.cpp index 1539e96a..f5a187b2 100644 --- a/libwvdrmengine/mediadrm/test/WVDrmPlugin_test.cpp +++ b/libwvdrmengine/mediadrm/test/WVDrmPlugin_test.cpp @@ -26,8 +26,9 @@ using namespace wvdrm; class MockCDM : public WvContentDecryptionModule { public: - MOCK_METHOD3(OpenSession, CdmResponseType(const CdmKeySystem&, + MOCK_METHOD4(OpenSession, CdmResponseType(const CdmKeySystem&, CdmClientPropertySet*, + WvCdmEventListener*, CdmSessionId*)); MOCK_METHOD1(CloseSession, CdmResponseType(const CdmSessionId&)); @@ -79,12 +80,6 @@ class MockCDM : public WvContentDecryptionModule { MOCK_METHOD1(ReleaseUsageInfo, CdmResponseType(const CdmUsageInfoReleaseMessage&)); - - MOCK_METHOD2(AttachEventListener, bool(const CdmSessionId&, - WvCdmEventListener*)); - - MOCK_METHOD2(DetachEventListener, bool(const CdmSessionId&, - WvCdmEventListener*)); }; class MockCrypto : public WVGenericCryptoInterface { @@ -158,8 +153,8 @@ TEST_F(WVDrmPluginTest, OpensSessions) { StrictMock crypto; WVDrmPlugin plugin(&cdm, &crypto); - EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _)) - .WillOnce(DoAll(SetArgPointee<2>(cdmSessionId), + EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _, _)) + .WillOnce(DoAll(SetArgPointee<3>(cdmSessionId), Return(wvcdm::NO_ERROR))); // Provide expected behavior when plugin requests session control info @@ -167,13 +162,6 @@ TEST_F(WVDrmPluginTest, OpensSessions) { .Times(AtLeast(1)) .WillRepeatedly(Invoke(setSessionIdOnMap<4>)); - // Let gMock know these calls will happen but we aren't interested in them. - EXPECT_CALL(cdm, AttachEventListener(_, _)) - .Times(AtLeast(0)); - - EXPECT_CALL(cdm, DetachEventListener(_, _)) - .Times(AtLeast(0)); - EXPECT_CALL(cdm, CloseSession(_)) .Times(AtLeast(0)); @@ -387,8 +375,8 @@ TEST_F(WVDrmPluginTest, HandlesPrivacyCertCaseOfAddKey) { // Provide expected behavior in response to OpenSession and store the // property set - EXPECT_CALL(cdm, OpenSession(_, _, _)) - .WillRepeatedly(DoAll(SetArgPointee<2>(cdmSessionId), + EXPECT_CALL(cdm, OpenSession(_, _, _, _)) + .WillRepeatedly(DoAll(SetArgPointee<3>(cdmSessionId), SaveArg<1>(&propertySet), Return(wvcdm::NO_ERROR))); @@ -396,13 +384,6 @@ TEST_F(WVDrmPluginTest, HandlesPrivacyCertCaseOfAddKey) { EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId, _)) .WillRepeatedly(Invoke(setSessionIdOnMap<4>)); - // Let gMock know these calls will happen but we aren't interested in them. - EXPECT_CALL(cdm, AttachEventListener(_, _)) - .Times(AtLeast(0)); - - EXPECT_CALL(cdm, DetachEventListener(_, _)) - .Times(AtLeast(0)); - EXPECT_CALL(cdm, CloseSession(_)) .Times(AtLeast(0)); @@ -824,22 +805,15 @@ TEST_F(WVDrmPluginTest, FailsGenericMethodsWithoutAnAlgorithmSet) { bool match; // Provide expected behavior to support session creation - EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _)) + EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _, _)) .Times(AtLeast(1)) - .WillRepeatedly(DoAll(SetArgPointee<2>(cdmSessionId), + .WillRepeatedly(DoAll(SetArgPointee<3>(cdmSessionId), Return(wvcdm::NO_ERROR))); EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId, _)) .Times(AtLeast(1)) .WillRepeatedly(Invoke(setSessionIdOnMap<4>)); - // Let gMock know these calls will happen but we aren't interested in them. - EXPECT_CALL(cdm, AttachEventListener(_, _)) - .Times(AtLeast(0)); - - EXPECT_CALL(cdm, DetachEventListener(_, _)) - .Times(AtLeast(0)); - EXPECT_CALL(cdm, CloseSession(_)) .Times(AtLeast(0)); @@ -910,22 +884,15 @@ TEST_F(WVDrmPluginTest, CallsGenericEncrypt) { } // Provide expected behavior to support session creation - EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _)) + EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _, _)) .Times(AtLeast(1)) - .WillRepeatedly(DoAll(SetArgPointee<2>(cdmSessionId), + .WillRepeatedly(DoAll(SetArgPointee<3>(cdmSessionId), Return(wvcdm::NO_ERROR))); EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId, _)) .Times(AtLeast(1)) .WillRepeatedly(Invoke(setSessionIdOnMap<4>)); - // Let gMock know these calls will happen but we aren't interested in them. - EXPECT_CALL(cdm, AttachEventListener(_, _)) - .Times(AtLeast(0)); - - EXPECT_CALL(cdm, DetachEventListener(_, _)) - .Times(AtLeast(0)); - EXPECT_CALL(cdm, CloseSession(_)) .Times(AtLeast(0)); @@ -977,22 +944,15 @@ TEST_F(WVDrmPluginTest, CallsGenericDecrypt) { } // Provide expected behavior to support session creation - EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _)) + EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _, _)) .Times(AtLeast(1)) - .WillRepeatedly(DoAll(SetArgPointee<2>(cdmSessionId), + .WillRepeatedly(DoAll(SetArgPointee<3>(cdmSessionId), Return(wvcdm::NO_ERROR))); EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId, _)) .Times(AtLeast(1)) .WillRepeatedly(Invoke(setSessionIdOnMap<4>)); - // Let gMock know these calls will happen but we aren't interested in them. - EXPECT_CALL(cdm, AttachEventListener(_, _)) - .Times(AtLeast(0)); - - EXPECT_CALL(cdm, DetachEventListener(_, _)) - .Times(AtLeast(0)); - EXPECT_CALL(cdm, CloseSession(_)) .Times(AtLeast(0)); @@ -1046,22 +1006,15 @@ TEST_F(WVDrmPluginTest, CallsGenericSign) { } // Provide expected behavior to support session creation - EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _)) + EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _, _)) .Times(AtLeast(1)) - .WillRepeatedly(DoAll(SetArgPointee<2>(cdmSessionId), + .WillRepeatedly(DoAll(SetArgPointee<3>(cdmSessionId), Return(wvcdm::NO_ERROR))); EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId, _)) .Times(AtLeast(1)) .WillRepeatedly(Invoke(setSessionIdOnMap<4>)); - // Let gMock know these calls will happen but we aren't interested in them. - EXPECT_CALL(cdm, AttachEventListener(_, _)) - .Times(AtLeast(0)); - - EXPECT_CALL(cdm, DetachEventListener(_, _)) - .Times(AtLeast(0)); - EXPECT_CALL(cdm, CloseSession(_)) .Times(AtLeast(0)); @@ -1125,22 +1078,15 @@ TEST_F(WVDrmPluginTest, CallsGenericVerify) { } // Provide expected behavior to support session creation - EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _)) + EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _, _)) .Times(AtLeast(1)) - .WillRepeatedly(DoAll(SetArgPointee<2>(cdmSessionId), + .WillRepeatedly(DoAll(SetArgPointee<3>(cdmSessionId), Return(wvcdm::NO_ERROR))); EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId, _)) .Times(AtLeast(1)) .WillRepeatedly(Invoke(setSessionIdOnMap<4>)); - // Let gMock know these calls will happen but we aren't interested in them. - EXPECT_CALL(cdm, AttachEventListener(_, _)) - .Times(AtLeast(0)); - - EXPECT_CALL(cdm, DetachEventListener(_, _)) - .Times(AtLeast(0)); - EXPECT_CALL(cdm, CloseSession(_)) .Times(AtLeast(0)); @@ -1164,23 +1110,16 @@ TEST_F(WVDrmPluginTest, RegistersForEvents) { StrictMock crypto; WVDrmPlugin plugin(&cdm, &crypto); - EXPECT_CALL(cdm, AttachEventListener(cdmSessionId, &plugin)) - .Times(1); - // Provide expected behavior to support session creation - EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _)) + EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, &plugin, _)) .Times(AtLeast(1)) - .WillRepeatedly(DoAll(SetArgPointee<2>(cdmSessionId), + .WillRepeatedly(DoAll(SetArgPointee<3>(cdmSessionId), Return(wvcdm::NO_ERROR))); EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId, _)) .Times(AtLeast(1)) .WillRepeatedly(Invoke(setSessionIdOnMap<4>)); - // Let gMock know this call will happen but we aren't interested in it. - EXPECT_CALL(cdm, DetachEventListener(_, _)) - .Times(AtLeast(0)); - EXPECT_CALL(cdm, CloseSession(_)) .Times(AtLeast(0)); @@ -1205,10 +1144,10 @@ TEST_F(WVDrmPluginTest, UnregistersForAllEventsOnDestruction) { CdmSessionId cdmSessionId1(sessionIdRaw1, sessionIdRaw1 + kSessionIdSize); CdmSessionId cdmSessionId2(sessionIdRaw2, sessionIdRaw2 + kSessionIdSize); - EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _)) - .WillOnce(DoAll(SetArgPointee<2>(cdmSessionId1), + EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _, _)) + .WillOnce(DoAll(SetArgPointee<3>(cdmSessionId1), Return(wvcdm::NO_ERROR))) - .WillOnce(DoAll(SetArgPointee<2>(cdmSessionId2), + .WillOnce(DoAll(SetArgPointee<3>(cdmSessionId2), Return(wvcdm::NO_ERROR))); EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId1, _)) @@ -1217,16 +1156,6 @@ TEST_F(WVDrmPluginTest, UnregistersForAllEventsOnDestruction) { EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId2, _)) .WillOnce(Invoke(setSessionIdOnMap<5>)); - EXPECT_CALL(cdm, DetachEventListener(cdmSessionId1, &plugin)) - .Times(1); - - EXPECT_CALL(cdm, DetachEventListener(cdmSessionId2, &plugin)) - .Times(1); - - // Let gMock know these calls will happen but we aren't interested in them. - EXPECT_CALL(cdm, AttachEventListener(_, _)) - .Times(AtLeast(0)); - EXPECT_CALL(cdm, CloseSession(_)) .Times(AtLeast(0)); @@ -1283,18 +1212,11 @@ TEST_F(WVDrmPluginTest, GeneratesProvisioningNeededEvent) { NULL)) .Times(1); - EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _)) + EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _, _)) .Times(AtLeast(1)) - .WillRepeatedly(DoAll(SetArgPointee<2>(cdmSessionId), + .WillRepeatedly(DoAll(SetArgPointee<3>(cdmSessionId), Return(wvcdm::NEED_PROVISIONING))); - // Let gMock know these calls will happen but we aren't interested in them. - EXPECT_CALL(cdm, AttachEventListener(_, _)) - .Times(AtLeast(0)); - - EXPECT_CALL(cdm, DetachEventListener(_, _)) - .Times(AtLeast(0)); - EXPECT_CALL(cdm, CloseSession(_)) .Times(AtLeast(0)); @@ -1316,8 +1238,8 @@ TEST_F(WVDrmPluginTest, ProvidesExpectedDefaultPropertiesToCdm) { { // Provide expected behavior in response to OpenSession and store the // property set - EXPECT_CALL(cdm, OpenSession(_, _, _)) - .WillRepeatedly(DoAll(SetArgPointee<2>(cdmSessionId), + EXPECT_CALL(cdm, OpenSession(_, _, _, _)) + .WillRepeatedly(DoAll(SetArgPointee<3>(cdmSessionId), SaveArg<1>(&propertySet), Return(wvcdm::NO_ERROR))); @@ -1325,13 +1247,6 @@ TEST_F(WVDrmPluginTest, ProvidesExpectedDefaultPropertiesToCdm) { EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId, _)) .WillRepeatedly(Invoke(setSessionIdOnMap<4>)); - // Let gMock know these calls will happen but we aren't interested in them. - EXPECT_CALL(cdm, AttachEventListener(_, _)) - .Times(AtLeast(0)); - - EXPECT_CALL(cdm, DetachEventListener(_, _)) - .Times(AtLeast(0)); - EXPECT_CALL(cdm, CloseSession(_)) .Times(AtLeast(0)); } @@ -1357,8 +1272,8 @@ TEST_F(WVDrmPluginTest, CanSetAppId) { { // Provide expected behavior in response to OpenSession and store the // property set - EXPECT_CALL(cdm, OpenSession(_, _, _)) - .WillRepeatedly(DoAll(SetArgPointee<2>(cdmSessionId), + EXPECT_CALL(cdm, OpenSession(_, _, _, _)) + .WillRepeatedly(DoAll(SetArgPointee<3>(cdmSessionId), SaveArg<1>(&propertySet), Return(wvcdm::NO_ERROR))); @@ -1366,13 +1281,6 @@ TEST_F(WVDrmPluginTest, CanSetAppId) { EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId, _)) .WillRepeatedly(Invoke(setSessionIdOnMap<4>)); - // Let gMock know these calls will happen but we aren't interested in them. - EXPECT_CALL(cdm, AttachEventListener(_, _)) - .Times(AtLeast(0)); - - EXPECT_CALL(cdm, DetachEventListener(_, _)) - .Times(AtLeast(0)); - EXPECT_CALL(cdm, CloseSession(_)) .Times(AtLeast(0)); } @@ -1422,8 +1330,8 @@ TEST_F(WVDrmPluginTest, CanSetSecurityLevel) { { // Provide expected behavior in response to OpenSession and store the // property set - EXPECT_CALL(cdm, OpenSession(_, _, _)) - .WillRepeatedly(DoAll(SetArgPointee<2>(cdmSessionId), + EXPECT_CALL(cdm, OpenSession(_, _, _, _)) + .WillRepeatedly(DoAll(SetArgPointee<3>(cdmSessionId), SaveArg<1>(&propertySet), Return(wvcdm::NO_ERROR))); @@ -1431,13 +1339,6 @@ TEST_F(WVDrmPluginTest, CanSetSecurityLevel) { EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId, _)) .WillRepeatedly(Invoke(setSessionIdOnMap<4>)); - // Let gMock know these calls will happen but we aren't interested in them. - EXPECT_CALL(cdm, AttachEventListener(_, _)) - .Times(AtLeast(0)); - - EXPECT_CALL(cdm, DetachEventListener(_, _)) - .Times(AtLeast(0)); - EXPECT_CALL(cdm, CloseSession(_)) .Times(AtLeast(0)); } @@ -1514,8 +1415,8 @@ TEST_F(WVDrmPluginTest, CanSetPrivacyMode) { { // Provide expected behavior in response to OpenSession and store the // property set - EXPECT_CALL(cdm, OpenSession(_, _, _)) - .WillRepeatedly(DoAll(SetArgPointee<2>(cdmSessionId), + EXPECT_CALL(cdm, OpenSession(_, _, _, _)) + .WillRepeatedly(DoAll(SetArgPointee<3>(cdmSessionId), SaveArg<1>(&propertySet), Return(wvcdm::NO_ERROR))); @@ -1523,13 +1424,6 @@ TEST_F(WVDrmPluginTest, CanSetPrivacyMode) { EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId, _)) .WillRepeatedly(Invoke(setSessionIdOnMap<4>)); - // Let gMock know these calls will happen but we aren't interested in them. - EXPECT_CALL(cdm, AttachEventListener(_, _)) - .Times(AtLeast(0)); - - EXPECT_CALL(cdm, DetachEventListener(_, _)) - .Times(AtLeast(0)); - EXPECT_CALL(cdm, CloseSession(_)) .Times(AtLeast(0)); } @@ -1576,8 +1470,8 @@ TEST_F(WVDrmPluginTest, CanSetServiceCertificate) { { // Provide expected behavior in response to OpenSession and store the // property set - EXPECT_CALL(cdm, OpenSession(_, _, _)) - .WillRepeatedly(DoAll(SetArgPointee<2>(cdmSessionId), + EXPECT_CALL(cdm, OpenSession(_, _, _, _)) + .WillRepeatedly(DoAll(SetArgPointee<3>(cdmSessionId), SaveArg<1>(&propertySet), Return(wvcdm::NO_ERROR))); @@ -1585,13 +1479,6 @@ TEST_F(WVDrmPluginTest, CanSetServiceCertificate) { EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId, _)) .WillRepeatedly(Invoke(setSessionIdOnMap<4>)); - // Let gMock know these calls will happen but we aren't interested in them. - EXPECT_CALL(cdm, AttachEventListener(_, _)) - .Times(AtLeast(0)); - - EXPECT_CALL(cdm, DetachEventListener(_, _)) - .Times(AtLeast(0)); - EXPECT_CALL(cdm, CloseSession(_)) .Times(AtLeast(0)); } @@ -1624,8 +1511,8 @@ TEST_F(WVDrmPluginTest, CanSetSessionSharing) { { // Provide expected behavior in response to OpenSession and store the // property set - EXPECT_CALL(cdm, OpenSession(_, _, _)) - .WillRepeatedly(DoAll(SetArgPointee<2>(cdmSessionId), + EXPECT_CALL(cdm, OpenSession(_, _, _, _)) + .WillRepeatedly(DoAll(SetArgPointee<3>(cdmSessionId), SaveArg<1>(&propertySet), Return(wvcdm::NO_ERROR))); @@ -1633,13 +1520,6 @@ TEST_F(WVDrmPluginTest, CanSetSessionSharing) { EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId, _)) .WillRepeatedly(Invoke(setSessionIdOnMap<4>)); - // Let gMock know these calls will happen but we aren't interested in them. - EXPECT_CALL(cdm, AttachEventListener(_, _)) - .Times(AtLeast(0)); - - EXPECT_CALL(cdm, DetachEventListener(_, _)) - .Times(AtLeast(0)); - EXPECT_CALL(cdm, CloseSession(_)) .Times(AtLeast(0)); } @@ -1690,8 +1570,8 @@ TEST_F(WVDrmPluginTest, AllowsStoringOfSessionSharingId) { { // Provide expected behavior in response to OpenSession and store the // property set - EXPECT_CALL(cdm, OpenSession(_, _, _)) - .WillRepeatedly(DoAll(SetArgPointee<2>(cdmSessionId), + EXPECT_CALL(cdm, OpenSession(_, _, _, _)) + .WillRepeatedly(DoAll(SetArgPointee<3>(cdmSessionId), SaveArg<1>(&propertySet), Return(wvcdm::NO_ERROR))); @@ -1699,13 +1579,6 @@ TEST_F(WVDrmPluginTest, AllowsStoringOfSessionSharingId) { EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId, _)) .WillRepeatedly(Invoke(setSessionIdOnMap<4>)); - // Let gMock know these calls will happen but we aren't interested in them. - EXPECT_CALL(cdm, AttachEventListener(_, _)) - .Times(AtLeast(0)); - - EXPECT_CALL(cdm, DetachEventListener(_, _)) - .Times(AtLeast(0)); - EXPECT_CALL(cdm, CloseSession(_)) .Times(AtLeast(0)); }