1 /* 2 * Copyright (C) 2014 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 android.media.audio.cts; 18 19 import static org.junit.Assert.assertNotNull; 20 import static org.junit.Assert.assertTrue; 21 22 import android.content.Context; 23 import android.content.pm.PackageManager; 24 import android.media.AudioManager; 25 import android.media.audiofx.AudioEffect; 26 import android.os.Looper; 27 28 import androidx.test.platform.app.InstrumentationRegistry; 29 30 import org.junit.Rule; 31 32 public class PostProcTestBase { 33 protected int mSession = -1; 34 protected boolean mHasControl = false; 35 protected boolean mIsEnabled = false; 36 protected boolean mInitialized = false; 37 protected Looper mLooper = null; 38 protected final Object mLock = new Object(); 39 protected int mChangedParameter = -1; 40 protected static final String BUNDLE_VOLUME_EFFECT_UUID = 41 "119341a0-8469-11df-81f9-0002a5d5c51b"; 42 43 @Rule 44 public EffectBeforeAfterRule mBeforeAfterRule = new EffectBeforeAfterRule(); 45 getContext()46 protected static Context getContext() { 47 return InstrumentationRegistry.getInstrumentation().getContext(); 48 } 49 hasAudioOutput()50 protected boolean hasAudioOutput() { 51 return getContext().getPackageManager().hasSystemFeature( 52 PackageManager.FEATURE_AUDIO_OUTPUT); 53 } 54 isBassBoostAvailable()55 protected boolean isBassBoostAvailable() { 56 return AudioEffect.isEffectTypeAvailable(AudioEffect.EFFECT_TYPE_BASS_BOOST); 57 } 58 isVirtualizerAvailable()59 protected boolean isVirtualizerAvailable() { 60 return AudioEffect.isEffectTypeAvailable(AudioEffect.EFFECT_TYPE_VIRTUALIZER); 61 } 62 isPresetReverbAvailable()63 protected boolean isPresetReverbAvailable() { 64 return AudioEffect.isEffectTypeAvailable(AudioEffect.EFFECT_TYPE_PRESET_REVERB); 65 } 66 isEnvReverbAvailable()67 protected boolean isEnvReverbAvailable() { 68 return AudioEffect.isEffectTypeAvailable(AudioEffect.EFFECT_TYPE_ENV_REVERB); 69 } 70 getSessionId()71 protected int getSessionId() { 72 AudioManager am = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE); 73 assertNotNull("could not get AudioManager", am); 74 int sessionId = am.generateAudioSessionId(); 75 assertTrue("Could not generate session id", sessionId > 0); 76 return sessionId; 77 } 78 79 } 80