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

Commit 75fe7e54 authored by Steven Moreland's avatar Steven Moreland Committed by Automerger Merge Worker
Browse files

Merge "Merge changes Ib1c28c94,Id3485a2a,If5ad5acf,Idc9054bd,Ie4e7e25d am:...

Merge "Merge changes Ib1c28c94,Id3485a2a,If5ad5acf,Idc9054bd,Ie4e7e25d am: 756621f5 am: aae80e18" into sc-dev-plus-aosp am: d2674a39 am: 3c0f30e5

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/native/+/15128207

Change-Id: Id4a8839d6096d7484b0abc5b66a49cc7dc12d192
parents 3f7c03bf 3c0f30e5
Loading
Loading
Loading
Loading
+26 −10
Original line number Diff line number Diff line
@@ -179,6 +179,17 @@ status_t IBinder::setRpcClientDebug(android::base::unique_fd socketFd,
    return transact(SET_RPC_CLIENT_TRANSACTION, data, &reply);
}

void IBinder::withLock(const std::function<void()>& doWithLock) {
    BBinder* local = localBinder();
    if (local) {
        local->withLock(doWithLock);
        return;
    }
    BpBinder* proxy = this->remoteBinder();
    LOG_ALWAYS_FATAL_IF(proxy == nullptr, "binder object must be either local or remote");
    proxy->withLock(doWithLock);
}

// ---------------------------------------------------------------------------

class BBinder::RpcServerLink : public IBinder::DeathRecipient {
@@ -311,15 +322,13 @@ status_t BBinder::dump(int /*fd*/, const Vector<String16>& /*args*/)
    return NO_ERROR;
}

void BBinder::attachObject(
    const void* objectID, void* object, void* cleanupCookie,
    object_cleanup_func func)
{
void* BBinder::attachObject(const void* objectID, void* object, void* cleanupCookie,
                            object_cleanup_func func) {
    Extras* e = getOrCreateExtras();
    if (!e) return; // out of memory
    if (!e) return nullptr; // out of memory

    AutoMutex _l(e->mLock);
    e->mObjects.attach(objectID, object, cleanupCookie, func);
    return e->mObjects.attach(objectID, object, cleanupCookie, func);
}

void* BBinder::findObject(const void* objectID) const
@@ -331,13 +340,20 @@ void* BBinder::findObject(const void* objectID) const
    return e->mObjects.find(objectID);
}

void BBinder::detachObject(const void* objectID)
{
void* BBinder::detachObject(const void* objectID) {
    Extras* e = mExtras.load(std::memory_order_acquire);
    if (!e) return;
    if (!e) return nullptr;

    AutoMutex _l(e->mLock);
    return e->mObjects.detach(objectID);
}

void BBinder::withLock(const std::function<void()>& doWithLock) {
    Extras* e = getOrCreateExtras();
    LOG_ALWAYS_FATAL_IF(!e, "no memory");

    AutoMutex _l(e->mLock);
    e->mObjects.detach(objectID);
    doWithLock();
}

BBinder* BBinder::localBinder()
+24 −20
Original line number Diff line number Diff line
@@ -61,22 +61,22 @@ BpBinder::ObjectManager::~ObjectManager()
    kill();
}

