2323import android .os .Looper ;
2424import android .test .AndroidTestCase ;
2525
26+ import java .lang .Boolean ;
27+ import java .util .HashMap ;
28+ import java .util .Map ;
29+ import java .util .UUID ;
30+
2631public class PostProcTestBase extends AndroidTestCase {
32+ private static final int CONTROL_PRIORITY = 100 ;
33+
2734 protected int mSession = -1 ;
2835 protected boolean mHasControl = false ;
2936 protected boolean mIsEnabled = false ;
@@ -34,6 +41,64 @@ public class PostProcTestBase extends AndroidTestCase {
3441 protected final static String BUNDLE_VOLUME_EFFECT_UUID =
3542 "119341a0-8469-11df-81f9-0002a5d5c51b" ;
3643
44+ private Map <UUID , Boolean > mOriginalEffectState = new HashMap <>();
45+
46+ /**
47+ * All potential effects under test are disabled at setup.
48+ * Initial state is backuped, restored in tearDown
49+ * @throws Exception
50+ */
51+ @ Override
52+ protected void setUp () throws Exception {
53+ super .setUp ();
54+
55+ final UUID [] effectTypes = {
56+ AudioEffect .EFFECT_TYPE_BASS_BOOST ,
57+ AudioEffect .EFFECT_TYPE_EQUALIZER ,
58+ AudioEffect .EFFECT_TYPE_VIRTUALIZER ,
59+ AudioEffect .EFFECT_TYPE_PRESET_REVERB ,
60+ AudioEffect .EFFECT_TYPE_ENV_REVERB ,
61+ };
62+ for (UUID effectType : effectTypes ) {
63+ try {
64+ if (AudioEffect .isEffectTypeAvailable (effectType )) {
65+ AudioEffect effect = new AudioEffect (effectType ,
66+ AudioEffect .EFFECT_TYPE_NULL ,
67+ CONTROL_PRIORITY ,
68+ 0 );
69+ assertTrue ("effect does not have control" , effect .hasControl ());
70+ mOriginalEffectState .put (effectType , effect .getEnabled ());
71+
72+ effect .setEnabled (false );
73+ assertFalse ("Could not disable effect" , effect .getEnabled ());
74+ effect .release ();
75+ }
76+ } catch (IllegalStateException e ) {
77+ } catch (IllegalArgumentException e ) {
78+ } catch (UnsupportedOperationException e ) {
79+ }
80+ }
81+ }
82+
83+ @ Override
84+ protected void tearDown () throws Exception {
85+ super .tearDown ();
86+ for (Map .Entry <UUID , Boolean > entry : mOriginalEffectState .entrySet ()) {
87+ try {
88+ AudioEffect effect = new AudioEffect (entry .getKey (),
89+ AudioEffect .EFFECT_TYPE_NULL ,
90+ CONTROL_PRIORITY ,
91+ 0 );
92+ assertTrue ("effect does not have control" , effect .hasControl ());
93+ effect .setEnabled (entry .getValue ());
94+ effect .release ();
95+ } catch (IllegalStateException e ) {
96+ } catch (IllegalArgumentException e ) {
97+ } catch (UnsupportedOperationException e ) {
98+ }
99+ }
100+ }
101+
37102 protected boolean hasAudioOutput () {
38103 return getContext ().getPackageManager ().hasSystemFeature (
39104 PackageManager .FEATURE_AUDIO_OUTPUT );
0 commit comments