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

Commit cf1b40fb authored by Rebecca Silberstein's avatar Rebecca Silberstein
Browse files

WifiManager: allow setWifiApConfiguration to return false

The api for setWifiApConfiguration allows for config saves to return
false, but the implementation always returns true (if there wasn't an
exception thrown).  This CL allows the API to actually return false and
adds unittests.

Bug: 67601382
Test: frameworks/base/wifi/tests/runtests.sh
Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh
Test: manually update ap config in settings and verify save
Test: wifi integration tests
Change-Id: I038ab68f5fc4bf22df5b61d329077eacda547338
parent 8b08d548
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -143,7 +143,7 @@ interface IWifiManager

    WifiConfiguration getWifiApConfiguration();

    void setWifiApConfiguration(in WifiConfiguration wifiConfig, String packageName);
    boolean setWifiApConfiguration(in WifiConfiguration wifiConfig, String packageName);

    Messenger getWifiServiceMessenger(String packageName);

+3 −3
Original line number Diff line number Diff line
@@ -2141,7 +2141,8 @@ public class WifiManager {
    }

    /**
     * Sets the Wi-Fi AP Configuration.
     * Sets the Wi-Fi AP Configuration.  The AP configuration must either be open or
     * WPA2 PSK networks.
     * @return {@code true} if the operation succeeded, {@code false} otherwise
     *
     * @hide
@@ -2150,8 +2151,7 @@ public class WifiManager {
    @RequiresPermission(android.Manifest.permission.CHANGE_WIFI_STATE)
    public boolean setWifiApConfiguration(WifiConfiguration wifiConfig) {
        try {
            mService.setWifiApConfiguration(wifiConfig, mContext.getOpPackageName());
            return true;
            return mService.setWifiApConfiguration(wifiConfig, mContext.getOpPackageName());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+36 −0
Original line number Diff line number Diff line
@@ -1034,4 +1034,40 @@ i * Verify that a call to cancel WPS immediately returns a failure.
        verifyNoMoreInteractions(mWifiService);
    }

    /**
     * Verify that a successful call properly returns true.
     */
    @Test
    public void testSetWifiApConfigurationSuccessReturnsTrue() throws Exception {
        WifiConfiguration apConfig = new WifiConfiguration();

        when(mWifiService.setWifiApConfiguration(eq(apConfig), eq(TEST_PACKAGE_NAME)))
                .thenReturn(true);
        assertTrue(mWifiManager.setWifiApConfiguration(apConfig));
    }

    /**
     * Verify that a failed call properly returns false.
     */
    @Test
    public void testSetWifiApConfigurationFailureReturnsFalse() throws Exception {
        WifiConfiguration apConfig = new WifiConfiguration();

        when(mWifiService.setWifiApConfiguration(eq(apConfig), eq(TEST_PACKAGE_NAME)))
                .thenReturn(false);
        assertFalse(mWifiManager.setWifiApConfiguration(apConfig));
    }

    /**
     * Verify Exceptions are rethrown when underlying calls to WifiService throw exceptions.
     */
    @Test
    public void testSetWifiApConfigurationRethrowsException() throws Exception {
        doThrow(new SecurityException()).when(mWifiService).setWifiApConfiguration(any(), any());

        try {
            mWifiManager.setWifiApConfiguration(new WifiConfiguration());
            fail("setWifiApConfiguration should rethrow Exceptions from WifiService");
        } catch (SecurityException e) { }
    }
}