diff options
author | Peter Qiu <zqiu@google.com> | 2017-07-07 10:25:31 -0700 |
---|---|---|
committer | Peter Qiu <zqiu@google.com> | 2017-07-14 11:04:11 -0700 |
commit | e81e74137b3da0254cc7d77a5773ea9bff67d5f8 (patch) | |
tree | 2d0c5ecdcd8b3f17ba8b1bbcc302030cb2e5e203 /tests | |
parent | ec0922425c007ba22527e0cacad1445d5f0d0ad8 (diff) |
Display notification when wrong password error is detected
A new notification will be generated and displayed when the wrong
password error is detected for the current connection.
It will be dismissed when:
- the user manually dismiss it or tap on it
- attempting a new Wi-Fi network connection
- timeout, currently set to 5 minutes
The current landing page for the notification is the network list page,
it will be updated when the new landing page is ready (dialog prompting
for the new password).
Bug: 33245941
Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh
Test: manual testing
Change-Id: Iaa75bff6d96ed8c9e9d8472a840d03c54f9f2c52
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java | 7 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WrongPasswordNotifierTest.java | 101 |
2 files changed, 107 insertions, 1 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java index 52b4d3687..71f29b4f6 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java @@ -344,6 +344,7 @@ public class WifiStateMachineTest { @Mock SelfRecovery mSelfRecovery; @Mock IpManager mIpManager; @Mock TelephonyManager mTelephonyManager; + @Mock WrongPasswordNotifier mWrongPasswordNotifier; public WifiStateMachineTest() throws Exception { } @@ -436,7 +437,8 @@ public class WifiStateMachineTest { private void initializeWsm() throws Exception { mWsm = new WifiStateMachine(mContext, mFrameworkFacade, mLooper.getLooper(), - mUserManager, mWifiInjector, mBackupManagerProxy, mCountryCode, mWifiNative); + mUserManager, mWifiInjector, mBackupManagerProxy, mCountryCode, mWifiNative, + mWrongPasswordNotifier); mWsmThread = getWsmHandlerThread(mWsm); final AsyncChannel channel = new AsyncChannel(); @@ -1113,6 +1115,7 @@ public class WifiStateMachineTest { WifiManager.ERROR_AUTH_FAILURE_WRONG_PSWD); mLooper.dispatchAll(); + verify(mWrongPasswordNotifier, never()).onWrongPasswordError(anyString()); verify(mWifiConfigManager).updateNetworkSelectionStatus(anyInt(), eq(WifiConfiguration.NetworkSelectionStatus.DISABLED_AUTHENTICATION_FAILURE)); @@ -1138,6 +1141,7 @@ public class WifiStateMachineTest { verify(mWifiConfigManager).enableNetwork(eq(0), eq(true), anyInt()); WifiConfiguration config = new WifiConfiguration(); + config.SSID = sSSID; config.getNetworkSelectionStatus().setHasEverConnected(false); when(mWifiConfigManager.getConfiguredNetwork(anyInt())).thenReturn(config); @@ -1145,6 +1149,7 @@ public class WifiStateMachineTest { WifiManager.ERROR_AUTH_FAILURE_WRONG_PSWD); mLooper.dispatchAll(); + verify(mWrongPasswordNotifier).onWrongPasswordError(eq(sSSID)); verify(mWifiConfigManager).updateNetworkSelectionStatus(anyInt(), eq(WifiConfiguration.NetworkSelectionStatus.DISABLED_BY_WRONG_PASSWORD)); diff --git a/tests/wifitests/src/com/android/server/wifi/WrongPasswordNotifierTest.java b/tests/wifitests/src/com/android/server/wifi/WrongPasswordNotifierTest.java new file mode 100644 index 000000000..405ab65c2 --- /dev/null +++ b/tests/wifitests/src/com/android/server/wifi/WrongPasswordNotifierTest.java @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2017 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 com.android.server.wifi; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; + +import android.app.Notification; +import android.app.NotificationManager; +import android.content.Context; +import android.content.res.Resources; + +import com.android.internal.notification.SystemNotificationChannels; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Answers; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +/** + * Unit tests for {@link com.android.server.wifi.WrongPasswordNotifier}. + */ +public class WrongPasswordNotifierTest { + private static final String TEST_SSID = "Test SSID"; + + @Mock Context mContext; + @Mock Resources mResources; + @Mock NotificationManager mNotificationManager; + @Mock FrameworkFacade mFrameworkFacade; + @Mock(answer = Answers.RETURNS_DEEP_STUBS) private Notification.Builder mNotificationBuilder; + WrongPasswordNotifier mWrongPassNotifier; + + /** + * Sets up for unit test + */ + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + when(mContext.getSystemService(Context.NOTIFICATION_SERVICE)) + .thenReturn(mNotificationManager); + when(mContext.getResources()).thenReturn(mResources); + mWrongPassNotifier = + new WrongPasswordNotifier(mContext, mFrameworkFacade); + } + + /** + * Verify that a wrong password notification will be generated/pushed when a wrong password + * error is detected for the current connection. + * + * @throws Exception + */ + @Test + public void onWrongPasswordError() throws Exception { + when(mFrameworkFacade.makeNotificationBuilder(any(), + eq(SystemNotificationChannels.NETWORK_ALERTS))).thenReturn(mNotificationBuilder); + mWrongPassNotifier.onWrongPasswordError(TEST_SSID); + verify(mNotificationManager).notify(eq(WrongPasswordNotifier.NOTIFICATION_ID), any()); + } + + /** + * Verify that we will attempt to dismiss the wrong password notification when starting a new + * connection attempt with the previous connection resulting in a wrong password error. + * + * @throws Exception + */ + @Test + public void onNewConnectionAttemptWithPreviousWrongPasswordError() throws Exception { + onWrongPasswordError(); + reset(mNotificationManager); + + mWrongPassNotifier.onNewConnectionAttempt(); + verify(mNotificationManager).cancel(any(), eq(WrongPasswordNotifier.NOTIFICATION_ID)); + } + + /** + * Verify that we don't attempt to dismiss the wrong password notification when starting a new + * connection attempt with the previous connection not resulting in a wrong password error. + * + * @throws Exception + */ + @Test + public void onNewConnectionAttemptWithoutPreviousWrongPasswordError() throws Exception { + mWrongPassNotifier.onNewConnectionAttempt(); + verify(mNotificationManager, never()).cancel(any(), anyInt()); + } +} |