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

Commit 589a236a authored by jiabin's avatar jiabin
Browse files

Add information of microphone on peripheral for mic enumeration APIs.

Bug: 64038649
Test: run cts
Change-Id: If66747359b6544d239898fc16fbf1d99002b6402
parent f2c32815
Loading
Loading
Loading
Loading
+7 −1
Original line number Original line Diff line number Diff line
@@ -24573,13 +24573,19 @@ package android.media {
    field public static final int DIRECTIONALITY_OMNI = 1; // 0x1
    field public static final int DIRECTIONALITY_OMNI = 1; // 0x1
    field public static final int DIRECTIONALITY_SUPER_CARDIOID = 5; // 0x5
    field public static final int DIRECTIONALITY_SUPER_CARDIOID = 5; // 0x5
    field public static final int DIRECTIONALITY_UNKNOWN = 0; // 0x0
    field public static final int DIRECTIONALITY_UNKNOWN = 0; // 0x0
    field public static final int GROUP_UNKNOWN = -1; // 0xffffffff
    field public static final int INDEX_IN_THE_GROUP_UNKNOWN = -1; // 0xffffffff
    field public static final int LOCATION_MAINBODY = 1; // 0x1
    field public static final int LOCATION_MAINBODY = 1; // 0x1
    field public static final int LOCATION_MAINBODY_MOVABLE = 2; // 0x2
    field public static final int LOCATION_MAINBODY_MOVABLE = 2; // 0x2
    field public static final int LOCATION_PERIPHERAL = 3; // 0x3
    field public static final int LOCATION_PERIPHERAL = 3; // 0x3
    field public static final int LOCATION_UNKNOWN = 0; // 0x0
    field public static final int LOCATION_UNKNOWN = 0; // 0x0
    field public static final android.media.MicrophoneInfo.Coordinate3F ORIENTATION_UNKNOWN;
    field public static final android.media.MicrophoneInfo.Coordinate3F POSITION_UNKNOWN;
    field public static final float SENSITIVITY_UNKNOWN = -3.4028235E38f;
    field public static final float SPL_UNKNOWN = -3.4028235E38f;
  }
  }
  public class MicrophoneInfo.Coordinate3F {
  public static final class MicrophoneInfo.Coordinate3F {
    field public final float x;
    field public final float x;
    field public final float y;
    field public final float y;
    field public final float z;
    field public final float z;
+1 −3
Original line number Original line Diff line number Diff line
@@ -65,13 +65,11 @@ jint convertMicrophoneInfoFromNative(JNIEnv *env, jobject *jMicrophoneInfo,
    }
    }
    jGeometricLocation = env->NewObject(gMicrophoneInfoCoordinateClass,
    jGeometricLocation = env->NewObject(gMicrophoneInfoCoordinateClass,
                                        gMicrophoneInfoCoordinateCstor,
                                        gMicrophoneInfoCoordinateCstor,
                                        NULL,
                                        microphoneInfo->getGeometricLocation()[0],
                                        microphoneInfo->getGeometricLocation()[0],
                                        microphoneInfo->getGeometricLocation()[1],
                                        microphoneInfo->getGeometricLocation()[1],
                                        microphoneInfo->getGeometricLocation()[2]);
                                        microphoneInfo->getGeometricLocation()[2]);
    jOrientation = env->NewObject(gMicrophoneInfoCoordinateClass,
    jOrientation = env->NewObject(gMicrophoneInfoCoordinateClass,
                                  gMicrophoneInfoCoordinateCstor,
                                  gMicrophoneInfoCoordinateCstor,
                                  NULL,
                                  microphoneInfo->getOrientation()[0],
                                  microphoneInfo->getOrientation()[0],
                                  microphoneInfo->getOrientation()[1],
                                  microphoneInfo->getOrientation()[1],
                                  microphoneInfo->getOrientation()[2]);
                                  microphoneInfo->getOrientation()[2]);
@@ -177,7 +175,7 @@ int register_android_media_MicrophoneInfo(JNIEnv *env)
            env, "android/media/MicrophoneInfo$Coordinate3F");
            env, "android/media/MicrophoneInfo$Coordinate3F");
    gMicrophoneInfoCoordinateClass = MakeGlobalRefOrDie(env, microphoneInfoCoordinateClass);
    gMicrophoneInfoCoordinateClass = MakeGlobalRefOrDie(env, microphoneInfoCoordinateClass);
    gMicrophoneInfoCoordinateCstor = GetMethodIDOrDie(env, microphoneInfoCoordinateClass, "<init>",
    gMicrophoneInfoCoordinateCstor = GetMethodIDOrDie(env, microphoneInfoCoordinateClass, "<init>",
           "(Landroid/media/MicrophoneInfo;FFF)V");
           "(FFF)V");


    jclass pairClass = FindClassOrDie(env, "android/util/Pair");
    jclass pairClass = FindClassOrDie(env, "android/util/Pair");
    gPairClass = MakeGlobalRefOrDie(env, pairClass);
    gPairClass = MakeGlobalRefOrDie(env, pairClass);
