Methods Summary |
---|
private void | attachControllersToConnection()
int count = mControllers.size();
for (int i = 0; i < count; i++) {
mControllers.get(i).attachConnection(mActiveConnection);
}
|
private void | bind()
if (!mBound) {
if (DEBUG) {
Log.d(TAG, this + ": Binding");
}
Intent service = new Intent(MediaRouteProviderProtocol.SERVICE_INTERFACE);
service.setComponent(mComponentName);
try {
mBound = getContext().bindService(service, this, Context.BIND_AUTO_CREATE);
if (!mBound && DEBUG) {
Log.d(TAG, this + ": Bind failed");
}
} catch (SecurityException ex) {
if (DEBUG) {
Log.d(TAG, this + ": Bind failed", ex);
}
}
}
|
private void | detachControllersFromConnection()
int count = mControllers.size();
for (int i = 0; i < count; i++) {
mControllers.get(i).detachConnection();
}
|
private void | disconnect()
if (mActiveConnection != null) {
setDescriptor(null);
mConnectionReady = false;
detachControllersFromConnection();
mActiveConnection.dispose();
mActiveConnection = null;
}
|
public boolean | hasComponentName(java.lang.String packageName, java.lang.String className)
return mComponentName.getPackageName().equals(packageName)
&& mComponentName.getClassName().equals(className);
|
private void | onConnectionDescriptorChanged(android.support.v7.media.RegisteredMediaRouteProvider$Connection connection, MediaRouteProviderDescriptor descriptor)
if (mActiveConnection == connection) {
if (DEBUG) {
Log.d(TAG, this + ": Descriptor changed, descriptor=" + descriptor);
}
setDescriptor(descriptor);
}
|
private void | onConnectionDied(android.support.v7.media.RegisteredMediaRouteProvider$Connection connection)
if (mActiveConnection == connection) {
if (DEBUG) {
Log.d(TAG, this + ": Service connection died");
}
disconnect();
}
|
private void | onConnectionError(android.support.v7.media.RegisteredMediaRouteProvider$Connection connection, java.lang.String error)
if (mActiveConnection == connection) {
if (DEBUG) {
Log.d(TAG, this + ": Service connection error - " + error);
}
unbind();
}
|
private void | onConnectionReady(android.support.v7.media.RegisteredMediaRouteProvider$Connection connection)
if (mActiveConnection == connection) {
mConnectionReady = true;
attachControllersToConnection();
MediaRouteDiscoveryRequest request = getDiscoveryRequest();
if (request != null) {
mActiveConnection.setDiscoveryRequest(request);
}
}
|
private void | onControllerReleased(android.support.v7.media.RegisteredMediaRouteProvider$Controller controller)
mControllers.remove(controller);
controller.detachConnection();
updateBinding();
|
public RouteController | onCreateRouteController(java.lang.String routeId)
MediaRouteProviderDescriptor descriptor = getDescriptor();
if (descriptor != null) {
List<MediaRouteDescriptor> routes = descriptor.getRoutes();
final int count = routes.size();
for (int i = 0; i < count; i++) {
final MediaRouteDescriptor route = routes.get(i);
if (route.getId().equals(routeId)) {
Controller controller = new Controller(routeId);
mControllers.add(controller);
if (mConnectionReady) {
controller.attachConnection(mActiveConnection);
}
updateBinding();
return controller;
}
}
}
return null;
|
public void | onDiscoveryRequestChanged(MediaRouteDiscoveryRequest request)
if (mConnectionReady) {
mActiveConnection.setDiscoveryRequest(request);
}
updateBinding();
|
public void | onServiceConnected(android.content.ComponentName name, android.os.IBinder service)
if (DEBUG) {
Log.d(TAG, this + ": Connected");
}
if (mBound) {
disconnect();
Messenger messenger = (service != null ? new Messenger(service) : null);
if (isValidRemoteMessenger(messenger)) {
Connection connection = new Connection(messenger);
if (connection.register()) {
mActiveConnection = connection;
} else {
if (DEBUG) {
Log.d(TAG, this + ": Registration failed");
}
}
} else {
Log.e(TAG, this + ": Service returned invalid messenger binder");
}
}
|
public void | onServiceDisconnected(android.content.ComponentName name)
if (DEBUG) {
Log.d(TAG, this + ": Service disconnected");
}
disconnect();
|
public void | rebindIfDisconnected()
if (mActiveConnection == null && shouldBind()) {
unbind();
bind();
}
|
private boolean | shouldBind()
if (mStarted) {
// Bind whenever there is a discovery request.
if (getDiscoveryRequest() != null) {
return true;
}
// Bind whenever the application has an active route controller.
// This means that one of this provider's routes is selected.
if (!mControllers.isEmpty()) {
return true;
}
}
return false;
|
public void | start()
if (!mStarted) {
if (DEBUG) {
Log.d(TAG, this + ": Starting");
}
mStarted = true;
updateBinding();
}
|
public void | stop()
if (mStarted) {
if (DEBUG) {
Log.d(TAG, this + ": Stopping");
}
mStarted = false;
updateBinding();
}
|
public java.lang.String | toString()
return "Service connection " + mComponentName.flattenToShortString();
|
private void | unbind()
if (mBound) {
if (DEBUG) {
Log.d(TAG, this + ": Unbinding");
}
mBound = false;
disconnect();
getContext().unbindService(this);
}
|
private void | updateBinding()
if (shouldBind()) {
bind();
} else {
unbind();
}
|