[Application.Common] Add internal APIs for getting path related resource control...
authorilho159kim <ilho159.kim@samsung.com>
Tue, 16 May 2023 01:52:45 +0000 (10:52 +0900)
committerGitHub <noreply@github.com>
Tue, 16 May 2023 01:52:45 +0000 (10:52 +0900)
- DirectoryInfo.GetResControlAllowedResource()
- DirectoryInfo.GetResControlGlobalResource()

Signed-off-by: ilho kim <ilho159.kim@samsung.com>
src/Tizen.Applications.Common/Interop/Interop.AppCommon.cs
src/Tizen.Applications.Common/Tizen.Applications/DirectoryInfo.cs

index 7d0362e..a117c30 100644 (file)
@@ -32,6 +32,16 @@ internal static partial class Interop
             Binary
         }
 
+        internal enum AppCommonErrorCode
+        {
+            None = Tizen.Internals.Errors.ErrorCode.None,
+            InvalidParameter = Tizen.Internals.Errors.ErrorCode.InvalidParameter,
+            OutOfMemory = Tizen.Internals.Errors.ErrorCode.OutOfMemory,
+            InvalidContext = -0x01100000 | 0x01,
+            NoSuchFile = Tizen.Internals.Errors.ErrorCode.NoSuchFile,
+            PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied,
+        }
+
         [DllImport(Libraries.AppCommon, EntryPoint = "app_get_id")]
         internal static extern ErrorCode AppGetId(out string appId);
 
@@ -94,6 +104,12 @@ internal static partial class Interop
 
         [DllImport(Libraries.AppCommon, EntryPoint = "app_event_get_suspended_state")]
         internal static extern ErrorCode AppEventGetSuspendedState(IntPtr handle, out SuspendedState state);
+
+        [DllImport(Libraries.AppCommon, EntryPoint = "app_get_res_control_allowed_resource_path")]
+        internal static extern AppCommonErrorCode AppGetResControlAllowedResourcePath(string applicationId, out string path);
+
+        [DllImport(Libraries.AppCommon, EntryPoint = "app_get_res_control_global_resource_path")]
+        internal static extern AppCommonErrorCode AppGetResControlGlobalResourcePath(string applicationId, out string path);
     }
 }
 
index cceaba4..d722df7 100644 (file)
  * limitations under the License.
  */
 
+using System;
+using System.ComponentModel;
+using System.IO;
+
 namespace Tizen.Applications
 {
     /// <summary>
@@ -180,5 +184,75 @@ namespace Tizen.Applications
                 return _expansionPackageResourcePath;
             }
         }
+
+        /// <summary>
+        /// Gets the absolute path to the application's resource control directory, which is used to share the allowed resources of the resource packages.
+        /// </summary>
+        /// <param name="resourceType">The resource type defined in the resource package</param>
+        /// <returns> The absolute path to the application's resource control directory, which is used to share the allowed resources of the resource packages.</returns>
+        /// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception>
+        /// <exception cref="OutOfMemoryException">Thrown in case of out of memory.</exception>
+        /// <exception cref="DirectoryNotFoundException">Thrown in case of nonexistence of resource.</exception>
+        /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
+        /// <since_tizen> 10 </since_tizen>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public string GetResourceControlAllowedResource(string resourceType)
+        {
+            string path = string.Empty;
+            Interop.AppCommon.AppCommonErrorCode err = Interop.AppCommon.AppGetResControlAllowedResourcePath(resourceType, out path);
+            if (err != Interop.AppCommon.AppCommonErrorCode.None)
+            {
+                switch (err)
+                {
+                    case Interop.AppCommon.AppCommonErrorCode.InvalidParameter:
+                        throw new ArgumentException("Invalid Arguments");
+                    case Interop.AppCommon.AppCommonErrorCode.OutOfMemory:
+                        throw new OutOfMemoryException("Out of memory");
+                    case Interop.AppCommon.AppCommonErrorCode.InvalidContext:
+                        throw new InvalidOperationException("Invalid app context");
+                    case Interop.AppCommon.AppCommonErrorCode.PermissionDenied:
+                        throw new DirectoryNotFoundException(String.Format("Allowed Resource about {0} is not Found", resourceType));
+                    default:
+                        throw new InvalidOperationException("Invalid Operation");
+                }
+            }
+
+            return path;
+        }
+
+        /// <summary>
+        /// Gets the absolute path to the application's resource control directory, which is used to share the global resources of the resource packages.
+        /// </summary>
+        /// <param name="resourceType">The resource type defined in the resource package</param>
+        /// <returns> The absolute path to the application's resource control directory, which is used to share the global resources of the resource packages.</returns>
+        /// <exception cref="ArgumentException">Thrown in case of an invalid parameter.</exception>
+        /// <exception cref="OutOfMemoryException">Thrown in case of out of memory.</exception>
+        /// <exception cref="DirectoryNotFoundException">Thrown in case of nonexistence of resource.</exception>
+        /// <exception cref="InvalidOperationException">Thrown in case of any internal error.</exception>
+        /// <since_tizen> 10 </since_tizen>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public string GetResourceControlGlobalResource(string resourceType)
+        {
+            string path = string.Empty;
+            Interop.AppCommon.AppCommonErrorCode err = Interop.AppCommon.AppGetResControlGlobalResourcePath(resourceType, out path);
+            if (err != Interop.AppCommon.AppCommonErrorCode.None)
+            {
+                switch (err)
+                {
+                    case Interop.AppCommon.AppCommonErrorCode.InvalidParameter:
+                        throw new ArgumentException("Invalid Arguments");
+                    case Interop.AppCommon.AppCommonErrorCode.OutOfMemory:
+                        throw new OutOfMemoryException("Out of memory");
+                    case Interop.AppCommon.AppCommonErrorCode.InvalidContext:
+                        throw new InvalidOperationException("Invalid app context");
+                    case Interop.AppCommon.AppCommonErrorCode.PermissionDenied:
+                        throw new DirectoryNotFoundException(String.Format("Allowed Resource about {0} is not Found", resourceType));
+                    default:
+                        throw new InvalidOperationException("Invalid Operation");
+                }
+            }
+
+            return path;
+        }
     }
 }