Merge "Identity Credential: Use assumptions to avoid failures when IC HAL not present."
diff --git a/hostsidetests/apex/src/android/apex/cts/ApexTest.java b/hostsidetests/apex/src/android/apex/cts/ApexTest.java
index 0347299..9bb09d8 100644
--- a/hostsidetests/apex/src/android/apex/cts/ApexTest.java
+++ b/hostsidetests/apex/src/android/apex/cts/ApexTest.java
@@ -33,7 +33,7 @@
   }
 
   private boolean isGSI() throws Exception {
-    String systemProduct = getDevice().getProperty("ro.product.system.name");
+    String systemProduct = getDevice().getProperty("ro.product.system_ext.name");
     return systemProduct.equals("aosp_arm")
       || systemProduct.equals("aosp_arm64")
       || systemProduct.equals("aosp_x86")
diff --git a/hostsidetests/hdmicec/src/android/hdmicec/cts/CecDevice.java b/hostsidetests/hdmicec/src/android/hdmicec/cts/CecDevice.java
index 57e1782..3dac5d5 100644
--- a/hostsidetests/hdmicec/src/android/hdmicec/cts/CecDevice.java
+++ b/hostsidetests/hdmicec/src/android/hdmicec/cts/CecDevice.java
@@ -22,6 +22,7 @@
 public enum CecDevice {
     TV(0x0),
     RECORDING_1(0x1),
+    TUNER_1(0x3),
     PLAYBACK_1(0x4),
     AUDIO_SYSTEM(0x5),
     PLAYBACK_2(0x8),
diff --git a/hostsidetests/hdmicec/src/android/hdmicec/cts/CecMessage.java b/hostsidetests/hdmicec/src/android/hdmicec/cts/CecMessage.java
index 793d93d..6437ec0 100644
--- a/hostsidetests/hdmicec/src/android/hdmicec/cts/CecMessage.java
+++ b/hostsidetests/hdmicec/src/android/hdmicec/cts/CecMessage.java
@@ -28,6 +28,8 @@
     USER_CONTROL_RELEASED(0x45),
     GIVE_OSD_NAME(0x46),
     SET_OSD_NAME(0x47),
+    SYSTEM_AUDIO_MODE_REQUEST(0x70),
+    SET_SYSTEM_AUDIO_MODE(0x72),
     GIVE_SYSTEM_AUDIO_MODE_STATUS(0x7d),
     ACTIVE_SOURCE(0x82),
     GIVE_PHYSICAL_ADDRESS(0x83),
diff --git a/hostsidetests/hdmicec/src/android/hdmicec/cts/HdmiCecClientWrapper.java b/hostsidetests/hdmicec/src/android/hdmicec/cts/HdmiCecClientWrapper.java
index 0ddde5b..4bbf0ec 100644
--- a/hostsidetests/hdmicec/src/android/hdmicec/cts/HdmiCecClientWrapper.java
+++ b/hostsidetests/hdmicec/src/android/hdmicec/cts/HdmiCecClientWrapper.java
@@ -166,13 +166,14 @@
     }
 
     /**
-     * Sends a <USER_CONTROL_PRESSED> and <USER_CONTROL_RELEASED> from TV to target device
+     * Sends a <USER_CONTROL_PRESSED> and <USER_CONTROL_RELEASED> from source to destination
      * through the output console of the cec-communication channel with the mentioned keycode.
      */
-    public void sendUserControlPressAndRelease(int keycode, boolean holdKey) throws Exception {
+    public void sendUserControlPressAndRelease(CecDevice source, CecDevice destination,
+            int keycode, boolean holdKey) throws Exception {
         checkCecClient();
         String key = String.format("%02x", keycode);
-        String command = "tx " + CecDevice.TV + CecDevice.PLAYBACK_1 + ":" +
+        String command = "tx " + source + destination + ":" +
                 CecMessage.USER_CONTROL_PRESSED + ":" + key;
 
         if (holdKey) {
@@ -190,7 +191,7 @@
         mOutputConsole.newLine();
         /* Sleep less than 200ms between press and release */
         TimeUnit.MILLISECONDS.sleep(100);
-        mOutputConsole.write("tx " + CecDevice.TV + CecDevice.PLAYBACK_1 + ":" +
+        mOutputConsole.write("tx " + source + destination + ":" +
                               CecMessage.USER_CONTROL_RELEASED);
         mOutputConsole.flush();
     }
diff --git a/hostsidetests/hdmicec/src/android/hdmicec/cts/HdmiCecConstants.java b/hostsidetests/hdmicec/src/android/hdmicec/cts/HdmiCecConstants.java
index 343828b..6383a4a 100644
--- a/hostsidetests/hdmicec/src/android/hdmicec/cts/HdmiCecConstants.java
+++ b/hostsidetests/hdmicec/src/android/hdmicec/cts/HdmiCecConstants.java
@@ -23,6 +23,7 @@
     public static final int REBOOT_TIMEOUT = 60000;
 
     public static final int PHYSICAL_ADDRESS = 0x1000;
+    public static final int TV_PHYSICAL_ADDRESS = 0x0000;
     public static final int PHYSICAL_ADDRESS_LENGTH = 4; /* Num nibbles in CEC message */
 
     public static final int PLAYBACK_DEVICE_TYPE = 0x04;
diff --git a/hostsidetests/hdmicec/src/android/hdmicec/cts/audio/HdmiCecSystemAudioModeTest.java b/hostsidetests/hdmicec/src/android/hdmicec/cts/audio/HdmiCecSystemAudioModeTest.java
new file mode 100644
index 0000000..6f6e4dc
--- /dev/null
+++ b/hostsidetests/hdmicec/src/android/hdmicec/cts/audio/HdmiCecSystemAudioModeTest.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2020 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 android.hdmicec.cts.audio;
+
+import static org.junit.Assert.assertThat;
+import static org.hamcrest.CoreMatchers.is;
+
+import android.hdmicec.cts.CecDevice;
+import android.hdmicec.cts.CecMessage;
+import android.hdmicec.cts.HdmiCecClientWrapper;
+import android.hdmicec.cts.HdmiCecConstants;
+
+import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
+import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test;
+
+import org.junit.Rule;
+import org.junit.runner.RunWith;
+import org.junit.Test;
+
+/** HDMI CEC test to test system audio mode (Section 11.2.15) */
+@RunWith(DeviceJUnit4ClassRunner.class)
+public final class HdmiCecSystemAudioModeTest extends BaseHostJUnit4Test {
+    private static final CecDevice AUDIO_DEVICE = CecDevice.AUDIO_SYSTEM;
+    private static final int ON = 0x1;
+
+    @Rule
+    public HdmiCecClientWrapper hdmiCecClient = new HdmiCecClientWrapper(AUDIO_DEVICE, this);
+
+    /**
+     * Test 11.2.15-1
+     * Tests that the device handles <System Audio Mode Request> messages from various logical
+     * addresses correctly as a follower.
+     */
+    @Test
+    public void cect_11_2_15_1_SystemAudioModeRequestAsFollower() throws Exception {
+        hdmiCecClient.sendCecMessage(CecDevice.TV, AUDIO_DEVICE,
+                CecMessage.SYSTEM_AUDIO_MODE_REQUEST,
+                hdmiCecClient.formatParams(HdmiCecConstants.TV_PHYSICAL_ADDRESS));
+        String message = hdmiCecClient.checkExpectedOutput(CecMessage.SET_SYSTEM_AUDIO_MODE);
+        assertThat(hdmiCecClient.getParamsFromMessage(message), is(ON));
+
+        /* Repeat test for device 0x3 (TUNER_1) */
+        hdmiCecClient.sendCecMessage(CecDevice.TUNER_1, AUDIO_DEVICE,
+                CecMessage.SYSTEM_AUDIO_MODE_REQUEST,
+                hdmiCecClient.formatParams(HdmiCecConstants.TV_PHYSICAL_ADDRESS));
+        message = hdmiCecClient.checkExpectedOutput(CecMessage.SET_SYSTEM_AUDIO_MODE);
+        assertThat(hdmiCecClient.getParamsFromMessage(message), is(ON));
+    }
+}
diff --git a/hostsidetests/hdmicec/src/android/hdmicec/cts/playback/HdmiCecRemoteControlPassThroughTest.java b/hostsidetests/hdmicec/src/android/hdmicec/cts/playback/HdmiCecRemoteControlPassThroughTest.java
index c2d77a1..9ac7eab 100644
--- a/hostsidetests/hdmicec/src/android/hdmicec/cts/playback/HdmiCecRemoteControlPassThroughTest.java
+++ b/hostsidetests/hdmicec/src/android/hdmicec/cts/playback/HdmiCecRemoteControlPassThroughTest.java
@@ -93,17 +93,23 @@
         device.executeAdbCommand("logcat", "-c");
         // Start the APK and wait for it to complete.
         device.executeShellCommand(START_COMMAND);
-        hdmiCecClient.sendUserControlPressAndRelease(HdmiCecConstants.CEC_CONTROL_UP, false);
+        hdmiCecClient.sendUserControlPressAndRelease(CecDevice.TV, CecDevice.PLAYBACK_1,
+                HdmiCecConstants.CEC_CONTROL_UP, false);
         lookForLog("Short press KEYCODE_DPAD_UP");
-        hdmiCecClient.sendUserControlPressAndRelease(HdmiCecConstants.CEC_CONTROL_DOWN, false);
+        hdmiCecClient.sendUserControlPressAndRelease(CecDevice.TV, CecDevice.PLAYBACK_1,
+                HdmiCecConstants.CEC_CONTROL_DOWN, false);
         lookForLog("Short press KEYCODE_DPAD_DOWN");
-        hdmiCecClient.sendUserControlPressAndRelease(HdmiCecConstants.CEC_CONTROL_LEFT, false);
+        hdmiCecClient.sendUserControlPressAndRelease(CecDevice.TV, CecDevice.PLAYBACK_1,
+                HdmiCecConstants.CEC_CONTROL_LEFT, false);
         lookForLog("Short press KEYCODE_DPAD_LEFT");
-        hdmiCecClient.sendUserControlPressAndRelease(HdmiCecConstants.CEC_CONTROL_RIGHT, false);
+        hdmiCecClient.sendUserControlPressAndRelease(CecDevice.TV, CecDevice.PLAYBACK_1,
+                HdmiCecConstants.CEC_CONTROL_RIGHT, false);
         lookForLog("Short press KEYCODE_DPAD_RIGHT");
-        hdmiCecClient.sendUserControlPressAndRelease(HdmiCecConstants.CEC_CONTROL_SELECT, false);
+        hdmiCecClient.sendUserControlPressAndRelease(CecDevice.TV, CecDevice.PLAYBACK_1,
+                HdmiCecConstants.CEC_CONTROL_SELECT, false);
         lookForLog("Short press KEYCODE_DPAD_CENTER");
-        hdmiCecClient.sendUserControlPressAndRelease(HdmiCecConstants.CEC_CONTROL_BACK, false);
+        hdmiCecClient.sendUserControlPressAndRelease(CecDevice.TV, CecDevice.PLAYBACK_1,
+                HdmiCecConstants.CEC_CONTROL_BACK, false);
         lookForLog("Short press KEYCODE_BACK");
     }
 
@@ -121,17 +127,23 @@
         device.executeAdbCommand("logcat", "-c");
         // Start the APK and wait for it to complete.
         device.executeShellCommand(START_COMMAND);
-        hdmiCecClient.sendUserControlPressAndRelease(HdmiCecConstants.CEC_CONTROL_UP, true);
+        hdmiCecClient.sendUserControlPressAndRelease(CecDevice.TV, CecDevice.PLAYBACK_1,
+                HdmiCecConstants.CEC_CONTROL_UP, true);
         lookForLog("Long press KEYCODE_DPAD_UP");
-        hdmiCecClient.sendUserControlPressAndRelease(HdmiCecConstants.CEC_CONTROL_DOWN, true);
+        hdmiCecClient.sendUserControlPressAndRelease(CecDevice.TV, CecDevice.PLAYBACK_1,
+                HdmiCecConstants.CEC_CONTROL_DOWN, true);
         lookForLog("Long press KEYCODE_DPAD_DOWN");
-        hdmiCecClient.sendUserControlPressAndRelease(HdmiCecConstants.CEC_CONTROL_LEFT, true);
+        hdmiCecClient.sendUserControlPressAndRelease(CecDevice.TV, CecDevice.PLAYBACK_1,
+                HdmiCecConstants.CEC_CONTROL_LEFT, true);
         lookForLog("Long press KEYCODE_DPAD_LEFT");
-        hdmiCecClient.sendUserControlPressAndRelease(HdmiCecConstants.CEC_CONTROL_RIGHT, true);
+        hdmiCecClient.sendUserControlPressAndRelease(CecDevice.TV, CecDevice.PLAYBACK_1,
+                HdmiCecConstants.CEC_CONTROL_RIGHT, true);
         lookForLog("Long press KEYCODE_DPAD_RIGHT");
-        hdmiCecClient.sendUserControlPressAndRelease(HdmiCecConstants.CEC_CONTROL_SELECT, true);
+        hdmiCecClient.sendUserControlPressAndRelease(CecDevice.TV, CecDevice.PLAYBACK_1,
+                HdmiCecConstants.CEC_CONTROL_SELECT, true);
         lookForLog("Long press KEYCODE_DPAD_CENTER");
-        hdmiCecClient.sendUserControlPressAndRelease(HdmiCecConstants.CEC_CONTROL_BACK, true);
+        hdmiCecClient.sendUserControlPressAndRelease(CecDevice.TV, CecDevice.PLAYBACK_1,
+                HdmiCecConstants.CEC_CONTROL_BACK, true);
         lookForLog("Long press KEYCODE_BACK");
     }
 }
diff --git a/tests/tests/location/src/android/location/cts/LocationManagerTest.java b/tests/tests/location/src/android/location/cts/LocationManagerTest.java
index 89ee843..27dd4ef 100644
--- a/tests/tests/location/src/android/location/cts/LocationManagerTest.java
+++ b/tests/tests/location/src/android/location/cts/LocationManagerTest.java
@@ -86,7 +86,7 @@
     /**
      * Helper method to add a test provider with given name.
      */
-    private void addTestProvider(final String providerName) {
+    private void addTestProvider(final String providerName) throws Exception {
         mManager.addTestProvider(providerName, true, //requiresNetwork,
                 false, // requiresSatellite,
                 true,  // requiresCell,
@@ -97,6 +97,7 @@
                 Criteria.POWER_MEDIUM, // powerRequirement
                 Criteria.ACCURACY_FINE); // accuracy
         mManager.setTestProviderEnabled(providerName, true);
+	Thread.sleep(500);
     }
 
     @Override
@@ -146,7 +147,7 @@
         }
     }
 
