diff options
| author | 2023-02-20 16:21:02 +0000 | |
|---|---|---|
| committer | 2023-02-20 16:21:02 +0000 | |
| commit | 86fb6b2c3b550e43fa1c0fb45d464ab5ab688941 (patch) | |
| tree | 2b3a2430a80f169cdca6127de6f9021f9c5f7291 | |
| parent | c8353eed0ba9758d74d150962a9054d221a9a1a8 (diff) | |
| parent | 70109e4661680ab041391e02c4a8be8429c06a3c (diff) | |
Merge "Use InetAddress for LowPowerStandbyPortDescription" into udc-dev
| -rw-r--r-- | core/api/system-current.txt | 8 | ||||
| -rw-r--r-- | core/java/android/os/IPowerManager.aidl | 2 | ||||
| -rw-r--r-- | core/java/android/os/PowerManager.java | 45 |
3 files changed, 30 insertions, 25 deletions
diff --git a/core/api/system-current.txt b/core/api/system-current.txt index f544e40d4ff3..e6d636155dcd 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -10719,15 +10719,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 { diff --git a/core/java/android/os/IPowerManager.aidl b/core/java/android/os/IPowerManager.aidl index 80ae8a890c45..6f4cdcef266a 100644 --- a/core/java/android/os/IPowerManager.aidl +++ b/core/java/android/os/IPowerManager.aidl @@ -104,7 +104,7 @@ interface IPowerManager int protocol; int portMatcher; int portNumber; - @nullable String bindAddress; + @nullable byte[] localAddress; } @UnsupportedAppUsage diff --git a/core/java/android/os/PowerManager.java b/core/java/android/os/PowerManager.java index 7fdfba47986d..38e331c4ac0d 100644 --- a/core/java/android/os/PowerManager.java +++ b/core/java/android/os/PowerManager.java @@ -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; @@ -3259,11 +3260,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 = { @@ -3292,7 +3293,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. @@ -3311,7 +3312,7 @@ public final class PowerManager { this.mProtocol = protocol; this.mPortMatcher = portMatcher; this.mPortNumber = portNumber; - this.mBindAddress = null; + this.mLocalAddress = null; } /** @@ -3323,16 +3324,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) { @@ -3398,8 +3399,8 @@ public final class PowerManager { * @see #getProtocol() */ @Nullable - public LinkAddress getBindAddress() { - return mBindAddress; + public InetAddress getLocalAddress() { + return mLocalAddress; } @Override @@ -3408,7 +3409,7 @@ public final class PowerManager { + "mProtocol=" + protocolToString(mProtocol) + ", mPortMatcher=" + portMatcherToString(mPortMatcher) + ", mPortNumber=" + mPortNumber - + ", mBindAddress=" + mBindAddress + + ", mLocalAddress=" + mLocalAddress + '}'; } @@ -3418,13 +3419,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 */ @@ -3439,8 +3440,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; } @@ -3466,15 +3467,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 */ |