Merge "Disable the spatializer options for device categories" into udc-qpr-dev
This commit is contained in:
@@ -109,6 +109,7 @@ public class BluetoothDetailsAudioDeviceTypeController extends BluetoothDetailsC
|
||||
mAudioManager.setBluetoothAudioDeviceCategory(mCachedDevice.getAddress(),
|
||||
mCachedDevice.getDevice().getType() == DEVICE_TYPE_LE,
|
||||
Integer.parseInt(value));
|
||||
mCachedDevice.onAudioDeviceCategoryChanged();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.android.settings.bluetooth;
|
||||
|
||||
import static android.media.Spatializer.SPATIALIZER_IMMERSIVE_LEVEL_NONE;
|
||||
|
||||
import android.content.Context;
|
||||
import android.media.AudioDeviceAttributes;
|
||||
import android.media.AudioDeviceInfo;
|
||||
@@ -51,9 +53,7 @@ public class BluetoothDetailsSpatialAudioController extends BluetoothDetailsCont
|
||||
@VisibleForTesting
|
||||
PreferenceCategory mProfilesContainer;
|
||||
@VisibleForTesting
|
||||
AudioDeviceAttributes mAudioDevice;
|
||||
|
||||
private boolean mIsAvailable;
|
||||
AudioDeviceAttributes mAudioDevice = null;
|
||||
|
||||
public BluetoothDetailsSpatialAudioController(
|
||||
Context context,
|
||||
@@ -63,13 +63,11 @@ public class BluetoothDetailsSpatialAudioController extends BluetoothDetailsCont
|
||||
super(context, fragment, device, lifecycle);
|
||||
AudioManager audioManager = context.getSystemService(AudioManager.class);
|
||||
mSpatializer = audioManager.getSpatializer();
|
||||
getAvailableDevice();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return mIsAvailable;
|
||||
return mSpatializer.getImmersiveAudioLevel() != SPATIALIZER_IMMERSIVE_LEVEL_NONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -77,15 +75,11 @@ public class BluetoothDetailsSpatialAudioController extends BluetoothDetailsCont
|
||||
SwitchPreference switchPreference = (SwitchPreference) preference;
|
||||
String key = switchPreference.getKey();
|
||||
if (TextUtils.equals(key, KEY_SPATIAL_AUDIO)) {
|
||||
if (switchPreference.isChecked()) {
|
||||
mSpatializer.addCompatibleAudioDevice(mAudioDevice);
|
||||
} else {
|
||||
mSpatializer.removeCompatibleAudioDevice(mAudioDevice);
|
||||
}
|
||||
refresh();
|
||||
updateSpatializerEnabled(switchPreference.isChecked());
|
||||
refreshSpatialAudioEnabled(switchPreference);
|
||||
return true;
|
||||
} else if (TextUtils.equals(key, KEY_HEAD_TRACKING)) {
|
||||
mSpatializer.setHeadTrackerEnabled(switchPreference.isChecked(), mAudioDevice);
|
||||
updateSpatializerHeadTracking(switchPreference.isChecked());
|
||||
return true;
|
||||
} else {
|
||||
Log.w(TAG, "invalid key name.");
|
||||
@@ -93,6 +87,26 @@ public class BluetoothDetailsSpatialAudioController extends BluetoothDetailsCont
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSpatializerEnabled(boolean enabled) {
|
||||
if (mAudioDevice == null) {
|
||||
Log.w(TAG, "cannot update spatializer enabled for null audio device.");
|
||||
return;
|
||||
}
|
||||
if (enabled) {
|
||||
mSpatializer.addCompatibleAudioDevice(mAudioDevice);
|
||||
} else {
|
||||
mSpatializer.removeCompatibleAudioDevice(mAudioDevice);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSpatializerHeadTracking(boolean enabled) {
|
||||
if (mAudioDevice == null) {
|
||||
Log.w(TAG, "cannot update spatializer head tracking for null audio device.");
|
||||
return;
|
||||
}
|
||||
mSpatializer.setHeadTrackerEnabled(enabled, mAudioDevice);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_SPATIAL_AUDIO_GROUP;
|
||||
@@ -106,12 +120,31 @@ public class BluetoothDetailsSpatialAudioController extends BluetoothDetailsCont
|
||||
|
||||
@Override
|
||||
protected void refresh() {
|
||||
SwitchPreference spatialAudioPref = mProfilesContainer.findPreference(KEY_SPATIAL_AUDIO);
|
||||
if (spatialAudioPref == null) {
|
||||
spatialAudioPref = createSpatialAudioPreference(mProfilesContainer.getContext());
|
||||
mProfilesContainer.addPreference(spatialAudioPref);
|
||||
if (mAudioDevice == null) {
|
||||
getAvailableDevice();
|
||||
}
|
||||
|
||||
SwitchPreference spatialAudioPref = mProfilesContainer.findPreference(KEY_SPATIAL_AUDIO);
|
||||
if (spatialAudioPref == null && mAudioDevice != null) {
|
||||
spatialAudioPref = createSpatialAudioPreference(mProfilesContainer.getContext());
|
||||
mProfilesContainer.addPreference(spatialAudioPref);
|
||||
} else if (mAudioDevice == null || !mSpatializer.isAvailableForDevice(mAudioDevice)) {
|
||||
if (spatialAudioPref != null) {
|
||||
mProfilesContainer.removePreference(spatialAudioPref);
|
||||
}
|
||||
final SwitchPreference headTrackingPref =
|
||||
mProfilesContainer.findPreference(KEY_HEAD_TRACKING);
|
||||
if (headTrackingPref != null) {
|
||||
mProfilesContainer.removePreference(headTrackingPref);
|
||||
}
|
||||
mAudioDevice = null;
|
||||
return;
|
||||
}
|
||||
|
||||
refreshSpatialAudioEnabled(spatialAudioPref);
|
||||
}
|
||||
|
||||
private void refreshSpatialAudioEnabled(SwitchPreference spatialAudioPref) {
|
||||
boolean isSpatialAudioOn = mSpatializer.getCompatibleAudioDevices().contains(mAudioDevice);
|
||||
Log.d(TAG, "refresh() isSpatialAudioOn : " + isSpatialAudioOn);
|
||||
spatialAudioPref.setChecked(isSpatialAudioOn);
|
||||
@@ -121,9 +154,13 @@ public class BluetoothDetailsSpatialAudioController extends BluetoothDetailsCont
|
||||
headTrackingPref = createHeadTrackingPreference(mProfilesContainer.getContext());
|
||||
mProfilesContainer.addPreference(headTrackingPref);
|
||||
}
|
||||
refreshHeadTracking(spatialAudioPref, headTrackingPref);
|
||||
}
|
||||
|
||||
private void refreshHeadTracking(SwitchPreference spatialAudioPref,
|
||||
SwitchPreference headTrackingPref) {
|
||||
boolean isHeadTrackingAvailable =
|
||||
isSpatialAudioOn && mSpatializer.hasHeadTracker(mAudioDevice);
|
||||
spatialAudioPref.isChecked() && mSpatializer.hasHeadTracker(mAudioDevice);
|
||||
Log.d(TAG, "refresh() has head tracker : " + mSpatializer.hasHeadTracker(mAudioDevice));
|
||||
headTrackingPref.setVisible(isHeadTrackingAvailable);
|
||||
if (isHeadTrackingAvailable) {
|
||||
@@ -173,7 +210,6 @@ public class BluetoothDetailsSpatialAudioController extends BluetoothDetailsCont
|
||||
AudioDeviceInfo.TYPE_HEARING_AID,
|
||||
mCachedDevice.getAddress());
|
||||
|
||||
mIsAvailable = true;
|
||||
if (mSpatializer.isAvailableForDevice(bleHeadsetDevice)) {
|
||||
mAudioDevice = bleHeadsetDevice;
|
||||
} else if (mSpatializer.isAvailableForDevice(bleSpeakerDevice)) {
|
||||
@@ -182,20 +218,20 @@ public class BluetoothDetailsSpatialAudioController extends BluetoothDetailsCont
|
||||
mAudioDevice = bleBroadcastDevice;
|
||||
} else if (mSpatializer.isAvailableForDevice(a2dpDevice)) {
|
||||
mAudioDevice = a2dpDevice;
|
||||
} else {
|
||||
mIsAvailable = mSpatializer.isAvailableForDevice(hearingAidDevice);
|
||||
} else if (mSpatializer.isAvailableForDevice(hearingAidDevice)) {
|
||||
mAudioDevice = hearingAidDevice;
|
||||
} else {
|
||||
mAudioDevice = null;
|
||||
}
|
||||
|
||||
Log.d(TAG, "getAvailableDevice() device : "
|
||||
+ mCachedDevice.getDevice().getAnonymizedAddress()
|
||||
+ ", type : " + mAudioDevice.getType()
|
||||
+ ", is available : " + mIsAvailable);
|
||||
+ ", is available : " + (mAudioDevice != null)
|
||||
+ ", type : " + (mAudioDevice == null ? "no type" : mAudioDevice.getType()));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void setAvailableDevice(AudioDeviceAttributes audioDevice) {
|
||||
mAudioDevice = audioDevice;
|
||||
mIsAvailable = mSpatializer.isAvailableForDevice(audioDevice);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user