blob: 020c0634333ae08f1864b61c4864e1125c60ae57 [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
Jeff Tinkera69729d2016-02-12 08:47:00 -080045 virtual sp<IDrm> makeDrm() {
46 Parcel data, reply;
47 data.writeInterfaceToken(IMediaDrmService::getInterfaceDescriptor());
48 remote()->transact(MAKE_DRM, data, &reply);
49 return interface_cast<IDrm>(reply.readStrongBinder());
50 }
51
52};
53
54IMPLEMENT_META_INTERFACE(MediaDrmService, "android.media.IMediaDrmService");
55
56// ----------------------------------------------------------------------
57
58status_t BnMediaDrmService::onTransact(
59 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
60{
61 switch (code) {
Jeff Tinkera69729d2016-02-12 08:47:00 -080062 case MAKE_DRM: {
63 CHECK_INTERFACE(IMediaDrmService, data, reply);
64 sp<IDrm> drm = makeDrm();
65 reply->writeStrongBinder(IInterface::asBinder(drm));
66 return NO_ERROR;
67 } break;
68 default:
69 return BBinder::onTransact(code, data, reply, flags);
70 }
71}
72
73// ----------------------------------------------------------------------------
74
Robert Shih28c2ed32019-10-27 22:55:12 -070075template<>
76sp<IDrm> IMediaDrmService::makeObject<IDrm>() {
77 return makeDrm();
78}
79
Jeff Tinkera69729d2016-02-12 08:47:00 -080080} // namespace android