fix: fix failed to publish

Signed-off-by: zengsiyu <zengsiyu3@huawei.com>
Change-Id: I6a4441b23e12cfca9ef7ebeeaaf439a351960c07
This commit is contained in:
zengsiyu
2022-03-18 17:15:46 +08:00
parent c58c3db857
commit 5fb9c461d1
2 changed files with 38 additions and 8 deletions
+28 -6
View File
@@ -54,9 +54,20 @@ bool CommonEventProxy::PublishCommonEvent(const CommonEventData &event, const Co
return false;
}
if (!data.WriteRemoteObject(commonEventListener)) {
EVENT_LOGE("Failed to write parcelable commonEventListener");
return false;
if (commonEventListener) {
if (!data.WriteBool(true)) {
EVENT_LOGE("Failed to write parcelable hasLastSubscrbier");
return false;
}
if (!data.WriteRemoteObject(commonEventListener)) {
EVENT_LOGE("Failed to write parcelable commonEventListener");
return false;
}
} else {
if (!data.WriteBool(false)) {
EVENT_LOGE("Failed to write parcelable hasLastSubscrbier");
return false;
}
}
if (!data.WriteInt32(userId)) {
@@ -96,9 +107,20 @@ bool CommonEventProxy::PublishCommonEvent(const CommonEventData &event, const Co
return false;
}
if (!data.WriteRemoteObject(commonEventListener)) {
EVENT_LOGE("Failed to write parcelable commonEventListener");
return false;
if (commonEventListener) {
if (!data.WriteBool(true)) {
EVENT_LOGE("Failed to write parcelable hasLastSubscriber");
return false;
}
if (!data.WriteRemoteObject(commonEventListener)) {
EVENT_LOGE("Failed to write parcelable commonEventListener");
return false;
}
} else {
if (!data.WriteBool(false)) {
EVENT_LOGE("Failed to write parcelable hasLastSubscriber");
return false;
}
}
if (!data.WriteInt32(uid)) {
+10 -2
View File
@@ -37,7 +37,11 @@ int CommonEventStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Message
case static_cast<uint32_t>(ICommonEvent::Message::CES_PUBLISH_COMMON_EVENT): {
std::unique_ptr<CommonEventData> event(data.ReadParcelable<CommonEventData>());
std::unique_ptr<CommonEventPublishInfo> publishinfo(data.ReadParcelable<CommonEventPublishInfo>());
sptr<IRemoteObject> commonEventListener = data.ReadRemoteObject();
sptr<IRemoteObject> commonEventListener = nullptr;
bool hasLastSubscriber = data.ReadBool();
if (hasLastSubscriber) {
sptr<IRemoteObject> commonEventListener = data.ReadRemoteObject();
}
int32_t userId = data.ReadInt32();
if (!event) {
EVENT_LOGE("Failed to ReadParcelable<CommonEventData>");
@@ -58,7 +62,11 @@ int CommonEventStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Message
case static_cast<uint32_t>(ICommonEvent::Message::CES_PUBLISH_COMMON_EVENT2): {
std::unique_ptr<CommonEventData> event(data.ReadParcelable<CommonEventData>());
std::unique_ptr<CommonEventPublishInfo> publishinfo(data.ReadParcelable<CommonEventPublishInfo>());
sptr<IRemoteObject> commonEventListener = data.ReadRemoteObject();
sptr<IRemoteObject> commonEventListener = nullptr;
bool hasLastSubscriber = data.ReadBool();
if (hasLastSubscriber) {
sptr<IRemoteObject> commonEventListener = data.ReadRemoteObject();
}
int uid = data.ReadInt32();
int32_t userId = data.ReadInt32();
if (!event) {