Use the binder to identify keepalive in IConnectivityManager
This is much simpler and less error-prone, as well as less
subject to race conditions.
It also allows for cleaning up some TODOs.
Test: FrameworksNetTests
CtsNetTestCases
Bug: 267116236
Change-Id: I470c709446946ef35a0324427defe2f58b434339
diff --git a/framework/src/android/net/ConnectivityManager.java b/framework/src/android/net/ConnectivityManager.java
index 4224da9..17389b4 100644
--- a/framework/src/android/net/ConnectivityManager.java
+++ b/framework/src/android/net/ConnectivityManager.java
@@ -2279,23 +2279,12 @@
private final ISocketKeepaliveCallback mCallback;
private final ExecutorService mExecutor;
- private volatile Integer mSlot;
-
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public void stop() {
try {
mExecutor.execute(() -> {
try {
- if (mSlot != null) {
- // TODO : this is incorrect, because in the presence of auto on/off
- // keepalive the slot associated with this keepalive can have
- // changed. Also, this actually causes another problem where some other
- // app might stop your keepalive if it just knows the network and
- // the slot and goes through the trouble of grabbing the aidl object.
- // This code should use the callback to identify what keepalive to
- // stop instead.
- mService.stopKeepalive(mNetwork, mSlot);
- }
+ mService.stopKeepalive(mCallback);
} catch (RemoteException e) {
Log.e(TAG, "Error stopping packet keepalive: ", e);
throw e.rethrowFromSystemServer();
@@ -2313,11 +2302,10 @@
mExecutor = Executors.newSingleThreadExecutor();
mCallback = new ISocketKeepaliveCallback.Stub() {
@Override
- public void onStarted(int slot) {
+ public void onStarted() {
final long token = Binder.clearCallingIdentity();
try {
mExecutor.execute(() -> {
- mSlot = slot;
callback.onStarted();
});
} finally {
@@ -2330,7 +2318,6 @@
final long token = Binder.clearCallingIdentity();
try {
mExecutor.execute(() -> {
- mSlot = null;
callback.onStopped();
});
} finally {
@@ -2344,7 +2331,6 @@
final long token = Binder.clearCallingIdentity();
try {
mExecutor.execute(() -> {
- mSlot = null;
callback.onError(error);
});
} finally {