Merge changes I5e9c9941,I3d94ddec,Ib62975af,I8537c68e,Id9c18ae6 into rvc-dev

* changes:
  Wifi: add CTS tests for WifiP2pGroup
  Wifi: add CTS tests for WifiP2pConfig
  Wifi: add CTS tests for WifiP2pInfo
  Wifi: add CTS tests for WifiP2pWfdInfo
  Wifi: add CTS tests for WifiP2pManager
diff --git a/tests/cts/net/assets/OWNERS b/tests/cts/net/assets/OWNERS
new file mode 100644
index 0000000..14edd1d
--- /dev/null
+++ b/tests/cts/net/assets/OWNERS
@@ -0,0 +1,4 @@
+# Bug component: 31808
+etancohen@google.com
+lorenzo@google.com
+satk@google.com
diff --git a/tests/cts/net/assets/ValidPasspointProfile.base64 b/tests/cts/net/assets/ValidPasspointProfile.base64
new file mode 100644
index 0000000..3f60eb8
--- /dev/null
+++ b/tests/cts/net/assets/ValidPasspointProfile.base64
@@ -0,0 +1 @@
+Q29udGVudC1UeXBlOiBtdWx0aXBhcnQvbWl4ZWQ7IGJvdW5kYXJ5PXtib3VuZGFyeX0KQ29udGVudC1UcmFuc2Zlci1FbmNvZGluZzogYmFzZTY0CgotLXtib3VuZGFyeX0KQ29udGVudC1UeXBlOiBhcHBsaWNhdGlvbi94LXBhc3Nwb2ludC1wcm9maWxlCkNvbnRlbnQtVHJhbnNmZXItRW5jb2Rpbmc6IGJhc2U2NAoKUEUxbmJYUlVjbVZsSUhodGJHNXpQU0p6ZVc1amJXdzZaRzFrWkdZeExqSWlQZ29nSUR4V1pYSkVWRVErTVM0eVBDOVdaWEpFVkVRK0NpQWdQRTV2WkdVK0NpQWdJQ0E4VG05a1pVNWhiV1UrVUdWeVVISnZkbWxrWlhKVGRXSnpZM0pwY0hScGIyNDhMMDV2WkdWT1lXMWxQZ29nSUNBZ1BGSlVVSEp2Y0dWeWRHbGxjejRLSUNBZ0lDQWdQRlI1Y0dVK0NpQWdJQ0FnSUNBZ1BFUkVSazVoYldVK2RYSnVPbmRtWVRwdGJ6cG9iM1J6Y0c5ME1tUnZkREF0Y0dWe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0S0lDQWdJQ0FnSUNBOEwwNXZaR1UrQ2lBZ0lDQWdJQ0FnUEU1dlpHVStDaUFnSUNBZ0lDQWdJQ0E4VG05a1pVNWhiV1UrVTBsTlBDOU9iMlJsVG1GdFpUNEtJQ0FnSUNBZ0lDQWdJRHhPYjJSbFBnb2dJQ0FnSUNBZ0lDQWdJQ0E4VG05a1pVNWhiV1UrU1UxVFNUd3ZUbTlrWlU1aGJXVStDaUFnSUNBZ0lDQWdJQ0FnSUR4V1lXeDFaVDR6TVRBME1UQXFQQzlXWVd4MVpUNEtJQ0FnSUNBZ0lDQWdJRHd2VG05a1pUNEtJQ0FnSUNBZ0lDQWdJQ0FnUEU1dlpHVStDaUFnSUNBZ0lDQWdJQ0FnSUNBZ1BFNXZaR1ZPWVcxbFBrVkJVRlI1Y0dVOEwwNXZaR1ZPWVcxbFBnb2dJQ0FnSUNBZ0lDQWdJQ0FnSUR4V1lXeDFaVDR5TXp3dlZtRnNkV1UrQ2lBZ0lDQWdJQ0FnSUNBZ0lEd3ZUbTlrWlQ0S0lDQWdJQ0FnSUNBOEwwNXZaR1UrQ2lBZ0lDQWdJRHd2VG05a1pUNEtJQ0FnSUR3dlRtOWtaVDRLSUNBOEwwNXZaR1UrQ2p3dlRXZHRkRlJ5WldVKwotLXtib3VuZGFyeX0tLQo=
diff --git a/tests/cts/net/src/android/net/wifi/cts/EasyConnectStatusCallbackTest.java b/tests/cts/net/src/android/net/wifi/cts/EasyConnectStatusCallbackTest.java
new file mode 100644
index 0000000..eef50a0
--- /dev/null
+++ b/tests/cts/net/src/android/net/wifi/cts/EasyConnectStatusCallbackTest.java
@@ -0,0 +1,170 @@
+/*
+ * Copyright (C) 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.net.wifi.cts;
+
+import static android.net.wifi.EasyConnectStatusCallback.EASY_CONNECT_EVENT_FAILURE_TIMEOUT;
+import static android.net.wifi.WifiConfiguration.SECURITY_TYPE_PSK;
+import static android.net.wifi.WifiManager.EASY_CONNECT_NETWORK_ROLE_STA;
+
+import android.app.UiAutomation;
+import android.content.Context;
+import android.net.wifi.EasyConnectStatusCallback;
+import android.net.wifi.WifiConfiguration;
+import android.net.wifi.WifiManager;
+import android.os.Handler;
+import android.os.HandlerExecutor;
+import android.os.HandlerThread;
+import android.test.AndroidTestCase;
+import android.util.SparseArray;
+import androidx.test.platform.app.InstrumentationRegistry;
+
+import java.util.concurrent.Executor;
+
+public class EasyConnectStatusCallbackTest extends AndroidTestCase {
+    private static final String TEST_SSID = "\"testSsid\"";
+    private static final String TEST_PASSPHRASE = "\"testPassword\"";
+    private static final int TEST_WAIT_DURATION_MS = 12_000; // Long delay is necessary, see below
+    private WifiManager mWifiManager;
+    private static final String TEST_DPP_URI =
+            "DPP:C:81/1;I:Easy_Connect_Demo;M:000102030405;"
+                    + "K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgACDmtXD1Sz6/5B4YRdmTkbkkFLDwk8f0yRnfm1Go"
+                    + "kpx/0=;;";
+    private final HandlerThread mHandlerThread = new HandlerThread("EasyConnectTest");
+    protected final Executor mExecutor;
+    {
+        mHandlerThread.start();
+        mExecutor = new HandlerExecutor(new Handler(mHandlerThread.getLooper()));
+    }
+    private final Object mLock = new Object();
+    private boolean mOnFailureCallback = false;
+    private int mErrorCode;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        if (!WifiFeature.isWifiSupported(getContext())) {
+            // skip the test if WiFi is not supported
+            return;
+        }
+
+        mWifiManager = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE);
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    private EasyConnectStatusCallback mEasyConnectStatusCallback = new EasyConnectStatusCallback() {
+        @Override
+        public void onEnrolleeSuccess(int newNetworkId) {
+
+        }
+
+        @Override
+        public void onConfiguratorSuccess(int code) {
+
+        }
+
+        @Override
+        public void onProgress(int code) {
+
+        }
+
+        @Override
+        public void onFailure(int code) {
+            synchronized (mLock) {
+                mOnFailureCallback = true;
+                mErrorCode = code;
+                mLock.notify();
+            }
+        }
+
+        public void onFailure(int code, String ssid, SparseArray<int[]> channelListArray,
+                int[] operatingClassArray) {
+            synchronized (mLock) {
+                mOnFailureCallback = true;
+                mErrorCode = code;
+                mLock.notify();
+            }
+        }
+    };
+
+    /**
+     * Tests {@link android.net.wifi.EasyConnectStatusCallback} class.
+     *
+     * Since Easy Connect requires 2 devices, start Easy Connect session and expect an error.
+     */
+    public void testConfiguratorInitiatorOnFailure() throws Exception {
+        if (!WifiFeature.isWifiSupported(getContext())) {
+            // skip the test if WiFi is not supported
+            return;
+        }
+        UiAutomation uiAutomation = InstrumentationRegistry.getInstrumentation().getUiAutomation();
+        try {
+            uiAutomation.adoptShellPermissionIdentity();
+            WifiConfiguration config;
+            config = new WifiConfiguration();
+            config.SSID = TEST_SSID;
+            config.preSharedKey = TEST_PASSPHRASE;
+            config.setSecurityParams(SECURITY_TYPE_PSK);
+            int networkId = mWifiManager.addNetwork(config);
+            assertFalse(networkId == -1);
+            synchronized (mLock) {
+                mWifiManager.startEasyConnectAsConfiguratorInitiator(TEST_DPP_URI, networkId,
+                        EASY_CONNECT_NETWORK_ROLE_STA, mExecutor, mEasyConnectStatusCallback);
+                // Note: A long delay is necessary because there is no enrollee, and the system
+                // tries to discover it. We will wait for a timeout error to occur.
+                mLock.wait(TEST_WAIT_DURATION_MS);
+            }
+            mWifiManager.removeNetwork(networkId);
+            assertTrue(mOnFailureCallback);
+            assertEquals(EASY_CONNECT_EVENT_FAILURE_TIMEOUT, mErrorCode);
+            mWifiManager.stopEasyConnectSession();
+        } finally {
+            uiAutomation.dropShellPermissionIdentity();
+        }
+    }
+
+    /**
+     * Tests {@link android.net.wifi.EasyConnectStatusCallback} class.
+     *
+     * Since Easy Connect requires 2 devices, start Easy Connect session and expect an error.
+     */
+    public void testEnrolleeInitiatorOnFailure() throws Exception {
+        if (!WifiFeature.isWifiSupported(getContext())) {
+            // skip the test if WiFi is not supported
+            return;
+        }
+        UiAutomation uiAutomation = InstrumentationRegistry.getInstrumentation().getUiAutomation();
+        try {
+            uiAutomation.adoptShellPermissionIdentity();
+            synchronized (mLock) {
+                mWifiManager.startEasyConnectAsEnrolleeInitiator(TEST_DPP_URI, mExecutor,
+                        mEasyConnectStatusCallback);
+                // Note: A long delay is necessary because there is no configurator, and the system
+                // tries to discover it. We will wait for a timeout error to occur.
+                mLock.wait(TEST_WAIT_DURATION_MS);
+            }
+            assertTrue(mOnFailureCallback);
+            assertEquals(EASY_CONNECT_EVENT_FAILURE_TIMEOUT, mErrorCode);
+            mWifiManager.stopEasyConnectSession();
+        } finally {
+            uiAutomation.dropShellPermissionIdentity();
+        }
+    }
+}
diff --git a/tests/cts/net/src/android/net/wifi/cts/WifiLockTest.java b/tests/cts/net/src/android/net/wifi/cts/WifiLockTest.java
index 6ac92d4..fee9ef0 100644
--- a/tests/cts/net/src/android/net/wifi/cts/WifiLockTest.java
+++ b/tests/cts/net/src/android/net/wifi/cts/WifiLockTest.java
@@ -19,6 +19,7 @@
 import android.content.Context;
 import android.net.wifi.WifiManager;
 import android.net.wifi.WifiManager.WifiLock;
