MediaRouter: Route setBluetoothA2dpOn() via MediaRouterService

The direct binder usage of AudioService.setBluetoothA2dpOn() is now
blocked by permission for security reasons.
This CL routes the usage to the MediaRouterService.

Bug: 181962322, Bug: 189176702
Test: GMM can play navigation sound when BT is connected
Change-Id: Ib13c224a0d412ef6d802eeaadd246649c819c26f
This commit is contained in:
Hyundo Moon
2021-10-13 16:55:03 +09:00
parent 80de4b8d1c
commit 2942e4b584
3 changed files with 22 additions and 1 deletions

View File

@@ -39,6 +39,7 @@ interface IMediaRouterService {
MediaRouterClientState getState(IMediaRouterClient client);
boolean isPlaybackActive(IMediaRouterClient client);
void setBluetoothA2dpOn(IMediaRouterClient client, boolean on);
void setDiscoveryRequest(IMediaRouterClient client, int routeTypes, boolean activeScan);
void setSelectedRoute(IMediaRouterClient client, String routeId, boolean explicit);
void requestSetVolume(IMediaRouterClient client, String routeId, int volume);

View File

@@ -1070,7 +1070,8 @@ public class MediaRouter {
&& (types & ROUTE_TYPE_LIVE_AUDIO) != 0
&& (route.isBluetooth() || route.isDefault())) {
try {
sStatic.mAudioService.setBluetoothA2dpOn(route.isBluetooth());
sStatic.mMediaRouterService.setBluetoothA2dpOn(sStatic.mClient,
route.isBluetooth());
} catch (RemoteException e) {
Log.e(TAG, "Error changing Bluetooth A2DP state", e);
}

View File

@@ -336,6 +336,25 @@ public final class MediaRouterService extends IMediaRouterService.Stub
}
}
// Binder call
@Override
public void setBluetoothA2dpOn(IMediaRouterClient client, boolean on) {
if (client == null) {
throw new IllegalArgumentException("client must not be null");
}
final long token = Binder.clearCallingIdentity();
try {
synchronized (mLock) {
mAudioService.setBluetoothA2dpOn(on);
}
} catch (RemoteException ex) {
Slog.w(TAG, "RemoteException while calling setBluetoothA2dpOn. on=" + on);
} finally {
Binder.restoreCallingIdentity(token);
}
}
// Binder call
@Override
public void setDiscoveryRequest(IMediaRouterClient client,