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
+ import java .util .concurrent .ExecutorService ;
19
+ import java .util .concurrent .Executors ;
18
20
import java .util .concurrent .TimeUnit ;
19
21
20
22
public class ContentAppAgentService extends Service {
@@ -38,6 +40,8 @@ public class ContentAppAgentService extends Service {
38
40
private static final int ATTRIBUTE_TIMEOUT = 2 ; // seconds
39
41
40
42
private static ResponseRegistry responseRegistry = new ResponseRegistry ();
43
+ private static ExecutorService executorService =
44
+ Executors .newFixedThreadPool (Runtime .getRuntime ().availableProcessors ());
41
45
42
46
private final IBinder appAgentBinder =
43
47
new IMatterAppAgent .Stub () {
@@ -76,8 +80,14 @@ 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 (
87
+ () -> {
88
+ AppPlatformService .get ()
89
+ .reportAttributeChange (contentApp .getEndpointId (), clusterId , attributeId );
90
+ });
81
91
return true ;
82
92
}
83
93
Log .e (TAG , "No matter content app found for package " + pkg );
0 commit comments