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

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

Merge "libbinder: add hints to waitForService error" am: ea830510 am: c82f3925 am: bc592752

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

Change-Id: Ic825ccc516a4d1aab4cbd170c6e5f0710f5acf8e
parents 7dbdbc80 bc592752
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -326,6 +326,11 @@ sp<IBinder> ServiceManagerShim::waitForService(const String16& name16)

    while(true) {
        {
            // It would be really nice if we could read binder commands on this
            // thread instead of needing a threadpool to be started, but for
            // instance, if we call getAndExecuteCommand, it might be the case
            // that another thread serves the callback, and we never get a
            // command, so we hang indefinitely.
            std::unique_lock<std::mutex> lock(waiter->mMutex);
            using std::literals::chrono_literals::operator""s;
            waiter->mCv.wait_for(lock, 1s, [&] {
@@ -334,6 +339,8 @@ sp<IBinder> ServiceManagerShim::waitForService(const String16& name16)
            if (waiter->mBinder != nullptr) return waiter->mBinder;
        }

        ALOGW("Waited one second for %s (is service started? are binder threads started and available?)", name.c_str());

        // Handle race condition for lazy services. Here is what can happen:
        // - the service dies (not processed by init yet).
        // - sm processes death notification.
@@ -347,8 +354,6 @@ sp<IBinder> ServiceManagerShim::waitForService(const String16& name16)
            return nullptr;
        }
        if (out != nullptr) return out;

        ALOGW("Waited one second for %s", name.c_str());
    }
}