Re-throw unexpected RemoteExceptions in MediaRouter

This change re-throws exceptions that can only be caused by a dead
system server. We avoid spamming the logs by just re-throwing.
This makes it more clear that the MediaRouter instance does not
end the method execution in a consistent state.

Bug: b/259025372
Test: atest MediaRouterTest
Change-Id: I28dbe7936e199e322dc634a8bcc2206afbc0eaf7
This commit is contained in:
Alex Dadukin
2022-11-16 10:33:25 +00:00
parent 7119c3e5d6
commit 317e3b8c11
2 changed files with 10 additions and 47 deletions

View File

@@ -387,7 +387,7 @@ public class MediaRouter {
try {
mMediaRouterService.registerClientGroupId(mClient, groupId);
} catch (RemoteException ex) {
Log.e(TAG, "Unable to register group ID of the client.", ex);
ex.rethrowFromSystemServer();
}
}
}
@@ -439,7 +439,7 @@ public class MediaRouter {
try {
mMediaRouterService.unregisterClient(mClient);
} catch (RemoteException ex) {
Log.e(TAG, "Unable to unregister media router client.", ex);
ex.rethrowFromSystemServer();
}
mClient = null;
}
@@ -466,7 +466,7 @@ public class MediaRouter {
mMediaRouterService.setDiscoveryRequest(mClient,
mDiscoveryRequestRouteTypes, mDiscoverRequestActiveScan);
} catch (RemoteException ex) {
Log.e(TAG, "Unable to publish media router client discovery request.", ex);
ex.rethrowFromSystemServer();
}
}
}
@@ -478,7 +478,7 @@ public class MediaRouter {
mSelectedRoute != null ? mSelectedRoute.mGlobalRouteId : null,
explicit);
} catch (RemoteException ex) {
Log.e(TAG, "Unable to publish media router client selected route.", ex);
ex.rethrowFromSystemServer();
}
}
}
@@ -490,7 +490,7 @@ public class MediaRouter {
try {
mClientState = mMediaRouterService.getState(mClient);
} catch (RemoteException ex) {
Log.e(TAG, "Unable to retrieve media router client state.", ex);
ex.rethrowFromSystemServer();
}
}
final ArrayList<MediaRouterClientState.RouteInfo> globalRoutes =
@@ -535,7 +535,7 @@ public class MediaRouter {
mMediaRouterService.requestSetVolume(mClient,
route.mGlobalRouteId, volume);
} catch (RemoteException ex) {
Log.w(TAG, "Unable to request volume change.", ex);
ex.rethrowFromSystemServer();
}
}
}
@@ -546,7 +546,7 @@ public class MediaRouter {
mMediaRouterService.requestUpdateVolume(mClient,
route.mGlobalRouteId, direction);
} catch (RemoteException ex) {
Log.w(TAG, "Unable to request volume change.", ex);
ex.rethrowFromSystemServer();
}
}
}
@@ -653,7 +653,7 @@ public class MediaRouter {
try {
return mMediaRouterService.isPlaybackActive(mClient);
} catch (RemoteException ex) {
Log.e(TAG, "Unable to retrieve playback active state.", ex);
ex.rethrowFromSystemServer();
}
}
return false;

View File

@@ -189,10 +189,6 @@ public final class MediaRouterService extends IMediaRouterService.Stub
// Binder call
@Override
public void registerClientAsUser(IMediaRouterClient client, String packageName, int userId) {
if (client == null) {
throw new IllegalArgumentException("client must not be null");
}
final int uid = Binder.getCallingUid();
if (!validatePackageName(uid, packageName)) {
throw new SecurityException("packageName must match the calling uid");
@@ -217,9 +213,6 @@ public final class MediaRouterService extends IMediaRouterService.Stub
// Binder call
@Override
public void registerClientGroupId(IMediaRouterClient client, String groupId) {
if (client == null) {
throw new NullPointerException("client must not be null");
}
if (mContext.checkCallingOrSelfPermission(
android.Manifest.permission.CONFIGURE_WIFI_DISPLAY)
!= PackageManager.PERMISSION_GRANTED) {
@@ -240,10 +233,6 @@ public final class MediaRouterService extends IMediaRouterService.Stub
// Binder call
@Override
public void unregisterClient(IMediaRouterClient client) {
if (client == null) {
throw new IllegalArgumentException("client must not be null");
}
final long token = Binder.clearCallingIdentity();
try {
synchronized (mLock) {
@@ -257,10 +246,6 @@ public final class MediaRouterService extends IMediaRouterService.Stub
// Binder call
@Override
public MediaRouterClientState getState(IMediaRouterClient client) {
if (client == null) {
throw new IllegalArgumentException("client must not be null");
}
final long token = Binder.clearCallingIdentity();
try {
synchronized (mLock) {
@@ -274,10 +259,6 @@ public final class MediaRouterService extends IMediaRouterService.Stub
// Binder call
@Override
public boolean isPlaybackActive(IMediaRouterClient client) {
if (client == null) {
throw new IllegalArgumentException("client must not be null");
}
final long token = Binder.clearCallingIdentity();
try {
ClientRecord clientRecord;
@@ -314,10 +295,6 @@ public final class MediaRouterService extends IMediaRouterService.Stub
@Override
public void setDiscoveryRequest(IMediaRouterClient client,
int routeTypes, boolean activeScan) {
if (client == null) {
throw new IllegalArgumentException("client must not be null");
}
final long token = Binder.clearCallingIdentity();
try {
synchronized (mLock) {
@@ -336,10 +313,6 @@ public final class MediaRouterService extends IMediaRouterService.Stub
// selected route or a default selection.
@Override
public void setSelectedRoute(IMediaRouterClient client, String routeId, boolean explicit) {
if (client == null) {
throw new IllegalArgumentException("client must not be null");
}
final long token = Binder.clearCallingIdentity();
try {
synchronized (mLock) {
@@ -353,12 +326,7 @@ public final class MediaRouterService extends IMediaRouterService.Stub
// Binder call
@Override
public void requestSetVolume(IMediaRouterClient client, String routeId, int volume) {
if (client == null) {
throw new IllegalArgumentException("client must not be null");
}
if (routeId == null) {
throw new IllegalArgumentException("routeId must not be null");
}
Objects.requireNonNull(routeId, "routeId must not be null");
final long token = Binder.clearCallingIdentity();
try {
@@ -373,12 +341,7 @@ public final class MediaRouterService extends IMediaRouterService.Stub
// Binder call
@Override
public void requestUpdateVolume(IMediaRouterClient client, String routeId, int direction) {
if (client == null) {
throw new IllegalArgumentException("client must not be null");
}
if (routeId == null) {
throw new IllegalArgumentException("routeId must not be null");
}
Objects.requireNonNull(routeId, "routeId must not be null");
final long token = Binder.clearCallingIdentity();
try {