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 #include "session_listener_stub.h"
16 #include "avsession_log.h"
17 #include "avsession_errors.h"
18 #include "avsession_trace.h"
19
20 namespace OHOS::AVSession {
CheckInterfaceToken(MessageParcel & data)21 bool SessionListenerStub::CheckInterfaceToken(MessageParcel& data)
22 {
23 auto localDescriptor = ISessionListener::GetDescriptor();
24 auto remoteDescriptor = data.ReadInterfaceToken();
25 if (remoteDescriptor != localDescriptor) {
26 SLOGI("interface token is not equal");
27 return false;
28 }
29 return true;
30 }
31
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)32 int32_t SessionListenerStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply,
33 MessageOption& option)
34 {
35 if (!CheckInterfaceToken(data)) {
36 return AVSESSION_ERROR;
37 }
38 if (code < LISTENER_CMD_MAX) {
39 return (this->*handlers[code])(data, reply);
40 }
41 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
42 }
43
HandleOnSessionCreate(MessageParcel & data,MessageParcel & reply)44 int32_t SessionListenerStub::HandleOnSessionCreate(MessageParcel& data, MessageParcel& reply)
45 {
46 AVSESSION_TRACE_SYNC_START("SessionListenerStub::OnSessionCreate");
47 AVSessionDescriptor descriptor;
48 CHECK_AND_RETURN_RET_LOG(descriptor.ReadFromParcel(data), ERR_NONE, "read descriptor failed");
49 OnSessionCreate(descriptor);
50 return ERR_NONE;
51 }
52
HandleOnSessionRelease(MessageParcel & data,MessageParcel & reply)53 int32_t SessionListenerStub::HandleOnSessionRelease(MessageParcel& data, MessageParcel& reply)
54 {
55 AVSessionDescriptor descriptor;
56 CHECK_AND_RETURN_RET_LOG(descriptor.ReadFromParcel(data), ERR_NONE, "read descriptor failed");
57 OnSessionRelease(descriptor);
58 return ERR_NONE;
59 }
60
HandleOnTopSessionChange(MessageParcel & data,MessageParcel & reply)61 int32_t SessionListenerStub::HandleOnTopSessionChange(MessageParcel& data, MessageParcel& reply)
62 {
63 AVSESSION_TRACE_SYNC_START("SessionListenerStub::OnTopSessionChange");
64 AVSessionDescriptor descriptor;
65 CHECK_AND_RETURN_RET_LOG(descriptor.ReadFromParcel(data), ERR_NONE, "read descriptor failed");
66 OnTopSessionChange(descriptor);
67 return ERR_NONE;
68 }
69 } // namespace OHOS::AVSession