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 "avcontroller_callback_stub.h"
16 #include "avsession_errors.h"
17 #include "avsession_log.h"
18 #include "avsession_trace.h"
19
20 namespace OHOS::AVSession {
CheckInterfaceToken(MessageParcel & data)21 bool AVControllerCallbackStub::CheckInterfaceToken(MessageParcel& data)
22 {
23 auto localDescriptor = IAVControllerCallback::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 AVControllerCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply,
33 MessageOption &option)
34 {
35 if (!CheckInterfaceToken(data)) {
36 return AVSESSION_ERROR;
37 }
38 if (code < CONTROLLER_CMD_MAX) {
39 return (this->*handlers[code])(data, reply);
40 }
41 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
42 }
43
HandleOnSessionDestroy(MessageParcel & data,MessageParcel & reply)44 int32_t AVControllerCallbackStub::HandleOnSessionDestroy(MessageParcel& data, MessageParcel& reply)
45 {
46 OnSessionDestroy();
47 return ERR_NONE;
48 }
49
HandleOnPlaybackStateChange(MessageParcel & data,MessageParcel & reply)50 int32_t AVControllerCallbackStub::HandleOnPlaybackStateChange(MessageParcel& data, MessageParcel& reply)
51 {
52 sptr<AVPlaybackState> state = data.ReadParcelable<AVPlaybackState>();
53
54 CHECK_AND_RETURN_RET_LOG(state != nullptr, ERR_NONE, "read PlaybackState failed");
55 AVSESSION_TRACE_SYNC_START("AVControllerCallbackStub::OnPlaybackStateChange");
56 OnPlaybackStateChange(*state);
57 return ERR_NONE;
58 }
59
HandleOnMetadataChange(MessageParcel & data,MessageParcel & reply)60 int32_t AVControllerCallbackStub::HandleOnMetadataChange(MessageParcel& data, MessageParcel& reply)
61 {
62 sptr<AVMetaData> metaData = data.ReadParcelable<AVMetaData>();
63
64 CHECK_AND_RETURN_RET_LOG(metaData != nullptr, ERR_NONE, "read MetaData failed");
65 AVSESSION_TRACE_SYNC_START("AVControllerCallbackStub::OnMetaDataChange");
66 OnMetaDataChange(*metaData);
67 return ERR_NONE;
68 }
69
HandleOnActiveStateChange(MessageParcel & data,MessageParcel & reply)70 int32_t AVControllerCallbackStub::HandleOnActiveStateChange(MessageParcel& data, MessageParcel& reply)
71 {
72 bool isActive = false;
73 CHECK_AND_RETURN_RET_LOG(data.ReadBool(isActive), ERR_NONE, "read isActive failed");
74 OnActiveStateChange(isActive);
75 return ERR_NONE;
76 }
77
HandleOnValidCommandChange(MessageParcel & data,MessageParcel & reply)78 int32_t AVControllerCallbackStub::HandleOnValidCommandChange(MessageParcel& data, MessageParcel& reply)
79 {
80 std::vector<int32_t> cmds;
81 CHECK_AND_RETURN_RET_LOG(data.ReadInt32Vector(&cmds), ERR_NONE, "read int32 vector failed");
82 OnValidCommandChange(cmds);
83 return ERR_NONE;
84 }
85
HandleOnOutputDeviceChange(MessageParcel & data,MessageParcel & reply)86 int32_t AVControllerCallbackStub::HandleOnOutputDeviceChange(MessageParcel& data, MessageParcel& reply)
87 {
88 OutputDeviceInfo outputDeviceInfo;
89 CHECK_AND_RETURN_RET_LOG(data.ReadBool(outputDeviceInfo.isRemote_), ERR_NONE, "read isRemote_ failed");
90 CHECK_AND_RETURN_RET_LOG(data.ReadStringVector(&outputDeviceInfo.deviceIds_), ERR_NONE, "read Ids failed");
91 CHECK_AND_RETURN_RET_LOG(data.ReadStringVector(&outputDeviceInfo.deviceNames_), ERR_NONE, "read Names failed");
92 OnOutputDeviceChange(outputDeviceInfo);
93 return ERR_NONE;
94 }
95 } // namespace OHOS::AVSession