1 /*
2  * Copyright (C) 2020 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 package com.android.devicehealthchecks;
17 
18 import android.media.MediaCodec;
19 import android.media.MediaCodecInfo;
20 import android.media.MediaCodecList;
21 
22 import org.junit.Assert;
23 import org.junit.Test;
24 
25 /*
26  * Tests used for basic media validation after the device boot is completed.
27  * This test is used for global presubmit.
28  */
29 // TODO: @GlobalPresubmit
30 public class MediaBootCheck {
31     /*
32      * Test if codecs are listed and instantiable.
33      */
34     @Test
checkCodecList()35     public void checkCodecList() throws Exception {
36         /*
37          * This is a simple test that checks the following:
38          * 1) MediaCodecList is not empty
39          * 2) The codecs listed can be created
40          */
41         MediaCodecList list = new MediaCodecList(MediaCodecList.ALL_CODECS);
42         MediaCodecInfo[] infos = list.getCodecInfos();
43         Assert.assertTrue("MediaCodecList should not be empty", infos.length > 0);
44         for (MediaCodecInfo info : infos) {
45             MediaCodec codec = null;
46             try {
47                 codec = MediaCodec.createByCodecName(info.getName());
48                 // Basic checks.
49                 Assert.assertEquals(codec.getName(), info.getName());
50                 Assert.assertEquals(codec.getCanonicalName(), info.getCanonicalName());
51             } finally {
52                 if (codec != null) {
53                     codec.release();
54                 }
55             }
56         }
57     }
58 }
59