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

Commit 8255bbdf authored by Santiago Seifert's avatar Santiago Seifert
Browse files

Replace Handler with Executor

This change addresses API council feedback around the new
setOnRtpRxNoticeListener method.

Bug: 168585020
Test: Manually built the tree.
Test: Tests pending as per b/169965769.
Change-Id: Ie8291df9b10960f78bdfdd5986767e896a953abf
parent 9038560d
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -5040,7 +5040,7 @@ package android.media {
  }
  }
  public class MediaPlayer implements android.media.AudioRouting android.media.VolumeAutomation {
  public class MediaPlayer implements android.media.AudioRouting android.media.VolumeAutomation {
    method @RequiresPermission(android.Manifest.permission.BIND_IMS_SERVICE) public void setOnRtpRxNoticeListener(@NonNull android.content.Context, @NonNull android.media.MediaPlayer.OnRtpRxNoticeListener, @Nullable android.os.Handler);
    method @RequiresPermission(android.Manifest.permission.BIND_IMS_SERVICE) public void setOnRtpRxNoticeListener(@NonNull android.content.Context, @NonNull java.util.concurrent.Executor, @NonNull android.media.MediaPlayer.OnRtpRxNoticeListener);
  }
  }
  public static interface MediaPlayer.OnRtpRxNoticeListener {
  public static interface MediaPlayer.OnRtpRxNoticeListener {
+11 −18
Original line number Original line Diff line number Diff line
@@ -91,6 +91,7 @@ import java.util.Scanner;
import java.util.Set;
import java.util.Set;
import java.util.UUID;
import java.util.UUID;
import java.util.Vector;
import java.util.Vector;
import java.util.concurrent.Executor;




/**
/**
@@ -2169,7 +2170,7 @@ public class MediaPlayer extends PlayerBase
        mOnVideoSizeChangedListener = null;
        mOnVideoSizeChangedListener = null;
        mOnTimedTextListener = null;
        mOnTimedTextListener = null;
        mOnRtpRxNoticeListener = null;
        mOnRtpRxNoticeListener = null;
        mOnRtpRxNoticeHandler = null;
        mOnRtpRxNoticeExecutor = null;
        synchronized (mTimeProviderLock) {
        synchronized (mTimeProviderLock) {
            if (mTimeProvider != null) {
            if (mTimeProvider != null) {
                mTimeProvider.close();
                mTimeProvider.close();
@@ -3705,7 +3706,6 @@ public class MediaPlayer extends PlayerBase


            case MEDIA_RTP_RX_NOTICE:
            case MEDIA_RTP_RX_NOTICE:
                final OnRtpRxNoticeListener rtpRxNoticeListener = mOnRtpRxNoticeListener;
                final OnRtpRxNoticeListener rtpRxNoticeListener = mOnRtpRxNoticeListener;
                final Handler rtpRxNoticeHandler = mOnRtpRxNoticeHandler;
                if (rtpRxNoticeListener == null) {
                if (rtpRxNoticeListener == null) {
                    return;
                    return;
                }
                }
@@ -3724,15 +3724,10 @@ public class MediaPlayer extends PlayerBase
                    } finally {
                    } finally {
                        parcel.recycle();
                        parcel.recycle();
                    }
                    }
                    if (rtpRxNoticeHandler == null) {
                    mOnRtpRxNoticeExecutor.execute(() ->
                        rtpRxNoticeListener.onRtpRxNotice(mMediaPlayer, noticeType, data);
                    } else {
                        rtpRxNoticeHandler.post(
                                () ->
                            rtpRxNoticeListener
                            rtpRxNoticeListener
                                    .onRtpRxNotice(mMediaPlayer, noticeType, data));
                                    .onRtpRxNotice(mMediaPlayer, noticeType, data));
                }
                }
                }
                return;
                return;


            default:
            default:
@@ -4299,28 +4294,26 @@ public class MediaPlayer extends PlayerBase
     *
     *
     * @see OnRtpRxNoticeListener
     * @see OnRtpRxNoticeListener
     *
     *
     * @param listener the listener called after a notice from RTP Rx
     * @param listener the listener called after a notice from RTP Rx.
     * @param handler the {@link Handler} that receives RTP Tx events. If null is passed,
     * @param executor the {@link Executor} on which to post RTP Tx events.
     *                notifications will be posted on the thread that created this MediaPlayer
     *                instance. If the creating thread does not have a {@link Looper}, then
     *                notifications will be posted on the main thread.
     * @hide
     * @hide
     */
     */
    @SystemApi
    @SystemApi
    @RequiresPermission(BIND_IMS_SERVICE)
    @RequiresPermission(BIND_IMS_SERVICE)
    public void setOnRtpRxNoticeListener(
    public void setOnRtpRxNoticeListener(
            @NonNull Context context,
            @NonNull Context context,
            @NonNull OnRtpRxNoticeListener listener, @Nullable Handler handler) {
            @NonNull Executor executor,
            @NonNull OnRtpRxNoticeListener listener) {
        Objects.requireNonNull(context);
        Objects.requireNonNull(context);
        Preconditions.checkArgument(
        Preconditions.checkArgument(
                context.checkSelfPermission(BIND_IMS_SERVICE) == PERMISSION_GRANTED,
                context.checkSelfPermission(BIND_IMS_SERVICE) == PERMISSION_GRANTED,
                BIND_IMS_SERVICE + " permission not granted.");
                BIND_IMS_SERVICE + " permission not granted.");
        mOnRtpRxNoticeListener = Objects.requireNonNull(listener);
        mOnRtpRxNoticeListener = Objects.requireNonNull(listener);
        mOnRtpRxNoticeHandler = handler;
        mOnRtpRxNoticeExecutor = Objects.requireNonNull(executor);
    }
    }


    private OnRtpRxNoticeListener mOnRtpRxNoticeListener;
    private OnRtpRxNoticeListener mOnRtpRxNoticeListener;
    private Handler mOnRtpRxNoticeHandler;
    private Executor mOnRtpRxNoticeExecutor;


    /**
    /**
     * Register a callback to be invoked when a selected track has timed metadata available.
     * Register a callback to be invoked when a selected track has timed metadata available.