Generate renewal and expiry events

The android timer class was not generating timer events correctly. This caused
renewal and expiration events not to be sent. A strong pointer to the
timer thread was not held and this caused the android util timer
thread to exit after firing once. This is now addressed.

Bug: 8736545

Merge of https://widevine-internal-review.googlesource.com/#/c/5353/
from the Widevine CDM repository.

Change-Id: I2d904e55d4d10eacc1a51f1c6b5c1a267c92c8d8
This commit is contained in:
Jeff Tinker
2013-05-02 16:42:04 -07:00
parent cb5541b740
commit 3cfb86cea1
6 changed files with 111 additions and 18 deletions

View File

@@ -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