Skip to content
Snippets Groups Projects
Commit ac0c8988 authored by Remi NGUYEN VAN's avatar Remi NGUYEN VAN
Browse files

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
parent 38a831c1
No related branches found
No related tags found
No related merge requests found
......@@ -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.
......
......@@ -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);
}
......
/*
* 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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment