[RPCPort][ACR] Support synchronous connection requests and private file sharing ...
authorhjhun <36876573+hjhun@users.noreply.github.com>
Mon, 10 Aug 2020 06:34:38 +0000 (15:34 +0900)
committerGitHub <noreply@github.com>
Mon, 10 Aug 2020 06:34:38 +0000 (15:34 +0900)
* [RPCPort] Support private sharing feature

If all added paths are under the caller application's data path which
can be obtained, those will be shared to the target application.
Platform will grant a temporary permission to the target application.

Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
* [RPCPort] Support synchronous version connection request method

Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
* [RPCPort] Move ShareFile() and UnshareFile() to Port.cs

Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
* [RPCPort] Change parameter type to IEnumerable<string>

Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
* [RPCPort] Remove unnecessary space

Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/Tizen.Applications.Common/Interop/Interop.RPCPort.cs
src/Tizen.Applications.Common/Tizen.Applications.RPCPort/Port.cs
src/Tizen.Applications.Common/Tizen.Applications.RPCPort/ProxyBase.cs

index bef6586..5a87b3e 100755 (executable)
@@ -19,6 +19,7 @@ using System.Runtime.InteropServices;
 
 using Tizen.Internals.Errors;
 using Tizen.Applications;
+using System.Reflection;
 
 internal static partial class Interop
 {
@@ -195,6 +196,10 @@ internal static partial class Interop
             //int rpc_port_proxy_get_port(rpc_port_proxy_h h, rpc_port_port_type_e type, rpc_port_h* port);
             [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_proxy_get_port")]
             internal static extern ErrorCode GetPort(IntPtr handle, PortType t, out IntPtr port);
+
+            //int rpc_port_proxy_connect_sync(rpc_port_proxy_h h, const char* appid, const char* port);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_proxy_connect_sync")]
+            internal static extern ErrorCode ConnectSync(IntPtr handle, string appId, string port);
         }
 
         internal static partial class Stub
@@ -247,5 +252,20 @@ internal static partial class Interop
             [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_stub_get_port")]
             internal static extern ErrorCode GetPort(IntPtr handle, PortType t, string instance, out IntPtr port);
         }
+
+        internal static partial class Port
+        {
+            //int rpc_port_set_private_sharing_array(rpc_port_h port, const char* paths[], unsigned int size);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_set_private_sharing_array")]
+            internal static extern ErrorCode SetPrivateSharingArray(IntPtr handle, string[] paths, uint size);
+
+            //int rpc_port_set_private_sharing(rpc_port_h port, const char* path);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_set_private_sharing_array")]
+            internal static extern ErrorCode SetPrivateSharing(IntPtr handle, string path);
+
+            //int rpc_port_unset_private_sharing(rpc_port_h port);
+            [DllImport(Libraries.RpcPort, EntryPoint = "rpc_port_unset_private_sharing")]
+            internal static extern ErrorCode UnsetPrivateSharing(IntPtr handle);
+        }
     }
 }
index f31364f..a8eca4c 100755 (executable)
@@ -15,6 +15,8 @@
  */
 
 using System;
+using System.Collections.Generic;
+using System.Linq;
 
 namespace Tizen.Applications.RPCPort
 {
@@ -42,5 +44,57 @@ namespace Tizen.Applications.RPCPort
 
         internal IntPtr Handle { get; set; }
         internal Port() { }
+
+        /// <summary>
+        /// Shares private files with other applications.
+        /// </summary>
+        /// <remarks>
+        /// If all added paths are under the caller application's data path which can be obtained, those will be shared to the target application.
+        /// Platform will grant a temporary permission to the target application for those files and revoke it when the target application is terminated or UnshareFile() is called.
+        /// Paths should be regular files. The target application can just read them.
+        /// Note that the target application doesn't have read permission of the directory that is obtained by caller's data path. You should open the file path with read only mode directly.
+        /// </remarks>
+        /// <param name="paths">The file paths to be shared.</param>
+        /// <exception cref="InvalidIOException">Thrown when an internal IO error occurrs.</exception>
+        /// <since_tizen> 8 </since_tizen>
+        public void ShareFile(IEnumerable<string> paths)
+        {
+            if (paths == null)
+                throw new InvalidIOException();
+
+            string[] pathArray = paths.ToArray<string>();
+            Interop.LibRPCPort.ErrorCode err = Interop.LibRPCPort.Port.SetPrivateSharingArray(Handle, pathArray, (uint)pathArray.Length);
+            if (err != Interop.LibRPCPort.ErrorCode.None)
+                throw new InvalidIOException();
+        }
+
+        /// <summary>
+        /// Shares the private file with other applications.
+        /// </summary>
+        /// <seealso cref="ShareFile(IEnumerable{string})"/>
+        /// <param name="path">The file path to be shared.</param>
+        /// <exception cref="InvalidIOException">Thrown when an internal IO error occurrs.</exception>
+        /// <since_tizen> 8 </since_tizen>
+        public void ShareFile(string path)
+        {
+            if (path == null)
+                throw new InvalidIOException();
+
+            Interop.LibRPCPort.ErrorCode err = Interop.LibRPCPort.Port.SetPrivateSharing(Handle, path);
+            if (err != Interop.LibRPCPort.ErrorCode.None)
+                throw new InvalidIOException();
+        }
+
+        /// <summary>
+        /// Unshares the private file.
+        /// </summary>
+        /// <exception cref="InvalidIOException">Thrown when an internal IO error occurrs.</exception>
+        /// <since_tizen> 8 </since_tizen>
+        public void UnshareFile()
+        {
+            Interop.LibRPCPort.ErrorCode err = Interop.LibRPCPort.Port.UnsetPrivateSharing(Handle);
+            if (err != Interop.LibRPCPort.ErrorCode.None)
+                throw new InvalidIOException();
+        }
     }
 }
index 7cb7f4e..edaabfa 100755 (executable)
@@ -87,6 +87,31 @@ namespace Tizen.Applications.RPCPort
         }
 
         /// <summary>
+        /// Connects to port synchronously.
+        /// </summary>
+        /// <param name="appid">The target stub app ID.</param>
+        /// <param name="port">The name of the RPC port.</param>
+        /// <exception cref="InvalidIDException">Thrown when not available app ID is used.</exception>
+        /// <exception cref="InvalidIOException">Thrown when an internal IO error occurs.</exception>
+        /// <exception cref="PermissionDeniedException">Thrown when the permission is denied.</exception>
+        /// <privilege>http://tizen.org/privilege/datasharing</privilege>
+        /// <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
+        /// <since_tizen> 8 </since_tizen>
+        protected void ConnectSync(string appid, string port)
+        {
+            var err = Interop.LibRPCPort.Proxy.ConnectSync(_proxy, appid, port);
+            switch (err)
+            {
+                case Interop.LibRPCPort.ErrorCode.InvalidParameter:
+                    throw new InvalidIDException();
+                case Interop.LibRPCPort.ErrorCode.PermissionDenied:
+                    throw new PermissionDeniedException();
+                case Interop.LibRPCPort.ErrorCode.IoError:
+                    throw new InvalidIOException();
+            }
+        }
+
+        /// <summary>
         /// Gets a port.
         /// </summary>
         /// <param name="t">The type of port.</param>