Merge "WifiManager: allow setWifiApConfiguration to return false" into pi-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
9c2c8f5df6
@@ -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);
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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) { }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user