Remove unnecessary if checks

This is a cherrypick of commit 58fb7d617d.

Bug: 239926177
Test: atest mediaroutertest CtsMediaBetterTogetherTestCases
Change-Id: I8478669747ca291d92b825e205f58add76e9a2a2
Merged-In: I8478669747ca291d92b825e205f58add76e9a2a2
This commit is contained in:
Santiago Seifert
2022-07-22 13:44:58 +00:00
parent cbca646e97
commit 0952e0377e

View File

@@ -166,9 +166,8 @@ public final class MediaRouter2Manager {
*/ */
public void registerScanRequest() { public void registerScanRequest() {
if (mScanRequestCount.getAndIncrement() == 0) { if (mScanRequestCount.getAndIncrement() == 0) {
Client client = getOrCreateClient();
try { try {
mMediaRouterService.startScan(client); mMediaRouterService.startScan(getOrCreateClient());
} catch (RemoteException ex) { } catch (RemoteException ex) {
throw ex.rethrowFromSystemServer(); throw ex.rethrowFromSystemServer();
} }
@@ -194,9 +193,8 @@ public final class MediaRouter2Manager {
} }
}) })
== 0) { == 0) {
Client client = getOrCreateClient();
try { try {
mMediaRouterService.stopScan(client); mMediaRouterService.stopScan(getOrCreateClient());
} catch (RemoteException ex) { } catch (RemoteException ex) {
throw ex.rethrowFromSystemServer(); throw ex.rethrowFromSystemServer();
} }
@@ -425,16 +423,12 @@ public final class MediaRouter2Manager {
*/ */
@NonNull @NonNull
public List<RoutingSessionInfo> getRemoteSessions() { public List<RoutingSessionInfo> getRemoteSessions() {
Client client = getOrCreateClient();
if (client != null) {
try { try {
return mMediaRouterService.getRemoteSessions(client); return mMediaRouterService.getRemoteSessions(getOrCreateClient());
} catch (RemoteException ex) { } catch (RemoteException ex) {
throw ex.rethrowFromSystemServer(); throw ex.rethrowFromSystemServer();
} }
} }
return Collections.emptyList();
}
/** /**
* Gets the list of all discovered routes. * Gets the list of all discovered routes.
@@ -516,16 +510,14 @@ public final class MediaRouter2Manager {
return; return;
} }
Client client = getOrCreateClient();
if (client != null) {
try { try {
int requestId = mNextRequestId.getAndIncrement(); int requestId = mNextRequestId.getAndIncrement();
mMediaRouterService.setRouteVolumeWithManager(client, requestId, route, volume); mMediaRouterService.setRouteVolumeWithManager(
getOrCreateClient(), requestId, route, volume);
} catch (RemoteException ex) { } catch (RemoteException ex) {
throw ex.rethrowFromSystemServer(); throw ex.rethrowFromSystemServer();
} }
} }
}
/** /**
* Requests a volume change for a routing session asynchronously. * Requests a volume change for a routing session asynchronously.
@@ -545,17 +537,14 @@ public final class MediaRouter2Manager {
return; return;
} }
Client client = getOrCreateClient();
if (client != null) {
try { try {
int requestId = mNextRequestId.getAndIncrement(); int requestId = mNextRequestId.getAndIncrement();
mMediaRouterService.setSessionVolumeWithManager( mMediaRouterService.setSessionVolumeWithManager(
client, requestId, sessionInfo.getId(), volume); getOrCreateClient(), requestId, sessionInfo.getId(), volume);
} catch (RemoteException ex) { } catch (RemoteException ex) {
throw ex.rethrowFromSystemServer(); throw ex.rethrowFromSystemServer();
} }
} }
}
void addRoutesOnHandler(List<MediaRoute2Info> routes) { void addRoutesOnHandler(List<MediaRoute2Info> routes) {
synchronized (mRoutesLock) { synchronized (mRoutesLock) {
@@ -810,17 +799,14 @@ public final class MediaRouter2Manager {
return; return;
} }
Client client = getOrCreateClient();
if (client != null) {
try { try {
int requestId = mNextRequestId.getAndIncrement(); int requestId = mNextRequestId.getAndIncrement();
mMediaRouterService.selectRouteWithManager( mMediaRouterService.selectRouteWithManager(
client, requestId, sessionInfo.getId(), route); getOrCreateClient(), requestId, sessionInfo.getId(), route);
} catch (RemoteException ex) { } catch (RemoteException ex) {
throw ex.rethrowFromSystemServer(); throw ex.rethrowFromSystemServer();
} }
} }
}
/** /**
* Deselects a route from the remote session. After a route is deselected, the media is * Deselects a route from the remote session. After a route is deselected, the media is
@@ -852,17 +838,14 @@ public final class MediaRouter2Manager {
return; return;
} }
Client client = getOrCreateClient();
if (client != null) {
try { try {
int requestId = mNextRequestId.getAndIncrement(); int requestId = mNextRequestId.getAndIncrement();
mMediaRouterService.deselectRouteWithManager( mMediaRouterService.deselectRouteWithManager(
client, requestId, sessionInfo.getId(), route); getOrCreateClient(), requestId, sessionInfo.getId(), route);
} catch (RemoteException ex) { } catch (RemoteException ex) {
throw ex.rethrowFromSystemServer(); throw ex.rethrowFromSystemServer();
} }
} }
}
/** /**
* Requests releasing a session. * Requests releasing a session.
@@ -877,17 +860,14 @@ public final class MediaRouter2Manager {
public void releaseSession(@NonNull RoutingSessionInfo sessionInfo) { public void releaseSession(@NonNull RoutingSessionInfo sessionInfo) {
Objects.requireNonNull(sessionInfo, "sessionInfo must not be null"); Objects.requireNonNull(sessionInfo, "sessionInfo must not be null");
Client client = getOrCreateClient();
if (client != null) {
try { try {
int requestId = mNextRequestId.getAndIncrement(); int requestId = mNextRequestId.getAndIncrement();
mMediaRouterService.releaseSessionWithManager( mMediaRouterService.releaseSessionWithManager(
client, requestId, sessionInfo.getId()); getOrCreateClient(), requestId, sessionInfo.getId());
} catch (RemoteException ex) { } catch (RemoteException ex) {
throw ex.rethrowFromSystemServer(); throw ex.rethrowFromSystemServer();
} }
} }
}
/** /**
* Transfers the remote session to the given route. * Transfers the remote session to the given route.
@@ -898,16 +878,13 @@ public final class MediaRouter2Manager {
@NonNull MediaRoute2Info route) { @NonNull MediaRoute2Info route) {
int requestId = createTransferRequest(session, route); int requestId = createTransferRequest(session, route);
Client client = getOrCreateClient();
if (client != null) {
try { try {
mMediaRouterService.transferToRouteWithManager( mMediaRouterService.transferToRouteWithManager(
client, requestId, session.getId(), route); getOrCreateClient(), requestId, session.getId(), route);
} catch (RemoteException ex) { } catch (RemoteException ex) {
throw ex.rethrowFromSystemServer(); throw ex.rethrowFromSystemServer();
} }
} }
}
private void requestCreateSession(RoutingSessionInfo oldSession, MediaRoute2Info route) { private void requestCreateSession(RoutingSessionInfo oldSession, MediaRoute2Info route) {
if (TextUtils.isEmpty(oldSession.getClientPackageName())) { if (TextUtils.isEmpty(oldSession.getClientPackageName())) {
@@ -918,16 +895,13 @@ public final class MediaRouter2Manager {
int requestId = createTransferRequest(oldSession, route); int requestId = createTransferRequest(oldSession, route);
Client client = getOrCreateClient();
if (client != null) {
try { try {
mMediaRouterService.requestCreateSessionWithManager( mMediaRouterService.requestCreateSessionWithManager(
client, requestId, oldSession, route); getOrCreateClient(), requestId, oldSession, route);
} catch (RemoteException ex) { } catch (RemoteException ex) {
throw ex.rethrowFromSystemServer(); throw ex.rethrowFromSystemServer();
} }
} }
}
private int createTransferRequest(RoutingSessionInfo session, MediaRoute2Info route) { private int createTransferRequest(RoutingSessionInfo session, MediaRoute2Info route) {
int requestId = mNextRequestId.getAndIncrement(); int requestId = mNextRequestId.getAndIncrement();