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 17 package com.android.tests.apex; 18 19 import static org.junit.Assert.assertEquals; 20 import static org.junit.Assert.assertTrue; 21 22 import com.android.tradefed.device.DeviceNotAvailableException; 23 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; 24 import com.android.tradefed.util.CommandResult; 25 26 import org.junit.runner.RunWith; 27 28 import java.util.Scanner; 29 import java.util.regex.Matcher; 30 import java.util.regex.Pattern; 31 32 /** 33 * Test to check if Apex can be staged, activated and uninstalled successfully. 34 */ 35 @RunWith(DeviceJUnit4ClassRunner.class) 36 public class MediaHostTest extends ApexE2EBaseHostTest { 37 // Pattern for extractor info in dumpsys media.extractor. e.g.: 38 // AAC Extractor: plugin_version(3), uuid(4fd80eae03d24d729eb948fa6bb54613), \ 39 // version(1), path(/apex/com.android.media/lib/extractors/libaacextractor.so), \ 40 // supports: aac 41 private static final Pattern EXTRACTOR_PLUGIN_REGEX = 42 Pattern.compile("\\s+(.*): plugin_version\\((\\d+)\\), uuid\\((.+)\\)" 43 + ", version\\((\\d+)\\), path\\((.+)\\), supports: (.*)"); 44 private static final int DEFAULT_EXTRACTOR_PLUGIN_COUNT = 10; 45 private static final String MEDIA_APEX_PATH = "/apex/com.android.media"; 46 47 @Override additionalCheck()48 public void additionalCheck() { 49 checkMediaExtractor(); 50 } 51 checkMediaExtractor()52 private void checkMediaExtractor() { 53 try { 54 CommandResult commandResult = 55 getDevice().executeShellV2Command("dumpsys media.extractor"); 56 assertEquals(0, (int) commandResult.getExitCode()); 57 58 String outputString = commandResult.getStdout(); 59 Scanner in = new Scanner(outputString); 60 int extractorCount = 0; 61 while (in.hasNextLine()) { 62 String line = in.nextLine(); 63 Matcher m = EXTRACTOR_PLUGIN_REGEX.matcher(line); 64 if (m.matches()) { 65 assertTrue("Plugin path does not start with " + MEDIA_APEX_PATH 66 + ". dumpsys output: " + line, 67 m.group(5).startsWith(MEDIA_APEX_PATH)); 68 extractorCount++; 69 } 70 } 71 assertTrue("Failed to find enough plug-ins. expected: " + DEFAULT_EXTRACTOR_PLUGIN_COUNT 72 + " actual: " + extractorCount + " dumpsys output: " + outputString, 73 DEFAULT_EXTRACTOR_PLUGIN_COUNT <= extractorCount); 74 } catch (DeviceNotAvailableException e) { 75 throw new AssertionError("Unable to run dumpsys", e); 76 } 77 } 78 } 79