summaryrefslogtreecommitdiff
path: root/src/android/net/ip/IpClient.java
diff options
context:
space:
mode:
authorXiao Ma <xiaom@google.com>2020-04-16 05:56:41 +0000
committerXiao Ma <xiaom@google.com>2020-04-16 06:43:56 +0000
commit39cd852a2060a579a79db2740e52b2c7129a3845 (patch)
treea0715af2b78d2fb02b307513295ef03236c8b5c6 /src/android/net/ip/IpClient.java
parent9aef7f0ee06f4715e5e447303752f33656689d91 (diff)
Renew previous IP address when roaming happens in certain specific Wi-Fi networks.
Bug: 131797393 Test: atest NetworkStackTests NetworkStackIntegrationTests Test: atest FrameworksNetTests Merged-In: I65ebdd142a2bb402035c63cd282bc2574ddf3d8d Change-Id: I65ebdd142a2bb402035c63cd282bc2574ddf3d8d
Diffstat (limited to 'src/android/net/ip/IpClient.java')
-rw-r--r--src/android/net/ip/IpClient.java72
1 files changed, 68 insertions, 4 deletions
diff --git a/src/android/net/ip/IpClient.java b/src/android/net/ip/IpClient.java
index 9ad2c78..4ddcc13 100644
--- a/src/android/net/ip/IpClient.java
+++ b/src/android/net/ip/IpClient.java
@@ -32,6 +32,7 @@ import android.net.Layer2InformationParcelable;
import android.net.Layer2PacketParcelable;
import android.net.LinkAddress;
import android.net.LinkProperties;
+import android.net.MacAddress;
import android.net.NattKeepalivePacketDataParcelable;
import android.net.NetworkStackIpMemoryStore;
import android.net.ProvisioningConfigurationParcelable;
@@ -92,6 +93,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
@@ -381,7 +383,8 @@ public class IpClient extends StateMachine {
private static final int CMD_ADD_KEEPALIVE_PACKET_FILTER_TO_APF = 13;
private static final int CMD_REMOVE_KEEPALIVE_PACKET_FILTER_FROM_APF = 14;
private static final int CMD_UPDATE_L2KEY_GROUPHINT = 15;
- protected static final int CMD_COMPLETE_PRECONNECTION = 16;
+ private static final int CMD_COMPLETE_PRECONNECTION = 16;
+ private static final int CMD_UPDATE_L2INFORMATION = 17;
// Internal commands to use instead of trying to call transitionTo() inside
// a given State's enter() method. Calling transitionTo() from enter/exit
@@ -423,6 +426,14 @@ public class IpClient extends StateMachine {
new byte[] { (byte) 0x00, (byte) 0x17, (byte) 0xf2, (byte) 0x06 }
));
+ // Initialize configurable particular SSID set supporting DHCP Roaming feature. See
+ // b/131797393 for more details.
+ private static final Set<String> DHCP_ROAMING_SSID_SET = new HashSet<>(
+ Arrays.asList(
+ "0001docomo", "ollehWiFi", "olleh GiGa WiFi", "KT WiFi",
+ "KT GiGA WiFi", "marente"
+ ));
+
private final State mStoppedState = new StoppedState();
private final State mStoppingState = new StoppingState();
private final State mClearingIpAddressesState = new ClearingIpAddressesState();
@@ -470,6 +481,7 @@ public class IpClient extends StateMachine {
private String mGroupHint; // The group hint for this network, for writing into the memory store
private boolean mMulticastFiltering;
private long mStartTimeMillis;
+ private MacAddress mCurrentBssid;
/**
* Reading the snapshot is an asynchronous operation initiated by invoking
@@ -704,7 +716,6 @@ public class IpClient extends StateMachine {
enforceNetworkStackCallingPermission();
IpClient.this.notifyPreconnectionComplete(success);
}
-
@Override
public void updateLayer2Information(Layer2InformationParcelable info) {
enforceNetworkStackCallingPermission();
@@ -772,6 +783,16 @@ public class IpClient extends StateMachine {
return;
}
+ final ScanResultInfo scanResultInfo = req.mScanResultInfo;
+ mCurrentBssid = null;
+ if (scanResultInfo != null) {
+ try {
+ mCurrentBssid = MacAddress.fromString(scanResultInfo.getBssid());
+ } catch (IllegalArgumentException e) {
+ Log.wtf(mTag, "Invalid BSSID: " + scanResultInfo.getBssid()
+ + " in provisioning configuration", e);
+ }
+ }
sendMessage(CMD_START, new android.net.shared.ProvisioningConfiguration(req));
}
@@ -819,9 +840,14 @@ public class IpClient extends StateMachine {
/**
* Set the L2 key and group hint for storing info into the memory store.
+ *
+ * This method is only supported on Q devices. For R or above releases,
+ * caller should call #updateLayer2Information() instead.
*/
public void setL2KeyAndGroupHint(String l2Key, String groupHint) {
- sendMessage(CMD_UPDATE_L2KEY_GROUPHINT, new Pair<>(l2Key, groupHint));
+ if (!ShimUtils.isReleaseOrDevelopmentApiAbove(Build.VERSION_CODES.Q)) {
+ sendMessage(CMD_UPDATE_L2KEY_GROUPHINT, new Pair<>(l2Key, groupHint));
+ }
}
/**
@@ -880,7 +906,7 @@ public class IpClient extends StateMachine {
* Update the network bssid, L2Key and GroupHint layer2 information.
*/
public void updateLayer2Information(@NonNull Layer2InformationParcelable info) {
- // TODO: add specific implementation.
+ sendMessage(CMD_UPDATE_L2INFORMATION, info);
}
/**
@@ -1502,6 +1528,36 @@ public class IpClient extends StateMachine {
}
}
+ private void handleUpdateL2Information(@NonNull Layer2InformationParcelable info) {
+ mL2Key = info.l2Key;
+ mGroupHint = info.groupHint;
+
+ // This means IpClient is still in the StoppedState, WiFi is trying to associate
+ // to the AP, just update L2Key and GroupHint at this stage, because these members
+ // will be used when starting DhcpClient.
+ if (info.bssid == null || mCurrentBssid == null) return;
+
+ // If the BSSID has not changed, there is nothing to do.
+ if (info.bssid.equals(mCurrentBssid)) return;
+
+ if (mIpReachabilityMonitor != null) {
+ mIpReachabilityMonitor.probeAll();
+ }
+
+ // Check whether to refresh previous IP lease on L2 roaming happened.
+ final String ssid = removeDoubleQuotes(mConfiguration.mDisplayName);
+ if (DHCP_ROAMING_SSID_SET.contains(ssid) && mDhcpClient != null) {
+ if (DBG) {
+ Log.d(mTag, "L2 roaming happened from " + mCurrentBssid
+ + " to " + info.bssid
+ + " , SSID: " + ssid
+ + " , starting refresh leased IP address");
+ }
+ mDhcpClient.sendMessage(DhcpClient.CMD_REFRESH_LINKADDRESS);
+ }
+ mCurrentBssid = info.bssid;
+ }
+
class StoppedState extends State {
@Override
public void enter() {
@@ -1554,6 +1610,10 @@ public class IpClient extends StateMachine {
break;
}
+ case CMD_UPDATE_L2INFORMATION:
+ handleUpdateL2Information((Layer2InformationParcelable) msg.obj);
+ break;
+
case CMD_SET_MULTICAST_FILTER:
mMulticastFiltering = (boolean) msg.obj;
break;
@@ -1763,6 +1823,10 @@ public class IpClient extends StateMachine {
break;
}
+ case CMD_UPDATE_L2INFORMATION:
+ handleUpdateL2Information((Layer2InformationParcelable) msg.obj);
+ break;
+
case EVENT_PROVISIONING_TIMEOUT:
handleProvisioningFailure();
break;