Use ParcelFileDescriptor instead of FileDescriptor in INetd.aidl

Stable aidl won't support FileDescriptor but ParcelFileDescriptor.
In order to migrate to stable aidl, replace all FileDescriptor in
INdetd.aidl.

Test: built, flashed, booted
      system/netd/tests/runtests.sh passes

Change-Id: I331626346959f127b4c1cb2ece33db37cb8dc550
diff --git a/server/NetdNativeService.cpp b/server/NetdNativeService.cpp
index 3e153ec..fdf55b4 100644
--- a/server/NetdNativeService.cpp
+++ b/server/NetdNativeService.cpp
@@ -50,6 +50,7 @@
 using android::base::StringPrintf;
 using android::net::TetherStatsParcel;
 using android::net::UidRangeParcel;
+using android::os::ParcelFileDescriptor;
 
 namespace android {
 namespace net {
@@ -738,13 +739,14 @@
             : binder::Status::fromExceptionCode(binder::Status::EX_ILLEGAL_ARGUMENT);
 }
 
-binder::Status NetdNativeService::ipSecSetEncapSocketOwner(const android::base::unique_fd& socket,
-                                                      int newUid) {
+binder::Status NetdNativeService::ipSecSetEncapSocketOwner(const ParcelFileDescriptor& socket,
+                                                           int newUid) {
     ENFORCE_PERMISSION(NETWORK_STACK)
     gLog.log("ipSecSetEncapSocketOwner()");
 
     uid_t callerUid = IPCThreadState::self()->getCallingUid();
-    return asBinderStatus(gCtls->xfrmCtrl.ipSecSetEncapSocketOwner(socket, newUid, callerUid));
+    return asBinderStatus(
+            gCtls->xfrmCtrl.ipSecSetEncapSocketOwner(socket.get(), newUid, callerUid));
 }
 
 binder::Status NetdNativeService::ipSecAllocateSpi(
@@ -794,31 +796,21 @@
 }
 
 binder::Status NetdNativeService::ipSecApplyTransportModeTransform(
-        const android::base::unique_fd& socket,
-        int32_t transformId,
-        int32_t direction,
-        const std::string& sourceAddress,
-        const std::string& destinationAddress,
-        int32_t spi) {
+        const ParcelFileDescriptor& socket, int32_t transformId, int32_t direction,
+        const std::string& sourceAddress, const std::string& destinationAddress, int32_t spi) {
     // Necessary locking done in IpSecService and kernel
     ENFORCE_PERMISSION(CONNECTIVITY_INTERNAL);
     gLog.log("ipSecApplyTransportModeTransform()");
     return asBinderStatus(gCtls->xfrmCtrl.ipSecApplyTransportModeTransform(
-                    socket,
-                    transformId,
-                    direction,
-                    sourceAddress,
-                    destinationAddress,
-                    spi));
+            socket.get(), transformId, direction, sourceAddress, destinationAddress, spi));
 }
 
 binder::Status NetdNativeService::ipSecRemoveTransportModeTransform(
-            const android::base::unique_fd& socket) {
+        const ParcelFileDescriptor& socket) {
     // Necessary locking done in IpSecService and kernel
     ENFORCE_PERMISSION(CONNECTIVITY_INTERNAL);
     gLog.log("ipSecRemoveTransportModeTransform()");
-    return asBinderStatus(gCtls->xfrmCtrl.ipSecRemoveTransportModeTransform(
-                    socket));
+    return asBinderStatus(gCtls->xfrmCtrl.ipSecRemoveTransportModeTransform(socket.get()));
 }
 
 binder::Status NetdNativeService::ipSecAddSecurityPolicy(int32_t transformId, int32_t selAddrFamily,
diff --git a/server/NetdNativeService.h b/server/NetdNativeService.h
index c03853a..0160cf1 100644
--- a/server/NetdNativeService.h
+++ b/server/NetdNativeService.h
@@ -157,7 +157,7 @@
     binder::Status getMetricsReportingLevel(int *reportingLevel) override;
     binder::Status setMetricsReportingLevel(const int reportingLevel) override;
 
-    binder::Status ipSecSetEncapSocketOwner(const android::base::unique_fd& socket, int newUid);
+    binder::Status ipSecSetEncapSocketOwner(const os::ParcelFileDescriptor& socket, int newUid);
 
     binder::Status ipSecAllocateSpi(
             int32_t transformId,
@@ -182,16 +182,13 @@
                                                   int32_t spi, int32_t markValue, int32_t markMask,
                                                   int32_t interfaceId);
 
-    binder::Status ipSecApplyTransportModeTransform(
-            const android::base::unique_fd& socket,
-            int32_t transformId,
-            int32_t direction,
-            const std::string& sourceAddress,
-            const std::string& destinationAddress,
-            int32_t spi);
+    binder::Status ipSecApplyTransportModeTransform(const os::ParcelFileDescriptor& socket,
+                                                    int32_t transformId, int32_t direction,
+                                                    const std::string& sourceAddress,
+                                                    const std::string& destinationAddress,
+                                                    int32_t spi);
 
-    binder::Status ipSecRemoveTransportModeTransform(
-            const android::base::unique_fd& socket);
+    binder::Status ipSecRemoveTransportModeTransform(const os::ParcelFileDescriptor& socket);
 
     binder::Status ipSecAddSecurityPolicy(int32_t transformId, int32_t selAddrFamily,
                                           int32_t direction, const std::string& tmplSrcAddress,
diff --git a/server/XfrmController.cpp b/server/XfrmController.cpp
index 684f5e9..de9aa0b 100644
--- a/server/XfrmController.cpp
+++ b/server/XfrmController.cpp
@@ -451,11 +451,11 @@
     return !errored;
 }
 
-netdutils::Status XfrmController::ipSecSetEncapSocketOwner(const android::base::unique_fd& socket,
-                                                           int newUid, uid_t callerUid) {
+netdutils::Status XfrmController::ipSecSetEncapSocketOwner(int socketFd, int newUid,
+                                                           uid_t callerUid) {
     ALOGD("XfrmController:%s, line=%d", __FUNCTION__, __LINE__);
 
-    const int fd = socket.get();
+    const int fd = socketFd;
     struct stat info;
     if (fstat(fd, &info)) {
         return netdutils::statusFromErrno(errno, "Failed to stat socket file descriptor");
@@ -470,7 +470,7 @@
     int optval;
     socklen_t optlen = sizeof(optval);
     netdutils::Status status =
-        getSyscallInstance().getsockopt(Fd(socket), IPPROTO_UDP, UDP_ENCAP, &optval, &optlen);
+            getSyscallInstance().getsockopt(Fd(fd), IPPROTO_UDP, UDP_ENCAP, &optval, &optlen);
     if (status != netdutils::status::ok) {
         return status;
     }
@@ -695,8 +695,8 @@
 }
 
 netdutils::Status XfrmController::ipSecApplyTransportModeTransform(
-    const android::base::unique_fd& socket, int32_t transformId, int32_t direction,
-    const std::string& sourceAddress, const std::string& destinationAddress, int32_t spi) {
+        int socketFd, int32_t transformId, int32_t direction, const std::string& sourceAddress,
+        const std::string& destinationAddress, int32_t spi) {
     ALOGD("XfrmController::%s, line=%d", __FUNCTION__, __LINE__);
     ALOGD("transformId=%d", transformId);
     ALOGD("direction=%d", direction);
@@ -704,7 +704,8 @@
     ALOGD("destinationAddress=%s", destinationAddress.c_str());
     ALOGD("spi=%0.8x", spi);
 
-    StatusOr<sockaddr_storage> ret = getSyscallInstance().getsockname<sockaddr_storage>(Fd(socket));
+    StatusOr<sockaddr_storage> ret =
+            getSyscallInstance().getsockname<sockaddr_storage>(Fd(socketFd));
     if (!isOk(ret)) {
         ALOGE("Failed to get socket info in %s", __FUNCTION__);
         return ret;
@@ -755,7 +756,7 @@
             return netdutils::statusFromErrno(EAFNOSUPPORT, "Invalid address family");
     }
 
-    status = getSyscallInstance().setsockopt(Fd(socket), sockLayer, sockOpt, policy);
+    status = getSyscallInstance().setsockopt(Fd(socketFd), sockLayer, sockOpt, policy);
     if (!isOk(status)) {
         ALOGE("Error setting socket option for XFRM! (%s)", toString(status).c_str());
     }
@@ -763,11 +764,11 @@
     return status;
 }
 
-netdutils::Status
-XfrmController::ipSecRemoveTransportModeTransform(const android::base::unique_fd& socket) {
+netdutils::Status XfrmController::ipSecRemoveTransportModeTransform(int socketFd) {
     ALOGD("XfrmController::%s, line=%d", __FUNCTION__, __LINE__);
 
-    StatusOr<sockaddr_storage> ret = getSyscallInstance().getsockname<sockaddr_storage>(Fd(socket));
+    StatusOr<sockaddr_storage> ret =
+            getSyscallInstance().getsockname<sockaddr_storage>(Fd(socketFd));
     if (!isOk(ret)) {
         ALOGE("Failed to get socket info in %s! (%s)", __FUNCTION__, toString(ret).c_str());
         return ret;
@@ -790,7 +791,7 @@
     // Kernel will delete the security policy on this socket for both direction
     // if optval is set to NULL and optlen is set to 0.
     netdutils::Status status =
-        getSyscallInstance().setsockopt(Fd(socket), sockLayer, sockOpt, nullptr, 0);
+            getSyscallInstance().setsockopt(Fd(socketFd), sockLayer, sockOpt, nullptr, 0);
     if (!isOk(status)) {
         ALOGE("Error removing socket option for XFRM! (%s)", toString(status).c_str());
     }
diff --git a/server/XfrmController.h b/server/XfrmController.h
index bba84e2..cc12c38 100644
--- a/server/XfrmController.h
+++ b/server/XfrmController.h
@@ -141,8 +141,7 @@
 
     static netdutils::Status Init();
 
-    static netdutils::Status ipSecSetEncapSocketOwner(const android::base::unique_fd& socket,
-                                                      int newUid, uid_t callerUid);
+    static netdutils::Status ipSecSetEncapSocketOwner(int socketFd, int newUid, uid_t callerUid);
 
     static netdutils::Status ipSecAllocateSpi(int32_t transformId, const std::string& localAddress,
                                               const std::string& remoteAddress, int32_t inSpi,
@@ -165,13 +164,13 @@
                                                             int32_t markMask,
                                                             int32_t xfrmInterfaceId);
 
-    static netdutils::Status
-    ipSecApplyTransportModeTransform(const android::base::unique_fd& socket, int32_t transformId,
-                                     int32_t direction, const std::string& localAddress,
-                                     const std::string& remoteAddress, int32_t spi);
+    static netdutils::Status ipSecApplyTransportModeTransform(int socketFd, int32_t transformId,
+                                                              int32_t direction,
+                                                              const std::string& localAddress,
+                                                              const std::string& remoteAddress,
+                                                              int32_t spi);
 
-    static netdutils::Status
-    ipSecRemoveTransportModeTransform(const android::base::unique_fd& socket);
+    static netdutils::Status ipSecRemoveTransportModeTransform(int socketFd);
 
     static netdutils::Status ipSecAddSecurityPolicy(int32_t transformId, int32_t selAddrFamily,
                                                     int32_t direction,
diff --git a/server/binder/android/net/INetd.aidl b/server/binder/android/net/INetd.aidl
index bc7b26e..d2a4125 100644
--- a/server/binder/android/net/INetd.aidl
+++ b/server/binder/android/net/INetd.aidl
@@ -315,13 +315,13 @@
     void setMetricsReportingLevel(int level);
 
    /**
-    * Sets owner of socket FileDescriptor to the new UID, checking to ensure that the caller's
+    * Sets owner of socket ParcelFileDescriptor to the new UID, checking to ensure that the caller's
     * uid is that of the old owner's, and that this is a UDP-encap socket
     *
-    * @param FileDescriptor socket Socket file descriptor
+    * @param ParcelFileDescriptor socket Socket file descriptor
     * @param int newUid UID of the new socket fd owner
     */
-    void ipSecSetEncapSocketOwner(in FileDescriptor socket, int newUid);
+    void ipSecSetEncapSocketOwner(in ParcelFileDescriptor socket, int newUid);
 
    /**
     * Reserve an SPI from the kernel
@@ -415,7 +415,7 @@
     * @param spi a 32-bit unique ID allocated to the user (socket owner)
     */
     void ipSecApplyTransportModeTransform(
-            in FileDescriptor socket,
+            in ParcelFileDescriptor socket,
             int transformId,
             int direction,
             in @utf8InCpp String sourceAddress,
@@ -429,7 +429,7 @@
     * @param socket a user-provided socket from which to remove any IPsec configuration
     */
     void ipSecRemoveTransportModeTransform(
-            in FileDescriptor socket);
+            in ParcelFileDescriptor socket);
 
    /**
     * Adds an IPsec global policy.