Add setProcessHidlReturnRestriction.
For critical processes (e.g. init/hwservicemanager), it's nice to check
that every error is checked. If these processes restart, it may be hard
to debug the system.
Bug: 124861676
Bug: 121004730
Test: use w/ hwservicemanager
Change-Id: I0d340c31e392bfb86a188dab902e6d20fa836814
Merged-In: I0d340c31e392bfb86a188dab902e6d20fa836814
diff --git a/base/include/hidl/Status.h b/base/include/hidl/Status.h
index 765f0f7..817277f 100644
--- a/base/include/hidl/Status.h
+++ b/base/include/hidl/Status.h
@@ -143,9 +143,8 @@
template <typename T, typename U>
friend Return<U> StatusOf(const Return<T> &other);
- protected:
- void assertOk() const;
public:
+ void assertOk() const;
return_status() {}
return_status(const Status& s) : mStatus(s) {}
@@ -189,6 +188,26 @@
};
} // namespace details
+enum class HidlReturnRestriction {
+ // Okay to ignore checking transport errors. This would instead rely on init to reset state
+ // after an error in the underlying transport. This is the default and expected for most
+ // usecases.
+ NONE,
+ // Log when there is an unchecked error.
+ ERROR_IF_UNCHECKED,
+ // Fatal when there is an unchecked error.
+ FATAL_IF_UNCHECKED,
+};
+
+/**
+ * This should be called during process initialization (e.g. before binder threadpool is created).
+ *
+ * Note: default of HidlReturnRestriction::NONE should be good for most usecases. See above.
+ *
+ * The restriction will be applied when Return objects are deconstructed.
+ */
+void setProcessHidlReturnRestriction(HidlReturnRestriction restriction);
+
template<typename T> class Return : public details::return_status {
private:
T mVal {};