contexthub: Handle service death
Register for notification of service death for callbacks registered with
the context hub HAL. Upon this notification, unregister the callback to
avoid crashing if an event occurs prior to the service coming back up.
Bug: 36202367
Test: adb shell stop, confirm death notification received via log;
vts-tradefed run commandAndExit vts --module VtsHalContexthubV1_0Target
Change-Id: I3c25229806cb9f2a116007939c752841edbf0985
diff --git a/contexthub/1.0/default/Contexthub.h b/contexthub/1.0/default/Contexthub.h
index 236e079..db23ec2 100644
--- a/contexthub/1.0/default/Contexthub.h
+++ b/contexthub/1.0/default/Contexthub.h
@@ -65,14 +65,26 @@
struct CachedHubInformation{
struct hub_app_name_t osAppName;
- sp<IContexthubCallback> callBack;
+ sp<IContexthubCallback> callback;
+ };
+
+ class DeathRecipient : public hidl_death_recipient {
+ public:
+ DeathRecipient(const sp<Contexthub> contexthub);
+
+ void serviceDied(
+ uint64_t cookie,
+ const wp<::android::hidl::base::V1_0::IBase>& who) override;
+
+ private:
+ sp<Contexthub> mContexthub;
};
status_t mInitCheck;
const struct context_hub_module_t *mContextHubModule;
std::unordered_map<uint32_t, CachedHubInformation> mCachedHubInfo;
- sp<IContexthubCallback> mCb;
+ sp<DeathRecipient> mDeathRecipient;
bool mIsTransactionPending;
uint32_t mTransactionId;
@@ -85,6 +97,9 @@
const uint8_t *msg,
int msgLen);
+ // Handle the case where the callback registered for the given hub ID dies
+ void handleServiceDeath(uint32_t hubId);
+
static int contextHubCb(uint32_t hubId,
const struct hub_message_t *rxMsg,
void *cookie);