From 4632e1f53bbae4bd719ee595d3266a132f7d0a57 Mon Sep 17 00:00:00 2001 From: Amit Jain Date: Mon, 12 Dec 2022 21:02:22 +0530 Subject: [PATCH] Fixes #24034 --- .../tv/server/service/ContentAppAgentService.java | 11 +++++++++-- 1 file changed, 9 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..03b3027e45c67a 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,9 @@ 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 +41,7 @@ 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,11 @@ 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);