Merge "Fix framework and NetworkStack classes conflicts"

am: 3f23efdd13

Change-Id: I8c207040c42a3d02b8383e13a4f839c250788f58
This commit is contained in:
Remi NGUYEN VAN
2019-02-15 16:38:52 -08:00
committed by android-build-merger
9 changed files with 34 additions and 6 deletions

View File

@@ -1,33 +0,0 @@
/*
* Copyright (C) 2018 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.dhcp;
/**
* Convenience wrapper around IDhcpServerCallbacks.Stub that implements getInterfaceVersion().
* @hide
*/
public abstract class DhcpServerCallbacks extends IDhcpServerCallbacks.Stub {
// TODO: add @Override here once the API is versioned
/**
* Get the version of the aidl interface implemented by the callbacks.
*/
public int getInterfaceVersion() {
// TODO: return IDhcpServerCallbacks.VERSION;
return 0;
}
}

View File

@@ -1,119 +0,0 @@
/*
* Copyright (C) 2019 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.ip;
import android.net.DhcpResults;
import android.net.LinkProperties;
/**
* Callbacks for handling IpClient events.
*
* This is a convenience class to allow clients not to override all methods of IIpClientCallbacks,
* and avoid unparceling arguments.
* These methods are called asynchronously on a Binder thread, as IpClient lives in a different
* process.
* @hide
*/
public class IpClientCallbacks {
/**
* Callback called upon IpClient creation.
*
* @param ipClient The Binder token to communicate with IpClient.
*/
public void onIpClientCreated(IIpClient ipClient) {}
/**
* Callback called prior to DHCP discovery/renewal.
*
* <p>In order to receive onPreDhcpAction(), call #withPreDhcpAction() when constructing a
* ProvisioningConfiguration.
*
* <p>Implementations of onPreDhcpAction() must call IpClient#completedPreDhcpAction() to
* indicate that DHCP is clear to proceed.
*/
public void onPreDhcpAction() {}
/**
* Callback called after DHCP discovery/renewal.
*/
public void onPostDhcpAction() {}
/**
* 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(DhcpResults dhcpResults) {}
/**
* Indicates that provisioning was successful.
*/
public void onProvisioningSuccess(LinkProperties newLp) {}
/**
* Indicates that provisioning failed.
*/
public void onProvisioningFailure(LinkProperties newLp) {}
/**
* Invoked on LinkProperties changes.
*/
public void onLinkPropertiesChange(LinkProperties newLp) {}
/**Called when the internal IpReachabilityMonitor (if enabled) has
* detected the loss of a critical number of required neighbors.
*/
public void onReachabilityLost(String logMsg) {}
/**
* Called when the IpClient state machine terminates.
*/
public void onQuit() {}
/**
* Called to indicate that a new APF program must be installed to filter incoming packets.
*/
public void installPacketFilter(byte[] filter) {}
/**
* Called to indicate that the APF Program & data buffer must be read asynchronously from the
* wifi driver.
*
* <p>Due to Wifi HAL limitations, the current implementation only supports dumping the entire
* buffer. In response to this request, the driver returns the data buffer asynchronously
* by sending an IpClient#EVENT_READ_PACKET_FILTER_COMPLETE message.
*/
public void startReadPacketFilter() {}
/**
* If multicast filtering cannot be accomplished with APF, this function will be called to
* actuate multicast filtering using another means.
*/
public void setFallbackMulticastFilter(boolean enabled) {}
/**
* Enabled/disable Neighbor Discover offload functionality. This is called, for example,
* whenever 464xlat is being started or stopped.
*/
public void setNeighborDiscoveryOffload(boolean enable) {}
}

View File

