如何解决Android HAL客户端未捕获的异常
我有一个运行HAL的服务,并带有注册的Java服务回调。 HAL调用Java回调实例的函数并对其自身进行回调。但是,Java服务从HAL发出的此调用请求中抛出了一个错误。之后,HAL因运输错误而崩溃。
我试图围绕对回调实例的HAL调用的调用进行try / catch关闭,但是,我仍然无法捕获异常。
这是我的HAL代码:
void ApplicationControl::onGetAppIcon(
const string &appId,ApplicationControlStub::getAppIconReply_t getAppIconReply) {
if (mAndroidServiceCallback) {
LOG(INFO) << __FUNCTION__ << "::Getting icon of app id: " << appId;
try {
//This call throws an exception in the mAndroidServiceCallback instance. We should handle it
mAndroidServiceCallback->getAppIcon(appId,getAppIconReply);
} catch (runtime_error &e) {
LOG(ERROR) << __FUNCTION__
<< "::A runtime error happened while getting app icon: "
<< e.what();
} catch (exception &e) {
LOG(ERROR) << __FUNCTION__
<< "::An error happened while getting app icon: "
<< e.what();
} catch (...) {
LOG(ERROR) << __FUNCTION__
<< "::An UNKNowN error happened while getting app icon";
}
} else {
LOG(ERROR) << __FUNCTION__ << "::Android callback is not registered!";
}
}
我的失败:
2020-09-17 13:50:09.647 6172-6197/com.xxx.bmt.rseapplicationcontrol E/android_os_HwBinder: Uncaught exception!
2020-09-17 13:50:09.648 6134-6134/? A/HidlStatus: Status.cpp:163] Failed HIDL return status not checked: Status(EX_TRANSACTION_Failed): 'UNKNowN_ERROR: '
2020-09-17 13:50:09.650 6134-6134/? A/libc: Fatal signal 6 (SIGABRT),code -1 (SI_QUEUE) in tid 6134 (applicationcont),pid 6134 (applicationcont)
2020-09-17 13:50:09.696 6249-6249/? I/crash_dump64: obtaining output fd from tombstoned,type: kDebuggerdTombstone
2020-09-17 13:50:09.699 433-433/? I//system/bin/tombstoned: received crash request for pid 6134
2020-09-17 13:50:09.700 6249-6249/? I/crash_dump64: performing dump of process 6134 (target tid = 6134)
2020-09-17 13:50:09.702 6249-6249/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
2020-09-17 13:50:09.702 6249-6249/? A/DEBUG: Build fingerprint: 'xxx/xxx_rse22_ext/xxx_rse22:10/QQ3A.200605.002/eng.moaaz.20200908.173748:userdebug/test-keys'
2020-09-17 13:50:09.702 6249-6249/? A/DEBUG: Revision: '0'
2020-09-17 13:50:09.702 6249-6249/? A/DEBUG: ABI: 'arm64'
2020-09-17 13:50:09.703 6249-6249/? A/DEBUG: Timestamp: 2020-09-17 11:50:09+0000
2020-09-17 13:50:09.703 6249-6249/? A/DEBUG: pid: 6134,tid: 6134,name: applicationcont >>> /vendor/bin/hw/vendor.xxx.applicationcontrol@1.0-service <<<
2020-09-17 13:50:09.703 6249-6249/? A/DEBUG: uid: 1000
2020-09-17 13:50:09.703 6249-6249/? A/DEBUG: signal 6 (SIGABRT),code -1 (SI_QUEUE),fault addr --------
2020-09-17 13:50:09.703 6249-6249/? A/DEBUG: Abort message: 'Failed HIDL return status not checked: Status(EX_TRANSACTION_Failed): 'UNKNowN_ERROR: ''
我希望能够检查HIDL呼叫并根据这些呼叫的结果采取行动。 谢谢。
解决方法
我找到了解决此问题的方法。问题是,我不检查来自Android服务调用的返回值。 这里是如何捕获这种失败的方法:
Return<void> ret = mAndroidServiceCallback->getAppIcon(appId,getAppIconReply);
if (!ret.isOk()) {
LOG(ERROR) << "Call to the Android Java service faile: ";
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。