Merge "Fix mic enumeration CTS fail on marlin." into pi-dev
am: 0b5dd8e560
Change-Id: I681eb47ec1577ad6c2b35d0e739c249bf61f0f26
This commit is contained in:
@@ -63,6 +63,7 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -4785,6 +4786,21 @@ public class AudioManager {
|
||||
return microphone;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add {@link MicrophoneInfo} by device information while filtering certain types.
|
||||
*/
|
||||
private void addMicrophonesFromAudioDeviceInfo(ArrayList<MicrophoneInfo> microphones,
|
||||
HashSet<Integer> filterTypes) {
|
||||
AudioDeviceInfo[] devices = getDevicesStatic(GET_DEVICES_INPUTS);
|
||||
for (AudioDeviceInfo device : devices) {
|
||||
if (filterTypes.contains(device.getType())) {
|
||||
continue;
|
||||
}
|
||||
MicrophoneInfo microphone = microphoneInfoFromAudioDeviceInfo(device);
|
||||
microphones.add(microphone);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of {@link MicrophoneInfo} that corresponds to the characteristics
|
||||
* of all available microphones. The list is empty when no microphones are available
|
||||
@@ -4796,21 +4812,17 @@ public class AudioManager {
|
||||
public List<MicrophoneInfo> getMicrophones() throws IOException {
|
||||
ArrayList<MicrophoneInfo> microphones = new ArrayList<MicrophoneInfo>();
|
||||
int status = AudioSystem.getMicrophones(microphones);
|
||||
HashSet<Integer> filterTypes = new HashSet<>();
|
||||
filterTypes.add(AudioDeviceInfo.TYPE_TELEPHONY);
|
||||
if (status != AudioManager.SUCCESS) {
|
||||
// fail and bail!
|
||||
// fail and populate microphones with unknown characteristics by device information.
|
||||
Log.e(TAG, "getMicrophones failed:" + status);
|
||||
return new ArrayList<MicrophoneInfo>(); // Always return a list.
|
||||
addMicrophonesFromAudioDeviceInfo(microphones, filterTypes);
|
||||
return microphones;
|
||||
}
|
||||
setPortIdForMicrophones(microphones);
|
||||
AudioDeviceInfo[] devices = getDevicesStatic(GET_DEVICES_INPUTS);
|
||||
for (AudioDeviceInfo device : devices) {
|
||||
if (device.getType() == AudioDeviceInfo.TYPE_BUILTIN_MIC ||
|
||||
device.getType() == AudioDeviceInfo.TYPE_TELEPHONY) {
|
||||
continue;
|
||||
}
|
||||
MicrophoneInfo microphone = microphoneInfoFromAudioDeviceInfo(device);
|
||||
microphones.add(microphone);
|
||||
}
|
||||
filterTypes.add(AudioDeviceInfo.TYPE_BUILTIN_MIC);
|
||||
addMicrophonesFromAudioDeviceInfo(microphones, filterTypes);
|
||||
return microphones;
|
||||
}
|
||||
|
||||
|
||||
@@ -1628,7 +1628,6 @@ public class AudioRecord implements AudioRouting
|
||||
int status = native_get_active_microphones(activeMicrophones);
|
||||
if (status != AudioManager.SUCCESS) {
|
||||
Log.e(TAG, "getActiveMicrophones failed:" + status);
|
||||
return new ArrayList<MicrophoneInfo>();
|
||||
}
|
||||
AudioManager.setPortIdForMicrophones(activeMicrophones);
|
||||
|
||||
|
||||
@@ -1434,7 +1434,6 @@ public class MediaRecorder implements AudioRouting
|
||||
int status = native_getActiveMicrophones(activeMicrophones);
|
||||
if (status != AudioManager.SUCCESS) {
|
||||
Log.e(TAG, "getActiveMicrophones failed:" + status);
|
||||
return new ArrayList<MicrophoneInfo>();
|
||||
}
|
||||
AudioManager.setPortIdForMicrophones(activeMicrophones);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user