1 /*
2 * Copyright (c) 2023-2024 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 "mediakeysystem_service_callback_stub.h"
17 #include "remote_request_code.h"
18 #include "drm_log.h"
19 #include "drm_error_code.h"
20
21 namespace OHOS {
22 namespace DrmStandard {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)23 int32_t MediaKeySystemServiceCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
24 MessageOption &option)
25 {
26 int32_t ret = DRM_ERROR;
27
28 if (data.ReadInterfaceToken() != GetDescriptor()) {
29 DRM_ERR_LOG("GetDescriptor faild, error code: %{public}d", ret);
30 return ret;
31 }
32 switch (code) {
33 case MEDIA_KEY_SYSTEM_SERVICE_CALLBACK_SEND_EVENT:
34 ret = MediaKeySystemServiceCallbackStub::HandleSendEvent(data);
35 break;
36 default:
37 DRM_ERR_LOG("MediaKeySystemServiceCallbackStub request code %{public}u not handled", code);
38 ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
39 break;
40 }
41 return ret;
42 }
43
HandleSendEvent(MessageParcel & data)44 int32_t MediaKeySystemServiceCallbackStub::HandleSendEvent(MessageParcel &data)
45 {
46 DRM_INFO_LOG("MediaKeySystemServiceCallbackStub HandleSendEvent enter.");
47 int32_t event = data.ReadInt32();
48 int32_t extra = data.ReadInt32();
49 uint32_t dataSize = data.ReadUint32();
50 DRM_CHECK_AND_RETURN_RET_LOG(dataSize < DATA_MAX_LEN, DRM_MEMORY_ERROR,
51 "The size of event data is too large.");
52 std::vector<uint8_t> customizedData;
53 for (uint32_t i = 0; i < dataSize; i++) {
54 customizedData.emplace_back(data.ReadUint8());
55 }
56 DrmEventType eventType = static_cast<DrmEventType>(event);
57 return SendEvent(eventType, extra, customizedData);
58 }
59 } // namespace DrmStandard
60 } // namespace OHOS
61