summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Robert Horvath <robhor@google.com> 2023-02-16 16:01:24 +0100
committer Cherrypicker Worker <android-build-cherrypicker-worker@google.com> 2023-02-17 15:33:31 +0000
commit70109e4661680ab041391e02c4a8be8429c06a3c (patch)
tree16382f24a4a2dc573f196a6ffdaccb06b7559d08
parent0b0ce87c4cc2bde2fbcf05b3c0d8e3cdc9c14ab0 (diff)
Use InetAddress for LowPowerStandbyPortDescription
Changes to LowPowerStandbyPortDescription: 1. The value of the PROTOCOL constants are updated to be the defined IP protocol numbers for those protocols 2. LinkAddress is changed to InetAddress 3. The "bindAddress" parameter is renamed to "localAddress" Bug: 234002812 Test: atest LowPowerStandbyTest LowPowerStandbyControllerTest Change-Id: Ib152bf621c006871add8b5e90a380e87a93985ad (cherry picked from commit f7ad2156a265fe9b1310d7f14453f1fabf0aead0) Merged-In: Ib152bf621c006871add8b5e90a380e87a93985ad
-rw-r--r--core/api/system-current.txt8
-rw-r--r--core/java/android/os/IPowerManager.aidl2
-rw-r--r--core/java/android/os/PowerManager.java45
3 files changed, 30 insertions, 25 deletions
diff --git a/core/api/system-current.txt b/core/api/system-current.txt
index 6581c421f970..0c5640192069 100644
--- a/core/api/system-current.txt
+++ b/core/api/system-current.txt
@@ -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 {
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 1a634f5ee33e..122494198b63 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;
@@ -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 */