Merge "Use ParcelFileDescriptor instead of FileDescriptor in the aidl" am: 39efdb2451
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1554098 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: I9b7818c5fc851a5b2a1406caec0db3dac3ff55c7
This commit is contained in:
@@ -206,11 +206,11 @@ interface IConnectivityManager
|
|||||||
void startNattKeepalive(in Network network, int intervalSeconds,
|
void startNattKeepalive(in Network network, int intervalSeconds,
|
||||||
in ISocketKeepaliveCallback cb, String srcAddr, int srcPort, String dstAddr);
|
in ISocketKeepaliveCallback cb, String srcAddr, int srcPort, String dstAddr);
|
||||||
|
|
||||||
void startNattKeepaliveWithFd(in Network network, in FileDescriptor fd, int resourceId,
|
void startNattKeepaliveWithFd(in Network network, in ParcelFileDescriptor pfd, int resourceId,
|
||||||
int intervalSeconds, in ISocketKeepaliveCallback cb, String srcAddr,
|
int intervalSeconds, in ISocketKeepaliveCallback cb, String srcAddr,
|
||||||
String dstAddr);
|
String dstAddr);
|
||||||
|
|
||||||
void startTcpKeepalive(in Network network, in FileDescriptor fd, int intervalSeconds,
|
void startTcpKeepalive(in Network network, in ParcelFileDescriptor pfd, int intervalSeconds,
|
||||||
in ISocketKeepaliveCallback cb);
|
in ISocketKeepaliveCallback cb);
|
||||||
|
|
||||||
void stopKeepalive(in Network network, int slot);
|
void stopKeepalive(in Network network, int slot);
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public final class NattSocketKeepalive extends SocketKeepalive {
|
|||||||
void startImpl(int intervalSec) {
|
void startImpl(int intervalSec) {
|
||||||
mExecutor.execute(() -> {
|
mExecutor.execute(() -> {
|
||||||
try {
|
try {
|
||||||
mService.startNattKeepaliveWithFd(mNetwork, mPfd.getFileDescriptor(), mResourceId,
|
mService.startNattKeepaliveWithFd(mNetwork, mPfd, mResourceId,
|
||||||
intervalSec, mCallback,
|
intervalSec, mCallback,
|
||||||
mSource.getHostAddress(), mDestination.getHostAddress());
|
mSource.getHostAddress(), mDestination.getHostAddress());
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import android.os.ParcelFileDescriptor;
|
|||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.io.FileDescriptor;
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
@@ -54,8 +53,7 @@ final class TcpSocketKeepalive extends SocketKeepalive {
|
|||||||
void startImpl(int intervalSec) {
|
void startImpl(int intervalSec) {
|
||||||
mExecutor.execute(() -> {
|
mExecutor.execute(() -> {
|
||||||
try {
|
try {
|
||||||
final FileDescriptor fd = mPfd.getFileDescriptor();
|
mService.startTcpKeepalive(mNetwork, mPfd, intervalSec, mCallback);
|
||||||
mService.startTcpKeepalive(mNetwork, fd, intervalSec, mCallback);
|
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Log.e(TAG, "Error starting packet keepalive: ", e);
|
Log.e(TAG, "Error starting packet keepalive: ", e);
|
||||||
throw e.rethrowFromSystemServer();
|
throw e.rethrowFromSystemServer();
|
||||||
|
|||||||
@@ -7912,10 +7912,11 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startNattKeepaliveWithFd(Network network, FileDescriptor fd, int resourceId,
|
public void startNattKeepaliveWithFd(Network network, ParcelFileDescriptor pfd, int resourceId,
|
||||||
int intervalSeconds, ISocketKeepaliveCallback cb, String srcAddr,
|
int intervalSeconds, ISocketKeepaliveCallback cb, String srcAddr,
|
||||||
String dstAddr) {
|
String dstAddr) {
|
||||||
try {
|
try {
|
||||||
|
final FileDescriptor fd = pfd.getFileDescriptor();
|
||||||
mKeepaliveTracker.startNattKeepalive(
|
mKeepaliveTracker.startNattKeepalive(
|
||||||
getNetworkAgentInfoForNetwork(network), fd, resourceId,
|
getNetworkAgentInfoForNetwork(network), fd, resourceId,
|
||||||
intervalSeconds, cb,
|
intervalSeconds, cb,
|
||||||
@@ -7923,24 +7924,25 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
} finally {
|
} finally {
|
||||||
// FileDescriptors coming from AIDL calls must be manually closed to prevent leaks.
|
// FileDescriptors coming from AIDL calls must be manually closed to prevent leaks.
|
||||||
// startNattKeepalive calls Os.dup(fd) before returning, so we can close immediately.
|
// startNattKeepalive calls Os.dup(fd) before returning, so we can close immediately.
|
||||||
if (fd != null && Binder.getCallingPid() != Process.myPid()) {
|
if (pfd != null && Binder.getCallingPid() != Process.myPid()) {
|
||||||
IoUtils.closeQuietly(fd);
|
IoUtils.closeQuietly(pfd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startTcpKeepalive(Network network, FileDescriptor fd, int intervalSeconds,
|
public void startTcpKeepalive(Network network, ParcelFileDescriptor pfd, int intervalSeconds,
|
||||||
ISocketKeepaliveCallback cb) {
|
ISocketKeepaliveCallback cb) {
|
||||||
try {
|
try {
|
||||||
enforceKeepalivePermission();
|
enforceKeepalivePermission();
|
||||||
|
final FileDescriptor fd = pfd.getFileDescriptor();
|
||||||
mKeepaliveTracker.startTcpKeepalive(
|
mKeepaliveTracker.startTcpKeepalive(
|
||||||
getNetworkAgentInfoForNetwork(network), fd, intervalSeconds, cb);
|
getNetworkAgentInfoForNetwork(network), fd, intervalSeconds, cb);
|
||||||
} finally {
|
} finally {
|
||||||
// FileDescriptors coming from AIDL calls must be manually closed to prevent leaks.
|
// FileDescriptors coming from AIDL calls must be manually closed to prevent leaks.
|
||||||
// startTcpKeepalive calls Os.dup(fd) before returning, so we can close immediately.
|
// startTcpKeepalive calls Os.dup(fd) before returning, so we can close immediately.
|
||||||
if (fd != null && Binder.getCallingPid() != Process.myPid()) {
|
if (pfd != null && Binder.getCallingPid() != Process.myPid()) {
|
||||||
IoUtils.closeQuietly(fd);
|
IoUtils.closeQuietly(pfd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user