Fix expiry time overflow if it is unlimited
Bug: 21324836 Merged from Widevine CDM repo: https://widevine-internal-review.googlesource.com/#/c/14392 Change-Id: I2a8da14c98f8ae0fece3667b6f6b8517577f8a98
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
#ifndef WVCDM_CORE_WV_CDM_CONSTANTS_H_
|
||||
#define WVCDM_CORE_WV_CDM_CONSTANTS_H_
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace wvcdm {
|
||||
@@ -14,6 +16,8 @@ static const size_t KEY_SIZE = 16;
|
||||
static const size_t MAC_KEY_SIZE = 32;
|
||||
static const size_t KEYBOX_KEY_DATA_SIZE = 72;
|
||||
|
||||
static const int64_t NEVER_EXPIRES = LLONG_MAX;
|
||||
|
||||
static const char SESSION_ID_PREFIX[] = "sid";
|
||||
static const char KEY_SET_ID_PREFIX[] = "ksid";
|
||||
static const char KEY_SYSTEM[] = "com.widevine";
|
||||
|
||||
@@ -18,7 +18,7 @@ class WvCdmEventListener {
|
||||
const CdmKeyStatusMap& keys_status,
|
||||
bool has_new_usable_key) = 0;
|
||||
virtual void OnExpirationUpdate(const CdmSessionId& session_id,
|
||||
int64_t new_expiry_time) = 0;
|
||||
int64_t new_expiry_time_seconds) = 0;
|
||||
|
||||
private:
|
||||
CORE_DISALLOW_COPY_AND_ASSIGN(WvCdmEventListener);
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
#include "license.h"
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "clock.h"
|
||||
|
||||
@@ -280,13 +280,13 @@ void PolicyEngine::UpdateRenewalRequest(int64_t current_time) {
|
||||
int64_t PolicyEngine::GetLicenseExpiryTime() {
|
||||
return policy_max_duration_seconds_ > 0
|
||||
? license_start_time_ + policy_max_duration_seconds_
|
||||
: LLONG_MAX;
|
||||
: NEVER_EXPIRES;
|
||||
}
|
||||
|
||||
int64_t PolicyEngine::GetPlaybackExpiryTime() {
|
||||
return (playback_start_time_ > 0 && policy_.playback_duration_seconds() > 0)
|
||||
? (playback_start_time_ + policy_.playback_duration_seconds())
|
||||
: LLONG_MAX;
|
||||
: NEVER_EXPIRES;
|
||||
}
|
||||
|
||||
int64_t PolicyEngine::GetLicenseDurationRemaining(int64_t current_time) {
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
namespace {
|
||||
const int64_t kDurationUnlimited = 0;
|
||||
const int64_t kNoExpiration = LLONG_MAX;
|
||||
const int64_t kLicenseStartTime = 1413517500; // ~ 01/01/2013
|
||||
const int64_t kPlaybackStartTime = kLicenseStartTime + 5;
|
||||
const int64_t kRentalDuration = 604800; // 7 days
|
||||
@@ -75,8 +74,8 @@ class MockCdmEventListener : public WvCdmEventListener {
|
||||
MOCK_METHOD3(OnSessionKeysChange, void(const CdmSessionId& session_id,
|
||||
const CdmKeyStatusMap& keys_status,
|
||||
bool has_new_usable_key));
|
||||
MOCK_METHOD2(OnExpirationUpdate,
|
||||
void(const CdmSessionId& session_id, int64_t new_expiry_time));
|
||||
MOCK_METHOD2(OnExpirationUpdate, void(const CdmSessionId& session_id,
|
||||
int64_t new_expiry_time_seconds));
|
||||
};
|
||||
|
||||
class MockMaxResEngine : public MaxResEngine {
|
||||
@@ -471,7 +470,7 @@ TEST_F(PolicyEngineTest, PlaybackOk_PlaybackDuration0) {
|
||||
EXPECT_CALL(mock_event_listener_,
|
||||
OnExpirationUpdate(_, kLicenseStartTime + kHighDuration));
|
||||
EXPECT_CALL(mock_event_listener_,
|
||||
OnExpirationUpdate(_, kNoExpiration));
|
||||
OnExpirationUpdate(_, NEVER_EXPIRES));
|
||||
EXPECT_CALL(check_, Call(1));
|
||||
EXPECT_CALL(mock_event_listener_, OnSessionRenewalNeeded(_));
|
||||
EXPECT_CALL(check_, Call(2));
|
||||
@@ -545,7 +544,7 @@ TEST_F(PolicyEngineTest, PlaybackOk_Durations0) {
|
||||
.WillOnce(Return(kLicenseStartTime + kHighDuration));
|
||||
|
||||
ExpectSessionKeysChange(kKeyStatusUsable, true);
|
||||
EXPECT_CALL(mock_event_listener_, OnExpirationUpdate(_, kNoExpiration));
|
||||
EXPECT_CALL(mock_event_listener_, OnExpirationUpdate(_, NEVER_EXPIRES));
|
||||
|
||||
policy_engine_->SetLicense(license_);
|
||||
|
||||
|
||||
@@ -495,8 +495,8 @@ class TestWvCdmEventListener : public WvCdmEventListener {
|
||||
MOCK_METHOD3(OnSessionKeysChange, void(const CdmSessionId& session_id,
|
||||
const CdmKeyStatusMap& keys_status,
|
||||
bool has_new_usable_key));
|
||||
MOCK_METHOD2(OnExpirationUpdate,
|
||||
void(const CdmSessionId& session_id, int64_t new_expiry_time));
|
||||
MOCK_METHOD2(OnExpirationUpdate, void(const CdmSessionId& session_id,
|
||||
int64_t new_expiry_time_seconds));
|
||||
};
|
||||
|
||||
class WvCdmRequestLicenseTest : public WvCdmTestBase {
|
||||
|
||||
@@ -145,7 +145,7 @@ class WVDrmPlugin : public android::DrmPlugin,
|
||||
bool hasNewUsableKey);
|
||||
|
||||
virtual void OnExpirationUpdate(const CdmSessionId& cdmSessionId,
|
||||
int64_t newExpiryTime);
|
||||
int64_t newExpiryTimeSeconds);
|
||||
|
||||
private:
|
||||
DISALLOW_EVIL_CONSTRUCTORS(WVDrmPlugin);
|
||||
|
||||
@@ -875,9 +875,12 @@ void WVDrmPlugin::OnSessionKeysChange(const CdmSessionId& cdmSessionId,
|
||||
}
|
||||
|
||||
void WVDrmPlugin::OnExpirationUpdate(const CdmSessionId& cdmSessionId,
|
||||
int64_t newExpiryTime) {
|
||||
int64_t newExpiryTimeSeconds) {
|
||||
Vector<uint8_t> sessionId = ToVector(cdmSessionId);
|
||||
sendExpirationUpdate(&sessionId, newExpiryTime * 1000);
|
||||
int64_t newExpiryTimeMilliseconds = newExpiryTimeSeconds == NEVER_EXPIRES
|
||||
? newExpiryTimeSeconds
|
||||
: newExpiryTimeSeconds * 1000;
|
||||
sendExpirationUpdate(&sessionId, newExpiryTimeMilliseconds);
|
||||
}
|
||||
|
||||
status_t WVDrmPlugin::queryProperty(const std::string& property,
|
||||
|
||||
@@ -1328,6 +1328,11 @@ TEST_F(WVDrmPluginTest, MarshalsEvents) {
|
||||
sendEvent(DrmPlugin::kDrmPluginEventKeyNeeded, 0,
|
||||
Pointee(ElementsAreArray(sessionIdRaw, kSessionIdSize)),
|
||||
NULL));
|
||||
// Expiry Time in Java API is in milliseconds.
|
||||
EXPECT_CALL(*listener,
|
||||
sendExpirationUpdate(
|
||||
Pointee(ElementsAreArray(sessionIdRaw, kSessionIdSize)),
|
||||
NEVER_EXPIRES));
|
||||
EXPECT_CALL(*listener,
|
||||
sendExpirationUpdate(
|
||||
Pointee(ElementsAreArray(sessionIdRaw, kSessionIdSize)),
|
||||
@@ -1364,6 +1369,7 @@ TEST_F(WVDrmPluginTest, MarshalsEvents) {
|
||||
plugin.OnSessionKeysChange(cdmSessionId, cdmKeysStatus, false);
|
||||
|
||||
plugin.OnSessionRenewalNeeded(cdmSessionId);
|
||||
plugin.OnExpirationUpdate(cdmSessionId, NEVER_EXPIRES);
|
||||
plugin.OnExpirationUpdate(cdmSessionId, kExpiryTimeInSeconds);
|
||||
|
||||
cdmKeysStatus[kKeyId1] = kKeyStatusUsable;
|
||||
|
||||
Reference in New Issue
Block a user