private void setSelectedRouteLocked(IMediaRouterClient client, String routeId, boolean explicit) { ClientRecord clientRecord = mAllClientRecords.get(client.asBinder()); if (clientRecord != null) { final String oldRouteId = clientRecord.mSelectedRouteId; if (!Objects.equals(routeId, oldRouteId)) { if (DEBUG) { Slog.d(TAG, clientRecord + ": Set selected route, routeId=" + routeId + ", oldRouteId=" + oldRouteId + ", explicit=" + explicit); } clientRecord.mSelectedRouteId = routeId; if (explicit) { // Any app can disconnect from the globally selected route. if (oldRouteId != null) { clientRecord.mUserRecord.mHandler.obtainMessage( UserHandler.MSG_UNSELECT_ROUTE, oldRouteId).sendToTarget(); } // Only let the system connect to new global routes for now. // A similar check exists in the display manager for wifi display. if (routeId != null && clientRecord.mTrusted) { clientRecord.mUserRecord.mHandler.obtainMessage( UserHandler.MSG_SELECT_ROUTE, routeId).sendToTarget(); } } } } }