-    public void testGetProviders() {
+    public void testGetProviders() throws Exception {
         List<String> providers = mManager.getAllProviders();
         assertTrue(providers.size() >= 2);
         assertTrue(hasTestProvider(providers));
@@ -165,6 +166,8 @@
         int oldSizeTrueProviders = providers.size();
 
         mManager.setTestProviderEnabled(TEST_MOCK_PROVIDER_NAME, false);
+	Thread.sleep(500);
+
         providers = mManager.getProviders(true);
         assertEquals(oldSizeTrueProviders - 1, providers.size());
         assertFalse(hasTestProvider(providers));
@@ -272,7 +275,7 @@
      * throws an {@link java.lang.IllegalArgumentException} if there is no such test provider,
      * so we have to add it before we clear it.
      */
-    private void forceRemoveTestProvider(String provider) {
+    private void forceRemoveTestProvider(String provider) throws Exception {
         addTestProvider(provider);
         mManager.removeTestProvider(provider);
     }
@@ -353,7 +356,7 @@
      * known way to determine if a given provider is a test provider.
      * @throws InterruptedException
      */
-    public void testReplaceRealProvidersWithMocks() throws InterruptedException {
+    public void testReplaceRealProvidersWithMocks() throws Exception {
         for (String providerName : mManager.getAllProviders()) {
             if (!providerName.equals(TEST_MOCK_PROVIDER_NAME) &&
                 !providerName.equals(LocationManager.PASSIVE_PROVIDER)) {
@@ -530,7 +533,7 @@
         }
     }
 
-    public void testLocationUpdatesWithCriteriaAndPendingIntent() throws InterruptedException {
+    public void testLocationUpdatesWithCriteriaAndPendingIntent() throws Exception {
         double latitude1 = 10;
         double longitude1 = 20;
         double latitude2 = 30;
@@ -586,7 +589,7 @@
         unmockFusedLocation();
     }
 
-    public void testSingleUpdateWithCriteriaAndPendingIntent() throws InterruptedException {
+    public void testSingleUpdateWithCriteriaAndPendingIntent() throws Exception {
         double latitude1 = 10;
         double longitude1 = 20;
         double latitude2 = 30;
@@ -650,7 +653,7 @@
     }
 
     public void testLocationUpdatesWithCriteriaAndLocationListenerAndLooper()
-            throws InterruptedException {
+            throws Exception {
         double latitude1 = 40;
         double longitude1 = 10;
         double latitude2 = 20;
@@ -706,7 +709,7 @@
     }
 
     public void testSingleUpdateWithCriteriaAndLocationListenerAndLooper()
-            throws InterruptedException {
+            throws Exception {
         double latitude1 = 40;
         double longitude1 = 10;
         double latitude2 = 20;
@@ -850,7 +853,7 @@
         mManager.removeNmeaListener((OnNmeaMessageListener) null);
     }
 
-    public void testIsProviderEnabled() {
+    public void testIsProviderEnabled() throws Exception {
         // this test assumes enabled TEST_MOCK_PROVIDER_NAME was created in setUp.
         assertNotNull(mManager.getProvider(TEST_MOCK_PROVIDER_NAME));
         assertTrue(mManager.isProviderEnabled(TEST_MOCK_PROVIDER_NAME));
@@ -867,7 +870,7 @@
 
         mManager.setTestProviderEnabled(TEST_MOCK_PROVIDER_NAME, true);
         try {
-            Thread.sleep(100);
+            Thread.sleep(500);
         } catch (Exception e) {
             Log.e(TAG, "fail in testIsProviderEnabled");
         }
@@ -1183,7 +1186,7 @@
         return criteria;
      }
 
-    private void mockFusedLocation() {
+    private void mockFusedLocation() throws Exception {
         addTestProvider(FUSED_PROVIDER_NAME);
     }
 
diff --git a/tests/tests/telephony/current/src/android/telephony/euicc/cts/EuiccServiceTest.java b/tests/tests/telephony/current/src/android/telephony/euicc/cts/EuiccServiceTest.java
index 5b0492f..aa60c8e 100644
--- a/tests/tests/telephony/current/src/android/telephony/euicc/cts/EuiccServiceTest.java
+++ b/tests/tests/telephony/current/src/android/telephony/euicc/cts/EuiccServiceTest.java
@@ -33,6 +33,7 @@
 import android.service.euicc.IDownloadSubscriptionCallback;
 import android.service.euicc.IEraseSubscriptionsCallback;
 import android.service.euicc.IEuiccService;
+import android.service.euicc.IEuiccServiceDumpResultCallback;
 import android.service.euicc.IGetDefaultDownloadableSubscriptionListCallback;
 import android.service.euicc.IGetDownloadableSubscriptionMetadataCallback;
 import android.service.euicc.IGetEidCallback;
@@ -432,4 +433,25 @@
 
         assertTrue(mCallback.isMethodCalled());
     }
+
+    @Test
+    public void testDump() throws Exception {
+        mCountDownLatch = new CountDownLatch(1);
+
+        mEuiccServiceBinder.dump(new IEuiccServiceDumpResultCallback.Stub() {
+            @Override
+            public void onComplete(String logs) {
+                assertEquals(MockEuiccService.MOCK_DUMPED_LOG, logs);
+                mCountDownLatch.countDown();
+            }
+        });
+
+        try {
+            mCountDownLatch.await(CALLBACK_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
+        } catch (InterruptedException e) {
+            fail(e.toString());
+        }
+
+        assertTrue(mCallback.isMethodCalled());
+    }
 }
diff --git a/tests/tests/telephony/current/src/android/telephony/euicc/cts/MockEuiccService.java b/tests/tests/telephony/current/src/android/telephony/euicc/cts/MockEuiccService.java
index c952446..bfd1601 100644
--- a/tests/tests/telephony/current/src/android/telephony/euicc/cts/MockEuiccService.java
+++ b/tests/tests/telephony/current/src/android/telephony/euicc/cts/MockEuiccService.java
@@ -29,10 +29,13 @@
 import android.telephony.euicc.EuiccManager;
 import android.telephony.euicc.EuiccManager.OtaStatus;
 
+import java.io.PrintWriter;
+
 /** Dummy implementation of {@link EuiccService} for testing. */
 public class MockEuiccService extends EuiccService {
     static String MOCK_EID = "89000000000000000000000000000000";
     static String MOCK_OS_VERSION = "1.0";
+    static final String MOCK_DUMPED_LOG = "log messages";
 
     interface IMockEuiccServiceCallback {
         void setMethodCalled();
@@ -61,6 +64,12 @@
     }
 
     @Override
+    public void dump(PrintWriter printWriter) {
+        sMockEuiccServiceCallback.setMethodCalled();
+        printWriter.append(MOCK_DUMPED_LOG);
+    }
+
+    @Override
     public void onStartOtaIfNecessary(int slotId, OtaStatusChangedCallback statusChangedCallback) {
         sMockEuiccServiceCallback.setMethodCalled();
         statusChangedCallback.onOtaStatusChanged(EuiccManager.EUICC_OTA_SUCCEEDED);