+32 −0
Original line number Original line Diff line number Diff line
@@ -53,6 +53,7 @@ import android.provider.Settings;
import android.text.TextUtils;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.ArrayMap;
import android.util.Log;
import android.util.Log;
import android.util.Pair;
import android.util.Slog;
import android.util.Slog;
import android.view.KeyEvent;
import android.view.KeyEvent;


@@ -4768,6 +4769,28 @@ public class AudioManager {
        }
        }
    }
    }


    /**
     * Convert {@link AudioDeviceInfo} to {@link MicrophoneInfo}.
     * @hide
     */
    public static MicrophoneInfo microphoneInfoFromAudioDeviceInfo(AudioDeviceInfo deviceInfo) {
        int deviceType = deviceInfo.getType();
        int micLocation = (deviceType == AudioDeviceInfo.TYPE_BUILTIN_MIC
                || deviceType == AudioDeviceInfo.TYPE_TELEPHONY) ? MicrophoneInfo.LOCATION_MAINBODY
                : deviceType == AudioDeviceInfo.TYPE_UNKNOWN ? MicrophoneInfo.LOCATION_UNKNOWN
                        : MicrophoneInfo.LOCATION_PERIPHERAL;
        MicrophoneInfo microphone = new MicrophoneInfo(
                deviceInfo.getPort().name() + deviceInfo.getId(),
                deviceInfo.getPort().type(), deviceInfo.getAddress(), micLocation,
                MicrophoneInfo.GROUP_UNKNOWN, MicrophoneInfo.INDEX_IN_THE_GROUP_UNKNOWN,
                MicrophoneInfo.POSITION_UNKNOWN, MicrophoneInfo.ORIENTATION_UNKNOWN,
                new ArrayList<Pair<Float, Float>>(), new ArrayList<Pair<Integer, Integer>>(),
                MicrophoneInfo.SENSITIVITY_UNKNOWN, MicrophoneInfo.SPL_UNKNOWN,
                MicrophoneInfo.SPL_UNKNOWN, MicrophoneInfo.DIRECTIONALITY_UNKNOWN);
        microphone.setId(deviceInfo.getId());
        return microphone;
    }

    /**
    /**
     * Returns a list of {@link MicrophoneInfo} that corresponds to the characteristics
     * Returns a list of {@link MicrophoneInfo} that corresponds to the characteristics
     * of all available microphones. The list is empty when no microphones are available
     * of all available microphones. The list is empty when no microphones are available
@@ -4785,6 +4808,15 @@ public class AudioManager {
            return new ArrayList<MicrophoneInfo>(); // Always return a list.
            return new ArrayList<MicrophoneInfo>(); // Always return a list.
        }
        }
        setPortIdForMicrophones(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);
        }
        return microphones;
        return microphones;
    }
    }


+15 −0
Original line number Original line Diff line number Diff line
@@ -41,6 +41,7 @@ import android.os.ServiceManager;
import android.text.TextUtils;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.ArrayMap;
import android.util.Log;
import android.util.Log;
import android.util.Pair;


import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.GuardedBy;


@@ -1630,6 +1631,20 @@ public class AudioRecord implements AudioRouting
            return new ArrayList<MicrophoneInfo>();
            return new ArrayList<MicrophoneInfo>();
        }
        }
        AudioManager.setPortIdForMicrophones(activeMicrophones);
        AudioManager.setPortIdForMicrophones(activeMicrophones);

        // Use routed device when there is not information returned by hal.
        if (activeMicrophones.size() == 0) {
            AudioDeviceInfo device = getRoutedDevice();
            if (device != null) {
                MicrophoneInfo microphone = AudioManager.microphoneInfoFromAudioDeviceInfo(device);
                ArrayList<Pair<Integer, Integer>> channelMapping = new ArrayList<>();
                for (int i = 0; i < mChannelCount; i++) {
                    channelMapping.add(new Pair(i, MicrophoneInfo.CHANNEL_MAPPING_DIRECT));
                }
                microphone.setChannelMapping(channelMapping);
                activeMicrophones.add(microphone);
            }
        }
        return activeMicrophones;
        return activeMicrophones;
    }
    }


+19 −0
Original line number Original line Diff line number Diff line
@@ -29,6 +29,7 @@ import android.os.PersistableBundle;
import android.text.TextUtils;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.ArrayMap;
import android.util.Log;
import android.util.Log;
import android.util.Pair;
import android.view.Surface;
import android.view.Surface;


import java.io.File;
import java.io.File;
@@ -105,6 +106,8 @@ public class MediaRecorder implements AudioRouting
    private OnErrorListener mOnErrorListener;
    private OnErrorListener mOnErrorListener;
    private OnInfoListener mOnInfoListener;
    private OnInfoListener mOnInfoListener;


    private int mChannelCount;

    /**
    /**
     * Default constructor.
     * Default constructor.
     */
     */
