1 /* 2 * Copyright 2017 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.mobileer.oboetester; 18 19 import android.content.pm.PackageManager; 20 import android.media.AudioManager; 21 import android.os.Build; 22 23 import java.io.BufferedReader; 24 import java.io.IOException; 25 import java.io.InputStreamReader; 26 import java.util.Locale; 27 28 public class AudioQueryTools { 29 private static String GETPROP_EXECUTABLE_PATH = "/system/bin/getprop"; 30 getSystemProperty(String propName)31 public static String getSystemProperty(String propName) { 32 Process process = null; 33 BufferedReader bufferedReader = null; 34 try { 35 process = new ProcessBuilder().command(GETPROP_EXECUTABLE_PATH, propName).redirectErrorStream(true).start(); 36 bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); 37 String line = bufferedReader.readLine(); 38 if (line == null){ 39 line = ""; //prop not set 40 } 41 return line; 42 } catch (Exception e) { 43 return ""; 44 } finally{ 45 if (bufferedReader != null){ 46 try { 47 bufferedReader.close(); 48 } catch (IOException e) {} 49 } 50 if (process != null){ 51 process.destroy(); 52 } 53 } 54 } 55 getAudioFeatureReport(PackageManager packageManager)56 public static String getAudioFeatureReport(PackageManager packageManager) { 57 StringBuffer report = new StringBuffer(); 58 report.append("\nProAudio Feature : " 59 + packageManager.hasSystemFeature(PackageManager.FEATURE_AUDIO_PRO)); 60 report.append("\nLowLatency Feature : " 61 + packageManager.hasSystemFeature(PackageManager.FEATURE_AUDIO_LOW_LATENCY)); 62 report.append("\nAudio Output Feature : " 63 + packageManager.hasSystemFeature(PackageManager.FEATURE_AUDIO_OUTPUT)); 64 report.append("\nMicrophone Feature : " 65 + packageManager.hasSystemFeature(PackageManager.FEATURE_MICROPHONE)); 66 report.append("\nMIDI Feature : " 67 + packageManager.hasSystemFeature(PackageManager.FEATURE_MIDI)); 68 report.append("\nUSB Host Feature : " 69 + packageManager.hasSystemFeature(PackageManager.FEATURE_USB_HOST)); 70 report.append("\nUSB Accessory Feature: " 71 + packageManager.hasSystemFeature(PackageManager.FEATURE_USB_ACCESSORY)); 72 return report.toString(); 73 } 74 getAudioManagerReport(AudioManager audioManager)75 public static String getAudioManagerReport(AudioManager audioManager) { 76 StringBuffer report = new StringBuffer(); 77 String unprocessedSupport = audioManager.getProperty( 78 AudioManager.PROPERTY_SUPPORT_AUDIO_SOURCE_UNPROCESSED); 79 report.append("\nSUPPORT_AUDIO_SOURCE_UNPROCESSED : " + ((unprocessedSupport == null) ? 80 "null" : unprocessedSupport)); 81 String outputFramesPerBuffer = audioManager.getProperty( 82 AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER); 83 report.append("\nOUTPUT_FRAMES_PER_BUFFER : " + ((outputFramesPerBuffer == null) ? 84 "null" : outputFramesPerBuffer)); 85 String outputSampleRate = audioManager.getProperty( 86 AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE); 87 report.append("\nOUTPUT_SAMPLE_RATE : " + ((outputSampleRate == null) ? "null" : 88 outputSampleRate)); 89 return report.toString(); 90 } 91 formatKeyValueLine(String key, String value)92 private static String formatKeyValueLine(String key, String value) { 93 int numSpaces = Math.max(1, 21 - key.length()); 94 String spaces = String.format(Locale.getDefault(), "%0" + numSpaces + "d", 0).replace("0", " "); 95 return "\n" + key + spaces + ": " + value; 96 } 97 getSystemPropertyLine(String key)98 private static String getSystemPropertyLine(String key) { 99 return formatKeyValueLine(key, getSystemProperty(key)); 100 } 101 convertSdkToShortName(int sdk)102 public static String convertSdkToShortName(int sdk) { 103 if (sdk < 16) return "early"; 104 if (sdk > 34) return "future"; 105 final String[] names = { 106 "J", // 16 107 "J+", 108 "J++", 109 "K", 110 "K+", 111 "L", // 21 112 "L+", 113 "M", 114 "N", // 24 115 "N_MR1", 116 "O", 117 "O_MR1", 118 "P", // 28 119 "Q", 120 "R", 121 "S", 122 "S_V2", 123 "T", // 33 124 "U" 125 }; 126 return names[sdk - 16]; 127 } 128 getMediaPerformanceClass()129 public static String getMediaPerformanceClass() { 130 if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.S) { 131 return formatKeyValueLine("Media Perf Class", "not supported"); 132 } 133 int mpc = Build.VERSION.MEDIA_PERFORMANCE_CLASS; 134 String text = (mpc == 0) ? "not declared" : convertSdkToShortName(mpc); 135 return formatKeyValueLine("Media Perf Class", 136 mpc + " (" + text + ")"); 137 } 138 getAudioPropertyReport()139 public static String getAudioPropertyReport() { 140 StringBuffer report = new StringBuffer(); 141 report.append(getSystemPropertyLine("aaudio.mmap_policy")); 142 report.append(getSystemPropertyLine("aaudio.mmap_exclusive_policy")); 143 report.append(getSystemPropertyLine("aaudio.mixer_bursts")); 144 report.append(getSystemPropertyLine("aaudio.wakeup_delay_usec")); 145 report.append(getSystemPropertyLine("aaudio.minimum_sleep_usec")); 146 report.append(getSystemPropertyLine("aaudio.hw_burst_min_usec")); 147 report.append(getSystemPropertyLine("aaudio.in_mmap_offset_usec")); 148 report.append(getSystemPropertyLine("aaudio.out_mmap_offset_usec")); 149 report.append(getSystemPropertyLine("ro.product.manufacturer")); 150 report.append(getSystemPropertyLine("ro.product.brand")); 151 report.append(getSystemPropertyLine("ro.product.model")); 152 report.append(getSystemPropertyLine("ro.product.name")); 153 report.append(getSystemPropertyLine("ro.product.device")); 154 report.append(getSystemPropertyLine("ro.product.cpu.abi")); 155 report.append(getSystemPropertyLine("ro.soc.manufacturer")); 156 report.append(getSystemPropertyLine("ro.soc.model")); 157 report.append(getSystemPropertyLine("ro.arch")); 158 report.append(getSystemPropertyLine("ro.hardware")); 159 report.append(getSystemPropertyLine("ro.hardware.chipname")); 160 report.append(getSystemPropertyLine("ro.board.platform")); 161 report.append(getSystemPropertyLine("ro.build.changelist")); 162 report.append(getSystemPropertyLine("ro.build.description")); 163 return report.toString(); 164 } 165 } 166