From c4eb51a2a47dd6412c9467bb39586cd26e3e3531 Mon Sep 17 00:00:00 2001 From: amitnj <74272437+amitnj@users.noreply.github.com> Date: Tue, 13 Dec 2022 00:30:51 +0530 Subject: [PATCH] Fixes #24034 (#24037) * Fixes #24034 * Restyled by google-java-format Co-authored-by: Restyled.io --- .../tv/server/service/ContentAppAgentService.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/service/ContentAppAgentService.java b/examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/service/ContentAppAgentService.java index a9a5e2af7d6b47..cc311b9481e194 100644 --- a/examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/service/ContentAppAgentService.java +++ b/examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/service/ContentAppAgentService.java @@ -15,6 +15,8 @@ import com.matter.tv.app.api.MatterIntentConstants; import com.matter.tv.server.model.ContentApp; import com.matter.tv.server.receivers.ContentAppDiscoveryService; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; public class ContentAppAgentService extends Service { @@ -38,6 +40,8 @@ public class ContentAppAgentService extends Service { private static final int ATTRIBUTE_TIMEOUT = 2; // seconds private static ResponseRegistry responseRegistry = new ResponseRegistry(); + private static ExecutorService executorService = + Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); private final IBinder appAgentBinder = new IMatterAppAgent.Stub() { @@ -76,8 +80,14 @@ public boolean reportAttributeChange(int clusterId, int attributeId) ContentApp contentApp = ContentAppDiscoveryService.getReceiverInstance().getDiscoveredContentApp(pkg); if (contentApp != null && contentApp.getEndpointId() != ContentApp.INVALID_ENDPOINTID) { - AppPlatformService.get() - .reportAttributeChange(contentApp.getEndpointId(), clusterId, attributeId); + // Make this call async so that even if the content apps make this call during command + // processing and synchronously, the command processing thread will not block for the + // chip stack lock. + executorService.execute( + () -> { + AppPlatformService.get() + .reportAttributeChange(contentApp.getEndpointId(), clusterId, attributeId); + }); return true; } Log.e(TAG, "No matter content app found for package " + pkg);