Fix CTS issue #7379336
Remove persistent networks to clean up a new connection. Also, disconnect
from Wi-Fi to avoid wifi from interfering with wifi direct.
Bug: 7379336
Change-Id: I05fce4b616c8fa306c82d6972b3bd015dd16fb4f
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/p2p/testcase/ConnectReqTestCase.java b/apps/CtsVerifier/src/com/android/cts/verifier/p2p/testcase/ConnectReqTestCase.java
index 02e7040..95c8d09 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/p2p/testcase/ConnectReqTestCase.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/p2p/testcase/ConnectReqTestCase.java
@@ -21,9 +21,12 @@
import android.net.wifi.p2p.WifiP2pConfig;
import android.net.wifi.p2p.WifiP2pDevice;
import android.net.wifi.p2p.WifiP2pInfo;
+import android.net.wifi.p2p.WifiP2pManager;
import com.android.cts.verifier.R;
+import java.lang.reflect.Method;
+
/**
* A base class for connection request test.
*/
@@ -42,6 +45,22 @@
super.setUp();
mReceiverTest = new P2pBroadcastReceiverTest(mContext);
mReceiverTest.init(mChannel);
+
+ try {
+ Method[] methods = WifiP2pManager.class.getMethods();
+ for (int i = 0; i < methods.length; i++) {
+ if (methods[i].getName().equals("deletePersistentGroup")) {
+ // Delete any persistent group
+ for (int netid = 0; netid < 32; netid++) {
+ methods[i].invoke(mP2pMgr, mChannel, netid, null);
+ }
+ }
+ }
+ } catch(Exception e) {
+ e.printStackTrace();
+ }
+ // Disconnect from wifi to avoid channel conflict
+ mWifiMgr.disconnect();
}
/**
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/p2p/testcase/TestCase.java b/apps/CtsVerifier/src/com/android/cts/verifier/p2p/testcase/TestCase.java
index f34bdb2..c3a6b8e 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/p2p/testcase/TestCase.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/p2p/testcase/TestCase.java
@@ -16,6 +16,7 @@
package com.android.cts.verifier.p2p.testcase;
import android.content.Context;
+import android.net.wifi.WifiManager;
import android.net.wifi.p2p.WifiP2pManager;
import android.net.wifi.p2p.WifiP2pManager.Channel;
@@ -49,6 +50,7 @@
protected String mReason;
protected WifiP2pManager mP2pMgr;
+ protected WifiManager mWifiMgr;
protected Channel mChannel;
// this is used for multi-client test
protected Channel mSubChannel;
@@ -141,6 +143,7 @@
*/
protected void setUp() {
mP2pMgr = (WifiP2pManager) mContext.getSystemService(Context.WIFI_P2P_SERVICE);
+ mWifiMgr = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
mChannel = mP2pMgr.initialize(mContext, mContext.getMainLooper(), null);
mSubChannel = mP2pMgr.initialize(mContext, mContext.getMainLooper(), null);
}