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

Commit 9e1e3c79 authored by Wenyu Zhang's avatar Wenyu Zhang Committed by Android (Google) Code Review
Browse files

Merge "Add @AudioDeviceType IntDef to enhance type check" into main

parents 78bcaac3 bb0e420d
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -595,21 +595,22 @@ public final class AudioDeviceInfo {
    }

    /** @hide */
    public static int convertDeviceTypeToInternalDevice(int deviceType) {
    public static int convertDeviceTypeToInternalDevice(@AudioDeviceType int deviceType) {
        return EXT_TO_INT_DEVICE_MAPPING.get(deviceType, AudioSystem.DEVICE_NONE);
    }

    /** @hide */
    public static int convertInternalDeviceToDeviceType(int intDevice) {
    public static @AudioDeviceType int convertInternalDeviceToDeviceType(int intDevice) {
        return INT_TO_EXT_DEVICE_MAPPING.get(intDevice, TYPE_UNKNOWN);
    }

    /** @hide */
    public static int convertDeviceTypeToInternalInputDevice(int deviceType) {
    public static int convertDeviceTypeToInternalInputDevice(@AudioDeviceType int deviceType) {
        return convertDeviceTypeToInternalInputDevice(deviceType, "");
    }
    /** @hide */
    public static int convertDeviceTypeToInternalInputDevice(int deviceType, String address) {
    public static int convertDeviceTypeToInternalInputDevice(@AudioDeviceType int deviceType,
            String address) {
        int internalType = EXT_TO_INT_INPUT_DEVICE_MAPPING.get(deviceType, AudioSystem.DEVICE_NONE);
        if (internalType == AudioSystem.DEVICE_IN_BUILTIN_MIC
                && "back".equals(address)) {
+2 −1
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.media.AudioAttributes.AttributeSystemUsage;
import android.media.AudioDeviceInfo;
import android.media.CallbackUtil.ListenerInfo;
import android.media.audiopolicy.AudioPolicy;
import android.media.audiopolicy.AudioPolicy.AudioPolicyFocusListener;
@@ -8157,7 +8158,7 @@ public class AudioManager {
     * @hide
     */
    public static MicrophoneInfo microphoneInfoFromAudioDeviceInfo(AudioDeviceInfo deviceInfo) {
        int deviceType = deviceInfo.getType();
        @AudioDeviceInfo.AudioDeviceType 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
+2 −2
Original line number Diff line number Diff line
@@ -4253,8 +4253,8 @@ public final class TvInputManager {
         *        AudioFormat.CHANNEL_OUT_DEFAULT.
         * @param format desired format. Use default when it's AudioFormat.ENCODING_DEFAULT.
         */
        public void overrideAudioSink(int audioType, String audioAddress, int samplingRate,
                int channelMask, int format) {
        public void overrideAudioSink(@AudioDeviceInfo.AudioDeviceType int audioType,
                String audioAddress, int samplingRate, int channelMask, int format) {
            try {
                mInterface.overrideAudioSink(audioType, audioAddress, samplingRate, channelMask,
                        format);
+8 −4
Original line number Diff line number Diff line
@@ -541,7 +541,8 @@ public class AudioDeviceBroker {
        return device.isSink() && isValidCommunicationDeviceType(device.getType());
    }

    private static boolean isValidCommunicationDeviceType(int deviceType) {
    private static boolean isValidCommunicationDeviceType(
            @AudioDeviceInfo.AudioDeviceType int deviceType) {
        for (int type : VALID_COMMUNICATION_DEVICE_TYPES) {
            if (deviceType == type) {
                return true;
@@ -740,7 +741,8 @@ public class AudioDeviceBroker {
     * @param deviceType the device type the query applies to.
     * @return true if this device type is requested for communication.
     */
    private boolean isDeviceRequestedForCommunication(int deviceType) {
    private boolean isDeviceRequestedForCommunication(
            @AudioDeviceInfo.AudioDeviceType int deviceType) {
        synchronized (mDeviceStateLock) {
            AudioDeviceAttributes device = requestedCommunicationDevice();
            return device != null && device.getType() == deviceType;
@@ -754,7 +756,8 @@ public class AudioDeviceBroker {
     * @param deviceType the device type the query applies to.
     * @return true if this device type is requested for communication.
     */
    private boolean isDeviceOnForCommunication(int deviceType) {
    private boolean isDeviceOnForCommunication(
            @AudioDeviceInfo.AudioDeviceType int deviceType) {
        synchronized (mDeviceStateLock) {
            AudioDeviceAttributes device = preferredCommunicationDevice();
            return device != null && device.getType() == deviceType;
@@ -768,7 +771,8 @@ public class AudioDeviceBroker {
     * @param deviceType the device type the query applies to.
     * @return true if this device type is requested for communication.
     */
    private boolean isDeviceActiveForCommunication(int deviceType) {
    private boolean isDeviceActiveForCommunication(
            @AudioDeviceInfo.AudioDeviceType int deviceType) {
        return mActiveCommunicationDevice != null
                && mActiveCommunicationDevice.getType() == deviceType
                && mPreferredCommunicationDevice != null
+4 −3
Original line number Diff line number Diff line
@@ -442,7 +442,7 @@ import java.util.Objects;
    @Nullable
    private MediaRoute2Info createMediaRoute2Info(
            @Nullable String routeId,
            int audioDeviceInfoType,
            @AudioDeviceInfo.AudioDeviceType int audioDeviceInfoType,
            @Nullable CharSequence deviceName,
            @Nullable String address) {
        SystemRouteInfo systemRouteInfo =
@@ -490,7 +490,8 @@ import java.util.Objects;
        public final boolean mCorrespondsToInactiveBluetoothRoute;

        public static MediaRoute2InfoHolder createForAudioManagerRoute(
                MediaRoute2Info mediaRoute2Info, int audioDeviceInfoType) {
                MediaRoute2Info mediaRoute2Info,
                @AudioDeviceInfo.AudioDeviceType int audioDeviceInfoType) {
            return new MediaRoute2InfoHolder(
                    mediaRoute2Info,
                    audioDeviceInfoType,
@@ -509,7 +510,7 @@ import java.util.Objects;

        private MediaRoute2InfoHolder(
                MediaRoute2Info mediaRoute2Info,
                int audioDeviceInfoType,
                @AudioDeviceInfo.AudioDeviceType int audioDeviceInfoType,
                boolean correspondsToInactiveBluetoothRoute) {
            mMediaRoute2Info = mediaRoute2Info;
            mAudioDeviceInfoType = audioDeviceInfoType;
Loading