Better error message when hidl call fails.
Now when a return object !isOk and is not checked, the error message
includes the description of the return object. This way, error codes are
exposed in logs on the device.
Test: hidl_test
Change-Id: Id886342d1d78297c3aa8301d565b48e4374665ee
diff --git a/base/Status.cpp b/base/Status.cpp
index 4ce26ee..8367fb8 100644
--- a/base/Status.cpp
+++ b/base/Status.cpp
@@ -13,9 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#define LOG_TAG "HidlStatus"
#include <hidl/Status.h>
+#include <android-base/logging.h>
+
namespace android {
namespace hardware {
@@ -94,5 +97,20 @@
return stream;
}
+namespace details {
+ void return_status::checkStatus() const {
+ if (!isOk()) {
+ LOG(FATAL) << "Attempted to retrieve value from failed HIDL call: " << description();
+ }
+ }
+
+ return_status::~return_status() {
+ // mCheckedStatus must be checked before isOk since isOk modifies mCheckedStatus
+ if (!mCheckedStatus && !isOk()) {
+ LOG(FATAL) << "Failed HIDL return status not checked: " << description();
+ }
+ }
+} // namespace details
+
} // namespace hardware
} // namespace android
diff --git a/base/include/hidl/Status.h b/base/include/hidl/Status.h
index 1be818d..13f0c2c 100644
--- a/base/include/hidl/Status.h
+++ b/base/include/hidl/Status.h
@@ -21,7 +21,6 @@
#include <sstream>
#include <android-base/macros.h>
-#include <hidl/HidlInternal.h>
#include <utils/Errors.h>
#include <utils/StrongPointer.h>
@@ -143,29 +142,19 @@
std::ostream& operator<< (std::ostream& stream, const Status& s);
namespace details {
- class return_status : public details::hidl_log_base {
+ class return_status {
private:
Status mStatus {};
mutable bool mCheckedStatus = false;
protected:
- void checkStatus() const {
- if (!isOk()) {
- logAlwaysFatal("Attempted to retrieve value from hidl service, "
- "but there was a transport error.");
- }
- }
+ void checkStatus() const;
public:
return_status() {}
return_status(Status s) : mStatus(s) {}
return_status(const return_status &) = default;
- ~return_status() {
- // mCheckedStatus must be checked before isOk since isOk modifies mCheckedStatus
- if (!mCheckedStatus && !isOk()) {
- logAlwaysFatal("HIDL return status not checked and transport error occured.");
- }
- }
+ ~return_status();
bool isOk() const {
mCheckedStatus = true;