Hugo Benichi | a43a095 | 2016-08-30 10:01:15 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016, The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.connectivity; |
| 18 | |
Hugo Benichi | 4a0c5d7 | 2017-10-11 11:26:25 +0900 | [diff] [blame] | 19 | import static org.junit.Assert.assertFalse; |
| 20 | import static org.junit.Assert.assertTrue; |
Hugo Benichi | a43a095 | 2016-08-30 10:01:15 +0900 | [diff] [blame] | 21 | import static org.mockito.Mockito.any; |
| 22 | import static org.mockito.Mockito.anyBoolean; |
| 23 | import static org.mockito.Mockito.anyInt; |
| 24 | import static org.mockito.Mockito.eq; |
| 25 | import static org.mockito.Mockito.never; |
Remi NGUYEN VAN | e67b0c3 | 2018-12-27 16:43:56 +0900 | [diff] [blame] | 26 | import static org.mockito.Mockito.reset; |
Hugo Benichi | a43a095 | 2016-08-30 10:01:15 +0900 | [diff] [blame] | 27 | import static org.mockito.Mockito.times; |
| 28 | import static org.mockito.Mockito.verify; |
| 29 | import static org.mockito.Mockito.when; |
| 30 | |
Hugo Benichi | 4a0c5d7 | 2017-10-11 11:26:25 +0900 | [diff] [blame] | 31 | import android.app.PendingIntent; |
| 32 | import android.content.Context; |
| 33 | import android.content.res.Resources; |
| 34 | import android.net.ConnectivityManager; |
Luke Huang | 6591477 | 2019-03-16 00:31:46 +0800 | [diff] [blame] | 35 | import android.net.IDnsResolver; |
Lorenzo Colitti | 9307ca2 | 2019-01-12 01:54:23 +0900 | [diff] [blame] | 36 | import android.net.INetd; |
Hugo Benichi | 4a0c5d7 | 2017-10-11 11:26:25 +0900 | [diff] [blame] | 37 | import android.net.Network; |
| 38 | import android.net.NetworkCapabilities; |
| 39 | import android.net.NetworkInfo; |
Lorenzo Colitti | 6654b08 | 2020-01-10 00:40:28 +0900 | [diff] [blame] | 40 | import android.net.NetworkProvider; |
Cody Kesting | 0d8d6ac | 2020-05-12 18:47:10 +0000 | [diff] [blame] | 41 | import android.os.Binder; |
Lorenzo Colitti | 9307ca2 | 2019-01-12 01:54:23 +0900 | [diff] [blame] | 42 | import android.os.INetworkManagementService; |
Hugo Benichi | 4a0c5d7 | 2017-10-11 11:26:25 +0900 | [diff] [blame] | 43 | import android.text.format.DateUtils; |
| 44 | |
Brett Chabot | 1ae2aa6 | 2019-03-04 14:14:56 -0800 | [diff] [blame] | 45 | import androidx.test.filters.SmallTest; |
| 46 | import androidx.test.runner.AndroidJUnit4; |
| 47 | |
Hugo Benichi | 4a0c5d7 | 2017-10-11 11:26:25 +0900 | [diff] [blame] | 48 | import com.android.internal.R; |
| 49 | import com.android.server.ConnectivityService; |
Hugo Benichi | 4a0c5d7 | 2017-10-11 11:26:25 +0900 | [diff] [blame] | 50 | import com.android.server.connectivity.NetworkNotificationManager.NotificationType; |
| 51 | |
Hugo Benichi | 4a0c5d7 | 2017-10-11 11:26:25 +0900 | [diff] [blame] | 52 | import org.junit.Before; |
| 53 | import org.junit.Test; |
Remi NGUYEN VAN | e67b0c3 | 2018-12-27 16:43:56 +0900 | [diff] [blame] | 54 | import org.junit.runner.RunWith; |
Hugo Benichi | 4a0c5d7 | 2017-10-11 11:26:25 +0900 | [diff] [blame] | 55 | import org.mockito.Mock; |
| 56 | import org.mockito.MockitoAnnotations; |
| 57 | |
| 58 | @RunWith(AndroidJUnit4.class) |
| 59 | @SmallTest |
| 60 | public class LingerMonitorTest { |
Hugo Benichi | a43a095 | 2016-08-30 10:01:15 +0900 | [diff] [blame] | 61 | static final String CELLULAR = "CELLULAR"; |
| 62 | static final String WIFI = "WIFI"; |
| 63 | |
Lorenzo Colitti | 84e6f123 | 2016-08-29 14:03:11 +0900 | [diff] [blame] | 64 | static final long LOW_RATE_LIMIT = DateUtils.MINUTE_IN_MILLIS; |
| 65 | static final long HIGH_RATE_LIMIT = 0; |
| 66 | |
| 67 | static final int LOW_DAILY_LIMIT = 2; |
| 68 | static final int HIGH_DAILY_LIMIT = 1000; |
| 69 | |
Hugo Benichi | a43a095 | 2016-08-30 10:01:15 +0900 | [diff] [blame] | 70 | LingerMonitor mMonitor; |
| 71 | |
| 72 | @Mock ConnectivityService mConnService; |
Luke Huang | 6591477 | 2019-03-16 00:31:46 +0800 | [diff] [blame] | 73 | @Mock IDnsResolver mDnsResolver; |
Lorenzo Colitti | 9307ca2 | 2019-01-12 01:54:23 +0900 | [diff] [blame] | 74 | @Mock INetd mNetd; |
| 75 | @Mock INetworkManagementService mNMS; |
Hugo Benichi | a43a095 | 2016-08-30 10:01:15 +0900 | [diff] [blame] | 76 | @Mock Context mCtx; |
Hugo Benichi | a43a095 | 2016-08-30 10:01:15 +0900 | [diff] [blame] | 77 | @Mock NetworkNotificationManager mNotifier; |
| 78 | @Mock Resources mResources; |
| 79 | |
Hugo Benichi | 4a0c5d7 | 2017-10-11 11:26:25 +0900 | [diff] [blame] | 80 | @Before |
Hugo Benichi | a43a095 | 2016-08-30 10:01:15 +0900 | [diff] [blame] | 81 | public void setUp() { |
| 82 | MockitoAnnotations.initMocks(this); |
| 83 | when(mCtx.getResources()).thenReturn(mResources); |
| 84 | when(mCtx.getPackageName()).thenReturn("com.android.server.connectivity"); |
Hugo Benichi | a43a095 | 2016-08-30 10:01:15 +0900 | [diff] [blame] | 85 | |
Lorenzo Colitti | 84e6f123 | 2016-08-29 14:03:11 +0900 | [diff] [blame] | 86 | mMonitor = new TestableLingerMonitor(mCtx, mNotifier, HIGH_DAILY_LIMIT, HIGH_RATE_LIMIT); |
Hugo Benichi | a43a095 | 2016-08-30 10:01:15 +0900 | [diff] [blame] | 87 | } |
| 88 | |
Hugo Benichi | 4a0c5d7 | 2017-10-11 11:26:25 +0900 | [diff] [blame] | 89 | @Test |
Hugo Benichi | a43a095 | 2016-08-30 10:01:15 +0900 | [diff] [blame] | 90 | public void testTransitions() { |
| 91 | setNotificationSwitch(transition(WIFI, CELLULAR)); |
| 92 | NetworkAgentInfo nai1 = wifiNai(100); |
| 93 | NetworkAgentInfo nai2 = cellNai(101); |
| 94 | |
| 95 | assertTrue(mMonitor.isNotificationEnabled(nai1, nai2)); |
| 96 | assertFalse(mMonitor.isNotificationEnabled(nai2, nai1)); |
| 97 | } |
| 98 | |
Hugo Benichi | 4a0c5d7 | 2017-10-11 11:26:25 +0900 | [diff] [blame] | 99 | @Test |
Hugo Benichi | a43a095 | 2016-08-30 10:01:15 +0900 | [diff] [blame] | 100 | public void testNotificationOnLinger() { |
| 101 | setNotificationSwitch(transition(WIFI, CELLULAR)); |
| 102 | setNotificationType(LingerMonitor.NOTIFY_TYPE_NOTIFICATION); |
| 103 | NetworkAgentInfo from = wifiNai(100); |
| 104 | NetworkAgentInfo to = cellNai(101); |
| 105 | |
| 106 | mMonitor.noteLingerDefaultNetwork(from, to); |
| 107 | verifyNotification(from, to); |
| 108 | } |
| 109 | |
Hugo Benichi | 4a0c5d7 | 2017-10-11 11:26:25 +0900 | [diff] [blame] | 110 | @Test |
Hugo Benichi | a43a095 | 2016-08-30 10:01:15 +0900 | [diff] [blame] | 111 | public void testToastOnLinger() { |
| 112 | setNotificationSwitch(transition(WIFI, CELLULAR)); |
| 113 | setNotificationType(LingerMonitor.NOTIFY_TYPE_TOAST); |
| 114 | NetworkAgentInfo from = wifiNai(100); |
| 115 | NetworkAgentInfo to = cellNai(101); |
| 116 | |
| 117 | mMonitor.noteLingerDefaultNetwork(from, to); |
| 118 | verifyToast(from, to); |
| 119 | } |
| 120 | |
Hugo Benichi | 4a0c5d7 | 2017-10-11 11:26:25 +0900 | [diff] [blame] | 121 | @Test |
Hugo Benichi | a43a095 | 2016-08-30 10:01:15 +0900 | [diff] [blame] | 122 | public void testNotificationClearedAfterDisconnect() { |
| 123 | setNotificationSwitch(transition(WIFI, CELLULAR)); |
| 124 | setNotificationType(LingerMonitor.NOTIFY_TYPE_NOTIFICATION); |
| 125 | NetworkAgentInfo from = wifiNai(100); |
| 126 | NetworkAgentInfo to = cellNai(101); |
| 127 | |
| 128 | mMonitor.noteLingerDefaultNetwork(from, to); |
| 129 | verifyNotification(from, to); |
| 130 | |
| 131 | mMonitor.noteDisconnect(to); |
| 132 | verify(mNotifier, times(1)).clearNotification(100); |
| 133 | } |
| 134 | |
Hugo Benichi | 4a0c5d7 | 2017-10-11 11:26:25 +0900 | [diff] [blame] | 135 | @Test |
Hugo Benichi | a43a095 | 2016-08-30 10:01:15 +0900 | [diff] [blame] | 136 | public void testNotificationClearedAfterSwitchingBack() { |
| 137 | setNotificationSwitch(transition(WIFI, CELLULAR)); |
| 138 | setNotificationType(LingerMonitor.NOTIFY_TYPE_NOTIFICATION); |
| 139 | NetworkAgentInfo from = wifiNai(100); |
| 140 | NetworkAgentInfo to = cellNai(101); |
| 141 | |
| 142 | mMonitor.noteLingerDefaultNetwork(from, to); |
| 143 | verifyNotification(from, to); |
| 144 | |
| 145 | mMonitor.noteLingerDefaultNetwork(to, from); |
| 146 | verify(mNotifier, times(1)).clearNotification(100); |
| 147 | } |
| 148 | |
Hugo Benichi | 4a0c5d7 | 2017-10-11 11:26:25 +0900 | [diff] [blame] | 149 | @Test |
Hugo Benichi | a43a095 | 2016-08-30 10:01:15 +0900 | [diff] [blame] | 150 | public void testUniqueToast() { |
| 151 | setNotificationSwitch(transition(WIFI, CELLULAR)); |
| 152 | setNotificationType(LingerMonitor.NOTIFY_TYPE_TOAST); |
| 153 | NetworkAgentInfo from = wifiNai(100); |
| 154 | NetworkAgentInfo to = cellNai(101); |
| 155 | |
| 156 | mMonitor.noteLingerDefaultNetwork(from, to); |
| 157 | verifyToast(from, to); |
| 158 | |
| 159 | mMonitor.noteLingerDefaultNetwork(to, from); |
| 160 | verify(mNotifier, times(1)).clearNotification(100); |
| 161 | |
Lorenzo Colitti | 84e6f123 | 2016-08-29 14:03:11 +0900 | [diff] [blame] | 162 | reset(mNotifier); |
Hugo Benichi | a43a095 | 2016-08-30 10:01:15 +0900 | [diff] [blame] | 163 | mMonitor.noteLingerDefaultNetwork(from, to); |
Lorenzo Colitti | 84e6f123 | 2016-08-29 14:03:11 +0900 | [diff] [blame] | 164 | verifyNoNotifications(); |
| 165 | } |
| 166 | |
Hugo Benichi | 4a0c5d7 | 2017-10-11 11:26:25 +0900 | [diff] [blame] | 167 | @Test |
Lorenzo Colitti | 84e6f123 | 2016-08-29 14:03:11 +0900 | [diff] [blame] | 168 | public void testMultipleNotifications() { |
| 169 | setNotificationSwitch(transition(WIFI, CELLULAR)); |
| 170 | setNotificationType(LingerMonitor.NOTIFY_TYPE_NOTIFICATION); |
| 171 | NetworkAgentInfo wifi1 = wifiNai(100); |
| 172 | NetworkAgentInfo wifi2 = wifiNai(101); |
| 173 | NetworkAgentInfo cell = cellNai(102); |
| 174 | |
| 175 | mMonitor.noteLingerDefaultNetwork(wifi1, cell); |
| 176 | verifyNotification(wifi1, cell); |
| 177 | |
| 178 | mMonitor.noteLingerDefaultNetwork(cell, wifi2); |
| 179 | verify(mNotifier, times(1)).clearNotification(100); |
| 180 | |
| 181 | reset(mNotifier); |
| 182 | mMonitor.noteLingerDefaultNetwork(wifi2, cell); |
| 183 | verifyNotification(wifi2, cell); |
| 184 | } |
| 185 | |
Hugo Benichi | 4a0c5d7 | 2017-10-11 11:26:25 +0900 | [diff] [blame] | 186 | @Test |
Lorenzo Colitti | 84e6f123 | 2016-08-29 14:03:11 +0900 | [diff] [blame] | 187 | public void testRateLimiting() throws InterruptedException { |
| 188 | mMonitor = new TestableLingerMonitor(mCtx, mNotifier, HIGH_DAILY_LIMIT, LOW_RATE_LIMIT); |
| 189 | |
| 190 | setNotificationSwitch(transition(WIFI, CELLULAR)); |
| 191 | setNotificationType(LingerMonitor.NOTIFY_TYPE_NOTIFICATION); |
| 192 | NetworkAgentInfo wifi1 = wifiNai(100); |
| 193 | NetworkAgentInfo wifi2 = wifiNai(101); |
| 194 | NetworkAgentInfo wifi3 = wifiNai(102); |
| 195 | NetworkAgentInfo cell = cellNai(103); |
| 196 | |
| 197 | mMonitor.noteLingerDefaultNetwork(wifi1, cell); |
| 198 | verifyNotification(wifi1, cell); |
| 199 | reset(mNotifier); |
| 200 | |
| 201 | Thread.sleep(50); |
| 202 | mMonitor.noteLingerDefaultNetwork(cell, wifi2); |
| 203 | mMonitor.noteLingerDefaultNetwork(wifi2, cell); |
| 204 | verifyNoNotifications(); |
| 205 | |
| 206 | Thread.sleep(50); |
| 207 | mMonitor.noteLingerDefaultNetwork(cell, wifi3); |
| 208 | mMonitor.noteLingerDefaultNetwork(wifi3, cell); |
| 209 | verifyNoNotifications(); |
| 210 | } |
| 211 | |
Hugo Benichi | 4a0c5d7 | 2017-10-11 11:26:25 +0900 | [diff] [blame] | 212 | @Test |
Lorenzo Colitti | 84e6f123 | 2016-08-29 14:03:11 +0900 | [diff] [blame] | 213 | public void testDailyLimiting() throws InterruptedException { |
| 214 | mMonitor = new TestableLingerMonitor(mCtx, mNotifier, LOW_DAILY_LIMIT, HIGH_RATE_LIMIT); |
| 215 | |
| 216 | setNotificationSwitch(transition(WIFI, CELLULAR)); |
| 217 | setNotificationType(LingerMonitor.NOTIFY_TYPE_NOTIFICATION); |
| 218 | NetworkAgentInfo wifi1 = wifiNai(100); |
| 219 | NetworkAgentInfo wifi2 = wifiNai(101); |
| 220 | NetworkAgentInfo wifi3 = wifiNai(102); |
| 221 | NetworkAgentInfo cell = cellNai(103); |
| 222 | |
| 223 | mMonitor.noteLingerDefaultNetwork(wifi1, cell); |
| 224 | verifyNotification(wifi1, cell); |
| 225 | reset(mNotifier); |
| 226 | |
| 227 | Thread.sleep(50); |
| 228 | mMonitor.noteLingerDefaultNetwork(cell, wifi2); |
| 229 | mMonitor.noteLingerDefaultNetwork(wifi2, cell); |
| 230 | verifyNotification(wifi2, cell); |
| 231 | reset(mNotifier); |
| 232 | |
| 233 | Thread.sleep(50); |
| 234 | mMonitor.noteLingerDefaultNetwork(cell, wifi3); |
| 235 | mMonitor.noteLingerDefaultNetwork(wifi3, cell); |
| 236 | verifyNoNotifications(); |
Hugo Benichi | a43a095 | 2016-08-30 10:01:15 +0900 | [diff] [blame] | 237 | } |
| 238 | |
Hugo Benichi | 4a0c5d7 | 2017-10-11 11:26:25 +0900 | [diff] [blame] | 239 | @Test |
Hugo Benichi | a43a095 | 2016-08-30 10:01:15 +0900 | [diff] [blame] | 240 | public void testUniqueNotification() { |
| 241 | setNotificationSwitch(transition(WIFI, CELLULAR)); |
| 242 | setNotificationType(LingerMonitor.NOTIFY_TYPE_NOTIFICATION); |
| 243 | NetworkAgentInfo from = wifiNai(100); |
| 244 | NetworkAgentInfo to = cellNai(101); |
| 245 | |
| 246 | mMonitor.noteLingerDefaultNetwork(from, to); |
| 247 | verifyNotification(from, to); |
| 248 | |
| 249 | mMonitor.noteLingerDefaultNetwork(to, from); |
| 250 | verify(mNotifier, times(1)).clearNotification(100); |
| 251 | |
| 252 | mMonitor.noteLingerDefaultNetwork(from, to); |
| 253 | verifyNotification(from, to); |
| 254 | } |
| 255 | |
Hugo Benichi | 4a0c5d7 | 2017-10-11 11:26:25 +0900 | [diff] [blame] | 256 | @Test |
Lorenzo Colitti | 84e6f123 | 2016-08-29 14:03:11 +0900 | [diff] [blame] | 257 | public void testIgnoreNeverValidatedNetworks() { |
Hugo Benichi | a43a095 | 2016-08-30 10:01:15 +0900 | [diff] [blame] | 258 | setNotificationType(LingerMonitor.NOTIFY_TYPE_TOAST); |
| 259 | setNotificationSwitch(transition(WIFI, CELLULAR)); |
| 260 | NetworkAgentInfo from = wifiNai(100); |
| 261 | NetworkAgentInfo to = cellNai(101); |
| 262 | from.everValidated = false; |
| 263 | |
| 264 | mMonitor.noteLingerDefaultNetwork(from, to); |
| 265 | verifyNoNotifications(); |
| 266 | } |
| 267 | |
Hugo Benichi | 4a0c5d7 | 2017-10-11 11:26:25 +0900 | [diff] [blame] | 268 | @Test |
Lorenzo Colitti | 84e6f123 | 2016-08-29 14:03:11 +0900 | [diff] [blame] | 269 | public void testIgnoreCurrentlyValidatedNetworks() { |
| 270 | setNotificationType(LingerMonitor.NOTIFY_TYPE_TOAST); |
| 271 | setNotificationSwitch(transition(WIFI, CELLULAR)); |
| 272 | NetworkAgentInfo from = wifiNai(100); |
| 273 | NetworkAgentInfo to = cellNai(101); |
| 274 | from.lastValidated = true; |
| 275 | |
| 276 | mMonitor.noteLingerDefaultNetwork(from, to); |
| 277 | verifyNoNotifications(); |
| 278 | } |
| 279 | |
Hugo Benichi | 4a0c5d7 | 2017-10-11 11:26:25 +0900 | [diff] [blame] | 280 | @Test |
Hugo Benichi | a43a095 | 2016-08-30 10:01:15 +0900 | [diff] [blame] | 281 | public void testNoNotificationType() { |
| 282 | setNotificationType(LingerMonitor.NOTIFY_TYPE_TOAST); |
| 283 | setNotificationSwitch(); |
| 284 | NetworkAgentInfo from = wifiNai(100); |
| 285 | NetworkAgentInfo to = cellNai(101); |
| 286 | |
| 287 | mMonitor.noteLingerDefaultNetwork(from, to); |
| 288 | verifyNoNotifications(); |
| 289 | } |
| 290 | |
Hugo Benichi | 4a0c5d7 | 2017-10-11 11:26:25 +0900 | [diff] [blame] | 291 | @Test |
Hugo Benichi | a43a095 | 2016-08-30 10:01:15 +0900 | [diff] [blame] | 292 | public void testNoTransitionToNotify() { |
| 293 | setNotificationType(LingerMonitor.NOTIFY_TYPE_NONE); |
| 294 | setNotificationSwitch(transition(WIFI, CELLULAR)); |
| 295 | NetworkAgentInfo from = wifiNai(100); |
| 296 | NetworkAgentInfo to = cellNai(101); |
| 297 | |
| 298 | mMonitor.noteLingerDefaultNetwork(from, to); |
| 299 | verifyNoNotifications(); |
| 300 | } |
| 301 | |
Hugo Benichi | 4a0c5d7 | 2017-10-11 11:26:25 +0900 | [diff] [blame] | 302 | @Test |
Hugo Benichi | a43a095 | 2016-08-30 10:01:15 +0900 | [diff] [blame] | 303 | public void testDifferentTransitionToNotify() { |
| 304 | setNotificationType(LingerMonitor.NOTIFY_TYPE_TOAST); |
| 305 | setNotificationSwitch(transition(CELLULAR, WIFI)); |
| 306 | NetworkAgentInfo from = wifiNai(100); |
| 307 | NetworkAgentInfo to = cellNai(101); |
| 308 | |
| 309 | mMonitor.noteLingerDefaultNetwork(from, to); |
| 310 | verifyNoNotifications(); |
| 311 | } |
| 312 | |
| 313 | void setNotificationSwitch(String... transitions) { |
| 314 | when(mResources.getStringArray(R.array.config_networkNotifySwitches)) |
| 315 | .thenReturn(transitions); |
| 316 | } |
| 317 | |
| 318 | String transition(String from, String to) { |
| 319 | return from + "-" + to; |
| 320 | } |
| 321 | |
| 322 | void setNotificationType(int type) { |
| 323 | when(mResources.getInteger(R.integer.config_networkNotifySwitchType)).thenReturn(type); |
| 324 | } |
| 325 | |
| 326 | void verifyNoToast() { |
| 327 | verify(mNotifier, never()).showToast(any(), any()); |
| 328 | } |
| 329 | |
| 330 | void verifyNoNotification() { |
| 331 | verify(mNotifier, never()) |
| 332 | .showNotification(anyInt(), any(), any(), any(), any(), anyBoolean()); |
| 333 | } |
| 334 | |
| 335 | void verifyNoNotifications() { |
| 336 | verifyNoToast(); |
| 337 | verifyNoNotification(); |
Hugo Benichi | a43a095 | 2016-08-30 10:01:15 +0900 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | void verifyToast(NetworkAgentInfo from, NetworkAgentInfo to) { |
| 341 | verifyNoNotification(); |
| 342 | verify(mNotifier, times(1)).showToast(from, to); |
| 343 | } |
| 344 | |
| 345 | void verifyNotification(NetworkAgentInfo from, NetworkAgentInfo to) { |
| 346 | verifyNoToast(); |
| 347 | verify(mNotifier, times(1)).showNotification(eq(from.network.netId), |
| 348 | eq(NotificationType.NETWORK_SWITCH), eq(from), eq(to), any(), eq(true)); |
| 349 | } |
| 350 | |
| 351 | NetworkAgentInfo nai(int netId, int transport, int networkType, String networkTypeName) { |
| 352 | NetworkInfo info = new NetworkInfo(networkType, 0, networkTypeName, ""); |
| 353 | NetworkCapabilities caps = new NetworkCapabilities(); |
| 354 | caps.addCapability(0); |
| 355 | caps.addTransportType(transport); |
| 356 | NetworkAgentInfo nai = new NetworkAgentInfo(null, null, new Network(netId), info, null, |
Automerger Merge Worker | 3d40f578 | 2020-03-08 06:07:47 +0000 | [diff] [blame] | 357 | caps, 50, mCtx, null, null /* config */, mConnService, mNetd, mDnsResolver, mNMS, |
Cody Kesting | 0d8d6ac | 2020-05-12 18:47:10 +0000 | [diff] [blame] | 358 | NetworkProvider.ID_NONE, Binder.getCallingUid()); |
Hugo Benichi | a43a095 | 2016-08-30 10:01:15 +0900 | [diff] [blame] | 359 | nai.everValidated = true; |
| 360 | return nai; |
| 361 | } |
| 362 | |
| 363 | NetworkAgentInfo wifiNai(int netId) { |
| 364 | return nai(netId, NetworkCapabilities.TRANSPORT_WIFI, |
| 365 | ConnectivityManager.TYPE_WIFI, WIFI); |
| 366 | } |
| 367 | |
| 368 | NetworkAgentInfo cellNai(int netId) { |
| 369 | return nai(netId, NetworkCapabilities.TRANSPORT_CELLULAR, |
| 370 | ConnectivityManager.TYPE_MOBILE, CELLULAR); |
| 371 | } |
| 372 | |
| 373 | public static class TestableLingerMonitor extends LingerMonitor { |
Lorenzo Colitti | 84e6f123 | 2016-08-29 14:03:11 +0900 | [diff] [blame] | 374 | public TestableLingerMonitor(Context c, NetworkNotificationManager n, int l, long r) { |
| 375 | super(c, n, l, r); |
Hugo Benichi | a43a095 | 2016-08-30 10:01:15 +0900 | [diff] [blame] | 376 | } |
| 377 | @Override protected PendingIntent createNotificationIntent() { |
| 378 | return null; |
| 379 | } |
| 380 | } |
| 381 | } |