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

Commit 8c38c679 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Crash if can't add window infos listener

When the listener can't be added, device will be unusable. Today, the
callers of 'addWindowInfosListener' simply ignore the condition where
the listener can't be added.

In practice, there's nothing that the client can do to recover from
this. Reboot is the best remedy for those cases.

In the future, this check will help simplify the handling of the initial
condition of window infos.

Bug: 404661556
Flag: EXEMPT refactor
Test: none
Change-Id: I5f887c4a50f2b201ed90025aac468e41010cd12c
parent 01334063
Loading
Loading
Loading
Loading
+11 −18
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@
 * limitations under the License.
 */

#include <android-base/logging.h>
#include <android/gui/ISurfaceComposer.h>
#include <android/gui/IWindowInfosListener.h>
#include <gui/AidlUtil.h>
@@ -35,29 +36,21 @@ sp<WindowInfosListenerReporter> WindowInfosListenerReporter::getInstance() {
android::base::Result<gui::WindowInfosUpdate> WindowInfosListenerReporter::addWindowInfosListener(
        sp<WindowInfosListener> windowInfosListener,
        const sp<gui::ISurfaceComposer>& surfaceComposer) {
    status_t status = OK;
    {
    std::scoped_lock lock(mListenersMutex);
    if (mWindowInfosListeners.empty()) {
        gui::WindowInfosListenerInfo listenerInfo;
            binder::Status s = surfaceComposer->addWindowInfosListener(this, &listenerInfo);
            status = statusTFromBinderStatus(s);
            if (status == OK) {
        binder::Status status = surfaceComposer->addWindowInfosListener(this, &listenerInfo);
        LOG_IF(FATAL, !status.isOk()) << "Can't register window infos listener for pid " << getpid()
                                      << ". Device won't be usable";

        mWindowInfosPublisher = std::move(listenerInfo.windowInfosPublisher);
        mListenerId = listenerInfo.listenerId;
    }
        }

        if (status == OK) {
    mWindowInfosListeners.emplace(std::move(windowInfosListener));
        }

    return mLastUpdate;
}

    return android::base::Error(status);
}

status_t WindowInfosListenerReporter::removeWindowInfosListener(
        const sp<WindowInfosListener>& windowInfosListener,
        const sp<gui::ISurfaceComposer>& surfaceComposer) {