RECORD_SOUND must be handled by sound recorder app

"Sound recorder support cross profile audio capture" should not appear
on devices without sound recording app

Bug: 25821804
Change-Id: I729570361685a4bb18ba6bb3eea7ccf699b72d14
diff --git a/apps/CtsVerifier/AndroidManifest.xml b/apps/CtsVerifier/AndroidManifest.xml
index a29e594..9df08ed 100644
--- a/apps/CtsVerifier/AndroidManifest.xml
+++ b/apps/CtsVerifier/AndroidManifest.xml
@@ -1488,10 +1488,9 @@
             </intent-filter>
         </activity>
 
-        <activity android:name=".managedprovisioning.CrossProfileTestActivity">
+        <activity android:name=".managedprovisioning.HandleIntentActivity"
+                android:enabled="false">
             <intent-filter>
-                <action android:name="com.android.cts.verifier.managedprovisioning.CROSS_PROFILE_TO_PERSONAL" />
-                <action android:name="com.android.cts.verifier.managedprovisioning.CROSS_PROFILE_TO_WORK" />
                 <!-- We need to have at least one activity listening to these intents on the device
                      to test if these are forwarded from the managed profile to the parent or
                      the other way around. -->
@@ -1574,6 +1573,14 @@
             </intent-filter>
         </activity>
 
+        <activity android:name=".managedprovisioning.CrossProfileTestActivity">
+            <intent-filter>
+                <action android:name="com.android.cts.verifier.managedprovisioning.CROSS_PROFILE_TO_PERSONAL" />
+                <action android:name="com.android.cts.verifier.managedprovisioning.CROSS_PROFILE_TO_WORK" />
+                <category android:name="android.intent.category.DEFAULT" />
+            </intent-filter>
+        </activity>
+
         <activity android:name=".managedprovisioning.WorkStatusTestActivity">
             <intent-filter>
                 <action android:name="com.android.cts.verifier.managedprovisioning.WORK_STATUS_ICON" />
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/ByodFlowTestActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/ByodFlowTestActivity.java
index 33e613f..9e3b2aa 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/ByodFlowTestActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/ByodFlowTestActivity.java
@@ -526,11 +526,15 @@
 
     private void checkIntentFilters() {
         try {
+            // Enable component HandleIntentActivity before intent filters are checked.
+            setHandleIntentActivityEnabledSetting(PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
             // We disable the ByodHelperActivity in the primary profile. So, this intent
             // will be handled by the ByodHelperActivity in the managed profile.
             Intent intent = new Intent(ByodHelperActivity.ACTION_CHECK_INTENT_FILTERS);
             startActivityForResult(intent, REQUEST_INTENT_FILTERS_STATUS);
         } catch (ActivityNotFoundException e) {
+            // Disable component HandleIntentActivity if intent filters check fails.
+            setHandleIntentActivityEnabledSetting(PackageManager.COMPONENT_ENABLED_STATE_DISABLED);
             Log.d(TAG, "checkIntentFilters: ActivityNotFoundException", e);
             setTestResult(mIntentFiltersTest, TestResult.TEST_RESULT_FAILED);
             showToast(R.string.provisioning_byod_no_activity);
@@ -538,6 +542,8 @@
     }
 
     private void handleIntentFiltersStatus(int resultCode) {
+        // Disable component HandleIntentActivity after intent filters are checked.
+        setHandleIntentActivityEnabledSetting(PackageManager.COMPONENT_ENABLED_STATE_DISABLED);
         // we use the resultCode from ByodHelperActivity in the managed profile to know if certain
         // intents fired from the managed profile are forwarded.
         final boolean intentFiltersSetForManagedIntents = (resultCode == RESULT_OK);
@@ -573,4 +579,10 @@
         }
     }
 
+    private void setHandleIntentActivityEnabledSetting(final int enableState) {
+        getPackageManager().setComponentEnabledSetting(
+            new ComponentName(ByodFlowTestActivity.this, HandleIntentActivity.class.getName()),
+            enableState, PackageManager.DONT_KILL_APP);
+    }
+
 }
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/HandleIntentActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/HandleIntentActivity.java
new file mode 100644
index 0000000..88cf105
--- /dev/null
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/managedprovisioning/HandleIntentActivity.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.cts.verifier.managedprovisioning;
+
+import android.app.Activity;
+
+public class HandleIntentActivity extends Activity { }