am 779b887b: Merge "Generate renewal and expiry events" into jb-mr2-dev
* commit '779b887bb3b2b88e50ddfc76dc0ace21734efdb1': Generate renewal and expiry events
This commit is contained in:
@@ -34,7 +34,7 @@ class Timer {
|
||||
Timer();
|
||||
~Timer();
|
||||
|
||||
void Start(TimerHandler *handler, uint32_t time_in_secs);
|
||||
bool Start(TimerHandler *handler, uint32_t time_in_secs);
|
||||
void Stop();
|
||||
bool IsRunning();
|
||||
|
||||
|
||||
@@ -101,6 +101,8 @@ CdmResponseType CdmEngine::CloseSession(const CdmSessionId& session_id) {
|
||||
}
|
||||
|
||||
sessions_.erase(session_id);
|
||||
if (sessions_.size() == 0)
|
||||
DisablePolicyTimer();
|
||||
iter->second->DestroySession();
|
||||
delete iter->second;
|
||||
return NO_ERROR;
|
||||
|
||||
54
libwvdrmengine/cdm/core/test/timer_unittest.cpp
Normal file
54
libwvdrmengine/cdm/core/test/timer_unittest.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
// Copyright 2013 Google Inc. All Rights Reserved.
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "timer.h"
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
class TestTimerHandler : public TimerHandler {
|
||||
public:
|
||||
TestTimerHandler() : timer_events_(0) {};
|
||||
virtual ~TestTimerHandler() {};
|
||||
|
||||
virtual void OnTimerEvent() {
|
||||
timer_events_++;
|
||||
}
|
||||
|
||||
uint32_t GetTimerEvents() { return timer_events_; }
|
||||
void ResetTimerEvents() { timer_events_ = 0; }
|
||||
|
||||
private:
|
||||
uint32_t timer_events_;
|
||||
};
|
||||
|
||||
TEST(TimerTest, ParametersCheck) {
|
||||
Timer timer;
|
||||
EXPECT_FALSE(timer.Start(NULL, 10));
|
||||
|
||||
TestTimerHandler handler;
|
||||
EXPECT_FALSE(timer.Start(&handler, 0));
|
||||
}
|
||||
|
||||
TEST(TimerTest, TimerCheck) {
|
||||
TestTimerHandler handler;
|
||||
Timer timer;
|
||||
uint32_t duration = 10;
|
||||
|
||||
EXPECT_EQ(static_cast<uint32_t>(0), handler.GetTimerEvents());
|
||||
EXPECT_FALSE(timer.IsRunning());
|
||||
|
||||
EXPECT_TRUE(timer.Start(&handler, 1));
|
||||
EXPECT_TRUE(timer.IsRunning());
|
||||
sleep(duration);
|
||||
|
||||
EXPECT_TRUE(duration-1 <= handler.GetTimerEvents());
|
||||
EXPECT_TRUE(handler.GetTimerEvents() <= duration+1);
|
||||
timer.Stop();
|
||||
EXPECT_FALSE(timer.IsRunning());
|
||||
sleep(duration);
|
||||
|
||||
EXPECT_TRUE(duration-1 <= handler.GetTimerEvents());
|
||||
EXPECT_TRUE(handler.GetTimerEvents() <= duration+1);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,30 +5,59 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "timer.h"
|
||||
#include "utils/RefBase.h"
|
||||
#include "utils/StrongPointer.h"
|
||||
#include "utils/Thread.h"
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
class Timer::Impl : public android::Thread {
|
||||
class Timer::Impl : virtual public android::RefBase {
|
||||
private:
|
||||
class ImplThread : public android::Thread {
|
||||
public:
|
||||
ImplThread() : Thread(false), handler_(NULL), period_(0) {}
|
||||
virtual ~ImplThread() {};
|
||||
|
||||
bool Start(TimerHandler *handler, uint32_t time_in_secs) {
|
||||
handler_ = handler;
|
||||
period_ = time_in_secs;
|
||||
return run() == android::NO_ERROR;
|
||||
}
|
||||
|
||||
private:
|
||||
virtual bool threadLoop() {
|
||||
sleep(period_);
|
||||
handler_->OnTimerEvent();
|
||||
return true;
|
||||
}
|
||||
|
||||
TimerHandler *handler_;
|
||||
uint32_t period_;
|
||||
|
||||
CORE_DISALLOW_COPY_AND_ASSIGN(ImplThread);
|
||||
};
|
||||
|
||||
android::sp<ImplThread> impl_thread_;
|
||||
|
||||
public:
|
||||
Impl() : Thread(false), handler_(NULL), period_(0) {}
|
||||
Impl() {}
|
||||
virtual ~Impl() {};
|
||||
|
||||
void Start(TimerHandler *handler, uint32_t time_in_secs) {
|
||||
handler_ = handler;
|
||||
period_ = time_in_secs;
|
||||
run();
|
||||
bool Start(TimerHandler *handler, uint32_t time_in_secs) {
|
||||
impl_thread_ = new ImplThread();
|
||||
return impl_thread_->Start(handler, time_in_secs);
|
||||
}
|
||||
|
||||
private:
|
||||
virtual bool threadLoop() {
|
||||
sleep(period_);
|
||||
handler_->OnTimerEvent();
|
||||
return true;
|
||||
void Stop() {
|
||||
impl_thread_->requestExitAndWait();
|
||||
impl_thread_.clear();
|
||||
}
|
||||
|
||||
TimerHandler *handler_;
|
||||
uint32_t period_;
|
||||
bool IsRunning() {
|
||||
return (impl_thread_ != NULL) && (impl_thread_->isRunning());
|
||||
}
|
||||
|
||||
CORE_DISALLOW_COPY_AND_ASSIGN(Impl);
|
||||
};
|
||||
|
||||
Timer::Timer() : impl_(new Timer::Impl()) {
|
||||
@@ -42,16 +71,19 @@ Timer::~Timer() {
|
||||
impl_ = NULL;
|
||||
}
|
||||
|
||||
void Timer::Start(TimerHandler *handler, uint32_t time_in_secs) {
|
||||
impl_->Start(handler, time_in_secs);
|
||||
bool Timer::Start(TimerHandler *handler, uint32_t time_in_secs) {
|
||||
if (!handler || time_in_secs == 0)
|
||||
return false;
|
||||
|
||||
return impl_->Start(handler, time_in_secs);
|
||||
}
|
||||
|
||||
void Timer::Stop() {
|
||||
impl_->requestExitAndWait();
|
||||
impl_->Stop();
|
||||
}
|
||||
|
||||
bool Timer::IsRunning() {
|
||||
return impl_->getTid() < 0;
|
||||
return impl_->IsRunning();
|
||||
}
|
||||
|
||||
} // namespace wvcdm
|
||||
|
||||
@@ -35,5 +35,9 @@ test_name := request_license_test
|
||||
test_src_dir := .
|
||||
include $(LOCAL_PATH)/unit-test.mk
|
||||
|
||||
test_name := timer_unittest
|
||||
test_src_dir := ../core/test
|
||||
include $(LOCAL_PATH)/unit-test.mk
|
||||
|
||||
test_name :=
|
||||
test_src_dir :=
|
||||
|
||||
@@ -16,6 +16,7 @@ adb shell /system/bin/cdm_engine_test
|
||||
adb shell /system/bin/oemcrypto_test
|
||||
adb shell /system/bin/file_store_unittest
|
||||
adb shell /system/bin/device_files_unittest
|
||||
adb shell /system/bin/timer_unittest
|
||||
adb shell LD_LIBRARY_PATH=/system/vendor/lib/mediadrm/ /system/bin/libwvdrmengine_test
|
||||
|
||||
adb shell am start com.widevine.test/com.widevine.test.MediaDrmAPITest
|
||||
|
||||
Reference in New Issue
Block a user