Merge "Synchronize access to mCallbacksList" into tm-dev

This commit is contained in:
Anthony Stange
2022-04-20 14:20:02 +00:00
committed by Android (Google) Code Review

View File

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