+import android.os.WorkSource;
 import android.platform.test.annotations.AppModeFull;
 import android.test.AndroidTestCase;
 
@@ -50,6 +51,7 @@
         WifiLock wl = wm.createWifiLock(lockType, WIFI_TAG);
 
         wl.setReferenceCounted(true);
+        wl.setWorkSource(new WorkSource());
         assertFalse(wl.isHeld());
         wl.acquire();
         assertTrue(wl.isHeld());
diff --git a/tests/cts/net/src/android/net/wifi/cts/WifiManagerTest.java b/tests/cts/net/src/android/net/wifi/cts/WifiManagerTest.java
index 9d36493..f4c20e3 100644
--- a/tests/cts/net/src/android/net/wifi/cts/WifiManagerTest.java
+++ b/tests/cts/net/src/android/net/wifi/cts/WifiManagerTest.java
@@ -32,6 +32,7 @@
 import android.content.pm.PackageInfo;
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
+import android.net.util.MacAddressUtils;
 import android.net.ConnectivityManager;
 import android.net.LinkProperties;
 import android.net.MacAddress;
@@ -42,8 +43,12 @@
 import android.net.wifi.ScanResult;
 import android.net.wifi.SoftApConfiguration;
 import android.net.wifi.WifiConfiguration;
+import android.net.wifi.WifiInfo;
 import android.net.wifi.WifiManager;
 import android.net.wifi.WifiManager.WifiLock;
