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
This commit is contained in:
parent
e3e9f5622b
commit
f0b261e7cc
7 changed files with 24 additions and 76 deletions
|
|
@ -2279,23 +2279,12 @@ public class ConnectivityManager {
|
|||
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 @@ public class ConnectivityManager {
|
|||
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 @@ public class ConnectivityManager {
|
|||
final long token = Binder.clearCallingIdentity();
|
||||
try {
|
||||
mExecutor.execute(() -> {
|
||||
mSlot = null;
|
||||
callback.onStopped();
|
||||
});
|
||||
} finally {
|
||||
|
|
@ -2344,7 +2331,6 @@ public class ConnectivityManager {
|
|||
final long token = Binder.clearCallingIdentity();
|
||||
try {
|
||||
mExecutor.execute(() -> {
|
||||
mSlot = null;
|
||||
callback.onError(error);
|
||||
});
|
||||
} finally {
|
||||
|
|
|
|||
|
|
@ -193,7 +193,7 @@ interface IConnectivityManager
|
|||
void startTcpKeepalive(in Network network, in ParcelFileDescriptor pfd, int intervalSeconds,
|
||||
in ISocketKeepaliveCallback cb);
|
||||
|
||||
void stopKeepalive(in Network network, int slot);
|
||||
void stopKeepalive(in ISocketKeepaliveCallback cb);
|
||||
|
||||
String getCaptivePortalServerUrl();
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ package android.net;
|
|||
oneway interface ISocketKeepaliveCallback
|
||||
{
|
||||
/** The keepalive was successfully started. */
|
||||
void onStarted(int slot);
|
||||
void onStarted();
|
||||
/** The keepalive was successfully stopped. */
|
||||
void onStopped();
|
||||
/** The keepalive was stopped because of an error. */
|
||||
|
|
|
|||
|
|
@ -91,9 +91,7 @@ public final class NattSocketKeepalive extends SocketKeepalive {
|
|||
protected void stopImpl() {
|
||||
mExecutor.execute(() -> {
|
||||
try {
|
||||
if (mSlot != null) {
|
||||
mService.stopKeepalive(mNetwork, mSlot);
|
||||
}
|
||||
mService.stopKeepalive(mCallback);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "Error stopping socket keepalive: ", e);
|
||||
throw e.rethrowFromSystemServer();
|
||||
|
|
|
|||
|
|
@ -291,7 +291,9 @@ public abstract class NetworkAgent {
|
|||
/**
|
||||
* Requests that the specified keepalive packet be stopped.
|
||||
*
|
||||
* arg1 = hardware slot number of the keepalive to stop.
|
||||
* arg1 = unused
|
||||
* arg2 = error code (SUCCESS)
|
||||
* obj = callback to identify the keepalive
|
||||
*
|
||||
* Also used internally by ConnectivityService / KeepaliveTracker, with different semantics.
|
||||
* @hide
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ import static android.annotation.SystemApi.Client.PRIVILEGED_APPS;
|
|||
import android.annotation.IntDef;
|
||||
import android.annotation.IntRange;
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.SystemApi;
|
||||
import android.os.Binder;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
|
|
@ -249,9 +248,6 @@ public abstract class SocketKeepalive implements AutoCloseable {
|
|||
@NonNull protected final Executor mExecutor;
|
||||
/** @hide */
|
||||
@NonNull protected final ISocketKeepaliveCallback mCallback;
|
||||
// TODO: remove slot since mCallback could be used to identify which keepalive to stop.
|
||||
/** @hide */
|
||||
@Nullable protected Integer mSlot;
|
||||
|
||||
/** @hide */
|
||||
public SocketKeepalive(@NonNull IConnectivityManager service, @NonNull Network network,
|
||||
|
|
@ -263,11 +259,10 @@ public abstract class SocketKeepalive implements AutoCloseable {
|
|||
mExecutor = executor;
|
||||
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 {
|
||||
|
|
@ -280,7 +275,6 @@ public abstract class SocketKeepalive implements AutoCloseable {
|
|||
final long token = Binder.clearCallingIdentity();
|
||||
try {
|
||||
executor.execute(() -> {
|
||||
mSlot = null;
|
||||
callback.onStopped();
|
||||
});
|
||||
} finally {
|
||||
|
|
@ -293,7 +287,6 @@ public abstract class SocketKeepalive implements AutoCloseable {
|
|||
final long token = Binder.clearCallingIdentity();
|
||||
try {
|
||||
executor.execute(() -> {
|
||||
mSlot = null;
|
||||
callback.onError(error);
|
||||
});
|
||||
} finally {
|
||||
|
|
@ -306,7 +299,6 @@ public abstract class SocketKeepalive implements AutoCloseable {
|
|||
final long token = Binder.clearCallingIdentity();
|
||||
try {
|
||||
executor.execute(() -> {
|
||||
mSlot = null;
|
||||
callback.onDataReceived();
|
||||
});
|
||||
} finally {
|
||||
|
|
|
|||
|
|
@ -69,9 +69,7 @@ public final class TcpSocketKeepalive extends SocketKeepalive {
|
|||
protected void stopImpl() {
|
||||
mExecutor.execute(() -> {
|
||||
try {
|
||||
if (mSlot != null) {
|
||||
mService.stopKeepalive(mNetwork, mSlot);
|
||||
}
|
||||
mService.stopKeepalive(mCallback);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "Error stopping packet keepalive: ", e);
|
||||
throw e.rethrowFromSystemServer();
|
||||
|
|
|
|||
Loading…
Reference in a new issue