Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e2cd3353 authored by Gloria Wang's avatar Gloria Wang Committed by Android (Google) Code Review
Browse files

Merge "Fix for bug 4165823. Add death listener to clean-up drmserver...

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
parents 6efa3599 9e1e9a33
Loading
Loading
Loading
Loading
+24 −8
Original line number Original line Diff line number Diff line
@@ -28,8 +28,9 @@ using namespace android;


#define INVALID_VALUE -1
#define INVALID_VALUE -1


Mutex DrmManagerClientImpl::mMutex;
Mutex DrmManagerClientImpl::sMutex;
sp<IDrmManagerService> DrmManagerClientImpl::mDrmManagerService;
sp<IDrmManagerService> DrmManagerClientImpl::sDrmManagerService;
sp<DrmManagerClientImpl::DeathNotifier> DrmManagerClientImpl::sDeathNotifier;
const String8 DrmManagerClientImpl::EMPTY_STRING("");
const String8 DrmManagerClientImpl::EMPTY_STRING("");


DrmManagerClientImpl* DrmManagerClientImpl::create(int* pUniqueId) {
DrmManagerClientImpl* DrmManagerClientImpl::create(int* pUniqueId) {
@@ -47,8 +48,8 @@ void DrmManagerClientImpl::remove(int uniqueId) {
}
}


const sp<IDrmManagerService>& DrmManagerClientImpl::getDrmManagerService() {
const sp<IDrmManagerService>& DrmManagerClientImpl::getDrmManagerService() {
    mMutex.lock();
    Mutex::Autolock lock(sMutex);
    if (NULL == mDrmManagerService.get()) {
    if (NULL == sDrmManagerService.get()) {
        sp<IServiceManager> sm = defaultServiceManager();
        sp<IServiceManager> sm = defaultServiceManager();
        sp<IBinder> binder;
        sp<IBinder> binder;
        do {
        do {
@@ -62,11 +63,13 @@ const sp<IDrmManagerService>& DrmManagerClientImpl::getDrmManagerService() {
            reqt.tv_nsec = 500000000; //0.5 sec
            reqt.tv_nsec = 500000000; //0.5 sec
            nanosleep(&reqt, NULL);
            nanosleep(&reqt, NULL);
        } while (true);
        } while (true);

        if (NULL == sDeathNotifier.get()) {
        mDrmManagerService = interface_cast<IDrmManagerService>(binder);
            sDeathNotifier = new DeathNotifier();
        }
        binder->linkToDeath(sDeathNotifier);
        sDrmManagerService = interface_cast<IDrmManagerService>(binder);
    }
    }
    mMutex.unlock();
    return sDrmManagerService;
    return mDrmManagerService;
}
}


void DrmManagerClientImpl::addClient(int uniqueId) {
void DrmManagerClientImpl::addClient(int uniqueId) {
@@ -309,3 +312,16 @@ status_t DrmManagerClientImpl::notify(const DrmInfoEvent& event) {
    return DRM_NO_ERROR;
    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!");
}
+10 −2
Original line number Original line Diff line number Diff line
@@ -407,9 +407,17 @@ private:
    Mutex mLock;
    Mutex mLock;
    sp<DrmManagerClient::OnInfoListener> mOnInfoListener;
    sp<DrmManagerClient::OnInfoListener> mOnInfoListener;


    class DeathNotifier: public IBinder::DeathRecipient {
        public:
            DeathNotifier() {}
            virtual ~DeathNotifier();
            virtual void binderDied(const wp<IBinder>& who);
    };

private:
private:
    static Mutex mMutex;
    static Mutex sMutex;
    static sp<IDrmManagerService> mDrmManagerService;
    static sp<DeathNotifier> sDeathNotifier;
    static sp<IDrmManagerService> sDrmManagerService;
    static const sp<IDrmManagerService>& getDrmManagerService();
    static const sp<IDrmManagerService>& getDrmManagerService();
    static const String8 EMPTY_STRING;
    static const String8 EMPTY_STRING;
};
};