+import android.net.wifi.WifiNetworkConnectionStatistics;
+import android.net.wifi.hotspot2.ConfigParser;
+import android.net.wifi.hotspot2.PasspointConfiguration;
 import android.os.Process;
 import android.os.SystemClock;
 import android.os.UserHandle;
@@ -62,6 +67,10 @@
 import com.android.compatibility.common.util.ShellIdentityUtils;
 import com.android.compatibility.common.util.SystemUtil;
 
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.net.HttpURLConnection;
 import java.net.URL;
 import java.util.List;
@@ -124,6 +133,9 @@
     private static final String TEST_SSID_UNQUOTED = "testSsid1";
     private static final MacAddress TEST_MAC = MacAddress.fromString("aa:bb:cc:dd:ee:ff");
     private static final String TEST_PASSPHRASE = "passphrase";
+    private static final String PASSPOINT_INSTALLATION_FILE_WITH_CA_CERT =
+            "assets/ValidPasspointProfile.base64";
+    private static final String TYPE_WIFI_CONFIG = "application/x-wifi-config";
 
     private IntentFilter mIntentFilter;
     private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@@ -742,6 +754,51 @@
     }
 
     /**
+     * Read the content of the given resource file into a String.
+     *
+     * @param filename String name of the file
+     * @return String
+     * @throws IOException
+     */
+    private String loadResourceFile(String filename) throws IOException {
+        InputStream in = getClass().getClassLoader().getResourceAsStream(filename);
+        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
+        StringBuilder builder = new StringBuilder();
+        String line;
+        while ((line = reader.readLine()) != null) {
+            builder.append(line).append("\n");
+        }
+        return builder.toString();
+    }
+
+    /**
+     * Verify that changing the mac randomization setting of a Passpoint configuration.
+     */
+    public void testMacRandomizationSettingPasspoint() throws Exception {
+        String configStr = loadResourceFile(PASSPOINT_INSTALLATION_FILE_WITH_CA_CERT);
+        PasspointConfiguration config =
+                ConfigParser.parsePasspointConfig(TYPE_WIFI_CONFIG, configStr.getBytes());
+        UiAutomation uiAutomation = InstrumentationRegistry.getInstrumentation().getUiAutomation();
+        try {
+            uiAutomation.adoptShellPermissionIdentity();
+
+            mWifiManager.addOrUpdatePasspointConfiguration(config);
+            List<PasspointConfiguration> passpointConfigs =
+                    mWifiManager.getPasspointConfigurations();
+            PasspointConfiguration passpointConfig = passpointConfigs.get(0);
+            assertEquals(1, passpointConfigs.size());
+            assertTrue("Mac randomization should be enabled for passpoint networks by default.",
+                    passpointConfig.isMacRandomizationEnabled());
+
+            String fqdn = passpointConfig.getHomeSp().getFqdn();
+            mWifiManager.setMacRandomizationSettingPasspointEnabled(fqdn, false);
+            assertFalse("Mac randomization should be disabled by the API call.",
+                    mWifiManager.getPasspointConfigurations().get(0).isMacRandomizationEnabled());
+        } finally {
+            uiAutomation.dropShellPermissionIdentity();
+        }
+    }
+    /**
      * Verify that the {@link android.Manifest.permission#NETWORK_STACK} permission is never held by
      * any package.
      * <p>
@@ -1337,6 +1394,67 @@
         }
     }
 
+    /**
+     * Tests {@link WifiManager#getFactoryMacAddresses()} returns at least one valid MAC address.
+     */
+    public void testGetFactoryMacAddresses() throws Exception {
+        if (!WifiFeature.isWifiSupported(getContext())) {
+            // skip the test if WiFi is not supported
+            return;
+        }
+        TestActionListener actionListener = new TestActionListener(mLock);
+        UiAutomation uiAutomation = InstrumentationRegistry.getInstrumentation().getUiAutomation();
+        int newNetworkId = INVALID_NETWORK_ID;
+        try {
+            uiAutomation.adoptShellPermissionIdentity();
+            // Obtain the factory MAC address
+            String[] macAddresses = mWifiManager.getFactoryMacAddresses();
+            assertTrue("At list one MAC address should be returned.", macAddresses.length > 0);
+            try {
+                MacAddress mac = MacAddress.fromString(macAddresses[0]);
+                assertNotEquals(WifiInfo.DEFAULT_MAC_ADDRESS, mac);
+                assertFalse(MacAddressUtils.isMulticastAddress(mac));
+            } catch (IllegalArgumentException e) {
+                fail("Factory MAC address is invalid");
+            }
+        } finally {
+            uiAutomation.dropShellPermissionIdentity();
+        }
+    }
+
+    /**
+     * Tests {@link WifiManager#isApMacRandomizationSupported()} does not crash.
+     */
+    public void testIsApMacRandomizationSupported() throws Exception {
+        if (!WifiFeature.isWifiSupported(getContext())) {
+            // skip the test if WiFi is not supported
+            return;
+        }
+        mWifiManager.isApMacRandomizationSupported();
+    }
+
+    /**
+     * Tests {@link WifiManager#isConnectedMacRandomizationSupported()} does not crash.
+     */
+    public void testIsConnectedMacRandomizationSupported() throws Exception {
+        if (!WifiFeature.isWifiSupported(getContext())) {
+            // skip the test if WiFi is not supported
+            return;
+        }
+        mWifiManager.isConnectedMacRandomizationSupported();
+    }
+
+    /**
+     * Tests {@link WifiManager#isPreferredNetworkOffloadSupported()} does not crash.
+     */
+    public void testIsPreferredNetworkOffloadSupported() throws Exception {
+        if (!WifiFeature.isWifiSupported(getContext())) {
+            // skip the test if WiFi is not supported
+            return;
+        }
+        mWifiManager.isPreferredNetworkOffloadSupported();
+    }
+
     private static class TestTrafficStateCallback implements WifiManager.TrafficStateCallback {
         private final Object mLock;
         public boolean onStateChangedCalled = false;
@@ -1559,6 +1677,16 @@
     }
 
     /**
+     * Test {@link WifiNetworkConnectionStatistics} does not crash.
+     * TODO(b/150891569): deprecate it in Android S, this API is not used anywhere.
+     */
+    public void testWifiNetworkConnectionStatistics() {
+        new WifiNetworkConnectionStatistics();
+        WifiNetworkConnectionStatistics stats = new WifiNetworkConnectionStatistics(0, 0);
+        new WifiNetworkConnectionStatistics(stats);
+    }
+
+    /**
      * Test that the wifi country code is either null, or a length-2 string.
      */
     public void testGetCountryCode() throws Exception {