summaryrefslogtreecommitdiff
path: root/services/net/java
diff options
context:
space:
mode:
authorRemi NGUYEN VAN <reminv@google.com>2020-04-06 16:40:51 +0900
committerRemi NGUYEN VAN <reminv@google.com>2020-06-09 17:19:24 +0900
commitac0c8988cefdf981c806ce2568817e7c573b1b77 (patch)
treed39216cce1f82d2358d46f6f529484919ab1adf2 /services/net/java
parent38a831c1e32e1dec31be273a3ad079d36ee52f3f (diff)
Remove IpClientCallbacks dependency on DhcpResults
DhcpResults should only be used inside the NetworkStack: modules are expected to use DhcpResultsParcelable instead. Add a compat utility so current users of DhcpResults can do the conversion (wifi in AOSP in particular). The utility can be removed when changes to stop depending on DhcpResults are merged in AOSP. Bug: 149403767 Test: built, flashed, WiFi working Change-Id: I5b85c1a541ecdf9dd3e9403b9fb1c2b5aba98dd8
Diffstat (limited to 'services/net/java')
-rw-r--r--services/net/java/android/net/ip/IpClientCallbacks.java23
-rw-r--r--services/net/java/android/net/ip/IpClientUtil.java3
-rw-r--r--services/net/java/android/net/util/DhcpResultsCompatUtil.java54
3 files changed, 63 insertions, 17 deletions
diff --git a/services/net/java/android/net/ip/IpClientCallbacks.java b/services/net/java/android/net/ip/IpClientCallbacks.java
index c93e5c5e4759..b172c4be7b0d 100644
--- a/services/net/java/android/net/ip/IpClientCallbacks.java
+++ b/services/net/java/android/net/ip/IpClientCallbacks.java
@@ -16,7 +16,6 @@
package android.net.ip;
-import android.net.DhcpResults;
import android.net.DhcpResultsParcelable;
import android.net.Layer2PacketParcelable;
import android.net.LinkProperties;
@@ -67,19 +66,15 @@ public class IpClientCallbacks {
* <p>DHCPv4 or static IPv4 configuration failure or success can be determined by whether or not
* the passed-in DhcpResults object is null.
*/
- public void onNewDhcpResults(DhcpResults dhcpResults) {}
-
- /**
- * Callback called when new DHCP results are available.
- *
- * <p>This is purely advisory and not an indication of provisioning success or failure. This is
- * only here for callers that want to expose DHCPv4 results to other APIs
- * (e.g., WifiInfo#setInetAddress).
- *
- * <p>DHCPv4 or static IPv4 configuration failure or success can be determined by whether or not
- * the passed-in DhcpResults object is null.
- */
- public void onNewDhcpResults(DhcpResultsParcelable dhcpResults) {}
+ public void onNewDhcpResults(DhcpResultsParcelable dhcpResults) {
+ // In general callbacks would not use a parcelable directly (DhcpResultsParcelable), and
+ // would use a wrapper instead. But there are already two classes in the tree for DHCP
+ // information: DhcpInfo and DhcpResults, and each of them do not expose an appropriate API
+ // (they are bags of mutable fields and can't be changed because they are public API and
+ // @UnsupportedAppUsage). Adding a third class would cost more than the gain considering
+ // that the only client of this callback is WiFi, which will end up converting the results
+ // to DhcpInfo anyway.
+ }
/**
* Indicates that provisioning was successful.
diff --git a/services/net/java/android/net/ip/IpClientUtil.java b/services/net/java/android/net/ip/IpClientUtil.java
index b329aeec4853..426614ec2f53 100644
--- a/services/net/java/android/net/ip/IpClientUtil.java
+++ b/services/net/java/android/net/ip/IpClientUtil.java
@@ -16,8 +16,6 @@
package android.net.ip;
-import static android.net.shared.IpConfigurationParcelableUtil.fromStableParcelable;
-
import android.content.Context;
import android.net.DhcpResultsParcelable;
import android.net.Layer2PacketParcelable;
@@ -118,7 +116,6 @@ public class IpClientUtil {
// null or not.
@Override
public void onNewDhcpResults(DhcpResultsParcelable dhcpResults) {
- mCb.onNewDhcpResults(fromStableParcelable(dhcpResults));
mCb.onNewDhcpResults(dhcpResults);
}
diff --git a/services/net/java/android/net/util/DhcpResultsCompatUtil.java b/services/net/java/android/net/util/DhcpResultsCompatUtil.java
new file mode 100644
index 000000000000..fce0834c116e
--- /dev/null
+++ b/services/net/java/android/net/util/DhcpResultsCompatUtil.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net.util;
+
+import static android.net.shared.IpConfigurationParcelableUtil.unparcelAddress;
+
+import android.annotation.Nullable;
+import android.net.DhcpResults;
+import android.net.DhcpResultsParcelable;
+
+import java.net.Inet4Address;
+
+/**
+ * Compatibility utility for code that still uses DhcpResults.
+ *
+ * TODO: remove this class when all usages of DhcpResults (including Wifi in AOSP) are removed.
+ */
+public class DhcpResultsCompatUtil {
+
+ /**
+ * Convert a DhcpResultsParcelable to DhcpResults.
+ *
+ * contract {
+ * returns(null) implies p == null
+ * returnsNotNull() implies p != null
+ * }
+ */
+ @Nullable
+ public static DhcpResults fromStableParcelable(@Nullable DhcpResultsParcelable p) {
+ if (p == null) return null;
+ final DhcpResults results = new DhcpResults(p.baseConfiguration);
+ results.leaseDuration = p.leaseDuration;
+ results.mtu = p.mtu;
+ results.serverAddress = (Inet4Address) unparcelAddress(p.serverAddress);
+ results.vendorInfo = p.vendorInfo;
+ results.serverHostName = p.serverHostName;
+ results.captivePortalApiUrl = p.captivePortalApiUrl;
+ return results;
+ }
+}