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

Commit 2f34814d authored by Steven Moreland's avatar Steven Moreland
Browse files

Hold onto linked binder.

unlinkToDeath is no longer required, (this change in behavior is to
avoid leaks) so holding onto ActivityManager here (still calling
unlinkToDeath to avoid a log, but may for instance remove all
unlinkToDeath calls in the future).

Exempt-From-Owner-Approval: approval received on AOSP CL, only
    whitespace difference here.

Bug: 134576445
Test: boot
Change-Id: I273f77aac2b80ba9be70197cc3842f83a11bbd1c
parent 964a7482
Loading
Loading
Loading
Loading
+4 −4
Original line number Original line Diff line number Diff line
@@ -170,6 +170,7 @@ sp<IMediaCodecList> MediaCodecList::getLocalInstance() {
sp<IMediaCodecList> MediaCodecList::sRemoteList;
sp<IMediaCodecList> MediaCodecList::sRemoteList;


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


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


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


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


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


        am.unregisterUidObserver(this);
        mAm.unregisterUidObserver(this);
    }
    }
}
}


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


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


    ActivityManager am;
    if (mRegistered) return;
    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_IDLE
            | ActivityManager::UID_OBSERVER_ACTIVE | ActivityManager::UID_OBSERVER_PROCSTATE,
            | ActivityManager::UID_OBSERVER_ACTIVE | ActivityManager::UID_OBSERVER_PROCSTATE,
            ActivityManager::PROCESS_STATE_UNKNOWN,
            ActivityManager::PROCESS_STATE_UNKNOWN,
            String16("cameraserver"));
            String16("cameraserver"));
    status_t res = am.linkToDeath(this);
    if (res == OK) {
    if (res == OK) {
        mRegistered = true;
        mRegistered = true;
        ALOGV("UidPolicy: Registered with ActivityManager");
        ALOGV("UidPolicy: Registered with ActivityManager");
@@ -2624,9 +2623,8 @@ void CameraService::UidPolicy::registerSelf() {
void CameraService::UidPolicy::unregisterSelf() {
void CameraService::UidPolicy::unregisterSelf() {
    Mutex::Autolock _l(mUidLock);
    Mutex::Autolock _l(mUidLock);


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