15
15
import com .matter .tv .app .api .MatterIntentConstants ;
16
16
import com .matter .tv .server .model .ContentApp ;
17
17
import com .matter .tv .server .receivers .ContentAppDiscoveryService ;
18
+
19
+ import java .util .concurrent .ExecutorService ;
20
+ import java .util .concurrent .Executors ;
18
21
import java .util .concurrent .TimeUnit ;
19
22
20
23
public class ContentAppAgentService extends Service {
@@ -38,6 +41,7 @@ public class ContentAppAgentService extends Service {
38
41
private static final int ATTRIBUTE_TIMEOUT = 2 ; // seconds
39
42
40
43
private static ResponseRegistry responseRegistry = new ResponseRegistry ();
44
+ private static ExecutorService executorService = Executors .newFixedThreadPool (Runtime .getRuntime ().availableProcessors ());
41
45
42
46
private final IBinder appAgentBinder =
43
47
new IMatterAppAgent .Stub () {
@@ -76,8 +80,11 @@ public boolean reportAttributeChange(int clusterId, int attributeId)
76
80
ContentApp contentApp =
77
81
ContentAppDiscoveryService .getReceiverInstance ().getDiscoveredContentApp (pkg );
78
82
if (contentApp != null && contentApp .getEndpointId () != ContentApp .INVALID_ENDPOINTID ) {
79
- AppPlatformService .get ()
80
- .reportAttributeChange (contentApp .getEndpointId (), clusterId , attributeId );
83
+ // Make this call async so that even if the content apps make this call during command
84
+ // processing and synchronously, the command processing thread will not block for the
85
+ // chip stack lock.
86
+ executorService .execute (()->{AppPlatformService .get ()
87
+ .reportAttributeChange (contentApp .getEndpointId (), clusterId , attributeId );});
81
88
return true ;
82
89
}
83
90
Log .e (TAG , "No matter content app found for package " + pkg );
0 commit comments