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

Commit 477c6b67 authored by Robert Horvath's avatar Robert Horvath Committed by Android (Google) Code Review
Browse files

Merge "Use InetAddress for LowPowerStandbyPortDescription"

parents 53bb7542 f7ad2156
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -10720,15 +10720,15 @@ package android.os {
  public static final class PowerManager.LowPowerStandbyPortDescription {
    ctor public PowerManager.LowPowerStandbyPortDescription(int, int, int);
    ctor public PowerManager.LowPowerStandbyPortDescription(int, int, int, @Nullable android.net.LinkAddress);
    method @Nullable public android.net.LinkAddress getBindAddress();
    ctor public PowerManager.LowPowerStandbyPortDescription(int, int, int, @Nullable java.net.InetAddress);
    method @Nullable public java.net.InetAddress getLocalAddress();
    method public int getPortMatcher();
    method public int getPortNumber();
    method public int getProtocol();
    field public static final int MATCH_PORT_LOCAL = 1; // 0x1
    field public static final int MATCH_PORT_REMOTE = 2; // 0x2
    field public static final int PROTOCOL_TCP = 1; // 0x1
    field public static final int PROTOCOL_UDP = 2; // 0x2
    field public static final int PROTOCOL_TCP = 6; // 0x6
    field public static final int PROTOCOL_UDP = 17; // 0x11
  }
  public final class PowerManager.LowPowerStandbyPortsLock {
+1 −1
Original line number Diff line number Diff line
@@ -104,7 +104,7 @@ interface IPowerManager
        int protocol;
        int portMatcher;
        int portNumber;
        @nullable String bindAddress;
        @nullable byte[] localAddress;
    }

    @UnsupportedAppUsage
+25 −20
Original line number Diff line number Diff line
@@ -32,7 +32,6 @@ import android.annotation.TestApi;
import android.app.PropertyInvalidatedCache;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.net.LinkAddress;
import android.service.dreams.Sandman;
import android.sysprop.InitProperties;
import android.util.ArrayMap;
@@ -45,6 +44,8 @@ import com.android.internal.util.Preconditions;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
@@ -3244,11 +3245,11 @@ public final class PowerManager {
        /**
         * Constant to indicate the {@link LowPowerStandbyPortDescription} refers to a TCP port.
         */
        public static final int PROTOCOL_TCP = 1;
        public static final int PROTOCOL_TCP = 6;
        /**
         * Constant to indicate the {@link LowPowerStandbyPortDescription} refers to a UDP port.
         */
        public static final int PROTOCOL_UDP = 2;
        public static final int PROTOCOL_UDP = 17;

        /** @hide */
        @IntDef(prefix = { "MATCH_PORT_" }, value = {
@@ -3277,7 +3278,7 @@ public final class PowerManager {
        private final int mPortMatcher;
        private final int mPortNumber;
        @Nullable
        private final LinkAddress mBindAddress;
        private final InetAddress mLocalAddress;

        /**
         * Describes a port.
@@ -3296,7 +3297,7 @@ public final class PowerManager {
            this.mProtocol = protocol;
            this.mPortMatcher = portMatcher;
            this.mPortNumber = portNumber;
            this.mBindAddress = null;
            this.mLocalAddress = null;
        }

        /**
@@ -3308,16 +3309,16 @@ public final class PowerManager {
         *                    ({@link #MATCH_PORT_REMOTE}), or the destination port
         *                    ({@link #MATCH_PORT_LOCAL}).
         * @param portNumber The port number to match.
         * @param bindAddress The bind address to match.
         * @param localAddress The local address to match.
         *
         * @see #newLowPowerStandbyPortsLock(List)
         */
        public LowPowerStandbyPortDescription(@Protocol int protocol, @PortMatcher int portMatcher,
                int portNumber, @Nullable LinkAddress bindAddress) {
                int portNumber, @Nullable InetAddress localAddress) {
            this.mProtocol = protocol;
            this.mPortMatcher = portMatcher;
            this.mPortNumber = portNumber;
            this.mBindAddress = bindAddress;
            this.mLocalAddress = localAddress;
        }

        private String protocolToString(int protocol) {
@@ -3383,8 +3384,8 @@ public final class PowerManager {
         * @see #getProtocol()
         */
        @Nullable
        public LinkAddress getBindAddress() {
            return mBindAddress;
        public InetAddress getLocalAddress() {
            return mLocalAddress;
        }

        @Override
@@ -3393,7 +3394,7 @@ public final class PowerManager {
                    + "mProtocol=" + protocolToString(mProtocol)
                    + ", mPortMatcher=" + portMatcherToString(mPortMatcher)
                    + ", mPortNumber=" + mPortNumber
                    + ", mBindAddress=" + mBindAddress
                    + ", mLocalAddress=" + mLocalAddress
                    + '}';
        }

@@ -3403,13 +3404,13 @@ public final class PowerManager {
            if (!(o instanceof LowPowerStandbyPortDescription)) return false;
            LowPowerStandbyPortDescription that = (LowPowerStandbyPortDescription) o;
            return mProtocol == that.mProtocol && mPortMatcher == that.mPortMatcher
                    && mPortNumber == that.mPortNumber && Objects.equals(mBindAddress,
                    that.mBindAddress);
                    && mPortNumber == that.mPortNumber && Objects.equals(mLocalAddress,
                    that.mLocalAddress);
        }

        @Override
        public int hashCode() {
            return Objects.hash(mProtocol, mPortMatcher, mPortNumber, mBindAddress);
            return Objects.hash(mProtocol, mPortMatcher, mPortNumber, mLocalAddress);
        }

        /** @hide */
@@ -3424,8 +3425,8 @@ public final class PowerManager {
            parcelablePortDescription.protocol = portDescription.mProtocol;
            parcelablePortDescription.portMatcher = portDescription.mPortMatcher;
            parcelablePortDescription.portNumber = portDescription.mPortNumber;
            if (portDescription.mBindAddress != null) {
                parcelablePortDescription.bindAddress = portDescription.mBindAddress.toString();
            if (portDescription.mLocalAddress != null) {
                parcelablePortDescription.localAddress = portDescription.mLocalAddress.getAddress();
            }
            return parcelablePortDescription;
        }
@@ -3451,15 +3452,19 @@ public final class PowerManager {
                return null;
            }

            LinkAddress bindAddress = null;
            if (parcelablePortDescription.bindAddress != null) {
                bindAddress = new LinkAddress(parcelablePortDescription.bindAddress);
            InetAddress localAddress = null;
            if (parcelablePortDescription.localAddress != null) {
                try {
                    localAddress = InetAddress.getByAddress(parcelablePortDescription.localAddress);
                } catch (UnknownHostException e) {
                    Log.w(TAG, "Address has invalid length", e);
                }
            }
            return new LowPowerStandbyPortDescription(
                    parcelablePortDescription.protocol,
                    parcelablePortDescription.portMatcher,
                    parcelablePortDescription.portNumber,
                    bindAddress);
                    localAddress);
        }

        /** @hide */