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

Commit 1b9d06d6 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Force callers to consume initial WindowInfosUpdate

Previously, this argument was optional. That suggested that there's
guarantee that the update will be provided soon after the listener is
registered. However, that's not the case.

In this CL, we are forcing all users of WindowInfosListener to consume
the initial data. This will save engineering time by forcing the
developer to consider how to handle initial condition immediately, and
not have to do run-time debugging to figure out why the window infos are
sometimes empty (and sometimes not).

Also in this CL, remove the std::pair construct in favor of the existing
WindowInfosUpdate.

Bug: 404661556
Flag: EXEMPT refactor
Test: none
Change-Id: I7ead3f2846fe722f7e7af656feb1a0782fe364ab
parent 5399f2c8
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -3402,10 +3402,10 @@ int SurfaceComposerClient::getGpuContextPriority() {

status_t SurfaceComposerClient::addWindowInfosListener(
        const sp<WindowInfosListener>& windowInfosListener,
        std::pair<std::vector<gui::WindowInfo>, std::vector<gui::DisplayInfo>>* outInitialInfo) {
        gui::WindowInfosUpdate* outInitialUpdate) {
    return WindowInfosListenerReporter::getInstance()
            ->addWindowInfosListener(windowInfosListener, ComposerServiceAIDL::getComposerService(),
                                     outInitialInfo);
                                     outInitialUpdate);
}

status_t SurfaceComposerClient::removeWindowInfosListener(
+5 −8
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ sp<WindowInfosListenerReporter> WindowInfosListenerReporter::getInstance() {
status_t WindowInfosListenerReporter::addWindowInfosListener(
        const sp<WindowInfosListener>& windowInfosListener,
        const sp<gui::ISurfaceComposer>& surfaceComposer,
        std::pair<std::vector<gui::WindowInfo>, std::vector<gui::DisplayInfo>>* outInitialInfo) {
        gui::WindowInfosUpdate* outInitialUpdate) {
    status_t status = OK;
    {
        std::scoped_lock lock(mListenersMutex);
@@ -53,9 +53,8 @@ status_t WindowInfosListenerReporter::addWindowInfosListener(
            mWindowInfosListeners.insert(windowInfosListener);
        }

        if (outInitialInfo != nullptr) {
            outInitialInfo->first = mLastWindowInfos;
            outInitialInfo->second = mLastDisplayInfos;
        if (outInitialUpdate != nullptr) {
            *outInitialUpdate = mLastUpdate;
        }
    }

@@ -77,8 +76,7 @@ status_t WindowInfosListenerReporter::removeWindowInfosListener(
            status = statusTFromBinderStatus(s);
            // Clear the last stored state since we're disabling updates and don't want to hold
            // stale values
            mLastWindowInfos.clear();
            mLastDisplayInfos.clear();
            mLastUpdate = gui::WindowInfosUpdate();
        }

        if (status == OK) {
@@ -100,8 +98,7 @@ binder::Status WindowInfosListenerReporter::onWindowInfosChanged(
            windowInfosListeners.insert(listener);
        }

        mLastWindowInfos = update.windowInfos;
        mLastDisplayInfos = update.displayInfos;
        mLastUpdate = update;
    }

    for (auto listener : windowInfosListeners) {
+2 −4
Original line number Diff line number Diff line
@@ -901,10 +901,8 @@ public:
    static status_t removeTunnelModeEnabledListener(
            const sp<gui::ITunnelModeEnabledListener>& listener);

    status_t addWindowInfosListener(
            const sp<gui::WindowInfosListener>& windowInfosListener,
            std::pair<std::vector<gui::WindowInfo>, std::vector<gui::DisplayInfo>>* outInitialInfo =
                    nullptr);
    status_t addWindowInfosListener(const sp<gui::WindowInfosListener>& windowInfosListener,
                                    gui::WindowInfosUpdate* outInitialUpdate);
    status_t removeWindowInfosListener(const sp<gui::WindowInfosListener>& windowInfosListener);

    static void notifyShutdown();
+4 −6
Original line number Diff line number Diff line
@@ -31,10 +31,9 @@ class WindowInfosListenerReporter : public gui::BnWindowInfosListener {
public:
    static sp<WindowInfosListenerReporter> getInstance();
    binder::Status onWindowInfosChanged(const gui::WindowInfosUpdate& update) override;
    status_t addWindowInfosListener(
            const sp<gui::WindowInfosListener>& windowInfosListener,
    status_t addWindowInfosListener(const sp<gui::WindowInfosListener>& windowInfosListener,
                                    const sp<gui::ISurfaceComposer>&,
            std::pair<std::vector<gui::WindowInfo>, std::vector<gui::DisplayInfo>>* outInitialInfo);
                                    gui::WindowInfosUpdate* outInitialUpdate);
    status_t removeWindowInfosListener(const sp<gui::WindowInfosListener>& windowInfosListener,
                                       const sp<gui::ISurfaceComposer>& surfaceComposer);
    void reconnect(const sp<gui::ISurfaceComposer>&);
@@ -47,8 +46,7 @@ private:
    std::unordered_set<sp<gui::WindowInfosListener>, gui::SpHash<gui::WindowInfosListener>>
            mWindowInfosListeners GUARDED_BY(mListenersMutex);

    std::vector<gui::WindowInfo> mLastWindowInfos GUARDED_BY(mListenersMutex);
    std::vector<gui::DisplayInfo> mLastDisplayInfos GUARDED_BY(mListenersMutex);
    gui::WindowInfosUpdate mLastUpdate GUARDED_BY(mListenersMutex);

    sp<gui::IWindowInfosPublisher> mWindowInfosPublisher;
    int64_t mListenerId;
+2 −3
Original line number Diff line number Diff line
@@ -107,13 +107,12 @@ PointerChoreographer::PointerChoreographer(InputListenerInterface& inputListener
      : PointerChoreographer(
                inputListener, policy,
                [](const sp<android::gui::WindowInfosListener>& listener) {
                    auto initialInfo = std::make_pair(std::vector<android::gui::WindowInfo>{},
                                                      std::vector<android::gui::DisplayInfo>{});
                    gui::WindowInfosUpdate initialInfo;
#if defined(__ANDROID__)
                    SurfaceComposerClient::getDefault()->addWindowInfosListener(listener,
                                                                                &initialInfo);
#endif
                    return initialInfo.first;
                    return initialInfo.windowInfos;
                },
                [](const sp<android::gui::WindowInfosListener>& listener) {
#if defined(__ANDROID__)
Loading