Merge "Snap for 8103809 from 543526f4c2fb90396c63df47d070c796aaf821ca to android12-tests-release" into android12-tests-release
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/usb/device/UsbDeviceTestActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/usb/device/UsbDeviceTestActivity.java
index faee07a..e68983b 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/usb/device/UsbDeviceTestActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/usb/device/UsbDeviceTestActivity.java
@@ -84,6 +84,7 @@
     private Thread mTestThread;
     private TextView mStatus;
     private ProgressBar mProgress;
+    private UsbDevice mDevice;
 
     /**
      * Some N and older accessories do not send a zero sized package after a request that is a
@@ -156,7 +157,6 @@
                         case ACTION_USB_PERMISSION:
                             boolean granted = intent.getBooleanExtra(
                                     UsbManager.EXTRA_PERMISSION_GRANTED, false);
-
                             if (granted) {
                                 if (!AoapInterface.isDeviceInAoapMode(device)) {
                                     mStatus.setText(R.string.usb_device_test_step3);
@@ -194,7 +194,6 @@
                 }
             }
         };
-
         registerReceiver(mUsbDeviceConnectionReceiver, filter);
     }
 
@@ -1557,6 +1556,15 @@
         connection.close();
     }
 
+    private void syncReconnectDevice(@NonNull UsbDevice device) {
+        this.mDevice = device;
+    }
+
+    private UsbDevice getReconnectDevice() {
+        return mDevice;
+    }
+
+
     /**
      * <p> This attachedtask the requests and does not care about them anymore after the
      * system took them. The {@link attachedTask} handles the test after the main test done.
@@ -1600,6 +1608,8 @@
             public void onReceive(Context context, Intent intent) {
                 synchronized (UsbDeviceTestActivity.this) {
                     UsbDevice device = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
+                    syncReconnectDevice(device);
+
                     switch (intent.getAction()) {
                         case ACTION_USB_PERMISSION:
                             boolean granted = intent.getBooleanExtra(
@@ -2267,6 +2277,12 @@
             // If reconnect timeout make the test fail
             assertEquals(0, errors.size());
 
+            // Update connection handle after reconnect
+            device = getReconnectDevice();
+            assertNotNull(device);
+            connection = mUsbManager.openDevice(device);
+            assertNotNull(connection);
+
             connection.close();
 
             // We should not be able to communicate with the device anymore
diff --git a/tests/filesystem/AndroidTest.xml b/tests/filesystem/AndroidTest.xml
index df140d6..3f0ddc0 100644
--- a/tests/filesystem/AndroidTest.xml
+++ b/tests/filesystem/AndroidTest.xml
@@ -26,8 +26,8 @@
     <test class="com.android.tradefed.testtype.AndroidJUnitTest" >
         <option name="package" value="android.filesystem.cts" />
         <option name="runtime-hint" value="14m48s" />
-        <!-- test-timeout unit is ms, value = 60 min -->
-        <option name="test-timeout" value="3600000" />
+        <!-- test-timeout unit is ms, value = 70 min -->
+        <option name="test-timeout" value="4200000" />
         <!-- shell-timeout unit is ms, value = 180 min for AlmostFullTest -->
         <option name="shell-timeout" value="10800000" />
         <!-- disable isolated storage so tests can write report log -->
diff --git a/tests/tests/hardware/src/android/hardware/input/cts/tests/InputTestCase.java b/tests/tests/hardware/src/android/hardware/input/cts/tests/InputTestCase.java
index ce9746b..209b912 100644
--- a/tests/tests/hardware/src/android/hardware/input/cts/tests/InputTestCase.java
+++ b/tests/tests/hardware/src/android/hardware/input/cts/tests/InputTestCase.java
@@ -82,6 +82,7 @@
     @Before
     public void setUp() throws Exception {
         mActivityRule.getActivity().clearUnhandleKeyCode();
+        mActivityRule.getActivity().setInputCallback(mInputListener);
         mDecorView = mActivityRule.getActivity().getWindow().getDecorView();
         mParser = new InputJsonParser(mInstrumentation.getTargetContext());
         mVid = mParser.readVendorId(mRegisterResourceId);
@@ -228,7 +229,6 @@
     }
 
     protected void verifyEvents(List<InputEvent> events) {
-        mActivityRule.getActivity().setInputCallback(mInputListener);
         // Make sure we received the expected input events
         if (events.size() == 0) {
             // If no event is expected we need to wait for event until timeout and fail on
diff --git a/tests/tests/wifi/src/android/net/wifi/cts/WifiNetworkSpecifierTest.java b/tests/tests/wifi/src/android/net/wifi/cts/WifiNetworkSpecifierTest.java
index 65bee68..c84525c 100644
--- a/tests/tests/wifi/src/android/net/wifi/cts/WifiNetworkSpecifierTest.java
+++ b/tests/tests/wifi/src/android/net/wifi/cts/WifiNetworkSpecifierTest.java
@@ -70,10 +70,13 @@
 import java.security.cert.X509Certificate;
 import java.security.spec.InvalidKeySpecException;
 import java.security.spec.PKCS8EncodedKeySpec;
+
 import java.util.List;
 import java.util.ArrayList;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
 
 /**
  * Tests the entire connection flow using {@link WifiNetworkSpecifier} embedded in a
@@ -227,6 +230,8 @@
                 () -> wifiManager.getPrivilegedConfiguredNetworks());
         assertWithMessage("Need at least one saved network")
                 .that(savedNetworks.isEmpty()).isFalse();
+        savedNetworks = savedNetworks.stream()
+                .filter(a -> !isEnterpriseConfig(a)).collect(Collectors.toList());
 
         // Pick any network in range.
         sTestNetwork = TestHelper.findMatchingSavedNetworksWithBssid(wifiManager, savedNetworks)
@@ -601,4 +606,10 @@
             assertThat(redacted.equals(specifier)).isTrue();
         }
     }
+
+    private static boolean isEnterpriseConfig(WifiConfiguration config) {
+        WifiEnterpriseConfig enterpriseConfig = config.enterpriseConfig;
+        return enterpriseConfig != null
+                && enterpriseConfig.getEapMethod() != WifiEnterpriseConfig.Eap.NONE;
+    }
 }