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


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


    AutoMutex _l(e->mLock);
    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
void* BBinder::findObject(const void* objectID) const
@@ -331,13 +340,20 @@ void* BBinder::findObject(const void* objectID) const
    return e->mObjects.find(objectID);
    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);
    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);
    AutoMutex _l(e->mLock);
    e->mObjects.detach(objectID);
    doWithLock();
}
}


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


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


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


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


void* BpBinder::ObjectManager::find(const void* objectID) const
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;
    return mObjects.valueAt(i).object;
}
}


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


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



void* BpBinder::attachObject(const void* objectID, void* object, void* cleanupCookie,
void BpBinder::attachObject(
                             object_cleanup_func func) {
    const void* objectID, void* object, void* cleanupCookie,
    object_cleanup_func func)
{
    AutoMutex _l(mLock);
    AutoMutex _l(mLock);
    ALOGV("Attaching object %p to binder %p (manager=%p)", object, this, &mObjects);
    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
void* BpBinder::findObject(const void* objectID) const
@@ -422,10 +422,14 @@ void* BpBinder::findObject(const void* objectID) const
    return mObjects.find(objectID);
    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);
    AutoMutex _l(mLock);
    mObjects.detach(objectID);
    doWithLock();
}
}


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


    virtual void        attachObject(   const void* objectID,
    virtual void* attachObject(const void* objectID, void* object, void* cleanupCookie,
                                        void* object,
                                        void* cleanupCookie,
                               object_cleanup_func func) final;
                               object_cleanup_func func) final;
    virtual void*       findObject(const void* objectID) const 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();
    virtual BBinder*    localBinder();


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


    virtual void        attachObject(   const void* objectID,
    virtual void* attachObject(const void* objectID, void* object, void* cleanupCookie,
                                        void* object,
                                        void* cleanupCookie,
                               object_cleanup_func func) final;
                               object_cleanup_func func) final;
    virtual void*       findObject(const void* objectID) const 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();
    virtual BpBinder*   remoteBinder();


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


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


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


        void kill();
        void kill();


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


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