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