Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d0be5b21 authored by jiabin's avatar jiabin
Browse files

Fix mic enumeration CTS fail on marlin.

The mic enumeration APIs only support on audio hal v4. Marlin failed due
to on audio hal v2. Make the APIs return mic with unknown
characteristics if the native call fail.

Bug: 77732156
Bug: 77732289
Test: run cts on marlin and walleye
Change-Id: I64b3e6a249ad76b754e841d630e8cf178dde9a86
parent 806be6b6
Loading
Loading
Loading
Loading
+23 −11
Original line number Diff line number Diff line
@@ -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;
    }

+0 −1
Original line number Diff line number Diff line
@@ -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);

+0 −1
Original line number Diff line number Diff line
@@ -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);