diff options
author | Sohani Rao <sohanirao@google.com> | 2017-02-06 14:02:17 -0800 |
---|---|---|
committer | Sohani Rao <sohanirao@google.com> | 2017-03-29 19:28:35 -0700 |
commit | 6459709af0e494f81c0b792566d9e8bee4b19d95 (patch) | |
tree | 0e789d04581bce2416220fb5854c07ae0709887c | |
parent | 32575fa7a506bf05edb20a37e59d42af981a0a13 (diff) |
Send Auth failure reason in broadcast intent
SupplicantStateChange broadcast intent for authentication failure
doesn't capture the reason for authentication failure. To indicate this
reason to the user, use the newly defined (but hidden), auth failure
codes to make the intent richer.
Bug: 33245941
Test: Unit test
Change-Id: I76496cfc7365103d9ec74b12d60bde772fcba801
6 files changed, 124 insertions, 25 deletions
diff --git a/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java b/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java index 681cf3a3e..f21c75490 100644 --- a/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java +++ b/service/java/com/android/server/wifi/SupplicantStaIfaceHal.java @@ -43,6 +43,7 @@ import android.hidl.manager.V1_0.IServiceNotification; import android.net.IpConfiguration; import android.net.wifi.SupplicantState; import android.net.wifi.WifiConfiguration; +import android.net.wifi.WifiManager; import android.net.wifi.WifiSsid; import android.os.HwRemoteBinder; import android.os.RemoteException; @@ -1919,7 +1920,7 @@ public class SupplicantStaIfaceHal { if (mStateIsFourway && (!locallyGenerated || reasonCode != WLAN_REASON_IE_IN_4WAY_DIFFERS)) { mWifiMonitor.broadcastAuthenticationFailureEvent( - mIfaceName, WifiMonitor.AUTHENTICATION_FAILURE_REASON_WRONG_PSWD); + mIfaceName, WifiManager.ERROR_AUTH_FAILURE_WRONG_PSWD); } mWifiMonitor.broadcastNetworkDisconnectionEvent( mIfaceName, locallyGenerated ? 1 : 0, reasonCode, @@ -1941,7 +1942,7 @@ public class SupplicantStaIfaceHal { logCallback("onAuthenticationTimeout"); synchronized (mLock) { mWifiMonitor.broadcastAuthenticationFailureEvent( - mIfaceName, WifiMonitor.AUTHENTICATION_FAILURE_REASON_TIMEOUT); + mIfaceName, WifiManager.ERROR_AUTH_FAILURE_TIMEOUT); } } @@ -1964,7 +1965,7 @@ public class SupplicantStaIfaceHal { logCallback("onEapFailure"); synchronized (mLock) { mWifiMonitor.broadcastAuthenticationFailureEvent( - mIfaceName, WifiMonitor.AUTHENTICATION_FAILURE_REASON_EAP_FAILURE); + mIfaceName, WifiManager.ERROR_AUTH_FAILURE_EAP_FAILURE); } } diff --git a/service/java/com/android/server/wifi/SupplicantStateTracker.java b/service/java/com/android/server/wifi/SupplicantStateTracker.java index 9ba64b9bc..cac7f06df 100644 --- a/service/java/com/android/server/wifi/SupplicantStateTracker.java +++ b/service/java/com/android/server/wifi/SupplicantStateTracker.java @@ -55,6 +55,14 @@ public class SupplicantStateTracker extends StateMachine { * for all type of failures: EAP, WPS & WPA networks */ private boolean mAuthFailureInSupplicantBroadcast = false; + /* Authentication failure reason + * see {@link android.net.wifi.WifiManager#ERROR_AUTH_FAILURE_NONE}, + * {@link android.net.wifi.WifiManager#ERROR_AUTH_FAILURE_TIMEOUT}, + * {@link android.net.wifi.WifiManager#ERROR_AUTH_FAILURE_WRONG_PSWD}, + * {@link android.net.wifi.WifiManager#ERROR_AUTH_FAILURE_EAP_FAILURE} + */ + private int mAuthFailureReason; + /* Maximum retries on a authentication failure notification */ private static final int MAX_RETRIES_ON_AUTHENTICATION_FAILURE = 2; @@ -171,6 +179,11 @@ public class SupplicantStateTracker extends StateMachine { } private void sendSupplicantStateChangedBroadcast(SupplicantState state, boolean failedAuth) { + sendSupplicantStateChangedBroadcast(state, failedAuth, WifiManager.ERROR_AUTH_FAILURE_NONE); + } + + private void sendSupplicantStateChangedBroadcast(SupplicantState state, boolean failedAuth, + int reasonCode) { int supplState; switch (state) { case DISCONNECTED: supplState = BatteryStats.WIFI_SUPPL_STATE_DISCONNECTED; break; @@ -204,8 +217,11 @@ public class SupplicantStateTracker extends StateMachine { intent.putExtra(WifiManager.EXTRA_NEW_STATE, (Parcelable) state); if (failedAuth) { intent.putExtra( - WifiManager.EXTRA_SUPPLICANT_ERROR, - WifiManager.ERROR_AUTHENTICATING); + WifiManager.EXTRA_SUPPLICANT_ERROR, + WifiManager.ERROR_AUTHENTICATING); + intent.putExtra( + WifiManager.EXTRA_SUPPLICANT_ERROR_REASON, + reasonCode); } mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); } @@ -225,12 +241,15 @@ public class SupplicantStateTracker extends StateMachine { switch (message.what) { case WifiMonitor.AUTHENTICATION_FAILURE_EVENT: mAuthFailureInSupplicantBroadcast = true; + mAuthFailureReason = message.arg2; break; case WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT: StateChangeResult stateChangeResult = (StateChangeResult) message.obj; SupplicantState state = stateChangeResult.state; - sendSupplicantStateChangedBroadcast(state, mAuthFailureInSupplicantBroadcast); + sendSupplicantStateChangedBroadcast(state, mAuthFailureInSupplicantBroadcast, + mAuthFailureReason); mAuthFailureInSupplicantBroadcast = false; + mAuthFailureReason = WifiManager.ERROR_AUTH_FAILURE_NONE; transitionOnSupplicantStateChange(stateChangeResult); break; case WifiStateMachine.CMD_RESET_SUPPLICANT_STATE: @@ -332,7 +351,7 @@ public class SupplicantStateTracker extends StateMachine { } mLoopDetectIndex = state.ordinal(); sendSupplicantStateChangedBroadcast(state, - mAuthFailureInSupplicantBroadcast); + mAuthFailureInSupplicantBroadcast, mAuthFailureReason); } else { //Have the DefaultState handle the transition return NOT_HANDLED; @@ -361,7 +380,8 @@ public class SupplicantStateTracker extends StateMachine { case WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT: StateChangeResult stateChangeResult = (StateChangeResult) message.obj; SupplicantState state = stateChangeResult.state; - sendSupplicantStateChangedBroadcast(state, mAuthFailureInSupplicantBroadcast); + sendSupplicantStateChangedBroadcast(state, mAuthFailureInSupplicantBroadcast, + mAuthFailureReason); /* Ignore any connecting state in completed state. Group re-keying * events and other auth events that do not affect connectivity are * ignored @@ -390,6 +410,7 @@ public class SupplicantStateTracker extends StateMachine { public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { super.dump(fd, pw, args); pw.println("mAuthFailureInSupplicantBroadcast " + mAuthFailureInSupplicantBroadcast); + pw.println("mAuthFailureReason " + mAuthFailureReason); pw.println("mNetworksDisabledDuringConnect " + mNetworksDisabledDuringConnect); pw.println(); } diff --git a/service/java/com/android/server/wifi/WifiMonitor.java b/service/java/com/android/server/wifi/WifiMonitor.java index 6c8ac813f..d1903a0de 100644 --- a/service/java/com/android/server/wifi/WifiMonitor.java +++ b/service/java/com/android/server/wifi/WifiMonitor.java @@ -96,15 +96,6 @@ public class WifiMonitor { /* hotspot 2.0 events */ public static final int HS20_REMEDIATION_EVENT = BASE + 61; - /** - * Authentication Failure reasonCode, used internally by WifiStateMachine - * @hide - */ - public static final int AUTHENTICATION_FAILURE_REASON_DEFAULT = 0; - public static final int AUTHENTICATION_FAILURE_REASON_TIMEOUT = 1; - public static final int AUTHENTICATION_FAILURE_REASON_WRONG_PSWD = 2; - public static final int AUTHENTICATION_FAILURE_REASON_EAP_FAILURE = 3; - /* WPS config errrors */ private static final int CONFIG_MULTIPLE_PBC_DETECTED = 12; private static final int CONFIG_AUTH_FAILURE = 18; @@ -480,7 +471,10 @@ public class WifiMonitor { * * @param iface Name of iface on which this occurred. * @param reason Reason for authentication failure. This has to be one of the - * |AUTHENTICATION_FAILURE_REASON_*| reason codes. + * {@link android.net.wifi.WifiManager#ERROR_AUTH_FAILURE_NONE}, + * {@link android.net.wifi.WifiManager#ERROR_AUTH_FAILURE_TIMEOUT}, + * {@link android.net.wifi.WifiManager#ERROR_AUTH_FAILURE_WRONG_PSWD}, + * {@link android.net.wifi.WifiManager#ERROR_AUTH_FAILURE_EAP_FAILURE} */ public void broadcastAuthenticationFailureEvent(String iface, int reason) { sendMessage(iface, AUTHENTICATION_FAILURE_EVENT, 0, reason); diff --git a/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java b/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java index d747c113b..f1897c8b2 100644 --- a/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java +++ b/tests/wifitests/src/com/android/server/wifi/SupplicantStaIfaceHalTest.java @@ -50,6 +50,7 @@ import android.hidl.manager.V1_0.IServiceNotification; import android.net.IpConfiguration; import android.net.wifi.SupplicantState; import android.net.wifi.WifiConfiguration; +import android.net.wifi.WifiManager; import android.net.wifi.WifiSsid; import android.os.IHwBinder; import android.os.RemoteException; @@ -962,7 +963,7 @@ public class SupplicantStaIfaceHalTest { NativeUtil.macAddressToByteArray(BSSID), false, reasonCode); verify(mWifiMonitor, times(2)).broadcastAuthenticationFailureEvent(eq(WLAN_IFACE_NAME), - eq(WifiMonitor.AUTHENTICATION_FAILURE_REASON_WRONG_PSWD)); + eq(WifiManager.ERROR_AUTH_FAILURE_WRONG_PSWD)); } @@ -1015,7 +1016,7 @@ public class SupplicantStaIfaceHalTest { mISupplicantStaIfaceCallback.onAuthenticationTimeout( NativeUtil.macAddressToByteArray(BSSID)); verify(mWifiMonitor).broadcastAuthenticationFailureEvent(eq(WLAN_IFACE_NAME), - eq(WifiMonitor.AUTHENTICATION_FAILURE_REASON_TIMEOUT)); + eq(WifiManager.ERROR_AUTH_FAILURE_TIMEOUT)); } /** @@ -1054,7 +1055,7 @@ public class SupplicantStaIfaceHalTest { mISupplicantStaIfaceCallback.onEapFailure(); verify(mWifiMonitor).broadcastAuthenticationFailureEvent(eq(WLAN_IFACE_NAME), - eq(WifiMonitor.AUTHENTICATION_FAILURE_REASON_EAP_FAILURE)); + eq(WifiManager.ERROR_AUTH_FAILURE_EAP_FAILURE)); } /** diff --git a/tests/wifitests/src/com/android/server/wifi/SupplicantStateTrackerTest.java b/tests/wifitests/src/com/android/server/wifi/SupplicantStateTrackerTest.java index f1a9e945d..98fa80046 100644 --- a/tests/wifitests/src/com/android/server/wifi/SupplicantStateTrackerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/SupplicantStateTrackerTest.java @@ -52,7 +52,6 @@ public class SupplicantStateTrackerTest { private SupplicantStateTracker mSupplicantStateTracker; private TestLooper mLooper; private FrameworkFacade mFacade; - private BroadcastReceiver mWifiBroadcastReceiver; private FrameworkFacade getFrameworkFacade() { FrameworkFacade facade = mock(FrameworkFacade.class); @@ -83,7 +82,7 @@ public class SupplicantStateTrackerTest { */ @Test public void testSupplicantStateChangeIntent() { - mWifiBroadcastReceiver = new BroadcastReceiver() { + BroadcastReceiver wifiBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); @@ -95,8 +94,91 @@ public class SupplicantStateTrackerTest { }; IntentFilter mIntentFilter = new IntentFilter(); mIntentFilter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION); - mContext.registerReceiver(mWifiBroadcastReceiver, mIntentFilter); + mContext.registerReceiver(wifiBroadcastReceiver, mIntentFilter); mSupplicantStateTracker.sendMessage(getSupplicantStateChangeMessage(0, sWifiSsid, sBSSID, SupplicantState.SCANNING)); } + + /** + * This test verifies that the current auth status is sent in the Broadcast intent + */ + @Test + public void testAuthPassInSupplicantStateChangeIntent() { + BroadcastReceiver wifiBroadcastReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + String action = intent.getAction(); + assertTrue(action.equals(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION)); + SupplicantState recvdState = + (SupplicantState) intent.getExtra(WifiManager.EXTRA_NEW_STATE, -1); + assertEquals(SupplicantState.AUTHENTICATING, recvdState); + boolean authStatus = + (boolean) intent.getExtra(WifiManager.EXTRA_SUPPLICANT_ERROR, -1); + assertEquals(authStatus, true); + } + }; + IntentFilter mIntentFilter = new IntentFilter(); + mIntentFilter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION); + mContext.registerReceiver(wifiBroadcastReceiver, mIntentFilter); + mSupplicantStateTracker.sendMessage(getSupplicantStateChangeMessage(0, sWifiSsid, + sBSSID, SupplicantState.AUTHENTICATING)); + mSupplicantStateTracker.sendMessage(WifiMonitor.AUTHENTICATION_FAILURE_EVENT); + } + + /** + * This test verifies that the current auth status is sent in the Broadcast intent + */ + @Test + public void testAuthFailedInSupplicantStateChangeIntent() { + BroadcastReceiver wifiBroadcastReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + String action = intent.getAction(); + assertTrue(action.equals(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION)); + SupplicantState recvdState = + (SupplicantState) intent.getExtra(WifiManager.EXTRA_NEW_STATE, -1); + assertEquals(SupplicantState.AUTHENTICATING, recvdState); + boolean authStatus = + (boolean) intent.getExtra(WifiManager.EXTRA_SUPPLICANT_ERROR, -1); + assertEquals(authStatus, false); + } + }; + IntentFilter mIntentFilter = new IntentFilter(); + mIntentFilter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION); + mContext.registerReceiver(wifiBroadcastReceiver, mIntentFilter); + mSupplicantStateTracker.sendMessage(WifiMonitor.AUTHENTICATION_FAILURE_EVENT); + mSupplicantStateTracker.sendMessage(getSupplicantStateChangeMessage(0, sWifiSsid, + sBSSID, SupplicantState.AUTHENTICATING)); + } + + /** + * This test verifies the correct reasonCode for auth failure is sent in Broadcast + * intent. + */ + @Test + public void testReasonCodeInSupplicantStateChangeIntent() { + BroadcastReceiver wifiBroadcastReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + String action = intent.getAction(); + assertTrue(action.equals(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION)); + SupplicantState recvdState = + (SupplicantState) intent.getExtra(WifiManager.EXTRA_NEW_STATE, -1); + assertEquals(SupplicantState.AUTHENTICATING, recvdState); + boolean authStatus = + (boolean) intent.getExtra(WifiManager.EXTRA_SUPPLICANT_ERROR, -1); + assertEquals(authStatus, false); + int reasonCode = (int) + intent.getExtra(WifiManager.EXTRA_SUPPLICANT_ERROR_REASON, -1); + assertEquals(reasonCode, WifiManager.ERROR_AUTH_FAILURE_WRONG_PSWD); + } + }; + IntentFilter mIntentFilter = new IntentFilter(); + mIntentFilter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION); + mContext.registerReceiver(wifiBroadcastReceiver, mIntentFilter); + mSupplicantStateTracker.sendMessage(WifiMonitor.AUTHENTICATION_FAILURE_EVENT, 0, + WifiManager.ERROR_AUTH_FAILURE_WRONG_PSWD); + mSupplicantStateTracker.sendMessage(getSupplicantStateChangeMessage(0, sWifiSsid, + sBSSID, SupplicantState.AUTHENTICATING)); + } } diff --git a/tests/wifitests/src/com/android/server/wifi/WifiMonitorTest.java b/tests/wifitests/src/com/android/server/wifi/WifiMonitorTest.java index 6e3dbbbcf..4b4a17dce 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiMonitorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiMonitorTest.java @@ -343,7 +343,7 @@ public class WifiMonitorTest { public void testBroadcastAuthenticationFailureEvent() { mWifiMonitor.registerHandler( WLAN_IFACE_NAME, WifiMonitor.AUTHENTICATION_FAILURE_EVENT, mHandlerSpy); - int reason = WifiMonitor.AUTHENTICATION_FAILURE_REASON_WRONG_PSWD; + int reason = WifiManager.ERROR_AUTH_FAILURE_WRONG_PSWD; mWifiMonitor.broadcastAuthenticationFailureEvent(WLAN_IFACE_NAME, reason); mLooper.dispatchAll(); |