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 com.android.cts.verifier.R; 20 21 import android.content.Context; 22 23 import android.media.AudioDeviceCallback; 24 import android.media.AudioDeviceInfo; 25 import android.media.AudioManager; 26 27 import android.os.Bundle; 28 29 import android.view.View; 30 import android.view.View.OnClickListener; 31 32 import android.widget.Button; 33 import android.widget.TextView; 34 35 /** 36 * Tests Audio Device Connection events for output devices by prompting the user to 37 * insert/remove a wired headset and noting the presence (or absence) of notifications. 38 */ 39 public class AudioOutputDeviceNotificationsActivity extends HeadsetHonorSystemActivity { 40 Context mContext; 41 42 TextView mConnectView; 43 TextView mDisconnectView; 44 Button mClearMsgsBtn; 45 46 private class TestAudioDeviceCallback extends AudioDeviceCallback { onAudioDevicesAdded(AudioDeviceInfo[] addedDevices)47 public void onAudioDevicesAdded(AudioDeviceInfo[] addedDevices) { 48 if (addedDevices.length != 0) { 49 mConnectView.setText( 50 mContext.getResources().getString(R.string.audio_dev_notification_connectMsg)); 51 } 52 } 53 onAudioDevicesRemoved(AudioDeviceInfo[] removedDevices)54 public void onAudioDevicesRemoved(AudioDeviceInfo[] removedDevices) { 55 if (removedDevices.length != 0) { 56 mDisconnectView.setText( 57 mContext.getResources().getString( 58 R.string.audio_dev_notification_disconnectMsg)); 59 } 60 } 61 } 62 63 @Override enableTestButtons(boolean enabled)64 protected void enableTestButtons(boolean enabled) { 65 // Nothing to do. 66 } 67 68 @Override onCreate(Bundle savedInstanceState)69 protected void onCreate(Bundle savedInstanceState) { 70 super.onCreate(savedInstanceState); 71 setContentView(R.layout.audio_dev_notify); 72 73 mContext = this; 74 75 mConnectView = (TextView)findViewById(R.id.audio_dev_notification_connect_msg); 76 mDisconnectView = (TextView)findViewById(R.id.audio_dev_notification_disconnect_msg); 77 78 ((TextView)findViewById(R.id.info_text)).setText(mContext.getResources().getString( 79 R.string.audio_out_devices_notification_instructions)); 80 81 mClearMsgsBtn = (Button)findViewById(R.id.audio_dev_notification_connect_clearmsgs_btn); 82 mClearMsgsBtn.setOnClickListener(new View.OnClickListener() { 83 public void onClick(View v) { 84 mConnectView.setText(""); 85 mDisconnectView.setText(""); 86 } 87 }); 88 89 AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE); 90 audioManager.registerAudioDeviceCallback(new TestAudioDeviceCallback(), null); 91 92 // "Honor System" buttons 93 super.setup(); 94 95 setPassFailButtonClickListeners(); 96 } 97 } 98