DO NOT MERGE Add ability to indicate support for USB Host Mode Audio

Bug: 149849032
Bug: 143046091
Test: Build, install and verify that the UI works as expected.
Change-Id: Ib604b8b31eec81a7bb71a9d6d00618d153ef09d0
diff --git a/apps/CtsVerifier/res/layout/uap_attribs_panel.xml b/apps/CtsVerifier/res/layout/uap_attribs_panel.xml
index 6c33d9f..b9c5d3e 100644
--- a/apps/CtsVerifier/res/layout/uap_attribs_panel.xml
+++ b/apps/CtsVerifier/res/layout/uap_attribs_panel.xml
@@ -9,6 +9,8 @@
     android:layout_width="match_parent"
     android:layout_height="wrap_content">
 
+    <include layout="@layout/uap_usb_confirm"/>
+
     <include layout="@layout/uap_profile_header"/>
 
     <LinearLayout
diff --git a/apps/CtsVerifier/res/layout/uap_buttons_panel.xml b/apps/CtsVerifier/res/layout/uap_buttons_panel.xml
index 4fdc757..355bfb6 100644
--- a/apps/CtsVerifier/res/layout/uap_buttons_panel.xml
+++ b/apps/CtsVerifier/res/layout/uap_buttons_panel.xml
@@ -9,6 +9,8 @@
     android:layout_width="match_parent"
     android:layout_height="wrap_content">
 
+    <include layout="@layout/uap_usb_confirm"/>
+
     <include layout="@layout/uap_profile_header"/>
 
     <LinearLayout
diff --git a/apps/CtsVerifier/res/layout/uap_play_panel.xml b/apps/CtsVerifier/res/layout/uap_play_panel.xml
index 2faa50c..30ef884 100644
--- a/apps/CtsVerifier/res/layout/uap_play_panel.xml
+++ b/apps/CtsVerifier/res/layout/uap_play_panel.xml
@@ -9,6 +9,8 @@
     android:layout_width="match_parent"
     android:layout_height="wrap_content">
 
+    <include layout="@layout/uap_usb_confirm"/>
+
     <include layout="@layout/uap_profile_header"/>
 
     <LinearLayout
diff --git a/apps/CtsVerifier/res/layout/uap_record_panel.xml b/apps/CtsVerifier/res/layout/uap_record_panel.xml
index 2deb738..a5bfcfc 100644
--- a/apps/CtsVerifier/res/layout/uap_record_panel.xml
+++ b/apps/CtsVerifier/res/layout/uap_record_panel.xml
@@ -9,6 +9,8 @@
     android:layout_width="match_parent"
     android:layout_height="wrap_content">
 
+    <include layout="@layout/uap_usb_confirm"/>
+
     <include layout="@layout/uap_profile_header"/>
 
     <LinearLayout
diff --git a/apps/CtsVerifier/res/layout/uap_usb_confirm.xml b/apps/CtsVerifier/res/layout/uap_usb_confirm.xml
new file mode 100644
index 0000000..ea73b88
--- /dev/null
+++ b/apps/CtsVerifier/res/layout/uap_usb_confirm.xml
@@ -0,0 +1,38 @@
+<LinearLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:orientation="vertical">
+
+    <TextView
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:text="@string/uap_test_question"/>
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="horizontal">
+
+        <Button
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:soundEffectsEnabled="false"
+            android:text="@string/uap_test_yes"
+            android:id="@+id/uap_tests_yes_btn" />
+
+        <Button
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:soundEffectsEnabled="false"
+            android:text="@string/uap_test_no"
+            android:id="@+id/uap_tests_no_btn" />
+
+        <Button
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:soundEffectsEnabled="false"
+            android:text="@string/uap_test_info"
+            android:id="@+id/uap_test_info_btn" />
+    </LinearLayout>
+</LinearLayout>
diff --git a/apps/CtsVerifier/res/values/strings.xml b/apps/CtsVerifier/res/values/strings.xml
index e6419e8..f2f49d7 100755
--- a/apps/CtsVerifier/res/values/strings.xml
+++ b/apps/CtsVerifier/res/values/strings.xml
@@ -4045,4 +4045,17 @@
         Click the button below to confirm that the incoming call was answered.
     </string>
     <string name="telecom_incoming_self_mgd_confirm_answer_button">Confirm Answer</string>
+
+    <string name="uap_test_no">No</string>
+    <string name="uap_test_yes">Yes</string>
+    <string name="uap_test_info">Info</string>
+    <string name="uap_test_question">Does this device allow for the connectiono of a USB reference microphone?</string>
+    <string name="uap_mic_dlg_caption">USB Host Mode Audio Required</string>
+    <string name="uap_mic_dlg_text">This test requires a USB audio peripheral to be connected to the device.
+    If the device under test does not support USB Host Mode Audio (either because it does not have a
+    USB port, or USB Host Mode Audio has been removed from the OS) you can be granted a provisional
+    pass on this test by pressing the \"No\" button and indicating \"Test Pass\" at the bottom.\n
+    Note: Handheld devices supporting USB host mode MUST support USB audio class (CDD 7.7 .2/H-1-1)\n
+    Note: Devices declaring feature android.hardware.audio.pro MUST implement USB host mode (CDD 5.10 C-1-3) and if they omit a 4 conductor 3.5mm audio jack MUST support USB audio class (CDD 5.10 C-3-1)
+    </string>
 </resources>
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralActivity.java
index 140757d..8f0a9b0 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralActivity.java
@@ -16,12 +16,18 @@
 
 package com.android.cts.verifier.audio;
 
