mirror of
https://github.com/Divested-Mobile/DivestOS-Build.git
synced 2024-08-30 22:21:55 +00:00
72 lines
2.9 KiB
Diff
72 lines
2.9 KiB
Diff
![]() |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||
|
From: Pratyush <39559233+empratyush@users.noreply.github.com>
|
||
|
Date: Thu, 20 May 2021 13:21:31 +0530
|
||
|
Subject: [PATCH] avoid reusing DHCP state for full MAC randomization
|
||
|
|
||
|
---
|
||
|
src/android/net/dhcp/DhcpClient.java | 30 +++++++++++++++++++++++++++-
|
||
|
1 file changed, 29 insertions(+), 1 deletion(-)
|
||
|
|
||
|
diff --git a/src/android/net/dhcp/DhcpClient.java b/src/android/net/dhcp/DhcpClient.java
|
||
|
index c45fc82..b62239c 100644
|
||
|
--- a/src/android/net/dhcp/DhcpClient.java
|
||
|
+++ b/src/android/net/dhcp/DhcpClient.java
|
||
|
@@ -60,6 +60,9 @@ import android.net.metrics.IpConnectivityLog;
|
||
|
import android.net.util.InterfaceParams;
|
||
|
import android.net.util.NetworkStackUtils;
|
||
|
import android.net.util.SocketUtils;
|
||
|
+import android.net.wifi.WifiConfiguration;
|
||
|
+import android.net.wifi.WifiInfo;
|
||
|
+import android.net.wifi.WifiManager;
|
||
|
import android.os.Message;
|
||
|
import android.os.SystemClock;
|
||
|
import android.system.ErrnoException;
|
||
|
@@ -84,6 +87,8 @@ import java.net.SocketAddress;
|
||
|
import java.net.SocketException;
|
||
|
import java.nio.ByteBuffer;
|
||
|
import java.util.Arrays;
|
||
|
+import java.util.ArrayList;
|
||
|
+import java.util.List;
|
||
|
import java.util.Random;
|
||
|
|
||
|
/**
|
||
|
@@ -917,7 +922,7 @@ public class DhcpClient extends StateMachine {
|
||
|
+ " lease expiry: " + attributes.assignedV4AddressExpiry
|
||
|
+ " current time: " + currentTime);
|
||
|
}
|
||
|
- if (currentTime >= attributes.assignedV4AddressExpiry) {
|
||
|
+ if (currentTime >= attributes.assignedV4AddressExpiry || shouldAvoidStateReuse()) {
|
||
|
// Lease has expired.
|
||
|
transitionTo(mDhcpInitState);
|
||
|
return HANDLED;
|
||
|
@@ -941,6 +946,29 @@ public class DhcpClient extends StateMachine {
|
||
|
}
|
||
|
}
|
||
|
|
||
|
+ private static final int RANDOMIZATION_ALWAYS = 100;
|
||
|
+
|
||
|
+ private boolean shouldAvoidStateReuse() {
|
||
|
+ try {
|
||
|
+ WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
|
||
|
+ WifiInfo wifiInfo = wifiManager.getConnectionInfo();
|
||
|
+ if (wifiInfo != null) {
|
||
|
+ int connectedNetworkId = wifiInfo.getNetworkId();
|
||
|
+ List<WifiConfiguration> configurationList = wifiManager.getConfiguredNetworks();
|
||
|
+ for (WifiConfiguration configuration : configurationList){
|
||
|
+ if (configuration.networkId == connectedNetworkId){
|
||
|
+ return configuration.macRandomizationSetting == RANDOMIZATION_ALWAYS;
|
||
|
+ }
|
||
|
+ }
|
||
|
+ }
|
||
|
+ } catch (Exception e) {
|
||
|
+ loge(e.getLocalizedMessage(), e);
|
||
|
+ }
|
||
|
+
|
||
|
+ loge("ConfiguredNetworks should contain Connected network id config");
|
||
|
+ return true;
|
||
|
+ }
|
||
|
+
|
||
|
class DhcpInitState extends PacketRetransmittingState {
|
||
|
public DhcpInitState() {
|
||
|
super();
|