From 51c53a9428883bbbd9530bb8aa4c07a0787544bb Mon Sep 17 00:00:00 2001 From: Rebecca Silberstein Date: Thu, 28 Sep 2017 15:09:47 -0700 Subject: [PATCH] WifiManager: delete the setWifiApEnabled method Delete the @removed setWifiApEnabled call along with any remaining callers. Bug: 66917593 Bug: 26753849 Test: frameworks/base/wifi/tests/runtests.sh Change-Id: Ieefc59e01d801d9f5a943830c66c86e9e624158c --- api/system-removed.txt | 1 - .../ConnectivityManagerStressTestRunner.java | 11 +- .../ConnectivityManagerTestBase.java | 6 - .../ConnectivityManagerUnitTestRunner.java | 2 - .../stress/WifiApStress.java | 125 ------------------ .../unit/WifiSoftAPTest.java | 78 ----------- .../policy/NetworkControllerImpl.java | 7 - wifi/java/android/net/wifi/WifiManager.java | 26 ---- .../src/android/net/wifi/WifiManagerTest.java | 9 -- 9 files changed, 1 insertion(+), 264 deletions(-) delete mode 100644 core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/stress/WifiApStress.java delete mode 100644 core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/unit/WifiSoftAPTest.java diff --git a/api/system-removed.txt b/api/system-removed.txt index 639877fae6e22..e9afa701c7559 100644 --- a/api/system-removed.txt +++ b/api/system-removed.txt @@ -330,7 +330,6 @@ package android.net.wifi { method public deprecated java.util.List getBatchedScanResults(); method public android.net.wifi.WifiConnectionStatistics getConnectionStatistics(); method public deprecated boolean isBatchedScanSupported(); - method public deprecated boolean setWifiApEnabled(android.net.wifi.WifiConfiguration, boolean); method public deprecated boolean startLocationRestrictedScan(android.os.WorkSource); } diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerStressTestRunner.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerStressTestRunner.java index fbaf0f324ab14..0806fa0b98796 100644 --- a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerStressTestRunner.java +++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerStressTestRunner.java @@ -20,7 +20,6 @@ import android.os.Bundle; import android.test.InstrumentationTestRunner; import android.test.InstrumentationTestSuite; -import com.android.connectivitymanagertest.stress.WifiApStress; import com.android.connectivitymanagertest.stress.WifiStressTest; import junit.framework.TestSuite; @@ -35,7 +34,7 @@ import junit.framework.TestSuite; */ public class ConnectivityManagerStressTestRunner extends InstrumentationTestRunner { - private int mSoftApIterations = 100; + private int mSoftApIterations = 0; private int mScanIterations = 100; private int mReconnectIterations = 100; // sleep time before restart wifi, default is set to 2 minutes @@ -47,7 +46,6 @@ public class ConnectivityManagerStressTestRunner extends InstrumentationTestRunn @Override public TestSuite getAllTests() { TestSuite suite = new InstrumentationTestSuite(this); - suite.addTestSuite(WifiApStress.class); suite.addTestSuite(WifiStressTest.class); return suite; } @@ -60,13 +58,6 @@ public class ConnectivityManagerStressTestRunner extends InstrumentationTestRunn @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); - String valueStr = icicle.getString("softap_iterations"); - if (valueStr != null) { - int iteration = Integer.parseInt(valueStr); - if (iteration > 0) { - mSoftApIterations = iteration; - } - } String scanIterationStr = icicle.getString("scan_iterations"); if (scanIterationStr != null) { diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestBase.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestBase.java index 64fed7f77176d..3706e4b3d8e80 100644 --- a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestBase.java +++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestBase.java @@ -129,12 +129,6 @@ public class ConnectivityManagerTestBase extends InstrumentationTestCase { // Get an instance of WifiManager mWifiManager =(WifiManager)mContext.getSystemService(Context.WIFI_SERVICE); - if (mWifiManager.isWifiApEnabled()) { - // if soft AP is enabled, disable it - mWifiManager.setWifiApEnabled(null, false); - logv("Disable soft ap"); - } - // register a connectivity receiver for CONNECTIVITY_ACTION; mConnectivityReceiver = new ConnectivityReceiver(); mContext.registerReceiver(mConnectivityReceiver, diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerUnitTestRunner.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerUnitTestRunner.java index 0e57a006eed02..746cb841da663 100644 --- a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerUnitTestRunner.java +++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerUnitTestRunner.java @@ -19,7 +19,6 @@ package com.android.connectivitymanagertest; import android.test.InstrumentationTestRunner; import android.test.InstrumentationTestSuite; import com.android.connectivitymanagertest.unit.WifiClientTest; -import com.android.connectivitymanagertest.unit.WifiSoftAPTest; import junit.framework.TestSuite; @@ -35,7 +34,6 @@ public class ConnectivityManagerUnitTestRunner extends InstrumentationTestRunner public TestSuite getAllTests() { TestSuite suite = new InstrumentationTestSuite(this); suite.addTestSuite(WifiClientTest.class); - suite.addTestSuite(WifiSoftAPTest.class); return suite; } diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/stress/WifiApStress.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/stress/WifiApStress.java deleted file mode 100644 index de934b9c9d82b..0000000000000 --- a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/stress/WifiApStress.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (C) 2010, 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.connectivitymanagertest.stress; - - -import android.net.wifi.WifiConfiguration; -import android.net.wifi.WifiConfiguration.AuthAlgorithm; -import android.net.wifi.WifiConfiguration.KeyMgmt; -import android.net.wifi.WifiManager; -import android.os.Environment; -import android.test.suitebuilder.annotation.LargeTest; - -import com.android.connectivitymanagertest.ConnectivityManagerStressTestRunner; -import com.android.connectivitymanagertest.ConnectivityManagerTestBase; - -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; - -/** - * Stress test setting up device as wifi hotspot - */ -public class WifiApStress extends ConnectivityManagerTestBase { - private static String NETWORK_ID = "AndroidAPTest"; - private static String PASSWD = "androidwifi"; - private final static String OUTPUT_FILE = "WifiStressTestOutput.txt"; - private int mTotalIterations; - private BufferedWriter mOutputWriter = null; - private int mLastIteration = 0; - private boolean mWifiOnlyFlag; - - public WifiApStress() { - super(WifiApStress.class.getSimpleName()); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - ConnectivityManagerStressTestRunner mRunner = - (ConnectivityManagerStressTestRunner)getInstrumentation(); - mTotalIterations = mRunner.getSoftApInterations(); - mWifiOnlyFlag = mRunner.isWifiOnly(); - turnScreenOn(); - } - - @Override - protected void tearDown() throws Exception { - // write the total number of iterations into output file - mOutputWriter = new BufferedWriter(new FileWriter(new File( - Environment.getExternalStorageDirectory(), OUTPUT_FILE))); - mOutputWriter.write(String.format("iteration %d out of %d\n", - mLastIteration + 1, mTotalIterations)); - mOutputWriter.flush(); - mOutputWriter.close(); - super.tearDown(); - } - - @LargeTest - public void testWifiHotSpot() { - if (mWifiOnlyFlag) { - logv(getName() + " is excluded for wi-fi only test"); - return; - } - WifiConfiguration config = new WifiConfiguration(); - config.SSID = NETWORK_ID; - config.allowedKeyManagement.set(KeyMgmt.WPA_PSK); - config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN); - config.preSharedKey = PASSWD; - - // if wifiap enabled, disable it - assertTrue("failed to disable wifi hotspot", - mWifiManager.setWifiApEnabled(config, false)); - assertTrue("wifi hotspot not enabled", waitForWifiApState( - WifiManager.WIFI_AP_STATE_DISABLED, 2 * LONG_TIMEOUT)); - - // if Wifi is enabled, disable it - if (mWifiManager.isWifiEnabled()) { - assertTrue("failed to disable wifi", disableWifi()); - // wait for the wifi state to be DISABLED - assertTrue("wifi state not disabled", waitForWifiState( - WifiManager.WIFI_STATE_DISABLED, LONG_TIMEOUT)); - } - int i; - for (i = 0; i < mTotalIterations; i++) { - logv("iteration: " + i); - mLastIteration = i; - // enable Wifi tethering - assertTrue("failed to enable wifi hotspot", - mWifiManager.setWifiApEnabled(config, true)); - // wait for wifi ap state to be ENABLED - assertTrue("wifi hotspot not enabled", waitForWifiApState( - WifiManager.WIFI_AP_STATE_ENABLED, 2 * LONG_TIMEOUT)); - // wait for wifi tethering result - assertTrue("tether state not changed", waitForTetherStateChange(LONG_TIMEOUT)); - // allow the wifi tethering to be enabled for 10 seconds - try { - Thread.sleep(2 * SHORT_TIMEOUT); - } catch (Exception e) { - // ignore - } - assertTrue("no uplink data connection after Wi-Fi tethering", pingTest()); - // disable wifi hotspot - assertTrue("failed to disable wifi hotspot", - mWifiManager.setWifiApEnabled(config, false)); - assertTrue("wifi hotspot not enabled", waitForWifiApState( - WifiManager.WIFI_AP_STATE_DISABLED, 2 * LONG_TIMEOUT)); - assertFalse("wifi hotspot still enabled", mWifiManager.isWifiApEnabled()); - } - } - -} diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/unit/WifiSoftAPTest.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/unit/WifiSoftAPTest.java deleted file mode 100644 index f202862f6dbf4..0000000000000 --- a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/unit/WifiSoftAPTest.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) 2010 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.connectivitymanagertest.unit; - -import android.content.Context; -import android.net.wifi.WifiManager; -import android.net.wifi.WifiConfiguration; -import android.net.wifi.WifiConfiguration.KeyMgmt; - -import android.test.suitebuilder.annotation.LargeTest; -import android.test.AndroidTestCase; - -import android.util.Log; - -/** - * Test Wifi soft AP configuration - */ -public class WifiSoftAPTest extends AndroidTestCase { - - private WifiManager mWifiManager; - private WifiConfiguration mWifiConfig = null; - private final String TAG = "WifiSoftAPTest"; - private final int DURATION = 10000; - - @Override - protected void setUp() throws Exception { - super.setUp(); - mWifiManager = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE); - assertNotNull(mWifiManager); - assertTrue(mWifiManager.setWifiApEnabled(null, true)); - mWifiConfig = mWifiManager.getWifiApConfiguration(); - if (mWifiConfig != null) { - Log.v(TAG, "mWifiConfig is " + mWifiConfig.toString()); - } else { - Log.v(TAG, "mWifiConfig is null."); - } - } - - @Override - protected void tearDown() throws Exception { - Log.v(TAG, "turn off wifi tethering"); - mWifiManager.setWifiApEnabled(null, false); - super.tearDown(); - } - - // Test case 1: Test the soft AP SSID with letters - @LargeTest - public void testApSsidWithAlphabet() { - WifiConfiguration config = new WifiConfiguration(); - config.SSID = "abcdefghijklmnopqrstuvwxyz"; - config.allowedKeyManagement.set(KeyMgmt.NONE); - mWifiConfig = config; - assertTrue(mWifiManager.setWifiApEnabled(mWifiConfig, true)); - try { - Thread.sleep(DURATION); - } catch (InterruptedException e) { - Log.v(TAG, "exception " + e.getStackTrace()); - assertFalse(true); - } - assertNotNull(mWifiManager.getWifiApConfiguration()); - assertEquals("wifi AP state is not enabled", WifiManager.WIFI_AP_STATE_ENABLED, - mWifiManager.getWifiApState()); - } -} diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java index d24e51c73151a..40ee8386e895b 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkControllerImpl.java @@ -382,13 +382,6 @@ public class NetworkControllerImpl extends BroadcastReceiver new AsyncTask() { @Override protected Void doInBackground(Void... args) { - // Disable tethering if enabling Wifi - final int wifiApState = mWifiManager.getWifiApState(); - if (enabled && ((wifiApState == WifiManager.WIFI_AP_STATE_ENABLING) || - (wifiApState == WifiManager.WIFI_AP_STATE_ENABLED))) { - mWifiManager.setWifiApEnabled(null, false); - } - mWifiManager.setWifiEnabled(enabled); return null; } diff --git a/wifi/java/android/net/wifi/WifiManager.java b/wifi/java/android/net/wifi/WifiManager.java index b08b4b7c71b6c..545d8253ef690 100644 --- a/wifi/java/android/net/wifi/WifiManager.java +++ b/wifi/java/android/net/wifi/WifiManager.java @@ -1856,32 +1856,6 @@ public class WifiManager { return rssiA - rssiB; } - /** - * This call is deprecated and removed. It is no longer used to - * start WiFi Tethering. Please use {@link ConnectivityManager#startTethering(int, boolean, - * ConnectivityManager#OnStartTetheringCallback)} if - * the caller has proper permissions. Callers can also use the LocalOnlyHotspot feature for a - * hotspot capable of communicating with co-located devices {@link - * WifiManager#startLocalOnlyHotspot(LocalOnlyHotspotCallback)}. - * - * @param wifiConfig SSID, security and channel details as - * part of WifiConfiguration - * @return {@code false} - * - * @hide - * @deprecated This API is nolonger supported. - * @removed - */ - @SystemApi - @Deprecated - @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED) - public boolean setWifiApEnabled(WifiConfiguration wifiConfig, boolean enabled) { - String packageName = mContext.getOpPackageName(); - - Log.w(TAG, packageName + " attempted call to setWifiApEnabled: enabled = " + enabled); - return false; - } - /** * Call allowing ConnectivityService to update WifiService with interface mode changes. * diff --git a/wifi/tests/src/android/net/wifi/WifiManagerTest.java b/wifi/tests/src/android/net/wifi/WifiManagerTest.java index 71ccc08f041a4..ee6f12b775a83 100644 --- a/wifi/tests/src/android/net/wifi/WifiManagerTest.java +++ b/wifi/tests/src/android/net/wifi/WifiManagerTest.java @@ -777,13 +777,4 @@ public class WifiManagerTest { mWifiManager.unregisterLocalOnlyHotspotObserver(); verify(mWifiService).stopWatchLocalOnlyHotspot(); } - - /** - * Verify that calls to setWifiApEnabled return false. - */ - @Test - public void testSetWifiApEnabledReturnsFalse() throws Exception { - assertFalse(mWifiManager.setWifiApEnabled(null, true)); - assertFalse(mWifiManager.setWifiApEnabled(null, false)); - } }