aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 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 | |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 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 "IDrmIOService.h" |
| 23 | |
| 24 | using namespace android; |
| 25 | |
| 26 | void BpDrmIOService::writeToFile(const String8& filePath, const String8& dataBuffer) { |
| 27 | Parcel data, reply; |
| 28 | |
| 29 | data.writeInterfaceToken(IDrmIOService::getInterfaceDescriptor()); |
| 30 | data.writeString8(filePath); |
| 31 | data.writeString8(dataBuffer); |
| 32 | |
| 33 | remote()->transact(WRITE_TO_FILE, data, &reply); |
| 34 | } |
| 35 | |
| 36 | String8 BpDrmIOService::readFromFile(const String8& filePath) { |
| 37 | |
| 38 | Parcel data, reply; |
| 39 | |
| 40 | data.writeInterfaceToken(IDrmIOService::getInterfaceDescriptor()); |
| 41 | data.writeString8(filePath); |
| 42 | |
| 43 | remote()->transact(READ_FROM_FILE, data, &reply); |
| 44 | return reply.readString8(); |
| 45 | } |
| 46 | |
| 47 | IMPLEMENT_META_INTERFACE(DrmIOService, "drm.IDrmIOService"); |
| 48 | |
| 49 | status_t BnDrmIOService::onTransact( |
| 50 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) { |
| 51 | |
| 52 | switch (code) { |
| 53 | case WRITE_TO_FILE: |
| 54 | { |
| 55 | CHECK_INTERFACE(IDrmIOService, data, reply); |
| 56 | |
| 57 | writeToFile(data.readString8(), data.readString8()); |
| 58 | return DRM_NO_ERROR; |
| 59 | } |
| 60 | |
| 61 | case READ_FROM_FILE: |
| 62 | { |
| 63 | CHECK_INTERFACE(IDrmIOService, data, reply); |
| 64 | |
| 65 | String8 dataBuffer = readFromFile(data.readString8()); |
| 66 | reply->writeString8(dataBuffer); |
| 67 | return DRM_NO_ERROR; |
| 68 | } |
| 69 | |
| 70 | default: |
| 71 | return BBinder::onTransact(code, data, reply, flags); |
| 72 | } |
| 73 | } |
| 74 | |