@@ -1,265 +0,0 @@
/*
* Copyright (C) 2016 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.shared;
import static android.os.MessageQueue.OnFileDescriptorEventListener.EVENT_ERROR;
import static android.os.MessageQueue.OnFileDescriptorEventListener.EVENT_INPUT;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.net.util.SocketUtils;
import android.os.Handler;
import android.os.Looper;
import android.os.MessageQueue;
import android.system.ErrnoException;
import android.system.OsConstants;
import java.io.FileDescriptor;
import java.io.IOException;
/**
* This class encapsulates the mechanics of registering a file descriptor
* with a thread's Looper and handling read events (and errors).
*
* Subclasses MUST implement createFd() and SHOULD override handlePacket(). They MAY override
* onStop() and onStart().
*
* Subclasses can expect a call life-cycle like the following:
*
* [1] when a client calls start(), createFd() is called, followed by the onStart() hook if all
* goes well. Implementations may override onStart() for additional initialization.
*
* [2] yield, waiting for read event or error notification:
*
* [a] readPacket() && handlePacket()
*
* [b] if (no error):
* goto 2
* else:
* goto 3
*
* [3] when a client calls stop(), the onStop() hook is called (unless already stopped or never
* started). Implementations may override onStop() for additional cleanup.
*
* The packet receive buffer is recycled on every read call, so subclasses
* should make any copies they would like inside their handlePacket()
* implementation.
*
* All public methods MUST only be called from the same thread with which
* the Handler constructor argument is associated.
*
* @param <BufferType> the type of the buffer used to read data.
* @hide
*/
public abstract class FdEventsReader<BufferType> {
private static final int FD_EVENTS = EVENT_INPUT | EVENT_ERROR;
private static final int UNREGISTER_THIS_FD = 0;
@NonNull
private final Handler mHandler;
@NonNull
private final MessageQueue mQueue;
@NonNull
private final BufferType mBuffer;
@Nullable
private FileDescriptor mFd;
private long mPacketsReceived;
protected static void closeFd(FileDescriptor fd) {
try {
SocketUtils.closeSocket(fd);
} catch (IOException ignored) {
}
}
protected FdEventsReader(@NonNull Handler h, @NonNull BufferType buffer) {
mHandler = h;
mQueue = mHandler.getLooper().getQueue();
mBuffer = buffer;
}
/** Start this FdEventsReader. */
public void start() {
if (onCorrectThread()) {
createAndRegisterFd();
} else {
mHandler.post(() -> {
logError("start() called from off-thread", null);
createAndRegisterFd();
});
}
}
/** Stop this FdEventsReader and destroy the file descriptor. */
public void stop() {
if (onCorrectThread()) {
unregisterAndDestroyFd();
} else {
mHandler.post(() -> {
logError("stop() called from off-thread", null);
unregisterAndDestroyFd();
});
}
}
@NonNull
public Handler getHandler() {
return mHandler;
}
protected abstract int recvBufSize(@NonNull BufferType buffer);
/** Returns the size of the receive buffer. */
public int recvBufSize() {
return recvBufSize(mBuffer);
}
/**
* Get the number of successful calls to {@link #readPacket(FileDescriptor, Object)}.
*
* <p>A call was successful if {@link #readPacket(FileDescriptor, Object)} returned a value > 0.
*/
public final long numPacketsReceived() {
return mPacketsReceived;
}
/**
* Subclasses MUST create the listening socket here, including setting all desired socket
* options, interface or address/port binding, etc. The socket MUST be created nonblocking.
*/
@Nullable
protected abstract FileDescriptor createFd();
/**
* Implementations MUST return the bytes read or throw an Exception.
*
* <p>The caller may throw a {@link ErrnoException} with {@link OsConstants#EAGAIN} or
* {@link OsConstants#EINTR}, in which case {@link FdEventsReader} will ignore the buffer
* contents and respectively wait for further input or retry the read immediately. For all other
* exceptions, the {@link FdEventsReader} will be stopped with no more interactions with this
* method.
*/
protected abstract int readPacket(@NonNull FileDescriptor fd, @NonNull BufferType buffer)
throws Exception;
/**
* Called by the main loop for every packet. Any desired copies of
* |recvbuf| should be made in here, as the underlying byte array is
* reused across all reads.
*/
protected void handlePacket(@NonNull BufferType recvbuf, int length) {}
/**
* Called by the main loop to log errors. In some cases |e| may be null.
*/
protected void logError(@NonNull String msg, @Nullable Exception e) {}
/**
* Called by start(), if successful, just prior to returning.
*/
protected void onStart() {}
/**
* Called by stop() just prior to returning.
*/
protected void onStop() {}
private void createAndRegisterFd() {
if (mFd != null) return;
try {
mFd = createFd();
} catch (Exception e) {
logError("Failed to create socket: ", e);
closeFd(mFd);
mFd = null;
}
if (mFd == null) return;
mQueue.addOnFileDescriptorEventListener(
mFd,
FD_EVENTS,
(fd, events) -> {
// Always call handleInput() so read/recvfrom are given
// a proper chance to encounter a meaningful errno and
// perhaps log a useful error message.
if (!isRunning() || !handleInput()) {
unregisterAndDestroyFd();
return UNREGISTER_THIS_FD;
}
return FD_EVENTS;
});
onStart();
}
private boolean isRunning() {
return (mFd != null) && mFd.valid();
}
// Keep trying to read until we get EAGAIN/EWOULDBLOCK or some fatal error.
private boolean handleInput() {
while (isRunning()) {
final int bytesRead;
try {
bytesRead = readPacket(mFd, mBuffer);
if (bytesRead < 1) {
if (isRunning()) logError("Socket closed, exiting", null);
break;
}
mPacketsReceived++;
} catch (ErrnoException e) {
if (e.errno == OsConstants.EAGAIN) {
// We've read everything there is to read this time around.
return true;
} else if (e.errno == OsConstants.EINTR) {
continue;
} else {
if (isRunning()) logError("readPacket error: ", e);
break;
}
} catch (Exception e) {
if (isRunning()) logError("readPacket error: ", e);
break;
}
try {
handlePacket(mBuffer, bytesRead);
} catch (Exception e) {
logError("handlePacket error: ", e);
break;
}
}
return false;
}
private void unregisterAndDestroyFd() {
if (mFd == null) return;
mQueue.removeOnFileDescriptorEventListener(mFd);
closeFd(mFd);
mFd = null;
onStop();
}
private boolean onCorrectThread() {
return (mHandler.getLooper() == Looper.myLooper());
}
}