• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.audio.cts;
18 
19 import android.content.Context;
20 import android.media.AudioDeviceInfo;
21 import android.media.AudioManager;
22 import android.media.AudioRouting;
23 import android.platform.test.annotations.AppModeSdkSandbox;
24 import android.test.AndroidTestCase;
25 
26 import java.util.List;
27 
28 @AppModeSdkSandbox(reason = "Allow test in the SDK sandbox (does not prevent other modes).")
29 public class AudioPlayRoutingNative extends AndroidTestCase {
30     private static final String TAG = "AudioPlayRoutingNative";
31 
32     private AudioManager mAudioManager;
33 
34     static {
35         System.loadLibrary("audiocts_jni");
36     }
37 
38     @Override
setUp()39     protected void setUp() throws Exception {
40         super.setUp();
41 
42         // get the AudioManager
43         mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
44         assertNotNull(mAudioManager);
45     }
46 
47     @Override
tearDown()48     protected void tearDown() throws Exception {
49         super.tearDown();
50     }
51 
52     //
53     // Tests
54     //
55 
56     // Test a basic Aquire/Release cycle on the default player.
testAquireDefaultProxy()57     public void testAquireDefaultProxy() throws Exception {
58         AudioPlayer player = new AudioPlayer();
59         player.ClearLastSLResult();
60         player.RealizePlayer();
61         player.RealizeRoutingProxy();
62 
63         AudioRouting routingObj = player.GetRoutingInterface();
64         assertNotNull(routingObj);
65 
66         // Not allowed to acquire twice
67         routingObj = player.GetRoutingInterface();
68         assertNull(routingObj);
69         assertTrue(player.GetLastSLResult() != 0);
70 
71         player.ReleaseRoutingInterface(routingObj);
72         assertTrue(player.GetLastSLResult() == 0);
73     }
74 
75     // Test an Aquire before the OpenSL ES player is Realized.
testAquirePreRealizeDefaultProxy()76     public void testAquirePreRealizeDefaultProxy() throws Exception {
77         AudioPlayer player = new AudioPlayer();
78         player.ClearLastSLResult();
79         player.RealizeRoutingProxy();
80         assertTrue(player.GetLastSLResult() == 0);
81 
82         AudioRouting routingObj = player.GetRoutingInterface();
83         assertTrue(player.GetLastSLResult() == 0);
84         assertNotNull(routingObj);
85 
86         player.RealizePlayer();
87         assertTrue(player.GetLastSLResult() == 0);
88 
89         player.ReleaseRoutingInterface(routingObj);
90         assertTrue(player.GetLastSLResult() == 0);
91     }
92 
93     // Test actually setting the routing through the enumerated devices.
testRouting()94     public void testRouting() {
95         AudioPlayer player = new AudioPlayer();
96         player.ClearLastSLResult();
97         player.RealizePlayer();
98         player.RealizeRoutingProxy();
99 
100         AudioRouting routingObj = player.GetRoutingInterface();
101         assertNotNull(routingObj);
102 
103         List<AudioDeviceInfo> mediaDevices = AudioTestUtil.getMediaDevices();
104         for (AudioDeviceInfo device : mediaDevices) {
105             assertTrue(routingObj.setPreferredDevice(device));
106         }
107 
108         player.ReleaseRoutingInterface(routingObj);
109         assertTrue(player.GetLastSLResult() == 0);
110     }
111 }
112