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

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

Merge "MediaPlayer2: replace Preconditions (internal api) with Media2Utils."

parents f49c8092 0c0e939d
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -18,8 +18,6 @@ package android.media;

import android.annotation.NonNull;

import com.android.internal.util.Preconditions;

/**
 * @hide
 * Structure for file data source descriptor.
@@ -105,7 +103,7 @@ public class CallbackDataSourceDesc extends DataSourceDesc {
         * @throws NullPointerException if m2ds is null.
         */
        public @NonNull Builder setDataSource(@NonNull Media2DataSource m2ds) {
            Preconditions.checkNotNull(m2ds);
            Media2Utils.checkArgument(m2ds != null, "data source cannot be null.");
            mMedia2DataSource = m2ds;
            return this;
        }
+1 −3
Original line number Diff line number Diff line
@@ -18,8 +18,6 @@ package android.media;

import android.annotation.NonNull;

import com.android.internal.util.Preconditions;

/**
 * @hide
 * Base class of data source descriptor.
@@ -118,7 +116,7 @@ public class DataSourceDesc {
         * @return the same instance of subclass of {@link DataSourceDesc}
         */
        void build(@NonNull DataSourceDesc dsd) {
            Preconditions.checkNotNull(dsd);
            Media2Utils.checkArgument(dsd != null,  "dsd cannot be null.");

            if (mStartPositionMs > mEndPositionMs) {
                throw new IllegalStateException("Illegal start/end position: "
+2 −4
Original line number Diff line number Diff line
@@ -18,8 +18,6 @@ package android.media;

import android.annotation.NonNull;

import com.android.internal.util.Preconditions;

import java.io.FileDescriptor;

/**
@@ -141,7 +139,7 @@ public class FileDataSourceDesc extends DataSourceDesc {
         * @throws NullPointerException if fd is null.
         */
        public @NonNull Builder setDataSource(@NonNull FileDescriptor fd) {
            Preconditions.checkNotNull(fd);
            Media2Utils.checkArgument(fd != null, "fd cannot be null.");
            resetDataSource();
            mFD = fd;
            return this;
@@ -163,7 +161,7 @@ public class FileDataSourceDesc extends DataSourceDesc {
         */
        public @NonNull Builder setDataSource(
                @NonNull FileDescriptor fd, long offset, long length) {
            Preconditions.checkNotNull(fd);
            Media2Utils.checkArgument(fd != null, "fd cannot be null.");
            if (offset < 0) {
                offset = 0;
            }
+14 −0
Original line number Diff line number Diff line
@@ -31,6 +31,20 @@ public class Media2Utils {
    private Media2Utils() {
    }

    /**
     * Ensures that an expression checking an argument is true.
     *
     * @param expression the expression to check
     * @param errorMessage the exception message to use if the check fails; will
     *     be converted to a string using {@link String#valueOf(Object)}
     * @throws IllegalArgumentException if {@code expression} is false
     */
    public static void checkArgument(boolean expression, String errorMessage) {
        if (!expression) {
            throw new IllegalArgumentException(errorMessage);
        }
    }

    public static synchronized void storeCookies(List<HttpCookie> cookies) {
        CookieHandler cookieHandler = CookieHandler.getDefault();
        if (cookieHandler == null) {
+6 −12
Original line number Diff line number Diff line
@@ -693,7 +693,7 @@ public class MediaPlayer2 implements AutoCloseable
        return addTask(new Task(CALL_COMPLETED_SET_DATA_SOURCE, false) {
            @Override
            void process() throws IOException {
                checkArgument(dsd != null, "the DataSourceDesc cannot be null");
                Media2Utils.checkArgument(dsd != null, "the DataSourceDesc cannot be null");
                int state = getState();
                if (state != PLAYER_STATE_ERROR && state != PLAYER_STATE_IDLE) {
                    throw new IllegalStateException("called in wrong state " + state);
@@ -719,7 +719,7 @@ public class MediaPlayer2 implements AutoCloseable
        return addTask(new Task(CALL_COMPLETED_SET_NEXT_DATA_SOURCE, false) {
            @Override
            void process() {
                checkArgument(dsd != null, "the DataSourceDesc cannot be null");
                Media2Utils.checkArgument(dsd != null, "the DataSourceDesc cannot be null");
                synchronized (mSrcLock) {
                    mNextSourceInfos.clear();
                    mNextSourceInfos.add(new SourceInfo(dsd));
@@ -788,7 +788,7 @@ public class MediaPlayer2 implements AutoCloseable

    private void handleDataSource(boolean isCurrent, @NonNull DataSourceDesc dsd, long srcId)
            throws IOException {
        checkArgument(dsd != null, "the DataSourceDesc cannot be null");
        Media2Utils.checkArgument(dsd != null, "the DataSourceDesc cannot be null");

        if (dsd instanceof CallbackDataSourceDesc) {
            CallbackDataSourceDesc cbDSD = (CallbackDataSourceDesc) dsd;
@@ -1513,7 +1513,7 @@ public class MediaPlayer2 implements AutoCloseable
        return addTask(new Task(CALL_COMPLETED_SET_BUFFERING_PARAMS, false) {
            @Override
            void process() {
                checkArgument(params != null, "the BufferingParams cannot be null");
                Media2Utils.checkArgument(params != null, "the BufferingParams cannot be null");
                native_setBufferingParams(params);
            }
        });
@@ -1536,7 +1536,7 @@ public class MediaPlayer2 implements AutoCloseable
        return addTask(new Task(CALL_COMPLETED_SET_PLAYBACK_PARAMS, false) {
            @Override
            void process() {
                checkArgument(params != null, "the PlaybackParams cannot be null");
                Media2Utils.checkArgument(params != null, "the PlaybackParams cannot be null");
                native_setPlaybackParams(params);
            }
        });
@@ -1564,7 +1564,7 @@ public class MediaPlayer2 implements AutoCloseable
        return addTask(new Task(CALL_COMPLETED_SET_SYNC_PARAMS, false) {
            @Override
            void process() {
                checkArgument(params != null, "the SyncParams cannot be null");
                Media2Utils.checkArgument(params != null, "the SyncParams cannot be null");
                native_setSyncParams(params);
            }
        });
@@ -2690,12 +2690,6 @@ public class MediaPlayer2 implements AutoCloseable
        }
    }

    private static void checkArgument(boolean expression, String errorMessage) {
        if (!expression) {
            throw new IllegalArgumentException(errorMessage);
        }
    }

    private void sendEvent(final EventNotifier notifier) {
        synchronized (mEventCbLock) {
            try {
Loading