mirror of
https://github.com/Evolution-X/hardware_interfaces
synced 2026-02-01 16:50:18 +00:00
Merge "contexthub: Handle service death" into oc-dev
This commit is contained in:
@@ -38,6 +38,7 @@ static constexpr uint64_t ALL_APPS = UINT64_C(0xFFFFFFFFFFFFFFFF);
|
|||||||
Contexthub::Contexthub()
|
Contexthub::Contexthub()
|
||||||
: mInitCheck(NO_INIT),
|
: mInitCheck(NO_INIT),
|
||||||
mContextHubModule(nullptr),
|
mContextHubModule(nullptr),
|
||||||
|
mDeathRecipient(new DeathRecipient(this)),
|
||||||
mIsTransactionPending(false) {
|
mIsTransactionPending(false) {
|
||||||
const hw_module_t *module;
|
const hw_module_t *module;
|
||||||
|
|
||||||
@@ -96,7 +97,7 @@ Return<void> Contexthub::getHubs(getHubs_cb _hidl_cb) {
|
|||||||
c.stoppedPowerDrawMw = hubArray[i].stopped_power_draw_mw;
|
c.stoppedPowerDrawMw = hubArray[i].stopped_power_draw_mw;
|
||||||
c.sleepPowerDrawMw = hubArray[i].sleep_power_draw_mw;
|
c.sleepPowerDrawMw = hubArray[i].sleep_power_draw_mw;
|
||||||
|
|
||||||
info.callBack = nullptr;
|
info.callback = nullptr;
|
||||||
info.osAppName = hubArray[i].os_app_name;
|
info.osAppName = hubArray[i].os_app_name;
|
||||||
mCachedHubInfo[hubArray[i].hub_id] = info;
|
mCachedHubInfo[hubArray[i].hub_id] = info;
|
||||||
|
|
||||||
@@ -110,6 +111,16 @@ Return<void> Contexthub::getHubs(getHubs_cb _hidl_cb) {
|
|||||||
return Void();
|
return Void();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Contexthub::DeathRecipient::DeathRecipient(sp<Contexthub> contexthub)
|
||||||
|
: mContexthub(contexthub) {}
|
||||||
|
|
||||||
|
void Contexthub::DeathRecipient::serviceDied(
|
||||||
|
uint64_t cookie,
|
||||||
|
const wp<::android::hidl::base::V1_0::IBase>& /*who*/) {
|
||||||
|
uint32_t hubId = static_cast<uint32_t>(cookie);
|
||||||
|
mContexthub->handleServiceDeath(hubId);
|
||||||
|
}
|
||||||
|
|
||||||
bool Contexthub::isValidHubId(uint32_t hubId) {
|
bool Contexthub::isValidHubId(uint32_t hubId) {
|
||||||
if (!mCachedHubInfo.count(hubId)) {
|
if (!mCachedHubInfo.count(hubId)) {
|
||||||
ALOGW("Hub information not found for hubId %" PRIu32, hubId);
|
ALOGW("Hub information not found for hubId %" PRIu32, hubId);
|
||||||
@@ -123,7 +134,7 @@ sp<IContexthubCallback> Contexthub::getCallBackForHubId(uint32_t hubId) {
|
|||||||
if (!isValidHubId(hubId)) {
|
if (!isValidHubId(hubId)) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
} else {
|
} else {
|
||||||
return mCachedHubInfo[hubId].callBack;
|
return mCachedHubInfo[hubId].callback;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,8 +204,22 @@ Return<Result> Contexthub::registerCallback(uint32_t hubId,
|
|||||||
contextHubCb,
|
contextHubCb,
|
||||||
this) == 0) {
|
this) == 0) {
|
||||||
// Initialized && valid hub && subscription successful
|
// Initialized && valid hub && subscription successful
|
||||||
|
if (mCachedHubInfo[hubId].callback != nullptr) {
|
||||||
|
ALOGD("Modifying callback for hubId %" PRIu32, hubId);
|
||||||
|
mCachedHubInfo[hubId].callback->unlinkToDeath(mDeathRecipient);
|
||||||
|
}
|
||||||
|
|
||||||
|
mCachedHubInfo[hubId].callback = cb;
|
||||||
|
if (cb != nullptr) {
|
||||||
|
Return<bool> linkResult = cb->linkToDeath(mDeathRecipient, hubId);
|
||||||
|
bool linkSuccess = linkResult.isOk() ?
|
||||||
|
static_cast<bool>(linkResult) : false;
|
||||||
|
if (!linkSuccess) {
|
||||||
|
ALOGW("Couldn't link death recipient for hubId %" PRIu32,
|
||||||
|
hubId);
|
||||||
|
}
|
||||||
|
}
|
||||||
retVal = Result::OK;
|
retVal = Result::OK;
|
||||||
mCachedHubInfo[hubId].callBack = cb;
|
|
||||||
} else {
|
} else {
|
||||||
// Initalized && valid hubId - but subscription unsuccessful
|
// Initalized && valid hubId - but subscription unsuccessful
|
||||||
// This is likely an internal error in the HAL implementation, but we
|
// This is likely an internal error in the HAL implementation, but we
|
||||||
@@ -309,6 +334,16 @@ int Contexthub::handleOsMessage(sp<IContexthubCallback> cb,
|
|||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Contexthub::handleServiceDeath(uint32_t hubId) {
|
||||||
|
ALOGI("Callback/service died for hubId %" PRIu32, hubId);
|
||||||
|
int ret = mContextHubModule->subscribe_messages(hubId, nullptr, nullptr);
|
||||||
|
if (ret != 0) {
|
||||||
|
ALOGW("Failed to unregister callback from hubId %" PRIu32 ": %d",
|
||||||
|
hubId, ret);
|
||||||
|
}
|
||||||
|
mCachedHubInfo[hubId].callback.clear();
|
||||||
|
}
|
||||||
|
|
||||||
int Contexthub::contextHubCb(uint32_t hubId,
|
int Contexthub::contextHubCb(uint32_t hubId,
|
||||||
const struct hub_message_t *rxMsg,
|
const struct hub_message_t *rxMsg,
|
||||||
void *cookie) {
|
void *cookie) {
|
||||||
|
|||||||
@@ -65,14 +65,26 @@ private:
|
|||||||
|
|
||||||
struct CachedHubInformation{
|
struct CachedHubInformation{
|
||||||
struct hub_app_name_t osAppName;
|
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;
|
status_t mInitCheck;
|
||||||
const struct context_hub_module_t *mContextHubModule;
|
const struct context_hub_module_t *mContextHubModule;
|
||||||
std::unordered_map<uint32_t, CachedHubInformation> mCachedHubInfo;
|
std::unordered_map<uint32_t, CachedHubInformation> mCachedHubInfo;
|
||||||
|
|
||||||
sp<IContexthubCallback> mCb;
|
sp<DeathRecipient> mDeathRecipient;
|
||||||
bool mIsTransactionPending;
|
bool mIsTransactionPending;
|
||||||
uint32_t mTransactionId;
|
uint32_t mTransactionId;
|
||||||
|
|
||||||
@@ -85,6 +97,9 @@ private:
|
|||||||
const uint8_t *msg,
|
const uint8_t *msg,
|
||||||
int msgLen);
|
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,
|
static int contextHubCb(uint32_t hubId,
|
||||||
const struct hub_message_t *rxMsg,
|
const struct hub_message_t *rxMsg,
|
||||||
void *cookie);
|
void *cookie);
|
||||||
|
|||||||
Reference in New Issue
Block a user