void BpBinder::ObjectManager::attach(
    const void* objectID, void* object, void* cleanupCookie,
    IBinder::object_cleanup_func func)
{
void* BpBinder::ObjectManager::attach(const void* objectID, void* object, void* cleanupCookie,
                                      IBinder::object_cleanup_func func) {
    entry_t e;
    e.object = object;
    e.cleanupCookie = cleanupCookie;
    e.func = func;

    if (mObjects.indexOfKey(objectID) >= 0) {
        ALOGE("Trying to attach object ID %p to binder ObjectManager %p with object %p, but object ID already in use",
    if (ssize_t idx = mObjects.indexOfKey(objectID); idx >= 0) {
        ALOGI("Trying to attach object ID %p to binder ObjectManager %p with object %p, but object "
              "ID already in use",
              objectID, this, object);
        return;
        return mObjects[idx].object;
    }

    mObjects.add(objectID, e);
    return nullptr;
}

void* BpBinder::ObjectManager::find(const void* objectID) const
@@ -86,9 +86,12 @@ void* BpBinder::ObjectManager::find(const void* objectID) const
    return mObjects.valueAt(i).object;
}

void BpBinder::ObjectManager::detach(const void* objectID)
{
    mObjects.removeItem(objectID);
void* BpBinder::ObjectManager::detach(const void* objectID) {
    ssize_t idx = mObjects.indexOfKey(objectID);
    if (idx < 0) return nullptr;
    void* value = mObjects[idx].object;
    mObjects.removeItemsAt(idx, 1);
    return value;
}

void BpBinder::ObjectManager::kill()
@@ -406,14 +409,11 @@ void BpBinder::reportOneDeath(const Obituary& obit)
    recipient->binderDied(wp<BpBinder>::fromExisting(this));
}


void BpBinder::attachObject(
    const void* objectID, void* object, void* cleanupCookie,
    object_cleanup_func func)
{
void* BpBinder::attachObject(const void* objectID, void* object, void* cleanupCookie,
                             object_cleanup_func func) {
    AutoMutex _l(mLock);
    ALOGV("Attaching object %p to binder %p (manager=%p)", object, this, &mObjects);
    mObjects.attach(objectID, object, cleanupCookie, func);
    return mObjects.attach(objectID, object, cleanupCookie, func);
}

void* BpBinder::findObject(const void* objectID) const
@@ -422,10 +422,14 @@ void* BpBinder::findObject(const void* objectID) const
    return mObjects.find(objectID);
}

void BpBinder::detachObject(const void* objectID)
{
void* BpBinder::detachObject(const void* objectID) {
    AutoMutex _l(mLock);
    return mObjects.detach(objectID);
}

void BpBinder::withLock(const std::function<void()>& doWithLock) {
    AutoMutex _l(mLock);
    mObjects.detach(objectID);
    doWithLock();
}

BpBinder* BpBinder::remoteBinder()
+1 −1
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@
      "name": "binderTextOutputTest"
    },
    {
      "name": "binderParcelTest"
      "name": "binderUnitTest"
    },
    {
      "name": "binderLibTest"
+4 −5
Original line number Diff line number Diff line
@@ -54,12 +54,11 @@ public:
                                        uint32_t flags = 0,
                                        wp<DeathRecipient>* outRecipient = nullptr);

    virtual void        attachObject(   const void* objectID,
                                        void* object,
                                        void* cleanupCookie,
    virtual void* attachObject(const void* objectID, void* object, void* cleanupCookie,
                               object_cleanup_func func) final;
    virtual void*       findObject(const void* objectID) const final;
    virtual void        detachObject(const void* objectID) final;
    virtual void* detachObject(const void* objectID) final;
    void withLock(const std::function<void()>& doWithLock);

    virtual BBinder*    localBinder();

+14 −19
Original line number Diff line number Diff line
@@ -72,12 +72,11 @@ public:
                                        uint32_t flags = 0,
                                        wp<DeathRecipient>* outRecipient = nullptr);

    virtual void        attachObject(   const void* objectID,
                                        void* object,
                                        void* cleanupCookie,
    virtual void* attachObject(const void* objectID, void* object, void* cleanupCookie,
                               object_cleanup_func func) final;
    virtual void*       findObject(const void* objectID) const final;
    virtual void        detachObject(const void* objectID) final;
    virtual void* detachObject(const void* objectID) final;
    void withLock(const std::function<void()>& doWithLock);

    virtual BpBinder*   remoteBinder();

@@ -91,18 +90,15 @@ public:
    static void         setLimitCallback(binder_proxy_limit_callback cb);
    static void         setBinderProxyCountWatermarks(int high, int low);

    class ObjectManager
    {
    class ObjectManager {
    public:
        ObjectManager();
        ~ObjectManager();

        void        attach( const void* objectID,
                            void* object,
                            void* cleanupCookie,
        void* attach(const void* objectID, void* object, void* cleanupCookie,
                     IBinder::object_cleanup_func func);
        void* find(const void* objectID) const;
        void        detach(const void* objectID);
        void* detach(const void* objectID);

        void kill();

@@ -110,8 +106,7 @@ public:
        ObjectManager(const ObjectManager&);
        ObjectManager& operator=(const ObjectManager&);

        struct entry_t
        {
        struct entry_t {
            void* object;
            void* cleanupCookie;
            IBinder::object_cleanup_func func;
Loading