Merge "MediaSession2: Ensure NonNull/Nullable for parameters of public methods" into pi-dev
This commit is contained in:
@@ -73,7 +73,7 @@ public abstract class MediaLibraryService2 extends MediaSessionService2 {
|
||||
* Callback for the {@link MediaLibrarySession}.
|
||||
*/
|
||||
public static class MediaLibrarySessionCallback extends MediaSession2.SessionCallback {
|
||||
public MediaLibrarySessionCallback(Context context) {
|
||||
public MediaLibrarySessionCallback(@NonNull Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ public abstract class MediaLibraryService2 extends MediaSessionService2 {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder setVolumeProvider(@NonNull VolumeProvider2 volumeProvider) {
|
||||
public Builder setVolumeProvider(@Nullable VolumeProvider2 volumeProvider) {
|
||||
return super.setVolumeProvider(volumeProvider);
|
||||
}
|
||||
|
||||
@@ -236,12 +236,12 @@ public abstract class MediaLibraryService2 extends MediaSessionService2 {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder setId(String id) {
|
||||
public Builder setId(@NonNull String id) {
|
||||
return super.setId(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder setSessionCallback(@NonNull Executor executor,
|
||||
public Builder setSessionCallback(@NonNull @CallbackExecutor Executor executor,
|
||||
@NonNull MediaLibrarySessionCallback callback) {
|
||||
return super.setSessionCallback(executor, callback);
|
||||
}
|
||||
|
||||
@@ -562,7 +562,7 @@ public final class MediaMetadata2 {
|
||||
* @param key The key the value is stored under
|
||||
* @return a CharSequence value, or null
|
||||
*/
|
||||
public @Nullable CharSequence getText(@TextKey String key) {
|
||||
public @Nullable CharSequence getText(@NonNull @TextKey String key) {
|
||||
return mProvider.getText_impl(key);
|
||||
}
|
||||
|
||||
@@ -611,7 +611,7 @@ public final class MediaMetadata2 {
|
||||
* @param key The key the value is stored under
|
||||
* @return A {@link Rating2} or {@code null}
|
||||
*/
|
||||
public @Nullable Rating2 getRating(@RatingKey String key) {
|
||||
public @Nullable Rating2 getRating(@NonNull @RatingKey String key) {
|
||||
return mProvider.getRating_impl(key);
|
||||
}
|
||||
|
||||
@@ -622,7 +622,7 @@ public final class MediaMetadata2 {
|
||||
* @param key The key the value is stored under
|
||||
* @return A {@link Bitmap} or null
|
||||
*/
|
||||
public Bitmap getBitmap(@BitmapKey String key) {
|
||||
public @Nullable Bitmap getBitmap(@NonNull @BitmapKey String key) {
|
||||
return mProvider.getBitmap_impl(key);
|
||||
}
|
||||
|
||||
@@ -749,7 +749,8 @@ public final class MediaMetadata2 {
|
||||
* @param value The CharSequence value to store
|
||||
* @return The Builder to allow chaining
|
||||
*/
|
||||
public @NonNull Builder putText(@TextKey String key, @Nullable CharSequence value) {
|
||||
public @NonNull Builder putText(@NonNull @TextKey String key,
|
||||
@Nullable CharSequence value) {
|
||||
return mProvider.putText_impl(key, value);
|
||||
}
|
||||
|
||||
@@ -780,7 +781,8 @@ public final class MediaMetadata2 {
|
||||
* @param value The String value to store
|
||||
* @return The Builder to allow chaining
|
||||
*/
|
||||
public @NonNull Builder putString(@TextKey String key, @Nullable String value) {
|
||||
public @NonNull Builder putString(@NonNull @TextKey String key,
|
||||
@Nullable String value) {
|
||||
return mProvider.putString_impl(key, value);
|
||||
}
|
||||
|
||||
|
||||
@@ -490,7 +490,7 @@ public class MediaSession2 implements AutoCloseable {
|
||||
* @return a new Command instance from the Bundle
|
||||
* @hide
|
||||
*/
|
||||
public static Command fromBundle(@NonNull Context context, Bundle command) {
|
||||
public static Command fromBundle(@NonNull Context context, @NonNull Bundle command) {
|
||||
return ApiLoader.getProvider(context).fromBundle_MediaSession2Command(context, command);
|
||||
}
|
||||
}
|
||||
@@ -501,17 +501,17 @@ public class MediaSession2 implements AutoCloseable {
|
||||
public static final class CommandGroup {
|
||||
private final CommandGroupProvider mProvider;
|
||||
|
||||
public CommandGroup(Context context) {
|
||||
public CommandGroup(@NonNull Context context) {
|
||||
mProvider = ApiLoader.getProvider(context)
|
||||
.createMediaSession2CommandGroup(context, this, null);
|
||||
}
|
||||
|
||||
public CommandGroup(Context context, CommandGroup others) {
|
||||
public CommandGroup(@NonNull Context context, @Nullable CommandGroup others) {
|
||||
mProvider = ApiLoader.getProvider(context)
|
||||
.createMediaSession2CommandGroup(context, this, others);
|
||||
}
|
||||
|
||||
public void addCommand(Command command) {
|
||||
public void addCommand(@NonNull Command command) {
|
||||
mProvider.addCommand_impl(command);
|
||||
}
|
||||
|
||||
@@ -519,11 +519,11 @@ public class MediaSession2 implements AutoCloseable {
|
||||
mProvider.addAllPredefinedCommands_impl();
|
||||
}
|
||||
|
||||
public void removeCommand(Command command) {
|
||||
public void removeCommand(@NonNull Command command) {
|
||||
mProvider.removeCommand_impl(command);
|
||||
}
|
||||
|
||||
public boolean hasCommand(Command command) {
|
||||
public boolean hasCommand(@NonNull Command command) {
|
||||
return mProvider.hasCommand_impl(command);
|
||||
}
|
||||
|
||||
@@ -531,14 +531,14 @@ public class MediaSession2 implements AutoCloseable {
|
||||
return mProvider.hasCommand_impl(code);
|
||||
}
|
||||
|
||||
public List<Command> getCommands() {
|
||||
public @NonNull List<Command> getCommands() {
|
||||
return mProvider.getCommands_impl();
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public CommandGroupProvider getProvider() {
|
||||
public @NonNull CommandGroupProvider getProvider() {
|
||||
return mProvider;
|
||||
}
|
||||
|
||||
@@ -546,7 +546,7 @@ public class MediaSession2 implements AutoCloseable {
|
||||
* @return new bundle from the CommandGroup
|
||||
* @hide
|
||||
*/
|
||||
public Bundle toBundle() {
|
||||
public @NonNull Bundle toBundle() {
|
||||
return mProvider.toBundle_impl();
|
||||
}
|
||||
|
||||
@@ -570,7 +570,10 @@ public class MediaSession2 implements AutoCloseable {
|
||||
public static abstract class SessionCallback {
|
||||
private final Context mContext;
|
||||
|
||||
public SessionCallback(Context context) {
|
||||
public SessionCallback(@NonNull Context context) {
|
||||
if (context == null) {
|
||||
throw new IllegalArgumentException("context shouldn't be null");
|
||||
}
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
@@ -584,7 +587,7 @@ public class MediaSession2 implements AutoCloseable {
|
||||
*
|
||||
* @param session the session for this event
|
||||
* @param controller controller information.
|
||||
* @return allowed commands. Can be {@code null} to reject coonnection.
|
||||
* @return allowed commands. Can be {@code null} to reject connection.
|
||||
*/
|
||||
public @Nullable CommandGroup onConnect(@NonNull MediaSession2 session,
|
||||
@NonNull ControllerInfo controller) {
|
||||
@@ -906,7 +909,7 @@ public class MediaSession2 implements AutoCloseable {
|
||||
*
|
||||
* @param player a {@link MediaPlayerBase} that handles actual media playback in your app.
|
||||
*/
|
||||
U setPlayer(@NonNull MediaPlayerBase player) {
|
||||
@NonNull U setPlayer(@NonNull MediaPlayerBase player) {
|
||||
mProvider.setPlayer_impl(player);
|
||||
return (U) this;
|
||||
}
|
||||
@@ -933,7 +936,7 @@ public class MediaSession2 implements AutoCloseable {
|
||||
*
|
||||
* @param volumeProvider The provider that will receive volume button events.
|
||||
*/
|
||||
U setVolumeProvider(@NonNull VolumeProvider2 volumeProvider) {
|
||||
@NonNull U setVolumeProvider(@Nullable VolumeProvider2 volumeProvider) {
|
||||
mProvider.setVolumeProvider_impl(volumeProvider);
|
||||
return (U) this;
|
||||
}
|
||||
@@ -945,7 +948,7 @@ public class MediaSession2 implements AutoCloseable {
|
||||
*
|
||||
* @param pi The intent to launch to show UI for this session.
|
||||
*/
|
||||
U setSessionActivity(@Nullable PendingIntent pi) {
|
||||
@NonNull U setSessionActivity(@Nullable PendingIntent pi) {
|
||||
mProvider.setSessionActivity_impl(pi);
|
||||
return (U) this;
|
||||
}
|
||||
@@ -960,7 +963,7 @@ public class MediaSession2 implements AutoCloseable {
|
||||
* @throws IllegalArgumentException if id is {@code null}
|
||||
* @return
|
||||
*/
|
||||
U setId(@NonNull String id) {
|
||||
@NonNull U setId(@NonNull String id) {
|
||||
mProvider.setId_impl(id);
|
||||
return (U) this;
|
||||
}
|
||||
@@ -972,7 +975,7 @@ public class MediaSession2 implements AutoCloseable {
|
||||
* @param callback session callback.
|
||||
* @return
|
||||
*/
|
||||
U setSessionCallback(@NonNull @CallbackExecutor Executor executor,
|
||||
@NonNull U setSessionCallback(@NonNull @CallbackExecutor Executor executor,
|
||||
@NonNull C callback) {
|
||||
mProvider.setSessionCallback_impl(executor, callback);
|
||||
return (U) this;
|
||||
@@ -985,7 +988,7 @@ public class MediaSession2 implements AutoCloseable {
|
||||
* @throws IllegalStateException if the session with the same id is already exists for the
|
||||
* package.
|
||||
*/
|
||||
T build() {
|
||||
@NonNull T build() {
|
||||
return mProvider.build_impl();
|
||||
}
|
||||
}
|
||||
@@ -1005,7 +1008,7 @@ public class MediaSession2 implements AutoCloseable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder setPlayer(@NonNull MediaPlayerBase player) {
|
||||
public @NonNull Builder setPlayer(@NonNull MediaPlayerBase player) {
|
||||
return super.setPlayer(player);
|
||||
}
|
||||
|
||||
@@ -1015,28 +1018,28 @@ public class MediaSession2 implements AutoCloseable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder setVolumeProvider(@NonNull VolumeProvider2 volumeProvider) {
|
||||
public @NonNull Builder setVolumeProvider(@Nullable VolumeProvider2 volumeProvider) {
|
||||
return super.setVolumeProvider(volumeProvider);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder setSessionActivity(@Nullable PendingIntent pi) {
|
||||
public @NonNull Builder setSessionActivity(@Nullable PendingIntent pi) {
|
||||
return super.setSessionActivity(pi);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder setId(@NonNull String id) {
|
||||
public @NonNull Builder setId(@NonNull String id) {
|
||||
return super.setId(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder setSessionCallback(@NonNull Executor executor,
|
||||
public @NonNull Builder setSessionCallback(@NonNull Executor executor,
|
||||
@Nullable SessionCallback callback) {
|
||||
return super.setSessionCallback(executor, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MediaSession2 build() {
|
||||
public @NonNull MediaSession2 build() {
|
||||
return super.build();
|
||||
}
|
||||
}
|
||||
@@ -1050,8 +1053,8 @@ public class MediaSession2 implements AutoCloseable {
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public ControllerInfo(Context context, int uid, int pid, String packageName,
|
||||
IInterface callback) {
|
||||
public ControllerInfo(@NonNull Context context, int uid, int pid,
|
||||
@NonNull String packageName, @NonNull IInterface callback) {
|
||||
mProvider = ApiLoader.getProvider(context)
|
||||
.createMediaSession2ControllerInfo(
|
||||
context, this, uid, pid, packageName, callback);
|
||||
@@ -1060,7 +1063,7 @@ public class MediaSession2 implements AutoCloseable {
|
||||
/**
|
||||
* @return package name of the controller
|
||||
*/
|
||||
public String getPackageName() {
|
||||
public @NonNull String getPackageName() {
|
||||
return mProvider.getPackageName_impl();
|
||||
}
|
||||
|
||||
@@ -1085,7 +1088,7 @@ public class MediaSession2 implements AutoCloseable {
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public ControllerInfoProvider getProvider() {
|
||||
public @NonNull ControllerInfoProvider getProvider() {
|
||||
return mProvider;
|
||||
}
|
||||
|
||||
@@ -1171,7 +1174,7 @@ public class MediaSession2 implements AutoCloseable {
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public CommandButtonProvider getProvider() {
|
||||
public @NonNull CommandButtonProvider getProvider() {
|
||||
return mProvider;
|
||||
}
|
||||
|
||||
@@ -1186,27 +1189,27 @@ public class MediaSession2 implements AutoCloseable {
|
||||
.createMediaSession2CommandButtonBuilder(context, this);
|
||||
}
|
||||
|
||||
public Builder setCommand(Command command) {
|
||||
public @NonNull Builder setCommand(@Nullable Command command) {
|
||||
return mProvider.setCommand_impl(command);
|
||||
}
|
||||
|
||||
public Builder setIconResId(int resId) {
|
||||
public @NonNull Builder setIconResId(int resId) {
|
||||
return mProvider.setIconResId_impl(resId);
|
||||
}
|
||||
|
||||
public Builder setDisplayName(String displayName) {
|
||||
public @NonNull Builder setDisplayName(@Nullable String displayName) {
|
||||
return mProvider.setDisplayName_impl(displayName);
|
||||
}
|
||||
|
||||
public Builder setEnabled(boolean enabled) {
|
||||
public @NonNull Builder setEnabled(boolean enabled) {
|
||||
return mProvider.setEnabled_impl(enabled);
|
||||
}
|
||||
|
||||
public Builder setExtras(Bundle extras) {
|
||||
public @NonNull Builder setExtras(@Nullable Bundle extras) {
|
||||
return mProvider.setExtras_impl(extras);
|
||||
}
|
||||
|
||||
public CommandButton build() {
|
||||
public @NonNull CommandButton build() {
|
||||
return mProvider.build_impl();
|
||||
}
|
||||
}
|
||||
@@ -1365,7 +1368,7 @@ public class MediaSession2 implements AutoCloseable {
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
public MediaSession2Provider getProvider() {
|
||||
public @NonNull MediaSession2Provider getProvider() {
|
||||
return mProvider;
|
||||
}
|
||||
|
||||
@@ -1432,7 +1435,7 @@ public class MediaSession2 implements AutoCloseable {
|
||||
*
|
||||
* @param afr the full request parameters
|
||||
*/
|
||||
public void setAudioFocusRequest(AudioFocusRequest afr) {
|
||||
public void setAudioFocusRequest(@Nullable AudioFocusRequest afr) {
|
||||
// TODO(jaewan): implement this (b/72529899)
|
||||
// mProvider.setAudioFocusRequest_impl(focusGain);
|
||||
}
|
||||
@@ -1745,7 +1748,7 @@ public class MediaSession2 implements AutoCloseable {
|
||||
* @throws IllegalArgumentException if the play list is null
|
||||
* @throws NullPointerException if index is outside play list range
|
||||
*/
|
||||
public void skipToPlaylistItem(MediaItem2 item) {
|
||||
public void skipToPlaylistItem(@NonNull MediaItem2 item) {
|
||||
mProvider.skipToPlaylistItem_impl(item);
|
||||
}
|
||||
|
||||
@@ -1785,7 +1788,7 @@ public class MediaSession2 implements AutoCloseable {
|
||||
*
|
||||
* @throws IllegalArgumentException if the play list is null
|
||||
*/
|
||||
public void removePlaylistItem(MediaItem2 item) {
|
||||
public void removePlaylistItem(@NonNull MediaItem2 item) {
|
||||
mProvider.removePlaylistItem_impl(item);
|
||||
}
|
||||
|
||||
|
||||
@@ -166,7 +166,7 @@ public abstract class MediaSessionService2 extends Service {
|
||||
*
|
||||
* @return a {@link MediaNotification}. If it's {@code null}, notification wouldn't be shown.
|
||||
*/
|
||||
public MediaNotification onUpdateNotification() {
|
||||
public @Nullable MediaNotification onUpdateNotification() {
|
||||
return mProvider.onUpdateNotification_impl();
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ public abstract class MediaSessionService2 extends Service {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returned by {@link #onUpdateNotification()} for making session service forground service
|
||||
* Returned by {@link #onUpdateNotification()} for making session service foreground service
|
||||
* to keep playback running in the background. It's highly recommended to show media style
|
||||
* notification here.
|
||||
*/
|
||||
@@ -229,7 +229,7 @@ public abstract class MediaSessionService2 extends Service {
|
||||
return mProvider.getNotificationId_impl();
|
||||
}
|
||||
|
||||
public Notification getNotification() {
|
||||
public @NonNull Notification getNotification() {
|
||||
return mProvider.getNotification_impl();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,7 +152,8 @@ public final class Rating2 {
|
||||
* or {@link #RATING_PERCENTAGE}.
|
||||
* @return null if an invalid rating style is passed, a new Rating2 instance otherwise.
|
||||
*/
|
||||
public static @Nullable Rating2 newUnratedRating(@NonNull Context context, @Style int ratingStyle) {
|
||||
public static @Nullable Rating2 newUnratedRating(@NonNull Context context,
|
||||
@Style int ratingStyle) {
|
||||
return ApiLoader.getProvider(context).newUnratedRating_Rating2(context, ratingStyle);
|
||||
}
|
||||
|
||||
@@ -225,8 +226,7 @@ public final class Rating2 {
|
||||
* {@link #RATING_3_STARS}, {@link #RATING_4_STARS}, {@link #RATING_5_STARS},
|
||||
* or {@link #RATING_PERCENTAGE}.
|
||||
*/
|
||||
@Style
|
||||
public int getRatingStyle() {
|
||||
public @Style int getRatingStyle() {
|
||||
return mProvider.getRatingStyle_impl();
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package android.media.update;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.content.res.Resources;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
@@ -33,7 +34,10 @@ public final class ApiLoader {
|
||||
|
||||
private ApiLoader() { }
|
||||
|
||||
public static StaticProvider getProvider(Context context) {
|
||||
public static StaticProvider getProvider(@NonNull Context context) {
|
||||
if (context == null) {
|
||||
throw new IllegalArgumentException("context shouldn't be null");
|
||||
}
|
||||
try {
|
||||
return (StaticProvider) getMediaLibraryImpl(context);
|
||||
} catch (PackageManager.NameNotFoundException | ReflectiveOperationException e) {
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package android.media.update;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.media.AudioFocusRequest;
|
||||
import android.media.MediaItem2;
|
||||
import android.media.MediaMetadata2;
|
||||
import android.media.MediaPlayerBase;
|
||||
@@ -51,7 +52,7 @@ public interface MediaSession2Provider extends TransportControlProvider {
|
||||
SessionToken2 getToken_impl();
|
||||
List<ControllerInfo> getConnectedControllers_impl();
|
||||
void setCustomLayout_impl(ControllerInfo controller, List<CommandButton> layout);
|
||||
void setAudioFocusRequest_impl(int focusGain);
|
||||
void setAudioFocusRequest_impl(AudioFocusRequest afr);
|
||||
void setAllowedCommands_impl(ControllerInfo controller, CommandGroup commands);
|
||||
void sendCustomCommand_impl(ControllerInfo controller, Command command, Bundle args,
|
||||
ResultReceiver receiver);
|
||||
|
||||
Reference in New Issue
Block a user