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 | |
| 17 | #define LOG_NDEBUG 0 |
| 18 | #define LOG_TAG "IDrmIOService" |
| 19 | #include <utils/Log.h> |
| 20 | |
| 21 | #include <stdint.h> |
| 22 | #include <sys/types.h> |
| 23 | #include <binder/Parcel.h> |
| 24 | #include <binder/IPCThreadState.h> |
| 25 | #include <drm/drm_framework_common.h> |
| 26 | #include "IDrmIOService.h" |
| 27 | |
| 28 | using namespace android; |
| 29 | |
| 30 | void BpDrmIOService::writeToFile(const String8& filePath, const String8& dataBuffer) { |
| 31 | Parcel data, reply; |
| 32 | |
| 33 | data.writeInterfaceToken(IDrmIOService::getInterfaceDescriptor()); |
| 34 | data.writeString8(filePath); |
| 35 | data.writeString8(dataBuffer); |
| 36 | |
| 37 | remote()->transact(WRITE_TO_FILE, data, &reply); |
| 38 | } |
| 39 | |
| 40 | String8 BpDrmIOService::readFromFile(const String8& filePath) { |
| 41 | |
| 42 | Parcel data, reply; |
| 43 | |
| 44 | data.writeInterfaceToken(IDrmIOService::getInterfaceDescriptor()); |
| 45 | data.writeString8(filePath); |
| 46 | |
| 47 | remote()->transact(READ_FROM_FILE, data, &reply); |
| 48 | return reply.readString8(); |
| 49 | } |
| 50 | |
| 51 | IMPLEMENT_META_INTERFACE(DrmIOService, "drm.IDrmIOService"); |
| 52 | |
| 53 | status_t BnDrmIOService::onTransact( |
| 54 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) { |
| 55 | |
| 56 | switch (code) { |
| 57 | case WRITE_TO_FILE: |
| 58 | { |
| 59 | CHECK_INTERFACE(IDrmIOService, data, reply); |
| 60 | |
| 61 | writeToFile(data.readString8(), data.readString8()); |
| 62 | return DRM_NO_ERROR; |
| 63 | } |
| 64 | |
| 65 | case READ_FROM_FILE: |
| 66 | { |
| 67 | CHECK_INTERFACE(IDrmIOService, data, reply); |
| 68 | |
| 69 | String8 dataBuffer = readFromFile(data.readString8()); |
| 70 | reply->writeString8(dataBuffer); |
| 71 | return DRM_NO_ERROR; |
| 72 | } |
| 73 | |
| 74 | default: |
| 75 | return BBinder::onTransact(code, data, reply, flags); |
| 76 | } |
| 77 | } |
| 78 | |