IDrmServiceListener.cpp revision 5ff7836da0220b3097f36c8a5e82111816ebca62
1/* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#include <stdint.h> 18#include <sys/types.h> 19#include <binder/Parcel.h> 20#include <binder/IPCThreadState.h> 21#include <drm/drm_framework_common.h> 22#include <drm/DrmInfoEvent.h> 23#include "IDrmServiceListener.h" 24 25using namespace android; 26 27status_t BpDrmServiceListener::notify(const DrmInfoEvent& event) { 28 Parcel data, reply; 29 30 data.writeInterfaceToken(IDrmServiceListener::getInterfaceDescriptor()); 31 data.writeInt32(event.getUniqueId()); 32 data.writeInt32(event.getType()); 33 data.writeString8(event.getMessage()); 34 35 data.writeInt32(event.getCount()); 36 DrmInfoEvent::KeyIterator keyIt = event.keyIterator(); 37 while (keyIt.hasNext()) { 38 String8 key = keyIt.next(); 39 data.writeString8(key); 40 data.writeString8(event.get(key)); 41 } 42 const DrmBuffer& value = event.getData(); 43 data.writeInt32(value.length); 44 if (value.length > 0) { 45 data.write(value.data, value.length); 46 } 47 48 remote()->transact(NOTIFY, data, &reply); 49 return reply.readInt32(); 50} 51 52IMPLEMENT_META_INTERFACE(DrmServiceListener, "drm.IDrmServiceListener"); 53 54status_t BnDrmServiceListener::onTransact( 55 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) { 56 57 switch (code) { 58 case NOTIFY: 59 { 60 CHECK_INTERFACE(IDrmServiceListener, data, reply); 61 int uniqueId = data.readInt32(); 62 int type = data.readInt32(); 63 const String8& message = data.readString8(); 64 65 DrmInfoEvent event(uniqueId, type, message); 66 int size = data.readInt32(); 67 for (int index = 0; index < size; index++) { 68 String8 key(data.readString8()); 69 String8 value(data.readString8()); 70 event.put(key, value); 71 } 72 int valueSize = data.readInt32(); 73 if (valueSize > 0) { 74 char* valueData = new char[valueSize]; 75 data.read(valueData, valueSize); 76 DrmBuffer drmBuffer(valueData, valueSize); 77 event.setData(drmBuffer); 78 delete[] valueData; 79 } 80 81 status_t status = notify(event); 82 83 reply->writeInt32(status); 84 85 return DRM_NO_ERROR; 86 } 87 default: 88 return BBinder::onTransact(code, data, reply, flags); 89 } 90} 91 92