MediaPlayer2: replace Preconditions (internal api) with Media2Utils.

Also setting sdk_verion for mediaplayer2.proto

Test: build
Bug: 112766913
Change-Id: I537ee296d9e1a0b127567943a68dc985a48ad86f
This commit is contained in:
Dongwon Kang
2018-11-26 20:09:20 -08:00
parent 9ebc59e956
commit 0c0e939d59
7 changed files with 29 additions and 28 deletions

View File

@@ -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;
}

View File

@@ -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: "

View File

@@ -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;
}

View File

@@ -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) {

View File

@@ -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 {

View File

@@ -21,8 +21,6 @@ import android.annotation.Nullable;
import android.content.Context;
import android.net.Uri;
import com.android.internal.util.Preconditions;
import java.net.CookieHandler;
import java.net.CookieManager;
import java.net.HttpCookie;
@@ -158,8 +156,8 @@ public class UriDataSourceDesc extends DataSourceDesc {
* @throws NullPointerException if context or uri is null.
*/
public @NonNull Builder setDataSource(@NonNull Context context, @NonNull Uri uri) {
Preconditions.checkNotNull(context, "context cannot be null");
Preconditions.checkNotNull(uri, "uri cannot be null");
Media2Utils.checkArgument(context != null, "context cannot be null");
Media2Utils.checkArgument(uri != null, "uri cannot be null");
resetDataSource();
mUri = uri;
mContext = context;
@@ -195,8 +193,8 @@ public class UriDataSourceDesc extends DataSourceDesc {
*/
public @NonNull Builder setDataSource(@NonNull Context context, @NonNull Uri uri,
@Nullable Map<String, String> headers, @Nullable List<HttpCookie> cookies) {
Preconditions.checkNotNull(context, "context cannot be null");
Preconditions.checkNotNull(uri);
Media2Utils.checkArgument(context != null, "context cannot be null");
Media2Utils.checkArgument(uri != null, "uri cannot be null");
if (cookies != null) {
CookieHandler cookieHandler = CookieHandler.getDefault();
if (cookieHandler != null && !(cookieHandler instanceof CookieManager)) {

View File

@@ -7,6 +7,7 @@ java_library_static {
srcs: ["mediaplayer2.proto"],
no_framework_libs: true,
jarjar_rules: "jarjar-rules.txt",
sdk_version: "28",
}
cc_library_static {