+import android.app.AlertDialog;
+import com.android.compatibility.common.util.ReportLog;
+import com.android.compatibility.common.util.ResultType;
+import com.android.compatibility.common.util.ResultUnit;
 import android.media.AudioDeviceCallback;
 import android.media.AudioDeviceInfo;
 import android.media.AudioManager;
 import android.os.Bundle;
 import android.os.Handler;
 import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
 import android.widget.TextView;
 
 import com.android.cts.verifier.audio.peripheralprofile.PeripheralProfile;
@@ -55,6 +61,68 @@
 
     private TextView mPeripheralNameTx;
 
+    private OnBtnClickListener mBtnClickListener = new OnBtnClickListener();
+
+    //
+    // Common UI Handling
+    //
+    protected void connectUSBPeripheralUI() {
+        findViewById(R.id.uap_tests_yes_btn).setOnClickListener(mBtnClickListener);
+        findViewById(R.id.uap_tests_no_btn).setOnClickListener(mBtnClickListener);
+        findViewById(R.id.uap_test_info_btn).setOnClickListener(mBtnClickListener);
+
+        // Leave the default state in tact
+        // enableTestUI(false);
+    }
+
+    private void showUAPInfoDialog() {
+        new AlertDialog.Builder(this)
+                .setTitle(R.string.uap_mic_dlg_caption)
+                .setMessage(R.string.uap_mic_dlg_text)
+                .setPositiveButton(R.string.audio_general_ok, null)
+                .show();
+    }
+
+    private class OnBtnClickListener implements OnClickListener {
+        @Override
+        public void onClick(View v) {
+            switch (v.getId()) {
+                case R.id.uap_tests_yes_btn:
+                    recordUSBAudioStatus(true);
+                    enableTestUI(true);
+                    // disable test button so that they will now run the test(s)
+                    getPassButton().setEnabled(false);
+                    break;
+
+                case R.id.uap_tests_no_btn:
+                    recordUSBAudioStatus(false);
+                    enableTestUI(false);
+                    // Allow the user to "pass" the test.
+                    getPassButton().setEnabled(true);
+                    break;
+
+                case R.id.uap_test_info_btn:
+                    showUAPInfoDialog();
+                    break;
+            }
+        }
+    }
+
+    private void recordUSBAudioStatus(boolean has) {
+        getReportLog().addValue(
+                "User reported USB Host Audio Support: ",
+                has ? 1.0 : 0,
+                ResultType.NEUTRAL,
+                ResultUnit.NONE);
+    }
+
+    //
+    // Overrides
+    //
+    void enableTestUI(boolean enable) {
+
+    }
+
     public USBAudioPeripheralActivity(boolean mandatedRequired) {
         super();
 
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralAttributesActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralAttributesActivity.java
index 5029160..23ed91a 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralAttributesActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralAttributesActivity.java
@@ -47,6 +47,8 @@
 
         setPassFailButtonClickListeners();
         setInfoResources(R.string.usbaudio_attribs_test, R.string.usbaudio_attribs_info, -1);
+
+        connectUSBPeripheralUI();
     }
 
     //
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralButtonsActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralButtonsActivity.java
index d5031df..b6aa933 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralButtonsActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralButtonsActivity.java
@@ -83,6 +83,8 @@
         setInfoResources(R.string.usbaudio_buttons_test, R.string.usbaudio_buttons_info, -1);
 
         showDisableAssistantDialog();
+
+        connectUSBPeripheralUI();
     }
 
     private void showButtonsState() {
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralPlayActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralPlayActivity.java
index de9016a..4ae5ec3 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralPlayActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralPlayActivity.java
@@ -50,11 +50,17 @@
 
         setPassFailButtonClickListeners();
         setInfoResources(R.string.usbaudio_play_test, R.string.usbaudio_play_info, -1);
+
+        connectUSBPeripheralUI();
     }
 
     //
     // USBAudioPeripheralActivity
     // Headset not publicly available, violates CTS Verifier additional equipment guidelines.
+    void enableTestUI(boolean enable) {
+        mPlayBtn.setEnabled(enable);
+    }
+
     public void updateConnectStatus() {
         mPlayBtn.setEnabled(mIsPeripheralAttached);
         getPassButton().setEnabled(mIsPeripheralAttached);
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralRecordActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralRecordActivity.java
index 22a2678..a2ecf9e 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralRecordActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralRecordActivity.java
@@ -134,11 +134,18 @@
 
         setPassFailButtonClickListeners();
         setInfoResources(R.string.usbaudio_record_test, R.string.usbaudio_record_info, -1);
+
+        connectUSBPeripheralUI();
     }
 
     //
     // USBAudioPeripheralActivity
     //
+    void enableTestUI(boolean enable) {
+        mRecordBtn.setEnabled(enable);
+        mRecordLoopbackBtn.setEnabled(enable);
+    }
+
     public void updateConnectStatus() {
         mRecordBtn.setEnabled(mIsPeripheralAttached);
         mRecordLoopbackBtn.setEnabled(mIsPeripheralAttached);