Merge changes I99d494d3,I208ceceb

* changes:
  [DK4-0]Add CM#setTestLowTcpPollingTimerForKeepalive for testing
  [DK3] Send onPause/onResume keepalive callbacks
This commit is contained in:
Jean Chalard
2023-02-13 05:06:20 +00:00
committed by Gerrit Code Review
7 changed files with 236 additions and 15 deletions

View File

@@ -1501,6 +1501,22 @@ public class ConnectivityManager {
}
}
/**
* Temporarily set automaticOnOff keeplaive TCP polling alarm timer to 1 second.
*
* TODO: Remove this when the TCP polling design is replaced with callback.
* @params timeMs The time of expiry, with System.currentTimeMillis() base. The value should be
* set no more than 5 minutes in the future.
* @hide
*/
public void setTestLowTcpPollingTimerForKeepalive(long timeMs) {
try {
mService.setTestLowTcpPollingTimerForKeepalive(timeMs);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Informs ConnectivityService of whether the legacy lockdown VPN, as implemented by
* LockdownVpnTracker, is in use. This is deprecated for new devices starting from Android 12
@@ -2213,9 +2229,13 @@ public class ConnectivityManager {
/** 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) {}
@@ -2313,6 +2333,18 @@ public class ConnectivityManager {
}
}
@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();
@@ -2326,6 +2358,19 @@ public class ConnectivityManager {
mExecutor.shutdown();
}
@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();

View File

@@ -251,4 +251,6 @@ interface IConnectivityManager
IBinder getCompanionDeviceManagerProxyService();
void setVpnNetworkPreference(String session, in UidRange[] ranges);
void setTestLowTcpPollingTimerForKeepalive(long timeMs);
}

View File

@@ -31,4 +31,8 @@ oneway interface ISocketKeepaliveCallback
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();
}

View File

@@ -63,6 +63,12 @@ public abstract class SocketKeepalive implements AutoCloseable {
@SystemApi
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.
@@ -270,6 +276,18 @@ public abstract class SocketKeepalive implements AutoCloseable {
}
}
@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();
@@ -282,6 +300,18 @@ public abstract class SocketKeepalive implements AutoCloseable {
}
}
@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();
@@ -387,8 +417,18 @@ public abstract class SocketKeepalive implements AutoCloseable {
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