Support QosCallback for UDP socket -Filter

Add matchProtocol() to QosFilter.
Add remoteAddress check to validate().
Add exception EX_TYPE_FILTER_SOCKET_REMOTE_ADDRESS_CHANGED
Don't send ParcelFileDescriptor to QosProvider for security reason

Bug: 203146631
Test: atest & verified on LTE test equipment
Change-Id: I7102ae9ba7cb9e1cc8d06b252aad4dad75860f3e
This commit is contained in:
sewookseo
2022-03-07 11:03:13 +00:00
parent 82657d70d7
commit afc22b02e2
7 changed files with 188 additions and 32 deletions

View File

@@ -165,25 +165,28 @@ public final class QosSocketInfo implements Parcelable {
/* Parcelable methods */
private QosSocketInfo(final Parcel in) {
mNetwork = Objects.requireNonNull(Network.CREATOR.createFromParcel(in));
mParcelFileDescriptor = ParcelFileDescriptor.CREATOR.createFromParcel(in);
final boolean withFd = in.readBoolean();
if (withFd) {
mParcelFileDescriptor = ParcelFileDescriptor.CREATOR.createFromParcel(in);
} else {
mParcelFileDescriptor = null;
}
final int localAddressLength = in.readInt();
mLocalSocketAddress = readSocketAddress(in, localAddressLength);
final int remoteAddressLength = in.readInt();
mRemoteSocketAddress = remoteAddressLength == 0 ? null
: readSocketAddress(in, remoteAddressLength);
mLocalSocketAddress = readSocketAddress(in);
mRemoteSocketAddress = readSocketAddress(in);
mSocketType = in.readInt();
}
private @NonNull InetSocketAddress readSocketAddress(final Parcel in, final int addressLength) {
final byte[] address = new byte[addressLength];
in.readByteArray(address);
private InetSocketAddress readSocketAddress(final Parcel in) {
final byte[] addrBytes = in.createByteArray();
if (addrBytes == null) {
return null;
}
final int port = in.readInt();
try {
return new InetSocketAddress(InetAddress.getByAddress(address), port);
return new InetSocketAddress(InetAddress.getByAddress(addrBytes), port);
} catch (final UnknownHostException e) {
/* This can never happen. UnknownHostException will never be thrown
since the address provided is numeric and non-null. */
@@ -198,20 +201,35 @@ public final class QosSocketInfo implements Parcelable {
@Override
public void writeToParcel(@NonNull final Parcel dest, final int flags) {
mNetwork.writeToParcel(dest, 0);
mParcelFileDescriptor.writeToParcel(dest, 0);
writeToParcelInternal(dest, flags, /*includeFd=*/ true);
}
final byte[] localAddress = mLocalSocketAddress.getAddress().getAddress();
dest.writeInt(localAddress.length);
dest.writeByteArray(localAddress);
/**
* Used when sending QosSocketInfo to telephony, which does not need access to the socket FD.
* @hide
*/
public void writeToParcelWithoutFd(@NonNull final Parcel dest, final int flags) {
writeToParcelInternal(dest, flags, /*includeFd=*/ false);
}
private void writeToParcelInternal(
@NonNull final Parcel dest, final int flags, boolean includeFd) {
mNetwork.writeToParcel(dest, 0);
if (includeFd) {
dest.writeBoolean(true);
mParcelFileDescriptor.writeToParcel(dest, 0);
} else {
dest.writeBoolean(false);
}
dest.writeByteArray(mLocalSocketAddress.getAddress().getAddress());
dest.writeInt(mLocalSocketAddress.getPort());
if (mRemoteSocketAddress == null) {
dest.writeInt(0);
dest.writeByteArray(null);
} else {
final byte[] remoteAddress = mRemoteSocketAddress.getAddress().getAddress();
dest.writeInt(remoteAddress.length);
dest.writeByteArray(remoteAddress);
dest.writeByteArray(mRemoteSocketAddress.getAddress().getAddress());
dest.writeInt(mRemoteSocketAddress.getPort());
}
dest.writeInt(mSocketType);