• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 package com.android.cts.verifier.audio;
18 
19 import android.content.Context;
20 import android.media.AudioDeviceCallback;
21 import android.media.AudioDeviceInfo;
22 import android.media.AudioManager;
23 import android.os.Bundle;
24 import android.view.View;
25 import android.widget.TextView;
26 
27 import com.android.cts.verifier.R;
28 import com.android.cts.verifier.audio.audiolib.AudioDeviceUtils;
29 
30 /**
31  * Tests Audio Device Connection events for output by prompting the user to insert/remove a
32  * wired headset (or microphone) and noting the presence (or absence) of notifications.
33  */
34 public class AudioInputDeviceNotificationsActivity extends AudioWiredDeviceBaseActivity {
35     Context mContext;
36 
37     TextView mConnectView;
38     TextView mDisconnectView;
39     TextView mInfoView;
40 
41     boolean mHandledInitialAddedMessage = false;
42     boolean mConnectReceived = false;
43     boolean mDisconnectReceived = false;
44 
45     private class TestAudioDeviceCallback extends AudioDeviceCallback {
onAudioDevicesAdded(AudioDeviceInfo[] addedDevices)46         public void onAudioDevicesAdded(AudioDeviceInfo[] addedDevices) {
47             // we will get this message when we setup the handler, so ignore the first one.
48             if (!mHandledInitialAddedMessage) {
49                 mHandledInitialAddedMessage = true;
50                 return;
51             }
52             if (addedDevices.length != 0) {
53                 mConnectView.setText(
54                     mContext.getResources().getString(R.string.audio_dev_notification_connectMsg));
55                 mConnectReceived = true;
56                 getPassButton().setEnabled(mConnectReceived && mDisconnectReceived);
57             }
58         }
59 
onAudioDevicesRemoved(AudioDeviceInfo[] removedDevices)60         public void onAudioDevicesRemoved(AudioDeviceInfo[] removedDevices) {
61             if (removedDevices.length != 0) {
62                 mDisconnectView.setText(
63                     mContext.getResources().getString(
64                         R.string.audio_dev_notification_disconnectMsg));
65                 mDisconnectReceived = true;
66                 getPassButton().setEnabled(mConnectReceived && mDisconnectReceived);
67             }
68         }
69     }
70 
71     @Override
onCreate(Bundle savedInstanceState)72     protected void onCreate(Bundle savedInstanceState) {
73         super.onCreate(savedInstanceState);
74         setContentView(R.layout.audio_dev_notify);
75 
76         mContext = this;
77 
78         mConnectView = (TextView) findViewById(R.id.audio_dev_notification_connect_msg);
79         mDisconnectView = (TextView) findViewById(R.id.audio_dev_notification_disconnect_msg);
80 
81         mInfoView = (TextView) findViewById(R.id.info_text);
82         mInfoView.setText(mContext.getResources().getString(
83                 R.string.audio_devices_notification_instructions));
84 
85         findViewById(R.id.audio_dev_notification_connect_clearmsgs_btn)
86                 .setOnClickListener(new View.OnClickListener() {
87                     public void onClick(View v) {
88                         mConnectView.setText("");
89                         mConnectReceived = false;
90                         mDisconnectView.setText("");
91                         mDisconnectReceived = false;
92                         calculatePass();
93                     }
94                 });
95 
96         AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
97         audioManager.registerAudioDeviceCallback(new TestAudioDeviceCallback(), null);
98 
99         // "Honor System" buttons
100         super.setup();
101 
102         setInfoResources(R.string.audio_in_devices_notifications_test,
103                 R.string.audio_in_devices_infotext, -1);
104         setPassFailButtonClickListeners();
105 
106         calculatePass();
107     }
108 
109     @Override
enableTestButtons(boolean enabled)110     protected void enableTestButtons(boolean enabled) {
111         mInfoView.setVisibility(enabled ? View.VISIBLE : View.INVISIBLE);
112     }
113 
114     @Override
calculatePass()115     protected void calculatePass() {
116         getPassButton().setEnabled(!mSupportsWiredPeripheral
117                 || (mConnectReceived && mDisconnectReceived));
118     }
119 }
120