Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6da2bbe5 authored by Remi NGUYEN VAN's avatar Remi NGUYEN VAN Committed by Automerger Merge Worker
Browse files

Merge "Remove IpClientCallbacks dependency on DhcpResults" am: 5bd9279c am:...

Merge "Remove IpClientCallbacks dependency on DhcpResults" am: 5bd9279c am: 4424726c am: 1ac0fb69 am: 6ce8e7fd

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1277608

Change-Id: I2909eb13b8f776bd88012805d3b07c6bc05c3481
parents 93cf266b 6ce8e7fd
Loading
Loading
Loading
Loading
+9 −14
Original line number Diff line number Diff line
@@ -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.
+0 −3
Original line number Diff line number Diff line
@@ -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);
        }

+54 −0
Original line number Diff line number Diff line
/*
 * 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;
    }
}