Methods Summary |
---|
private void | addSubscription(java.lang.String id, android.service.media.MediaBrowserService$ConnectionRecord connection)Save the subscription and if it is a new subscription send the results.
// Save the subscription
final boolean added = connection.subscriptions.add(id);
// If this is a new subscription, send the results
if (added) {
performLoadChildren(id, connection);
}
|
public void | dump(java.io.FileDescriptor fd, java.io.PrintWriter writer, java.lang.String[] args)
|
public MediaSession.Token | getSessionToken()Gets the session token, or null if it has not yet been created
or if it has been destroyed.
return mSession;
|
private boolean | isValidPackage(java.lang.String pkg, int uid)Return whether the given package is one of the ones that is owned by the uid.
if (pkg == null) {
return false;
}
final PackageManager pm = getPackageManager();
final String[] packages = pm.getPackagesForUid(uid);
final int N = packages.length;
for (int i=0; i<N; i++) {
if (packages[i].equals(pkg)) {
return true;
}
}
return false;
|
public void | notifyChildrenChanged(java.lang.String parentId)Notifies all connected media browsers that the children of
the specified parent id have changed in some way.
This will cause browsers to fetch subscribed content again.
if (parentId == null) {
throw new IllegalArgumentException("parentId cannot be null in notifyChildrenChanged");
}
mHandler.post(new Runnable() {
@Override
public void run() {
for (IBinder binder : mConnections.keySet()) {
ConnectionRecord connection = mConnections.get(binder);
if (connection.subscriptions.contains(parentId)) {
performLoadChildren(parentId, connection);
}
}
}
});
|
public android.os.IBinder | onBind(android.content.Intent intent)
if (SERVICE_INTERFACE.equals(intent.getAction())) {
return mBinder;
}
return null;
|
public void | onCreate()
super.onCreate();
mBinder = new ServiceBinder();
|
public abstract android.service.media.MediaBrowserService$BrowserRoot | onGetRoot(java.lang.String clientPackageName, int clientUid, android.os.Bundle rootHints)Called to get the root information for browsing by a particular client.
The implementation should verify that the client package has
permission to access browse media information before returning
the root id; it should return null if the client is not
allowed to access this information.
|
public abstract void | onLoadChildren(java.lang.String parentId, android.service.media.MediaBrowserService$Result result)Called to get information about the children of a media item.
Implementations must call result.{@link Result#sendResult result.sendResult} with the list
of children. If loading the children will be an expensive operation that should be performed
on another thread, result.{@link Result#detach result.detach} may be called before returning
from this function, and then {@link Result#sendResult result.sendResult} called when
the loading is complete.
|
private void | performLoadChildren(java.lang.String parentId, android.service.media.MediaBrowserService$ConnectionRecord connection)Call onLoadChildren and then send the results back to the connection.
Callers must make sure that this connection is still connected.
final Result<List<MediaBrowser.MediaItem>> result
= new Result<List<MediaBrowser.MediaItem>>(parentId) {
@Override
void onResultSent(List<MediaBrowser.MediaItem> list) {
if (list == null) {
throw new IllegalStateException("onLoadChildren sent null list for id "
+ parentId);
}
if (mConnections.get(connection.callbacks.asBinder()) != connection) {
if (DBG) {
Log.d(TAG, "Not sending onLoadChildren result for connection that has"
+ " been disconnected. pkg=" + connection.pkg + " id=" + parentId);
}
return;
}
final ParceledListSlice<MediaBrowser.MediaItem> pls = new ParceledListSlice(list);
try {
connection.callbacks.onLoadChildren(parentId, pls);
} catch (RemoteException ex) {
// The other side is in the process of crashing.
Log.w(TAG, "Calling onLoadChildren() failed for id=" + parentId
+ " package=" + connection.pkg);
}
}
};
onLoadChildren(parentId, result);
if (!result.isDone()) {
throw new IllegalStateException("onLoadChildren must call detach() or sendResult()"
+ " before returning for package=" + connection.pkg + " id=" + parentId);
}
|
public void | setSessionToken(MediaSession.Token token)Call to set the media session.
This should be called as soon as possible during the service's startup.
It may only be called once.
if (token == null) {
throw new IllegalArgumentException("Session token may not be null.");
}
if (mSession != null) {
throw new IllegalStateException("The session token has already been set.");
}
mSession = token;
mHandler.post(new Runnable() {
@Override
public void run() {
for (IBinder key : mConnections.keySet()) {
ConnectionRecord connection = mConnections.get(key);
try {
connection.callbacks.onConnect(connection.root.getRootId(), token,
connection.root.getExtras());
} catch (RemoteException e) {
Log.w(TAG, "Connection for " + connection.pkg + " is no longer valid.");
mConnections.remove(key);
}
}
}
});
|