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

Commit 39e4080c authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Set docking ringtone to be played from builtin speaker."

parents 82f57548 1fcfa355
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -89,6 +89,7 @@ public class Ringtone {
            .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
            .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
            .build();
    private boolean mPreferBuiltinDevice;
    // playback properties, use synchronized with mPlaybackSettingsLock
    private boolean mIsLooping = false;
    private float mVolume = 1.0f;
@@ -156,6 +157,37 @@ public class Ringtone {
        mAudioAttributes = attributes;
    }

    /**
     * Finds the output device of type {@link AudioDeviceInfo#TYPE_BUILTIN_SPEAKER}. This device is
     * the one on which outgoing audio for SIM calls is played.
     *
     * @param audioManager the audio manage.
     * @return the {@link AudioDeviceInfo} corresponding to the builtin device, or {@code null} if
     *     none can be found.
     */
    private AudioDeviceInfo getBuiltinDevice(AudioManager audioManager) {
        AudioDeviceInfo[] deviceList = audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS);
        for (AudioDeviceInfo device : deviceList) {
            if (device.getType() == AudioDeviceInfo.TYPE_BUILTIN_SPEAKER) {
                return device;
            }
        }
        return null;
    }

    /**
     * Sets the preferred device of the ringtong playback to the built-in device.
     *
     * @hide
     */
    public boolean preferBuiltinDevice(boolean enable) {
        mPreferBuiltinDevice = enable;
        if (mLocalPlayer == null) {
            return true;
        }
        return mLocalPlayer.setPreferredDevice(getBuiltinDevice(mAudioManager));
    }

    /**
     * Creates a local media player for the ringtone using currently set attributes.
     * @return true if media player creation succeeded or is deferred,
@@ -174,6 +206,8 @@ public class Ringtone {
        try {
            mLocalPlayer.setDataSource(mContext, mUri);
            mLocalPlayer.setAudioAttributes(mAudioAttributes);
            mLocalPlayer.setPreferredDevice(
                    mPreferBuiltinDevice ? getBuiltinDevice(mAudioManager) : null);
            synchronized (mPlaybackSettingsLock) {
                applyPlaybackProperties_sync();
            }
+1 −0
Original line number Diff line number Diff line
@@ -302,6 +302,7 @@ final class DockObserver extends SystemService {
                                    getContext(), soundUri);
                            if (sfx != null) {
                                sfx.setStreamType(AudioManager.STREAM_SYSTEM);
                                sfx.preferBuiltinDevice(true);
                                sfx.play();
                            }
                        }