1 /* 2 * Copyright (C) 2023 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.media.AudioDeviceInfo; 20 import android.os.Bundle; 21 import android.view.View; 22 import android.widget.TextView; 23 24 import com.android.cts.verifier.R; 25 import com.android.cts.verifier.audio.audiolib.AudioDeviceUtils; 26 27 // MegaAudio 28 import org.hyphonate.megaaudio.player.AudioSourceProvider; 29 import org.hyphonate.megaaudio.player.sources.SparseChannelAudioSourceProvider; 30 import org.hyphonate.megaaudio.recorder.AudioSinkProvider; 31 import org.hyphonate.megaaudio.recorder.sinks.AppCallbackAudioSinkProvider; 32 33 public class AudioDataPathsAnalogActivity extends AudioDataPathsBaseActivity { 34 private static final String TAG = "AudioDataPathsAnalogActivity"; 35 36 private boolean mHeadsetSupport; 37 38 @Override onCreate(Bundle savedInstanceState)39 protected void onCreate(Bundle savedInstanceState) { 40 setContentView(R.layout.audio_datapaths_analog); 41 42 super.onCreate(savedInstanceState); 43 setInfoResources( 44 R.string.audio_datapaths_analog_test, R.string.audio_datapaths_analog_info, -1); 45 46 boolean canRunTest = 47 AudioDeviceUtils.supportsAnalogHeadset(this) != AudioDeviceUtils.SUPPORTSDEVICE_NO; 48 49 enableTestButtons(canRunTest); 50 51 getPassButton().setEnabled(passBtnEnabled()); 52 } 53 gatherTestModules(TestManager testManager)54 void gatherTestModules(TestManager testManager) { 55 AudioSourceProvider leftSineSourceProvider = new SparseChannelAudioSourceProvider( 56 SparseChannelAudioSourceProvider.CHANNELMASK_LEFT); 57 AudioSourceProvider rightSineSourceProvider = new SparseChannelAudioSourceProvider( 58 SparseChannelAudioSourceProvider.CHANNELMASK_RIGHT); 59 60 AudioSinkProvider micSinkProvider = 61 new AppCallbackAudioSinkProvider(mAnalysisCallbackHandler); 62 63 TestModule testModule; 64 65 testModule = new TestModule( 66 AudioDeviceInfo.TYPE_WIRED_HEADSET, 48000, 2, 67 AudioDeviceInfo.TYPE_WIRED_HEADSET, 48000, 1); 68 testModule.setSectionTitle("Analog Jack"); 69 testModule.setDescription("Analog:2:Left Analog:1"); 70 testModule.setSources(leftSineSourceProvider, micSinkProvider); 71 testManager.addTestModule(testModule); 72 73 testModule = new TestModule( 74 AudioDeviceInfo.TYPE_WIRED_HEADSET, 48000, 2, 75 AudioDeviceInfo.TYPE_WIRED_HEADSET, 48000, 1); 76 testModule.setDescription("Analog:2:Right Analog:1"); 77 testModule.setSources(rightSineSourceProvider, micSinkProvider); 78 testManager.addTestModule(testModule); 79 } 80 postValidateTestDevices(int numValidTestModules)81 void postValidateTestDevices(int numValidTestModules) { 82 TextView promptView = (TextView) findViewById(R.id.audio_datapaths_deviceprompt); 83 if (mIsHandheld) { 84 int headsetSupport = AudioDeviceUtils.supportsAnalogHeadset(this); 85 if (headsetSupport == AudioDeviceUtils.SUPPORTSDEVICE_YES) { 86 if (mTestManager.calculatePass()) { 87 promptView.setVisibility(View.GONE); 88 } else { 89 promptView.setVisibility(numValidTestModules == 0 ? View.VISIBLE : View.GONE); 90 } 91 mHeadsetSupport = true; 92 } else if (headsetSupport == AudioDeviceUtils.SUPPORTSDEVICE_NO) { 93 promptView.setText( 94 getResources().getString(R.string.audio_datapaths_analog_noanalogjack)); 95 mHeadsetSupport = false; 96 } else { 97 // AudioDeviceUtils.SUPPORTSDEVICE_UNDETERMINED 98 promptView.setText(getResources().getString( 99 R.string.audio_datapaths_analog_headsetundetermined)); 100 mHeadsetSupport = false; // until proven otherwise 101 } 102 103 } else { 104 promptView.setText(getResources().getString(R.string.audio_datapaths_analog_autopass)); 105 } 106 107 enableTestButtons(numValidTestModules != 0); 108 } 109 hasPeripheralSupport()110 protected boolean hasPeripheralSupport() { 111 return mHeadsetSupport; 112 } 113 } 114