SF: Trigger ANR when buffer cache is full
* Updates the transaction queue stall listener to take a string that
contains the reason for hanging.
* Updates ClientCache::add to indicate whether or not a failure is due
to the cache being full
* Calls the transaction queue stall listener when the ClientCache is
full
Bug: 244218818
Test: presubmits
Change-Id: I5fdc9aef0f0a1601ace1c42cfac5024c3de8d299
diff --git a/services/surfaceflinger/ClientCache.cpp b/services/surfaceflinger/ClientCache.cpp
index b01932e..2bd8f32 100644
--- a/services/surfaceflinger/ClientCache.cpp
+++ b/services/surfaceflinger/ClientCache.cpp
@@ -59,16 +59,17 @@
return true;
}
-bool ClientCache::add(const client_cache_t& cacheId, const sp<GraphicBuffer>& buffer) {
+base::expected<std::shared_ptr<renderengine::ExternalTexture>, ClientCache::AddError>
+ClientCache::add(const client_cache_t& cacheId, const sp<GraphicBuffer>& buffer) {
auto& [processToken, id] = cacheId;
if (processToken == nullptr) {
ALOGE_AND_TRACE("ClientCache::add - invalid (nullptr) process token");
- return false;
+ return base::unexpected(AddError::Unspecified);
}
if (!buffer) {
ALOGE_AND_TRACE("ClientCache::add - invalid (nullptr) buffer");
- return false;
+ return base::unexpected(AddError::Unspecified);
}
std::lock_guard lock(mMutex);
@@ -81,7 +82,7 @@
token = processToken.promote();
if (!token) {
ALOGE_AND_TRACE("ClientCache::add - invalid token");
- return false;
+ return base::unexpected(AddError::Unspecified);
}
// Only call linkToDeath if not a local binder
@@ -89,7 +90,7 @@
status_t err = token->linkToDeath(mDeathRecipient);
if (err != NO_ERROR) {
ALOGE_AND_TRACE("ClientCache::add - could not link to death");
- return false;
+ return base::unexpected(AddError::Unspecified);
}
}
auto [itr, success] =
@@ -104,17 +105,17 @@
if (processBuffers.size() > BUFFER_CACHE_MAX_SIZE) {
ALOGE_AND_TRACE("ClientCache::add - cache is full");
- return false;
+ return base::unexpected(AddError::CacheFull);
}
LOG_ALWAYS_FATAL_IF(mRenderEngine == nullptr,
"Attempted to build the ClientCache before a RenderEngine instance was "
"ready!");
- processBuffers[id].buffer = std::make_shared<
- renderengine::impl::ExternalTexture>(buffer, *mRenderEngine,
- renderengine::impl::ExternalTexture::Usage::
- READABLE);
- return true;
+
+ return (processBuffers[id].buffer = std::make_shared<
+ renderengine::impl::ExternalTexture>(buffer, *mRenderEngine,
+ renderengine::impl::ExternalTexture::
+ Usage::READABLE));
}
void ClientCache::erase(const client_cache_t& cacheId) {