From ba6bfc14b5895cfbbae8abd54e059044a59783e6 Mon Sep 17 00:00:00 2001 From: yu-tengao Date: Sat, 9 Apr 2022 16:50:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DSA=E4=B8=AD=E7=BB=A7=E6=BC=8F?= =?UTF-8?q?=E6=B4=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yu-tengao --- .../ipc/avmetadatahelper_service_proxy.cpp | 35 ++++ .../ipc/avmetadatahelper_service_stub.cpp | 6 + .../ipc/media_data_source_proxy.cpp | 18 ++ .../ipc/media_data_source_stub.cpp | 6 + .../player/ipc/player_service_proxy.cpp | 129 +++++++++++++ .../player/ipc/player_service_stub.cpp | 6 + .../recorder/ipc/recorder_service_proxy.cpp | 174 ++++++++++++++++++ .../recorder/ipc/recorder_service_stub.cpp | 6 + .../sa_media/ipc/media_service_proxy.cpp | 12 ++ .../sa_media/ipc/media_service_stub.cpp | 6 + 10 files changed, 398 insertions(+) diff --git a/services/services/avmetadatahelper/ipc/avmetadatahelper_service_proxy.cpp b/services/services/avmetadatahelper/ipc/avmetadatahelper_service_proxy.cpp index fd0e00b68..1f6701a40 100644 --- a/services/services/avmetadatahelper/ipc/avmetadatahelper_service_proxy.cpp +++ b/services/services/avmetadatahelper/ipc/avmetadatahelper_service_proxy.cpp @@ -40,6 +40,11 @@ int32_t AVMetadataHelperServiceProxy::DestroyStub() MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(AVMetadataHelperServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } int error = Remote()->SendRequest(DESTROY, data, reply, option); if (error != MSERR_OK) { MEDIA_LOGE("destroy failed, error: %{public}d", error); @@ -53,6 +58,12 @@ int32_t AVMetadataHelperServiceProxy::SetSource(const std::string &uri, int32_t MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(AVMetadataHelperServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + (void)data.WriteString(uri); (void)data.WriteInt32(usage); @@ -69,6 +80,12 @@ std::string AVMetadataHelperServiceProxy::ResolveMetadata(int32_t key) MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(AVMetadataHelperServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return ""; + } + (void)data.WriteInt32(key); int error = Remote()->SendRequest(RESOLVE_METADATA, data, reply, option); @@ -85,6 +102,12 @@ std::unordered_map AVMetadataHelperServiceProxy::ResolveMe MessageParcel reply; MessageOption option; std::unordered_map metadata; + + if (!data.WriteInterfaceToken(AVMetadataHelperServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return metadata; + } + int error = Remote()->SendRequest(RESOLVE_METADATA_MAP, data, reply, option); if (error != MSERR_OK) { MEDIA_LOGE("ResolveMetadata failed, error: %{public}d", error); @@ -120,6 +143,12 @@ std::shared_ptr AVMetadataHelperServiceProxy::FetchFrameAtTime(i MessageParcel data; MessageParcel reply; MessageOption opt; + + if (!data.WriteInterfaceToken(AVMetadataHelperServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return nullptr; + } + (void)data.WriteInt64(timeUs); (void)data.WriteInt32(option); (void)data.WriteInt32(param.dstWidth); @@ -139,6 +168,12 @@ void AVMetadataHelperServiceProxy::Release() MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(AVMetadataHelperServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return; + } + int error = Remote()->SendRequest(RELEASE, data, reply, option); if (error != MSERR_OK) { MEDIA_LOGE("Release failed, error: %{public}d", error); diff --git a/services/services/avmetadatahelper/ipc/avmetadatahelper_service_stub.cpp b/services/services/avmetadatahelper/ipc/avmetadatahelper_service_stub.cpp index 3c8eaee97..97d015103 100644 --- a/services/services/avmetadatahelper/ipc/avmetadatahelper_service_stub.cpp +++ b/services/services/avmetadatahelper/ipc/avmetadatahelper_service_stub.cpp @@ -72,6 +72,12 @@ int AVMetadataHelperServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &d { MEDIA_LOGI("Stub: OnRemoteRequest of code: %{public}u is received", code); + auto remoteDescriptor = data.ReadInterfaceToken(); + if (AVMetadataHelperServiceStub::GetDescriptor() != remoteDescriptor) { + MEDIA_LOGE("Invalid descriptor"); + return MSERR_INVALID_OPERATION; + } + auto itFunc = avMetadataHelperFuncs_.find(code); if (itFunc != avMetadataHelperFuncs_.end()) { auto memberFunc = itFunc->second; diff --git a/services/services/media_data_source/ipc/media_data_source_proxy.cpp b/services/services/media_data_source/ipc/media_data_source_proxy.cpp index ffa8b1ba5..0c0b4c8ac 100644 --- a/services/services/media_data_source/ipc/media_data_source_proxy.cpp +++ b/services/services/media_data_source/ipc/media_data_source_proxy.cpp @@ -69,6 +69,12 @@ int32_t MediaDataSourceProxy::ReadAt(int64_t pos, uint32_t length, const std::sh MessageParcel data; MessageParcel reply; MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(MediaDataSourceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + data.WriteInt64(pos); data.WriteUint32(length); WriteAVSharedMemoryToParcel(mem, data); @@ -86,6 +92,12 @@ int32_t MediaDataSourceProxy::ReadAt(uint32_t length, const std::shared_ptrSendRequest(ListenerMsg::READ_AT, data, reply, option); @@ -102,6 +114,12 @@ int32_t MediaDataSourceProxy::GetSize(int64_t &size) MessageParcel data; MessageParcel reply; MessageOption option(MessageOption::TF_SYNC); + + if (!data.WriteInterfaceToken(MediaDataSourceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + int error = Remote()->SendRequest(ListenerMsg::GET_SIZE, data, reply, option); if (error != MSERR_OK) { MEDIA_LOGE("on info failed, error: %{public}d", error); diff --git a/services/services/media_data_source/ipc/media_data_source_stub.cpp b/services/services/media_data_source/ipc/media_data_source_stub.cpp index d0916e03c..70d22468a 100644 --- a/services/services/media_data_source/ipc/media_data_source_stub.cpp +++ b/services/services/media_data_source/ipc/media_data_source_stub.cpp @@ -39,6 +39,12 @@ MediaDataSourceStub::~MediaDataSourceStub() int MediaDataSourceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { + auto remoteDescriptor = data.ReadInterfaceToken(); + if (MediaDataSourceStub::GetDescriptor() != remoteDescriptor) { + MEDIA_LOGE("Invalid descriptor"); + return MSERR_INVALID_OPERATION; + } + switch (code) { case ListenerMsg::READ_AT: { uint32_t length = data.ReadUint32(); diff --git a/services/services/player/ipc/player_service_proxy.cpp b/services/services/player/ipc/player_service_proxy.cpp index 56df4171c..4b44ef957 100644 --- a/services/services/player/ipc/player_service_proxy.cpp +++ b/services/services/player/ipc/player_service_proxy.cpp @@ -40,6 +40,12 @@ int32_t PlayerServiceProxy::SetListenerObject(const sptr &object) MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(PlayerServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + (void)data.WriteRemoteObject(object); int error = Remote()->SendRequest(SET_LISTENER_OBJ, data, reply, option); if (error != MSERR_OK) { @@ -55,6 +61,10 @@ int32_t PlayerServiceProxy::SetSource(const std::string &uri) MessageParcel data; MessageParcel reply; MessageOption option; + if (!data.WriteInterfaceToken(PlayerServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } data.WriteString(uri); int error = Remote()->SendRequest(SET_SOURCE, data, reply, option); if (error != MSERR_OK) { @@ -69,6 +79,12 @@ int32_t PlayerServiceProxy::SetSource(const sptr &object) MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(PlayerServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + (void)data.WriteRemoteObject(object); int error = Remote()->SendRequest(SET_MEDIA_DATA_SRC_OBJ, data, reply, option); if (error != MSERR_OK) { @@ -84,6 +100,12 @@ int32_t PlayerServiceProxy::Play() MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(PlayerServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + int error = Remote()->SendRequest(PLAY, data, reply, option); if (error != MSERR_OK) { MEDIA_LOGE("Play failed, error: %{public}d", error); @@ -97,6 +119,12 @@ int32_t PlayerServiceProxy::Prepare() MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(PlayerServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + int error = Remote()->SendRequest(PREPARE, data, reply, option); if (error != MSERR_OK) { MEDIA_LOGE("Prepare failed, error: %{public}d", error); @@ -110,6 +138,12 @@ int32_t PlayerServiceProxy::PrepareAsync() MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(PlayerServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + int error = Remote()->SendRequest(PREPAREASYNC, data, reply, option); if (error != MSERR_OK) { MEDIA_LOGE("PrepareAsync failed, error: %{public}d", error); @@ -123,6 +157,12 @@ int32_t PlayerServiceProxy::Pause() MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(PlayerServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + int error = Remote()->SendRequest(PAUSE, data, reply, option); if (error != MSERR_OK) { MEDIA_LOGE("Pause failed, error: %{public}d", error); @@ -136,6 +176,12 @@ int32_t PlayerServiceProxy::Stop() MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(PlayerServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + int error = Remote()->SendRequest(STOP, data, reply, option); if (error != MSERR_OK) { MEDIA_LOGE("Stop failed, error: %{public}d", error); @@ -149,6 +195,12 @@ int32_t PlayerServiceProxy::Reset() MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(PlayerServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + int error = Remote()->SendRequest(RESET, data, reply, option); if (error != MSERR_OK) { MEDIA_LOGE("Reset failed, error: %{public}d", error); @@ -162,6 +214,12 @@ int32_t PlayerServiceProxy::Release() MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(PlayerServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + int error = Remote()->SendRequest(RELEASE, data, reply, option); if (error != MSERR_OK) { MEDIA_LOGE("Release failed, error: %{public}d", error); @@ -175,6 +233,12 @@ int32_t PlayerServiceProxy::SetVolume(float leftVolume, float rightVolume) MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(PlayerServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + data.WriteFloat(leftVolume); data.WriteFloat(rightVolume); int error = Remote()->SendRequest(SET_VOLUME, data, reply, option); @@ -190,6 +254,12 @@ int32_t PlayerServiceProxy::Seek(int32_t mSeconds, PlayerSeekMode mode) MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(PlayerServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + data.WriteInt32(mSeconds); data.WriteInt32(mode); int error = Remote()->SendRequest(SEEK, data, reply, option); @@ -205,6 +275,12 @@ int32_t PlayerServiceProxy::GetCurrentTime(int32_t ¤tTime) MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(PlayerServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + int error = Remote()->SendRequest(GET_CURRENT_TIME, data, reply, option); if (error != MSERR_OK) { MEDIA_LOGE("Get current time failed, error: %{public}d", error); @@ -219,6 +295,12 @@ int32_t PlayerServiceProxy::GetDuration(int32_t &duration) MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(PlayerServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + int error = Remote()->SendRequest(GET_DURATION, data, reply, option); if (error != MSERR_OK) { MEDIA_LOGE("Get current time failed, error: %{public}d", error); @@ -233,6 +315,12 @@ int32_t PlayerServiceProxy::SetPlaybackSpeed(PlaybackRateMode mode) MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(PlayerServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + data.WriteInt32(mode); int error = Remote()->SendRequest(SET_PLAYERBACK_SPEED, data, reply, option); if (error != MSERR_OK) { @@ -247,6 +335,12 @@ int32_t PlayerServiceProxy::GetPlaybackSpeed(PlaybackRateMode &mode) MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(PlayerServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + int error = Remote()->SendRequest(GET_PLAYERBACK_SPEED, data, reply, option); if (error != MSERR_OK) { MEDIA_LOGE("GetPlaybackSpeed failed, error: %{public}d", error); @@ -273,6 +367,12 @@ int32_t PlayerServiceProxy::SetVideoSurface(sptr surface) const std::string surfaceFormat = "SURFACE_FORMAT"; std::string format = surface->GetUserData(surfaceFormat); MEDIA_LOGI("surfaceFormat is %{public}s!", format.c_str()); + + if (!data.WriteInterfaceToken(PlayerServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + (void)data.WriteRemoteObject(object); data.WriteString(format); int error = Remote()->SendRequest(SET_VIDEO_SURFACE, data, reply, option); @@ -288,6 +388,12 @@ bool PlayerServiceProxy::IsPlaying() MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(PlayerServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return false; + } + int error = Remote()->SendRequest(IS_PLAYING, data, reply, option); if (error != MSERR_OK) { MEDIA_LOGE("Get is playing failed, error: %{public}d", error); @@ -302,6 +408,12 @@ bool PlayerServiceProxy::IsLooping() MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(PlayerServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return false; + } + int error = Remote()->SendRequest(IS_LOOPING, data, reply, option); if (error != MSERR_OK) { MEDIA_LOGE("Get is looping failed, error: %{public}d", error); @@ -316,6 +428,12 @@ int32_t PlayerServiceProxy::SetLooping(bool loop) MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(PlayerServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + data.WriteBool(loop); int error = Remote()->SendRequest(SET_LOOPING, data, reply, option); if (error != MSERR_OK) { @@ -330,6 +448,11 @@ int32_t PlayerServiceProxy::DestroyStub() MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(PlayerServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } int error = Remote()->SendRequest(DESTROY, data, reply, option); if (error != MSERR_OK) { MEDIA_LOGE("destroy failed, error: %{public}d", error); @@ -343,6 +466,12 @@ int32_t PlayerServiceProxy::SetPlayerCallback() MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(PlayerServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + int error = Remote()->SendRequest(SET_CALLBACK, data, reply, option); if (error != MSERR_OK) { MEDIA_LOGE("set callback failed, error: %{public}d", error); diff --git a/services/services/player/ipc/player_service_stub.cpp b/services/services/player/ipc/player_service_stub.cpp index 647708717..9de6694c8 100644 --- a/services/services/player/ipc/player_service_stub.cpp +++ b/services/services/player/ipc/player_service_stub.cpp @@ -90,6 +90,12 @@ int PlayerServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Messa { MEDIA_LOGI("Stub: OnRemoteRequest of code: %{public}d is received", code); + auto remoteDescriptor = data.ReadInterfaceToken(); + if (PlayerServiceStub::GetDescriptor() != remoteDescriptor) { + MEDIA_LOGE("Invalid descriptor"); + return MSERR_INVALID_OPERATION; + } + auto itFunc = playerFuncs_.find(code); if (itFunc != playerFuncs_.end()) { auto memberFunc = itFunc->second; diff --git a/services/services/recorder/ipc/recorder_service_proxy.cpp b/services/services/recorder/ipc/recorder_service_proxy.cpp index 38e4f9f5d..05f8a6bbd 100644 --- a/services/services/recorder/ipc/recorder_service_proxy.cpp +++ b/services/services/recorder/ipc/recorder_service_proxy.cpp @@ -40,6 +40,12 @@ int32_t RecorderServiceProxy::SetListenerObject(const sptr &objec MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(RecorderServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + (void)data.WriteRemoteObject(object); int error = Remote()->SendRequest(SET_LISTENER_OBJ, data, reply, option); if (error != MSERR_OK) { @@ -54,6 +60,12 @@ int32_t RecorderServiceProxy::SetVideoSource(VideoSourceType source, int32_t &so MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(RecorderServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + data.WriteInt32(source); int error = Remote()->SendRequest(SET_VIDEO_SOURCE, data, reply, option); if (error != MSERR_OK) { @@ -69,6 +81,12 @@ int32_t RecorderServiceProxy::SetVideoEncoder(int32_t sourceId, VideoCodecFormat MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(RecorderServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + data.WriteInt32(sourceId); data.WriteInt32(encoder); int error = Remote()->SendRequest(SET_VIDEO_ENCODER, data, reply, option); @@ -85,6 +103,12 @@ int32_t RecorderServiceProxy::SetVideoSize(int32_t sourceId, int32_t width, int3 MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(RecorderServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + data.WriteInt32(sourceId); data.WriteInt32(width); data.WriteInt32(height); @@ -101,6 +125,12 @@ int32_t RecorderServiceProxy::SetVideoFrameRate(int32_t sourceId, int32_t frameR MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(RecorderServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + data.WriteInt32(sourceId); data.WriteInt32(frameRate); int error = Remote()->SendRequest(SET_VIDEO_FARAME_RATE, data, reply, option); @@ -116,6 +146,12 @@ int32_t RecorderServiceProxy::SetVideoEncodingBitRate(int32_t sourceId, int32_t MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(RecorderServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + data.WriteInt32(sourceId); data.WriteInt32(rate); int error = Remote()->SendRequest(SET_VIDEO_ENCODING_BIT_RATE, data, reply, option); @@ -131,6 +167,12 @@ int32_t RecorderServiceProxy::SetCaptureRate(int32_t sourceId, double fps) MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(RecorderServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + data.WriteInt32(sourceId); data.WriteDouble(fps); int error = Remote()->SendRequest(SET_CAPTURE_RATE, data, reply, option); @@ -146,6 +188,12 @@ sptr RecorderServiceProxy::GetSurface(int32_t sourceId) MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(RecorderServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return nullptr; + } + data.WriteInt32(sourceId); int error = Remote()->SendRequest(GET_SURFACE, data, reply, option); if (error != MSERR_OK) { @@ -173,6 +221,12 @@ int32_t RecorderServiceProxy::SetAudioSource(AudioSourceType source, int32_t &so MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(RecorderServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + data.WriteInt32(static_cast(source)); int error = Remote()->SendRequest(SET_AUDIO_SOURCE, data, reply, option); if (error != MSERR_OK) { @@ -188,6 +242,12 @@ int32_t RecorderServiceProxy::SetAudioEncoder(int32_t sourceId, AudioCodecFormat MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(RecorderServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + data.WriteInt32(sourceId); data.WriteInt32(static_cast(encoder)); int error = Remote()->SendRequest(SET_AUDIO_ENCODER, data, reply, option); @@ -203,6 +263,12 @@ int32_t RecorderServiceProxy::SetAudioSampleRate(int32_t sourceId, int32_t rate) MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(RecorderServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + data.WriteInt32(sourceId); data.WriteInt32(rate); int error = Remote()->SendRequest(SET_AUDIO_SAMPLE_RATE, data, reply, option); @@ -218,6 +284,12 @@ int32_t RecorderServiceProxy::SetAudioChannels(int32_t sourceId, int32_t num) MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(RecorderServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + data.WriteInt32(sourceId); data.WriteInt32(num); int error = Remote()->SendRequest(SET_AUDIO_CHANNELS, data, reply, option); @@ -233,6 +305,12 @@ int32_t RecorderServiceProxy::SetAudioEncodingBitRate(int32_t sourceId, int32_t MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(RecorderServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + data.WriteInt32(sourceId); data.WriteInt32(bitRate); int error = Remote()->SendRequest(SET_AUDIO_ENCODING_BIT_RATE, data, reply, option); @@ -248,6 +326,12 @@ int32_t RecorderServiceProxy::SetDataSource(DataSourceType dataType, int32_t &so MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(RecorderServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + data.WriteInt32(static_cast(dataType)); int error = Remote()->SendRequest(SET_DATA_SOURCE, data, reply, option); if (error != MSERR_OK) { @@ -263,6 +347,12 @@ int32_t RecorderServiceProxy::SetMaxDuration(int32_t duration) MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(RecorderServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + data.WriteInt32(duration); int error = Remote()->SendRequest(SET_MAX_DURATION, data, reply, option); if (error != MSERR_OK) { @@ -277,6 +367,12 @@ int32_t RecorderServiceProxy::SetOutputFormat(OutputFormatType format) MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(RecorderServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + data.WriteInt32(static_cast(format)); int error = Remote()->SendRequest(SET_OUTPUT_FORMAT, data, reply, option); if (error != MSERR_OK) { @@ -291,6 +387,12 @@ int32_t RecorderServiceProxy::SetOutputPath(const std::string &path) MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(RecorderServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + data.WriteString(path); int error = Remote()->SendRequest(SET_OUTPUT_PATH, data, reply, option); if (error != MSERR_OK) { @@ -305,6 +407,12 @@ int32_t RecorderServiceProxy::SetOutputFile(int32_t fd) MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(RecorderServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + (void)data.WriteFileDescriptor(fd); int error = Remote()->SendRequest(SET_OUTPUT_FILE, data, reply, option); if (error != MSERR_OK) { @@ -319,6 +427,12 @@ int32_t RecorderServiceProxy::SetNextOutputFile(int32_t fd) MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(RecorderServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + (void)data.WriteFileDescriptor(fd); int error = Remote()->SendRequest(SET_NEXT_OUTPUT_FILE, data, reply, option); if (error != MSERR_OK) { @@ -333,6 +447,12 @@ int32_t RecorderServiceProxy::SetMaxFileSize(int64_t size) MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(RecorderServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + data.WriteInt64(size); int error = Remote()->SendRequest(SET_MAX_FILE_SIZE, data, reply, option); if (error != MSERR_OK) { @@ -347,6 +467,12 @@ int32_t RecorderServiceProxy::Prepare() MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(RecorderServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + int error = Remote()->SendRequest(PREPARE, data, reply, option); if (error != MSERR_OK) { MEDIA_LOGE("prepare failed, error: %{public}d", error); @@ -360,6 +486,12 @@ int32_t RecorderServiceProxy::Start() MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(RecorderServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + int error = Remote()->SendRequest(START, data, reply, option); if (error != MSERR_OK) { MEDIA_LOGE("start failed, error: %{public}d", error); @@ -373,6 +505,12 @@ int32_t RecorderServiceProxy::Pause() MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(RecorderServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + int error = Remote()->SendRequest(PAUSE, data, reply, option); if (error != MSERR_OK) { MEDIA_LOGE("pause failed, error: %{public}d", error); @@ -386,6 +524,12 @@ int32_t RecorderServiceProxy::Resume() MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(RecorderServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + int error = Remote()->SendRequest(RESUME, data, reply, option); if (error != MSERR_OK) { MEDIA_LOGE("resume failed, error: %{public}d", error); @@ -399,6 +543,12 @@ int32_t RecorderServiceProxy::Stop(bool block) MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(RecorderServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + data.WriteBool(block); int error = Remote()->SendRequest(STOP, data, reply, option); if (error != MSERR_OK) { @@ -413,6 +563,12 @@ int32_t RecorderServiceProxy::Reset() MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(RecorderServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + int error = Remote()->SendRequest(RESET, data, reply, option); if (error != MSERR_OK) { MEDIA_LOGE("reset failed, error: %{public}d", error); @@ -426,6 +582,12 @@ int32_t RecorderServiceProxy::Release() MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(RecorderServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + int error = Remote()->SendRequest(RELEASE, data, reply, option); if (error != MSERR_OK) { MEDIA_LOGE("release failed, error: %{public}d", error); @@ -439,6 +601,12 @@ int32_t RecorderServiceProxy::SetFileSplitDuration(FileSplitType type, int64_t t MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(RecorderServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + data.WriteInt32(static_cast(type)); data.WriteInt64(timestamp); data.WriteUint32(duration); @@ -455,6 +623,12 @@ int32_t RecorderServiceProxy::DestroyStub() MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(RecorderServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + int error = Remote()->SendRequest(DESTROY, data, reply, option); if (error != MSERR_OK) { MEDIA_LOGE("destroy failed, error: %{public}d", error); diff --git a/services/services/recorder/ipc/recorder_service_stub.cpp b/services/services/recorder/ipc/recorder_service_stub.cpp index d5aad9e56..fb1627ef7 100644 --- a/services/services/recorder/ipc/recorder_service_stub.cpp +++ b/services/services/recorder/ipc/recorder_service_stub.cpp @@ -96,6 +96,12 @@ int RecorderServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Mes { MEDIA_LOGI("Stub: OnRemoteRequest of code: %{public}d is received", code); + auto remoteDescriptor = data.ReadInterfaceToken(); + if (RecorderServiceStub::GetDescriptor() != remoteDescriptor) { + MEDIA_LOGE("Invalid descriptor"); + return MSERR_INVALID_OPERATION; + } + auto itFunc = recFuncs_.find(code); if (itFunc != recFuncs_.end()) { auto memberFunc = itFunc->second; diff --git a/services/services/sa_media/ipc/media_service_proxy.cpp b/services/services/sa_media/ipc/media_service_proxy.cpp index 7e62077a3..75f5ddc70 100644 --- a/services/services/sa_media/ipc/media_service_proxy.cpp +++ b/services/services/sa_media/ipc/media_service_proxy.cpp @@ -39,6 +39,12 @@ sptr MediaServiceProxy::GetSubSystemAbility(IStandardMediaService MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(MediaServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return nullptr; + } + data.WriteInt32(static_cast(subSystemId)); int error = Remote()->SendRequest(MediaServiceMsg::GET_SUBSYSTEM, data, reply, option); if (error != MSERR_OK) { @@ -54,6 +60,12 @@ int32_t MediaServiceProxy::SetListenerObject(const sptr &object) MessageParcel data; MessageParcel reply; MessageOption option; + + if (!data.WriteInterfaceToken(MediaServiceProxy::GetDescriptor())) { + MEDIA_LOGE("Failed to write descriptor"); + return MSERR_UNKNOWN; + } + (void)data.WriteRemoteObject(object); int error = Remote()->SendRequest(SET_LISTENER_OBJ, data, reply, option); if (error != MSERR_OK) { diff --git a/services/services/sa_media/ipc/media_service_stub.cpp b/services/services/sa_media/ipc/media_service_stub.cpp index b11675d82..0fd7ad154 100644 --- a/services/services/sa_media/ipc/media_service_stub.cpp +++ b/services/services/sa_media/ipc/media_service_stub.cpp @@ -80,6 +80,12 @@ int MediaServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Messag { MEDIA_LOGI("Stub: OnRemoteRequest of code: %{public}u is received", code); + auto remoteDescriptor = data.ReadInterfaceToken(); + if (MediaServiceStub::GetDescriptor() != remoteDescriptor) { + MEDIA_LOGE("Invalid descriptor"); + return MSERR_INVALID_OPERATION; + } + auto itFunc = mediaFuncs_.find(code); if (itFunc != mediaFuncs_.end()) { auto memberFunc = itFunc->second; -- Gitee