Add event for Spatial Audio toggle in Settings

Bug: 322279959
Test: atest BluetoothDetailsSpatialAudioControllerTest
Change-Id: Id0a3e4c0bcdce80c25326c83db7913a51462ef58
This commit is contained in:
Haijie Hong
2024-03-13 14:15:01 +08:00
parent 42be6f6e88
commit b2d6c06c5c
2 changed files with 136 additions and 28 deletions

View File

@@ -18,6 +18,7 @@ package com.android.settings.bluetooth;
import static android.media.Spatializer.SPATIALIZER_IMMERSIVE_LEVEL_NONE;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.media.AudioDeviceAttributes;
import android.media.AudioDeviceInfo;
@@ -60,6 +61,7 @@ public class BluetoothDetailsSpatialAudioController extends BluetoothDetailsCont
AudioDeviceAttributes mAudioDevice = null;
AtomicBoolean mHasHeadTracker = new AtomicBoolean(false);
AtomicBoolean mInitialRefresh = new AtomicBoolean(true);
public BluetoothDetailsSpatialAudioController(
Context context,
@@ -81,6 +83,10 @@ public class BluetoothDetailsSpatialAudioController extends BluetoothDetailsCont
TwoStatePreference switchPreference = (TwoStatePreference) preference;
String key = switchPreference.getKey();
if (TextUtils.equals(key, KEY_SPATIAL_AUDIO)) {
mMetricsFeatureProvider.action(
mContext,
SettingsEnums.ACTION_BLUETOOTH_DEVICE_DETAILS_SPATIAL_AUDIO_TOGGLE_CLICKED,
switchPreference.isChecked());
updateSpatializerEnabled(switchPreference.isChecked());
ThreadUtils.postOnBackgroundThread(
() -> {
@@ -91,6 +97,10 @@ public class BluetoothDetailsSpatialAudioController extends BluetoothDetailsCont
});
return true;
} else if (TextUtils.equals(key, KEY_HEAD_TRACKING)) {
mMetricsFeatureProvider.action(
mContext,
SettingsEnums.ACTION_BLUETOOTH_DEVICE_DETAILS_HEAD_TRACKING_TOGGLE_CLICKED,
switchPreference.isChecked());
updateSpatializerHeadTracking(switchPreference.isChecked());
return true;
} else {
@@ -186,6 +196,20 @@ public class BluetoothDetailsSpatialAudioController extends BluetoothDetailsCont
if (isHeadTrackingAvailable) {
headTrackingPref.setChecked(mSpatializer.isHeadTrackerEnabled(mAudioDevice));
}
if (mInitialRefresh.compareAndSet(true, false)) {
// Only triggered when shown for the first time
mMetricsFeatureProvider.action(
mContext,
SettingsEnums.ACTION_BLUETOOTH_DEVICE_DETAILS_SPATIAL_AUDIO_TRIGGERED,
spatialAudioPref.isChecked());
if (mHasHeadTracker.get()) {
mMetricsFeatureProvider.action(
mContext,
SettingsEnums.ACTION_BLUETOOTH_DEVICE_DETAILS_HEAD_TRACKING_TRIGGERED,
headTrackingPref.isChecked());
}
}
}
@VisibleForTesting