1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.net.util; 18 19 import static android.net.shared.IpConfigurationParcelableUtil.unparcelAddress; 20 21 import android.annotation.Nullable; 22 import android.net.DhcpResults; 23 import android.net.DhcpResultsParcelable; 24 25 import java.net.Inet4Address; 26 27 /** 28 * Compatibility utility for code that still uses DhcpResults. 29 * 30 * TODO: remove this class when all usages of DhcpResults (including Wifi in AOSP) are removed. 31 */ 32 public class DhcpResultsCompatUtil { 33 34 /** 35 * Convert a DhcpResultsParcelable to DhcpResults. 36 * 37 * contract { 38 * returns(null) implies p == null 39 * returnsNotNull() implies p != null 40 * } 41 */ 42 @Nullable fromStableParcelable(@ullable DhcpResultsParcelable p)43 public static DhcpResults fromStableParcelable(@Nullable DhcpResultsParcelable p) { 44 if (p == null) return null; 45 final DhcpResults results = new DhcpResults(p.baseConfiguration); 46 results.leaseDuration = p.leaseDuration; 47 results.mtu = p.mtu; 48 results.serverAddress = (Inet4Address) unparcelAddress(p.serverAddress); 49 results.vendorInfo = p.vendorInfo; 50 results.serverHostName = p.serverHostName; 51 results.captivePortalApiUrl = p.captivePortalApiUrl; 52 return results; 53 } 54 } 55