blob: b6a42551a791d4e6f48d9585403ab6ffd1617f2e [file] [log] [blame]
Paul McLeanaf80c872015-06-05 07:48:15 -07001/*
2 * Copyright (C) 2015 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
17package com.android.cts.verifier.audio;
18
19import com.android.cts.verifier.PassFailButtons;
20import com.android.cts.verifier.R;
21
22import android.content.Context;
23
24import android.media.AudioDeviceCallback;
25import android.media.AudioDeviceInfo;
26import android.media.AudioManager;
27import android.media.AudioRecord;
28import android.media.AudioTrack;
29
30import android.os.Bundle;
31import android.os.Handler;
32
33import android.util.Log;
34
35import android.view.View;
36import android.view.View.OnClickListener;
37
38import android.widget.Button;
39import android.widget.TextView;
40
41/**
42 * Tests AudioTrack and AudioRecord (re)Routing messages.
43 */
44public class AudioRoutingNotificationsActivity extends PassFailButtons.Activity {
45 private static final String TAG = "AudioRoutingNotificationsActivity";
46
47 Context mContext;
48
49 OnBtnClickListener mBtnClickListener = new OnBtnClickListener();
50
51 int mNumTrackNotifications = 0;
52 int mNumRecordNotifications = 0;
53
54 TrivialPlayer mAudioPlayer = new TrivialPlayer();
55 TrivialRecorder mAudioRecorder = new TrivialRecorder();
56
57 private class OnBtnClickListener implements OnClickListener {
58 @Override
59 public void onClick(View v) {
60 switch (v.getId()) {
61 case R.id.audio_routingnotification_playBtn:
62 Log.i(TAG, "audio_routingnotification_playBtn");
63 mAudioPlayer.start();
64 break;
65
66 case R.id.audio_routingnotification_playStopBtn:
67 Log.i(TAG, "audio_routingnotification_playStopBtn");
68 mAudioPlayer.stop();
69 break;
70
71 case R.id.audio_routingnotification_recordBtn:
72 break;
73
74 case R.id.audio_routingnotification_recordStopBtn:
75 break;
76 }
77 }
78 }
79
80 private class AudioTrackRoutingChangeListener implements AudioTrack.OnRoutingChangedListener {
81 public void onRoutingChanged(AudioTrack audioTrack) {
82 mNumTrackNotifications++;
83 TextView textView =
84 (TextView)findViewById(R.id.audio_routingnotification_audioTrack_change);
85 String msg = mContext.getResources().getString(
86 R.string.audio_routingnotification_trackRoutingMsg);
87 AudioDeviceInfo routedDevice = audioTrack.getRoutedDevice();
88 CharSequence deviceName = routedDevice != null ? routedDevice.getProductName() : "none";
89 int deviceType = routedDevice != null ? routedDevice.getType() : -1;
90 textView.setText(msg + " - " +
91 deviceName + " [0x" + Integer.toHexString(deviceType) + "]" +
92 " - " + mNumTrackNotifications);
93 }
94 }
95
96 private class AudioRecordRoutingChangeListener implements AudioRecord.OnRoutingChangedListener {
97 public void onRoutingChanged(AudioRecord audioRecord) {
98 mNumRecordNotifications++;
99 TextView textView =
100 (TextView)findViewById(R.id.audio_routingnotification_audioRecord_change);
101 String msg = mContext.getResources().getString(
102 R.string.audio_routingnotification_recordRoutingMsg);
103 AudioDeviceInfo routedDevice = audioRecord.getRoutedDevice();
104 CharSequence deviceName = routedDevice != null ? routedDevice.getProductName() : "none";
105 int deviceType = routedDevice != null ? routedDevice.getType() : -1;
106 textView.setText(msg + " - " +
107 deviceName + " [0x" + Integer.toHexString(deviceType) + "]" +
108 " - " + mNumRecordNotifications);
109 }
110 }
111
112 @Override
113 protected void onCreate(Bundle savedInstanceState) {
114 super.onCreate(savedInstanceState);
115 setContentView(R.layout.audio_routingnotifications_test);
116
117 Button btn;
118 btn = (Button)findViewById(R.id.audio_routingnotification_playBtn);
119 btn.setOnClickListener(mBtnClickListener);
120 btn = (Button)findViewById(R.id.audio_routingnotification_playStopBtn);
121 btn.setOnClickListener(mBtnClickListener);
122 btn = (Button)findViewById(R.id.audio_routingnotification_recordBtn);
123 btn.setOnClickListener(mBtnClickListener);
124 btn = (Button)findViewById(R.id.audio_routingnotification_recordStopBtn);
125 btn.setOnClickListener(mBtnClickListener);
126
127 mContext = this;
128
129 AudioTrack audioTrack = mAudioPlayer.getAudioTrack();
130 audioTrack.addOnRoutingChangedListener(
131 new AudioTrackRoutingChangeListener(), new Handler());
132
133 AudioRecord audioRecord = mAudioRecorder.getAudioRecord();
134 audioRecord.addOnRoutingChangedListener(
135 new AudioRecordRoutingChangeListener(), new Handler());
136
137 setPassFailButtonClickListeners();
138 }
139
140 @Override
141 public void onBackPressed () {
142 mAudioPlayer.shutDown();
143 mAudioRecorder.shutDown();
144 super.onBackPressed();
145 }
146}