Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 39efdb24 authored by Chiachang Wang's avatar Chiachang Wang Committed by Gerrit Code Review
Browse files

Merge "Use ParcelFileDescriptor instead of FileDescriptor in the aidl"

parents e8bf3e90 92b94e1e
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -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);
+1 −1
Original line number Original line Diff line number Diff line
@@ -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) {
+1 −3
Original line number Original line Diff line number Diff line
@@ -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();
+8 −6
Original line number Original line Diff line number Diff line
@@ -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);
            }
            }
        }
        }
    }
    }