@@ -119,6 +122,7 @@ public class MediaRecorder implements AudioRouting
            mEventHandler = null;
            mEventHandler = null;
        }
        }


        mChannelCount = 1;
        String packageName = ActivityThread.currentPackageName();
        String packageName = ActivityThread.currentPackageName();
        /* Native setup requires a weak reference to our object.
        /* Native setup requires a weak reference to our object.
         * It's easier to create it here than in C++.
         * It's easier to create it here than in C++.
@@ -755,6 +759,7 @@ public class MediaRecorder implements AudioRouting
        if (numChannels <= 0) {
        if (numChannels <= 0) {
            throw new IllegalArgumentException("Number of channels is not positive");
            throw new IllegalArgumentException("Number of channels is not positive");
        }
        }
        mChannelCount = numChannels;
        setParameter("audio-param-number-of-channels=" + numChannels);
        setParameter("audio-param-number-of-channels=" + numChannels);
    }
    }


@@ -1432,6 +1437,20 @@ public class MediaRecorder implements AudioRouting
            return new ArrayList<MicrophoneInfo>();
            return new ArrayList<MicrophoneInfo>();
        }
        }
        AudioManager.setPortIdForMicrophones(activeMicrophones);
        AudioManager.setPortIdForMicrophones(activeMicrophones);

        // Use routed device when there is not information returned by hal.
        if (activeMicrophones.size() == 0) {
            AudioDeviceInfo device = getRoutedDevice();
            if (device != null) {
                MicrophoneInfo microphone = AudioManager.microphoneInfoFromAudioDeviceInfo(device);
                ArrayList<Pair<Integer, Integer>> channelMapping = new ArrayList<>();
                for (int i = 0; i < mChannelCount; i++) {
                    channelMapping.add(new Pair(i, MicrophoneInfo.CHANNEL_MAPPING_DIRECT));
                }
                microphone.setChannelMapping(channelMapping);
                activeMicrophones.add(microphone);
            }
        }
        return activeMicrophones;
        return activeMicrophones;
    }
    }


Loading