summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRebecca Silberstein <silberst@google.com>2018-05-25 16:33:38 -0700
committerRebecca Silberstein <silberst@google.com>2018-06-04 12:48:01 -0700
commitc14521bbc37a0e18c85c4f3baeadfbf70d569cec (patch)
tree62649001578c04f1d5a77b5df20a981dc3439f9e
parent4aef2aafbec238bd33c1f8d64c0ecf6134a55bb0 (diff)
WifiServiceImpl: system server side for apband conversion check
Add underlying impl for use of needs5GHzToAnyApBandConversion in WifiServiceImpl. Bug: 80251951 Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh Change-Id: I1bf6155fd729ef2d81ca5f6029eb61da2c6d09a3
-rw-r--r--service/java/com/android/server/wifi/WifiServiceImpl.java23
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java51
2 files changed, 72 insertions, 2 deletions
diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java
index e01266f2c..a0bbded9d 100644
--- a/service/java/com/android/server/wifi/WifiServiceImpl.java
+++ b/service/java/com/android/server/wifi/WifiServiceImpl.java
@@ -2182,15 +2182,33 @@ public class WifiServiceImpl extends IWifiManager.Stub {
@Override
public boolean isDualBandSupported() {
- //TODO: Should move towards adding a driver API that checks at runtime
+ //TODO (b/80552904): Should move towards adding a driver API that checks at runtime
if (mVerboseLoggingEnabled) {
mLog.info("isDualBandSupported uid=%").c(Binder.getCallingUid()).flush();
}
+
return mContext.getResources().getBoolean(
com.android.internal.R.bool.config_wifi_dual_band_support);
}
/**
+ * Method allowing callers with NETWORK_SETTINGS permission to check if this is a dual mode
+ * capable device (STA+AP).
+ *
+ * @return true if a dual mode capable device
+ */
+ @Override
+ public boolean needs5GHzToAnyApBandConversion() {
+ enforceNetworkSettingsPermission();
+
+ if (mVerboseLoggingEnabled) {
+ mLog.info("needs5GHzToAnyApBandConversion uid=%").c(Binder.getCallingUid()).flush();
+ }
+ return mContext.getResources().getBoolean(
+ com.android.internal.R.bool.config_wifi_convert_apband_5ghz_to_any);
+ }
+
+ /**
* Return the DHCP-assigned addresses from the last successful DHCP request,
* if any.
* @return the DHCP information
@@ -2209,7 +2227,8 @@ public class WifiServiceImpl extends IWifiManager.Stub {
if (dhcpResults.ipAddress != null &&
dhcpResults.ipAddress.getAddress() instanceof Inet4Address) {
- info.ipAddress = NetworkUtils.inetAddressToInt((Inet4Address) dhcpResults.ipAddress.getAddress());
+ info.ipAddress = NetworkUtils.inetAddressToInt(
+ (Inet4Address) dhcpResults.ipAddress.getAddress());
}
if (dhcpResults.gateway != null) {
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
index f3d967e73..6a248161c 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java
@@ -2739,6 +2739,57 @@ public class WifiServiceImplTest {
verify(mWifiStateMachine, never()).removeUserConfigs(userHandle);
}
+ /**
+ * Test for needs5GHzToAnyApBandConversion returns true. Requires the NETWORK_SETTINGS
+ * permission.
+ */
+ @Test
+ public void testNeeds5GHzToAnyApBandConversionReturnedTrue() {
+ when(mResources.getBoolean(
+ eq(com.android.internal.R.bool.config_wifi_convert_apband_5ghz_to_any)))
+ .thenReturn(true);
+ assertTrue(mWifiServiceImpl.needs5GHzToAnyApBandConversion());
+
+ verify(mContext).enforceCallingOrSelfPermission(
+ eq(android.Manifest.permission.NETWORK_SETTINGS), eq("WifiService"));
+ }
+
+ /**
+ * Test for needs5GHzToAnyApBandConversion returns false. Requires the NETWORK_SETTINGS
+ * permission.
+ */
+ @Test
+ public void testNeeds5GHzToAnyApBandConversionReturnedFalse() {
+ when(mResources.getBoolean(
+ eq(com.android.internal.R.bool.config_wifi_convert_apband_5ghz_to_any)))
+ .thenReturn(false);
+
+ assertFalse(mWifiServiceImpl.needs5GHzToAnyApBandConversion());
+
+ verify(mContext).enforceCallingOrSelfPermission(
+ eq(android.Manifest.permission.NETWORK_SETTINGS), eq("WifiService"));
+ }
+
+ /**
+ * The API impl for needs5GHzToAnyApBandConversion requires the NETWORK_SETTINGS permission,
+ * verify an exception is thrown without holding the permission.
+ */
+ @Test
+ public void testNeeds5GHzToAnyApBandConversionThrowsWithoutProperPermissions() {
+ doThrow(new SecurityException()).when(mContext)
+ .enforceCallingOrSelfPermission(eq(android.Manifest.permission.NETWORK_SETTINGS),
+ eq("WifiService"));
+
+ try {
+ mWifiServiceImpl.needs5GHzToAnyApBandConversion();
+ // should have thrown an exception - fail test
+ fail();
+ } catch (SecurityException e) {
+ // expected
+ }
+ }
+
+
private class IdleModeIntentMatcher implements ArgumentMatcher<IntentFilter> {
@Override
public boolean matches(IntentFilter filter) {