Refactored base code to getDeviceForPortId
Refactored base code to use AudioManager.getDeviceForPortId where possible: AudioRecorder MediaRecorder AudioTrack MediaPlayer AudioPlaybackConfiguration AudioRecordingConfiguration Bug: 175802592 Test: atest AudioPlaybackConfiguration Test: atest AudioRecordingConfiguration Test: atest AudioRecorderTest Test: atest MediaRecorderTest Change-Id: I15dfcd587fdc732e666a6dfec0de82f80512dad7
This commit is contained in:
@@ -298,15 +298,7 @@ public final class AudioPlaybackConfiguration implements Parcelable {
|
||||
if (mDeviceId == PLAYER_DEVICEID_INVALID) {
|
||||
return null;
|
||||
}
|
||||
// TODO(175802592): change this to AudioManager.getDeviceForPortId() when available
|
||||
AudioDeviceInfo[] devices =
|
||||
AudioManager.getDevicesStatic(AudioManager.GET_DEVICES_OUTPUTS);
|
||||
for (int i = 0; i < devices.length; i++) {
|
||||
if (devices[i].getId() == mDeviceId) {
|
||||
return devices[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return AudioManager.getDeviceForPortId(mDeviceId, AudioManager.GET_DEVICES_OUTPUTS);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1578,14 +1578,7 @@ public class AudioRecord implements AudioRouting, MicrophoneDirection,
|
||||
if (deviceId == 0) {
|
||||
return null;
|
||||
}
|
||||
AudioDeviceInfo[] devices =
|
||||
AudioManager.getDevicesStatic(AudioManager.GET_DEVICES_INPUTS);
|
||||
for (int i = 0; i < devices.length; i++) {
|
||||
if (devices[i].getId() == deviceId) {
|
||||
return devices[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return AudioManager.getDeviceForPortId(deviceId, AudioManager.GET_DEVICES_INPUTS);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -262,14 +262,8 @@ public final class AudioRecordingConfiguration implements Parcelable {
|
||||
final AudioPortConfig[] sources = patch.sources();
|
||||
if ((sources != null) && (sources.length > 0)) {
|
||||
// not supporting multiple sources, so just look at the first source
|
||||
final int devId = sources[0].port().id();
|
||||
final AudioDeviceInfo[] devices =
|
||||
AudioManager.getDevicesStatic(AudioManager.GET_DEVICES_INPUTS);
|
||||
for (int j = 0; j < devices.length; j++) {
|
||||
if (devices[j].getId() == devId) {
|
||||
return devices[j];
|
||||
}
|
||||
}
|
||||
int devId = sources[0].port().id();
|
||||
return AudioManager.getDeviceForPortId(devId, AudioManager.GET_DEVICES_INPUTS);
|
||||
}
|
||||
// patch handle is unique, there won't be another with the same handle
|
||||
break;
|
||||
|
||||
@@ -3493,14 +3493,7 @@ public class AudioTrack extends PlayerBase
|
||||
if (deviceId == 0) {
|
||||
return null;
|
||||
}
|
||||
AudioDeviceInfo[] devices =
|
||||
AudioManager.getDevicesStatic(AudioManager.GET_DEVICES_OUTPUTS);
|
||||
for (int i = 0; i < devices.length; i++) {
|
||||
if (devices[i].getId() == deviceId) {
|
||||
return devices[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return AudioManager.getDeviceForPortId(deviceId, AudioManager.GET_DEVICES_OUTPUTS);
|
||||
}
|
||||
|
||||
private void tryToDisableNativeRoutingCallback() {
|
||||
|
||||
@@ -1484,14 +1484,7 @@ public class MediaPlayer extends PlayerBase
|
||||
if (deviceId == 0) {
|
||||
return null;
|
||||
}
|
||||
AudioDeviceInfo[] devices =
|
||||
AudioManager.getDevicesStatic(AudioManager.GET_DEVICES_OUTPUTS);
|
||||
for (int i = 0; i < devices.length; i++) {
|
||||
if (devices[i].getId() == deviceId) {
|
||||
return devices[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return AudioManager.getDeviceForPortId(deviceId, AudioManager.GET_DEVICES_OUTPUTS);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1507,14 +1507,7 @@ public class MediaRecorder implements AudioRouting,
|
||||
if (deviceId == 0) {
|
||||
return null;
|
||||
}
|
||||
AudioDeviceInfo[] devices =
|
||||
AudioManager.getDevicesStatic(AudioManager.GET_DEVICES_INPUTS);
|
||||
for (int i = 0; i < devices.length; i++) {
|
||||
if (devices[i].getId() == deviceId) {
|
||||
return devices[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return AudioManager.getDeviceForPortId(deviceId, AudioManager.GET_DEVICES_INPUTS);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user