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

Commit b693081b authored by Steven Moreland's avatar Steven Moreland Committed by Gerrit Code Review
Browse files

Merge "Hold onto linked binder."

parents 4c76131a 6a9fc9ee
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -165,6 +165,7 @@ sp<IMediaCodecList> MediaCodecList::getLocalInstance() {
sp<IMediaCodecList> MediaCodecList::sRemoteList;

sp<MediaCodecList::BinderDeathObserver> MediaCodecList::sBinderDeathObserver;
sp<IBinder> MediaCodecList::sMediaPlayer;  // kept since linked to death

void MediaCodecList::BinderDeathObserver::binderDied(const wp<IBinder> &who __unused) {
    Mutex::Autolock _l(sRemoteInitMutex);
@@ -176,15 +177,14 @@ void MediaCodecList::BinderDeathObserver::binderDied(const wp<IBinder> &who __un
sp<IMediaCodecList> MediaCodecList::getInstance() {
    Mutex::Autolock _l(sRemoteInitMutex);
    if (sRemoteList == nullptr) {
        sp<IBinder> binder =
            defaultServiceManager()->getService(String16("media.player"));
        sMediaPlayer = defaultServiceManager()->getService(String16("media.player"));
        sp<IMediaPlayerService> service =
            interface_cast<IMediaPlayerService>(binder);
            interface_cast<IMediaPlayerService>(sMediaPlayer);
        if (service.get() != nullptr) {
            sRemoteList = service->getCodecList();
            if (sRemoteList != nullptr) {
                sBinderDeathObserver = new BinderDeathObserver();
                binder->linkToDeath(sBinderDeathObserver.get());
                sMediaPlayer->linkToDeath(sBinderDeathObserver.get());
            }
        }
        if (sRemoteList == nullptr) {
+1 −0
Original line number Diff line number Diff line
@@ -83,6 +83,7 @@ private:
    };

    static sp<BinderDeathObserver> sBinderDeathObserver;
    static sp<IBinder> sMediaPlayer;

    static sp<IMediaCodecList> sCodecList;
    static sp<IMediaCodecList> sRemoteList;
+5 −8
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@
#include <cutils/multiuser.h>
#include <cutils/properties.h>
#include <binder/IPCThreadState.h>
#include <binder/ActivityManager.h>
#include <binder/PermissionController.h>
#include <binder/IResultReceiver.h>
#include <utils/String16.h>
@@ -502,26 +501,24 @@ status_t AudioPolicyService::printHelp(int out) {
// -----------  AudioPolicyService::UidPolicy implementation ----------

void AudioPolicyService::UidPolicy::registerSelf() {
    ActivityManager am;
    am.registerUidObserver(this, ActivityManager::UID_OBSERVER_GONE
    status_t res = mAm.linkToDeath(this);
    mAm.registerUidObserver(this, ActivityManager::UID_OBSERVER_GONE
            | ActivityManager::UID_OBSERVER_IDLE
            | ActivityManager::UID_OBSERVER_ACTIVE,
            ActivityManager::PROCESS_STATE_UNKNOWN,
            String16("audioserver"));
    status_t res = am.linkToDeath(this);
    if (!res) {
        Mutex::Autolock _l(mLock);
        mObserverRegistered = true;
    } else {
        ALOGE("UidPolicy::registerSelf linkToDeath failed: %d", res);
        am.unregisterUidObserver(this);
        mAm.unregisterUidObserver(this);
    }
}

void AudioPolicyService::UidPolicy::unregisterSelf() {
    ActivityManager am;
    am.unlinkToDeath(this);
    am.unregisterUidObserver(this);
    mAm.unlinkToDeath(this);
    mAm.unregisterUidObserver(this);
    Mutex::Autolock _l(mLock);
    mObserverRegistered = false;
}
+2 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
#include <utils/String8.h>
#include <utils/Vector.h>
#include <utils/SortedVector.h>
#include <binder/ActivityManager.h>
#include <binder/BinderService.h>
#include <binder/IUidObserver.h>
#include <system/audio.h>
@@ -302,6 +303,7 @@ private:

        wp<AudioPolicyService> mService;
        Mutex mLock;
        ActivityManager mAm;
        bool mObserverRegistered;
        std::unordered_map<uid_t, bool> mOverrideUids;
        std::unordered_map<uid_t, bool> mCachedUids;
+4 −6
Original line number Diff line number Diff line
@@ -2395,14 +2395,13 @@ void CameraService::Client::OpsCallback::opChanged(int32_t op,
void CameraService::UidPolicy::registerSelf() {
    Mutex::Autolock _l(mUidLock);

    ActivityManager am;
    if (mRegistered) return;
    am.registerUidObserver(this, ActivityManager::UID_OBSERVER_GONE
    status_t res = mAm.linkToDeath(this);
    mAm.registerUidObserver(this, ActivityManager::UID_OBSERVER_GONE
            | ActivityManager::UID_OBSERVER_IDLE
            | ActivityManager::UID_OBSERVER_ACTIVE,
            ActivityManager::PROCESS_STATE_UNKNOWN,
            String16("cameraserver"));
    status_t res = am.linkToDeath(this);
    if (res == OK) {
        mRegistered = true;
        ALOGV("UidPolicy: Registered with ActivityManager");
@@ -2412,9 +2411,8 @@ void CameraService::UidPolicy::registerSelf() {
void CameraService::UidPolicy::unregisterSelf() {
    Mutex::Autolock _l(mUidLock);

    ActivityManager am;
    am.unregisterUidObserver(this);
    am.unlinkToDeath(this);
    mAm.unregisterUidObserver(this);
    mAm.unlinkToDeath(this);
    mRegistered = false;
    mActiveUids.clear();
    ALOGV("UidPolicy: Unregistered with ActivityManager");
Loading