Merge "Cache stream volumes to prevent ANR" am: db50d542af
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1535787 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: I4708784338648ba3f9365f519332e4ee36445f36
This commit is contained in:
@@ -43,6 +43,7 @@ import android.os.RemoteException;
|
|||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.util.ArrayMap;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Display;
|
import android.view.Display;
|
||||||
|
|
||||||
@@ -51,6 +52,7 @@ import java.lang.annotation.RetentionPolicy;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
@@ -108,6 +110,8 @@ public class MediaRouter {
|
|||||||
IMediaRouterClient mClient;
|
IMediaRouterClient mClient;
|
||||||
MediaRouterClientState mClientState;
|
MediaRouterClientState mClientState;
|
||||||
|
|
||||||
|
Map<Integer, Integer> mStreamVolume = new ArrayMap<>();
|
||||||
|
|
||||||
final IAudioRoutesObserver.Stub mAudioRoutesObserver = new IAudioRoutesObserver.Stub() {
|
final IAudioRoutesObserver.Stub mAudioRoutesObserver = new IAudioRoutesObserver.Stub() {
|
||||||
@Override
|
@Override
|
||||||
public void dispatchAudioRoutesChanged(final AudioRoutesInfo newRoutes) {
|
public void dispatchAudioRoutesChanged(final AudioRoutesInfo newRoutes) {
|
||||||
@@ -259,6 +263,17 @@ public class MediaRouter {
|
|||||||
mCurAudioRoutesInfo.bluetoothName = newRoutes.bluetoothName;
|
mCurAudioRoutesInfo.bluetoothName = newRoutes.bluetoothName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int getStreamVolume(int streamType) {
|
||||||
|
if (!mStreamVolume.containsKey(streamType)) {
|
||||||
|
try {
|
||||||
|
mStreamVolume.put(streamType, mAudioService.getStreamVolume(streamType));
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.e(TAG, "Error getting local stream volume", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mStreamVolume.get(streamType);
|
||||||
|
}
|
||||||
|
|
||||||
boolean isBluetoothA2dpOn() {
|
boolean isBluetoothA2dpOn() {
|
||||||
try {
|
try {
|
||||||
return mBluetoothA2dpRoute != null && mAudioService.isBluetoothA2dpOn();
|
return mBluetoothA2dpRoute != null && mAudioService.isBluetoothA2dpOn();
|
||||||
@@ -1956,13 +1971,7 @@ public class MediaRouter {
|
|||||||
*/
|
*/
|
||||||
public int getVolume() {
|
public int getVolume() {
|
||||||
if (mPlaybackType == PLAYBACK_TYPE_LOCAL) {
|
if (mPlaybackType == PLAYBACK_TYPE_LOCAL) {
|
||||||
int vol = 0;
|
return sStatic.getStreamVolume(mPlaybackStream);
|
||||||
try {
|
|
||||||
vol = sStatic.mAudioService.getStreamVolume(mPlaybackStream);
|
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "Error getting local stream volume", e);
|
|
||||||
}
|
|
||||||
return vol;
|
|
||||||
} else {
|
} else {
|
||||||
return mVolume;
|
return mVolume;
|
||||||
}
|
}
|
||||||
@@ -3077,11 +3086,12 @@ public class MediaRouter {
|
|||||||
if (intent.getAction().equals(AudioManager.VOLUME_CHANGED_ACTION)) {
|
if (intent.getAction().equals(AudioManager.VOLUME_CHANGED_ACTION)) {
|
||||||
final int streamType = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE,
|
final int streamType = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE,
|
||||||
-1);
|
-1);
|
||||||
|
final int newVolume = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, 0);
|
||||||
|
sStatic.mStreamVolume.put(streamType, newVolume);
|
||||||
if (streamType != AudioManager.STREAM_MUSIC) {
|
if (streamType != AudioManager.STREAM_MUSIC) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int newVolume = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE, 0);
|
|
||||||
final int oldVolume = intent.getIntExtra(
|
final int oldVolume = intent.getIntExtra(
|
||||||
AudioManager.EXTRA_PREV_VOLUME_STREAM_VALUE, 0);
|
AudioManager.EXTRA_PREV_VOLUME_STREAM_VALUE, 0);
|
||||||
if (newVolume != oldVolume) {
|
if (newVolume != oldVolume) {
|
||||||
|
|||||||
Reference in New Issue
Block a user