Merge "Remove IpClientCallbacks dependency on DhcpResults" into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
0109b8da49
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user