Merge "Fix for bug 4165823. Add death listener to clean-up drmserver appropriately when drmserver died. Cherry-pick from master. Do not merge." into honeycomb-mr1

This commit is contained in:
Gloria Wang
2011-03-24 10:40:26 -07:00
committed by Android (Google) Code Review
2 changed files with 34 additions and 10 deletions

View File

@@ -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!");
}

View File

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