SpatializerHelper: Add properties for enable defaults

Test: see bug
Test: atest SpatializerHelperTest
Bug: 270980127
Merged-In: I5f5a8ab9fc30cc3549ab8c3d2873c4570bbeef00
Change-Id: I5f5a8ab9fc30cc3549ab8c3d2873c4570bbeef00
This commit is contained in:
Andy Hung
2023-03-16 19:55:33 -07:00
parent 2325b1da98
commit 864253c959
3 changed files with 25 additions and 6 deletions

View File

@@ -1014,9 +1014,14 @@ public class AudioService extends IAudioService.Stub
mSfxHelper = new SoundEffectsHelper(mContext, playerBase -> ignorePlayerLogs(playerBase));
final boolean headTrackingDefault = mContext.getResources().getBoolean(
final boolean binauralEnabledDefault = SystemProperties.getBoolean(
"ro.audio.spatializer_binaural_enabled_default", true);
final boolean transauralEnabledDefault = SystemProperties.getBoolean(
"ro.audio.spatializer_transaural_enabled_default", true);
final boolean headTrackingEnabledDefault = mContext.getResources().getBoolean(
com.android.internal.R.bool.config_spatial_audio_head_tracking_enabled_default);
mSpatializerHelper = new SpatializerHelper(this, mAudioSystem, headTrackingDefault);
mSpatializerHelper = new SpatializerHelper(this, mAudioSystem,
binauralEnabledDefault, transauralEnabledDefault, headTrackingEnabledDefault);
mVibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
mHasVibrator = mVibrator == null ? false : mVibrator.hasVibrator();

View File

@@ -171,13 +171,17 @@ public class SpatializerHelper {
// initialization
@SuppressWarnings("StaticAssignmentInConstructor")
SpatializerHelper(@NonNull AudioService mother, @NonNull AudioSystemAdapter asa,
boolean headTrackingEnabledByDefault) {
boolean binauralEnabledDefault,
boolean transauralEnabledDefault,
boolean headTrackingEnabledDefault) {
mAudioService = mother;
mASA = asa;
// "StaticAssignmentInConstructor" warning is suppressed as the SpatializerHelper being
// constructed here is the factory for SADeviceState, thus SADeviceState and its
// private static field sHeadTrackingEnabledDefault should never be accessed directly.
SADeviceState.sHeadTrackingEnabledDefault = headTrackingEnabledByDefault;
SADeviceState.sBinauralEnabledDefault = binauralEnabledDefault;
SADeviceState.sTransauralEnabledDefault = transauralEnabledDefault;
SADeviceState.sHeadTrackingEnabledDefault = headTrackingEnabledDefault;
}
synchronized void initForTest(boolean hasBinaural, boolean hasTransaural) {
@@ -1539,10 +1543,12 @@ public class SpatializerHelper {
}
/*package*/ static final class SADeviceState {
private static boolean sBinauralEnabledDefault = true;
private static boolean sTransauralEnabledDefault = true;
private static boolean sHeadTrackingEnabledDefault = false;
final @AudioDeviceInfo.AudioDeviceType int mDeviceType;
final @NonNull String mDeviceAddress;
boolean mEnabled = true; // by default, SA is enabled on any device
boolean mEnabled;
boolean mHasHeadTracker = false;
boolean mHeadTrackerEnabled;
static final String SETTING_FIELD_SEPARATOR = ",";
@@ -1558,6 +1564,12 @@ public class SpatializerHelper {
SADeviceState(@AudioDeviceInfo.AudioDeviceType int deviceType, @Nullable String address) {
mDeviceType = deviceType;
mDeviceAddress = isWireless(deviceType) ? Objects.requireNonNull(address) : "";
final int spatMode = SPAT_MODE_FOR_DEVICE_TYPE.get(deviceType, Integer.MIN_VALUE);
mEnabled = spatMode == SpatializationMode.SPATIALIZER_BINAURAL
? sBinauralEnabledDefault
: spatMode == SpatializationMode.SPATIALIZER_TRANSAURAL
? sTransauralEnabledDefault
: false;
mHeadTrackerEnabled = sHeadTrackingEnabledDefault;
}

View File

@@ -56,7 +56,9 @@ public class SpatializerHelperTest {
mSpyAudioSystem = spy(new NoOpAudioSystemAdapter());
mSpatHelper = new SpatializerHelper(mMockAudioService, mSpyAudioSystem,
false /*headTrackingEnabledByDefault*/);
true /*binauralEnabledDefault*/,
true /*transauralEnabledDefault*/,
false /*headTrackingEnabledDefault*/);
}
/**