blob: f320d0bb7651830d2385a4529b0017f8b6b17f68 [file] [log] [blame]
Jeff Tinkera69729d2016-02-12 08:47:00 -08001/*
2**
3** Copyright 2015, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#include <stdint.h>
19#include <sys/types.h>
20
21#include <binder/Parcel.h>
22#include <binder/IMemory.h>
Jeff Tinker7d2c6e82018-02-16 16:14:59 -080023#include <mediadrm/ICrypto.h>
24#include <mediadrm/IDrm.h>
25#include <mediadrm/IMediaDrmService.h>
Jeff Tinkera69729d2016-02-12 08:47:00 -080026
27#include <utils/Errors.h> // for status_t
28#include <utils/String8.h>
29
30namespace android {
31
32enum {
33 MAKE_CRYPTO = IBinder::FIRST_CALL_TRANSACTION,
34 MAKE_DRM,
35};
36
37class BpMediaDrmService: public BpInterface<IMediaDrmService>
38{
39public:
Chih-Hung Hsieh64a28702016-05-03 09:52:51 -070040 explicit BpMediaDrmService(const sp<IBinder>& impl)
Jeff Tinkera69729d2016-02-12 08:47:00 -080041 : BpInterface<IMediaDrmService>(impl)
42 {
43 }
44
45 virtual sp<ICrypto> makeCrypto() {
46 Parcel data, reply;
47 data.writeInterfaceToken(IMediaDrmService::getInterfaceDescriptor());
48 remote()->transact(MAKE_CRYPTO, data, &reply);
49 return interface_cast<ICrypto>(reply.readStrongBinder());
50 }
51
52 virtual sp<IDrm> makeDrm() {
53 Parcel data, reply;
54 data.writeInterfaceToken(IMediaDrmService::getInterfaceDescriptor());
55 remote()->transact(MAKE_DRM, data, &reply);
56 return interface_cast<IDrm>(reply.readStrongBinder());
57 }
58
59};
60
61IMPLEMENT_META_INTERFACE(MediaDrmService, "android.media.IMediaDrmService");
62
63// ----------------------------------------------------------------------
64
65status_t BnMediaDrmService::onTransact(
66 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
67{
68 switch (code) {
69 case MAKE_CRYPTO: {
70 CHECK_INTERFACE(IMediaDrmService, data, reply);
71 sp<ICrypto> crypto = makeCrypto();
72 reply->writeStrongBinder(IInterface::asBinder(crypto));
73 return NO_ERROR;
74 } break;
75 case MAKE_DRM: {
76 CHECK_INTERFACE(IMediaDrmService, data, reply);
77 sp<IDrm> drm = makeDrm();
78 reply->writeStrongBinder(IInterface::asBinder(drm));
79 return NO_ERROR;
80 } break;
81 default:
82 return BBinder::onTransact(code, data, reply, flags);
83 }
84}
85
86// ----------------------------------------------------------------------------
87
88} // namespace android