summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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;
};