use of com.google.android.libraries.cast.companionlibrary.cast.callbacks.BaseCastConsumer in project Shuttle by timusus.
the class BaseCastManager method disconnectDevice.
/**
* Disconnects from the connected device.
*
* @param stopAppOnExit If {@code true}, the application running on the cast device will be
* stopped when disconnected.
* @param clearPersistedConnectionData If {@code true}, the persisted connection information
* will be cleared as part of this call.
* @param setDefaultRoute If {@code true}, after disconnection, the selected route will be set
* to the Default Route.
*/
public final void disconnectDevice(boolean stopAppOnExit, boolean clearPersistedConnectionData, boolean setDefaultRoute) {
LOGD(TAG, "disconnectDevice(" + clearPersistedConnectionData + "," + setDefaultRoute + ")");
if (mSelectedCastDevice == null) {
return;
}
mSelectedCastDevice = null;
mDeviceName = null;
String message = "disconnectDevice() Disconnect Reason: ";
int reason;
if (mConnectionSuspended) {
message += "Connectivity lost";
reason = DISCONNECT_REASON_CONNECTIVITY;
} else {
switch(mApplicationErrorCode) {
case CastStatusCodes.APPLICATION_NOT_RUNNING:
message += "App was taken over or not available anymore";
reason = DISCONNECT_REASON_APP_NOT_RUNNING;
break;
case NO_APPLICATION_ERROR:
message += "Intentional disconnect";
reason = DISCONNECT_REASON_EXPLICIT;
break;
default:
message += "Other";
reason = DISCONNECT_REASON_OTHER;
}
}
LOGD(TAG, message);
for (BaseCastConsumer consumer : mBaseCastConsumers) {
consumer.onDisconnectionReason(reason);
}
LOGD(TAG, "mConnectionSuspended: " + mConnectionSuspended);
if (!mConnectionSuspended && clearPersistedConnectionData) {
clearPersistedConnectionInfo(CLEAR_ALL);
stopReconnectionService();
}
try {
if ((isConnected() || isConnecting()) && stopAppOnExit) {
LOGD(TAG, "Calling stopApplication");
stopApplication();
}
} catch (NoConnectionException | TransientNetworkDisconnectionException e) {
LOGE(TAG, "Failed to stop the application after disconnecting route", e);
}
onDeviceUnselected();
if (mApiClient != null) {
// will throw an exception
if (mApiClient.isConnected()) {
LOGD(TAG, "Trying to disconnect");
mApiClient.disconnect();
}
if ((mMediaRouter != null) && setDefaultRoute) {
LOGD(TAG, "disconnectDevice(): Setting route to default");
mMediaRouter.selectRoute(mMediaRouter.getDefaultRoute());
}
mApiClient = null;
}
mSessionId = null;
onDisconnected(stopAppOnExit, clearPersistedConnectionData, setDefaultRoute);
}
Aggregations