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: I602b3ca079e51a0c8d7e1a0b9606c361287963da
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:23:55 +00:00
committed by Automerger Merge Worker

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;
} }