1 /* 2 * Copyright (C) 2019 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.ip; 18 19 import android.net.DhcpResultsParcelable; 20 import android.net.Layer2PacketParcelable; 21 import android.net.LinkProperties; 22 import android.net.networkstack.aidl.ip.ReachabilityLossInfoParcelable; 23 24 import java.util.List; 25 26 /** 27 * Callbacks for handling IpClient events. 28 * 29 * This is a convenience class to allow clients not to override all methods of IIpClientCallbacks, 30 * and avoid unparceling arguments. 31 * These methods are called asynchronously on a Binder thread, as IpClient lives in a different 32 * process. 33 * @hide 34 */ 35 public class IpClientCallbacks { 36 37 /** 38 * Callback called upon IpClient creation. 39 * 40 * @param ipClient The Binder token to communicate with IpClient. 41 */ onIpClientCreated(IIpClient ipClient)42 public void onIpClientCreated(IIpClient ipClient) {} 43 44 /** 45 * Callback called prior to DHCP discovery/renewal. 46 * 47 * <p>In order to receive onPreDhcpAction(), call #withPreDhcpAction() when constructing a 48 * ProvisioningConfiguration. 49 * 50 * <p>Implementations of onPreDhcpAction() must call IpClient#completedPreDhcpAction() to 51 * indicate that DHCP is clear to proceed. 52 */ onPreDhcpAction()53 public void onPreDhcpAction() {} 54 55 /** 56 * Callback called after DHCP discovery/renewal. 57 */ onPostDhcpAction()58 public void onPostDhcpAction() {} 59 60 /** 61 * Callback called when new DHCP results are available. 62 * 63 * <p>This is purely advisory and not an indication of provisioning success or failure. This is 64 * only here for callers that want to expose DHCPv4 results to other APIs 65 * (e.g., WifiInfo#setInetAddress). 66 * 67 * <p>DHCPv4 or static IPv4 configuration failure or success can be determined by whether or not 68 * the passed-in DhcpResults object is null. 69 */ onNewDhcpResults(DhcpResultsParcelable dhcpResults)70 public void onNewDhcpResults(DhcpResultsParcelable dhcpResults) { 71 // In general callbacks would not use a parcelable directly (DhcpResultsParcelable), and 72 // would use a wrapper instead, because of the lack of safety of stable parcelables. But 73 // there are already two classes in the tree for DHCP information: DhcpInfo and DhcpResults, 74 // and neither of them exposes an appropriate API (they are bags of mutable fields and can't 75 // be changed because they are public API and @UnsupportedAppUsage, being no better than the 76 // stable parcelable). Adding a third class would cost more than the gain considering that 77 // the only client of this callback is WiFi, which will end up converting the results to 78 // DhcpInfo anyway. 79 } 80 81 /** 82 * Indicates that provisioning was successful. 83 */ onProvisioningSuccess(LinkProperties newLp)84 public void onProvisioningSuccess(LinkProperties newLp) {} 85 86 /** 87 * Indicates that provisioning failed. 88 */ onProvisioningFailure(LinkProperties newLp)89 public void onProvisioningFailure(LinkProperties newLp) {} 90 91 /** 92 * Invoked on LinkProperties changes. 93 */ onLinkPropertiesChange(LinkProperties newLp)94 public void onLinkPropertiesChange(LinkProperties newLp) {} 95 96 /**Called when the internal IpReachabilityMonitor (if enabled) has 97 * detected the loss of a critical number of required neighbors. 98 */ onReachabilityLost(String logMsg)99 public void onReachabilityLost(String logMsg) {} 100 101 /** 102 * Called when the IpClient state machine terminates. 103 */ onQuit()104 public void onQuit() {} 105 106 /** 107 * Called to indicate that a new APF program must be installed to filter incoming packets. 108 */ installPacketFilter(byte[] filter)109 public void installPacketFilter(byte[] filter) {} 110 111 /** 112 * Called to indicate that the APF Program & data buffer must be read asynchronously from the 113 * wifi driver. 114 * 115 * <p>Due to Wifi HAL limitations, the current implementation only supports dumping the entire 116 * buffer. In response to this request, the driver returns the data buffer asynchronously 117 * by sending an IpClient#EVENT_READ_PACKET_FILTER_COMPLETE message. 118 */ startReadPacketFilter()119 public void startReadPacketFilter() {} 120 121 /** 122 * If multicast filtering cannot be accomplished with APF, this function will be called to 123 * actuate multicast filtering using another means. 124 */ setFallbackMulticastFilter(boolean enabled)125 public void setFallbackMulticastFilter(boolean enabled) {} 126 127 /** 128 * Enabled/disable Neighbor Discover offload functionality. This is called, for example, 129 * whenever 464xlat is being started or stopped. 130 */ setNeighborDiscoveryOffload(boolean enable)131 public void setNeighborDiscoveryOffload(boolean enable) {} 132 133 /** 134 * Invoked on starting preconnection process. 135 */ onPreconnectionStart(List<Layer2PacketParcelable> packets)136 public void onPreconnectionStart(List<Layer2PacketParcelable> packets) {} 137 138 /** 139 * Called when the internal IpReachabilityMonitor (if enabled) has detected the loss of a 140 * critical number of required neighbors or DHCP roaming fails. 141 * 142 * @param lossInfo the specific neighbor reachability loss information. 143 */ onReachabilityFailure(ReachabilityLossInfoParcelable lossInfo)144 public void onReachabilityFailure(ReachabilityLossInfoParcelable lossInfo) { 145 // If the client does not implement this method, call the older 146 // onReachabilityLost method. 147 onReachabilityLost(lossInfo.message); 148 } 149 150 /** 151 * Set maximum acceptable DTIM multiplier to hardware driver. 152 * 153 * @param multiplier an integer maximum DTIM multiplier value to set. 154 */ setMaxDtimMultiplier(int multiplier)155 public void setMaxDtimMultiplier(int multiplier) {} 156 } 157