1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "avsession_descriptor.h"
17 #include "avsession_log.h"
18
19 namespace OHOS::AVSession {
WriteToParcel(Parcel & out) const20 bool AVSessionDescriptor::WriteToParcel(Parcel& out) const
21 {
22 CHECK_AND_RETURN_RET_LOG(out.WriteString(sessionId_), false, "write sessionId failed");
23 CHECK_AND_RETURN_RET_LOG(out.WriteInt32(sessionType_), false, "write sessionType failed");
24 CHECK_AND_RETURN_RET_LOG(out.WriteString(sessionTag_), false, "write sessionTag failed");
25 CHECK_AND_RETURN_RET_LOG(out.WriteInt32(pid_), false, "write pid failed");
26 CHECK_AND_RETURN_RET_LOG(out.WriteInt32(uid_), false, "write uid failed");
27 CHECK_AND_RETURN_RET_LOG(out.WriteBool(isActive_), false, "write isActive failed");
28 CHECK_AND_RETURN_RET_LOG(out.WriteBool(isTopSession_), false, "write isTopSession failed");
29 CHECK_AND_RETURN_RET_LOG(out.WriteBool(outputDeviceInfo_.isRemote_), false, "write isRemote failed");
30 CHECK_AND_RETURN_RET_LOG(out.WriteStringVector(outputDeviceInfo_.deviceIds_), false, "write deviceIds failed");
31 CHECK_AND_RETURN_RET_LOG(out.WriteStringVector(outputDeviceInfo_.deviceNames_), false, "write deviceNames failed");
32 CHECK_AND_RETURN_RET_LOG(out.WriteParcelable(&elementName_), false, "write elementName failed");
33 return true;
34 }
35
ReadFromParcel(Parcel & in)36 bool AVSessionDescriptor::ReadFromParcel(Parcel& in)
37 {
38 CHECK_AND_RETURN_RET_LOG(in.ReadString(sessionId_), false, "Read sessionId failed");
39 CHECK_AND_RETURN_RET_LOG(in.ReadInt32(sessionType_), false, "Read sessionType failed");
40 CHECK_AND_RETURN_RET_LOG(in.ReadString(sessionTag_), false, "Read sessionTag failed");
41 CHECK_AND_RETURN_RET_LOG(in.ReadInt32(pid_), false, "Read pid failed");
42 CHECK_AND_RETURN_RET_LOG(in.ReadInt32(uid_), false, "Read uid failed");
43 CHECK_AND_RETURN_RET_LOG(in.ReadBool(isActive_), false, "Read isActive failed");
44 CHECK_AND_RETURN_RET_LOG(in.ReadBool(isTopSession_), false, "Read isTopSession failed");
45 CHECK_AND_RETURN_RET_LOG(in.ReadBool(outputDeviceInfo_.isRemote_), false, "Read isRemote failed");
46 CHECK_AND_RETURN_RET_LOG(in.ReadStringVector(&outputDeviceInfo_.deviceIds_), false, "Read deviceIds failed");
47 CHECK_AND_RETURN_RET_LOG(in.ReadStringVector(&outputDeviceInfo_.deviceNames_), false, "Read deviceNames failed");
48
49 sptr elementName = in.ReadParcelable<AppExecFwk::ElementName>();
50 if (elementName == nullptr) {
51 SLOGE("read element name failed");
52 return false;
53 }
54 elementName_ = *elementName;
55 return true;
56 }
57 }