private AudioPlayerStateMonitor mAudioPlayerStateMonitor;
// Used to notify System UI and Settings when remote volume was changed.
+ @GuardedBy("mLock")
final RemoteCallbackList<IRemoteVolumeController> mRemoteVolumeControllers =
new RemoteCallbackList<>();
if (!session.isActive()) {
return;
}
- int size = mRemoteVolumeControllers.beginBroadcast();
- MediaSession.Token token = session.getSessionToken();
- for (int i = size - 1; i >= 0; i--) {
- try {
- IRemoteVolumeController cb = mRemoteVolumeControllers.getBroadcastItem(i);
- cb.remoteVolumeChanged(token, flags);
- } catch (Exception e) {
- Log.w(TAG, "Error sending volume change.", e);
+ synchronized (mLock) {
+ int size = mRemoteVolumeControllers.beginBroadcast();
+ MediaSession.Token token = session.getSessionToken();
+ for (int i = size - 1; i >= 0; i--) {
+ try {
+ IRemoteVolumeController cb = mRemoteVolumeControllers.getBroadcastItem(i);
+ cb.remoteVolumeChanged(token, flags);
+ } catch (Exception e) {
+ Log.w(TAG, "Error sending volume change.", e);
+ }
}
+ mRemoteVolumeControllers.finishBroadcast();
}
- mRemoteVolumeControllers.finishBroadcast();
}
@Override
return;
}
- int size = mRemoteVolumeControllers.beginBroadcast();
- MediaSessionRecord record = user.mPriorityStack.getDefaultRemoteSession(userId);
- MediaSession.Token token = record == null ? null : record.getSessionToken();
+ synchronized (mLock) {
+ int size = mRemoteVolumeControllers.beginBroadcast();
+ MediaSessionRecord record = user.mPriorityStack.getDefaultRemoteSession(userId);
+ MediaSession.Token token = record == null ? null : record.getSessionToken();
- for (int i = size - 1; i >= 0; i--) {
- try {
- IRemoteVolumeController cb = mRemoteVolumeControllers.getBroadcastItem(i);
- cb.updateRemoteController(token);
- } catch (Exception e) {
- Log.w(TAG, "Error sending default remote volume.", e);
+ for (int i = size - 1; i >= 0; i--) {
+ try {
+ IRemoteVolumeController cb = mRemoteVolumeControllers.getBroadcastItem(i);
+ cb.updateRemoteController(token);
+ } catch (Exception e) {
+ Log.w(TAG, "Error sending default remote volume.", e);
+ }
}
+ mRemoteVolumeControllers.finishBroadcast();
}
- mRemoteVolumeControllers.finishBroadcast();
}
void pushSession2TokensChangedLocked(int userId) {
final int pid = Binder.getCallingPid();
final int uid = Binder.getCallingUid();
final long token = Binder.clearCallingIdentity();
- try {
- enforceStatusBarServicePermission("listen for volume changes", pid, uid);
- mRemoteVolumeControllers.register(rvc);
- } finally {
- Binder.restoreCallingIdentity(token);
+ synchronized (mLock) {
+ try {
+ enforceStatusBarServicePermission("listen for volume changes", pid, uid);
+ mRemoteVolumeControllers.register(rvc);
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
}
}
final int pid = Binder.getCallingPid();
final int uid = Binder.getCallingUid();
final long token = Binder.clearCallingIdentity();
- try {
- enforceStatusBarServicePermission("listen for volume changes", pid, uid);
- mRemoteVolumeControllers.unregister(rvc);
- } finally {
- Binder.restoreCallingIdentity(token);
+ synchronized (mLock) {
+ try {
+ enforceStatusBarServicePermission("listen for volume changes", pid, uid);
+ mRemoteVolumeControllers.unregister(rvc);
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
}
}