Update syncInputWindows to use a callback.
Adds callbacks to InputWindowCommands and updates
SurfaceComposerClient::Transaction::syncInputWindows to use those
callbacks. A subsequent CL will replace syncInputWindows with a method
that adds user defined callbacks to InputWindowCommands. The condition
variable added to SurfaceComposerClient::Transaction is used to retain
syncInputWindows' existing behavior and will be removed once users can
define callbacks.
Bug: b/222421815
Test: manual, TransactionApplicationTest, SwitchImeWindowsFromGestureNavTest
Change-Id: Ib582aded1e42f5e049ebe21d5f2ccedf4cf7d654
diff --git a/libs/gui/LayerState.cpp b/libs/gui/LayerState.cpp
index 7f0f638..59c4c5d 100644
--- a/libs/gui/LayerState.cpp
+++ b/libs/gui/LayerState.cpp
@@ -664,29 +664,44 @@
changes |= !other.focusRequests.empty();
focusRequests.insert(focusRequests.end(), std::make_move_iterator(other.focusRequests.begin()),
std::make_move_iterator(other.focusRequests.end()));
- changes |= other.syncInputWindows && !syncInputWindows;
- syncInputWindows |= other.syncInputWindows;
+ changes |= !other.windowInfosReportedListeners.empty();
+ windowInfosReportedListeners.insert(other.windowInfosReportedListeners.begin(),
+ other.windowInfosReportedListeners.end());
return changes;
}
bool InputWindowCommands::empty() const {
- return focusRequests.empty() && !syncInputWindows;
+ return focusRequests.empty() && windowInfosReportedListeners.empty();
}
void InputWindowCommands::clear() {
focusRequests.clear();
- syncInputWindows = false;
+ windowInfosReportedListeners.clear();
}
status_t InputWindowCommands::write(Parcel& output) const {
SAFE_PARCEL(output.writeParcelableVector, focusRequests);
- SAFE_PARCEL(output.writeBool, syncInputWindows);
+
+ SAFE_PARCEL(output.writeInt32, windowInfosReportedListeners.size());
+ for (const auto& listener : windowInfosReportedListeners) {
+ SAFE_PARCEL(output.writeStrongBinder, listener);
+ }
+
return NO_ERROR;
}
status_t InputWindowCommands::read(const Parcel& input) {
SAFE_PARCEL(input.readParcelableVector, &focusRequests);
- SAFE_PARCEL(input.readBool, &syncInputWindows);
+
+ int listenerSize = 0;
+ SAFE_PARCEL_READ_SIZE(input.readInt32, &listenerSize, input.dataSize());
+ windowInfosReportedListeners.reserve(listenerSize);
+ for (int i = 0; i < listenerSize; i++) {
+ sp<gui::IWindowInfosReportedListener> listener;
+ SAFE_PARCEL(input.readStrongBinder, &listener);
+ windowInfosReportedListeners.insert(listener);
+ }
+
return NO_ERROR;
}
diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp
index 7191de8..647a22c 100644
--- a/libs/gui/SurfaceComposerClient.cpp
+++ b/libs/gui/SurfaceComposerClient.cpp
@@ -19,6 +19,7 @@
#include <stdint.h>
#include <sys/types.h>
+#include <android/gui/BnWindowInfosReportedListener.h>
#include <android/gui/DisplayState.h>
#include <android/gui/ISurfaceComposerClient.h>
#include <android/gui/IWindowInfosListener.h>
@@ -635,7 +636,8 @@
mDesiredPresentTime(other.mDesiredPresentTime),
mIsAutoTimestamp(other.mIsAutoTimestamp),
mFrameTimelineInfo(other.mFrameTimelineInfo),
- mApplyToken(other.mApplyToken) {
+ mApplyToken(other.mApplyToken),
+ mWindowInfosReportedEvent(other.mWindowInfosReportedEvent) {
mDisplayStates = other.mDisplayStates;
mComposerStates = other.mComposerStates;
mInputWindowCommands = other.mInputWindowCommands;
@@ -879,6 +881,9 @@
mEarlyWakeupStart = mEarlyWakeupStart || other.mEarlyWakeupStart;
mEarlyWakeupEnd = mEarlyWakeupEnd || other.mEarlyWakeupEnd;
mApplyToken = other.mApplyToken;
+ if (other.mWindowInfosReportedEvent) {
+ mWindowInfosReportedEvent = std::move(other.mWindowInfosReportedEvent);
+ }
mergeFrameTimelineInfo(mFrameTimelineInfo, other.mFrameTimelineInfo);
@@ -901,6 +906,7 @@
mIsAutoTimestamp = true;
clearFrameTimelineInfo(mFrameTimelineInfo);
mApplyToken = nullptr;
+ mWindowInfosReportedEvent = nullptr;
}
uint64_t SurfaceComposerClient::Transaction::getId() {
@@ -1047,6 +1053,10 @@
hasListenerCallbacks, listenerCallbacks, mId);
mId = generateId();
+ if (mWindowInfosReportedEvent && !mWindowInfosReportedEvent->wait()) {
+ ALOGE("Timed out waiting for window infos to be reported.");
+ }
+
// Clear the current states and flags
clear();
@@ -1733,8 +1743,25 @@
return *this;
}
+class NotifyWindowInfosReported : public gui::BnWindowInfosReportedListener {
+public:
+ NotifyWindowInfosReported(
+ std::shared_ptr<SurfaceComposerClient::Event> windowInfosReportedEvent)
+ : mWindowInfosReportedEvent(windowInfosReportedEvent) {}
+
+ binder::Status onWindowInfosReported() {
+ mWindowInfosReportedEvent->set();
+ return binder::Status::ok();
+ }
+
+private:
+ std::shared_ptr<SurfaceComposerClient::Event> mWindowInfosReportedEvent;
+};
+
SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::syncInputWindows() {
- mInputWindowCommands.syncInputWindows = true;
+ mWindowInfosReportedEvent = std::make_shared<Event>();
+ mInputWindowCommands.windowInfosReportedListeners.insert(
+ sp<NotifyWindowInfosReported>::make(mWindowInfosReportedEvent));
return *this;
}
@@ -2809,4 +2836,17 @@
}
}
+// ---------------------------------------------------------------------------------
+
+void SurfaceComposerClient::Event::set() {
+ std::lock_guard<std::mutex> lock(mMutex);
+ mComplete = true;
+ mConditionVariable.notify_all();
+}
+
+bool SurfaceComposerClient::Event::wait() {
+ std::unique_lock<std::mutex> lock(mMutex);
+ return mConditionVariable.wait_for(lock, sTimeout, [this] { return mComplete; });
+}
+
} // namespace android
diff --git a/libs/gui/include/gui/LayerState.h b/libs/gui/include/gui/LayerState.h
index 37a1595..423cd84 100644
--- a/libs/gui/include/gui/LayerState.h
+++ b/libs/gui/include/gui/LayerState.h
@@ -21,6 +21,7 @@
#include <stdint.h>
#include <sys/types.h>
+#include <android/gui/IWindowInfosReportedListener.h>
#include <android/native_window.h>
#include <gui/IGraphicBufferProducer.h>
#include <gui/ITransactionCompletedListener.h>
@@ -359,7 +360,9 @@
struct InputWindowCommands {
std::vector<gui::FocusRequest> focusRequests;
- bool syncInputWindows{false};
+ std::unordered_set<sp<gui::IWindowInfosReportedListener>,
+ SpHash<gui::IWindowInfosReportedListener>>
+ windowInfosReportedListeners;
// Merges the passed in commands and returns true if there were any changes.
bool merge(const InputWindowCommands& other);
diff --git a/libs/gui/include/gui/SurfaceComposerClient.h b/libs/gui/include/gui/SurfaceComposerClient.h
index 9f036a6..0927363 100644
--- a/libs/gui/include/gui/SurfaceComposerClient.h
+++ b/libs/gui/include/gui/SurfaceComposerClient.h
@@ -387,6 +387,22 @@
std::unordered_set<sp<SurfaceControl>, SCHash> surfaceControls;
};
+ // TODO(b/222421815) this class should be removed when
+ // SurfaceComposerClient::Transaction::syncInputWindows is removed and replaced with a method
+ // for adding callbacks to InputWindowCommands.
+ class Event {
+ private:
+ static constexpr std::chrono::seconds sTimeout{5};
+
+ bool mComplete = false;
+ std::condition_variable mConditionVariable;
+ std::mutex mMutex;
+
+ public:
+ void set();
+ bool wait();
+ };
+
class Transaction : public Parcelable {
private:
void releaseBufferIfOverwriting(const layer_state_t& state);
@@ -436,6 +452,8 @@
InputWindowCommands mInputWindowCommands;
int mStatus = NO_ERROR;
+ std::shared_ptr<Event> mWindowInfosReportedEvent = nullptr;
+
layer_state_t* getLayerState(const sp<SurfaceControl>& sc);
DisplayState& getDisplayState(const sp<IBinder>& token);