!325 SetListenerObject IPC接口成员变量并发加锁

Merge pull request !325 from baoxy92/master
This commit is contained in:
openharmony_ci
2024-12-31 09:21:24 +00:00
committed by Gitee
11 changed files with 0 additions and 129 deletions
@@ -41,7 +41,6 @@ public:
int32_t GetMediaDecryptModule(sptr<IMediaDecryptModuleService> &decryptModule) override;
int32_t GetContentProtectionLevel(IMediaKeySessionService::ContentProtectionLevel *securityLevel) override;
int32_t RequireSecureDecoderModule(std::string &mimeType, bool *status) override;
int32_t SetListenerObject(const sptr<IRemoteObject> &object) override;
int32_t SetCallback(sptr<IMediaKeySessionServiceCallback> &callback) override;
private:
@@ -46,7 +46,6 @@ public:
int32_t GetOfflineMediaKeyStatus(std::vector<uint8_t> &licenseId,
IMediaKeySessionService::OfflineMediaKeyStatus &status) override;
int32_t ClearOfflineMediaKeys(std::vector<uint8_t> &licenseId) override;
int32_t SetListenerObject(const sptr<IRemoteObject> &object) override;
int32_t SetCallback(sptr<IMediaKeySystemServiceCallback> &callback) override;
private:
@@ -404,23 +404,6 @@ int32_t MediaKeySessionServiceProxy::RequireSecureDecoderModule(std::string &mim
return ret;
}
int32_t MediaKeySessionServiceProxy::SetListenerObject(const sptr<IRemoteObject> &object)
{
DRM_INFO_LOG("SetListenerObject enter.");
MessageParcel data;
MessageParcel reply;
MessageOption option;
data.WriteInterfaceToken(GetDescriptor());
(void)data.WriteRemoteObject(object);
int ret = Remote()->SendRequest(MEDIA_KEY_SESSION_SET_LISTENER_OBJ, data, reply, option);
if (ret != DRM_OK) {
DRM_ERR_LOG("Set listener obj failed, errcode: %{public}d", ret);
return IPC_PROXY_ERR;
}
return reply.ReadInt32();
}
int32_t MediaKeySessionServiceProxy::SetCallback(sptr<IMediaKeySessionServiceCallback> &callback)
{
DRM_INFO_LOG("SetCallback enter.");
@@ -25,26 +25,6 @@ MediaKeySystemServiceProxy::MediaKeySystemServiceProxy(const sptr<IRemoteObject>
{
}
int32_t MediaKeySystemServiceProxy::SetListenerObject(const sptr<IRemoteObject> &object)
{
DRM_INFO_LOG("SetListenerObject.");
MessageParcel data;
MessageParcel reply;
MessageOption option;
data.WriteInterfaceToken(GetDescriptor());
if (!data.WriteRemoteObject(object)) {
DRM_ERR_LOG("WriteRemoteObject failed.");
return IPC_PROXY_ERR;
}
int ret = Remote()->SendRequest(MEDIA_KEY_SYSTEM_SET_LISTENER_OBJ, data, reply, option);
if (ret != DRM_OK) {
DRM_ERR_LOG("Set listener obj failed, errcode: %{public}d", ret);
return IPC_PROXY_ERR;
}
return reply.ReadInt32();
}
int32_t MediaKeySystemServiceProxy::Release()
{
DRM_INFO_LOG("Release enter.");
@@ -97,7 +97,6 @@ public:
virtual int32_t ClearMediaKeys() = 0;
virtual int32_t GetContentProtectionLevel(IMediaKeySessionService::ContentProtectionLevel *securityLevel) = 0;
virtual int32_t RequireSecureDecoderModule(std::string &mimeType, bool *status) = 0;
virtual int32_t SetListenerObject(const sptr<IRemoteObject> &object) = 0;
virtual int32_t SetCallback(sptr<IMediaKeySessionServiceCallback> &callback) = 0;
DECLARE_INTERFACE_DESCRIPTOR(u"IMediaKeySessionService");
};
@@ -76,7 +76,6 @@ public:
virtual int32_t GetOfflineMediaKeyStatus(std::vector<uint8_t> &licenseId,
IMediaKeySessionService::OfflineMediaKeyStatus &status) = 0;
virtual int32_t ClearOfflineMediaKeys(std::vector<uint8_t> &licenseId) = 0;
virtual int32_t SetListenerObject(const sptr<IRemoteObject> &object) = 0;
virtual int32_t SetCallback(sptr<IMediaKeySystemServiceCallback> &callback) = 0;
DECLARE_INTERFACE_DESCRIPTOR(u"IMediaKeySystemSystemService");
};
@@ -41,7 +41,6 @@ enum MediaKeySystemServiceRequestCode {
MEDIA_KEY_SYSTEM_GET_OFFLINELICENSEIDS,
MEDIA_KEY_SYSTEM_GET_OFFLINEKEY_STATUS,
MEDIA_KEY_SYSTEM_REMOVE_OFFLINELICENSE,
MEDIA_KEY_SYSTEM_SET_LISTENER_OBJ,
MEDIA_KEY_SYSTEM_SETCALLBACK,
};
@@ -57,7 +56,6 @@ enum MediaKeySessionServiceRequestCode {
MEDIA_KEY_SESSION_REMOVE_LICENSE,
MEDIA_KEY_SESSION_SET_CALLBACK,
MEDIA_KEY_SESSION_REQUIRE_SECURE_DECODER,
MEDIA_KEY_SESSION_SET_LISTENER_OBJ,
MEDIA_KEY_SESSION_GETSECURITYLEVEL,
};
@@ -32,7 +32,6 @@ public:
~MediaKeySessionServiceStub() = default;
virtual int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
MessageOption &option) override;
int32_t SetListenerObject(const sptr<IRemoteObject> &object) override;
private:
void MediaKeySessionClientDied(pid_t pid);
@@ -34,7 +34,6 @@ public:
~MediaKeySystemServiceStub();
virtual int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
MessageOption &option) override;
int32_t SetListenerObject(const sptr<IRemoteObject> &object) override;
private:
void MediaKeySystemClientDied(pid_t pid);
@@ -65,9 +65,6 @@ static int32_t ProcessRequireSecureDecoder(MediaKeySessionServiceStub *stub, Mes
static int32_t ProcessGetContentProtectionLevel(MediaKeySessionServiceStub *stub, MessageParcel &data,
MessageParcel &reply, MessageOption &option);
static int32_t ProcessSetListenerObject(MediaKeySessionServiceStub *stub, MessageParcel &data,
MessageParcel &reply, MessageOption &option);
static struct ProcessRemoteRequestFuncArray g_mediaKeySessionServiceStubRequestProcessFunc[] = {
{GET_MEDIA_DECRYPT_MODULE, ProcessGetMediaDecryptModule},
{KEY_SESSION_RELEASE, ProcessReleaseKeySession},
@@ -80,7 +77,6 @@ static struct ProcessRemoteRequestFuncArray g_mediaKeySessionServiceStubRequestP
{MEDIA_KEY_SESSION_REMOVE_LICENSE, ProcessClearMediaKeys},
{MEDIA_KEY_SESSION_SET_CALLBACK, ProcessSetCallback},
{MEDIA_KEY_SESSION_REQUIRE_SECURE_DECODER, ProcessRequireSecureDecoder},
{MEDIA_KEY_SESSION_SET_LISTENER_OBJ, ProcessSetListenerObject},
{MEDIA_KEY_SESSION_GETSECURITYLEVEL, ProcessGetContentProtectionLevel},
};
@@ -342,45 +338,6 @@ void MediaKeySessionServiceStub::MediaKeySessionClientDied(pid_t pid)
DRM_ERR_LOG("MediaKeySession client has died, pid:%{public}d", pid);
}
int32_t MediaKeySessionServiceStub::SetListenerObject(const sptr<IRemoteObject> &object)
{
std::lock_guard<std::recursive_mutex> lock(drmSessionStubMutex_);
pid_t pid = IPCSkeleton::GetCallingPid();
if (clientListener_ != nullptr && clientListener_->AsObject() != nullptr && deathRecipient_ != nullptr) {
DRM_DEBUG_LOG("This MediaKeySessionServiceStub has already set listener!");
(void)clientListener_->AsObject()->RemoveDeathRecipient(deathRecipient_);
deathRecipient_ = nullptr;
clientListener_ = nullptr;
}
DRM_CHECK_AND_RETURN_RET_LOG(object != nullptr, DRM_MEMORY_ERROR, "set listener object is nullptr");
sptr<IDrmListener> clientListener_ = iface_cast<IDrmListener>(object);
DRM_CHECK_AND_RETURN_RET_LOG(
clientListener_ != nullptr, DRM_MEMORY_ERROR, "failed to convert IDrmListener");
deathRecipient_ = new (std::nothrow) DrmDeathRecipient(pid);
DRM_CHECK_AND_RETURN_RET_LOG(deathRecipient_ != nullptr, DRM_MEMORY_ERROR, "failed to new DrmDeathRecipient");
deathRecipient_->SetNotifyCb([this] (pid_t pid) {
this->MediaKeySessionClientDied(pid);
});
if (clientListener_->AsObject() != nullptr) {
(void)clientListener_->AsObject()->AddDeathRecipient(deathRecipient_);
}
DRM_DEBUG_LOG("MediaKeySession client pid pid:%{public}d", pid);
return DRM_OK;
}
static int32_t ProcessSetListenerObject(MediaKeySessionServiceStub *stub, MessageParcel &data,
MessageParcel &reply, MessageOption &option)
{
DRM_INFO_LOG("ProcessSetListenerObject.");
(void)reply;
sptr<IRemoteObject> object = data.ReadRemoteObject();
int32_t ret = stub->SetListenerObject(object);
DRM_CHECK_AND_RETURN_RET_LOG(ret == DRM_OK, ret,
"ProcessSetListenerObject faild, errCode:%{public}d", ret);
return ret;
}
static int32_t ProcessGetContentProtectionLevel(MediaKeySessionServiceStub *stub, MessageParcel &data,
MessageParcel &reply, MessageOption &option)
{
@@ -72,9 +72,6 @@ static int32_t ProcessGetOfflineMediaKeyStatus(MediaKeySystemServiceStub *stub,
static int32_t ProcessRemoveOfflineMediaKey(MediaKeySystemServiceStub *stub, MessageParcel &data, MessageParcel &reply,
MessageOption &option);
static int32_t ProcessSetListenerObject(MediaKeySystemServiceStub *stub, MessageParcel &data, MessageParcel &reply,
MessageOption &option);
static int32_t ProcessSetCallabck(MediaKeySystemServiceStub *stub, MessageParcel &data, MessageParcel &reply,
MessageOption &option);
@@ -93,7 +90,6 @@ static struct ProcessRemoteRequestFuncArray g_mediaKeySystemServiceStubRequestPr
{MEDIA_KEY_SYSTEM_GET_OFFLINELICENSEIDS, ProcessGetOfflineMediaKeyIds},
{MEDIA_KEY_SYSTEM_GET_OFFLINEKEY_STATUS, ProcessGetOfflineMediaKeyStatus},
{MEDIA_KEY_SYSTEM_REMOVE_OFFLINELICENSE, ProcessRemoveOfflineMediaKey},
{MEDIA_KEY_SYSTEM_SET_LISTENER_OBJ, ProcessSetListenerObject},
{MEDIA_KEY_SYSTEM_SETCALLBACK, ProcessSetCallabck},
};
@@ -379,43 +375,6 @@ void MediaKeySystemServiceStub::MediaKeySystemClientDied(pid_t pid)
DRM_ERR_LOG("MediaKeySystemService client has died, pid:%{public}d", pid);
}
int32_t MediaKeySystemServiceStub::SetListenerObject(const sptr<IRemoteObject> &object)
{
pid_t pid = IPCSkeleton::GetCallingPid();
if (clientListener_ != nullptr && clientListener_->AsObject() != nullptr && deathRecipient_ != nullptr) {
DRM_DEBUG_LOG("This MediaKeySystemServiceStub has already set listener!");
(void)clientListener_->AsObject()->RemoveDeathRecipient(deathRecipient_);
deathRecipient_ = nullptr;
clientListener_ = nullptr;
}
DRM_CHECK_AND_RETURN_RET_LOG(object != nullptr, DRM_MEMORY_ERROR, "set listener object is nullptr");
sptr<IDrmListener> clientListener_ = iface_cast<IDrmListener>(object);
DRM_CHECK_AND_RETURN_RET_LOG(
clientListener_ != nullptr, DRM_MEMORY_ERROR, "failed to convert IDrmListener");
deathRecipient_ = new (std::nothrow) DrmDeathRecipient(pid);
DRM_CHECK_AND_RETURN_RET_LOG(deathRecipient_ != nullptr, DRM_MEMORY_ERROR, "failed to new DrmDeathRecipient");
deathRecipient_->SetNotifyCb([this] (pid_t pid) {
this->MediaKeySystemClientDied(pid);
});
if (clientListener_->AsObject() != nullptr) {
(void)clientListener_->AsObject()->AddDeathRecipient(deathRecipient_);
}
return DRM_OK;
}
static int32_t ProcessSetListenerObject(MediaKeySystemServiceStub *stub, MessageParcel &data, MessageParcel &reply,
MessageOption &option)
{
DRM_INFO_LOG("ProcessSetListenerObject.");
(void)reply;
sptr<IRemoteObject> object = data.ReadRemoteObject();
int32_t ret = stub->SetListenerObject(object);
DRM_CHECK_AND_RETURN_RET_LOG(ret == DRM_OK, ret,
"ProcessSetListenerObject faild, errCode:%{public}d", ret);
return ret;
}
static int32_t ProcessSetCallabck(MediaKeySystemServiceStub *stub, MessageParcel &data, MessageParcel &reply,
MessageOption &option)
{