1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settings.notification; 18 19 import android.content.Context; 20 import android.media.AudioManager; 21 import android.media.Spatializer; 22 import android.util.Log; 23 24 import com.android.settings.R; 25 import com.android.settings.core.BasePreferenceController; 26 27 /** 28 * Parent menu summary of the Spatial audio settings 29 */ 30 public class SpatialAudioParentPreferenceController extends BasePreferenceController { 31 private static final String TAG = "SpatialAudioSetting"; 32 private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); 33 34 private final Spatializer mSpatializer; 35 private SpatialAudioPreferenceController mSpatialAudioPreferenceController; 36 private SpatialAudioWiredHeadphonesController mSpatialAudioWiredHeadphonesController; 37 SpatialAudioParentPreferenceController(Context context, String key)38 public SpatialAudioParentPreferenceController(Context context, String key) { 39 super(context, key); 40 AudioManager audioManager = context.getSystemService(AudioManager.class); 41 mSpatializer = audioManager.getSpatializer(); 42 mSpatialAudioPreferenceController = new SpatialAudioPreferenceController(context, "unused"); 43 mSpatialAudioWiredHeadphonesController = new SpatialAudioWiredHeadphonesController(context, 44 "unused"); 45 } 46 47 @Override getAvailabilityStatus()48 public int getAvailabilityStatus() { 49 int level = mSpatializer.getImmersiveAudioLevel(); 50 if (DEBUG) { 51 Log.d(TAG, "spatialization level: " + level); 52 } 53 return level == Spatializer.SPATIALIZER_IMMERSIVE_LEVEL_NONE 54 ? UNSUPPORTED_ON_DEVICE : AVAILABLE; 55 } 56 57 @Override getSummary()58 public CharSequence getSummary() { 59 boolean speakerOn = mSpatialAudioPreferenceController.isAvailable() 60 && mSpatialAudioPreferenceController.isChecked(); 61 boolean wiredHeadphonesOn = mSpatialAudioWiredHeadphonesController.isAvailable() 62 && mSpatialAudioWiredHeadphonesController.isChecked(); 63 if (speakerOn && wiredHeadphonesOn) { 64 return mContext.getString(R.string.spatial_summary_on_two, 65 mContext.getString(R.string.spatial_audio_speaker), 66 mContext.getString(R.string.spatial_audio_wired_headphones)); 67 } else if (speakerOn) { 68 return mContext.getString(R.string.spatial_summary_on_one, 69 mContext.getString(R.string.spatial_audio_speaker)); 70 } else if (wiredHeadphonesOn) { 71 return mContext.getString(R.string.spatial_summary_on_one, 72 mContext.getString(R.string.spatial_audio_wired_headphones)); 73 } else { 74 return mContext.getString(R.string.spatial_summary_off); 75 } 76 } 77 } 78