Loading media/java/android/media/MediaRouter2.java +53 −62 Original line number Diff line number Diff line Loading @@ -1309,18 +1309,24 @@ public final class MediaRouter2 { return; } RoutingController newController; if (sessionInfo.isSystemSession()) { newController = getSystemController(); newController.setRoutingSessionInfo(sessionInfo); RoutingController newController = addRoutingController(sessionInfo); notifyTransfer(oldController, newController); } @NonNull private RoutingController addRoutingController(@NonNull RoutingSessionInfo session) { RoutingController controller; if (session.isSystemSession()) { // mSystemController is never released, so we only need to update its status. mSystemController.setRoutingSessionInfo(session); controller = mSystemController; } else { newController = new RoutingController(sessionInfo); controller = new RoutingController(session); synchronized (mLock) { mNonSystemRoutingControllers.put(newController.getId(), newController); mNonSystemRoutingControllers.put(controller.getId(), controller); } } notifyTransfer(oldController, newController); return controller; } void updateControllerOnHandler(RoutingSessionInfo sessionInfo) { Loading @@ -1329,76 +1335,61 @@ public final class MediaRouter2 { return; } if (sessionInfo.isSystemSession()) { // The session info is sent from SystemMediaRoute2Provider. RoutingController systemController = getSystemController(); systemController.setRoutingSessionInfo(sessionInfo); notifyControllerUpdated(systemController); return; RoutingController controller = getMatchingController(sessionInfo, /* logPrefix */ "updateControllerOnHandler"); if (controller != null) { controller.setRoutingSessionInfo(sessionInfo); notifyControllerUpdated(controller); } RoutingController matchingController; synchronized (mLock) { matchingController = mNonSystemRoutingControllers.get(sessionInfo.getId()); } if (matchingController == null) { Log.w( TAG, "updateControllerOnHandler: Matching controller not found. uniqueSessionId=" + sessionInfo.getId()); void releaseControllerOnHandler(RoutingSessionInfo sessionInfo) { if (sessionInfo == null) { Log.w(TAG, "releaseControllerOnHandler: Ignoring null sessionInfo."); return; } RoutingSessionInfo oldInfo = matchingController.getRoutingSessionInfo(); if (!TextUtils.equals(oldInfo.getProviderId(), sessionInfo.getProviderId())) { Log.w( TAG, "updateControllerOnHandler: Provider IDs are not matched. old=" + oldInfo.getProviderId() + ", new=" + sessionInfo.getProviderId()); return; } RoutingController matchingController = getMatchingController(sessionInfo, /* logPrefix */ "releaseControllerOnHandler"); matchingController.setRoutingSessionInfo(sessionInfo); notifyControllerUpdated(matchingController); if (matchingController != null) { matchingController.releaseInternal(/* shouldReleaseSession= */ false); } void releaseControllerOnHandler(RoutingSessionInfo sessionInfo) { if (sessionInfo == null) { Log.w(TAG, "releaseControllerOnHandler: Ignoring null sessionInfo."); return; } RoutingController matchingController; @Nullable private RoutingController getMatchingController( RoutingSessionInfo sessionInfo, String logPrefix) { if (sessionInfo.isSystemSession()) { return getSystemController(); } else { RoutingController controller; synchronized (mLock) { matchingController = mNonSystemRoutingControllers.get(sessionInfo.getId()); controller = mNonSystemRoutingControllers.get(sessionInfo.getId()); } if (matchingController == null) { if (DEBUG) { Log.d( if (controller == null) { Log.w( TAG, "releaseControllerOnHandler: Matching controller not found. " + "uniqueSessionId=" logPrefix + ": Matching controller not found. uniqueSessionId=" + sessionInfo.getId()); } return; return null; } RoutingSessionInfo oldInfo = matchingController.getRoutingSessionInfo(); RoutingSessionInfo oldInfo = controller.getRoutingSessionInfo(); if (!TextUtils.equals(oldInfo.getProviderId(), sessionInfo.getProviderId())) { Log.w( TAG, "releaseControllerOnHandler: Provider IDs are not matched. old=" logPrefix + ": Provider IDs are not matched. old=" + oldInfo.getProviderId() + ", new=" + sessionInfo.getProviderId()); return; return null; } return controller; } matchingController.releaseInternal(/* shouldReleaseSession= */ false); } void onRequestCreateControllerByManagerOnHandler( Loading Loading
media/java/android/media/MediaRouter2.java +53 −62 Original line number Diff line number Diff line Loading @@ -1309,18 +1309,24 @@ public final class MediaRouter2 { return; } RoutingController newController; if (sessionInfo.isSystemSession()) { newController = getSystemController(); newController.setRoutingSessionInfo(sessionInfo); RoutingController newController = addRoutingController(sessionInfo); notifyTransfer(oldController, newController); } @NonNull private RoutingController addRoutingController(@NonNull RoutingSessionInfo session) { RoutingController controller; if (session.isSystemSession()) { // mSystemController is never released, so we only need to update its status. mSystemController.setRoutingSessionInfo(session); controller = mSystemController; } else { newController = new RoutingController(sessionInfo); controller = new RoutingController(session); synchronized (mLock) { mNonSystemRoutingControllers.put(newController.getId(), newController); mNonSystemRoutingControllers.put(controller.getId(), controller); } } notifyTransfer(oldController, newController); return controller; } void updateControllerOnHandler(RoutingSessionInfo sessionInfo) { Loading @@ -1329,76 +1335,61 @@ public final class MediaRouter2 { return; } if (sessionInfo.isSystemSession()) { // The session info is sent from SystemMediaRoute2Provider. RoutingController systemController = getSystemController(); systemController.setRoutingSessionInfo(sessionInfo); notifyControllerUpdated(systemController); return; RoutingController controller = getMatchingController(sessionInfo, /* logPrefix */ "updateControllerOnHandler"); if (controller != null) { controller.setRoutingSessionInfo(sessionInfo); notifyControllerUpdated(controller); } RoutingController matchingController; synchronized (mLock) { matchingController = mNonSystemRoutingControllers.get(sessionInfo.getId()); } if (matchingController == null) { Log.w( TAG, "updateControllerOnHandler: Matching controller not found. uniqueSessionId=" + sessionInfo.getId()); void releaseControllerOnHandler(RoutingSessionInfo sessionInfo) { if (sessionInfo == null) { Log.w(TAG, "releaseControllerOnHandler: Ignoring null sessionInfo."); return; } RoutingSessionInfo oldInfo = matchingController.getRoutingSessionInfo(); if (!TextUtils.equals(oldInfo.getProviderId(), sessionInfo.getProviderId())) { Log.w( TAG, "updateControllerOnHandler: Provider IDs are not matched. old=" + oldInfo.getProviderId() + ", new=" + sessionInfo.getProviderId()); return; } RoutingController matchingController = getMatchingController(sessionInfo, /* logPrefix */ "releaseControllerOnHandler"); matchingController.setRoutingSessionInfo(sessionInfo); notifyControllerUpdated(matchingController); if (matchingController != null) { matchingController.releaseInternal(/* shouldReleaseSession= */ false); } void releaseControllerOnHandler(RoutingSessionInfo sessionInfo) { if (sessionInfo == null) { Log.w(TAG, "releaseControllerOnHandler: Ignoring null sessionInfo."); return; } RoutingController matchingController; @Nullable private RoutingController getMatchingController( RoutingSessionInfo sessionInfo, String logPrefix) { if (sessionInfo.isSystemSession()) { return getSystemController(); } else { RoutingController controller; synchronized (mLock) { matchingController = mNonSystemRoutingControllers.get(sessionInfo.getId()); controller = mNonSystemRoutingControllers.get(sessionInfo.getId()); } if (matchingController == null) { if (DEBUG) { Log.d( if (controller == null) { Log.w( TAG, "releaseControllerOnHandler: Matching controller not found. " + "uniqueSessionId=" logPrefix + ": Matching controller not found. uniqueSessionId=" + sessionInfo.getId()); } return; return null; } RoutingSessionInfo oldInfo = matchingController.getRoutingSessionInfo(); RoutingSessionInfo oldInfo = controller.getRoutingSessionInfo(); if (!TextUtils.equals(oldInfo.getProviderId(), sessionInfo.getProviderId())) { Log.w( TAG, "releaseControllerOnHandler: Provider IDs are not matched. old=" logPrefix + ": Provider IDs are not matched. old=" + oldInfo.getProviderId() + ", new=" + sessionInfo.getProviderId()); return; return null; } return controller; } matchingController.releaseInternal(/* shouldReleaseSession= */ false); } void onRequestCreateControllerByManagerOnHandler( Loading