Merge "Prevent MediaRoute2ProviderService#onReleaseSession() from being called twice" into rvc-dev am: f4314e3ae9 am: 37c3f450b2
Change-Id: I1c592bfac1bdd00584cd4d55bce8251409583dd5
This commit is contained in:
@@ -409,7 +409,7 @@ public final class MediaRouter2 {
|
|||||||
|
|
||||||
// TODO: Check thread-safety
|
// TODO: Check thread-safety
|
||||||
if (!mRoutes.containsKey(route.getId())) {
|
if (!mRoutes.containsKey(route.getId())) {
|
||||||
notifyTransferFailed(route);
|
notifyTransferFailure(route);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (controller.getRoutingSessionInfo().getTransferableRoutes().contains(route.getId())) {
|
if (controller.getRoutingSessionInfo().getTransferableRoutes().contains(route.getId())) {
|
||||||
@@ -588,14 +588,14 @@ public final class MediaRouter2 {
|
|||||||
if (sessionInfo == null) {
|
if (sessionInfo == null) {
|
||||||
// TODO: We may need to distinguish between failure and rejection.
|
// TODO: We may need to distinguish between failure and rejection.
|
||||||
// One way can be introducing 'reason'.
|
// One way can be introducing 'reason'.
|
||||||
notifyTransferFailed(requestedRoute);
|
notifyTransferFailure(requestedRoute);
|
||||||
return;
|
return;
|
||||||
} else if (!sessionInfo.getSelectedRoutes().contains(requestedRoute.getId())) {
|
} else if (!sessionInfo.getSelectedRoutes().contains(requestedRoute.getId())) {
|
||||||
Log.w(TAG, "The session does not contain the requested route. "
|
Log.w(TAG, "The session does not contain the requested route. "
|
||||||
+ "(requestedRouteId=" + requestedRoute.getId()
|
+ "(requestedRouteId=" + requestedRoute.getId()
|
||||||
+ ", actualRoutes=" + sessionInfo.getSelectedRoutes()
|
+ ", actualRoutes=" + sessionInfo.getSelectedRoutes()
|
||||||
+ ")");
|
+ ")");
|
||||||
notifyTransferFailed(requestedRoute);
|
notifyTransferFailure(requestedRoute);
|
||||||
return;
|
return;
|
||||||
} else if (!TextUtils.equals(requestedRoute.getProviderId(),
|
} else if (!TextUtils.equals(requestedRoute.getProviderId(),
|
||||||
sessionInfo.getProviderId())) {
|
sessionInfo.getProviderId())) {
|
||||||
@@ -603,7 +603,7 @@ public final class MediaRouter2 {
|
|||||||
+ "(requested route's providerId=" + requestedRoute.getProviderId()
|
+ "(requested route's providerId=" + requestedRoute.getProviderId()
|
||||||
+ ", actual providerId=" + sessionInfo.getProviderId()
|
+ ", actual providerId=" + sessionInfo.getProviderId()
|
||||||
+ ")");
|
+ ")");
|
||||||
notifyTransferFailed(requestedRoute);
|
notifyTransferFailure(requestedRoute);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -619,7 +619,7 @@ public final class MediaRouter2 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//TODO: Determine oldController properly when transfer is launched by Output Switcher.
|
//TODO: Determine oldController properly when transfer is launched by Output Switcher.
|
||||||
notifyTransferred(matchingRequest != null ? matchingRequest.mController :
|
notifyTransfer(matchingRequest != null ? matchingRequest.mController :
|
||||||
getSystemController(), newController);
|
getSystemController(), newController);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -687,15 +687,7 @@ public final class MediaRouter2 {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean removed;
|
matchingController.releaseInternal(/* shouldReleaseSession= */ false);
|
||||||
synchronized (sRouterLock) {
|
|
||||||
removed = mRoutingControllers.remove(uniqueSessionId, matchingController);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (removed) {
|
|
||||||
matchingController.release();
|
|
||||||
notifyStopped(matchingController);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<MediaRoute2Info> filterRoutes(List<MediaRoute2Info> routes,
|
private List<MediaRoute2Info> filterRoutes(List<MediaRoute2Info> routes,
|
||||||
@@ -736,22 +728,21 @@ public final class MediaRouter2 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void notifyTransferred(RoutingController oldController,
|
private void notifyTransfer(RoutingController oldController, RoutingController newController) {
|
||||||
RoutingController newController) {
|
|
||||||
for (TransferCallbackRecord record: mTransferCallbackRecords) {
|
for (TransferCallbackRecord record: mTransferCallbackRecords) {
|
||||||
record.mExecutor.execute(
|
record.mExecutor.execute(
|
||||||
() -> record.mTransferCallback.onTransfer(oldController, newController));
|
() -> record.mTransferCallback.onTransfer(oldController, newController));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void notifyTransferFailed(MediaRoute2Info route) {
|
private void notifyTransferFailure(MediaRoute2Info route) {
|
||||||
for (TransferCallbackRecord record: mTransferCallbackRecords) {
|
for (TransferCallbackRecord record: mTransferCallbackRecords) {
|
||||||
record.mExecutor.execute(
|
record.mExecutor.execute(
|
||||||
() -> record.mTransferCallback.onTransferFailure(route));
|
() -> record.mTransferCallback.onTransferFailure(route));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void notifyStopped(RoutingController controller) {
|
private void notifyStop(RoutingController controller) {
|
||||||
for (TransferCallbackRecord record: mTransferCallbackRecords) {
|
for (TransferCallbackRecord record: mTransferCallbackRecords) {
|
||||||
record.mExecutor.execute(
|
record.mExecutor.execute(
|
||||||
() -> record.mTransferCallback.onStop(controller));
|
() -> record.mTransferCallback.onStop(controller));
|
||||||
@@ -1189,32 +1180,38 @@ public final class MediaRouter2 {
|
|||||||
*/
|
*/
|
||||||
// TODO: Add tests using {@link MediaRouter2Manager#getActiveSessions()}.
|
// TODO: Add tests using {@link MediaRouter2Manager#getActiveSessions()}.
|
||||||
public void release() {
|
public void release() {
|
||||||
|
releaseInternal(/* shouldReleaseSession= */ true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void releaseInternal(boolean shouldReleaseSession) {
|
||||||
synchronized (mControllerLock) {
|
synchronized (mControllerLock) {
|
||||||
if (mIsReleased) {
|
if (mIsReleased) {
|
||||||
Log.w(TAG, "release() called on released controller. Ignoring.");
|
Log.w(TAG, "releaseInternal() called on released controller. Ignoring.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mIsReleased = true;
|
mIsReleased = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
MediaRouter2Stub stub;
|
MediaRouter2Stub stub;
|
||||||
boolean removed;
|
|
||||||
synchronized (sRouterLock) {
|
synchronized (sRouterLock) {
|
||||||
removed = mRoutingControllers.remove(getId(), this);
|
mRoutingControllers.remove(getId(), this);
|
||||||
stub = mStub;
|
stub = mStub;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (removed) {
|
if (shouldReleaseSession && stub != null) {
|
||||||
mHandler.post(() -> notifyStopped(RoutingController.this));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stub != null) {
|
|
||||||
try {
|
try {
|
||||||
mMediaRouterService.releaseSessionWithRouter2(stub, getId());
|
mMediaRouterService.releaseSessionWithRouter2(stub, getId());
|
||||||
} catch (RemoteException ex) {
|
} catch (RemoteException ex) {
|
||||||
Log.e(TAG, "Unable to notify of controller release", ex);
|
Log.e(TAG, "Unable to release session", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Thread.currentThread() == mHandler.getLooper().getThread()) {
|
||||||
|
notifyStop(this);
|
||||||
|
} else {
|
||||||
|
mHandler.sendMessage(obtainMessage(MediaRouter2::notifyStop, MediaRouter2.this,
|
||||||
|
RoutingController.this));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user