Handles hub reset at ContextHubClientManager
Bug: 67734082 Test: make and flash device, do adb shell pkill chre and verify onMessageReceipt for reset is triggered by service (by reading logs) Change-Id: I4ea2f2930763dd8182e4e062cdb9312c3e23855e
This commit is contained in:
@@ -177,4 +177,18 @@ public class ContextHubClientBroker extends IContextHubClient.Stub
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a hub reset for this client.
|
||||
*/
|
||||
/* package */ void onHubReset() {
|
||||
if (mConnectionOpen.get()) {
|
||||
try {
|
||||
mCallbackInterface.onHubReset();
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "RemoteException while calling onHubReset on client" +
|
||||
" (host endpoint ID = " + mHostEndPointId + ")", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import android.util.Log;
|
||||
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* A class that manages registration/unregistration of clients and manages messages to/from clients.
|
||||
@@ -147,6 +148,15 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a hub reset.
|
||||
*
|
||||
* @param contextHubId the ID of the hub that has reset.
|
||||
*/
|
||||
/* package */ void onHubReset(int contextHubId) {
|
||||
forEachClientOfHub(contextHubId, client -> client.onHubReset());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new ContextHubClientBroker object for a client and registers it with the client
|
||||
* manager.
|
||||
@@ -188,9 +198,19 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
* @param message the message send by a nanoapp
|
||||
*/
|
||||
private void broadcastMessage(int contextHubId, NanoAppMessage message) {
|
||||
for (ContextHubClientBroker proxy : mHostEndPointIdToClientMap.values()) {
|
||||
if (proxy.getAttachedContextHubId() == contextHubId) {
|
||||
proxy.sendMessageToClient(message);
|
||||
forEachClientOfHub(contextHubId, client -> client.sendMessageToClient(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs a command for each client that is attached to a hub with the given ID.
|
||||
*
|
||||
* @param contextHubId the ID of the hub
|
||||
* @param callback the command to invoke for the client
|
||||
*/
|
||||
private void forEachClientOfHub(int contextHubId, Consumer<ContextHubClientBroker> callback) {
|
||||
for (ContextHubClientBroker broker : mHostEndPointIdToClientMap.values()) {
|
||||
if (broker.getAttachedContextHubId() == contextHubId) {
|
||||
callback.accept(broker);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,6 +225,8 @@ public class ContextHubService extends IContextHubService.Stub {
|
||||
|
||||
@Override
|
||||
public void onHubReset() {
|
||||
byte[] data = {TransactionResult.SUCCESS};
|
||||
onMessageReceiptOldApi(MSG_HUB_RESET, contextHubId, OS_APP_INSTANCE, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -634,8 +636,7 @@ public class ContextHubService extends IContextHubService.Stub {
|
||||
mTransactionManager.onHubReset();
|
||||
queryNanoAppsInternal(contextHubId);
|
||||
|
||||
byte[] data = {TransactionResult.SUCCESS};
|
||||
onMessageReceiptOldApi(MSG_HUB_RESET, contextHubId, OS_APP_INSTANCE, data);
|
||||
mClientManager.onHubReset(contextHubId);
|
||||
} else {
|
||||
Log.i(TAG, "Received unknown hub event (hub ID = " + contextHubId + ", type = "
|
||||
+ eventType + ")");
|
||||
|
||||
Reference in New Issue
Block a user