Merge "Synchronize access to mCallbacksList" into tm-dev am: 21363f2e74

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17826644

Change-Id: I46a71e66d212a8c2ded2dbf795409b6953dc96d2
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Anthony Stange
2022-04-20 14:58:59 +00:00
committed by Automerger Merge Worker

View File

@@ -1058,31 +1058,35 @@ public class ContextHubService extends IContextHubService.Stub {
}
int msgVersion = 0;
int callbacksCount = mCallbacksList.beginBroadcast();
if (DEBUG_LOG_ENABLED) {
Log.v(TAG, "Sending message " + msgType + " version " + msgVersion + " from hubHandle "
+ contextHubHandle + ", appInstance " + appInstance + ", callBackCount "
+ callbacksCount);
}
if (callbacksCount < 1) {
// Synchronize access to mCallbacksList to prevent more than one outstanding broadcast as
// that will cause a crash.
synchronized (mCallbacksList) {
int callbacksCount = mCallbacksList.beginBroadcast();
if (DEBUG_LOG_ENABLED) {
Log.v(TAG, "No message callbacks registered.");
Log.v(TAG, "Sending message " + msgType + " version " + msgVersion
+ " from hubHandle " + contextHubHandle + ", appInstance " + appInstance
+ ", callBackCount " + callbacksCount);
}
return 0;
}
ContextHubMessage msg = new ContextHubMessage(msgType, msgVersion, data);
for (int i = 0; i < callbacksCount; ++i) {
IContextHubCallback callback = mCallbacksList.getBroadcastItem(i);
try {
callback.onMessageReceipt(contextHubHandle, appInstance, msg);
} catch (RemoteException e) {
Log.i(TAG, "Exception (" + e + ") calling remote callback (" + callback + ").");
continue;
if (callbacksCount < 1) {
if (DEBUG_LOG_ENABLED) {
Log.v(TAG, "No message callbacks registered.");
}
return 0;
}
ContextHubMessage msg = new ContextHubMessage(msgType, msgVersion, data);
for (int i = 0; i < callbacksCount; ++i) {
IContextHubCallback callback = mCallbacksList.getBroadcastItem(i);
try {
callback.onMessageReceipt(contextHubHandle, appInstance, msg);
} catch (RemoteException e) {
Log.i(TAG, "Exception (" + e + ") calling remote callback (" + callback + ").");
continue;
}
}
mCallbacksList.finishBroadcast();
}
mCallbacksList.finishBroadcast();
return 0;
}