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

Commit baa4bf51 authored by nharold's avatar nharold Committed by Gerrit Code Review
Browse files

Merge "Add NonNull Annotations To IpSec API Surface"

parents 8173db40 8fd26f67
Loading
Loading
Loading
Loading
+6 −2
Original line number Original line Diff line number Diff line
@@ -129,7 +129,7 @@ public final class IpSecAlgorithm implements Parcelable {
     * @param algorithm name of the algorithm.
     * @param algorithm name of the algorithm.
     * @param key key padded to a multiple of 8 bits.
     * @param key key padded to a multiple of 8 bits.
     */
     */
    public IpSecAlgorithm(@AlgorithmName String algorithm, @NonNull byte[] key) {
    public IpSecAlgorithm(@NonNull @AlgorithmName String algorithm, @NonNull byte[] key) {
        this(algorithm, key, key.length * 8);
        this(algorithm, key, key.length * 8);
    }
    }


@@ -144,7 +144,8 @@ public final class IpSecAlgorithm implements Parcelable {
     * @param key key padded to a multiple of 8 bits.
     * @param key key padded to a multiple of 8 bits.
     * @param truncLenBits number of bits of output hash to use.
     * @param truncLenBits number of bits of output hash to use.
     */
     */
    public IpSecAlgorithm(@AlgorithmName String algorithm, @NonNull byte[] key, int truncLenBits) {
    public IpSecAlgorithm(
            @NonNull @AlgorithmName String algorithm, @NonNull byte[] key, int truncLenBits) {
        mName = algorithm;
        mName = algorithm;
        mKey = key.clone();
        mKey = key.clone();
        mTruncLenBits = truncLenBits;
        mTruncLenBits = truncLenBits;
@@ -152,11 +153,13 @@ public final class IpSecAlgorithm implements Parcelable {
    }
    }


    /** Get the algorithm name */
    /** Get the algorithm name */
    @NonNull
    public String getName() {
    public String getName() {
        return mName;
        return mName;
    }
    }


    /** Get the key for this algorithm */
    /** Get the key for this algorithm */
    @NonNull
    public byte[] getKey() {
    public byte[] getKey() {
        return mKey.clone();
        return mKey.clone();
    }
    }
@@ -270,6 +273,7 @@ public final class IpSecAlgorithm implements Parcelable {
    }
    }


    @Override
    @Override
    @NonNull
    public String toString() {
    public String toString() {
        return new StringBuilder()
        return new StringBuilder()
                .append("{mName=")
                .append("{mName=")
+22 −22
Original line number Original line Diff line number Diff line
@@ -253,8 +253,9 @@ public final class IpSecManager {
     * @throws {@link #ResourceUnavailableException} indicating that too many SPIs are
     * @throws {@link #ResourceUnavailableException} indicating that too many SPIs are
     *     currently allocated for this user
     *     currently allocated for this user
     */
     */
    public SecurityParameterIndex allocateSecurityParameterIndex(InetAddress destinationAddress)
    @NonNull
            throws ResourceUnavailableException {
    public SecurityParameterIndex allocateSecurityParameterIndex(
                @NonNull InetAddress destinationAddress) throws ResourceUnavailableException {
        try {
        try {
            return new SecurityParameterIndex(
            return new SecurityParameterIndex(
                    mService,
                    mService,
@@ -280,8 +281,9 @@ public final class IpSecManager {
     * @throws {@link #SpiUnavailableException} indicating that the requested SPI could not be
     * @throws {@link #SpiUnavailableException} indicating that the requested SPI could not be
     *     reserved
     *     reserved
     */
     */
    @NonNull
    public SecurityParameterIndex allocateSecurityParameterIndex(
    public SecurityParameterIndex allocateSecurityParameterIndex(
            InetAddress destinationAddress, int requestedSpi)
            @NonNull InetAddress destinationAddress, int requestedSpi)
            throws SpiUnavailableException, ResourceUnavailableException {
            throws SpiUnavailableException, ResourceUnavailableException {
        if (requestedSpi == IpSecManager.INVALID_SECURITY_PARAMETER_INDEX) {
        if (requestedSpi == IpSecManager.INVALID_SECURITY_PARAMETER_INDEX) {
            throw new IllegalArgumentException("Requested SPI must be a valid (non-zero) SPI");
            throw new IllegalArgumentException("Requested SPI must be a valid (non-zero) SPI");
@@ -318,9 +320,8 @@ public final class IpSecManager {
     * @param transform a transport mode {@code IpSecTransform}
     * @param transform a transport mode {@code IpSecTransform}
     * @throws IOException indicating that the transform could not be applied
     * @throws IOException indicating that the transform could not be applied
     */
     */
    public void applyTransportModeTransform(
    public void applyTransportModeTransform(@NonNull Socket socket,
            Socket socket, @PolicyDirection int direction, IpSecTransform transform)
            @PolicyDirection int direction, @NonNull IpSecTransform transform) throws IOException {
            throws IOException {
        applyTransportModeTransform(socket.getFileDescriptor$(), direction, transform);
        applyTransportModeTransform(socket.getFileDescriptor$(), direction, transform);
    }
    }


@@ -353,9 +354,8 @@ public final class IpSecManager {
     * @param transform a transport mode {@code IpSecTransform}
     * @param transform a transport mode {@code IpSecTransform}
     * @throws IOException indicating that the transform could not be applied
     * @throws IOException indicating that the transform could not be applied
     */
     */
    public void applyTransportModeTransform(
    public void applyTransportModeTransform(@NonNull DatagramSocket socket,
            DatagramSocket socket, @PolicyDirection int direction, IpSecTransform transform)
            @PolicyDirection int direction, @NonNull IpSecTransform transform) throws IOException {
            throws IOException {
        applyTransportModeTransform(socket.getFileDescriptor$(), direction, transform);
        applyTransportModeTransform(socket.getFileDescriptor$(), direction, transform);
    }
    }


@@ -388,9 +388,8 @@ public final class IpSecManager {
     * @param transform a transport mode {@code IpSecTransform}
     * @param transform a transport mode {@code IpSecTransform}
     * @throws IOException indicating that the transform could not be applied
     * @throws IOException indicating that the transform could not be applied
     */
     */
    public void applyTransportModeTransform(
    public void applyTransportModeTransform(@NonNull FileDescriptor socket,
            FileDescriptor socket, @PolicyDirection int direction, IpSecTransform transform)
            @PolicyDirection int direction, @NonNull IpSecTransform transform) throws IOException {
            throws IOException {
        // We dup() the FileDescriptor here because if we don't, then the ParcelFileDescriptor()
        // We dup() the FileDescriptor here because if we don't, then the ParcelFileDescriptor()
        // constructor takes control and closes the user's FD when we exit the method.
        // constructor takes control and closes the user's FD when we exit the method.
        try (ParcelFileDescriptor pfd = ParcelFileDescriptor.dup(socket)) {
        try (ParcelFileDescriptor pfd = ParcelFileDescriptor.dup(socket)) {
@@ -413,8 +412,7 @@ public final class IpSecManager {
     * @param socket a socket that previously had a transform applied to it
     * @param socket a socket that previously had a transform applied to it
     * @throws IOException indicating that the transform could not be removed from the socket
     * @throws IOException indicating that the transform could not be removed from the socket
     */
     */
    public void removeTransportModeTransforms(Socket socket)
    public void removeTransportModeTransforms(@NonNull Socket socket) throws IOException {
            throws IOException {
        removeTransportModeTransforms(socket.getFileDescriptor$());
        removeTransportModeTransforms(socket.getFileDescriptor$());
    }
    }


@@ -431,8 +429,7 @@ public final class IpSecManager {
     * @param socket a socket that previously had a transform applied to it
     * @param socket a socket that previously had a transform applied to it
     * @throws IOException indicating that the transform could not be removed from the socket
     * @throws IOException indicating that the transform could not be removed from the socket
     */
     */
    public void removeTransportModeTransforms(DatagramSocket socket)
    public void removeTransportModeTransforms(@NonNull DatagramSocket socket) throws IOException {
            throws IOException {
        removeTransportModeTransforms(socket.getFileDescriptor$());
        removeTransportModeTransforms(socket.getFileDescriptor$());
    }
    }


@@ -449,8 +446,7 @@ public final class IpSecManager {
     * @param socket a socket that previously had a transform applied to it
     * @param socket a socket that previously had a transform applied to it
     * @throws IOException indicating that the transform could not be removed from the socket
     * @throws IOException indicating that the transform could not be removed from the socket
     */
     */
    public void removeTransportModeTransforms(FileDescriptor socket)
    public void removeTransportModeTransforms(@NonNull FileDescriptor socket) throws IOException {
            throws IOException {
        try (ParcelFileDescriptor pfd = ParcelFileDescriptor.dup(socket)) {
        try (ParcelFileDescriptor pfd = ParcelFileDescriptor.dup(socket)) {
            mService.removeTransportModeTransforms(pfd);
            mService.removeTransportModeTransforms(pfd);
        } catch (RemoteException e) {
        } catch (RemoteException e) {
@@ -588,6 +584,7 @@ public final class IpSecManager {
    // safely usable for Encapsulation without allowing a user to possibly unbind from/close
    // safely usable for Encapsulation without allowing a user to possibly unbind from/close
    // the port, which could potentially impact the traffic of the next user who binds to that
    // the port, which could potentially impact the traffic of the next user who binds to that
    // socket.
    // socket.
    @NonNull
    public UdpEncapsulationSocket openUdpEncapsulationSocket(int port)
    public UdpEncapsulationSocket openUdpEncapsulationSocket(int port)
            throws IOException, ResourceUnavailableException {
            throws IOException, ResourceUnavailableException {
        /*
        /*
@@ -617,6 +614,7 @@ public final class IpSecManager {
    // safely usable for Encapsulation without allowing a user to possibly unbind from/close
    // safely usable for Encapsulation without allowing a user to possibly unbind from/close
    // the port, which could potentially impact the traffic of the next user who binds to that
    // the port, which could potentially impact the traffic of the next user who binds to that
    // socket.
    // socket.
    @NonNull
    public UdpEncapsulationSocket openUdpEncapsulationSocket()
    public UdpEncapsulationSocket openUdpEncapsulationSocket()
            throws IOException, ResourceUnavailableException {
            throws IOException, ResourceUnavailableException {
        return new UdpEncapsulationSocket(mService, 0);
        return new UdpEncapsulationSocket(mService, 0);
@@ -645,6 +643,7 @@ public final class IpSecManager {
        private int mResourceId = INVALID_RESOURCE_ID;
        private int mResourceId = INVALID_RESOURCE_ID;


        /** Get the underlying SPI held by this object. */
        /** Get the underlying SPI held by this object. */
        @NonNull
        public String getInterfaceName() {
        public String getInterfaceName() {
            return mInterfaceName;
            return mInterfaceName;
        }
        }
@@ -659,7 +658,7 @@ public final class IpSecManager {
         * @hide
         * @hide
         */
         */
        @SystemApi
        @SystemApi
        public void addAddress(LinkAddress address) throws IOException {
        public void addAddress(@NonNull LinkAddress address) throws IOException {
            try {
            try {
                mService.addAddressToTunnelInterface(mResourceId, address);
                mService.addAddressToTunnelInterface(mResourceId, address);
            } catch (RemoteException e) {
            } catch (RemoteException e) {
@@ -676,7 +675,7 @@ public final class IpSecManager {
         * @hide
         * @hide
         */
         */
        @SystemApi
        @SystemApi
        public void removeAddress(LinkAddress address) throws IOException {
        public void removeAddress(@NonNull LinkAddress address) throws IOException {
            try {
            try {
                mService.removeAddressFromTunnelInterface(mResourceId, address);
                mService.removeAddressFromTunnelInterface(mResourceId, address);
            } catch (RemoteException e) {
            } catch (RemoteException e) {
@@ -768,6 +767,7 @@ public final class IpSecManager {
     * @hide
     * @hide
     */
     */
    @SystemApi
    @SystemApi
    @NonNull
    @RequiresPermission(android.Manifest.permission.NETWORK_STACK)
    @RequiresPermission(android.Manifest.permission.NETWORK_STACK)
    public IpSecTunnelInterface createIpSecTunnelInterface(@NonNull InetAddress localAddress,
    public IpSecTunnelInterface createIpSecTunnelInterface(@NonNull InetAddress localAddress,
            @NonNull InetAddress remoteAddress, @NonNull Network underlyingNetwork)
            @NonNull InetAddress remoteAddress, @NonNull Network underlyingNetwork)
@@ -794,8 +794,8 @@ public final class IpSecManager {
     */
     */
    @SystemApi
    @SystemApi
    @RequiresPermission(android.Manifest.permission.NETWORK_STACK)
    @RequiresPermission(android.Manifest.permission.NETWORK_STACK)
    public void applyTunnelModeTransform(IpSecTunnelInterface tunnel,
    public void applyTunnelModeTransform(@NonNull IpSecTunnelInterface tunnel,
            @PolicyDirection int direction, IpSecTransform transform) throws IOException {
            @PolicyDirection int direction, @NonNull IpSecTransform transform) throws IOException {
        try {
        try {
            mService.applyTunnelModeTransform(
            mService.applyTunnelModeTransform(
                    tunnel.getResourceId(), direction, transform.getResourceId());
                    tunnel.getResourceId(), direction, transform.getResourceId());
+6 −0
Original line number Original line Diff line number Diff line
@@ -350,6 +350,7 @@ public final class IpSecTransform implements AutoCloseable {
         *
         *
         * @param algo {@link IpSecAlgorithm} specifying the encryption to be applied.
         * @param algo {@link IpSecAlgorithm} specifying the encryption to be applied.
         */
         */
        @NonNull
        public IpSecTransform.Builder setEncryption(@NonNull IpSecAlgorithm algo) {
        public IpSecTransform.Builder setEncryption(@NonNull IpSecAlgorithm algo) {
            // TODO: throw IllegalArgumentException if algo is not an encryption algorithm.
            // TODO: throw IllegalArgumentException if algo is not an encryption algorithm.
            Preconditions.checkNotNull(algo);
            Preconditions.checkNotNull(algo);
@@ -364,6 +365,7 @@ public final class IpSecTransform implements AutoCloseable {
         *
         *
         * @param algo {@link IpSecAlgorithm} specifying the authentication to be applied.
         * @param algo {@link IpSecAlgorithm} specifying the authentication to be applied.
         */
         */
        @NonNull
        public IpSecTransform.Builder setAuthentication(@NonNull IpSecAlgorithm algo) {
        public IpSecTransform.Builder setAuthentication(@NonNull IpSecAlgorithm algo) {
            // TODO: throw IllegalArgumentException if algo is not an authentication algorithm.
            // TODO: throw IllegalArgumentException if algo is not an authentication algorithm.
            Preconditions.checkNotNull(algo);
            Preconditions.checkNotNull(algo);
@@ -384,6 +386,7 @@ public final class IpSecTransform implements AutoCloseable {
         * @param algo {@link IpSecAlgorithm} specifying the authenticated encryption algorithm to
         * @param algo {@link IpSecAlgorithm} specifying the authenticated encryption algorithm to
         *     be applied.
         *     be applied.
         */
         */
        @NonNull
        public IpSecTransform.Builder setAuthenticatedEncryption(@NonNull IpSecAlgorithm algo) {
        public IpSecTransform.Builder setAuthenticatedEncryption(@NonNull IpSecAlgorithm algo) {
            Preconditions.checkNotNull(algo);
            Preconditions.checkNotNull(algo);
            mConfig.setAuthenticatedEncryption(algo);
            mConfig.setAuthenticatedEncryption(algo);
@@ -403,6 +406,7 @@ public final class IpSecTransform implements AutoCloseable {
         * @param remotePort the UDP port number of the remote host that will send and receive
         * @param remotePort the UDP port number of the remote host that will send and receive
         *     encapsulated traffic. In the case of IKEv2, this should be port 4500.
         *     encapsulated traffic. In the case of IKEv2, this should be port 4500.
         */
         */
        @NonNull
        public IpSecTransform.Builder setIpv4Encapsulation(
        public IpSecTransform.Builder setIpv4Encapsulation(
                @NonNull IpSecManager.UdpEncapsulationSocket localSocket, int remotePort) {
                @NonNull IpSecManager.UdpEncapsulationSocket localSocket, int remotePort) {
            Preconditions.checkNotNull(localSocket);
            Preconditions.checkNotNull(localSocket);
@@ -436,6 +440,7 @@ public final class IpSecTransform implements AutoCloseable {
         *     collides with an existing transform
         *     collides with an existing transform
         * @throws IOException indicating other errors
         * @throws IOException indicating other errors
         */
         */
        @NonNull
        public IpSecTransform buildTransportModeTransform(
        public IpSecTransform buildTransportModeTransform(
                @NonNull InetAddress sourceAddress,
                @NonNull InetAddress sourceAddress,
                @NonNull IpSecManager.SecurityParameterIndex spi)
                @NonNull IpSecManager.SecurityParameterIndex spi)
@@ -472,6 +477,7 @@ public final class IpSecTransform implements AutoCloseable {
         * @hide
         * @hide
         */
         */
        @SystemApi
        @SystemApi
        @NonNull
        @RequiresPermission(android.Manifest.permission.NETWORK_STACK)
        @RequiresPermission(android.Manifest.permission.NETWORK_STACK)
        public IpSecTransform buildTunnelModeTransform(
        public IpSecTransform buildTunnelModeTransform(
                @NonNull InetAddress sourceAddress,
                @NonNull InetAddress sourceAddress,