@1.2::IServiceManager:onNoClients->onClients(bool)
The onClients method is now called with a boolean reflecting whether
clients are present or not. This is to handle a case where multiple
HALs are in the same process, and when none of them are being used,
the process can be shut down.
- onClients(true) (when true) must be called immediately
- onClients(false) (when false) may be delayed when hwservicemanager (or
something else in the future) thinks that the HAL may be used again.
For instance, in the future, we may add heuristic where if a client
has been used for X HAL in the last 10 minutes, we wouldn't ever
notify the HAL that it has no clients. The important thing is that
this ownership of the lifecycle is retained by hwservicemanager.
Given this behavior, when multiple hals are in the same lazy process,
they can wait until onClients(false) is true for each of them and then
shutdown.
Fixes: 117779690
Test: hidl_test
Test: manually test and use this API
Change-Id: Ic8d9fa8485855daa5a7d5639b09934305a560a0a
diff --git a/transport/manager/1.2/IClientCallback.hal b/transport/manager/1.2/IClientCallback.hal
index 030bcd0..1189e44 100644
--- a/transport/manager/1.2/IClientCallback.hal
+++ b/transport/manager/1.2/IClientCallback.hal
@@ -18,9 +18,15 @@
interface IClientCallback {
/**
- * Called when there are no clients remaining for the HAL registered with this service.
+ * This is called when there is a transition between having >= 1 clients and having 0 clients
+ * (or vice versa).
*
* @param registered binder 'server' registered with IServiceManager's registerClientCallback
+ * @param hasClients whether there are currently clients
+ * true - when there are >= 1 clients. This must be called as soon as IServiceManager::get
+ * is called (no race).
+ * false - when there are 0 clients. This may be delayed if it is thought that another
+ * may be used again soon.
*/
- oneway onNoClients(interface registered);
+ oneway onClients(interface registered, bool hasClients);
};
diff --git a/transport/manager/1.2/IServiceManager.hal b/transport/manager/1.2/IServiceManager.hal
index 8d34fb6..ae3fdfd 100644
--- a/transport/manager/1.2/IServiceManager.hal
+++ b/transport/manager/1.2/IServiceManager.hal
@@ -29,7 +29,8 @@
/**
* Adds a callback that must be called when the specified server has no clients.
*
- * This must only be called after the first time the service has no clients.
+ * If the service has clients at the time of registration, the callback is called with
+ * hasClients true. After that, it is called based on the changes in clientele.
*
* @param server non-null service waiting to have no clients
* @param cb non-null callback to call when there are no clients