[DK3] Send onPause/onResume keepalive callbacks
Test: CTS in the patch immediately on top of this, [DK4]
Change-Id: I208ceceb37c7977452479361f70f046fabafb37a
diff --git a/framework/src/android/net/ConnectivityManager.java b/framework/src/android/net/ConnectivityManager.java
index 17389b4..497c105 100644
--- a/framework/src/android/net/ConnectivityManager.java
+++ b/framework/src/android/net/ConnectivityManager.java
@@ -2213,9 +2213,13 @@
/** The requested keepalive was successfully started. */
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public void onStarted() {}
+ /** The keepalive was resumed after being paused by the system. */
+ public void onResumed() {}
/** The keepalive was successfully stopped. */
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public void onStopped() {}
+ /** The keepalive was paused automatically by the system. */
+ public void onPaused() {}
/** An error occurred. */
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public void onError(int error) {}
@@ -2314,6 +2318,18 @@
}
@Override
+ public void onResumed() {
+ final long token = Binder.clearCallingIdentity();
+ try {
+ mExecutor.execute(() -> {
+ callback.onResumed();
+ });
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
+ }
+
+ @Override
public void onStopped() {
final long token = Binder.clearCallingIdentity();
try {
@@ -2327,6 +2343,19 @@
}
@Override
+ public void onPaused() {
+ final long token = Binder.clearCallingIdentity();
+ try {
+ mExecutor.execute(() -> {
+ callback.onPaused();
+ });
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
+ mExecutor.shutdown();
+ }
+
+ @Override
public void onError(int error) {
final long token = Binder.clearCallingIdentity();
try {
diff --git a/framework/src/android/net/ISocketKeepaliveCallback.aidl b/framework/src/android/net/ISocketKeepaliveCallback.aidl
index 1240e37..0a1de6c 100644
--- a/framework/src/android/net/ISocketKeepaliveCallback.aidl
+++ b/framework/src/android/net/ISocketKeepaliveCallback.aidl
@@ -31,4 +31,8 @@
void onError(int error);
/** The keepalive on a TCP socket was stopped because the socket received data. */
void onDataReceived();
+ /** The keepalive was paused by the system because it's not necessary right now. */
+ void onPaused();
+ /** The keepalive was resumed by the system after being suspended. */
+ void onResumed();
}
diff --git a/framework/src/android/net/SocketKeepalive.java b/framework/src/android/net/SocketKeepalive.java
index 2911ce7..00104f6 100644
--- a/framework/src/android/net/SocketKeepalive.java
+++ b/framework/src/android/net/SocketKeepalive.java
@@ -64,6 +64,12 @@
public static final int SUCCESS = 0;
/**
+ * Success when trying to suspend.
+ * @hide
+ */
+ public static final int SUCCESS_PAUSED = 1;
+
+ /**
* No keepalive. This should only be internally as it indicates There is no keepalive.
* It should not propagate to applications.
* @hide
@@ -271,6 +277,18 @@
}
@Override
+ public void onResumed() {
+ final long token = Binder.clearCallingIdentity();
+ try {
+ mExecutor.execute(() -> {
+ callback.onResumed();
+ });
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
+ }
+
+ @Override
public void onStopped() {
final long token = Binder.clearCallingIdentity();
try {
@@ -283,6 +301,18 @@
}
@Override
+ public void onPaused() {
+ final long token = Binder.clearCallingIdentity();
+ try {
+ executor.execute(() -> {
+ callback.onPaused();
+ });
+ } finally {
+ Binder.restoreCallingIdentity(token);
+ }
+ }
+
+ @Override
public void onError(int error) {
final long token = Binder.clearCallingIdentity();
try {
@@ -387,8 +417,18 @@
public static class Callback {
/** The requested keepalive was successfully started. */
public void onStarted() {}
+ /**
+ * The keepalive was resumed by the system after being suspended.
+ * @hide
+ **/
+ public void onResumed() {}
/** The keepalive was successfully stopped. */
public void onStopped() {}
+ /**
+ * The keepalive was paused by the system because it's not necessary right now.
+ * @hide
+ **/
+ public void onPaused() {}
/** An error occurred. */
public void onError(@ErrorCode int error) {}
/** The keepalive on a TCP socket was stopped because the socket received data. This is