Store last data received from WindowInfosListener
Store the last data received from WindowInfoListener on the client so it
can easily be retrieved when a new caller registers to listen for
updates. This will help with accessibility since they won't need to
register their listener all the time and instead just get the last data
that was sent, immediately.
From the system server process, the data is constantly being updated
because WindowInfo is sent to InputDispatcher when any geometry in SF
changes. If a different process registers for the WindowInfoListener,
it's possible the initial data will be empty since we won't explicitly
request the latest data immediately.
Test: Accessibility register only when enabled
Bug: 222767081
Change-Id: If13b8f44bc2fc38796df009d389b984408da55b3
diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp
index 27856ce..efa73df 100644
--- a/libs/gui/SurfaceComposerClient.cpp
+++ b/libs/gui/SurfaceComposerClient.cpp
@@ -2320,9 +2320,11 @@
}
status_t SurfaceComposerClient::addWindowInfosListener(
- const sp<WindowInfosListener>& windowInfosListener) {
+ const sp<WindowInfosListener>& windowInfosListener,
+ std::pair<std::vector<gui::WindowInfo>, std::vector<gui::DisplayInfo>>* outInitialInfo) {
return WindowInfosListenerReporter::getInstance()
- ->addWindowInfosListener(windowInfosListener, ComposerService::getComposerService());
+ ->addWindowInfosListener(windowInfosListener, ComposerService::getComposerService(),
+ outInitialInfo);
}
status_t SurfaceComposerClient::removeWindowInfosListener(
diff --git a/libs/gui/WindowInfosListenerReporter.cpp b/libs/gui/WindowInfosListenerReporter.cpp
index 4112f74..cfc7dbc 100644
--- a/libs/gui/WindowInfosListenerReporter.cpp
+++ b/libs/gui/WindowInfosListenerReporter.cpp
@@ -31,7 +31,8 @@
status_t WindowInfosListenerReporter::addWindowInfosListener(
const sp<WindowInfosListener>& windowInfosListener,
- const sp<ISurfaceComposer>& surfaceComposer) {
+ const sp<ISurfaceComposer>& surfaceComposer,
+ std::pair<std::vector<gui::WindowInfo>, std::vector<gui::DisplayInfo>>* outInitialInfo) {
status_t status = OK;
{
std::scoped_lock lock(mListenersMutex);
@@ -42,6 +43,11 @@
if (status == OK) {
mWindowInfosListeners.insert(windowInfosListener);
}
+
+ if (outInitialInfo != nullptr) {
+ outInitialInfo->first = mLastWindowInfos;
+ outInitialInfo->second = mLastDisplayInfos;
+ }
}
return status;
@@ -55,6 +61,10 @@
std::scoped_lock lock(mListenersMutex);
if (mWindowInfosListeners.size() == 1) {
status = surfaceComposer->removeWindowInfosListener(this);
+ // Clear the last stored state since we're disabling updates and don't want to hold
+ // stale values
+ mLastWindowInfos.clear();
+ mLastDisplayInfos.clear();
}
if (status == OK) {
@@ -75,6 +85,9 @@
for (auto listener : mWindowInfosListeners) {
windowInfosListeners.insert(listener);
}
+
+ mLastWindowInfos = windowInfos;
+ mLastDisplayInfos = displayInfos;
}
for (auto listener : windowInfosListeners) {
diff --git a/libs/gui/include/gui/SurfaceComposerClient.h b/libs/gui/include/gui/SurfaceComposerClient.h
index c8ac166..9d03f58 100644
--- a/libs/gui/include/gui/SurfaceComposerClient.h
+++ b/libs/gui/include/gui/SurfaceComposerClient.h
@@ -696,7 +696,10 @@
static status_t removeTunnelModeEnabledListener(
const sp<gui::ITunnelModeEnabledListener>& listener);
- status_t addWindowInfosListener(const sp<gui::WindowInfosListener>& windowInfosListener);
+ status_t addWindowInfosListener(
+ const sp<gui::WindowInfosListener>& windowInfosListener,
+ std::pair<std::vector<gui::WindowInfo>, std::vector<gui::DisplayInfo>>* outInitialInfo =
+ nullptr);
status_t removeWindowInfosListener(const sp<gui::WindowInfosListener>& windowInfosListener);
protected:
diff --git a/libs/gui/include/gui/WindowInfosListenerReporter.h b/libs/gui/include/gui/WindowInfosListenerReporter.h
index 96bd0b1..3b4aed4 100644
--- a/libs/gui/include/gui/WindowInfosListenerReporter.h
+++ b/libs/gui/include/gui/WindowInfosListenerReporter.h
@@ -34,15 +34,19 @@
const std::vector<gui::DisplayInfo>&,
const sp<gui::IWindowInfosReportedListener>&) override;
- status_t addWindowInfosListener(const sp<gui::WindowInfosListener>& windowInfosListener,
- const sp<ISurfaceComposer>&);
+ status_t addWindowInfosListener(
+ const sp<gui::WindowInfosListener>& windowInfosListener, const sp<ISurfaceComposer>&,
+ std::pair<std::vector<gui::WindowInfo>, std::vector<gui::DisplayInfo>>* outInitialInfo);
status_t removeWindowInfosListener(const sp<gui::WindowInfosListener>& windowInfosListener,
- const sp<ISurfaceComposer>&);
+ const sp<ISurfaceComposer>& surfaceComposer);
void reconnect(const sp<ISurfaceComposer>&);
private:
std::mutex mListenersMutex;
std::unordered_set<sp<gui::WindowInfosListener>, SpHash<gui::WindowInfosListener>>
mWindowInfosListeners GUARDED_BY(mListenersMutex);
+
+ std::vector<gui::WindowInfo> mLastWindowInfos GUARDED_BY(mListenersMutex);
+ std::vector<gui::DisplayInfo> mLastDisplayInfos GUARDED_BY(mListenersMutex);
};
} // namespace android