Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8cc4eb79 authored by Rebecca Silberstein's avatar Rebecca Silberstein
Browse files

WifiManager: setWifiApEnabled always returns false

The method setWifiApEnabled should not be used.  Introduction of the
start/stopTethering API left this call in an intermediate state, thus
introducing race conditions.  Callers with proper permissions should be
calling ConnectivityManager.startTethering or
WifiManager.startLocalOnlyHotspot.

Note: integration tests are being updated to reflect this change.

Bug: 38436732
Test: frameworks/base/wifi/tests/runtests.sh
Change-Id: I84b9514bf6bb67d733fd1a32492e0e0d485e2cd6
parent 1ba237d2
Loading
Loading
Loading
Loading
+12 −12
Original line number Diff line number Diff line
@@ -1763,25 +1763,25 @@ public class WifiManager {
    }

    /**
     * Start AccessPoint mode with the specified
     * configuration. If the radio is already running in
     * AP mode, update the new configuration
     * Note that starting in access point mode disables station
     * mode operation
     * This call will be deprecated and removed in an upcoming release.  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 true} if the operation succeeds, {@code false} otherwise
     * @return {@code false}
     *
     * @hide
     */
    @SystemApi
    public boolean setWifiApEnabled(WifiConfiguration wifiConfig, boolean enabled) {
        try {
            mService.setWifiApEnabled(wifiConfig, enabled);
            return true;
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
        String packageName = mContext.getOpPackageName();

        Log.w(TAG, packageName + " attempted call to setWifiApEnabled: enabled = " + enabled);
        return false;
    }

    /**
+9 −0
Original line number Diff line number Diff line
@@ -778,4 +778,13 @@ public class WifiManagerTest {
        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));
        verify(mWifiService, never()).setWifiApEnabled(any(), anyBoolean());
    }
}