summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--media/java/android/media/browse/MediaBrowser.java34
-rw-r--r--media/java/android/service/media/MediaBrowserService.java34
2 files changed, 38 insertions, 30 deletions
diff --git a/media/java/android/media/browse/MediaBrowser.java b/media/java/android/media/browse/MediaBrowser.java
index 93e6dacdd98c..80b3ffc23e31 100644
--- a/media/java/android/media/browse/MediaBrowser.java
+++ b/media/java/android/media/browse/MediaBrowser.java
@@ -115,7 +115,7 @@ public final class MediaBrowser {
* @param callback The connection callback.
* @param rootHints An optional bundle of service-specific arguments to send
* to the media browse service when connecting and retrieving the root id
- * for browsing, or null if none. The contents of this bundle may affect
+ * for browsing, or null if none. The contents of this bundle may affect
* the information returned when browsing.
*/
public MediaBrowser(Context context, ComponentName serviceComponent,
@@ -178,9 +178,9 @@ public final class MediaBrowser {
}
if (!bound) {
- // Tell them that it didn't work. We are already on the main thread,
- // but we don't want to do callbacks inside of connect(). So post it,
- // and then check that we are on the same ServiceConnection. We know
+ // Tell them that it didn't work. We are already on the main thread,
+ // but we don't want to do callbacks inside of connect(). So post it,
+ // and then check that we are on the same ServiceConnection. We know
// we won't also get an onServiceConnected or onServiceDisconnected,
// so we won't be doing double callbacks.
mHandler.post(new Runnable() {
@@ -207,13 +207,13 @@ public final class MediaBrowser {
*/
public void disconnect() {
// It's ok to call this any state, because allowing this lets apps not have
- // to check isConnected() unnecessarily. They won't appreciate the extra
- // assertions for this. We do everything we can here to go back to a sane state.
+ // to check isConnected() unnecessarily. They won't appreciate the extra
+ // assertions for this. We do everything we can here to go back to a sane state.
if (mServiceCallbacks != null) {
try {
mServiceBinder.disconnect(mServiceCallbacks);
} catch (RemoteException ex) {
- // We are disconnecting anyway. Log, just for posterity but it's not
+ // We are disconnecting anyway. Log, just for posterity but it's not
// a big problem.
Log.w(TAG, "RemoteException during connect for " + mServiceComponent);
}
@@ -227,12 +227,12 @@ public final class MediaBrowser {
}
/**
- * Null out the variables and unbind from the service. This doesn't include
+ * Null out the variables and unbind from the service. This doesn't include
* calling disconnect on the service, because we only try to do that in the
* clean shutdown cases.
* <p>
* Everywhere that calls this EXCEPT for disconnect() should follow it with
- * a call to mCallback.onConnectionFailed(). Disconnect doesn't do that callback
+ * a call to mCallback.onConnectionFailed(). Disconnect doesn't do that callback
* for a clean shutdown, but everywhere else is a dirty shutdown and should
* notify the app.
*/
@@ -455,8 +455,8 @@ public final class MediaBrowser {
private void subscribeInternal(String parentId, Bundle options, SubscriptionCallback callback) {
// Check arguments.
- if (parentId == null) {
- throw new IllegalArgumentException("parentId is null");
+ if (TextUtils.isEmpty(parentId)) {
+ throw new IllegalArgumentException("parentId is empty.");
}
if (callback == null) {
throw new IllegalArgumentException("callback is null");
@@ -659,7 +659,7 @@ public final class MediaBrowser {
}
/**
- * Return true if {@code callback} is the current ServiceCallbacks. Also logs if it's not.
+ * Return true if {@code callback} is the current ServiceCallbacks. Also logs if it's not.
*/
private boolean isCurrent(IMediaBrowserServiceCallbacks callback, String funcName) {
if (mServiceCallbacks != callback) {
@@ -955,8 +955,8 @@ public final class MediaBrowser {
mServiceCallbacks);
} catch (RemoteException ex) {
// Connect failed, which isn't good. But the auto-reconnect on the service
- // will take over and we will come back. We will also get the
- // onServiceDisconnected, which has all the cleanup code. So let that do
+ // will take over and we will come back. We will also get the
+ // onServiceDisconnected, which has all the cleanup code. So let that do
// it.
Log.w(TAG, "RemoteException during connect for " + mServiceComponent);
if (DBG) {
@@ -1005,7 +1005,7 @@ public final class MediaBrowser {
}
/**
- * Return true if this is the current ServiceConnection. Also logs if it's not.
+ * Return true if this is the current ServiceConnection. Also logs if it's not.
*/
private boolean isCurrent(String funcName) {
if (mServiceConnection != this) {
@@ -1031,7 +1031,7 @@ public final class MediaBrowser {
}
/**
- * The other side has acknowledged our connection. The parameters to this function
+ * The other side has acknowledged our connection. The parameters to this function
* are the initial data as requested.
*/
@Override
@@ -1044,7 +1044,7 @@ public final class MediaBrowser {
}
/**
- * The other side does not like us. Tell the app via onConnectionFailed.
+ * The other side does not like us. Tell the app via onConnectionFailed.
*/
@Override
public void onConnectFailed() {
diff --git a/media/java/android/service/media/MediaBrowserService.java b/media/java/android/service/media/MediaBrowserService.java
index 299b77071c55..0393c943784d 100644
--- a/media/java/android/service/media/MediaBrowserService.java
+++ b/media/java/android/service/media/MediaBrowserService.java
@@ -16,6 +16,7 @@
package android.service.media;
+import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SdkConstant;
@@ -41,6 +42,8 @@ import android.util.Log;
import java.io.FileDescriptor;
import java.io.PrintWriter;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -49,7 +52,7 @@ import java.util.List;
* Base class for media browse services.
* <p>
* Media browse services enable applications to browse media content provided by an application
- * and ask the application to start playing it. They may also be used to control content that
+ * and ask the application to start playing it. They may also be used to control content that
* is already playing by way of a {@link MediaSession}.
* </p>
*
@@ -86,6 +89,11 @@ public abstract class MediaBrowserService extends Service {
private static final int RESULT_FLAG_OPTION_NOT_HANDLED = 0x00000001;
+ /** @hide */
+ @Retention(RetentionPolicy.SOURCE)
+ @IntDef(flag=true, value = { RESULT_FLAG_OPTION_NOT_HANDLED })
+ private @interface ResultFlags { }
+
private final ArrayMap<IBinder, ConnectionRecord> mConnections = new ArrayMap<>();
private final Handler mHandler = new Handler();
private ServiceBinder mBinder;
@@ -106,10 +114,10 @@ public abstract class MediaBrowserService extends Service {
* Completion handler for asynchronous callback methods in {@link MediaBrowserService}.
* <p>
* Each of the methods that takes one of these to send the result must call
- * {@link #sendResult} to respond to the caller with the given results. If those
+ * {@link #sendResult} to respond to the caller with the given results. If those
* functions return without calling {@link #sendResult}, they must instead call
* {@link #detach} before returning, and then may call {@link #sendResult} when
- * they are done. If more than one of those methods is called, an exception will
+ * they are done. If more than one of those methods is called, an exception will
* be thrown.
*
* @see MediaBrowserService#onLoadChildren
@@ -119,7 +127,7 @@ public abstract class MediaBrowserService extends Service {
private Object mDebug;
private boolean mDetachCalled;
private boolean mSendResultCalled;
- private int mFlag;
+ private int mFlags;
Result(Object debug) {
mDebug = debug;
@@ -133,7 +141,7 @@ public abstract class MediaBrowserService extends Service {
throw new IllegalStateException("sendResult() called twice for: " + mDebug);
}
mSendResultCalled = true;
- onResultSent(result, mFlag);
+ onResultSent(result, mFlags);
}
/**
@@ -156,15 +164,15 @@ public abstract class MediaBrowserService extends Service {
return mDetachCalled || mSendResultCalled;
}
- void setFlag(int flag) {
- mFlag = flag;
+ void setFlags(@ResultFlags int flags) {
+ mFlags = flags;
}
/**
* Called when the result is sent, after assertions about not being called twice
* have happened.
*/
- void onResultSent(T result, int flag) {
+ void onResultSent(T result, @ResultFlags int flags) {
}
}
@@ -184,7 +192,7 @@ public abstract class MediaBrowserService extends Service {
public void run() {
final IBinder b = callbacks.asBinder();
- // Clear out the old subscriptions. We are getting new ones.
+ // Clear out the old subscriptions. We are getting new ones.
mConnections.remove(b);
final ConnectionRecord connection = new ConnectionRecord();
@@ -228,7 +236,7 @@ public abstract class MediaBrowserService extends Service {
public void run() {
final IBinder b = callbacks.asBinder();
- // Clear out the old subscriptions. We are getting new ones.
+ // Clear out the old subscriptions. We are getting new ones.
final ConnectionRecord old = mConnections.remove(b);
if (old != null) {
// TODO
@@ -388,7 +396,7 @@ public abstract class MediaBrowserService extends Service {
// To support backward compatibility, when the implementation of MediaBrowserService doesn't
// override onLoadChildren() with options, onLoadChildren() without options will be used
// instead, and the options will be applied in the implementation of result.onResultSent().
- result.setFlag(RESULT_FLAG_OPTION_NOT_HANDLED);
+ result.setFlags(RESULT_FLAG_OPTION_NOT_HANDLED);
onLoadChildren(parentId, result);
}
@@ -574,7 +582,7 @@ public abstract class MediaBrowserService extends Service {
final Result<List<MediaBrowser.MediaItem>> result
= new Result<List<MediaBrowser.MediaItem>>(parentId) {
@Override
- void onResultSent(List<MediaBrowser.MediaItem> list, int flag) {
+ void onResultSent(List<MediaBrowser.MediaItem> list, @ResultFlags int flag) {
if (mConnections.get(connection.callbacks.asBinder()) != connection) {
if (DBG) {
Log.d(TAG, "Not sending onLoadChildren result for connection that has"
@@ -639,7 +647,7 @@ public abstract class MediaBrowserService extends Service {
final Result<MediaBrowser.MediaItem> result =
new Result<MediaBrowser.MediaItem>(itemId) {
@Override
- void onResultSent(MediaBrowser.MediaItem item, int flag) {
+ void onResultSent(MediaBrowser.MediaItem item, @ResultFlags int flag) {
Bundle bundle = new Bundle();
bundle.putParcelable(KEY_MEDIA_ITEM, item);
receiver.send(0, bundle);