summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2017-09-29 21:37:50 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2017-09-29 21:37:50 +0000
commitdbaf29e09adbf2e44a598438fa8ad38f70c47b5b (patch)
tree392b4a73805450b92290fa217f6241266a0b0222 /tests
parent2f5d10a29d17781e903eeddedb4a547e62c55524 (diff)
parenta88242633e76bf3a070cfcc0a018ff7f9806f1f4 (diff)
Merge "WifiMetrics: add methods to increment ONA metrics." into oc-mr1-dev
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/OpenNetworkNotifierTest.java162
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java100
2 files changed, 258 insertions, 4 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/OpenNetworkNotifierTest.java b/tests/wifitests/src/com/android/server/wifi/OpenNetworkNotifierTest.java
index 46ec1597e..5a0b011f2 100644
--- a/tests/wifitests/src/com/android/server/wifi/OpenNetworkNotifierTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/OpenNetworkNotifierTest.java
@@ -20,6 +20,7 @@ import static com.android.server.wifi.OpenNetworkNotifier.DEFAULT_REPEAT_DELAY_S
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
@@ -31,6 +32,8 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
+import android.database.ContentObserver;
+import android.net.Uri;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;
import android.os.Message;
@@ -41,6 +44,8 @@ import android.os.test.TestLooper;
import android.provider.Settings;
import android.util.ArraySet;
+import com.android.server.wifi.nano.WifiMetricsProto.ConnectToNetworkNotificationAndActionCount;
+
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
@@ -57,11 +62,13 @@ import java.util.Set;
public class OpenNetworkNotifierTest {
private static final String TEST_SSID_1 = "Test SSID 1";
+ private static final String TEST_SSID_2 = "Test SSID 2";
private static final int MIN_RSSI_LEVEL = -127;
@Mock private Context mContext;
@Mock private Resources mResources;
@Mock private FrameworkFacade mFrameworkFacade;
+ @Mock private WifiMetrics mWifiMetrics;
@Mock private Clock mClock;
@Mock private WifiConfigStore mWifiConfigStore;
@Mock private WifiConfigManager mWifiConfigManager;
@@ -73,6 +80,7 @@ public class OpenNetworkNotifierTest {
private OpenNetworkNotifier mNotificationController;
private TestLooper mLooper;
private BroadcastReceiver mBroadcastReceiver;
+ private ContentObserver mContentObserver;
private ScanResult mDummyNetwork;
private List<ScanDetail> mOpenNetworks;
private Set<String> mBlacklistedSsids;
@@ -103,16 +111,42 @@ public class OpenNetworkNotifierTest {
mLooper = new TestLooper();
mNotificationController = new OpenNetworkNotifier(
- mContext, mLooper.getLooper(), mFrameworkFacade, mClock, mWifiConfigManager,
- mWifiConfigStore, mWifiStateMachine, mOpenNetworkRecommender, mNotificationBuilder);
+ mContext, mLooper.getLooper(), mFrameworkFacade, mClock, mWifiMetrics,
+ mWifiConfigManager, mWifiConfigStore, mWifiStateMachine, mOpenNetworkRecommender,
+ mNotificationBuilder);
ArgumentCaptor<BroadcastReceiver> broadcastReceiverCaptor =
ArgumentCaptor.forClass(BroadcastReceiver.class);
verify(mContext).registerReceiver(broadcastReceiverCaptor.capture(), any(), any(), any());
mBroadcastReceiver = broadcastReceiverCaptor.getValue();
+ ArgumentCaptor<ContentObserver> observerCaptor =
+ ArgumentCaptor.forClass(ContentObserver.class);
+ verify(mFrameworkFacade).registerContentObserver(eq(mContext), any(Uri.class), eq(true),
+ observerCaptor.capture());
+ mContentObserver = observerCaptor.getValue();
mNotificationController.handleScreenStateChanged(true);
}
/**
+ * On {@link OpenNetworkNotifier} construction, WifiMetrics should track setting state.
+ */
+ @Test
+ public void onCreate_setWifiNetworksAvailableNotificationSettingState() {
+ verify(mWifiMetrics).setIsWifiNetworksAvailableNotificationEnabled(true);
+ }
+
+ /**
+ * When feature setting is toggled, WifiMetrics should track the disabled setting state.
+ */
+ @Test
+ public void onFeatureDisable_setWifiNetworksAvailableNotificationSettingDisabled() {
+ when(mFrameworkFacade.getIntegerSetting(mContext,
+ Settings.Global.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON, 1)).thenReturn(0);
+ mContentObserver.onChange(false);
+
+ verify(mWifiMetrics).setIsWifiNetworksAvailableNotificationEnabled(false);
+ }
+
+ /**
* When scan results with open networks are handled, a notification is posted.
*/
@Test
@@ -121,6 +155,8 @@ public class OpenNetworkNotifierTest {
verify(mOpenNetworkRecommender).recommendNetwork(mOpenNetworks, mBlacklistedSsids);
verify(mNotificationBuilder).createConnectToNetworkNotification(mDummyNetwork);
+ verify(mWifiMetrics).incrementConnectToNetworkNotification(
+ ConnectToNetworkNotificationAndActionCount.NOTIFICATION_RECOMMEND_NETWORK);
verify(mNotificationManager).notify(anyInt(), any());
}
@@ -136,6 +172,20 @@ public class OpenNetworkNotifierTest {
}
/**
+ * When the feature is disabled, no notifications are posted.
+ */
+ @Test
+ public void handleScanResults_featureDisabled_notificationNotDisplayed() {
+ when(mFrameworkFacade.getIntegerSetting(mContext,
+ Settings.Global.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON, 1)).thenReturn(0);
+ mContentObserver.onChange(false);
+ mNotificationController.handleScanResults(new ArrayList<>());
+
+ verify(mOpenNetworkRecommender, never()).recommendNetwork(any(), any());
+ verify(mNotificationManager, never()).notify(anyInt(), any());
+ }
+
+ /**
* When a notification is showing and scan results with no open networks are handled, the
* notification is cleared.
*/
@@ -145,6 +195,8 @@ public class OpenNetworkNotifierTest {
verify(mOpenNetworkRecommender).recommendNetwork(mOpenNetworks, mBlacklistedSsids);
verify(mNotificationBuilder).createConnectToNetworkNotification(mDummyNetwork);
+ verify(mWifiMetrics).incrementConnectToNetworkNotification(
+ ConnectToNetworkNotificationAndActionCount.NOTIFICATION_RECOMMEND_NETWORK);
verify(mNotificationManager).notify(anyInt(), any());
mNotificationController.handleScanResults(new ArrayList<>());
@@ -162,6 +214,8 @@ public class OpenNetworkNotifierTest {
verify(mOpenNetworkRecommender).recommendNetwork(mOpenNetworks, mBlacklistedSsids);
verify(mNotificationBuilder).createConnectToNetworkNotification(mDummyNetwork);
+ verify(mWifiMetrics).incrementConnectToNetworkNotification(
+ ConnectToNetworkNotificationAndActionCount.NOTIFICATION_RECOMMEND_NETWORK);
verify(mNotificationManager).notify(anyInt(), any());
when(mOpenNetworkRecommender.recommendNetwork(any(), any())).thenReturn(null);
@@ -180,6 +234,8 @@ public class OpenNetworkNotifierTest {
verify(mOpenNetworkRecommender).recommendNetwork(mOpenNetworks, mBlacklistedSsids);
verify(mNotificationBuilder).createConnectToNetworkNotification(mDummyNetwork);
+ verify(mWifiMetrics).incrementConnectToNetworkNotification(
+ ConnectToNetworkNotificationAndActionCount.NOTIFICATION_RECOMMEND_NETWORK);
verify(mNotificationManager).notify(anyInt(), any());
mNotificationController.handleScreenStateChanged(false);
@@ -198,6 +254,8 @@ public class OpenNetworkNotifierTest {
verify(mOpenNetworkRecommender).recommendNetwork(mOpenNetworks, mBlacklistedSsids);
verify(mNotificationBuilder).createConnectToNetworkNotification(mDummyNetwork);
+ verify(mWifiMetrics).incrementConnectToNetworkNotification(
+ ConnectToNetworkNotificationAndActionCount.NOTIFICATION_RECOMMEND_NETWORK);
verify(mNotificationManager).notify(anyInt(), any());
mNotificationController.clearPendingNotification(true);
@@ -239,15 +297,25 @@ public class OpenNetworkNotifierTest {
verify(mOpenNetworkRecommender).recommendNetwork(mOpenNetworks, mBlacklistedSsids);
verify(mNotificationBuilder).createConnectToNetworkNotification(mDummyNetwork);
+ verify(mWifiMetrics).incrementConnectToNetworkNotification(
+ ConnectToNetworkNotificationAndActionCount.NOTIFICATION_RECOMMEND_NETWORK);
verify(mNotificationManager).notify(anyInt(), any());
+ ScanResult newNetwork = new ScanResult();
+ newNetwork.SSID = TEST_SSID_2;
+ mDummyNetwork.capabilities = "[ESS]";
+ mDummyNetwork.level = MIN_RSSI_LEVEL;
+ mOpenNetworks.add(new ScanDetail(newNetwork, null /* networkDetail */));
+ when(mOpenNetworkRecommender.recommendNetwork(any(), any())).thenReturn(newNetwork);
+
mNotificationController.handleScreenStateChanged(false);
mNotificationController.handleScanResults(mOpenNetworks);
- // Recommendation made twice
+ // Recommendation changed
verify(mOpenNetworkRecommender, times(2)).recommendNetwork(
mOpenNetworks, mBlacklistedSsids);
- verify(mNotificationBuilder, times(2)).createConnectToNetworkNotification(mDummyNetwork);
+ verify(mNotificationBuilder).createConnectToNetworkNotification(newNetwork);
+ verify(mWifiMetrics).incrementNumOpenNetworkRecommendationUpdates();
verify(mNotificationManager, times(2)).notify(anyInt(), any());
}
@@ -261,6 +329,8 @@ public class OpenNetworkNotifierTest {
verify(mOpenNetworkRecommender).recommendNetwork(mOpenNetworks, mBlacklistedSsids);
verify(mNotificationBuilder).createConnectToNetworkNotification(mDummyNetwork);
+ verify(mWifiMetrics).incrementConnectToNetworkNotification(
+ ConnectToNetworkNotificationAndActionCount.NOTIFICATION_RECOMMEND_NETWORK);
verify(mNotificationManager).notify(anyInt(), any());
mNotificationController.clearPendingNotification(false);
@@ -283,6 +353,8 @@ public class OpenNetworkNotifierTest {
verify(mOpenNetworkRecommender).recommendNetwork(mOpenNetworks, mBlacklistedSsids);
verify(mNotificationBuilder).createConnectToNetworkNotification(mDummyNetwork);
+ verify(mWifiMetrics).incrementConnectToNetworkNotification(
+ ConnectToNetworkNotificationAndActionCount.NOTIFICATION_RECOMMEND_NETWORK);
verify(mNotificationManager).notify(anyInt(), any());
mNotificationController.clearPendingNotification(true);
@@ -292,6 +364,8 @@ public class OpenNetworkNotifierTest {
verify(mOpenNetworkRecommender, times(2)).recommendNetwork(
mOpenNetworks, mBlacklistedSsids);
verify(mNotificationBuilder, times(2)).createConnectToNetworkNotification(mDummyNetwork);
+ verify(mWifiMetrics, times(2)).incrementConnectToNetworkNotification(
+ ConnectToNetworkNotificationAndActionCount.NOTIFICATION_RECOMMEND_NETWORK);
verify(mNotificationManager, times(2)).notify(anyInt(), any());
}
@@ -305,6 +379,8 @@ public class OpenNetworkNotifierTest {
verify(mOpenNetworkRecommender).recommendNetwork(mOpenNetworks, mBlacklistedSsids);
verify(mNotificationBuilder).createConnectToNetworkNotification(mDummyNetwork);
+ verify(mWifiMetrics).incrementConnectToNetworkNotification(
+ ConnectToNetworkNotificationAndActionCount.NOTIFICATION_RECOMMEND_NETWORK);
verify(mNotificationManager).notify(anyInt(), any());
mBroadcastReceiver.onReceive(
@@ -320,6 +396,7 @@ public class OpenNetworkNotifierTest {
Set<String> expectedBlacklist = new ArraySet<>();
expectedBlacklist.add(mDummyNetwork.SSID);
verify(mOpenNetworkRecommender).recommendNetwork(mOpenNetworks, expectedBlacklist);
+ verify(mWifiMetrics).setOpenNetworkRecommenderBlacklistSize(expectedBlacklist.size());
}
/**
@@ -332,6 +409,8 @@ public class OpenNetworkNotifierTest {
verify(mOpenNetworkRecommender).recommendNetwork(mOpenNetworks, mBlacklistedSsids);
verify(mNotificationBuilder).createConnectToNetworkNotification(mDummyNetwork);
+ verify(mWifiMetrics).incrementConnectToNetworkNotification(
+ ConnectToNetworkNotificationAndActionCount.NOTIFICATION_RECOMMEND_NETWORK);
verify(mNotificationManager).notify(anyInt(), any());
mNotificationController.clearPendingNotification(false);
@@ -344,6 +423,8 @@ public class OpenNetworkNotifierTest {
verify(mOpenNetworkRecommender, times(2)).recommendNetwork(
mOpenNetworks, mBlacklistedSsids);
verify(mNotificationBuilder, times(2)).createConnectToNetworkNotification(mDummyNetwork);
+ verify(mWifiMetrics, times(2)).incrementConnectToNetworkNotification(
+ ConnectToNetworkNotificationAndActionCount.NOTIFICATION_RECOMMEND_NETWORK);
verify(mNotificationManager, times(2)).notify(anyInt(), any());
}
@@ -366,6 +447,8 @@ public class OpenNetworkNotifierTest {
verify(mOpenNetworkRecommender).recommendNetwork(mOpenNetworks, mBlacklistedSsids);
verify(mNotificationBuilder).createConnectToNetworkNotification(mDummyNetwork);
+ verify(mWifiMetrics).incrementConnectToNetworkNotification(
+ ConnectToNetworkNotificationAndActionCount.NOTIFICATION_RECOMMEND_NETWORK);
verify(mNotificationManager).notify(anyInt(), any());
when(mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_WIFI, UserHandle.CURRENT))
@@ -399,6 +482,8 @@ public class OpenNetworkNotifierTest {
verify(mOpenNetworkRecommender).recommendNetwork(mOpenNetworks, mBlacklistedSsids);
// Initial Notification
verify(mNotificationBuilder).createConnectToNetworkNotification(mDummyNetwork);
+ verify(mWifiMetrics).incrementConnectToNetworkNotification(
+ ConnectToNetworkNotificationAndActionCount.NOTIFICATION_RECOMMEND_NETWORK);
verify(mNotificationManager).notify(anyInt(), any());
mBroadcastReceiver.onReceive(mContext,
@@ -407,10 +492,41 @@ public class OpenNetworkNotifierTest {
verify(mWifiStateMachine).sendMessage(any(Message.class));
// Connecting Notification
verify(mNotificationBuilder).createNetworkConnectingNotification(mDummyNetwork);
+ verify(mWifiMetrics).incrementConnectToNetworkNotification(
+ ConnectToNetworkNotificationAndActionCount.NOTIFICATION_CONNECTING_TO_NETWORK);
+ verify(mWifiMetrics).incrementConnectToNetworkNotificationAction(
+ ConnectToNetworkNotificationAndActionCount.NOTIFICATION_RECOMMEND_NETWORK,
+ ConnectToNetworkNotificationAndActionCount.ACTION_CONNECT_TO_NETWORK);
verify(mNotificationManager, times(2)).notify(anyInt(), any());
}
/**
+ * {@link ConnectToNetworkNotificationBuilder#ACTION_PICK_WIFI_NETWORK} opens Wi-Fi settings
+ * if the recommendation notification is showing.
+ */
+ @Test
+ public void actionPickWifiNetwork_currentRecommendationExists_opensWifiSettings() {
+ mNotificationController.handleScanResults(mOpenNetworks);
+
+ verify(mOpenNetworkRecommender).recommendNetwork(mOpenNetworks, mBlacklistedSsids);
+ // Initial Notification
+ verify(mNotificationBuilder).createConnectToNetworkNotification(mDummyNetwork);
+ verify(mWifiMetrics).incrementConnectToNetworkNotification(
+ ConnectToNetworkNotificationAndActionCount.NOTIFICATION_RECOMMEND_NETWORK);
+ verify(mNotificationManager).notify(anyInt(), any());
+
+ mBroadcastReceiver.onReceive(mContext,
+ new Intent(ConnectToNetworkNotificationBuilder.ACTION_PICK_WIFI_NETWORK));
+
+ ArgumentCaptor<Intent> pickerIntentCaptor = ArgumentCaptor.forClass(Intent.class);
+ verify(mContext).startActivity(pickerIntentCaptor.capture());
+ assertEquals(pickerIntentCaptor.getValue().getAction(), Settings.ACTION_WIFI_SETTINGS);
+ verify(mWifiMetrics).incrementConnectToNetworkNotificationAction(
+ ConnectToNetworkNotificationAndActionCount.NOTIFICATION_RECOMMEND_NETWORK,
+ ConnectToNetworkNotificationAndActionCount.ACTION_PICK_WIFI_NETWORK);
+ }
+
+ /**
* {@link OpenNetworkNotifier#handleWifiConnected()} does not post connected notification if
* the connecting notification is not showing
*/
@@ -419,6 +535,8 @@ public class OpenNetworkNotifierTest {
mNotificationController.handleWifiConnected();
verify(mNotificationManager, never()).notify(anyInt(), any());
+ verify(mWifiMetrics, never()).incrementConnectToNetworkNotification(
+ ConnectToNetworkNotificationAndActionCount.NOTIFICATION_CONNECTED_TO_NETWORK);
}
/**
@@ -431,6 +549,8 @@ public class OpenNetworkNotifierTest {
verify(mOpenNetworkRecommender).recommendNetwork(mOpenNetworks, mBlacklistedSsids);
// Initial Notification
verify(mNotificationBuilder).createConnectToNetworkNotification(mDummyNetwork);
+ verify(mWifiMetrics).incrementConnectToNetworkNotification(
+ ConnectToNetworkNotificationAndActionCount.NOTIFICATION_RECOMMEND_NETWORK);
verify(mNotificationManager).notify(anyInt(), any());
mNotificationController.handleWifiConnected();
@@ -449,6 +569,8 @@ public class OpenNetworkNotifierTest {
verify(mOpenNetworkRecommender).recommendNetwork(mOpenNetworks, mBlacklistedSsids);
// Initial Notification
verify(mNotificationBuilder).createConnectToNetworkNotification(mDummyNetwork);
+ verify(mWifiMetrics).incrementConnectToNetworkNotification(
+ ConnectToNetworkNotificationAndActionCount.NOTIFICATION_RECOMMEND_NETWORK);
verify(mNotificationManager).notify(anyInt(), any());
mBroadcastReceiver.onReceive(mContext,
@@ -456,12 +578,19 @@ public class OpenNetworkNotifierTest {
// Connecting Notification
verify(mNotificationBuilder).createNetworkConnectingNotification(mDummyNetwork);
+ verify(mWifiMetrics).incrementConnectToNetworkNotification(
+ ConnectToNetworkNotificationAndActionCount.NOTIFICATION_CONNECTING_TO_NETWORK);
+ verify(mWifiMetrics).incrementConnectToNetworkNotificationAction(
+ ConnectToNetworkNotificationAndActionCount.NOTIFICATION_RECOMMEND_NETWORK,
+ ConnectToNetworkNotificationAndActionCount.ACTION_CONNECT_TO_NETWORK);
verify(mNotificationManager, times(2)).notify(anyInt(), any());
mNotificationController.handleWifiConnected();
// Connected Notification
verify(mNotificationBuilder).createNetworkConnectedNotification(mDummyNetwork);
+ verify(mWifiMetrics).incrementConnectToNetworkNotification(
+ ConnectToNetworkNotificationAndActionCount.NOTIFICATION_CONNECTED_TO_NETWORK);
verify(mNotificationManager, times(3)).notify(anyInt(), any());
}
@@ -474,6 +603,8 @@ public class OpenNetworkNotifierTest {
mNotificationController.handleConnectionFailure();
verify(mNotificationManager, never()).notify(anyInt(), any());
+ verify(mWifiMetrics, never()).incrementConnectToNetworkNotification(
+ ConnectToNetworkNotificationAndActionCount.NOTIFICATION_FAILED_TO_CONNECT);
}
/**
@@ -487,6 +618,8 @@ public class OpenNetworkNotifierTest {
verify(mOpenNetworkRecommender).recommendNetwork(mOpenNetworks, mBlacklistedSsids);
// Initial Notification
verify(mNotificationBuilder).createConnectToNetworkNotification(mDummyNetwork);
+ verify(mWifiMetrics).incrementConnectToNetworkNotification(
+ ConnectToNetworkNotificationAndActionCount.NOTIFICATION_RECOMMEND_NETWORK);
verify(mNotificationManager).notify(anyInt(), any());
mBroadcastReceiver.onReceive(mContext,
@@ -494,12 +627,19 @@ public class OpenNetworkNotifierTest {
// Connecting Notification
verify(mNotificationBuilder).createNetworkConnectingNotification(mDummyNetwork);
+ verify(mWifiMetrics).incrementConnectToNetworkNotification(
+ ConnectToNetworkNotificationAndActionCount.NOTIFICATION_CONNECTING_TO_NETWORK);
+ verify(mWifiMetrics).incrementConnectToNetworkNotificationAction(
+ ConnectToNetworkNotificationAndActionCount.NOTIFICATION_RECOMMEND_NETWORK,
+ ConnectToNetworkNotificationAndActionCount.ACTION_CONNECT_TO_NETWORK);
verify(mNotificationManager, times(2)).notify(anyInt(), any());
mNotificationController.handleConnectionFailure();
// Failed to Connect Notification
verify(mNotificationBuilder).createNetworkFailedNotification();
+ verify(mWifiMetrics).incrementConnectToNetworkNotification(
+ ConnectToNetworkNotificationAndActionCount.NOTIFICATION_FAILED_TO_CONNECT);
verify(mNotificationManager, times(3)).notify(anyInt(), any());
}
@@ -515,6 +655,8 @@ public class OpenNetworkNotifierTest {
verify(mOpenNetworkRecommender).recommendNetwork(mOpenNetworks, mBlacklistedSsids);
// Initial Notification
verify(mNotificationBuilder).createConnectToNetworkNotification(mDummyNetwork);
+ verify(mWifiMetrics).incrementConnectToNetworkNotification(
+ ConnectToNetworkNotificationAndActionCount.NOTIFICATION_RECOMMEND_NETWORK);
verify(mNotificationManager).notify(anyInt(), any());
mBroadcastReceiver.onReceive(mContext,
@@ -526,6 +668,11 @@ public class OpenNetworkNotifierTest {
// Connecting Notification
verify(mNotificationBuilder).createNetworkConnectingNotification(mDummyNetwork);
+ verify(mWifiMetrics).incrementConnectToNetworkNotification(
+ ConnectToNetworkNotificationAndActionCount.NOTIFICATION_CONNECTING_TO_NETWORK);
+ verify(mWifiMetrics).incrementConnectToNetworkNotificationAction(
+ ConnectToNetworkNotificationAndActionCount.NOTIFICATION_RECOMMEND_NETWORK,
+ ConnectToNetworkNotificationAndActionCount.ACTION_CONNECT_TO_NETWORK);
verify(mNotificationManager, times(2)).notify(anyInt(), any());
Message connectFailedMsg = Message.obtain();
@@ -535,6 +682,9 @@ public class OpenNetworkNotifierTest {
// Failed to Connect Notification
verify(mNotificationBuilder).createNetworkFailedNotification();
+ verify(mWifiMetrics).incrementConnectToNetworkNotification(
+ ConnectToNetworkNotificationAndActionCount.NOTIFICATION_FAILED_TO_CONNECT);
+ verify(mWifiMetrics).incrementNumOpenNetworkConnectMessageFailedToSend();
verify(mNotificationManager, times(3)).notify(anyInt(), any());
mBroadcastReceiver.onReceive(mContext,
@@ -544,5 +694,9 @@ public class OpenNetworkNotifierTest {
ArgumentCaptor<Intent> pickerIntentCaptor = ArgumentCaptor.forClass(Intent.class);
verify(mContext).startActivity(pickerIntentCaptor.capture());
assertEquals(pickerIntentCaptor.getValue().getAction(), Settings.ACTION_WIFI_SETTINGS);
+ verify(mWifiMetrics).incrementConnectToNetworkNotificationAction(
+ ConnectToNetworkNotificationAndActionCount.NOTIFICATION_FAILED_TO_CONNECT,
+ ConnectToNetworkNotificationAndActionCount
+ .ACTION_PICK_WIFI_NETWORK_AFTER_CONNECT_FAILURE);
}
}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java
index 10ad3c620..65427beb2 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java
@@ -38,6 +38,7 @@ import com.android.server.wifi.hotspot2.PasspointManager;
import com.android.server.wifi.hotspot2.PasspointMatch;
import com.android.server.wifi.hotspot2.PasspointProvider;
import com.android.server.wifi.nano.WifiMetricsProto;
+import com.android.server.wifi.nano.WifiMetricsProto.ConnectToNetworkNotificationAndActionCount;
import com.android.server.wifi.nano.WifiMetricsProto.PnoScanMetrics;
import com.android.server.wifi.nano.WifiMetricsProto.StaEvent;
@@ -259,6 +260,19 @@ public class WifiMetricsTest {
private static final int NUM_PNO_SCAN_STARTED_OVER_OFFLOAD = 17;
private static final int NUM_PNO_SCAN_FAILED_OVER_OFFLOAD = 8;
private static final int NUM_PNO_FOUND_NETWORK_EVENTS = 10;
+ /** Number of notifications per "Connect to Network" notification type. */
+ private static final int[] NUM_CONNECT_TO_NETWORK_NOTIFICATIONS = {0, 10, 20, 30, 40};
+ /** Number of notifications per "Connect to Network notification type and action type. */
+ private static final int[][] NUM_CONNECT_TO_NETWORK_NOTIFICATION_ACTIONS = {
+ {0, 1, 2, 3, 4},
+ {10, 11, 12, 13, 14},
+ {20, 21, 22, 23, 24},
+ {30, 31, 32, 33, 34},
+ {40, 41, 42, 43, 44}};
+ private static final int SIZE_OPEN_NETWORK_RECOMMENDER_BLACKLIST = 10;
+ private static final boolean IS_WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON = true;
+ private static final int NUM_OPEN_NETWORK_CONNECT_MESSAGE_FAILED_TO_SEND = 5;
+ private static final int NUM_OPEN_NETWORK_RECOMMENDATION_UPDATES = 8;
private ScanDetail buildMockScanDetail(boolean hidden, NetworkDetail.HSRelease hSRelease,
String capabilities) {
@@ -498,6 +512,33 @@ public class WifiMetricsTest {
for (int i = 0; i < NUM_PNO_FOUND_NETWORK_EVENTS; i++) {
mWifiMetrics.incrementPnoFoundNetworkEventCount();
}
+
+ // set and increment "connect to network" notification metrics
+ for (int i = 0; i < NUM_CONNECT_TO_NETWORK_NOTIFICATIONS.length; i++) {
+ int count = NUM_CONNECT_TO_NETWORK_NOTIFICATIONS[i];
+ for (int j = 0; j < count; j++) {
+ mWifiMetrics.incrementConnectToNetworkNotification(i);
+ }
+ }
+ for (int i = 0; i < NUM_CONNECT_TO_NETWORK_NOTIFICATION_ACTIONS.length; i++) {
+ int[] actions = NUM_CONNECT_TO_NETWORK_NOTIFICATION_ACTIONS[i];
+ for (int j = 0; j < actions.length; j++) {
+ int count = actions[j];
+ for (int k = 0; k < count; k++) {
+ mWifiMetrics.incrementConnectToNetworkNotificationAction(i, j);
+ }
+ }
+ }
+ mWifiMetrics.setOpenNetworkRecommenderBlacklistSize(
+ SIZE_OPEN_NETWORK_RECOMMENDER_BLACKLIST);
+ mWifiMetrics.setIsWifiNetworksAvailableNotificationEnabled(
+ IS_WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON);
+ for (int i = 0; i < NUM_OPEN_NETWORK_RECOMMENDATION_UPDATES; i++) {
+ mWifiMetrics.incrementNumOpenNetworkRecommendationUpdates();
+ }
+ for (int i = 0; i < NUM_OPEN_NETWORK_CONNECT_MESSAGE_FAILED_TO_SEND; i++) {
+ mWifiMetrics.incrementNumOpenNetworkConnectMessageFailedToSend();
+ }
}
/**
@@ -650,6 +691,32 @@ public class WifiMetricsTest {
assertEquals(NUM_PNO_SCAN_STARTED_OVER_OFFLOAD, pno_metrics.numPnoScanStartedOverOffload);
assertEquals(NUM_PNO_SCAN_FAILED_OVER_OFFLOAD, pno_metrics.numPnoScanFailedOverOffload);
assertEquals(NUM_PNO_FOUND_NETWORK_EVENTS, pno_metrics.numPnoFoundNetworkEvents);
+
+ for (ConnectToNetworkNotificationAndActionCount notificationCount
+ : mDecodedProto.connectToNetworkNotificationCount) {
+ assertEquals(NUM_CONNECT_TO_NETWORK_NOTIFICATIONS[notificationCount.notification],
+ notificationCount.count);
+ assertEquals(ConnectToNetworkNotificationAndActionCount.RECOMMENDER_OPEN,
+ notificationCount.recommender);
+ }
+ for (ConnectToNetworkNotificationAndActionCount notificationActionCount
+ : mDecodedProto.connectToNetworkNotificationActionCount) {
+ assertEquals(NUM_CONNECT_TO_NETWORK_NOTIFICATION_ACTIONS
+ [notificationActionCount.notification]
+ [notificationActionCount.action],
+ notificationActionCount.count);
+ assertEquals(ConnectToNetworkNotificationAndActionCount.RECOMMENDER_OPEN,
+ notificationActionCount.recommender);
+ }
+
+ assertEquals(SIZE_OPEN_NETWORK_RECOMMENDER_BLACKLIST,
+ mDecodedProto.openNetworkRecommenderBlacklistSize);
+ assertEquals(IS_WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON,
+ mDecodedProto.isWifiNetworksAvailableNotificationOn);
+ assertEquals(NUM_OPEN_NETWORK_RECOMMENDATION_UPDATES,
+ mDecodedProto.numOpenNetworkRecommendationUpdates);
+ assertEquals(NUM_OPEN_NETWORK_CONNECT_MESSAGE_FAILED_TO_SEND,
+ mDecodedProto.numOpenNetworkConnectMessageFailedToSend);
}
/**
@@ -1203,6 +1270,39 @@ public class WifiMetricsTest {
a(WifiMetrics.MAX_CONNECTABLE_BSSID_NETWORK_BUCKET), a(1));
}
+ /**
+ * Test Open Network Notification blacklist size and feature state are not cleared when proto
+ * is dumped.
+ */
+ public void testOpenNetworkNotificationBlacklistSizeAndFeatureStateNotCleared()
+ throws Exception {
+ mWifiMetrics.setOpenNetworkRecommenderBlacklistSize(
+ SIZE_OPEN_NETWORK_RECOMMENDER_BLACKLIST);
+ mWifiMetrics.setIsWifiNetworksAvailableNotificationEnabled(
+ IS_WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON);
+ for (int i = 0; i < NUM_OPEN_NETWORK_RECOMMENDATION_UPDATES; i++) {
+ mWifiMetrics.incrementNumOpenNetworkRecommendationUpdates();
+ }
+
+ // This should clear most metrics in mWifiMetrics
+ dumpProtoAndDeserialize();
+ assertEquals(SIZE_OPEN_NETWORK_RECOMMENDER_BLACKLIST,
+ mDecodedProto.openNetworkRecommenderBlacklistSize);
+ assertEquals(IS_WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON,
+ mDecodedProto.isWifiNetworksAvailableNotificationOn);
+ assertEquals(NUM_OPEN_NETWORK_RECOMMENDATION_UPDATES,
+ mDecodedProto.numOpenNetworkRecommendationUpdates);
+
+ // Check that blacklist size and feature state persist on next dump but
+ // others do not.
+ dumpProtoAndDeserialize();
+ assertEquals(SIZE_OPEN_NETWORK_RECOMMENDER_BLACKLIST,
+ mDecodedProto.openNetworkRecommenderBlacklistSize);
+ assertEquals(IS_WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON,
+ mDecodedProto.isWifiNetworksAvailableNotificationOn);
+ assertEquals(0, mDecodedProto.numOpenNetworkRecommendationUpdates);
+ }
+
/** short hand for instantiating an anonymous int array, instead of 'new int[]{a1, a2, ...}' */
private int[] a(int... element) {
return element;