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

Commit f178449b authored by Valentin Iftime's avatar Valentin Iftime
Browse files

Add volume to IRingtonePlayer.playAsync

 Add volume param to IRingtonePlayer so that notification
 alerts can have their volume adjusted.

Test: atest FrameworksUiServicesTests
Bug: 270456865
Change-Id: Iec72c74642ade5a4b8d110abf21f6e713814e7f1
parent 84282d80
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ interface IRingtonePlayer {
    oneway void setHapticGeneratorEnabled(IBinder token, boolean hapticGeneratorEnabled);

    /** Used for Notification sound playback. */
    oneway void playAsync(in Uri uri, in UserHandle user, boolean looping, in AudioAttributes aa);
    oneway void playAsync(in Uri uri, in UserHandle user, boolean looping, in AudioAttributes aa, float volume);
    oneway void stopAsync();

    /** Return the title of the media. */
+10 −3
Original line number Diff line number Diff line
@@ -51,11 +51,12 @@ public class NotificationPlayer implements OnCompletionListener, OnErrorListener
        Uri uri;
        boolean looping;
        AudioAttributes attributes;
        float volume;
        long requestTime;

        public String toString() {
            return "{ code=" + code + " looping=" + looping + " attributes=" + attributes
                    + " uri=" + uri + " }";
                    + " volume=" + volume + " uri=" + uri + " }";
        }
    }

@@ -101,6 +102,7 @@ public class NotificationPlayer implements OnCompletionListener, OnErrorListener
                    player.setAudioAttributes(mCmd.attributes);
                    player.setDataSource(mCmd.context, mCmd.uri);
                    player.setLooping(mCmd.looping);
                    player.setVolume(mCmd.volume);
                    player.setOnCompletionListener(NotificationPlayer.this);
                    player.setOnErrorListener(NotificationPlayer.this);
                    player.prepare();
@@ -401,10 +403,11 @@ public class NotificationPlayer implements OnCompletionListener, OnErrorListener
     *          (see {@link MediaPlayer#setLooping(boolean)})
     * @param stream the AudioStream to use.
     *          (see {@link MediaPlayer#setAudioStreamType(int)})
     * @param volume the volume for the audio with values in range [0.0, 1.0]
     * @deprecated use {@link #play(Context, Uri, boolean, AudioAttributes)} instead.
     */
    @Deprecated
    public void play(Context context, Uri uri, boolean looping, int stream) {
    public void play(Context context, Uri uri, boolean looping, int stream, float volume) {
        if (DEBUG) { Log.d(mTag, "play uri=" + uri.toString()); }
        PlayerBase.deprecateStreamTypeForPlayback(stream, "NotificationPlayer", "play");
        Command cmd = new Command();
@@ -414,6 +417,7 @@ public class NotificationPlayer implements OnCompletionListener, OnErrorListener
        cmd.uri = uri;
        cmd.looping = looping;
        cmd.attributes = new AudioAttributes.Builder().setInternalLegacyStreamType(stream).build();
        cmd.volume = volume;
        synchronized (mCmdQueue) {
            enqueueLocked(cmd);
            mState = PLAY;
@@ -432,8 +436,10 @@ public class NotificationPlayer implements OnCompletionListener, OnErrorListener
     *          (see {@link MediaPlayer#setLooping(boolean)})
     * @param attributes the AudioAttributes to use.
     *          (see {@link MediaPlayer#setAudioAttributes(AudioAttributes)})
     * @param volume the volume for the audio with values in range [0.0, 1.0]
     */
    public void play(Context context, Uri uri, boolean looping, AudioAttributes attributes) {
    public void play(Context context, Uri uri, boolean looping, AudioAttributes attributes,
            float volume) {
        if (DEBUG) { Log.d(mTag, "play uri=" + uri.toString()); }
        Command cmd = new Command();
        cmd.requestTime = SystemClock.uptimeMillis();
@@ -442,6 +448,7 @@ public class NotificationPlayer implements OnCompletionListener, OnErrorListener
        cmd.uri = uri;
        cmd.looping = looping;
        cmd.attributes = attributes;
        cmd.volume = volume;
        synchronized (mCmdQueue) {
            enqueueLocked(cmd);
            mState = PLAY;
+3 −2
Original line number Diff line number Diff line
@@ -285,7 +285,8 @@ public class RingtonePlayer implements CoreStartable {
        }

        @Override
        public void playAsync(Uri uri, UserHandle user, boolean looping, AudioAttributes aa) {
        public void playAsync(Uri uri, UserHandle user, boolean looping, AudioAttributes aa,
                float volume) {
            if (LOGD) Log.d(TAG, "playAsync(uri=" + uri + ", user=" + user + ")");
            if (Binder.getCallingUid() != Process.SYSTEM_UID) {
                throw new SecurityException("Async playback only available from system UID.");
@@ -293,7 +294,7 @@ public class RingtonePlayer implements CoreStartable {
            if (UserHandle.ALL.equals(user)) {
                user = UserHandle.SYSTEM;
            }
            mAsyncPlayer.play(getContextForUser(user), uri, looping, aa);
            mAsyncPlayer.play(getContextForUser(user), uri, looping, aa, volume);
        }

        @Override
+1 −1
Original line number Diff line number Diff line
@@ -468,7 +468,7 @@ public final class NotificationAttentionHelper {
                                + record.getAudioAttributes());
                    }
                    player.playAsync(soundUri, record.getSbn().getUser(), looping,
                            record.getAudioAttributes());
                            record.getAudioAttributes(), 1.0f);
                    return true;
                }
            } catch (RemoteException e) {
+1 −1
Original line number Diff line number Diff line
@@ -8757,7 +8757,7 @@ public class NotificationManagerService extends SystemService {
                    if (DBG) Slog.v(TAG, "Playing sound " + soundUri
                            + " with attributes " + record.getAudioAttributes());
                    player.playAsync(soundUri, record.getSbn().getUser(), looping,
                            record.getAudioAttributes());
                            record.getAudioAttributes(), 1.0f);
                    return true;
                }
            } catch (RemoteException e) {
Loading