summaryrefslogtreecommitdiffstats
path: root/tests/wifitests/src/com/android/server/wifi/WakeupOnboardingTest.java
diff options
context:
space:
mode:
authorEric Schwarzenbach <easchwar@google.com>2017-12-15 10:49:09 -0800
committerEric Schwarzenbach <easchwar@google.com>2018-01-23 15:53:14 -0800
commit9d60c0ff94757e8862f167f6de54789fe2e1bab2 (patch)
treeb9c0da46c368bbcce8a26077e7e1e534cbaa3f50 /tests/wifitests/src/com/android/server/wifi/WakeupOnboardingTest.java
parent7eac1e20f0afc510535cd6de1024309f1adb9b4e (diff)
downloadandroid_frameworks_opt_net_wifi-9d60c0ff94757e8862f167f6de54789fe2e1bab2.tar.gz
android_frameworks_opt_net_wifi-9d60c0ff94757e8862f167f6de54789fe2e1bab2.tar.bz2
android_frameworks_opt_net_wifi-9d60c0ff94757e8862f167f6de54789fe2e1bab2.zip
Add onboarding process for Wifi Wake.
Creates a notification to display to the user the first time they turn off wifi with the feature enabled. Updates the ConfigStoreData to include a bit for "isOnboarded". Creates a factory class to handle constructing the actual notification. Gates handleScanResults on user onboarded status. Bug: 64094365 Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh Test: adb push old WifiConfigStore.xml; adb shell stop; adb shell start; verify that the config store loads properly and writes the new WakeupConfigStoreData Change-Id: Ia3949a70a2c64bc40fc658788e395061a7ca86ee
Diffstat (limited to 'tests/wifitests/src/com/android/server/wifi/WakeupOnboardingTest.java')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WakeupOnboardingTest.java201
1 files changed, 201 insertions, 0 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WakeupOnboardingTest.java b/tests/wifitests/src/com/android/server/wifi/WakeupOnboardingTest.java
new file mode 100644
index 000000000..1e98b1455
--- /dev/null
+++ b/tests/wifitests/src/com/android/server/wifi/WakeupOnboardingTest.java
@@ -0,0 +1,201 @@
+/*
+ * Copyright (C) 2018 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 com.android.server.wifi.WakeupNotificationFactory.ACTION_DISMISS_NOTIFICATION;
+import static com.android.server.wifi.WakeupNotificationFactory.ACTION_OPEN_WIFI_PREFERENCES;
+import static com.android.server.wifi.WakeupNotificationFactory.ACTION_TURN_OFF_WIFI_WAKE;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.app.NotificationManager;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.Handler;
+import android.os.test.TestLooper;
+import android.provider.Settings;
+
+import com.android.internal.messages.nano.SystemMessageProto.SystemMessage;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.InOrder;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+
+/** Unit tests for {@link com.android.server.wifi.WakeupOnboarding} */
+public class WakeupOnboardingTest {
+
+ @Mock private Context mContext;
+ @Mock private WifiConfigManager mWifiConfigManager;
+ @Mock private FrameworkFacade mFrameworkFacade;
+ @Mock private WakeupNotificationFactory mWakeupNotificationFactory;
+ @Mock private NotificationManager mNotificationManager;
+
+ private TestLooper mLooper;
+ private WakeupOnboarding mWakeupOnboarding;
+
+ // convenience method for resetting onboarded status
+ private void setOnboardedStatus(boolean isOnboarded) {
+ mWakeupOnboarding.getDataSource().setData(isOnboarded);
+ }
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ when(mContext.getSystemService(Context.NOTIFICATION_SERVICE))
+ .thenReturn(mNotificationManager);
+
+ mLooper = new TestLooper();
+ mWakeupOnboarding = new WakeupOnboarding(mContext, mWifiConfigManager, mLooper.getLooper(),
+ mFrameworkFacade, mWakeupNotificationFactory);
+ }
+
+ /**
+ * Verify that the notification shows if the user isn't onboarded.
+ */
+ @Test
+ public void showsNotificationIfNotOnboarded() {
+ setOnboardedStatus(false);
+ mWakeupOnboarding.maybeShowNotification();
+
+ verify(mNotificationManager).notify(eq(SystemMessage.NOTE_WIFI_WAKE_ONBOARD), any());
+ }
+
+ /**
+ * Verify that the notification does not show if the user is onboarded.
+ */
+ @Test
+ public void doesNotShowNotificationIfAlreadyOnboarded() {
+ setOnboardedStatus(true);
+ mWakeupOnboarding.maybeShowNotification();
+
+ verify(mNotificationManager, never())
+ .notify(eq(SystemMessage.NOTE_WIFI_WAKE_ONBOARD), any());
+ }
+
+ /**
+ * Verify that the notification does not relaunch if it's already showing.
+ */
+ @Test
+ public void doesNotShowNotificationIfAlreadyShowing() {
+ setOnboardedStatus(false);
+ mWakeupOnboarding.maybeShowNotification();
+ mWakeupOnboarding.maybeShowNotification();
+
+ InOrder inOrder = Mockito.inOrder(mNotificationManager);
+ inOrder.verify(mNotificationManager)
+ .notify(eq(SystemMessage.NOTE_WIFI_WAKE_ONBOARD), any());
+ inOrder.verifyNoMoreInteractions();
+ }
+
+ /**
+ * Verify that the user is onboarded when the notification is dismissed.
+ */
+ @Test
+ public void dismissNotificationAction_setsOnboarded() {
+ setOnboardedStatus(false);
+ assertFalse(mWakeupOnboarding.isOnboarded());
+
+ mWakeupOnboarding.maybeShowNotification();
+ ArgumentCaptor<BroadcastReceiver> captor = ArgumentCaptor.forClass(BroadcastReceiver.class);
+ verify(mContext).registerReceiver(captor.capture(), any(IntentFilter.class), any(),
+ any(Handler.class));
+ BroadcastReceiver broadcastReceiver = captor.getValue();
+
+ broadcastReceiver.onReceive(mContext, new Intent(ACTION_DISMISS_NOTIFICATION));
+
+ verify(mNotificationManager).cancel(SystemMessage.NOTE_WIFI_WAKE_ONBOARD);
+ verify(mWifiConfigManager).saveToStore(false);
+ assertTrue(mWakeupOnboarding.isOnboarded());
+ }
+
+ /**
+ * Verify that the user is onboarded and Wifi Wake is turned off when the user selects the
+ * ACTION_TURN_OFF_WIFI_WAKE action.
+ */
+ @Test
+ public void turnOffWifiWakeAction_setsOnboardedAndTurnsOffWifiWake() {
+ setOnboardedStatus(false);
+ assertFalse(mWakeupOnboarding.isOnboarded());
+
+ mWakeupOnboarding.maybeShowNotification();
+ ArgumentCaptor<BroadcastReceiver> captor = ArgumentCaptor.forClass(BroadcastReceiver.class);
+ verify(mContext).registerReceiver(captor.capture(), any(IntentFilter.class), any(),
+ any(Handler.class));
+ BroadcastReceiver broadcastReceiver = captor.getValue();
+
+ broadcastReceiver.onReceive(mContext, new Intent(ACTION_TURN_OFF_WIFI_WAKE));
+
+ verify(mFrameworkFacade).setIntegerSetting(mContext,
+ Settings.Global.WIFI_WAKEUP_ENABLED, 0);
+
+ verify(mNotificationManager).cancel(SystemMessage.NOTE_WIFI_WAKE_ONBOARD);
+ verify(mWifiConfigManager).saveToStore(false);
+ assertTrue(mWakeupOnboarding.isOnboarded());
+ }
+
+ /**
+ * Verify that the user is onboarded and sent to WifiSettings when the user selects the
+ * ACTION_OPEN_WIFI_SETTINGS action.
+ */
+ @Test
+ public void openWifiSettingsAction_setsOnboardedAndOpensWifiSettings() {
+ setOnboardedStatus(false);
+ assertFalse(mWakeupOnboarding.isOnboarded());
+
+ mWakeupOnboarding.maybeShowNotification();
+ ArgumentCaptor<BroadcastReceiver> captor = ArgumentCaptor.forClass(BroadcastReceiver.class);
+ verify(mContext).registerReceiver(captor.capture(), any(IntentFilter.class), any(),
+ any(Handler.class));
+ BroadcastReceiver broadcastReceiver = captor.getValue();
+
+ broadcastReceiver.onReceive(mContext, new Intent(ACTION_OPEN_WIFI_PREFERENCES));
+
+ verify(mContext).startActivity(any());
+
+ verify(mNotificationManager).cancel(SystemMessage.NOTE_WIFI_WAKE_ONBOARD);
+ verify(mWifiConfigManager).saveToStore(false);
+ assertTrue(mWakeupOnboarding.isOnboarded());
+ }
+
+ /**
+ * Verify that onStop() doesn't onboard the user.
+ */
+ @Test
+ public void onStopDismissesNotificationWithoutOnboarding() {
+ setOnboardedStatus(false);
+ assertFalse(mWakeupOnboarding.isOnboarded());
+
+ mWakeupOnboarding.maybeShowNotification();
+ mWakeupOnboarding.onStop();
+
+ verify(mNotificationManager).cancel(SystemMessage.NOTE_WIFI_WAKE_ONBOARD);
+ assertFalse(mWakeupOnboarding.isOnboarded());
+ }
+}