Cherry-Pick of ag/22299858 - Prompt for ReportLog permissions only for tests that use ReportLog

Bug: 260029549
Bug: 244389128
Test: install, run "adb shell appops reset com.android.cts.verifier" run each audio test
Change-Id: I93536570d5749e8ce929b9d71b29ac690a8f98ca
Merged-In: I93536570d5749e8ce929b9d71b29ac690a8f98ca
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/PassFailButtons.java b/apps/CtsVerifier/src/com/android/cts/verifier/PassFailButtons.java
index 36975c2..fab437e 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/PassFailButtons.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/PassFailButtons.java
@@ -148,8 +148,11 @@
         protected boolean mRequireReportLogToPass;
 
         public Activity() {
-            newReportLog();
             this.mHistoryCollection = new TestResultHistoryCollection();
+            if (requiresReportLog()) {
+                // if the subclass reports a report filename, they need a ReportLog object
+                newReportLog();
+            }
         }
 
         @Override
@@ -161,7 +164,7 @@
                 mWakeLock.acquire();
             }
 
-            if (!this.mReportLog.isOpen()) {
+            if (mReportLog != null && !mReportLog.isOpen()) {
                 showReportLogWarningDialog(this);
             }
         }
@@ -216,6 +219,14 @@
                     getReportFileName(), getReportSectionName());
         }
 
