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

Commit eada8716 authored by Andy Hung's avatar Andy Hung Committed by Automerger Merge Worker
Browse files

Merge "Use device set for getDevicesForStream" into tm-dev am: c640ee83

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/17030564

Change-Id: Idc759c906b1df7ea2a24a6b18fb83c4fae0e8df1
parents 73fb6d62 c640ee83
Loading
Loading
Loading
Loading
+0 −8
Original line number Original line Diff line number Diff line
@@ -828,13 +828,6 @@ android_media_AudioSystem_getMasterBalance(JNIEnv *env, jobject thiz)
    return balance;
    return balance;
}
}


static jint
android_media_AudioSystem_getDevicesForStream(JNIEnv *env, jobject thiz, jint stream)
{
    return (jint)deviceTypesToBitMask(
            AudioSystem::getDevicesForStream(static_cast<audio_stream_type_t>(stream)));
}

static jint
static jint
android_media_AudioSystem_getPrimaryOutputSamplingRate(JNIEnv *env, jobject clazz)
android_media_AudioSystem_getPrimaryOutputSamplingRate(JNIEnv *env, jobject clazz)
{
{
@@ -2959,7 +2952,6 @@ static const JNINativeMethod gMethods[] =
         {"getMasterMono", "()Z", (void *)android_media_AudioSystem_getMasterMono},
         {"getMasterMono", "()Z", (void *)android_media_AudioSystem_getMasterMono},
         {"setMasterBalance", "(F)I", (void *)android_media_AudioSystem_setMasterBalance},
         {"setMasterBalance", "(F)I", (void *)android_media_AudioSystem_setMasterBalance},
         {"getMasterBalance", "()F", (void *)android_media_AudioSystem_getMasterBalance},
         {"getMasterBalance", "()F", (void *)android_media_AudioSystem_getMasterBalance},
         {"getDevicesForStream", "(I)I", (void *)android_media_AudioSystem_getDevicesForStream},
         {"getPrimaryOutputSamplingRate", "()I",
         {"getPrimaryOutputSamplingRate", "()I",
          (void *)android_media_AudioSystem_getPrimaryOutputSamplingRate},
          (void *)android_media_AudioSystem_getPrimaryOutputSamplingRate},
         {"getPrimaryOutputFrameCount", "()I",
         {"getPrimaryOutputFrameCount", "()I",
+23 −17
Original line number Original line Diff line number Diff line
@@ -5624,9 +5624,15 @@ public class AudioManager {
     * Note that the information may be imprecise when the implementation
     * Note that the information may be imprecise when the implementation
     * cannot distinguish whether a particular device is enabled.
     * cannot distinguish whether a particular device is enabled.
     *
     *
     * {@hide}
     * @deprecated on {@link android.os.Build.VERSION_CODES#T} as new devices
     *             will have multi-bit device types.
     *             Prefer to use {@link #getDevicesForAttributes()} instead,
     *             noting that getDevicesForStream() has a few small discrepancies
     *             for better volume handling.
     * @hide
     */
     */
    @UnsupportedAppUsage
    @UnsupportedAppUsage
    @Deprecated
    public int getDevicesForStream(int streamType) {
    public int getDevicesForStream(int streamType) {
        switch (streamType) {
        switch (streamType) {
            case STREAM_VOICE_CALL:
            case STREAM_VOICE_CALL:
@@ -5639,7 +5645,7 @@ public class AudioManager {
            case STREAM_ACCESSIBILITY:
            case STREAM_ACCESSIBILITY:
                final IAudioService service = getService();
                final IAudioService service = getService();
                try {
                try {
                return service.getDevicesForStream(streamType);
                    return service.getDeviceMaskForStream(streamType);
                } catch (RemoteException e) {
                } catch (RemoteException e) {
                    throw e.rethrowFromSystemServer();
                    throw e.rethrowFromSystemServer();
                }
                }
+67 −14
Original line number Original line Diff line number Diff line
@@ -29,6 +29,7 @@ import android.content.pm.PackageManager;
import android.media.audio.common.AidlConversion;
import android.media.audio.common.AidlConversion;
import android.media.audiofx.AudioEffect;
import android.media.audiofx.AudioEffect;
import android.media.audiopolicy.AudioMix;
import android.media.audiopolicy.AudioMix;
import android.media.audiopolicy.AudioProductStrategy;
import android.os.Build;
import android.os.Build;
import android.os.IBinder;
import android.os.IBinder;
import android.os.Parcel;
import android.os.Parcel;
@@ -47,6 +48,7 @@ import java.util.List;
import java.util.Map;
import java.util.Map;
import java.util.Objects;
import java.util.Objects;
import java.util.Set;
import java.util.Set;
import java.util.TreeSet;


/* IF YOU CHANGE ANY OF THE CONSTANTS IN THIS FILE, DO NOT FORGET
/* IF YOU CHANGE ANY OF THE CONSTANTS IN THIS FILE, DO NOT FORGET
 * TO UPDATE THE CORRESPONDING NATIVE GLUE AND AudioManager.java.
 * TO UPDATE THE CORRESPONDING NATIVE GLUE AND AudioManager.java.
@@ -1655,9 +1657,63 @@ public class AudioSystem
    /** @hide */
    /** @hide */
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    public static native boolean getMasterMute();
    public static native boolean getMasterMute();
    /** @hide */
    /** @hide
     * Only used (unsupported) for legacy apps.
     * @deprecated on {@link android.os.Build.VERSION_CODES#T} as new devices
     *             will have multi-bit device types.
     *             Use {@link AudioManager#getDevicesForAttributes(AudioAttributes)} instead.
     */
    @UnsupportedAppUsage
    @UnsupportedAppUsage
    public static native int getDevicesForStream(int stream);
    @Deprecated
    public static int getDevicesForStream(int stream) {
        final AudioAttributes attr =
                AudioProductStrategy.getAudioAttributesForStrategyWithLegacyStreamType(stream);
        return getDeviceMaskFromSet(generateAudioDeviceTypesSet(
                getDevicesForAttributes(attr, true /* forVolume */)));
    }

    /** @hide
     * Conversion from a device set to a bit mask.
     *
     * Legacy compatibility method (use a device list instead of a bit mask).
     * Conversion to bit mask skips multi-bit (S and later) internal device types
     * (e.g. AudioSystem.DEVICE_OUT* or AudioManager.DEVICE_OUT*) for legacy
     * compatibility reasons.  Legacy apps will not understand these new device types
     * and it will raise false matches with old device types.
     */
    public static int getDeviceMaskFromSet(@NonNull Set<Integer> deviceSet) {
        int deviceMask = DEVICE_NONE; // zero.
        int deviceInChecksum = DEVICE_BIT_IN;
        for (Integer device : deviceSet) {
            if ((device & (device - 1) & ~DEVICE_BIT_IN) != 0) {
                Log.v(TAG, "getDeviceMaskFromSet skipping multi-bit device value " + device);
                continue;
            }
            deviceMask |= device;
            deviceInChecksum &= device;
        }
        // Validate that deviceSet is either ALL input devices or ALL output devices.
        // We check that the "OR" of all the DEVICE_BIT_INs == the "AND" of all DEVICE_BIT_INs.
        if (!deviceSet.isEmpty() && deviceInChecksum != (deviceMask & DEVICE_BIT_IN)) {
            Log.e(TAG, "getDeviceMaskFromSet: Invalid set: " + deviceSetToString(deviceSet));
        }
        return deviceMask;
    }

    /** @hide */
    @NonNull
    public static String deviceSetToString(@NonNull Set<Integer> devices) {
        int n = 0;
        StringBuilder sb = new StringBuilder();
        for (Integer device : devices) {
            if (n++ > 0) {
                sb.append(", ");
            }
            sb.append(AudioSystem.getDeviceName(device));
            sb.append("(" + Integer.toHexString(device) + ")");
        }
        return sb.toString();
    }


    /**
    /**
     * @hide
     * @hide
@@ -2252,18 +2308,15 @@ public class AudioSystem


    /**
    /**
     * @hide
     * @hide
     * Return a set of audio device types from a bit mask audio device type, which may
     * Return a set of audio device types from a list of audio device attributes, which may
     * represent multiple audio device types.
     * represent multiple audio device types.
     * FIXME: Remove this when getting ride of bit mask usage of audio device types.
     */
     */
    public static Set<Integer> generateAudioDeviceTypesSet(int types) {
    @NonNull
        Set<Integer> deviceTypes = new HashSet<>();
    public static Set<Integer> generateAudioDeviceTypesSet(
        Set<Integer> allDeviceTypes =
            @NonNull List<AudioDeviceAttributes> deviceList) {
                (types & DEVICE_BIT_IN) == 0 ? DEVICE_OUT_ALL_SET : DEVICE_IN_ALL_SET;
        Set<Integer> deviceTypes = new TreeSet<>();
        for (int deviceType : allDeviceTypes) {
        for (AudioDeviceAttributes device : deviceList) {
            if ((types & deviceType) == deviceType) {
            deviceTypes.add(device.getInternalType());
                deviceTypes.add(deviceType);
            }
        }
        }
        return deviceTypes;
        return deviceTypes;
    }
    }
@@ -2274,7 +2327,7 @@ public class AudioSystem
     */
     */
    public static Set<Integer> intersectionAudioDeviceTypes(
    public static Set<Integer> intersectionAudioDeviceTypes(
            @NonNull Set<Integer> a, @NonNull Set<Integer> b) {
            @NonNull Set<Integer> a, @NonNull Set<Integer> b) {
        Set<Integer> intersection = new HashSet<>(a);
        Set<Integer> intersection = new TreeSet<>(a);
        intersection.retainAll(b);
        intersection.retainAll(b);
        return intersection;
        return intersection;
    }
    }
+1 −1
Original line number Original line Diff line number Diff line
@@ -360,7 +360,7 @@ interface IAudioService {


    boolean isMusicActive(in boolean remotely);
    boolean isMusicActive(in boolean remotely);


    int getDevicesForStream(in int streamType);
    int getDeviceMaskForStream(in int streamType);


    int[] getAvailableCommunicationDeviceIds();
    int[] getAvailableCommunicationDeviceIds();


+9 −2
Original line number Original line Diff line number Diff line
@@ -1565,6 +1565,13 @@ import java.util.concurrent.atomic.AtomicBoolean;


    private AtomicBoolean mMusicMuted = new AtomicBoolean(false);
    private AtomicBoolean mMusicMuted = new AtomicBoolean(false);


    private static <T> boolean hasIntersection(Set<T> a, Set<T> b) {
        for (T e : a) {
            if (b.contains(e)) return true;
        }
        return false;
    }

    boolean messageMutesMusic(int message) {
    boolean messageMutesMusic(int message) {
        if (message == 0) {
        if (message == 0) {
            return false;
            return false;
@@ -1574,8 +1581,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
                || message == MSG_L_A2DP_DEVICE_CONNECTION_CHANGE_EXT
                || message == MSG_L_A2DP_DEVICE_CONNECTION_CHANGE_EXT
                || message == MSG_L_A2DP_DEVICE_CONFIG_CHANGE)
                || message == MSG_L_A2DP_DEVICE_CONFIG_CHANGE)
                && AudioSystem.isStreamActive(AudioSystem.STREAM_MUSIC, 0)
                && AudioSystem.isStreamActive(AudioSystem.STREAM_MUSIC, 0)
                && mDeviceInventory.DEVICE_OVERRIDE_A2DP_ROUTE_ON_PLUG_SET.contains(
                && hasIntersection(mDeviceInventory.DEVICE_OVERRIDE_A2DP_ROUTE_ON_PLUG_SET,
                        mAudioService.getDevicesForStream(AudioSystem.STREAM_MUSIC))) {
                        mAudioService.getDeviceSetForStream(AudioSystem.STREAM_MUSIC))) {
            return false;
            return false;
        }
        }
        return true;
        return true;
Loading