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

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

Merge "libbinder: attachObject* APIs [[nodiscard]]" am: 02c4473b am: dc9149f9 am: f3cc7855

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

Change-Id: I8ba680fe475e7b07b734675fccdfa03ab65c500c
parents 47e6dd1b f3cc7855
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -167,9 +167,12 @@ sp<IBinder> getDeviceService(std::vector<std::string>&& serviceDispatcherArgs) {
        ALOGE("RpcSession::getRootObject returns nullptr");
        return nullptr;
    }

    LOG_ALWAYS_FATAL_IF(
            nullptr !=
            binder->attachObject(kDeviceServiceExtraId,
                                 static_cast<void*>(new CommandResult(std::move(*result))), nullptr,
                         &cleanupCommandResult);
                                 &cleanupCommandResult));
    return binder;
}

+7 −8
Original line number Diff line number Diff line
@@ -259,21 +259,20 @@ public:
     * but calls from different threads are allowed to be interleaved.
     *
     * This returns the object which is already attached. If this returns a
     * non-null value, it means that attachObject failed. TODO(b/192023359):
     * remove logs and add [[nodiscard]]
     * non-null value, it means that attachObject failed (a given objectID can
     * only be used once).
     */
    virtual void* attachObject(const void* objectID, void* object, void* cleanupCookie,
                               object_cleanup_func func) = 0;
    [[nodiscard]] virtual void* attachObject(const void* objectID, void* object,
                                             void* cleanupCookie, object_cleanup_func func) = 0;
    /**
     * Returns object attached with attachObject.
     */
    virtual void*           findObject(const void* objectID) const = 0;
    [[nodiscard]] virtual void* findObject(const void* objectID) const = 0;
    /**
     * Returns object attached with attachObject, and detaches it. This does not
     * delete the object. This is equivalent to using attachObject to attach a null
     * object.
     * delete the object.
     */
    virtual void* detachObject(const void* objectID) = 0;
    [[nodiscard]] virtual void* detachObject(const void* objectID) = 0;

    /**
     * Use the lock that this binder contains internally. For instance, this can
+2 −1
Original line number Diff line number Diff line
@@ -47,7 +47,8 @@ static void* kValue = static_cast<void*>(new bool{true});
void clean(const void* /*id*/, void* /*obj*/, void* /*cookie*/){/* do nothing */};

static void attach(const sp<IBinder>& binder) {
    binder->attachObject(kId, kValue, nullptr /*cookie*/, clean);
    // can only attach once
    CHECK_EQ(nullptr, binder->attachObject(kId, kValue, nullptr /*cookie*/, clean));
}
static bool has(const sp<IBinder>& binder) {
    return binder != nullptr && binder->findObject(kId) == kValue;
+10 −8
Original line number Diff line number Diff line
@@ -62,20 +62,22 @@ static const std::vector<std::function<void(FuzzedDataProvider*, IBinder*)>> gIB
             object = fdp->ConsumeIntegral<uint32_t>();
             cleanup_cookie = fdp->ConsumeIntegral<uint32_t>();
             IBinder::object_cleanup_func func = IBinder::object_cleanup_func();
             ibinder->attachObject(fdp->ConsumeBool() ? reinterpret_cast<void*>(&objectID)
             (void)ibinder->attachObject(fdp->ConsumeBool() ? reinterpret_cast<void*>(&objectID)
                                                            : nullptr,
                                   fdp->ConsumeBool() ? reinterpret_cast<void*>(&object) : nullptr,
                                   fdp->ConsumeBool() ? reinterpret_cast<void*>(&cleanup_cookie)
                                         fdp->ConsumeBool() ? reinterpret_cast<void*>(&object)
                                                            : nullptr,
                                         fdp->ConsumeBool()
                                                 ? reinterpret_cast<void*>(&cleanup_cookie)
                                                 : nullptr,
                                         func);
         },
         [](FuzzedDataProvider* fdp, IBinder* ibinder) -> void {
             uint32_t id = fdp->ConsumeIntegral<uint32_t>();
             ibinder->findObject(reinterpret_cast<void*>(&id));
             (void)ibinder->findObject(reinterpret_cast<void*>(&id));
         },
         [](FuzzedDataProvider* fdp, IBinder* ibinder) -> void {
             uint32_t id = fdp->ConsumeIntegral<uint32_t>();
             ibinder->detachObject(reinterpret_cast<void*>(&id));
             (void)ibinder->detachObject(reinterpret_cast<void*>(&id));
         },
         [](FuzzedDataProvider* fdp, IBinder* ibinder) -> void {
             uint32_t code = fdp->ConsumeIntegral<uint32_t>();