+        /**
+         * Specifies if the test module will write a ReportLog entry
+         * @return true if the test module will write a ReportLog entry
+         */
+        public boolean requiresReportLog() {
+            return false;
+        }
+
         @Override
         public CtsVerifierReportLog getReportLog() {
             return mReportLog;
@@ -226,7 +237,7 @@
          * @return true if the ReportLog is open OR if the test does not require that.
          */
         public boolean isReportLogOkToPass() {
-            return !mRequireReportLogToPass || mReportLog.isOpen();
+            return !mRequireReportLogToPass || (mReportLog != null & mReportLog.isOpen());
         }
 
         /**
@@ -273,8 +284,8 @@
         private final TestResultHistoryCollection mHistoryCollection;
 
         public ListActivity() {
-            this.mReportLog = new CtsVerifierReportLog(getReportFileName(), getReportSectionName());
-            this.mHistoryCollection = new TestResultHistoryCollection();
+            mHistoryCollection = new TestResultHistoryCollection();
+            mReportLog = null;
         }
 
         @Override
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/audio/AnalogHeadsetAudioActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/audio/AnalogHeadsetAudioActivity.java
index 3b207b3d..e5c57f6 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/audio/AnalogHeadsetAudioActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/audio/AnalogHeadsetAudioActivity.java
@@ -114,7 +114,6 @@
     private static final String KEY_KEYCODE_VOLUME_DOWN = "keycode_volume_down";
 
     public AnalogHeadsetAudioActivity() {
-        super();
     }
 
     @Override
@@ -206,9 +205,11 @@
         }
     }
 
-    //
-    // PassFailButtons Overrides
-    //
+    @Override
+    public boolean requiresReportLog() {
+        return true;
+    }
+
     @Override
     public String getReportFileName() { return PassFailButtons.AUDIO_TESTS_REPORT_LOG_NAME; }
 
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/audio/AudioFrequencyActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/audio/AudioFrequencyActivity.java
index d992e98..6ff2cdb 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/audio/AudioFrequencyActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/audio/AudioFrequencyActivity.java
@@ -54,7 +54,6 @@
     // i.e. AudioFrequencyActivity <- RefMicActivity
     private OnBtnClickListener mBtnClickListener = new OnBtnClickListener();
 
-
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/audio/AudioInputDeviceNotificationsActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/audio/AudioInputDeviceNotificationsActivity.java
index 9a5f314..402025d 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/audio/AudioInputDeviceNotificationsActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/audio/AudioInputDeviceNotificationsActivity.java
@@ -25,6 +25,7 @@
 import android.widget.TextView;
 
 import com.android.cts.verifier.R;
+import com.android.cts.verifier.audio.audiolib.AudioDeviceUtils;
 
 /**
  * Tests Audio Device Connection events for output by prompting the user to insert/remove a
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/audio/AudioLoopbackLatencyActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/audio/AudioLoopbackLatencyActivity.java
index c97edc7..4e52981 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/audio/AudioLoopbackLatencyActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/audio/AudioLoopbackLatencyActivity.java
@@ -507,6 +507,11 @@
     }
 
     @Override
+    public boolean requiresReportLog() {
+        return true;
+    }
+
+    @Override
     public String getReportFileName() { return PassFailButtons.AUDIO_TESTS_REPORT_LOG_NAME; }
 
     @Override
@@ -524,7 +529,7 @@
 
     private void recordRouteResults(int routeIndex) {
         if (mTestSpecs[routeIndex].mTestRun) {
-            CtsVerifierReportLog reportLog = newReportLog();
+            CtsVerifierReportLog reportLog = getReportLog();
 
             int audioLevel = mAudioLevelSeekbar.getProgress();
             reportLog.addValue(
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/audio/AudioMicrophoneMuteToggleActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/audio/AudioMicrophoneMuteToggleActivity.java
index 1e250ef..87b5f12 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/audio/AudioMicrophoneMuteToggleActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/audio/AudioMicrophoneMuteToggleActivity.java
@@ -55,6 +55,9 @@
     private static final String KEY_REC_RATE = "rec_rate";
     private static final String KEY_AUDIO_SOURCE = "audio_source";
 
+    public AudioMicrophoneMuteToggleActivity() {
+    }
+
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/audio/AudioOutputDeviceNotificationsActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/audio/AudioOutputDeviceNotificationsActivity.java
index 5fb51c4..2025121 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/audio/AudioOutputDeviceNotificationsActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/audio/AudioOutputDeviceNotificationsActivity.java
@@ -25,6 +25,7 @@
 import android.widget.TextView;
 
 import com.android.cts.verifier.R;
+import com.android.cts.verifier.audio.audiolib.AudioDeviceUtils;
 
 /**
  * Tests Audio Device Connection events for output devices by prompting the user to
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/audio/AudioOutputRoutingNotificationsActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/audio/AudioOutputRoutingNotificationsActivity.java
index 1ece2f1..f6eb5f0 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/audio/AudioOutputRoutingNotificationsActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/audio/AudioOutputRoutingNotificationsActivity.java
@@ -32,9 +32,9 @@
 
 import com.android.compatibility.common.util.ResultType;
 import com.android.compatibility.common.util.ResultUnit;
-import com.android.cts.verifier.audio.audiolib.AudioDeviceUtils;
 import com.android.cts.verifier.CtsVerifierReportLog;
 import com.android.cts.verifier.R;
+import com.android.cts.verifier.audio.audiolib.AudioDeviceUtils;
 
 import org.hyphonate.megaaudio.player.AudioSourceProvider;
 import org.hyphonate.megaaudio.player.JavaPlayer;
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/audio/AudioTap2ToneActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/audio/AudioTap2ToneActivity.java
index c61689c..7c58394 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/audio/AudioTap2ToneActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/audio/AudioTap2ToneActivity.java
@@ -144,6 +144,21 @@
 
     private double[] mLatencyMillis = new double[NUM_TEST_PHASES];
 
+    @Override
+    public boolean requiresReportLog() {
+        return true;
+    }
+
+    @Override
+    public String getReportFileName() {
+        return PassFailButtons.AUDIO_TESTS_REPORT_LOG_NAME;
+    }
+
+    @Override
+    public final String getReportSectionName() {
+        return setTestNameSuffix(sCurrentDisplayMode, "tap_to_tone_latency");
+    }
+
     // ReportLog Schema
     // Note that each key will be suffixed with the ID of the API tested
     private static final String KEY_LATENCY_MIN = "latency_min_";
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/audio/AudioWiredDeviceBaseActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/audio/AudioWiredDeviceBaseActivity.java
index 97813af..efb9c56 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/audio/AudioWiredDeviceBaseActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/audio/AudioWiredDeviceBaseActivity.java
@@ -47,6 +47,9 @@
     protected static final String KEY_ROUTING_RECEIVED = "routing_received";
     protected static final String KEY_CONNECTED_PERIPHERAL = "routing_connected_peripheral";
 
+    AudioWiredDeviceBaseActivity() {
+    }
+
     private void recordWiredPortFound(boolean found) {
         getReportLog().addValue(
                 "User Reported Wired Port",
@@ -101,6 +104,11 @@
     // PassFailButtons Overrides
     //
     @Override
+    public boolean requiresReportLog() {
+        return true;
+    }
+
+    @Override
     public String getReportFileName() {
         return PassFailButtons.AUDIO_TESTS_REPORT_LOG_NAME;
     }
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/audio/ProAudioActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/audio/ProAudioActivity.java
index e93d2b3..337cce7 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/audio/ProAudioActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/audio/ProAudioActivity.java
@@ -79,7 +79,6 @@
     private static final String KEY_CLAIMS_HDMI = "claims_hdmi";
 
     public ProAudioActivity() {
-        super();
     }
 
     // HDMI Stuff
@@ -247,6 +246,11 @@
     // PassFailButtons Overrides
     //
     @Override
+    public boolean requiresReportLog() {
+        return true;
+    }
+
+    @Override
     public String getReportFileName() { return PassFailButtons.AUDIO_TESTS_REPORT_LOG_NAME; }
 
     @Override
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 298a3bb..48cb942 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralActivity.java
@@ -100,6 +100,16 @@
         }
     }
 
+    @Override
+    public boolean requiresReportLog() {
+        return true;
+    }
+
+    @Override
+    public String getReportFileName() {
+        return PassFailButtons.AUDIO_TESTS_REPORT_LOG_NAME;
+    }
+
     private void recordUSBAudioStatus(boolean has) {
         getReportLog().addValue(
                 KEY_CLAIMS_HOST,
@@ -119,8 +129,6 @@
     }
 
     public USBAudioPeripheralActivity(boolean mandatedRequired) {
-        super();
-
         // determine if to show "UNSUPPORTED" if the mandated peripheral is required.
         mIsMandatedRequired = mandatedRequired;
 
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralNotificationsTest.java b/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralNotificationsTest.java
index 6270a5a..c768ab6 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralNotificationsTest.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/audio/USBAudioPeripheralNotificationsTest.java
@@ -125,6 +125,16 @@
         }
     }
 
+    @Override
+    public boolean requiresReportLog() {
+        return true;
+    }
+
+    @Override
+    public String getReportFileName() {
+        return PassFailButtons.AUDIO_TESTS_REPORT_LOG_NAME;
+    }
+
     private void reportPlugIntent(Intent intent) {
         // [ 7.8 .2.2/H-2-1] MUST broadcast Intent ACTION_HEADSET_PLUG with "microphone" extra
         // set to 0 when the USB audio terminal types 0x0302 is detected.