diff options
12 files changed, 228 insertions, 158 deletions
diff --git a/service/java/com/android/server/wifi/ClientModeImpl.java b/service/java/com/android/server/wifi/ClientModeImpl.java index e7371a9f1..f4e3ed5f3 100644 --- a/service/java/com/android/server/wifi/ClientModeImpl.java +++ b/service/java/com/android/server/wifi/ClientModeImpl.java @@ -910,8 +910,6 @@ public class ClientModeImpl extends StateMachine { getHandler()); mWifiMonitor.registerHandler(mInterfaceName, WifiMonitor.NETWORK_CONNECTION_EVENT, getHandler()); - mWifiMonitor.registerHandler(mInterfaceName, WifiMonitor.FILS_NETWORK_CONNECTION_EVENT, - getHandler()); mWifiMonitor.registerHandler(mInterfaceName, WifiMonitor.NETWORK_DISCONNECTION_EVENT, getHandler()); mWifiMonitor.registerHandler(mInterfaceName, WifiMonitor.RX_HS20_ANQP_ICON_EVENT, @@ -1998,7 +1996,6 @@ public class ClientModeImpl extends StateMachine { } sb.append(" blacklist=" + Boolean.toString(mDidBlackListBSSID)); break; - case WifiMonitor.FILS_NETWORK_CONNECTION_EVENT: case WifiMonitor.NETWORK_CONNECTION_EVENT: sb.append(" "); sb.append(Integer.toString(msg.arg1)); @@ -2264,9 +2261,6 @@ public class ClientModeImpl extends StateMachine { case WifiMonitor.NETWORK_CONNECTION_EVENT: s = "NETWORK_CONNECTION_EVENT"; break; - case WifiMonitor.FILS_NETWORK_CONNECTION_EVENT: - s = "FILS_NETWORK_CONNECTION_EVENT"; - break; case WifiMonitor.NETWORK_DISCONNECTION_EVENT: s = "NETWORK_DISCONNECTION_EVENT"; break; @@ -3456,7 +3450,6 @@ public class ClientModeImpl extends StateMachine { case CMD_RECONNECT: case CMD_REASSOCIATE: case WifiMonitor.NETWORK_CONNECTION_EVENT: - case WifiMonitor.FILS_NETWORK_CONNECTION_EVENT: case WifiMonitor.NETWORK_DISCONNECTION_EVENT: case WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT: case WifiMonitor.AUTHENTICATION_FAILURE_EVENT: @@ -4213,12 +4206,11 @@ public class ClientModeImpl extends StateMachine { } handleStatus = NOT_HANDLED; break; - case WifiMonitor.FILS_NETWORK_CONNECTION_EVENT: - mWifiMetrics.incrementL2ConnectionThroughFilsAuthCount(); - mSentHLPs = true; case WifiMonitor.NETWORK_CONNECTION_EVENT: if (mVerboseLoggingEnabled) log("Network connection established"); mLastNetworkId = message.arg1; + mSentHLPs = message.arg2 == 1; + if (mSentHLPs) mWifiMetrics.incrementL2ConnectionThroughFilsAuthCount(); mWifiConfigManager.clearRecentFailureReason(mLastNetworkId); mLastBssid = (String) message.obj; reasonCode = message.arg2; @@ -4908,7 +4900,6 @@ public class ClientModeImpl extends StateMachine { } break; case WifiMonitor.NETWORK_CONNECTION_EVENT: - case WifiMonitor.FILS_NETWORK_CONNECTION_EVENT: mWifiInfo.setBSSID((String) message.obj); mLastNetworkId = message.arg1; mWifiInfo.setNetworkId(mLastNetworkId); diff --git a/service/java/com/android/server/wifi/SupplicantStaIfaceCallbackImpl.java b/service/java/com/android/server/wifi/SupplicantStaIfaceCallbackImpl.java index 9d69003cf..0e2189ba0 100644 --- a/service/java/com/android/server/wifi/SupplicantStaIfaceCallbackImpl.java +++ b/service/java/com/android/server/wifi/SupplicantStaIfaceCallbackImpl.java @@ -157,9 +157,11 @@ abstract class SupplicantStaIfaceCallbackImpl extends ISupplicantStaIfaceCallbac } } - @Override - public void onStateChanged(int newState, byte[/* 6 */] bssid, int id, - ArrayList<Byte> ssid) { + /** + * Added to plumb the new {@code filsHlpSent} param from the V1.3 callback version. + */ + public void onStateChanged(int newState, byte[/* 6 */] bssid, int id, ArrayList<Byte> ssid, + boolean filsHlpSent) { synchronized (mLock) { mStaIfaceHal.logCallback("onStateChanged"); SupplicantState newSupplicantState = @@ -174,7 +176,8 @@ abstract class SupplicantStaIfaceCallbackImpl extends ISupplicantStaIfaceCallbac } if (newState == State.COMPLETED) { mWifiMonitor.broadcastNetworkConnectionEvent( - mIfaceName, mStaIfaceHal.getCurrentNetworkId(mIfaceName), bssidStr); + mIfaceName, mStaIfaceHal.getCurrentNetworkId(mIfaceName), filsHlpSent, + bssidStr); } mWifiMonitor.broadcastSupplicantStateChangeEvent( mIfaceName, mStaIfaceHal.getCurrentNetworkId(mIfaceName), wifiSsid, @@ -183,6 +186,11 @@ abstract class SupplicantStaIfaceCallbackImpl extends ISupplicantStaIfaceCallbac } @Override + public void onStateChanged(int newState, byte[/* 6 */] bssid, int id, ArrayList<Byte> ssid) { + onStateChanged(newState, bssid, id, ssid, false); + } + + @Override public void onAnqpQueryDone(byte[/* 6 */] bssid, ISupplicantStaIfaceCallback.AnqpData data, ISupplicantStaIfaceCallback.Hs20AnqpData hs20Data) { diff --git a/service/java/com/android/server/wifi/SupplicantStaIfaceCallbackV1_1Impl.java b/service/java/com/android/server/wifi/SupplicantStaIfaceCallbackV1_1Impl.java index 12e025e69..c4a3dda16 100644 --- a/service/java/com/android/server/wifi/SupplicantStaIfaceCallbackV1_1Impl.java +++ b/service/java/com/android/server/wifi/SupplicantStaIfaceCallbackV1_1Impl.java @@ -53,10 +53,18 @@ abstract class SupplicantStaIfaceCallbackV1_1Impl extends mCallbackV10.onNetworkRemoved(id); } + /** + * Added to plumb the new {@code filsHlpSent} param from the V1.3 callback version. + */ + public void onStateChanged(int newState, byte[/* 6 */] bssid, int id, ArrayList<Byte> ssid, + boolean filsHlpSent) { + mCallbackV10.onStateChanged(newState, bssid, id, ssid, filsHlpSent); + } + @Override public void onStateChanged(int newState, byte[/* 6 */] bssid, int id, ArrayList<Byte> ssid) { - mCallbackV10.onStateChanged(newState, bssid, id, ssid); + onStateChanged(newState, bssid, id, ssid, false); } @Override diff --git a/service/java/com/android/server/wifi/SupplicantStaIfaceCallbackV1_2Impl.java b/service/java/com/android/server/wifi/SupplicantStaIfaceCallbackV1_2Impl.java index 89e66d22c..973e11a4a 100644 --- a/service/java/com/android/server/wifi/SupplicantStaIfaceCallbackV1_2Impl.java +++ b/service/java/com/android/server/wifi/SupplicantStaIfaceCallbackV1_2Impl.java @@ -59,10 +59,18 @@ abstract class SupplicantStaIfaceCallbackV1_2Impl extends mCallbackV11.onNetworkRemoved(id); } + /** + * Added to plumb the new {@code filsHlpSent} param from the V1.3 callback version. + */ + public void onStateChanged(int newState, byte[/* 6 */] bssid, int id, ArrayList<Byte> ssid, + boolean filsHlpSent) { + mCallbackV11.onStateChanged(newState, bssid, id, ssid, filsHlpSent); + } + @Override public void onStateChanged(int newState, byte[/* 6 */] bssid, int id, ArrayList<Byte> ssid) { - mCallbackV11.onStateChanged(newState, bssid, id, ssid); + onStateChanged(newState, bssid, id, ssid, false); } @Override diff --git a/service/java/com/android/server/wifi/SupplicantStaIfaceCallbackV1_3Impl.java b/service/java/com/android/server/wifi/SupplicantStaIfaceCallbackV1_3Impl.java index f293b9d7c..154fde40b 100644 --- a/service/java/com/android/server/wifi/SupplicantStaIfaceCallbackV1_3Impl.java +++ b/service/java/com/android/server/wifi/SupplicantStaIfaceCallbackV1_3Impl.java @@ -15,19 +15,13 @@ */ package com.android.server.wifi; -import static com.android.server.wifi.SupplicantStaIfaceCallbackImpl.supplicantHidlStateToFrameworkState; import android.annotation.NonNull; import android.hardware.wifi.supplicant.V1_0.ISupplicantStaIfaceCallback; -import android.hardware.wifi.supplicant.V1_3.ISupplicantStaIfaceCallback.BssTmData; -import android.net.wifi.SupplicantState; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiManager; -import android.net.wifi.WifiSsid; import android.util.Log; -import com.android.server.wifi.util.NativeUtil; - import java.util.ArrayList; abstract class SupplicantStaIfaceCallbackV1_3Impl extends @@ -37,7 +31,6 @@ abstract class SupplicantStaIfaceCallbackV1_3Impl extends private final String mIfaceName; private final WifiMonitor mWifiMonitor; private final SupplicantStaIfaceHal.SupplicantStaIfaceHalCallbackV1_2 mCallbackV12; - private boolean mStateIsFourwayV13 = false; // Used to help check for PSK password mismatch SupplicantStaIfaceCallbackV1_3Impl(@NonNull SupplicantStaIfaceHal staIfaceHal, @NonNull String ifaceName, @@ -57,9 +50,7 @@ abstract class SupplicantStaIfaceCallbackV1_3Impl extends @Override public void onNetworkRemoved(int id) { - mStaIfaceHal.logCallback("onNetworkRemoved"); - // Reset 4way handshake state since network has been removed. - mStateIsFourwayV13 = false; + mCallbackV12.onNetworkRemoved(id); } @Override @@ -96,20 +87,7 @@ abstract class SupplicantStaIfaceCallbackV1_3Impl extends @Override public void onDisconnected(byte[/* 6 */] bssid, boolean locallyGenerated, int reasonCode) { - mStaIfaceHal.logCallback("onDisconnected"); - if (mStaIfaceHal.isVerboseLoggingEnabled()) { - Log.e(TAG, "onDisconnected 4way=" + mStateIsFourwayV13 - + " locallyGenerated=" + locallyGenerated - + " reasonCode=" + reasonCode); - } - if (mStateIsFourwayV13 - && (!locallyGenerated || reasonCode != ReasonCode.IE_IN_4WAY_DIFFERS)) { - mWifiMonitor.broadcastAuthenticationFailureEvent( - mIfaceName, WifiManager.ERROR_AUTH_FAILURE_WRONG_PSWD, -1); - } - mWifiMonitor.broadcastNetworkDisconnectionEvent( - mIfaceName, locallyGenerated ? 1 : 0, reasonCode, - NativeUtil.macAddressFromByteArray(bssid)); + mCallbackV12.onDisconnected(bssid, locallyGenerated, reasonCode); } @Override @@ -365,25 +343,6 @@ abstract class SupplicantStaIfaceCallbackV1_3Impl extends @Override public void onStateChanged_1_3(int newState, byte[/* 6 */] bssid, int id, ArrayList<Byte> ssid, boolean filsHlpSent) { - mStaIfaceHal.logCallback("onStateChanged_1_3"); - SupplicantState newSupplicantState = - supplicantHidlStateToFrameworkState(newState); - WifiSsid wifiSsid = - WifiSsid.createFromByteArray(NativeUtil.byteArrayFromArrayList(ssid)); - String bssidStr = NativeUtil.macAddressFromByteArray(bssid); - mStateIsFourwayV13 = - (newState == ISupplicantStaIfaceCallback.State.FOURWAY_HANDSHAKE); - if (newSupplicantState == SupplicantState.COMPLETED) { - if (filsHlpSent) { - mWifiMonitor.broadcastFilsNetworkConnectionEvent( - mIfaceName, mStaIfaceHal.getCurrentNetworkId(mIfaceName), bssidStr); - } else { - mWifiMonitor.broadcastNetworkConnectionEvent( - mIfaceName, mStaIfaceHal.getCurrentNetworkId(mIfaceName), bssidStr); - } - } - mWifiMonitor.broadcastSupplicantStateChangeEvent( - mIfaceName, mStaIfaceHal.getCurrentNetworkId(mIfaceName), - wifiSsid, bssidStr, newSupplicantState); + mCallbackV12.onStateChanged(newState, bssid, id, ssid, filsHlpSent); } } diff --git a/service/java/com/android/server/wifi/WifiMonitor.java b/service/java/com/android/server/wifi/WifiMonitor.java index 7f620851d..32a96d0eb 100644 --- a/service/java/com/android/server/wifi/WifiMonitor.java +++ b/service/java/com/android/server/wifi/WifiMonitor.java @@ -100,9 +100,6 @@ public class WifiMonitor { /* MBO/OCE events */ public static final int MBO_OCE_BSS_TM_HANDLING_DONE = BASE + 71; - /* Fils network connection completed */ - public static final int FILS_NETWORK_CONNECTION_EVENT = BASE + 62; - /* WPS config errrors */ private static final int CONFIG_MULTIPLE_PBC_DETECTED = 12; private static final int CONFIG_AUTH_FAILURE = 18; @@ -500,21 +497,12 @@ public class WifiMonitor { * * @param iface Name of iface on which this occurred. * @param networkId ID of the network in wpa_supplicant. + * @param filsHlpSent Whether the connection used FILS. * @param bssid BSSID of the access point. */ - public void broadcastNetworkConnectionEvent(String iface, int networkId, String bssid) { - sendMessage(iface, NETWORK_CONNECTION_EVENT, networkId, 0, bssid); - } - - /** - * Broadcast the fils network connection event to all the handlers registered for this event. - * - * @param iface Name of iface on which this occurred. - * @param networkId ID of the network in wpa_supplicant. - * @param bssid BSSID of the access point. - */ - public void broadcastFilsNetworkConnectionEvent(String iface, int networkId, String bssid) { - sendMessage(iface, FILS_NETWORK_CONNECTION_EVENT, networkId, 0, bssid); + public void broadcastNetworkConnectionEvent(String iface, int networkId, boolean filsHlpSent, + String bssid) { + sendMessage(iface, NETWORK_CONNECTION_EVENT, networkId, filsHlpSent ? 1 : 0, bssid); } /** diff --git a/service/java/com/android/server/wifi/p2p/SupplicantP2pIfaceHal.java b/service/java/com/android/server/wifi/p2p/SupplicantP2pIfaceHal.java index 3d15ec647..dca3a6082 100644 --- a/service/java/com/android/server/wifi/p2p/SupplicantP2pIfaceHal.java +++ b/service/java/com/android/server/wifi/p2p/SupplicantP2pIfaceHal.java @@ -63,7 +63,6 @@ public class SupplicantP2pIfaceHal { private static final String TAG = "SupplicantP2pIfaceHal"; private static boolean sVerboseLoggingEnabled = true; private static final int RESULT_NOT_VALID = -1; - private static final int DEFAULT_GROUP_OWNER_INTENT = 6; private static final int DEFAULT_OPERATING_CLASS = 81; /** * Regex pattern for extracting the wps device type bytes. @@ -828,13 +827,9 @@ public class SupplicantP2pIfaceHal { String preSelectedPin = TextUtils.isEmpty(config.wps.pin) ? "" : config.wps.pin; boolean persistent = (config.netId == WifiP2pGroup.NETWORK_ID_PERSISTENT); - int goIntent = 0; - if (!joinExistingGroup) { - int groupOwnerIntent = config.groupOwnerIntent; - if (groupOwnerIntent < 0 || groupOwnerIntent > 15) { - groupOwnerIntent = DEFAULT_GROUP_OWNER_INTENT; - } - goIntent = groupOwnerIntent; + if (config.groupOwnerIntent < 0 || config.groupOwnerIntent > 15) { + Log.e(TAG, "Invalid group owner intent: " + config.groupOwnerIntent); + return null; } SupplicantResult<String> result = new SupplicantResult( @@ -842,7 +837,7 @@ public class SupplicantP2pIfaceHal { try { mISupplicantP2pIface.connect( peerAddress, provisionMethod, preSelectedPin, joinExistingGroup, - persistent, goIntent, + persistent, config.groupOwnerIntent, (SupplicantStatus status, String generatedPin) -> { result.setResult(status, generatedPin); }); diff --git a/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java b/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java index 219da3884..eb2a89c4e 100644 --- a/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java +++ b/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java @@ -44,6 +44,9 @@ import android.net.ip.IIpClient; import android.net.ip.IpClientCallbacks; import android.net.ip.IpClientUtil; import android.net.shared.ProvisioningConfiguration; +import android.net.wifi.ScanResult; +import android.net.wifi.WifiConfiguration; +import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.net.wifi.WpsInfo; import android.net.wifi.p2p.IWifiP2pManager; @@ -130,6 +133,8 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub { private static final String TAG = "WifiP2pService"; private boolean mVerboseLoggingEnabled = false; private static final String NETWORKTYPE = "WIFI_P2P"; + @VisibleForTesting + static final int DEFAULT_GROUP_OWNER_INTENT = 6; private Context mContext; @@ -2240,6 +2245,8 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub { break; case PEER_CONNECTION_USER_CONFIRM: mSavedPeerConfig.wps.setup = WpsInfo.DISPLAY; + mSavedPeerConfig.groupOwnerIntent = + selectGroupOwnerIntentIfNecessary(mSavedPeerConfig); mWifiNative.p2pConnect(mSavedPeerConfig, FORM_GROUP); transitionTo(mGroupNegotiationState); break; @@ -3537,6 +3544,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub { Log.e(TAG, "Invalid device"); return; } + config.groupOwnerIntent = selectGroupOwnerIntentIfNecessary(config); String pin = mWifiNative.p2pConnect(config, dev.isGroupOwner()); try { Integer.parseInt(pin); @@ -4313,6 +4321,38 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub { clearServiceRequests(c.mMessenger); } } + + private int selectGroupOwnerIntentIfNecessary(WifiP2pConfig config) { + int intent = config.groupOwnerIntent; + // return the legacy default value for invalid values. + if (intent != WifiP2pConfig.GROUP_OWNER_INTENT_AUTO) { + if (intent < WifiP2pConfig.GROUP_OWNER_INTENT_MIN + || intent > WifiP2pConfig.GROUP_OWNER_INTENT_MAX) { + intent = DEFAULT_GROUP_OWNER_INTENT; + } + return intent; + } + + WifiManager wifiManager = mContext.getSystemService(WifiManager.class); + + WifiInfo wifiInfo = wifiManager.getConnectionInfo(); + Log.d(TAG, "WifiInfo: " + wifiInfo); + int freq = wifiInfo.getFrequency(); + if (wifiInfo.getNetworkId() == WifiConfiguration.INVALID_NETWORK_ID) { + intent = DEFAULT_GROUP_OWNER_INTENT + 1; + } else if (ScanResult.is24GHz(freq)) { + intent = WifiP2pConfig.GROUP_OWNER_INTENT_MIN; + } else if (ScanResult.is5GHz(freq)) { + // If both sides use the maximum, the negotiation would fail. + intent = WifiP2pConfig.GROUP_OWNER_INTENT_MAX - 1; + } else { + intent = DEFAULT_GROUP_OWNER_INTENT; + } + Log.i(TAG, "change GO intent value from " + + config.groupOwnerIntent + " to " + intent); + return intent; + } + } /** diff --git a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java index fd1ef1718..d4af7ecac 100644 --- a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java @@ -4986,7 +4986,7 @@ public class ClientModeImplTest extends WifiBaseTest { verify(mWifiMetrics, times(1)).incrementConnectRequestWithFilsAkmCount(); - mCmi.sendMessage(WifiMonitor.FILS_NETWORK_CONNECTION_EVENT, 0, 0, sBSSID); + mCmi.sendMessage(WifiMonitor.NETWORK_CONNECTION_EVENT, 0, 1, sBSSID); mLooper.dispatchAll(); verify(mWifiMetrics, times(1)).incrementL2ConnectionThroughFilsAuthCount(); diff --git a/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java b/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java index 762691184..7e0c20faf 100644 --- a/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java +++ b/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java @@ -1010,7 +1010,7 @@ public class SupplicantStaIfaceHalTest extends WifiBaseTest { NativeUtil.decodeSsid(SUPPLICANT_SSID)); wifiMonitorInOrder.verify(mWifiMonitor).broadcastNetworkConnectionEvent( - eq(WLAN0_IFACE_NAME), eq(frameworkNetworkId), eq(BSSID)); + eq(WLAN0_IFACE_NAME), eq(frameworkNetworkId), eq(false), eq(BSSID)); wifiMonitorInOrder.verify(mWifiMonitor).broadcastSupplicantStateChangeEvent( eq(WLAN0_IFACE_NAME), eq(frameworkNetworkId), any(WifiSsid.class), eq(BSSID), eq(SupplicantState.COMPLETED)); @@ -2824,7 +2824,7 @@ public class SupplicantStaIfaceHalTest extends WifiBaseTest { NativeUtil.decodeSsid(SUPPLICANT_SSID), false); wifiMonitorInOrder.verify(mWifiMonitor).broadcastNetworkConnectionEvent( - eq(WLAN0_IFACE_NAME), eq(frameworkNetworkId), eq(BSSID)); + eq(WLAN0_IFACE_NAME), eq(frameworkNetworkId), eq(false), eq(BSSID)); wifiMonitorInOrder.verify(mWifiMonitor).broadcastSupplicantStateChangeEvent( eq(WLAN0_IFACE_NAME), eq(frameworkNetworkId), any(WifiSsid.class), eq(BSSID), eq(SupplicantState.COMPLETED)); @@ -2904,8 +2904,8 @@ public class SupplicantStaIfaceHalTest extends WifiBaseTest { NativeUtil.macAddressToByteArray(BSSID), SUPPLICANT_NETWORK_ID, NativeUtil.decodeSsid(SUPPLICANT_SSID), true); - wifiMonitorInOrder.verify(mWifiMonitor).broadcastFilsNetworkConnectionEvent( - eq(WLAN0_IFACE_NAME), eq(frameworkNetworkId), eq(BSSID)); + wifiMonitorInOrder.verify(mWifiMonitor).broadcastNetworkConnectionEvent( + eq(WLAN0_IFACE_NAME), eq(frameworkNetworkId), eq(true), eq(BSSID)); wifiMonitorInOrder.verify(mWifiMonitor).broadcastSupplicantStateChangeEvent( eq(WLAN0_IFACE_NAME), eq(frameworkNetworkId), any(WifiSsid.class), eq(BSSID), eq(SupplicantState.COMPLETED)); diff --git a/tests/wifitests/src/com/android/server/wifi/WifiMonitorTest.java b/tests/wifitests/src/com/android/server/wifi/WifiMonitorTest.java index 24bb968a5..c4acd73c2 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiMonitorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiMonitorTest.java @@ -423,13 +423,14 @@ public class WifiMonitorTest extends WifiBaseTest { WLAN_IFACE_NAME, WifiMonitor.NETWORK_CONNECTION_EVENT, mHandlerSpy); int networkId = NETWORK_ID; String bssid = BSSID; - mWifiMonitor.broadcastNetworkConnectionEvent(WLAN_IFACE_NAME, networkId, bssid); + mWifiMonitor.broadcastNetworkConnectionEvent(WLAN_IFACE_NAME, networkId, false, bssid); mLooper.dispatchAll(); ArgumentCaptor<Message> messageCaptor = ArgumentCaptor.forClass(Message.class); verify(mHandlerSpy).handleMessage(messageCaptor.capture()); assertEquals(WifiMonitor.NETWORK_CONNECTION_EVENT, messageCaptor.getValue().what); assertEquals(networkId, messageCaptor.getValue().arg1); + assertEquals(0, messageCaptor.getValue().arg2); assertEquals(bssid, (String) messageCaptor.getValue().obj); } @@ -607,17 +608,17 @@ public class WifiMonitorTest extends WifiBaseTest { @Test public void testBroadcastFilsNetworkConnectionEvent() { mWifiMonitor.registerHandler( - WLAN_IFACE_NAME, WifiMonitor.FILS_NETWORK_CONNECTION_EVENT, mHandlerSpy); + WLAN_IFACE_NAME, WifiMonitor.NETWORK_CONNECTION_EVENT, mHandlerSpy); int networkId = NETWORK_ID; String bssid = BSSID; - mWifiMonitor.broadcastFilsNetworkConnectionEvent(WLAN_IFACE_NAME, networkId, bssid); + mWifiMonitor.broadcastNetworkConnectionEvent(WLAN_IFACE_NAME, networkId, true, bssid); mLooper.dispatchAll(); ArgumentCaptor<Message> messageCaptor = ArgumentCaptor.forClass(Message.class); verify(mHandlerSpy).handleMessage(messageCaptor.capture()); - assertEquals(WifiMonitor.FILS_NETWORK_CONNECTION_EVENT, messageCaptor.getValue().what); + assertEquals(WifiMonitor.NETWORK_CONNECTION_EVENT, messageCaptor.getValue().what); assertEquals(networkId, messageCaptor.getValue().arg1); + assertEquals(1, messageCaptor.getValue().arg2); assertEquals(bssid, (String) messageCaptor.getValue().obj); } - } diff --git a/tests/wifitests/src/com/android/server/wifi/p2p/WifiP2pServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/p2p/WifiP2pServiceImplTest.java index cae812d58..171dc9b24 100644 --- a/tests/wifitests/src/com/android/server/wifi/p2p/WifiP2pServiceImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/p2p/WifiP2pServiceImplTest.java @@ -56,6 +56,8 @@ import android.location.LocationManager; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.net.TetheringManager; +import android.net.wifi.WifiConfiguration; +import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.net.wifi.WpsInfo; import android.net.wifi.p2p.WifiP2pConfig; @@ -65,6 +67,7 @@ import android.net.wifi.p2p.WifiP2pGroup; import android.net.wifi.p2p.WifiP2pGroupList; import android.net.wifi.p2p.WifiP2pInfo; import android.net.wifi.p2p.WifiP2pManager; +import android.net.wifi.p2p.WifiP2pProvDiscEvent; import android.net.wifi.p2p.WifiP2pWfdInfo; import android.net.wifi.p2p.nsd.WifiP2pServiceInfo; import android.net.wifi.p2p.nsd.WifiP2pServiceRequest; @@ -167,6 +170,8 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Mock WifiP2pServiceRequest mTestWifiP2pServiceRequest; @Mock UserManager mUserManager; @Mock WifiP2pMetrics mWifiP2pMetrics; + @Mock WifiManager mWifiManager; + @Mock WifiInfo mWifiInfo; @Spy FakeWifiLog mLog; @Spy MockWifiP2pMonitor mWifiMonitor; @@ -626,6 +631,25 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { } /** + * Send simple API msg. + * + * Mock the API msg with objects. + * + * @param replyMessenger for checking replied message. + */ + private void sendSimpleMsg(Messenger replyMessenger, + int what, Object obj) throws Exception { + Message msg = Message.obtain(); + msg.what = what; + msg.obj = obj; + if (replyMessenger != null) { + msg.replyTo = replyMessenger; + } + mP2pStateMachineMessenger.send(Message.obtain(msg)); + mLooper.dispatchAll(); + } + + /** * force P2p State enter InactiveState to start others unit test * * @param clientBinder client binder to use for p2p channel init @@ -747,6 +771,8 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { when(mContext.getPackageManager()).thenReturn(mPackageManager); when(mContext.getResources()).thenReturn(mResources); + when(mContext.getSystemService(WifiManager.class)).thenReturn(mWifiManager); + when(mWifiManager.getConnectionInfo()).thenReturn(mWifiInfo); when(mWifiSettingsConfigStore.get(eq(WIFI_P2P_DEVICE_NAME))).thenReturn(thisDeviceName); when(mWifiSettingsConfigStore.get(eq(WIFI_P2P_PENDING_FACTORY_RESET))).thenReturn(false); when(mHandlerThread.getLooper()).thenReturn(mLooper.getLooper()); @@ -772,6 +798,8 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { when(mWifiPermissionsUtil.checkNetworkStackPermission(anyInt())).thenReturn(true); when(mWifiPermissionsUtil.checkReadWifiCredentialPermission(anyInt())).thenReturn(true); when(mWifiPermissionsUtil.checkConfigOverridePermission(anyInt())).thenReturn(true); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), + anyBoolean())).thenReturn(true); when(mWifiNative.setupInterface(any(), any())).thenReturn(IFACE_NAME_P2P); when(mWifiNative.p2pGetDeviceAddress()).thenReturn(thisDeviceMac); doAnswer(new AnswerWithArguments() { @@ -982,8 +1010,6 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { forceP2pEnabled(mClient1); sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); doNothing().when(mWifiPermissionsUtil).checkPackage(anyInt(), anyString()); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), - anyBoolean())).thenReturn(true); when(mWifiNative.p2pServiceAdd(any())).thenReturn(true); sendAddLocalServiceMsg(mClientMessenger); verify(mWifiNative).p2pServiceAdd(any()); @@ -1000,8 +1026,6 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { forceP2pEnabled(mClient1); sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); doNothing().when(mWifiPermissionsUtil).checkPackage(anyInt(), anyString()); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), - anyBoolean())).thenReturn(true); when(mWifiNative.p2pServiceAdd(any())).thenReturn(false); sendAddLocalServiceMsg(mClientMessenger); verify(mWifiNative).p2pServiceAdd(any()); @@ -1062,8 +1086,6 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Test public void testConnectWithConfigValidAsGroupSuccess() throws Exception { forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), - anyBoolean())).thenReturn(true); sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); when(mWifiNative.p2pGroupAdd(any(), eq(true))).thenReturn(true); sendConnectMsgWithConfigValidAsGroup(mClientMessenger); @@ -1079,8 +1101,6 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Test public void testConnectWithConfigValidAsGroupFailureWhenNativeCallFailure() throws Exception { forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), - anyBoolean())).thenReturn(true); sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); when(mWifiNative.p2pGroupAdd(any(), eq(true))).thenReturn(false); sendConnectMsgWithConfigValidAsGroup(mClientMessenger); @@ -1147,8 +1167,6 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Test public void testCreateGroupWithConfigValidAsGroupSuccess() throws Exception { forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), - anyBoolean())).thenReturn(true); sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); when(mWifiNative.p2pGroupAdd(any(), eq(false))).thenReturn(true); sendCreateGroupMsgWithConfigValidAsGroup(mClientMessenger); @@ -1165,8 +1183,6 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { public void testCreateGroupWithConfigValidAsGroupFailureWhenNativeCallFailure() throws Exception { forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), - anyBoolean())).thenReturn(true); sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); when(mWifiNative.p2pGroupAdd(any(), eq(false))).thenReturn(false); sendCreateGroupMsgWithConfigValidAsGroup(mClientMessenger); @@ -1247,8 +1263,6 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Test public void testDiscoverPeersSuccess() throws Exception { forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), - anyBoolean())).thenReturn(true); when(mWifiNative.p2pFind(anyInt())).thenReturn(true); sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendDiscoverPeersMsg(mClientMessenger); @@ -1264,8 +1278,6 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Test public void testDiscoverPeersFailureWhenNativeCallFailure() throws Exception { forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), - anyBoolean())).thenReturn(true); when(mWifiNative.p2pFind(anyInt())).thenReturn(false); sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendDiscoverPeersMsg(mClientMessenger); @@ -1364,8 +1376,6 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { .thenReturn("mServiceDiscReqId"); when(mWifiNative.p2pFind(anyInt())).thenReturn(true); forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), - anyBoolean())).thenReturn(true); sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendAddServiceRequestMsg(mClientMessenger); sendDiscoverServiceMsg(mClientMessenger); @@ -1383,8 +1393,6 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { public void testDiscoverServicesFailureWhenAddServiceRequestFailure() throws Exception { when(mWifiNative.p2pServDiscReq(anyString(), anyString())).thenReturn(null); forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), - anyBoolean())).thenReturn(true); sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendAddServiceRequestMsg(mClientMessenger); sendDiscoverServiceMsg(mClientMessenger); @@ -1404,8 +1412,6 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { .thenReturn("mServiceDiscReqId"); when(mWifiNative.p2pFind(anyInt())).thenReturn(false); forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), - anyBoolean())).thenReturn(true); sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendAddServiceRequestMsg(mClientMessenger); sendDiscoverServiceMsg(mClientMessenger); @@ -1504,8 +1510,6 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { public void testRequestPeersSuccess() throws Exception { forceP2pEnabled(mClient1); mockPeersList(); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), - anyBoolean())).thenReturn(true); sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendRequestPeersMsg(mClientMessenger); verify(mClientHandler).sendMessage(mMessageCaptor.capture()); @@ -1581,8 +1585,6 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { sendGroupStartedMsg(mTestWifiP2pGroup); simulateTetherReady(); when(mWifiPermissionsUtil.checkLocalMacAddressPermission(anyInt())).thenReturn(false); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), - anyBoolean())).thenReturn(true); sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendRequestGroupInfoMsg(mClientMessenger); verify(mClientHandler).sendMessage(mMessageCaptor.capture()); @@ -1606,8 +1608,6 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { sendGroupStartedMsg(mTestWifiP2pGroup); simulateTetherReady(); when(mWifiPermissionsUtil.checkLocalMacAddressPermission(anyInt())).thenReturn(true); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), - anyBoolean())).thenReturn(true); sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendRequestGroupInfoMsg(mClientMessenger); verify(mClientHandler).sendMessage(mMessageCaptor.capture()); @@ -1791,8 +1791,6 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Test public void testPeerScanMetricWhenSendDiscoverPeers() throws Exception { forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), - anyBoolean())).thenReturn(true); when(mWifiNative.p2pFind(anyInt())).thenReturn(true); sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendDiscoverPeersMsg(mClientMessenger); @@ -1811,8 +1809,6 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { .thenReturn("mServiceDiscReqId"); when(mWifiNative.p2pFind(anyInt())).thenReturn(true); forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), - anyBoolean())).thenReturn(true); sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendAddServiceRequestMsg(mClientMessenger); sendDiscoverServiceMsg(mClientMessenger); @@ -1920,8 +1916,6 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Test public void testStartFreshConnectionEventWhenSendConnect() throws Exception { forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), - anyBoolean())).thenReturn(true); sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); mockPeersList(); @@ -1943,8 +1937,6 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Test public void testStartReinvokeConnectionEventWhenSendConnect() throws Exception { forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), - anyBoolean())).thenReturn(true); when(mWifiNative.p2pGroupAdd(anyInt())) .thenReturn(true); when(mTestWifiP2pDevice.isGroupOwner()).thenReturn(true); @@ -1976,8 +1968,6 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { public void testStartReinvokeConnectionEventWhenCreateGroup() throws Exception { forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), - anyBoolean())).thenReturn(true); sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendCreateGroupMsg(mClientMessenger, WifiP2pGroup.NETWORK_ID_PERSISTENT, null); @@ -1996,8 +1986,6 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Test public void testStartLocalConnectionWhenCreateGroup() throws Exception { forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), - anyBoolean())).thenReturn(true); sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); // permissions for factory reset @@ -2028,8 +2016,6 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Test public void testStartLocalConnectionEventWhenCreateTemporaryGroup() throws Exception { forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), - anyBoolean())).thenReturn(true); sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendCreateGroupMsg(mClientMessenger, WifiP2pGroup.NETWORK_ID_TEMPORARY, null); @@ -2049,8 +2035,6 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { public void testStartFastConnectionEventWhenSendConnectWithConfig() throws Exception { forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), - anyBoolean())).thenReturn(true); when(mWifiNative.p2pGroupAdd(any(), eq(true))).thenReturn(true); sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); @@ -2075,8 +2059,6 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { public void testStartFastConnectionEventWhenCreateGroupWithConfig() throws Exception { forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), - anyBoolean())).thenReturn(true); sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendCreateGroupMsg(mClientMessenger, 0, mTestWifiP2pFastConnectionConfig); @@ -2118,8 +2100,6 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Test public void testEndConnectionEventWhenTimeout() throws Exception { forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), - anyBoolean())).thenReturn(true); when(mWifiNative.p2pGroupAdd(anyBoolean())).thenReturn(true); sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); @@ -2140,8 +2120,6 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Test public void testEndConnectionEventWhenCancel() throws Exception { forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), - anyBoolean())).thenReturn(true); when(mWifiNative.p2pGroupAdd(anyBoolean())).thenReturn(true); sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); @@ -2161,8 +2139,6 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Test public void testEndConnectionEventWhenProvDiscFailure() throws Exception { forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), - anyBoolean())).thenReturn(true); when(mWifiNative.p2pGroupAdd(anyBoolean())).thenReturn(true); sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); @@ -2182,8 +2158,6 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Test public void testEndConnectionEventWhenGroupRemoval() throws Exception { forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), - anyBoolean())).thenReturn(true); when(mWifiNative.p2pGroupAdd(anyBoolean())).thenReturn(true); sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); @@ -2203,8 +2177,6 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Test public void testEndConnectionEventWhenInvitationFailure() throws Exception { forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), - anyBoolean())).thenReturn(true); when(mWifiNative.p2pGroupAdd(anyBoolean())).thenReturn(true); sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); @@ -2244,8 +2216,6 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Test public void testRequestDeviceInfoSuccessWhenP2pEnabled() throws Exception { forceP2pEnabled(mClient1); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), - anyBoolean())).thenReturn(true); sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendSimpleMsg(mClientMessenger, WifiP2pManager.REQUEST_DEVICE_INFO); verify(mWifiPermissionsUtil).checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), @@ -2263,8 +2233,6 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { */ @Test public void testRequestDeviceInfoReturnEmptyWifiP2pDeviceWhenP2pDisabled() throws Exception { - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), - anyBoolean())).thenReturn(true); sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendSimpleMsg(mClientMessenger, WifiP2pManager.REQUEST_DEVICE_INFO); verify(mWifiPermissionsUtil).checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), @@ -2284,8 +2252,6 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { public void testRequestDeviceInfoReturnsActualMacForNetworkSettingsApp() throws Exception { forceP2pEnabled(mClient1); when(mWifiPermissionsUtil.checkLocalMacAddressPermission(anyInt())).thenReturn(true); - when(mWifiPermissionsUtil.checkCanAccessWifiDirect(anyString(), anyString(), anyInt(), - anyBoolean())).thenReturn(true); sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); sendSimpleMsg(mClientMessenger, WifiP2pManager.REQUEST_DEVICE_INFO); verify(mWifiPermissionsUtil).checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), @@ -3578,6 +3544,8 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { @Test public void testRequestDiscoveryStateWhenStarted() throws Exception { forceP2pEnabled(mClient1); + when(mWifiPermissionsUtil.checkCanAccessWifiDirect(any(), any(), + anyInt(), anyBoolean())).thenReturn(false); when(mWifiPermissionsUtil.checkCanAccessWifiDirect(eq("testPkg1"), eq("testFeature"), anyInt(), anyBoolean())).thenReturn(true); when(mWifiNative.p2pFind(anyInt())).thenReturn(true); @@ -4002,4 +3970,108 @@ public class WifiP2pServiceImplTest extends WifiBaseTest { Message message = mMessageCaptor.getValue(); assertEquals(WifiP2pManager.CONNECT_FAILED, message.what); } + + /** + * Verify the group owner intent value is selected correctly when no STA connection. + */ + @Test + public void testGroupOwnerIntentSelectionWithoutStaConnection() throws Exception { + when(mWifiInfo.getNetworkId()).thenReturn(WifiConfiguration.INVALID_NETWORK_ID); + when(mWifiInfo.getFrequency()).thenReturn(2412); + forceP2pEnabled(mClient1); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); + + mockEnterProvisionDiscoveryState(); + + WifiP2pProvDiscEvent pdEvent = new WifiP2pProvDiscEvent(); + pdEvent.device = mTestWifiP2pDevice; + sendSimpleMsg(null, + WifiP2pMonitor.P2P_PROV_DISC_PBC_RSP_EVENT, + pdEvent); + + ArgumentCaptor<WifiP2pConfig> configCaptor = + ArgumentCaptor.forClass(WifiP2pConfig.class); + verify(mWifiNative).p2pConnect(configCaptor.capture(), anyBoolean()); + WifiP2pConfig config = configCaptor.getValue(); + assertEquals(WifiP2pServiceImpl.DEFAULT_GROUP_OWNER_INTENT + 1, + config.groupOwnerIntent); + } + + /** + * Verify the group owner intent value is selected correctly when 2.4GHz STA connection. + */ + @Test + public void testGroupOwnerIntentSelectionWith24GStaConnection() throws Exception { + when(mWifiInfo.getNetworkId()).thenReturn(1); + when(mWifiInfo.getFrequency()).thenReturn(2412); + forceP2pEnabled(mClient1); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); + + mockEnterProvisionDiscoveryState(); + + WifiP2pProvDiscEvent pdEvent = new WifiP2pProvDiscEvent(); + pdEvent.device = mTestWifiP2pDevice; + sendSimpleMsg(null, + WifiP2pMonitor.P2P_PROV_DISC_PBC_RSP_EVENT, + pdEvent); + + ArgumentCaptor<WifiP2pConfig> configCaptor = + ArgumentCaptor.forClass(WifiP2pConfig.class); + verify(mWifiNative).p2pConnect(configCaptor.capture(), anyBoolean()); + WifiP2pConfig config = configCaptor.getValue(); + assertEquals(WifiP2pConfig.GROUP_OWNER_INTENT_MIN, + config.groupOwnerIntent); + } + + /** + * Verify the group owner intent value is selected correctly when 5GHz STA connection. + */ + @Test + public void testGroupOwnerIntentSelectionWith5GHzStaConnection() throws Exception { + when(mWifiInfo.getNetworkId()).thenReturn(1); + when(mWifiInfo.getFrequency()).thenReturn(5200); + forceP2pEnabled(mClient1); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); + + mockEnterProvisionDiscoveryState(); + + WifiP2pProvDiscEvent pdEvent = new WifiP2pProvDiscEvent(); + pdEvent.device = mTestWifiP2pDevice; + sendSimpleMsg(null, + WifiP2pMonitor.P2P_PROV_DISC_PBC_RSP_EVENT, + pdEvent); + + ArgumentCaptor<WifiP2pConfig> configCaptor = + ArgumentCaptor.forClass(WifiP2pConfig.class); + verify(mWifiNative).p2pConnect(configCaptor.capture(), anyBoolean()); + WifiP2pConfig config = configCaptor.getValue(); + assertEquals(WifiP2pConfig.GROUP_OWNER_INTENT_MAX - 1, + config.groupOwnerIntent); + } + + /** + * Verify the group owner intent value is selected correctly when 6GHz STA connection. + */ + @Test + public void testGroupOwnerIntentSelectionWith6GHzStaConnection() throws Exception { + when(mWifiInfo.getNetworkId()).thenReturn(1); + when(mWifiInfo.getFrequency()).thenReturn(6000); + forceP2pEnabled(mClient1); + sendChannelInfoUpdateMsg("testPkg1", "testFeature", mClient1, mClientMessenger); + + mockEnterProvisionDiscoveryState(); + + WifiP2pProvDiscEvent pdEvent = new WifiP2pProvDiscEvent(); + pdEvent.device = mTestWifiP2pDevice; + sendSimpleMsg(null, + WifiP2pMonitor.P2P_PROV_DISC_PBC_RSP_EVENT, + pdEvent); + + ArgumentCaptor<WifiP2pConfig> configCaptor = + ArgumentCaptor.forClass(WifiP2pConfig.class); + verify(mWifiNative).p2pConnect(configCaptor.capture(), anyBoolean()); + WifiP2pConfig config = configCaptor.getValue(); + assertEquals(WifiP2pServiceImpl.DEFAULT_GROUP_OWNER_INTENT, + config.groupOwnerIntent); + } } |