AudioManager: isFixedVolume() fix for dynamic volume behavior
AudioManager.isFixedVolume() was only considering the fixed volume global property, but was not checking the current volume behavior. Bug: 203034282 Test: atest MediaActivityTest ; atest MediaRouter2Test#testCallbacksAreCalledWhenVolumeChanged Change-Id: I1e22e5bcd75c41c1ab6a47dc1e0d7619df989970
This commit is contained in:
@@ -96,8 +96,6 @@ public class AudioManager {
|
||||
private Context mOriginalContext;
|
||||
private Context mApplicationContext;
|
||||
private long mVolumeKeyUpTime;
|
||||
private boolean mUseFixedVolumeInitialized;
|
||||
private boolean mUseFixedVolume;
|
||||
private static final String TAG = "AudioManager";
|
||||
private static final boolean DEBUG = false;
|
||||
private static final AudioPortEventHandler sAudioPortEventHandler = new AudioPortEventHandler();
|
||||
@@ -893,19 +891,13 @@ public class AudioManager {
|
||||
* </ul>
|
||||
*/
|
||||
public boolean isVolumeFixed() {
|
||||
synchronized (this) {
|
||||
try {
|
||||
if (!mUseFixedVolumeInitialized) {
|
||||
mUseFixedVolume = getContext().getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_useFixedVolume);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} finally {
|
||||
// only ever try once, so always consider initialized even if query failed
|
||||
mUseFixedVolumeInitialized = true;
|
||||
}
|
||||
boolean res = false;
|
||||
try {
|
||||
res = getService().isVolumeFixed();
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "Error querying isVolumeFixed", e);
|
||||
}
|
||||
return mUseFixedVolume;
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -456,4 +456,6 @@ interface IAudioService {
|
||||
void registerSpatializerOutputCallback(in ISpatializerOutputCallback cb);
|
||||
|
||||
void unregisterSpatializerOutputCallback(in ISpatializerOutputCallback cb);
|
||||
|
||||
boolean isVolumeFixed();
|
||||
}
|
||||
|
||||
@@ -6185,9 +6185,15 @@ public class AudioService extends IAudioService.Stub
|
||||
*/
|
||||
public @AudioManager.DeviceVolumeBehavior
|
||||
int getDeviceVolumeBehavior(@NonNull AudioDeviceAttributes device) {
|
||||
Objects.requireNonNull(device);
|
||||
// verify permissions
|
||||
enforceQueryStateOrModifyRoutingPermission();
|
||||
|
||||
return getDeviceVolumeBehaviorInt(device);
|
||||
}
|
||||
|
||||
private @AudioManager.DeviceVolumeBehavior
|
||||
int getDeviceVolumeBehaviorInt(@NonNull AudioDeviceAttributes device) {
|
||||
// translate Java device type to native device type (for the devices masks for full / fixed)
|
||||
final int audioSystemDeviceOut = AudioDeviceInfo.convertDeviceTypeToInternalDevice(
|
||||
device.getType());
|
||||
@@ -6215,6 +6221,29 @@ public class AudioService extends IAudioService.Stub
|
||||
return AudioManager.DEVICE_VOLUME_BEHAVIOR_VARIABLE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see AudioManager#isVolumeFixed()
|
||||
* Note there are no permission checks on this operation, as this is part of API 21
|
||||
* @return true if the current device's volume behavior for media is
|
||||
* DEVICE_VOLUME_BEHAVIOR_FIXED
|
||||
*/
|
||||
public boolean isVolumeFixed() {
|
||||
if (mUseFixedVolume) {
|
||||
return true;
|
||||
}
|
||||
final AudioAttributes attributes = new AudioAttributes.Builder()
|
||||
.setUsage(AudioAttributes.USAGE_MEDIA)
|
||||
.build();
|
||||
// calling getDevice*Int to bypass permission check
|
||||
final List<AudioDeviceAttributes> devices = getDevicesForAttributesInt(attributes);
|
||||
for (AudioDeviceAttributes device : devices) {
|
||||
if (getDeviceVolumeBehaviorInt(device) == AudioManager.DEVICE_VOLUME_BEHAVIOR_FIXED) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*package*/ static final int CONNECTION_STATE_DISCONNECTED = 0;
|
||||
/*package*/ static final int CONNECTION_STATE_CONNECTED = 1;
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user