diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2019-04-24 21:58:09 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-04-24 21:58:09 +0000 |
commit | d04a29f8721e70ac1ae4e1aa82d18baa53bd8f97 (patch) | |
tree | 0fc435621249fc7a84d2e178fa748f107e3cfdde | |
parent | a7a78153b4fa396c3e735444cdef3bba87aeb4f7 (diff) | |
parent | 924467b1e35f0ad560207d1eb652e6e575f5fc22 (diff) |
Merge "Update the l2 and group hint identifiers for wifi network" into qt-dev
4 files changed, 62 insertions, 0 deletions
diff --git a/service/java/com/android/server/wifi/ClientModeImpl.java b/service/java/com/android/server/wifi/ClientModeImpl.java index 2ae6b4ed5..e7de1ca4f 100644 --- a/service/java/com/android/server/wifi/ClientModeImpl.java +++ b/service/java/com/android/server/wifi/ClientModeImpl.java @@ -2896,6 +2896,7 @@ public class ClientModeImpl extends StateMachine { mWifiInfo.setBSSID(null); mWifiInfo.setSSID(null); } + updateL2KeyAndGroupHint(); // SSID might have been updated, so call updateCapabilities updateCapabilities(); @@ -2930,6 +2931,25 @@ public class ClientModeImpl extends StateMachine { } /** + * Tells IpClient what L2Key and GroupHint to use for IpMemoryStore. + */ + private void updateL2KeyAndGroupHint() { + if (mIpClient != null) { + Pair<String, String> p = mWifiScoreCard.getL2KeyAndGroupHint(mWifiInfo); + if (!p.equals(mLastL2KeyAndGroupHint)) { + try { + mIpClient.setL2KeyAndGroupHint(p.first, p.second); + mLastL2KeyAndGroupHint = p; + } catch (RemoteException e) { + loge("Failed setL2KeyAndGroupHint"); + mLastL2KeyAndGroupHint = null; + } + } + } + } + private @Nullable Pair<String, String> mLastL2KeyAndGroupHint = null; + + /** * Resets the Wi-Fi Connections by clearing any state, resetting any sockets * using the interface, stopping DHCP & disabling interface */ @@ -2980,6 +3000,7 @@ public class ClientModeImpl extends StateMachine { registerDisconnected(); mLastNetworkId = WifiConfiguration.INVALID_NETWORK_ID; mWifiScoreCard.resetConnectionState(); + updateL2KeyAndGroupHint(); } void handlePreDhcpSetup() { diff --git a/service/java/com/android/server/wifi/WifiScoreCard.java b/service/java/com/android/server/wifi/WifiScoreCard.java index 850a20643..973c06dc9 100644 --- a/service/java/com/android/server/wifi/WifiScoreCard.java +++ b/service/java/com/android/server/wifi/WifiScoreCard.java @@ -155,6 +155,18 @@ public class WifiScoreCard { } /** + * Gets the L2Key and GroupHint associated with the connection. + */ + public @NonNull Pair<String, String> getL2KeyAndGroupHint(ExtendedWifiInfo wifiInfo) { + PerBssid perBssid = lookupBssid(wifiInfo.getSSID(), wifiInfo.getBSSID()); + if (perBssid == mDummyPerBssid) { + return new Pair<>(null, null); + } + final long groupIdHash = computeHashLong(perBssid.ssid, mDummyPerBssid.bssid); + return new Pair<>(perBssid.l2Key, groupHintFromLong(groupIdHash)); + } + + /** * Resets the connection state */ public void resetConnectionState() { @@ -611,6 +623,10 @@ public class WifiScoreCard { return "W" + Long.toHexString(hash); } + private static String groupHintFromLong(long hash) { + return "G" + Long.toHexString(hash); + } + @VisibleForTesting PerBssid fetchByBssid(MacAddress mac) { return mApForBssid.get(mac); diff --git a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java index 452dfa399..46fce6aa4 100644 --- a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java @@ -496,6 +496,7 @@ public class ClientModeImplTest { mOsuProvider = PasspointProvisioningTestUtil.generateOsuProvider(true); mConnectedNetwork = spy(WifiConfigurationTestUtil.createOpenNetwork()); when(mNullAsyncChannel.sendMessageSynchronously(any())).thenReturn(null); + when(mWifiScoreCard.getL2KeyAndGroupHint(any())).thenReturn(new Pair<>(null, null)); } private void registerAsyncChannel(Consumer<AsyncChannel> consumer, Messenger messenger) { @@ -2817,9 +2818,12 @@ public class ClientModeImplTest { */ @Test public void testScoreCardNoteConnectionComplete() throws Exception { + Pair<String, String> l2KeyAndGroupHint = Pair.create("Wad", "Gab"); + when(mWifiScoreCard.getL2KeyAndGroupHint(any())).thenReturn(l2KeyAndGroupHint); connect(); mLooper.dispatchAll(); verify(mWifiScoreCard).noteIpConfiguration(any()); + verify(mIpClient).setL2KeyAndGroupHint(eq("Wad"), eq("Gab")); } /** diff --git a/tests/wifitests/src/com/android/server/wifi/WifiScoreCardTest.java b/tests/wifitests/src/com/android/server/wifi/WifiScoreCardTest.java index 28aa180e9..577f5bc65 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiScoreCardTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiScoreCardTest.java @@ -25,6 +25,7 @@ import android.net.MacAddress; import android.net.wifi.WifiInfo; import android.net.wifi.WifiSsid; import android.util.Base64; +import android.util.Pair; import androidx.test.filters.SmallTest; @@ -124,6 +125,26 @@ public class WifiScoreCardTest { } /** + * Test identifiers. + */ + @Test + public void testIdentifiers() throws Exception { + mWifiInfo.setSSID(TEST_SSID_1); + mWifiInfo.setBSSID(TEST_BSSID_1.toString()); + Pair<String, String> p1 = mWifiScoreCard.getL2KeyAndGroupHint(mWifiInfo); + assertNotNull(p1.first); + assertNotNull(p1.second); + mWifiInfo.setBSSID(TEST_BSSID_2.toString()); + Pair<String, String> p2 = mWifiScoreCard.getL2KeyAndGroupHint(mWifiInfo); + assertNotEquals(p1.first, p2.first); + assertEquals(p1.second, p2.second); + mWifiInfo.setBSSID(null); + Pair<String, String> p3 = mWifiScoreCard.getL2KeyAndGroupHint(mWifiInfo); + assertNull(p3.first); + assertNull(p3.second); + } + + /** * Test rssi poll updates */ @Test |