Home | History | Annotate | Download | only in cts
      1 /*
      2  * Copyright (C) 2016 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.cts;
     18 
     19 import android.annotation.IntDef;
     20 import android.annotation.NonNull;
     21 import android.content.Context;
     22 import android.media.AudioDeviceInfo;
     23 import android.media.AudioManager;
     24 import android.media.AudioRouting;
     25 import android.test.AndroidTestCase;
     26 import android.util.Log;
     27 
     28 import com.android.compatibility.common.util.CtsAndroidTestCase;
     29 import com.android.ndkaudio.AudioPlayer;
     30 
     31 import java.lang.annotation.Retention;
     32 import java.lang.annotation.RetentionPolicy;
     33 
     34 public class AudioPlayRoutingNative extends AndroidTestCase {
     35     private static final String TAG = "AudioPlayRoutingNative";
     36 
     37     private AudioManager mAudioManager;
     38 
     39     static {
     40         System.loadLibrary("ndkaudioLib");
     41     }
     42 
     43     @Override
     44     protected void setUp() throws Exception {
     45         super.setUp();
     46 
     47         // get the AudioManager
     48         mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
     49         assertNotNull(mAudioManager);
     50     }
     51 
     52     @Override
     53     protected void tearDown() throws Exception {
     54         super.tearDown();
     55     }
     56 
     57     //
     58     // Tests
     59     //
     60 
     61     // Test a basic Aquire/Release cycle on the default player.
     62     public void testAquireDefaultProxy() throws Exception {
     63         AudioPlayer player = new AudioPlayer();
     64         player.ClearLastSLResult();
     65         player.RealizePlayer();
     66         player.RealizeRoutingProxy();
     67 
     68         AudioRouting routingObj = player.GetRoutingInterface();
     69         assertNotNull(routingObj);
     70 
     71         // Not allowed to acquire twice
     72         routingObj = player.GetRoutingInterface();
     73         assertNull(routingObj);
     74         assertTrue(player.GetLastSLResult() != 0);
     75 
     76         player.ReleaseRoutingInterface(routingObj);
     77         assertTrue(player.GetLastSLResult() == 0);
     78     }
     79 
     80     // Test an Aquire before the OpenSL ES player is Realized.
     81     public void testAquirePreRealizeDefaultProxy() throws Exception {
     82         AudioPlayer player = new AudioPlayer();
     83         player.ClearLastSLResult();
     84         player.RealizeRoutingProxy();
     85         assertTrue(player.GetLastSLResult() == 0);
     86 
     87         AudioRouting routingObj = player.GetRoutingInterface();
     88         assertTrue(player.GetLastSLResult() == 0);
     89         assertNotNull(routingObj);
     90 
     91         player.RealizePlayer();
     92         assertTrue(player.GetLastSLResult() == 0);
     93 
     94         player.ReleaseRoutingInterface(routingObj);
     95         assertTrue(player.GetLastSLResult() == 0);
     96     }
     97 
     98     // Test actually setting the routing through the enumerated devices.
     99     public void testRouting() {
    100         AudioPlayer player = new AudioPlayer();
    101         player.ClearLastSLResult();
    102         player.RealizePlayer();
    103         player.RealizeRoutingProxy();
    104 
    105         AudioRouting routingObj = player.GetRoutingInterface();
    106         assertNotNull(routingObj);
    107 
    108         AudioDeviceInfo[] deviceList;
    109         deviceList = mAudioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS);
    110         assertTrue(deviceList != null);
    111         for (AudioDeviceInfo devInfo : deviceList) {
    112             assertTrue(routingObj.setPreferredDevice(devInfo));
    113         }
    114 
    115         player.ReleaseRoutingInterface(routingObj);
    116         assertTrue(player.GetLastSLResult() == 0);
    117     }
    118 }
    119