• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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 AVHistoryDescriptor::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.WriteString(bundleName_), false, "write bundleName failed");
24     CHECK_AND_RETURN_RET_LOG(out.WriteString(abilityName_), false, "write abilityName failed");
25     return true;
26 }
27 
ReadFromParcel(Parcel & in)28 bool AVHistoryDescriptor::ReadFromParcel(Parcel& in)
29 {
30     CHECK_AND_RETURN_RET_LOG(in.ReadString(sessionId_), false, "Read sessionId failed");
31     CHECK_AND_RETURN_RET_LOG(in.ReadString(bundleName_), false, "Read bundleName failed");
32     CHECK_AND_RETURN_RET_LOG(in.ReadString(abilityName_), false, "Read abilityName failed");
33     return true;
34 }
35 
WriteToParcel(Parcel & out) const36 bool AVSessionDescriptor::WriteToParcel(Parcel& out) const
37 {
38     CHECK_AND_RETURN_RET_LOG(out.WriteString(sessionId_), false, "write sessionId failed");
39     CHECK_AND_RETURN_RET_LOG(out.WriteInt32(sessionType_), false, "write sessionType failed");
40     CHECK_AND_RETURN_RET_LOG(out.WriteString(sessionTag_), false, "write sessionTag failed");
41     CHECK_AND_RETURN_RET_LOG(out.WriteInt32(pid_), false, "write pid failed");
42     CHECK_AND_RETURN_RET_LOG(out.WriteInt32(uid_), false, "write uid failed");
43     CHECK_AND_RETURN_RET_LOG(out.WriteBool(isActive_), false, "write isActive failed");
44     CHECK_AND_RETURN_RET_LOG(out.WriteBool(isTopSession_), false, "write isTopSession failed");
45 
46     int32_t deviceInfoSize = outputDeviceInfo_.deviceInfos_.size();
47     CHECK_AND_RETURN_RET_LOG(out.WriteInt32(deviceInfoSize), false, "write deviceInfoSize failed");
48     for (DeviceInfo deviceInfo : outputDeviceInfo_.deviceInfos_) {
49         CHECK_AND_RETURN_RET_LOG(out.WriteInt32(deviceInfo.castCategory_), false, "write castCategory failed");
50         CHECK_AND_RETURN_RET_LOG(out.WriteString(deviceInfo.deviceId_), false, "write deviceId failed");
51         CHECK_AND_RETURN_RET_LOG(out.WriteString(deviceInfo.deviceName_), false, "write deviceName failed");
52         CHECK_AND_RETURN_RET_LOG(out.WriteInt32(deviceInfo.deviceType_), false, "write deviceType failed");
53         CHECK_AND_RETURN_RET_LOG(out.WriteString(deviceInfo.ipAddress_), false, "write ipAddress failed");
54         CHECK_AND_RETURN_RET_LOG(out.WriteInt32(deviceInfo.providerId_), false, "write providerId failed");
55         CHECK_AND_RETURN_RET_LOG(out.WriteInt32(deviceInfo.supportedProtocols_), false,
56             "write supportedProtocols failed");
57         CHECK_AND_RETURN_RET_LOG(out.WriteInt32(deviceInfo.authenticationStatus_), false,
58             "write authenticationStatus failed");
59     }
60     CHECK_AND_RETURN_RET_LOG(out.WriteParcelable(&elementName_), false, "write elementName failed");
61     return true;
62 }
63 
ReadFromParcel(Parcel & in)64 bool AVSessionDescriptor::ReadFromParcel(Parcel& in)
65 {
66     CHECK_AND_RETURN_RET_LOG(in.ReadString(sessionId_), false, "Read sessionId failed");
67     CHECK_AND_RETURN_RET_LOG(in.ReadInt32(sessionType_), false, "Read sessionType failed");
68     CHECK_AND_RETURN_RET_LOG(in.ReadString(sessionTag_), false, "Read sessionTag failed");
69     CHECK_AND_RETURN_RET_LOG(in.ReadInt32(pid_), false, "Read pid failed");
70     CHECK_AND_RETURN_RET_LOG(in.ReadInt32(uid_), false, "Read uid failed");
71     CHECK_AND_RETURN_RET_LOG(in.ReadBool(isActive_), false, "Read isActive failed");
72     CHECK_AND_RETURN_RET_LOG(in.ReadBool(isTopSession_), false, "Read isTopSession failed");
73 
74     int32_t deviceInfoSize;
75     CHECK_AND_RETURN_RET_LOG(in.ReadInt32(deviceInfoSize), false, "write deviceInfoSize failed");
76     for (int i = 0; i < deviceInfoSize; i++) {
77         DeviceInfo deviceInfo;
78         CHECK_AND_RETURN_RET_LOG(in.ReadInt32(deviceInfo.castCategory_), false, "Read castCategory failed");
79         CHECK_AND_RETURN_RET_LOG(in.ReadString(deviceInfo.deviceId_), false, "Read deviceId failed");
80         CHECK_AND_RETURN_RET_LOG(in.ReadString(deviceInfo.deviceName_), false, "Read deviceName failed");
81         CHECK_AND_RETURN_RET_LOG(in.ReadInt32(deviceInfo.deviceType_), false, "Read deviceType failed");
82         CHECK_AND_RETURN_RET_LOG(in.ReadString(deviceInfo.ipAddress_), false, "Read ipAddress failed");
83         CHECK_AND_RETURN_RET_LOG(in.ReadInt32(deviceInfo.providerId_), false, "Read providerId failed");
84         CHECK_AND_RETURN_RET_LOG(in.ReadInt32(deviceInfo.supportedProtocols_), false,
85             "Read supportedProtocols failed");
86         CHECK_AND_RETURN_RET_LOG(in.ReadInt32(deviceInfo.authenticationStatus_), false,
87             "Read authenticationStatus failed");
88         outputDeviceInfo_.deviceInfos_.emplace_back(deviceInfo);
89     }
90 
91     sptr elementName = in.ReadParcelable<AppExecFwk::ElementName>();
92     if (elementName == nullptr) {
93         SLOGE("read element name failed");
94         return false;
95     }
96     elementName_ = *elementName;
97     return true;
98 }
99 
WriteToParcel(Parcel & out) const100 bool DeviceInfo::WriteToParcel(Parcel& out) const
101 {
102     CHECK_AND_RETURN_RET_LOG(out.WriteInt32(castCategory_), false, "write castCategory failed");
103     CHECK_AND_RETURN_RET_LOG(out.WriteString(deviceId_), false, "write deviceId failed");
104     CHECK_AND_RETURN_RET_LOG(out.WriteString(deviceName_), false, "write deviceName failed");
105     CHECK_AND_RETURN_RET_LOG(out.WriteInt32(deviceType_), false, "write deviceType failed");
106     CHECK_AND_RETURN_RET_LOG(out.WriteString(ipAddress_), false, "write ipAddress failed");
107     CHECK_AND_RETURN_RET_LOG(out.WriteInt32(providerId_), false, "write providerId failed");
108     CHECK_AND_RETURN_RET_LOG(out.WriteInt32(supportedProtocols_), false,
109         "write supportedProtocols failed");
110     CHECK_AND_RETURN_RET_LOG(out.WriteInt32(authenticationStatus_), false,
111         "write authenticationStatus failed");
112 
113     return true;
114 }
115 
ReadFromParcel(Parcel & in)116 bool DeviceInfo::ReadFromParcel(Parcel& in)
117 {
118     CHECK_AND_RETURN_RET_LOG(in.ReadInt32(castCategory_), false, "Read castCategory failed");
119     CHECK_AND_RETURN_RET_LOG(in.ReadString(deviceId_), false, "Read deviceId failed");
120     CHECK_AND_RETURN_RET_LOG(in.ReadString(deviceName_), false, "Read deviceName failed");
121     CHECK_AND_RETURN_RET_LOG(in.ReadInt32(deviceType_), false, "Read deviceType failed");
122     CHECK_AND_RETURN_RET_LOG(in.ReadString(ipAddress_), false, "Read ipAddress failed");
123     CHECK_AND_RETURN_RET_LOG(in.ReadInt32(providerId_), false, "Read providerId failed");
124     CHECK_AND_RETURN_RET_LOG(in.ReadInt32(supportedProtocols_), false,
125         "Read supportedProtocols failed");
126     CHECK_AND_RETURN_RET_LOG(in.ReadInt32(authenticationStatus_), false,
127         "Read authenticationStatus failed");
128 
129     return true;
130 }
131 
WriteToParcel(Parcel & out) const132 bool OutputDeviceInfo::WriteToParcel(Parcel& out) const
133 {
134     int32_t deviceInfoSize = deviceInfos_.size();
135     CHECK_AND_RETURN_RET_LOG(out.WriteInt32(deviceInfoSize), false, "write deviceInfoSize failed");
136     for (DeviceInfo deviceInfo : deviceInfos_) {
137         CHECK_AND_RETURN_RET_LOG(out.WriteInt32(deviceInfo.castCategory_), false, "write castCategory failed");
138         CHECK_AND_RETURN_RET_LOG(out.WriteString(deviceInfo.deviceId_), false, "write deviceId failed");
139         CHECK_AND_RETURN_RET_LOG(out.WriteString(deviceInfo.deviceName_), false, "write deviceName failed");
140         CHECK_AND_RETURN_RET_LOG(out.WriteInt32(deviceInfo.deviceType_), false, "write deviceType failed");
141         CHECK_AND_RETURN_RET_LOG(out.WriteString(deviceInfo.ipAddress_), false, "write ipAddress failed");
142         CHECK_AND_RETURN_RET_LOG(out.WriteInt32(deviceInfo.providerId_), false, "write providerId failed");
143         CHECK_AND_RETURN_RET_LOG(out.WriteInt32(deviceInfo.supportedProtocols_), false,
144             "Read supportedProtocols failed");
145         CHECK_AND_RETURN_RET_LOG(out.WriteInt32(deviceInfo.authenticationStatus_), false,
146             "Read authenticationStatus failed");
147     }
148     return true;
149 }
150 
ReadFromParcel(Parcel & in)151 bool OutputDeviceInfo::ReadFromParcel(Parcel& in)
152 {
153     int32_t deviceInfoSize;
154     CHECK_AND_RETURN_RET_LOG(in.ReadInt32(deviceInfoSize), false, "write deviceInfoSize failed");
155     for (int i = 0; i < deviceInfoSize; i++) {
156         DeviceInfo deviceInfo;
157         CHECK_AND_RETURN_RET_LOG(in.ReadInt32(deviceInfo.castCategory_), false, "Read castCategory failed");
158         CHECK_AND_RETURN_RET_LOG(in.ReadString(deviceInfo.deviceId_), false, "Read deviceId failed");
159         CHECK_AND_RETURN_RET_LOG(in.ReadString(deviceInfo.deviceName_), false, "Read deviceName failed");
160         CHECK_AND_RETURN_RET_LOG(in.ReadInt32(deviceInfo.deviceType_), false, "Read deviceType failed");
161         CHECK_AND_RETURN_RET_LOG(in.ReadString(deviceInfo.ipAddress_), false, "Read ipAddress failed");
162         CHECK_AND_RETURN_RET_LOG(in.ReadInt32(deviceInfo.providerId_), false, "Read providerId failed");
163         CHECK_AND_RETURN_RET_LOG(in.ReadInt32(deviceInfo.supportedProtocols_), false,
164             "Read supportedProtocols failed");
165         CHECK_AND_RETURN_RET_LOG(in.ReadInt32(deviceInfo.authenticationStatus_), false,
166             "Read authenticationStatus failed");
167         deviceInfos_.emplace_back(deviceInfo);
168     }
169     return true;
170 }
171 } // namespace OHOS::AVSession
172