180922886Sopenharmony_ci/* 280922886Sopenharmony_ci * Copyright (c) 2022-2024 Huawei Device Co., Ltd. 380922886Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 480922886Sopenharmony_ci * you may not use this file except in compliance with the License. 580922886Sopenharmony_ci * You may obtain a copy of the License at 680922886Sopenharmony_ci * 780922886Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 880922886Sopenharmony_ci * 980922886Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1080922886Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1180922886Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1280922886Sopenharmony_ci * See the License for the specific language governing permissions and 1380922886Sopenharmony_ci * limitations under the License. 1480922886Sopenharmony_ci */ 1580922886Sopenharmony_ci 1680922886Sopenharmony_ci#include "avsession_stub.h" 1780922886Sopenharmony_ci#include "avsession_callback_proxy.h" 1880922886Sopenharmony_ci#include "avsession_trace.h" 1980922886Sopenharmony_ci#include "session_xcollie.h" 2080922886Sopenharmony_ci 2180922886Sopenharmony_cinamespace OHOS::AVSession { 2280922886Sopenharmony_cibool AVSessionStub::CheckInterfaceToken(MessageParcel& data) 2380922886Sopenharmony_ci{ 2480922886Sopenharmony_ci auto localDescriptor = IAVSession::GetDescriptor(); 2580922886Sopenharmony_ci auto remoteDescriptor = data.ReadInterfaceToken(); 2680922886Sopenharmony_ci if (remoteDescriptor != localDescriptor) { 2780922886Sopenharmony_ci SLOGI("interface token is not equal"); 2880922886Sopenharmony_ci return false; 2980922886Sopenharmony_ci } 3080922886Sopenharmony_ci return true; 3180922886Sopenharmony_ci} 3280922886Sopenharmony_ci 3380922886Sopenharmony_ciint32_t AVSessionStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) 3480922886Sopenharmony_ci{ 3580922886Sopenharmony_ci if (code >= static_cast<uint32_t>(IAVSession::SESSION_CMD_GET_SESSION_ID) 3680922886Sopenharmony_ci && code < static_cast<uint32_t>(IAVSession::SESSION_CMD_MAX)) { 3780922886Sopenharmony_ci SessionXCollie sessionXCollie(mapCodeToFuncNameXCollie[code]); 3880922886Sopenharmony_ci } 3980922886Sopenharmony_ci if (!CheckInterfaceToken(data)) { 4080922886Sopenharmony_ci return AVSESSION_ERROR; 4180922886Sopenharmony_ci } 4280922886Sopenharmony_ci SLOGI("cmd code is %{public}d", code); 4380922886Sopenharmony_ci if (code >= static_cast<uint32_t>(IAVSession::SESSION_CMD_GET_SESSION_ID) 4480922886Sopenharmony_ci && code < static_cast<uint32_t>(IAVSession::SESSION_CMD_MAX)) { 4580922886Sopenharmony_ci return handlers[code](data, reply); 4680922886Sopenharmony_ci } 4780922886Sopenharmony_ci return IPCObjectStub::OnRemoteRequest(code, data, reply, option); 4880922886Sopenharmony_ci} 4980922886Sopenharmony_ci 5080922886Sopenharmony_ciint32_t AVSessionStub::HandleGetSessionId(MessageParcel& data, MessageParcel& reply) 5180922886Sopenharmony_ci{ 5280922886Sopenharmony_ci CHECK_AND_PRINT_LOG(reply.WriteString(GetSessionId()), "write int32_t failed"); 5380922886Sopenharmony_ci return ERR_NONE; 5480922886Sopenharmony_ci} 5580922886Sopenharmony_ci 5680922886Sopenharmony_ciint32_t AVSessionStub::HandleGetSessionType(MessageParcel& data, MessageParcel& reply) 5780922886Sopenharmony_ci{ 5880922886Sopenharmony_ci CHECK_AND_PRINT_LOG(reply.WriteString(GetSessionType()), "write int32_t failed"); 5980922886Sopenharmony_ci return ERR_NONE; 6080922886Sopenharmony_ci} 6180922886Sopenharmony_ci 6280922886Sopenharmony_ciint32_t AVSessionStub::HandleRegisterCallbackInner(MessageParcel& data, MessageParcel& reply) 6380922886Sopenharmony_ci{ 6480922886Sopenharmony_ci auto remoteObject = data.ReadRemoteObject(); 6580922886Sopenharmony_ci if (remoteObject == nullptr) { 6680922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ERR_UNMARSHALLING), ERR_NONE, "write int32_t failed"); 6780922886Sopenharmony_ci return ERR_NONE; 6880922886Sopenharmony_ci } 6980922886Sopenharmony_ci auto callback = iface_cast<AVSessionCallbackProxy>(remoteObject); 7080922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(callback != nullptr, ERR_NONE, "callback is nullptr"); 7180922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(RegisterCallbackInner(callback)), 7280922886Sopenharmony_ci ERR_NONE, "write int32_t failed"); 7380922886Sopenharmony_ci return ERR_NONE; 7480922886Sopenharmony_ci} 7580922886Sopenharmony_ci 7680922886Sopenharmony_ciint32_t AVSessionStub::HandleDestroy(MessageParcel& data, MessageParcel& reply) 7780922886Sopenharmony_ci{ 7880922886Sopenharmony_ci int32_t ret = Destroy(); 7980922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(AVSESSION_SUCCESS), ERR_NONE, "write int32_t failed"); 8080922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ret, "Destroy failed"); 8180922886Sopenharmony_ci return ERR_NONE; 8280922886Sopenharmony_ci} 8380922886Sopenharmony_ci 8480922886Sopenharmony_ciint32_t AVSessionStub::HandleSetAVCallMetaData(MessageParcel& data, MessageParcel& reply) 8580922886Sopenharmony_ci{ 8680922886Sopenharmony_ci AVSESSION_TRACE_SYNC_START("AVSessionStub::SetAVCallMetaData"); 8780922886Sopenharmony_ci sptr avCallMetaData = data.ReadParcelable<AVCallMetaData>(); 8880922886Sopenharmony_ci if (avCallMetaData == nullptr) { 8980922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ERR_UNMARSHALLING), ERR_NONE, "WriteInt32 result failed"); 9080922886Sopenharmony_ci return ERR_NONE; 9180922886Sopenharmony_ci } 9280922886Sopenharmony_ci int32_t ret = SetAVCallMetaData(*avCallMetaData); 9380922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "WriteInt32 result failed"); 9480922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ret, "GetAVCallMetaData failed"); 9580922886Sopenharmony_ci return ERR_NONE; 9680922886Sopenharmony_ci} 9780922886Sopenharmony_ci 9880922886Sopenharmony_ciint32_t AVSessionStub::HandleSetAVCallState(MessageParcel& data, MessageParcel& reply) 9980922886Sopenharmony_ci{ 10080922886Sopenharmony_ci AVSESSION_TRACE_SYNC_START("AVSessionStub::SetAVCallState"); 10180922886Sopenharmony_ci sptr avCallState = data.ReadParcelable<AVCallState>(); 10280922886Sopenharmony_ci if (avCallState == nullptr) { 10380922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ERR_UNMARSHALLING), ERR_NONE, "WriteInt32 result failed"); 10480922886Sopenharmony_ci return ERR_NONE; 10580922886Sopenharmony_ci } 10680922886Sopenharmony_ci int32_t ret = SetAVCallState(*avCallState); 10780922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "WriteInt32 result failed"); 10880922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ret, "GetAVCallState failed"); 10980922886Sopenharmony_ci return ERR_NONE; 11080922886Sopenharmony_ci} 11180922886Sopenharmony_ci 11280922886Sopenharmony_ciint32_t AVSessionStub::HandleGetAVPlaybackState(MessageParcel& data, MessageParcel& reply) 11380922886Sopenharmony_ci{ 11480922886Sopenharmony_ci AVPlaybackState avPlaybackState; 11580922886Sopenharmony_ci int32_t ret = GetAVPlaybackState(avPlaybackState); 11680922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "write int32 failed"); 11780922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ret, "GetAVPlaybackState failed"); 11880922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteParcelable(&avPlaybackState), ERR_NONE, "write avPlaybackState failed"); 11980922886Sopenharmony_ci return ERR_NONE; 12080922886Sopenharmony_ci} 12180922886Sopenharmony_ci 12280922886Sopenharmony_ciint32_t AVSessionStub::HandleSetAVPlaybackState(MessageParcel& data, MessageParcel& reply) 12380922886Sopenharmony_ci{ 12480922886Sopenharmony_ci AVSESSION_TRACE_SYNC_START("AVSessionStub::SetAVPlaybackState"); 12580922886Sopenharmony_ci sptr avPlaybackState = data.ReadParcelable<AVPlaybackState>(); 12680922886Sopenharmony_ci if (avPlaybackState == nullptr) { 12780922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ERR_UNMARSHALLING), ERR_NONE, "WriteInt32 result failed"); 12880922886Sopenharmony_ci return ERR_NONE; 12980922886Sopenharmony_ci } 13080922886Sopenharmony_ci int32_t ret = SetAVPlaybackState(*avPlaybackState); 13180922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "WriteInt32 result failed"); 13280922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ret, "GetAVPlaybackState failed"); 13380922886Sopenharmony_ci return ERR_NONE; 13480922886Sopenharmony_ci} 13580922886Sopenharmony_ci 13680922886Sopenharmony_ciint32_t AVSessionStub::SetImageData(AVMetaData& meta, const char *buffer, int twoImageLength) 13780922886Sopenharmony_ci{ 13880922886Sopenharmony_ci int mediaImageLength = meta.GetMediaLength(); 13980922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(mediaImageLength >= 0, ERR_NONE, "mediaImageLength is negative number"); 14080922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(mediaImageLength <= twoImageLength, ERR_NONE, "Maybe cuase Out-of-bunds read"); 14180922886Sopenharmony_ci 14280922886Sopenharmony_ci std::shared_ptr<AVSessionPixelMap> mediaPixelMap = std::make_shared<AVSessionPixelMap>(); 14380922886Sopenharmony_ci SLOGI("change for-loop to vector init"); 14480922886Sopenharmony_ci std::vector<uint8_t> mediaImageBuffer(buffer, buffer + mediaImageLength); 14580922886Sopenharmony_ci mediaPixelMap->SetInnerImgBuffer(mediaImageBuffer); 14680922886Sopenharmony_ci meta.SetMediaImage(mediaPixelMap); 14780922886Sopenharmony_ci 14880922886Sopenharmony_ci std::shared_ptr<AVSessionPixelMap> avQueuePixelMap = std::make_shared<AVSessionPixelMap>(); 14980922886Sopenharmony_ci std::vector<uint8_t> avQueueImageBuffer(buffer + mediaImageLength, buffer + twoImageLength); 15080922886Sopenharmony_ci avQueuePixelMap->SetInnerImgBuffer(avQueueImageBuffer); 15180922886Sopenharmony_ci meta.SetAVQueueImage(avQueuePixelMap); 15280922886Sopenharmony_ci 15380922886Sopenharmony_ci return AVSESSION_SUCCESS; 15480922886Sopenharmony_ci} 15580922886Sopenharmony_ci 15680922886Sopenharmony_ciint32_t AVSessionStub::HandleSetAVMetaData(MessageParcel& data, MessageParcel& reply) 15780922886Sopenharmony_ci{ 15880922886Sopenharmony_ci AVSESSION_TRACE_SYNC_START("AVSessionStub::SetAVMetaData"); 15980922886Sopenharmony_ci int twoImageLength = data.ReadInt32(); 16080922886Sopenharmony_ci SLOGD("read length from twoImage %{public}d", twoImageLength); 16180922886Sopenharmony_ci if (twoImageLength <= 0 || twoImageLength > MAX_IMAGE_SIZE) { 16280922886Sopenharmony_ci sptr avMetaData = data.ReadParcelable<AVMetaData>(); 16380922886Sopenharmony_ci if (avMetaData == nullptr) { 16480922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ERR_UNMARSHALLING), ERR_NONE, "WriteInt32 result failed"); 16580922886Sopenharmony_ci return ERR_NONE; 16680922886Sopenharmony_ci } 16780922886Sopenharmony_ci int32_t ret = SetAVMetaData(*avMetaData); 16880922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "WriteInt32 result failed"); 16980922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ERR_NONE, "SetAVMetaData failed"); 17080922886Sopenharmony_ci return ERR_NONE; 17180922886Sopenharmony_ci } 17280922886Sopenharmony_ci 17380922886Sopenharmony_ci AVMetaData meta; 17480922886Sopenharmony_ci AVMetaData::UnmarshallingExceptImg(data, meta); 17580922886Sopenharmony_ci const char *buffer = nullptr; 17680922886Sopenharmony_ci buffer = reinterpret_cast<const char *>(data.ReadRawData(twoImageLength)); 17780922886Sopenharmony_ci if (buffer == nullptr) { 17880922886Sopenharmony_ci SLOGI("read raw data with null, try set without length = %{public}d", twoImageLength); 17980922886Sopenharmony_ci int32_t ret = SetAVMetaData(meta); 18080922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "WriteInt32 result failed"); 18180922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ERR_NONE, "SetAVMetaData failed"); 18280922886Sopenharmony_ci return ERR_NONE; 18380922886Sopenharmony_ci } 18480922886Sopenharmony_ci 18580922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(!SetImageData(meta, buffer, twoImageLength), ERR_NONE, "SetImageData fail"); 18680922886Sopenharmony_ci 18780922886Sopenharmony_ci int32_t ret = SetAVMetaData(meta); 18880922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "WriteInt32 result failed"); 18980922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ERR_NONE, "SetAVMetaData failed"); 19080922886Sopenharmony_ci return ERR_NONE; 19180922886Sopenharmony_ci} 19280922886Sopenharmony_ci 19380922886Sopenharmony_ciint32_t AVSessionStub::HandleSetLaunchAbility(MessageParcel& data, MessageParcel& reply) 19480922886Sopenharmony_ci{ 19580922886Sopenharmony_ci sptr want = data.ReadParcelable<AbilityRuntime::WantAgent::WantAgent>(); 19680922886Sopenharmony_ci if (want == nullptr) { 19780922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ERR_UNMARSHALLING), ERR_NONE, "WriteInt32 result failed"); 19880922886Sopenharmony_ci return ERR_NONE; 19980922886Sopenharmony_ci } 20080922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(SetLaunchAbility(*want)), ERR_NONE, "WriteInt32 result failed"); 20180922886Sopenharmony_ci return ERR_NONE; 20280922886Sopenharmony_ci} 20380922886Sopenharmony_ci 20480922886Sopenharmony_ciint32_t AVSessionStub::HandleGetAVMetaData(MessageParcel& data, MessageParcel& reply) 20580922886Sopenharmony_ci{ 20680922886Sopenharmony_ci AVMetaData avMetaData; 20780922886Sopenharmony_ci reply.SetMaxCapacity(defaultIpcCapacity); 20880922886Sopenharmony_ci int32_t ret = GetAVMetaData(avMetaData); 20980922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "write int32 failed"); 21080922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ERR_NONE, "GetAVMetaData failed"); 21180922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteParcelable(&avMetaData), ERR_NONE, "write avMetaData failed"); 21280922886Sopenharmony_ci SLOGI("clear media img after handle get metadata"); 21380922886Sopenharmony_ci std::shared_ptr<AVSessionPixelMap> innerQueuePixelMap = avMetaData.GetAVQueueImage(); 21480922886Sopenharmony_ci if (innerQueuePixelMap != nullptr) { 21580922886Sopenharmony_ci innerQueuePixelMap->Clear(); 21680922886Sopenharmony_ci } 21780922886Sopenharmony_ci std::shared_ptr<AVSessionPixelMap> innerMediaPixelMap = avMetaData.GetMediaImage(); 21880922886Sopenharmony_ci if (innerMediaPixelMap != nullptr) { 21980922886Sopenharmony_ci innerMediaPixelMap->Clear(); 22080922886Sopenharmony_ci } 22180922886Sopenharmony_ci return ERR_NONE; 22280922886Sopenharmony_ci} 22380922886Sopenharmony_ci 22480922886Sopenharmony_ciint32_t AVSessionStub::HandleGetAVQueueItems(MessageParcel& data, MessageParcel& reply) 22580922886Sopenharmony_ci{ 22680922886Sopenharmony_ci std::vector<AVQueueItem> avQueueItems; 22780922886Sopenharmony_ci int32_t ret = GetAVQueueItems(avQueueItems); 22880922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "write int32 failed"); 22980922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ERR_NONE, "GetAVQueueItems failed"); 23080922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(avQueueItems.size()), ERR_NONE, "write items num int32 failed"); 23180922886Sopenharmony_ci for (auto &parcelable : avQueueItems) { 23280922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteParcelable(&parcelable), ERR_NONE, "Write items failed"); 23380922886Sopenharmony_ci } 23480922886Sopenharmony_ci return ERR_NONE; 23580922886Sopenharmony_ci} 23680922886Sopenharmony_ci 23780922886Sopenharmony_ciint32_t AVSessionStub::HandleSetAVQueueItems(MessageParcel& data, MessageParcel& reply) 23880922886Sopenharmony_ci{ 23980922886Sopenharmony_ci AVSESSION_TRACE_SYNC_START("AVSessionStub::SetAVQueueItems"); 24080922886Sopenharmony_ci int32_t maxQueueItemLength = 1000; // The maximum allowed playlist size is 1000 24180922886Sopenharmony_ci std::vector<AVQueueItem> items_; 24280922886Sopenharmony_ci int32_t itemNum = data.ReadInt32(); 24380922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG((itemNum >= 0) && (itemNum < maxQueueItemLength), 24480922886Sopenharmony_ci ERR_UNMARSHALLING, "read int32 itemNum failed"); 24580922886Sopenharmony_ci for (int32_t i = 0; i < itemNum; i++) { 24680922886Sopenharmony_ci AVQueueItem *item = data.ReadParcelable<AVQueueItem>(); 24780922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(item != nullptr, ERR_UNMARSHALLING, "read parcelable AVQueueItem failed"); 24880922886Sopenharmony_ci if (item == nullptr) { 24980922886Sopenharmony_ci SLOGE("HandleSetAVQueueItems: read parcelable AVQueueItem failed"); 25080922886Sopenharmony_ci delete item; 25180922886Sopenharmony_ci item = nullptr; 25280922886Sopenharmony_ci return ERR_UNMARSHALLING; 25380922886Sopenharmony_ci } 25480922886Sopenharmony_ci items_.emplace_back(*item); 25580922886Sopenharmony_ci delete item; 25680922886Sopenharmony_ci item = nullptr; 25780922886Sopenharmony_ci } 25880922886Sopenharmony_ci int32_t ret = SetAVQueueItems(items_); 25980922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "WriteInt32 result failed"); 26080922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ret, "SetAVQueueItems failed"); 26180922886Sopenharmony_ci return ERR_NONE; 26280922886Sopenharmony_ci} 26380922886Sopenharmony_ci 26480922886Sopenharmony_ciint32_t AVSessionStub::HandleGetAVQueueTitle(MessageParcel& data, MessageParcel& reply) 26580922886Sopenharmony_ci{ 26680922886Sopenharmony_ci std::string title; 26780922886Sopenharmony_ci int32_t ret = GetAVQueueTitle(title); 26880922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "write int32 failed"); 26980922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ERR_NONE, "GetAVQueueTitle failed"); 27080922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteString(title), ERR_NONE, "write title string failed"); 27180922886Sopenharmony_ci return ERR_NONE; 27280922886Sopenharmony_ci} 27380922886Sopenharmony_ci 27480922886Sopenharmony_ciint32_t AVSessionStub::HandleSetAVQueueTitle(MessageParcel& data, MessageParcel& reply) 27580922886Sopenharmony_ci{ 27680922886Sopenharmony_ci AVSESSION_TRACE_SYNC_START("AVSessionStub::SetAVQueueTitle"); 27780922886Sopenharmony_ci std::string title; 27880922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(data.ReadString(title), ERR_NONE, "read title string failed"); 27980922886Sopenharmony_ci int32_t ret = SetAVQueueTitle(title); 28080922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "WriteInt32 result failed"); 28180922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ret, "SetAVQueueTitle failed"); 28280922886Sopenharmony_ci return ERR_NONE; 28380922886Sopenharmony_ci} 28480922886Sopenharmony_ci 28580922886Sopenharmony_ciint32_t AVSessionStub::HandleGetExtras(MessageParcel& data, MessageParcel& reply) 28680922886Sopenharmony_ci{ 28780922886Sopenharmony_ci AVSESSION_TRACE_SYNC_START("AVSessionStub::HandleGetExtras"); 28880922886Sopenharmony_ci AAFwk::WantParams extras; 28980922886Sopenharmony_ci int32_t ret = GetExtras(extras); 29080922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "write int32 failed"); 29180922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ERR_NONE, "GetExtras failed"); 29280922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteParcelable(&extras), ERR_NONE, "write extras failed"); 29380922886Sopenharmony_ci return ERR_NONE; 29480922886Sopenharmony_ci} 29580922886Sopenharmony_ci 29680922886Sopenharmony_ciint32_t AVSessionStub::HandleSetExtras(MessageParcel& data, MessageParcel& reply) 29780922886Sopenharmony_ci{ 29880922886Sopenharmony_ci AVSESSION_TRACE_SYNC_START("AVSessionStub::HandleSetExtras"); 29980922886Sopenharmony_ci sptr extrasWant = data.ReadParcelable<AAFwk::WantParams>(); 30080922886Sopenharmony_ci if (extrasWant == nullptr) { 30180922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ERR_UNMARSHALLING), ERR_NONE, "WriteInt32 result failed"); 30280922886Sopenharmony_ci return ERR_NONE; 30380922886Sopenharmony_ci } 30480922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(SetExtras(*extrasWant)), ERR_NONE, "WriteInt32 result failed"); 30580922886Sopenharmony_ci return ERR_NONE; 30680922886Sopenharmony_ci} 30780922886Sopenharmony_ci 30880922886Sopenharmony_ciint32_t AVSessionStub::HandleGetController(MessageParcel& data, MessageParcel& reply) 30980922886Sopenharmony_ci{ 31080922886Sopenharmony_ci sptr<IRemoteObject> controller = GetControllerInner(); 31180922886Sopenharmony_ci if (controller == nullptr) { 31280922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(AVSESSION_ERROR), ERR_NONE, "write int32 failed"); 31380922886Sopenharmony_ci return ERR_NONE; 31480922886Sopenharmony_ci } 31580922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(AVSESSION_SUCCESS), ERR_NONE, "write int32 failed"); 31680922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteRemoteObject(controller), ERR_NONE, "write object failed"); 31780922886Sopenharmony_ci return ERR_NONE; 31880922886Sopenharmony_ci} 31980922886Sopenharmony_ci 32080922886Sopenharmony_ci#ifdef CASTPLUS_CAST_ENGINE_ENABLE 32180922886Sopenharmony_ciint32_t AVSessionStub::HandleGetAVCastController(MessageParcel& data, MessageParcel& reply) 32280922886Sopenharmony_ci{ 32380922886Sopenharmony_ci sptr<IRemoteObject> castController = GetAVCastControllerInner(); 32480922886Sopenharmony_ci if (castController == nullptr) { 32580922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(AVSESSION_ERROR), ERR_NONE, "write int32 failed"); 32680922886Sopenharmony_ci return ERR_NONE; 32780922886Sopenharmony_ci } 32880922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(AVSESSION_SUCCESS), ERR_NONE, "write int32 failed"); 32980922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteRemoteObject(castController), ERR_NONE, "write object failed"); 33080922886Sopenharmony_ci return ERR_NONE; 33180922886Sopenharmony_ci} 33280922886Sopenharmony_ci#endif 33380922886Sopenharmony_ci 33480922886Sopenharmony_ciint32_t AVSessionStub::HandleActivate(MessageParcel& data, MessageParcel& reply) 33580922886Sopenharmony_ci{ 33680922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(Activate()), ERR_NONE, "WriteInt32 failed"); 33780922886Sopenharmony_ci return ERR_NONE; 33880922886Sopenharmony_ci} 33980922886Sopenharmony_ci 34080922886Sopenharmony_ciint32_t AVSessionStub::HandleDeactivate(MessageParcel& data, MessageParcel& reply) 34180922886Sopenharmony_ci{ 34280922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(Deactivate()), ERR_NONE, "WriteInt32 failed"); 34380922886Sopenharmony_ci return ERR_NONE; 34480922886Sopenharmony_ci} 34580922886Sopenharmony_ci 34680922886Sopenharmony_ciint32_t AVSessionStub::HandleIsActive(MessageParcel& data, MessageParcel& reply) 34780922886Sopenharmony_ci{ 34880922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteBool(IsActive()), ERR_NONE, "WriteBool failed"); 34980922886Sopenharmony_ci return ERR_NONE; 35080922886Sopenharmony_ci} 35180922886Sopenharmony_ci 35280922886Sopenharmony_ciint32_t AVSessionStub::HandleAddSupportCommand(MessageParcel& data, MessageParcel& reply) 35380922886Sopenharmony_ci{ 35480922886Sopenharmony_ci int32_t ret = AddSupportCommand(data.ReadInt32()); 35580922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "WriteInt32 failed"); 35680922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ERR_NONE, "AddSupportCommand failed"); 35780922886Sopenharmony_ci return ERR_NONE; 35880922886Sopenharmony_ci} 35980922886Sopenharmony_ci 36080922886Sopenharmony_ciint32_t AVSessionStub::HandleDeleteSupportCommand(MessageParcel& data, MessageParcel& reply) 36180922886Sopenharmony_ci{ 36280922886Sopenharmony_ci int32_t ret = DeleteSupportCommand(data.ReadInt32()); 36380922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "WriteInt32 failed"); 36480922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ERR_NONE, "DeleteSupportCommand failed"); 36580922886Sopenharmony_ci return ERR_NONE; 36680922886Sopenharmony_ci} 36780922886Sopenharmony_ci 36880922886Sopenharmony_ciint32_t AVSessionStub::HandleSetSessionEvent(MessageParcel& data, MessageParcel& reply) 36980922886Sopenharmony_ci{ 37080922886Sopenharmony_ci auto event = data.ReadString(); 37180922886Sopenharmony_ci sptr want = data.ReadParcelable<AAFwk::WantParams>(); 37280922886Sopenharmony_ci if (want == nullptr) { 37380922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ERR_UNMARSHALLING), ERR_NONE, "WriteInt32 result failed"); 37480922886Sopenharmony_ci return ERR_NONE; 37580922886Sopenharmony_ci } 37680922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(SetSessionEvent(event, *want)), ERR_NONE, "WriteInt32 result failed"); 37780922886Sopenharmony_ci return ERR_NONE; 37880922886Sopenharmony_ci} 37980922886Sopenharmony_ci 38080922886Sopenharmony_ci#ifdef CASTPLUS_CAST_ENGINE_ENABLE 38180922886Sopenharmony_ciint32_t AVSessionStub::HandleReleaseCast(MessageParcel& data, MessageParcel& reply) 38280922886Sopenharmony_ci{ 38380922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ReleaseCast()), ERR_NONE, "WriteInt32 failed"); 38480922886Sopenharmony_ci return ERR_NONE; 38580922886Sopenharmony_ci} 38680922886Sopenharmony_ci 38780922886Sopenharmony_ciint32_t AVSessionStub::HandleStartCastDisplayListener(MessageParcel& data, MessageParcel& reply) 38880922886Sopenharmony_ci{ 38980922886Sopenharmony_ci int32_t ret = StartCastDisplayListener(); 39080922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "WriteInt32 failed"); 39180922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ERR_NONE, "StartCastDisplayListener failed"); 39280922886Sopenharmony_ci return ERR_NONE; 39380922886Sopenharmony_ci} 39480922886Sopenharmony_ci 39580922886Sopenharmony_ciint32_t AVSessionStub::HandleStopCastDisplayListener(MessageParcel& data, MessageParcel& reply) 39680922886Sopenharmony_ci{ 39780922886Sopenharmony_ci int32_t ret = StopCastDisplayListener(); 39880922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "WriteInt32 failed"); 39980922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ERR_NONE, "StopCastDisplayListener failed"); 40080922886Sopenharmony_ci return ERR_NONE; 40180922886Sopenharmony_ci} 40280922886Sopenharmony_ci 40380922886Sopenharmony_ciint32_t AVSessionStub::HandleGetAllCastDisplays(MessageParcel& data, MessageParcel& reply) 40480922886Sopenharmony_ci{ 40580922886Sopenharmony_ci std::vector<CastDisplayInfo> castDisplays; 40680922886Sopenharmony_ci int32_t ret = GetAllCastDisplays(castDisplays); 40780922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(ret), ERR_NONE, "WriteInt32 failed"); 40880922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(ret == AVSESSION_SUCCESS, ERR_NONE, "GetAllCastDisplays failed"); 40980922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(castDisplays.size()), ERR_NONE, "WriteInt32 failed"); 41080922886Sopenharmony_ci for (auto &castDisplay : castDisplays) { 41180922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(static_cast<int32_t>(castDisplay.displayState)), 41280922886Sopenharmony_ci ERR_NONE, "Write displayState failed"); 41380922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteUint64(castDisplay.displayId), ERR_NONE, "Write displayId failed"); 41480922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteString(castDisplay.name), ERR_NONE, "Write name failed"); 41580922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(castDisplay.width), ERR_NONE, "Write width failed"); 41680922886Sopenharmony_ci CHECK_AND_RETURN_RET_LOG(reply.WriteInt32(castDisplay.height), ERR_NONE, "Write height failed"); 41780922886Sopenharmony_ci } 41880922886Sopenharmony_ci return ERR_NONE; 41980922886Sopenharmony_ci} 42080922886Sopenharmony_ci#endif 42180922886Sopenharmony_ci} // namespace OHOS::AVSession 422