Paul McLean | 365be3a | 2015-06-04 12:40:18 -0700 | [diff] [blame] | 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 | |
Paul McLean | 365be3a | 2015-06-04 12:40:18 -0700 | [diff] [blame] | 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 | /** |
Paul McLean | f8b1dd7 | 2015-10-06 12:12:58 -0600 | [diff] [blame] | 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. |
Paul McLean | 365be3a | 2015-06-04 12:40:18 -0700 | [diff] [blame] | 38 | */ |
Paul McLean | a7b5b95 | 2015-10-15 13:06:39 -0600 | [diff] [blame] | 39 | public class AudioOutputDeviceNotificationsActivity extends HeadsetHonorSystemActivity { |
Paul McLean | 365be3a | 2015-06-04 12:40:18 -0700 | [diff] [blame] | 40 | Context mContext; |
| 41 | |
| 42 | TextView mConnectView; |
| 43 | TextView mDisconnectView; |
| 44 | Button mClearMsgsBtn; |
| 45 | |
| 46 | private class TestAudioDeviceCallback extends AudioDeviceCallback { |
| 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 | |
| 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 |
Paul McLean | a7b5b95 | 2015-10-15 13:06:39 -0600 | [diff] [blame] | 64 | protected void enableTestButtons(boolean enabled) { |
| 65 | // Nothing to do. |
| 66 | } |
| 67 | |
| 68 | @Override |
Paul McLean | 365be3a | 2015-06-04 12:40:18 -0700 | [diff] [blame] | 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 | |
Paul McLean | f8b1dd7 | 2015-10-06 12:12:58 -0600 | [diff] [blame] | 78 | ((TextView)findViewById(R.id.info_text)).setText(mContext.getResources().getString( |
| 79 | R.string.audio_out_devices_notification_instructions)); |
| 80 | |
Paul McLean | 365be3a | 2015-06-04 12:40:18 -0700 | [diff] [blame] | 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 | |
Paul McLean | a7b5b95 | 2015-10-15 13:06:39 -0600 | [diff] [blame] | 92 | // "Honor System" buttons |
| 93 | super.setup(); |
| 94 | |
Paul McLean | 365be3a | 2015-06-04 12:40:18 -0700 | [diff] [blame] | 95 | setPassFailButtonClickListeners(); |
| 96 | } |
| 97 | } |