Merge "DO NOT MERGE Add setting page for the Spatial audio" into tm-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
e8ca43b239
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.notification;
|
||||
|
||||
import android.content.Context;
|
||||
import android.media.AudioManager;
|
||||
import android.media.Spatializer;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
/**
|
||||
* Parent menu summary of the Spatial audio settings
|
||||
*/
|
||||
public class SpatialAudioParentPreferenceController extends BasePreferenceController {
|
||||
private static final String TAG = "SpatialAudioSetting";
|
||||
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
|
||||
|
||||
private final Spatializer mSpatializer;
|
||||
private SpatialAudioPreferenceController mSpatialAudioPreferenceController;
|
||||
private SpatialAudioWiredHeadphonesController mSpatialAudioWiredHeadphonesController;
|
||||
|
||||
public SpatialAudioParentPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
AudioManager audioManager = context.getSystemService(AudioManager.class);
|
||||
mSpatializer = audioManager.getSpatializer();
|
||||
mSpatialAudioPreferenceController = new SpatialAudioPreferenceController(context, "unused");
|
||||
mSpatialAudioWiredHeadphonesController = new SpatialAudioWiredHeadphonesController(context,
|
||||
"unused");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
int level = mSpatializer.getImmersiveAudioLevel();
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "spatialization level: " + level);
|
||||
}
|
||||
return level == Spatializer.SPATIALIZER_IMMERSIVE_LEVEL_NONE
|
||||
? UNSUPPORTED_ON_DEVICE : AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
boolean speakerOn = mSpatialAudioPreferenceController.isAvailable()
|
||||
&& mSpatialAudioWiredHeadphonesController.isChecked();
|
||||
boolean wiredHeadphonesOn = mSpatialAudioWiredHeadphonesController.isAvailable()
|
||||
&& mSpatialAudioWiredHeadphonesController.isChecked();
|
||||
if (speakerOn && wiredHeadphonesOn) {
|
||||
return mContext.getString(R.string.spatial_summary_on_two,
|
||||
mContext.getString(R.string.spatial_audio_speaker),
|
||||
mContext.getString(R.string.spatial_audio_wired_headphones));
|
||||
} else if (speakerOn) {
|
||||
return mContext.getString(R.string.spatial_summary_on_one,
|
||||
mContext.getString(R.string.spatial_audio_speaker));
|
||||
} else if (wiredHeadphonesOn) {
|
||||
return mContext.getString(R.string.spatial_summary_on_one,
|
||||
mContext.getString(R.string.spatial_audio_wired_headphones));
|
||||
} else {
|
||||
return mContext.getString(R.string.spatial_summary_off);
|
||||
}
|
||||
}
|
||||
}
|
@@ -17,46 +17,55 @@
|
||||
package com.android.settings.notification;
|
||||
|
||||
import android.content.Context;
|
||||
import android.media.AudioDeviceAttributes;
|
||||
import android.media.AudioDeviceInfo;
|
||||
import android.media.AudioManager;
|
||||
import android.media.Spatializer;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
|
||||
/**
|
||||
* The controller of the Spatial audio setting in the SoundSettings.
|
||||
* The controller of the Spatial audio setting for speaker in the SoundSettings.
|
||||
*/
|
||||
public class SpatialAudioPreferenceController extends TogglePreferenceController {
|
||||
|
||||
private static final String KEY_SPATIAL_AUDIO = "spatial_audio";
|
||||
|
||||
private final Spatializer mSpatializer;
|
||||
@VisibleForTesting
|
||||
final AudioDeviceAttributes mSpeaker = new AudioDeviceAttributes(
|
||||
AudioDeviceAttributes.ROLE_OUTPUT, AudioDeviceInfo.TYPE_BUILTIN_SPEAKER, ""
|
||||
);
|
||||
|
||||
public SpatialAudioPreferenceController(Context context) {
|
||||
super(context, KEY_SPATIAL_AUDIO);
|
||||
public SpatialAudioPreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
AudioManager audioManager = context.getSystemService(AudioManager.class);
|
||||
mSpatializer = audioManager.getSpatializer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return mSpatializer.getImmersiveAudioLevel() == Spatializer.SPATIALIZER_IMMERSIVE_LEVEL_NONE
|
||||
? UNSUPPORTED_ON_DEVICE : AVAILABLE;
|
||||
return mSpatializer.isAvailableForDevice(mSpeaker) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return mSpatializer.isEnabled();
|
||||
return mSpatializer.getCompatibleAudioDevices().contains(mSpeaker);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
mSpatializer.setEnabled(isChecked);
|
||||
if (isChecked) {
|
||||
mSpatializer.addCompatibleAudioDevice(mSpeaker);
|
||||
} else {
|
||||
mSpatializer.removeCompatibleAudioDevice(mSpeaker);
|
||||
}
|
||||
return isChecked == isChecked();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSliceHighlightMenuRes() {
|
||||
return R.string.menu_key_notifications;
|
||||
return R.string.menu_key_sound;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.notification;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
|
||||
/**
|
||||
* Spatial audio settings located in the sound menu
|
||||
*/
|
||||
@SearchIndexable
|
||||
public class SpatialAudioSettings extends DashboardFragment {
|
||||
|
||||
private static final String TAG = "SpatialAudioSettings";
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return SettingsEnums.SETTINGS_SPATIAL_AUDIO;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
return R.xml.spatial_audio_settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLogTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider(R.xml.spatial_audio_settings);
|
||||
}
|
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.notification;
|
||||
|
||||
import android.content.Context;
|
||||
import android.media.AudioDeviceAttributes;
|
||||
import android.media.AudioDeviceInfo;
|
||||
import android.media.AudioManager;
|
||||
import android.media.Spatializer;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
|
||||
/**
|
||||
* The controller of the Spatial audio setting for wired headphones in the SoundSettings.
|
||||
*/
|
||||
public class SpatialAudioWiredHeadphonesController extends TogglePreferenceController {
|
||||
|
||||
private final Spatializer mSpatializer;
|
||||
@VisibleForTesting
|
||||
final AudioDeviceAttributes mWiredHeadphones = new AudioDeviceAttributes(
|
||||
AudioDeviceAttributes.ROLE_OUTPUT, AudioDeviceInfo.TYPE_WIRED_HEADPHONES, ""
|
||||
);
|
||||
|
||||
public SpatialAudioWiredHeadphonesController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
AudioManager audioManager = context.getSystemService(AudioManager.class);
|
||||
mSpatializer = audioManager.getSpatializer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return mSpatializer.isAvailableForDevice(mWiredHeadphones) ? AVAILABLE
|
||||
: UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return mSpatializer.getCompatibleAudioDevices().contains(mWiredHeadphones);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
if (isChecked) {
|
||||
mSpatializer.addCompatibleAudioDevice(mWiredHeadphones);
|
||||
} else {
|
||||
mSpatializer.removeCompatibleAudioDevice(mWiredHeadphones);
|
||||
}
|
||||
return isChecked == isChecked();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSliceHighlightMenuRes() {
|
||||
return R.string.menu_key_sound;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user