Christopher Wiley | 497c147 | 2016-10-11 13:26:03 -0700 | [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 | |
Erik Kline | ea9cc48 | 2017-03-10 19:35:34 +0900 | [diff] [blame] | 19 | import static org.junit.Assert.assertEquals; |
Christopher Wiley | 497c147 | 2016-10-11 13:26:03 -0700 | [diff] [blame] | 20 | import static org.junit.Assert.assertTrue; |
Erik Kline | ea9cc48 | 2017-03-10 19:35:34 +0900 | [diff] [blame] | 21 | import static org.mockito.Mockito.any; |
Christopher Wiley | 497c147 | 2016-10-11 13:26:03 -0700 | [diff] [blame] | 22 | import static org.mockito.Matchers.anyBoolean; |
Erik Kline | ea9cc48 | 2017-03-10 19:35:34 +0900 | [diff] [blame] | 23 | import static org.mockito.Matchers.anyInt; |
| 24 | import static org.mockito.Matchers.anyString; |
Christopher Wiley | 497c147 | 2016-10-11 13:26:03 -0700 | [diff] [blame] | 25 | import static org.mockito.Matchers.eq; |
Erik Kline | ea9cc48 | 2017-03-10 19:35:34 +0900 | [diff] [blame] | 26 | import static org.mockito.Mockito.atLeastOnce; |
| 27 | import static org.mockito.Mockito.times; |
| 28 | import static org.mockito.Mockito.verify; |
| 29 | import static org.mockito.Mockito.verifyNoMoreInteractions; |
Christopher Wiley | 497c147 | 2016-10-11 13:26:03 -0700 | [diff] [blame] | 30 | import static org.mockito.Mockito.when; |
| 31 | |
Erik Kline | 8351faa | 2017-04-17 16:47:23 +0900 | [diff] [blame^] | 32 | import android.content.BroadcastReceiver; |
Christopher Wiley | 497c147 | 2016-10-11 13:26:03 -0700 | [diff] [blame] | 33 | import android.content.Context; |
Erik Kline | ea9cc48 | 2017-03-10 19:35:34 +0900 | [diff] [blame] | 34 | import android.content.ContextWrapper; |
| 35 | import android.content.Intent; |
Erik Kline | 8351faa | 2017-04-17 16:47:23 +0900 | [diff] [blame^] | 36 | import android.content.IntentFilter; |
Christopher Wiley | 497c147 | 2016-10-11 13:26:03 -0700 | [diff] [blame] | 37 | import android.content.res.Resources; |
Erik Kline | ea9cc48 | 2017-03-10 19:35:34 +0900 | [diff] [blame] | 38 | import android.hardware.usb.UsbManager; |
| 39 | import android.net.ConnectivityManager; |
| 40 | import android.net.ConnectivityManager.NetworkCallback; |
Christopher Wiley | 497c147 | 2016-10-11 13:26:03 -0700 | [diff] [blame] | 41 | import android.net.INetworkPolicyManager; |
| 42 | import android.net.INetworkStatsService; |
Erik Kline | ea9cc48 | 2017-03-10 19:35:34 +0900 | [diff] [blame] | 43 | import android.net.InterfaceConfiguration; |
| 44 | import android.net.NetworkRequest; |
| 45 | import android.net.wifi.WifiConfiguration; |
| 46 | import android.net.wifi.WifiManager; |
| 47 | import android.os.Handler; |
Christopher Wiley | 497c147 | 2016-10-11 13:26:03 -0700 | [diff] [blame] | 48 | import android.os.INetworkManagementService; |
| 49 | import android.os.PersistableBundle; |
| 50 | import android.os.test.TestLooper; |
Erik Kline | ea9cc48 | 2017-03-10 19:35:34 +0900 | [diff] [blame] | 51 | import android.os.UserHandle; |
Christopher Wiley | 497c147 | 2016-10-11 13:26:03 -0700 | [diff] [blame] | 52 | import android.support.test.filters.SmallTest; |
| 53 | import android.support.test.runner.AndroidJUnit4; |
| 54 | import android.telephony.CarrierConfigManager; |
| 55 | |
Erik Kline | ea9cc48 | 2017-03-10 19:35:34 +0900 | [diff] [blame] | 56 | import com.android.internal.util.test.BroadcastInterceptingContext; |
| 57 | |
Erik Kline | 8351faa | 2017-04-17 16:47:23 +0900 | [diff] [blame^] | 58 | import org.junit.After; |
Christopher Wiley | 497c147 | 2016-10-11 13:26:03 -0700 | [diff] [blame] | 59 | import org.junit.Before; |
| 60 | import org.junit.Test; |
| 61 | import org.junit.runner.RunWith; |
| 62 | import org.mockito.Mock; |
| 63 | import org.mockito.MockitoAnnotations; |
| 64 | |
Erik Kline | 8351faa | 2017-04-17 16:47:23 +0900 | [diff] [blame^] | 65 | import java.util.ArrayList; |
| 66 | import java.util.Vector; |
| 67 | |
Christopher Wiley | 497c147 | 2016-10-11 13:26:03 -0700 | [diff] [blame] | 68 | @RunWith(AndroidJUnit4.class) |
| 69 | @SmallTest |
| 70 | public class TetheringTest { |
| 71 | private static final String[] PROVISIONING_APP_NAME = {"some", "app"}; |
| 72 | |
| 73 | @Mock private Context mContext; |
Erik Kline | ea9cc48 | 2017-03-10 19:35:34 +0900 | [diff] [blame] | 74 | @Mock private ConnectivityManager mConnectivityManager; |
Christopher Wiley | 497c147 | 2016-10-11 13:26:03 -0700 | [diff] [blame] | 75 | @Mock private INetworkManagementService mNMService; |
| 76 | @Mock private INetworkStatsService mStatsService; |
| 77 | @Mock private INetworkPolicyManager mPolicyManager; |
| 78 | @Mock private MockableSystemProperties mSystemProperties; |
| 79 | @Mock private Resources mResources; |
Erik Kline | ea9cc48 | 2017-03-10 19:35:34 +0900 | [diff] [blame] | 80 | @Mock private UsbManager mUsbManager; |
| 81 | @Mock private WifiManager mWifiManager; |
Christopher Wiley | 497c147 | 2016-10-11 13:26:03 -0700 | [diff] [blame] | 82 | @Mock private CarrierConfigManager mCarrierConfigManager; |
| 83 | |
| 84 | // Like so many Android system APIs, these cannot be mocked because it is marked final. |
| 85 | // We have to use the real versions. |
| 86 | private final PersistableBundle mCarrierConfig = new PersistableBundle(); |
| 87 | private final TestLooper mLooper = new TestLooper(); |
Erik Kline | ea9cc48 | 2017-03-10 19:35:34 +0900 | [diff] [blame] | 88 | private final String mTestIfname = "test_wlan0"; |
Christopher Wiley | 497c147 | 2016-10-11 13:26:03 -0700 | [diff] [blame] | 89 | |
Erik Kline | 8351faa | 2017-04-17 16:47:23 +0900 | [diff] [blame^] | 90 | private Vector<Intent> mIntents; |
Erik Kline | ea9cc48 | 2017-03-10 19:35:34 +0900 | [diff] [blame] | 91 | private BroadcastInterceptingContext mServiceContext; |
Erik Kline | 8351faa | 2017-04-17 16:47:23 +0900 | [diff] [blame^] | 92 | private BroadcastReceiver mBroadcastReceiver; |
Christopher Wiley | 497c147 | 2016-10-11 13:26:03 -0700 | [diff] [blame] | 93 | private Tethering mTethering; |
| 94 | |
Erik Kline | ea9cc48 | 2017-03-10 19:35:34 +0900 | [diff] [blame] | 95 | private class MockContext extends BroadcastInterceptingContext { |
| 96 | MockContext(Context base) { |
| 97 | super(base); |
| 98 | } |
| 99 | |
| 100 | @Override |
| 101 | public Resources getResources() { return mResources; } |
| 102 | |
| 103 | @Override |
| 104 | public Object getSystemService(String name) { |
| 105 | if (Context.CONNECTIVITY_SERVICE.equals(name)) return mConnectivityManager; |
| 106 | if (Context.WIFI_SERVICE.equals(name)) return mWifiManager; |
| 107 | return super.getSystemService(name); |
| 108 | } |
| 109 | } |
| 110 | |
Erik Kline | 8351faa | 2017-04-17 16:47:23 +0900 | [diff] [blame^] | 111 | @Before |
| 112 | public void setUp() throws Exception { |
Christopher Wiley | 497c147 | 2016-10-11 13:26:03 -0700 | [diff] [blame] | 113 | MockitoAnnotations.initMocks(this); |
Christopher Wiley | 497c147 | 2016-10-11 13:26:03 -0700 | [diff] [blame] | 114 | when(mResources.getStringArray(com.android.internal.R.array.config_tether_dhcp_range)) |
| 115 | .thenReturn(new String[0]); |
| 116 | when(mResources.getStringArray(com.android.internal.R.array.config_tether_usb_regexs)) |
| 117 | .thenReturn(new String[0]); |
| 118 | when(mResources.getStringArray(com.android.internal.R.array.config_tether_wifi_regexs)) |
Erik Kline | ea9cc48 | 2017-03-10 19:35:34 +0900 | [diff] [blame] | 119 | .thenReturn(new String[]{ "test_wlan\\d" }); |
Christopher Wiley | 497c147 | 2016-10-11 13:26:03 -0700 | [diff] [blame] | 120 | when(mResources.getStringArray(com.android.internal.R.array.config_tether_bluetooth_regexs)) |
| 121 | .thenReturn(new String[0]); |
| 122 | when(mResources.getIntArray(com.android.internal.R.array.config_tether_upstream_types)) |
| 123 | .thenReturn(new int[0]); |
Erik Kline | ea9cc48 | 2017-03-10 19:35:34 +0900 | [diff] [blame] | 124 | when(mNMService.listInterfaces()) |
| 125 | .thenReturn(new String[]{ "test_rmnet_data0", mTestIfname }); |
| 126 | when(mNMService.getInterfaceConfig(anyString())) |
| 127 | .thenReturn(new InterfaceConfiguration()); |
| 128 | |
| 129 | mServiceContext = new MockContext(mContext); |
Erik Kline | 8351faa | 2017-04-17 16:47:23 +0900 | [diff] [blame^] | 130 | mIntents = new Vector<>(); |
| 131 | mBroadcastReceiver = new BroadcastReceiver() { |
| 132 | @Override |
| 133 | public void onReceive(Context context, Intent intent) { |
| 134 | mIntents.addElement(intent); |
| 135 | } |
| 136 | }; |
| 137 | mServiceContext.registerReceiver(mBroadcastReceiver, |
| 138 | new IntentFilter(ConnectivityManager.ACTION_TETHER_STATE_CHANGED)); |
Erik Kline | ea9cc48 | 2017-03-10 19:35:34 +0900 | [diff] [blame] | 139 | mTethering = new Tethering(mServiceContext, mNMService, mStatsService, mPolicyManager, |
Christopher Wiley | 497c147 | 2016-10-11 13:26:03 -0700 | [diff] [blame] | 140 | mLooper.getLooper(), mSystemProperties); |
| 141 | } |
| 142 | |
Erik Kline | 8351faa | 2017-04-17 16:47:23 +0900 | [diff] [blame^] | 143 | @After |
| 144 | public void tearDown() { |
| 145 | mServiceContext.unregisterReceiver(mBroadcastReceiver); |
| 146 | } |
| 147 | |
Christopher Wiley | 497c147 | 2016-10-11 13:26:03 -0700 | [diff] [blame] | 148 | private void setupForRequiredProvisioning() { |
| 149 | // Produce some acceptable looking provision app setting if requested. |
| 150 | when(mResources.getStringArray( |
| 151 | com.android.internal.R.array.config_mobile_hotspot_provision_app)) |
| 152 | .thenReturn(PROVISIONING_APP_NAME); |
| 153 | // Don't disable tethering provisioning unless requested. |
| 154 | when(mSystemProperties.getBoolean(eq(Tethering.DISABLE_PROVISIONING_SYSPROP_KEY), |
| 155 | anyBoolean())).thenReturn(false); |
| 156 | // Act like the CarrierConfigManager is present and ready unless told otherwise. |
| 157 | when(mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE)) |
| 158 | .thenReturn(mCarrierConfigManager); |
| 159 | when(mCarrierConfigManager.getConfig()).thenReturn(mCarrierConfig); |
| 160 | mCarrierConfig.putBoolean(CarrierConfigManager.KEY_REQUIRE_ENTITLEMENT_CHECKS_BOOL, true); |
| 161 | } |
| 162 | |
| 163 | @Test |
| 164 | public void canRequireProvisioning() { |
| 165 | setupForRequiredProvisioning(); |
| 166 | assertTrue(mTethering.isTetherProvisioningRequired()); |
| 167 | } |
| 168 | |
| 169 | @Test |
| 170 | public void toleratesCarrierConfigManagerMissing() { |
| 171 | setupForRequiredProvisioning(); |
| 172 | when(mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE)) |
| 173 | .thenReturn(null); |
| 174 | // Couldn't get the CarrierConfigManager, but still had a declared provisioning app. |
| 175 | // We therefore still require provisioning. |
| 176 | assertTrue(mTethering.isTetherProvisioningRequired()); |
| 177 | } |
| 178 | |
| 179 | @Test |
| 180 | public void toleratesCarrierConfigMissing() { |
| 181 | setupForRequiredProvisioning(); |
| 182 | when(mCarrierConfigManager.getConfig()).thenReturn(null); |
| 183 | // We still have a provisioning app configured, so still require provisioning. |
| 184 | assertTrue(mTethering.isTetherProvisioningRequired()); |
| 185 | } |
| 186 | |
| 187 | @Test |
| 188 | public void provisioningNotRequiredWhenAppNotFound() { |
| 189 | setupForRequiredProvisioning(); |
| 190 | when(mResources.getStringArray( |
| 191 | com.android.internal.R.array.config_mobile_hotspot_provision_app)) |
| 192 | .thenReturn(null); |
| 193 | assertTrue(!mTethering.isTetherProvisioningRequired()); |
| 194 | when(mResources.getStringArray( |
| 195 | com.android.internal.R.array.config_mobile_hotspot_provision_app)) |
| 196 | .thenReturn(new String[] {"malformedApp"}); |
| 197 | assertTrue(!mTethering.isTetherProvisioningRequired()); |
| 198 | } |
Erik Kline | ea9cc48 | 2017-03-10 19:35:34 +0900 | [diff] [blame] | 199 | |
| 200 | private void sendWifiApStateChanged(int state) { |
| 201 | final Intent intent = new Intent(WifiManager.WIFI_AP_STATE_CHANGED_ACTION); |
| 202 | intent.putExtra(WifiManager.EXTRA_WIFI_AP_STATE, state); |
| 203 | mServiceContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); |
| 204 | } |
| 205 | |
Erik Kline | 8351faa | 2017-04-17 16:47:23 +0900 | [diff] [blame^] | 206 | private void verifyInterfaceServingModeStarted() throws Exception { |
| 207 | verify(mNMService, times(1)).listInterfaces(); |
| 208 | verify(mNMService, times(1)).getInterfaceConfig(mTestIfname); |
| 209 | verify(mNMService, times(1)) |
| 210 | .setInterfaceConfig(eq(mTestIfname), any(InterfaceConfiguration.class)); |
| 211 | verify(mNMService, times(1)).tetherInterface(mTestIfname); |
| 212 | } |
| 213 | |
| 214 | private void verifyTetheringBroadcast(String ifname, String whichExtra) { |
| 215 | // Verify that ifname is in the whichExtra array of the tether state changed broadcast. |
| 216 | final Intent bcast = mIntents.get(0); |
| 217 | assertEquals(ConnectivityManager.ACTION_TETHER_STATE_CHANGED, bcast.getAction()); |
| 218 | final ArrayList<String> ifnames = bcast.getStringArrayListExtra(whichExtra); |
| 219 | assertTrue(ifnames.contains(ifname)); |
| 220 | mIntents.remove(bcast); |
| 221 | } |
| 222 | |
Erik Kline | ea9cc48 | 2017-03-10 19:35:34 +0900 | [diff] [blame] | 223 | @Test |
| 224 | public void workingLocalOnlyHotspot() throws Exception { |
| 225 | when(mConnectivityManager.isTetheringSupported()).thenReturn(true); |
| 226 | when(mWifiManager.setWifiApEnabled(any(WifiConfiguration.class), anyBoolean())) |
| 227 | .thenReturn(true); |
| 228 | |
| 229 | // Emulate externally-visible WifiManager effects, causing the |
| 230 | // per-interface state machine to start up, and telling us that |
| 231 | // hotspot mode is to be started. |
| 232 | mTethering.interfaceStatusChanged(mTestIfname, true); |
| 233 | sendWifiApStateChanged(WifiManager.WIFI_AP_STATE_ENABLED); |
| 234 | mLooper.dispatchAll(); |
| 235 | |
Erik Kline | 8351faa | 2017-04-17 16:47:23 +0900 | [diff] [blame^] | 236 | verifyInterfaceServingModeStarted(); |
| 237 | verifyTetheringBroadcast(mTestIfname, ConnectivityManager.EXTRA_AVAILABLE_TETHER); |
Erik Kline | ea9cc48 | 2017-03-10 19:35:34 +0900 | [diff] [blame] | 238 | verify(mNMService, times(1)).setIpForwardingEnabled(true); |
| 239 | verify(mNMService, times(1)).startTethering(any(String[].class)); |
| 240 | verifyNoMoreInteractions(mNMService); |
Erik Kline | 8351faa | 2017-04-17 16:47:23 +0900 | [diff] [blame^] | 241 | verifyTetheringBroadcast(mTestIfname, ConnectivityManager.EXTRA_ACTIVE_LOCAL_ONLY); |
Erik Kline | ea9cc48 | 2017-03-10 19:35:34 +0900 | [diff] [blame] | 242 | // UpstreamNetworkMonitor will be started, and will register two callbacks: |
| 243 | // a "listen all" and a "track default". |
| 244 | verify(mConnectivityManager, times(1)).registerNetworkCallback( |
| 245 | any(NetworkRequest.class), any(NetworkCallback.class), any(Handler.class)); |
| 246 | verify(mConnectivityManager, times(1)).registerDefaultNetworkCallback( |
| 247 | any(NetworkCallback.class), any(Handler.class)); |
| 248 | // TODO: Figure out why this isn't exactly once, for sendTetherStateChangedBroadcast(). |
| 249 | verify(mConnectivityManager, atLeastOnce()).isTetheringSupported(); |
| 250 | verifyNoMoreInteractions(mConnectivityManager); |
| 251 | |
| 252 | // Emulate externally-visible WifiManager effects, when hotspot mode |
| 253 | // is being torn down. |
| 254 | sendWifiApStateChanged(WifiManager.WIFI_AP_STATE_DISABLED); |
| 255 | mTethering.interfaceRemoved(mTestIfname); |
| 256 | mLooper.dispatchAll(); |
| 257 | |
| 258 | verify(mNMService, times(1)).untetherInterface(mTestIfname); |
| 259 | // TODO: Why is {g,s}etInterfaceConfig() called more than once? |
| 260 | verify(mNMService, atLeastOnce()).getInterfaceConfig(mTestIfname); |
| 261 | verify(mNMService, atLeastOnce()) |
| 262 | .setInterfaceConfig(eq(mTestIfname), any(InterfaceConfiguration.class)); |
| 263 | verify(mNMService, times(1)).stopTethering(); |
| 264 | verify(mNMService, times(1)).setIpForwardingEnabled(false); |
| 265 | verifyNoMoreInteractions(mNMService); |
| 266 | // Asking for the last error after the per-interface state machine |
| 267 | // has been reaped yields an unknown interface error. |
| 268 | assertEquals(ConnectivityManager.TETHER_ERROR_UNKNOWN_IFACE, |
| 269 | mTethering.getLastTetherError(mTestIfname)); |
| 270 | } |
| 271 | |
| 272 | @Test |
| 273 | public void workingWifiTethering() throws Exception { |
| 274 | when(mConnectivityManager.isTetheringSupported()).thenReturn(true); |
| 275 | when(mWifiManager.setWifiApEnabled(any(WifiConfiguration.class), anyBoolean())) |
| 276 | .thenReturn(true); |
| 277 | |
| 278 | // Emulate pressing the WiFi tethering button. |
| 279 | mTethering.startTethering(ConnectivityManager.TETHERING_WIFI, null, false); |
| 280 | mLooper.dispatchAll(); |
| 281 | verify(mWifiManager, times(1)).setWifiApEnabled(null, true); |
| 282 | verifyNoMoreInteractions(mWifiManager); |
| 283 | verifyNoMoreInteractions(mConnectivityManager); |
| 284 | verifyNoMoreInteractions(mNMService); |
| 285 | |
| 286 | // Emulate externally-visible WifiManager effects, causing the |
| 287 | // per-interface state machine to start up, and telling us that |
| 288 | // tethering mode is to be started. |
| 289 | mTethering.interfaceStatusChanged(mTestIfname, true); |
| 290 | sendWifiApStateChanged(WifiManager.WIFI_AP_STATE_ENABLED); |
| 291 | mLooper.dispatchAll(); |
| 292 | |
Erik Kline | 8351faa | 2017-04-17 16:47:23 +0900 | [diff] [blame^] | 293 | verifyInterfaceServingModeStarted(); |
| 294 | verifyTetheringBroadcast(mTestIfname, ConnectivityManager.EXTRA_AVAILABLE_TETHER); |
Erik Kline | ea9cc48 | 2017-03-10 19:35:34 +0900 | [diff] [blame] | 295 | verify(mNMService, times(1)).setIpForwardingEnabled(true); |
| 296 | verify(mNMService, times(1)).startTethering(any(String[].class)); |
| 297 | verifyNoMoreInteractions(mNMService); |
Erik Kline | 8351faa | 2017-04-17 16:47:23 +0900 | [diff] [blame^] | 298 | verifyTetheringBroadcast(mTestIfname, ConnectivityManager.EXTRA_ACTIVE_TETHER); |
Erik Kline | ea9cc48 | 2017-03-10 19:35:34 +0900 | [diff] [blame] | 299 | // UpstreamNetworkMonitor will be started, and will register two callbacks: |
| 300 | // a "listen all" and a "track default". |
| 301 | verify(mConnectivityManager, times(1)).registerNetworkCallback( |
| 302 | any(NetworkRequest.class), any(NetworkCallback.class), any(Handler.class)); |
| 303 | verify(mConnectivityManager, times(1)).registerDefaultNetworkCallback( |
| 304 | any(NetworkCallback.class), any(Handler.class)); |
| 305 | // In tethering mode, in the default configuration, an explicit request |
| 306 | // for a mobile network is also made. |
| 307 | verify(mConnectivityManager, atLeastOnce()).getNetworkInfo(anyInt()); |
| 308 | verify(mConnectivityManager, times(1)).requestNetwork( |
| 309 | any(NetworkRequest.class), any(NetworkCallback.class), eq(0), anyInt(), |
| 310 | any(Handler.class)); |
| 311 | // TODO: Figure out why this isn't exactly once, for sendTetherStateChangedBroadcast(). |
| 312 | verify(mConnectivityManager, atLeastOnce()).isTetheringSupported(); |
| 313 | verifyNoMoreInteractions(mConnectivityManager); |
| 314 | |
| 315 | ///// |
| 316 | // We do not currently emulate any upstream being found. |
| 317 | // |
| 318 | // This is why there are no calls to verify mNMService.enableNat() or |
| 319 | // mNMService.startInterfaceForwarding(). |
| 320 | ///// |
| 321 | |
| 322 | // Emulate pressing the WiFi tethering button. |
| 323 | mTethering.stopTethering(ConnectivityManager.TETHERING_WIFI); |
| 324 | mLooper.dispatchAll(); |
| 325 | verify(mWifiManager, times(1)).setWifiApEnabled(null, false); |
| 326 | verifyNoMoreInteractions(mWifiManager); |
| 327 | verifyNoMoreInteractions(mConnectivityManager); |
| 328 | verifyNoMoreInteractions(mNMService); |
| 329 | |
| 330 | // Emulate externally-visible WifiManager effects, when tethering mode |
| 331 | // is being torn down. |
| 332 | sendWifiApStateChanged(WifiManager.WIFI_AP_STATE_DISABLED); |
| 333 | mTethering.interfaceRemoved(mTestIfname); |
| 334 | mLooper.dispatchAll(); |
| 335 | |
| 336 | verify(mNMService, times(1)).untetherInterface(mTestIfname); |
| 337 | // TODO: Why is {g,s}etInterfaceConfig() called more than once? |
| 338 | verify(mNMService, atLeastOnce()).getInterfaceConfig(mTestIfname); |
| 339 | verify(mNMService, atLeastOnce()) |
| 340 | .setInterfaceConfig(eq(mTestIfname), any(InterfaceConfiguration.class)); |
| 341 | verify(mNMService, times(1)).stopTethering(); |
| 342 | verify(mNMService, times(1)).setIpForwardingEnabled(false); |
| 343 | verifyNoMoreInteractions(mNMService); |
| 344 | // Asking for the last error after the per-interface state machine |
| 345 | // has been reaped yields an unknown interface error. |
| 346 | assertEquals(ConnectivityManager.TETHER_ERROR_UNKNOWN_IFACE, |
| 347 | mTethering.getLastTetherError(mTestIfname)); |
| 348 | } |
| 349 | |
| 350 | // TODO: Test that a request for hotspot mode doesn't interface with an |
| 351 | // already operating tethering mode interface. |
Christopher Wiley | 497c147 | 2016-10-11 13:26:03 -0700 | [diff] [blame] | 352 | } |