summaryrefslogtreecommitdiff
path: root/transport/include/hidl
diff options
context:
space:
mode:
Diffstat (limited to 'transport/include/hidl')
-rw-r--r--transport/include/hidl/HidlLazyUtils.h45
-rw-r--r--transport/include/hidl/ServiceManagement.h9
2 files changed, 52 insertions, 2 deletions
diff --git a/transport/include/hidl/HidlLazyUtils.h b/transport/include/hidl/HidlLazyUtils.h
index 6a62c97..427611b 100644
--- a/transport/include/hidl/HidlLazyUtils.h
+++ b/transport/include/hidl/HidlLazyUtils.h
@@ -16,6 +16,8 @@
#pragma once
+#include <functional>
+
#include <android/hidl/base/1.0/IBase.h>
#include <utils/RefBase.h>
#include <utils/StrongPointer.h>
@@ -26,12 +28,53 @@ namespace details {
class LazyServiceRegistrarImpl;
} // namespace details
-/** Exits when all HALs registered through this object have 0 clients */
+/**
+ * Exits when all HALs registered through this object have 0 clients
+ *
+ * In order to use this class, it's expected that your service:
+ * - registers all services in the process with this API
+ * - configures services as oneshot + disabled in init .rc files
+ * - uses 'interface' declarations in init .rc files
+ *
+ * For more information on init .rc configuration, see system/core/init/README.md
+ **/
class LazyServiceRegistrar {
public:
static LazyServiceRegistrar& getInstance();
status_t registerService(const sp<::android::hidl::base::V1_0::IBase>& service,
const std::string& name = "default");
+ /**
+ * Set a callback that is invoked when the active HAL count (i.e. HALs with clients)
+ * registered with this process drops to zero (or becomes nonzero).
+ * The callback takes a boolean argument, which is 'true' if there is
+ * at least one HAL with clients.
+ *
+ * Callback return value:
+ * - false: Default behavior for lazy HALs (shut down the process if there
+ * are no clients).
+ * - true: Don't shut down the process even if there are no clients.
+ *
+ * This callback gives a chance to:
+ * 1 - Perform some additional operations before exiting;
+ * 2 - Prevent the process from exiting by returning "true" from the
+ * callback.
+ *
+ * This method should be called before 'registerService' to avoid races.
+ */
+ void setActiveServicesCallback(const std::function<bool(bool)>& activeServicesCallback);
+
+ /**
+ * Try to unregister all services previously registered with 'registerService'.
+ * Returns 'true' if successful.
+ */
+ bool tryUnregister();
+
+ /**
+ * Re-register services that were unregistered by 'tryUnregister'.
+ * This method should be called in the case 'tryUnregister' fails
+ * (and should be called on the same thread).
+ */
+ void reRegister();
private:
std::shared_ptr<details::LazyServiceRegistrarImpl> mImpl;
diff --git a/transport/include/hidl/ServiceManagement.h b/transport/include/hidl/ServiceManagement.h
index 4573a25..886e816 100644
--- a/transport/include/hidl/ServiceManagement.h
+++ b/transport/include/hidl/ServiceManagement.h
@@ -47,10 +47,17 @@ namespace details {
// e.x.: android.hardware.foo@1.0::IFoo, default
void waitForHwService(const std::string &interface, const std::string &instanceName);
+// Only works on userdebug/eng builds. This allows getService to bypass the
+// VINTF manifest for testing only.
+void setTrebleTestingOverride(bool testingOverride);
+
void preloadPassthroughService(const std::string &descriptor);
// Returns a service with the following constraints:
-// - retry => service is waited for and returned if available in this process
+// - retry => service is waited for and returned if it is declared in the
+// manifest AND it is available in this process (if errors indicate an
+// sepolicy denial, then this will return - TODO(b/28321379) more precise
+// errors to handle more cases)
// - getStub => internal only. Forces to get the unwrapped (no BsFoo) if available.
// TODO(b/65843592)
// If the service is a remote service, this function returns BpBase. If the service is