summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGloria Wang <gwang@google.com>2011-03-23 22:35:13 -0700
committerGloria Wang <gwang@google.com>2011-03-24 10:30:57 -0700
commit07d0220bcc9036bcbe36819912559267d9c1c538 (patch)
treeb321b94e19eeca3423f8cf5e110e4206b70f483a
parenteabd34665adc284525fe7337ad5c56a8b92964ef (diff)
downloadframeworks_av-07d0220bcc9036bcbe36819912559267d9c1c538.zip
frameworks_av-07d0220bcc9036bcbe36819912559267d9c1c538.tar.gz
frameworks_av-07d0220bcc9036bcbe36819912559267d9c1c538.tar.bz2
Fix for bug 4165823.
Add death listener to clean-up drmserver appropriately when drmserver died. Cherry-pick from master. Do not merge. Change-Id: I7782cc96ce173a87ebfd315950f3880fa90294d6
-rw-r--r--drm/libdrmframework/DrmManagerClientImpl.cpp32
-rw-r--r--drm/libdrmframework/include/DrmManagerClientImpl.h12
2 files changed, 34 insertions, 10 deletions
diff --git a/drm/libdrmframework/DrmManagerClientImpl.cpp b/drm/libdrmframework/DrmManagerClientImpl.cpp
index d20de92..9c7fed3 100644
--- a/drm/libdrmframework/DrmManagerClientImpl.cpp
+++ b/drm/libdrmframework/DrmManagerClientImpl.cpp
@@ -28,8 +28,9 @@ using namespace android;
#define INVALID_VALUE -1
-Mutex DrmManagerClientImpl::mMutex;
-sp<IDrmManagerService> DrmManagerClientImpl::mDrmManagerService;
+Mutex DrmManagerClientImpl::sMutex;
+sp<IDrmManagerService> DrmManagerClientImpl::sDrmManagerService;
+sp<DrmManagerClientImpl::DeathNotifier> DrmManagerClientImpl::sDeathNotifier;
const String8 DrmManagerClientImpl::EMPTY_STRING("");
DrmManagerClientImpl* DrmManagerClientImpl::create(int* pUniqueId) {
@@ -47,8 +48,8 @@ void DrmManagerClientImpl::remove(int uniqueId) {
}
const sp<IDrmManagerService>& DrmManagerClientImpl::getDrmManagerService() {
- mMutex.lock();
- if (NULL == mDrmManagerService.get()) {
+ Mutex::Autolock lock(sMutex);
+ if (NULL == sDrmManagerService.get()) {
sp<IServiceManager> sm = defaultServiceManager();
sp<IBinder> binder;
do {
@@ -62,11 +63,13 @@ const sp<IDrmManagerService>& DrmManagerClientImpl::getDrmManagerService() {
reqt.tv_nsec = 500000000; //0.5 sec
nanosleep(&reqt, NULL);
} while (true);
-
- mDrmManagerService = interface_cast<IDrmManagerService>(binder);
+ if (NULL == sDeathNotifier.get()) {
+ sDeathNotifier = new DeathNotifier();
+ }
+ binder->linkToDeath(sDeathNotifier);
+ sDrmManagerService = interface_cast<IDrmManagerService>(binder);
}
- mMutex.unlock();
- return mDrmManagerService;
+ return sDrmManagerService;
}
void DrmManagerClientImpl::addClient(int uniqueId) {
@@ -309,3 +312,16 @@ status_t DrmManagerClientImpl::notify(const DrmInfoEvent& event) {
return DRM_NO_ERROR;
}
+DrmManagerClientImpl::DeathNotifier::~DeathNotifier() {
+ Mutex::Autolock lock(sMutex);
+ if (NULL != sDrmManagerService.get()) {
+ sDrmManagerService->asBinder()->unlinkToDeath(this);
+ }
+}
+
+void DrmManagerClientImpl::DeathNotifier::binderDied(const wp<IBinder>& who) {
+ Mutex::Autolock lock(sMutex);
+ DrmManagerClientImpl::sDrmManagerService.clear();
+ LOGW("DrmManager server died!");
+}
+
diff --git a/drm/libdrmframework/include/DrmManagerClientImpl.h b/drm/libdrmframework/include/DrmManagerClientImpl.h
index 0a7fcd1..429e4c3 100644
--- a/drm/libdrmframework/include/DrmManagerClientImpl.h
+++ b/drm/libdrmframework/include/DrmManagerClientImpl.h
@@ -407,9 +407,17 @@ private:
Mutex mLock;
sp<DrmManagerClient::OnInfoListener> mOnInfoListener;
+ class DeathNotifier: public IBinder::DeathRecipient {
+ public:
+ DeathNotifier() {}
+ virtual ~DeathNotifier();
+ virtual void binderDied(const wp<IBinder>& who);
+ };
+
private:
- static Mutex mMutex;
- static sp<IDrmManagerService> mDrmManagerService;
+ static Mutex sMutex;
+ static sp<DeathNotifier> sDeathNotifier;
+ static sp<IDrmManagerService> sDrmManagerService;
static const sp<IDrmManagerService>& getDrmManagerService();
static const String8 EMPTY_STRING;
};