diff options
author | Roshan Pius <rpius@google.com> | 2020-01-27 13:03:22 -0800 |
---|---|---|
committer | Roshan Pius <rpius@google.com> | 2020-01-28 07:55:59 -0800 |
commit | b1e532d28ebdbb4778b20dcfd152b61558fb8d53 (patch) | |
tree | f60c46a664fca70fba551a1a3e78e2766170887c | |
parent | 7ccb386789f1442878ea2e1be079079a3af9d390 (diff) |
WifiServiceImpl: Move the feature set overrides to WifiServiceImpl
ClientModeImpl's supported feature set logic is only needed to wrap the
native call, the rest of the feature set modifications based on overlays
(& HalDeviceManager interactions in the next CL) can be done in
WifiServiceImpl.
Bug: 141452146
Test: atest com.android.server.wifi
Change-Id: I4a55ab529c2ac18f56630c654c9c1800d477e33e
4 files changed, 115 insertions, 121 deletions
diff --git a/service/java/com/android/server/wifi/ClientModeImpl.java b/service/java/com/android/server/wifi/ClientModeImpl.java index 09cc46493..ae67a37c7 100644 --- a/service/java/com/android/server/wifi/ClientModeImpl.java +++ b/service/java/com/android/server/wifi/ClientModeImpl.java @@ -1638,30 +1638,6 @@ public class ClientModeImpl extends StateMachine { if (messageIsNull(resultMsg)) return 0; long supportedFeatureSet = ((Long) resultMsg.obj).longValue(); resultMsg.recycle(); - - // Mask the feature set against system properties. - boolean rttSupported = mContext.getPackageManager().hasSystemFeature( - PackageManager.FEATURE_WIFI_RTT); - if (!rttSupported) { - // flags filled in by vendor HAL, remove if overlay disables it. - supportedFeatureSet &= - ~(WifiManager.WIFI_FEATURE_D2D_RTT | WifiManager.WIFI_FEATURE_D2AP_RTT); - } - if (!mContext.getResources().getBoolean( - R.bool.config_wifi_p2p_mac_randomization_supported)) { - // flags filled in by vendor HAL, remove if overlay disables it. - supportedFeatureSet &= ~WifiManager.WIFI_FEATURE_P2P_RAND_MAC; - } - if (mContext.getResources().getBoolean( - R.bool.config_wifi_connected_mac_randomization_supported)) { - // no corresponding flags in vendor HAL, set if overlay enables it. - supportedFeatureSet |= WifiManager.WIFI_FEATURE_CONNECTED_RAND_MAC; - } - if (mContext.getResources().getBoolean( - R.bool.config_wifi_ap_mac_randomization_supported)) { - // no corresponding flags in vendor HAL, set if overlay enables it. - supportedFeatureSet |= WifiManager.WIFI_FEATURE_AP_RAND_MAC; - } return supportedFeatureSet; } diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java index 1b67f24df..f5524dc56 100644 --- a/service/java/com/android/server/wifi/WifiServiceImpl.java +++ b/service/java/com/android/server/wifi/WifiServiceImpl.java @@ -3620,12 +3620,37 @@ public class WifiServiceImpl extends BaseWifiService { private long getSupportedFeaturesInternal() { final AsyncChannel channel = mClientModeImplChannel; + long supportedFeatureSet = 0L; if (channel != null) { - return mClientModeImpl.syncGetSupportedFeatures(channel); + supportedFeatureSet = mClientModeImpl.syncGetSupportedFeatures(channel); } else { Log.e(TAG, "mClientModeImplChannel is not initialized"); - return 0; - } + return supportedFeatureSet; + } + // Mask the feature set against system properties. + boolean rttSupported = mContext.getPackageManager().hasSystemFeature( + PackageManager.FEATURE_WIFI_RTT); + if (!rttSupported) { + // flags filled in by vendor HAL, remove if overlay disables it. + supportedFeatureSet &= + ~(WifiManager.WIFI_FEATURE_D2D_RTT | WifiManager.WIFI_FEATURE_D2AP_RTT); + } + if (!mContext.getResources().getBoolean( + R.bool.config_wifi_p2p_mac_randomization_supported)) { + // flags filled in by vendor HAL, remove if overlay disables it. + supportedFeatureSet &= ~WifiManager.WIFI_FEATURE_P2P_RAND_MAC; + } + if (mContext.getResources().getBoolean( + R.bool.config_wifi_connected_mac_randomization_supported)) { + // no corresponding flags in vendor HAL, set if overlay enables it. + supportedFeatureSet |= WifiManager.WIFI_FEATURE_CONNECTED_RAND_MAC; + } + if (mContext.getResources().getBoolean( + R.bool.config_wifi_ap_mac_randomization_supported)) { + // no corresponding flags in vendor HAL, set if overlay enables it. + supportedFeatureSet |= WifiManager.WIFI_FEATURE_AP_RAND_MAC; + } + return supportedFeatureSet; } private static boolean hasAutomotiveFeature(Context context) { diff --git a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java index 8e326d3f2..06e88bbe3 100644 --- a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java @@ -1937,100 +1937,6 @@ public class ClientModeImplTest extends WifiBaseTest { .count()); } - private long testGetSupportedFeaturesCaseForRtt(long supportedFeatures, boolean rttDisabled) { - AsyncChannel channel = mock(AsyncChannel.class); - Message reply = Message.obtain(); - reply.obj = Long.valueOf(supportedFeatures); - reset(mPropertyService); // Ignore calls made in setUp() - when(channel.sendMessageSynchronously(ClientModeImpl.CMD_GET_SUPPORTED_FEATURES)) - .thenReturn(reply); - - // ugly, this is set to true by default in setup. - mResources.setBoolean(R.bool.config_wifi_connected_mac_randomization_supported, false); - when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_WIFI_RTT)).thenReturn( - !rttDisabled); - return mCmi.syncGetSupportedFeatures(channel); - } - - /** Verifies that syncGetSupportedFeatures() masks out capabilities based on system flags. */ - @Test - public void syncGetSupportedFeaturesForRtt() { - final long featureAware = WifiManager.WIFI_FEATURE_AWARE; - final long featureInfra = WifiManager.WIFI_FEATURE_INFRA; - final long featureD2dRtt = WifiManager.WIFI_FEATURE_D2D_RTT; - final long featureD2apRtt = WifiManager.WIFI_FEATURE_D2AP_RTT; - final long featureLongBits = 0x1000000000L; - - assertEquals(0, testGetSupportedFeaturesCaseForRtt(0, false)); - assertEquals(0, testGetSupportedFeaturesCaseForRtt(0, true)); - assertEquals(featureAware | featureInfra, - testGetSupportedFeaturesCaseForRtt(featureAware | featureInfra, false)); - assertEquals(featureAware | featureInfra, - testGetSupportedFeaturesCaseForRtt(featureAware | featureInfra, true)); - assertEquals(featureInfra | featureD2dRtt, - testGetSupportedFeaturesCaseForRtt(featureInfra | featureD2dRtt, false)); - assertEquals(featureInfra, - testGetSupportedFeaturesCaseForRtt(featureInfra | featureD2dRtt, true)); - assertEquals(featureInfra | featureD2apRtt, - testGetSupportedFeaturesCaseForRtt(featureInfra | featureD2apRtt, false)); - assertEquals(featureInfra, - testGetSupportedFeaturesCaseForRtt(featureInfra | featureD2apRtt, true)); - assertEquals(featureInfra | featureD2dRtt | featureD2apRtt, - testGetSupportedFeaturesCaseForRtt( - featureInfra | featureD2dRtt | featureD2apRtt, false)); - assertEquals(featureInfra, - testGetSupportedFeaturesCaseForRtt( - featureInfra | featureD2dRtt | featureD2apRtt, true)); - - assertEquals(featureLongBits | featureInfra | featureD2dRtt | featureD2apRtt, - testGetSupportedFeaturesCaseForRtt( - featureLongBits | featureInfra | featureD2dRtt | featureD2apRtt, false)); - assertEquals(featureLongBits | featureInfra, - testGetSupportedFeaturesCaseForRtt( - featureLongBits | featureInfra | featureD2dRtt | featureD2apRtt, true)); - } - - private long testGetSupportedFeaturesCaseForMacRandomization( - long supportedFeatures, boolean apMacRandomizationEnabled, - boolean staConnectedMacRandomizationEnabled, boolean p2pMacRandomizationEnabled) { - AsyncChannel channel = mock(AsyncChannel.class); - Message reply = Message.obtain(); - reply.obj = Long.valueOf(supportedFeatures); - reset(mPropertyService); // Ignore calls made in setUp() - when(channel.sendMessageSynchronously(ClientModeImpl.CMD_GET_SUPPORTED_FEATURES)) - .thenReturn(reply); - - mResources.setBoolean(R.bool.config_wifi_connected_mac_randomization_supported, - staConnectedMacRandomizationEnabled); - mResources.setBoolean(R.bool.config_wifi_ap_mac_randomization_supported, - apMacRandomizationEnabled); - mResources.setBoolean(R.bool.config_wifi_p2p_mac_randomization_supported, - p2pMacRandomizationEnabled); - return mCmi.syncGetSupportedFeatures(channel); - } - - /** Verifies that syncGetSupportedFeatures() masks out capabilities based on system flags. */ - @Test - public void syncGetSupportedFeaturesForMacRandomization() { - final long featureStaConnectedMacRandomization = - WifiManager.WIFI_FEATURE_CONNECTED_RAND_MAC; - final long featureApMacRandomization = - WifiManager.WIFI_FEATURE_AP_RAND_MAC; - final long featureP2pMacRandomization = - WifiManager.WIFI_FEATURE_CONNECTED_RAND_MAC; - - assertEquals(featureStaConnectedMacRandomization | featureApMacRandomization - | featureP2pMacRandomization, - testGetSupportedFeaturesCaseForMacRandomization( - featureP2pMacRandomization, true, true, true)); - // p2p supported by HAL, but disabled by overlay. - assertEquals(featureStaConnectedMacRandomization | featureApMacRandomization, - testGetSupportedFeaturesCaseForMacRandomization( - featureP2pMacRandomization, true, true, false)); - assertEquals(featureStaConnectedMacRandomization | featureApMacRandomization, - testGetSupportedFeaturesCaseForMacRandomization(0, true, true, false)); - } - /** * Verify that syncStartSubscriptionProvisioning will redirect calls with right parameters * to {@link PasspointManager} with expected true being returned when in client mode. diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java index 51106c285..ec7eeb614 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java @@ -5414,4 +5414,91 @@ public class WifiServiceImplTest extends WifiBaseTest { mLooper.dispatchAll(); verify(mWifiScoreReport).clearWifiConnectedNetworkScorer(); } + + private long testGetSupportedFeaturesCaseForRtt( + long supportedFeaturesFromClientModeImpl, boolean rttDisabled) { + when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_WIFI_RTT)).thenReturn( + !rttDisabled); + when(mClientModeImpl.syncGetSupportedFeatures(any())) + .thenReturn(supportedFeaturesFromClientModeImpl); + return mWifiServiceImpl.getSupportedFeatures(); + } + + /** Verifies that syncGetSupportedFeatures() masks out capabilities based on system flags. */ + @Test + public void syncGetSupportedFeaturesForRtt() { + final long featureAware = WifiManager.WIFI_FEATURE_AWARE; + final long featureInfra = WifiManager.WIFI_FEATURE_INFRA; + final long featureD2dRtt = WifiManager.WIFI_FEATURE_D2D_RTT; + final long featureD2apRtt = WifiManager.WIFI_FEATURE_D2AP_RTT; + final long featureLongBits = 0x1000000000L; + + assertEquals(0, testGetSupportedFeaturesCaseForRtt(0, false)); + assertEquals(0, testGetSupportedFeaturesCaseForRtt(0, true)); + assertEquals(featureAware | featureInfra, + testGetSupportedFeaturesCaseForRtt(featureAware | featureInfra, false)); + assertEquals(featureAware | featureInfra, + testGetSupportedFeaturesCaseForRtt(featureAware | featureInfra, true)); + assertEquals(featureInfra | featureD2dRtt, + testGetSupportedFeaturesCaseForRtt(featureInfra | featureD2dRtt, false)); + assertEquals(featureInfra, + testGetSupportedFeaturesCaseForRtt(featureInfra | featureD2dRtt, true)); + assertEquals(featureInfra | featureD2apRtt, + testGetSupportedFeaturesCaseForRtt(featureInfra | featureD2apRtt, false)); + assertEquals(featureInfra, + testGetSupportedFeaturesCaseForRtt(featureInfra | featureD2apRtt, true)); + assertEquals(featureInfra | featureD2dRtt | featureD2apRtt, + testGetSupportedFeaturesCaseForRtt( + featureInfra | featureD2dRtt | featureD2apRtt, false)); + assertEquals(featureInfra, + testGetSupportedFeaturesCaseForRtt( + featureInfra | featureD2dRtt | featureD2apRtt, true)); + + assertEquals(featureLongBits | featureInfra | featureD2dRtt | featureD2apRtt, + testGetSupportedFeaturesCaseForRtt( + featureLongBits | featureInfra | featureD2dRtt | featureD2apRtt, false)); + assertEquals(featureLongBits | featureInfra, + testGetSupportedFeaturesCaseForRtt( + featureLongBits | featureInfra | featureD2dRtt | featureD2apRtt, true)); + } + + private long testGetSupportedFeaturesCaseForMacRandomization( + long supportedFeaturesFromClientModeImpl, boolean apMacRandomizationEnabled, + boolean staConnectedMacRandomizationEnabled, boolean p2pMacRandomizationEnabled) { + when(mResources.getBoolean( + R.bool.config_wifi_connected_mac_randomization_supported)) + .thenReturn(staConnectedMacRandomizationEnabled); + when(mResources.getBoolean( + R.bool.config_wifi_ap_mac_randomization_supported)) + .thenReturn(apMacRandomizationEnabled); + when(mResources.getBoolean( + R.bool.config_wifi_p2p_mac_randomization_supported)) + .thenReturn(p2pMacRandomizationEnabled); + when(mClientModeImpl.syncGetSupportedFeatures( + any())).thenReturn(supportedFeaturesFromClientModeImpl); + return mWifiServiceImpl.getSupportedFeatures(); + } + + /** Verifies that syncGetSupportedFeatures() masks out capabilities based on system flags. */ + @Test + public void syncGetSupportedFeaturesForMacRandomization() { + final long featureStaConnectedMacRandomization = + WifiManager.WIFI_FEATURE_CONNECTED_RAND_MAC; + final long featureApMacRandomization = + WifiManager.WIFI_FEATURE_AP_RAND_MAC; + final long featureP2pMacRandomization = + WifiManager.WIFI_FEATURE_CONNECTED_RAND_MAC; + + assertEquals(featureStaConnectedMacRandomization | featureApMacRandomization + | featureP2pMacRandomization, + testGetSupportedFeaturesCaseForMacRandomization( + featureP2pMacRandomization, true, true, true)); + // p2p supported by HAL, but disabled by overlay. + assertEquals(featureStaConnectedMacRandomization | featureApMacRandomization, + testGetSupportedFeaturesCaseForMacRandomization( + featureP2pMacRandomization, true, true, false)); + assertEquals(featureStaConnectedMacRandomization | featureApMacRandomization, + testGetSupportedFeaturesCaseForMacRandomization(0, true, true, false)); + } + } |